WIP track derived content for ValidatedFragment

This commit is contained in:
dotasek 2023-09-26 16:46:22 -04:00
parent c79fa08473
commit d850944057
9 changed files with 43 additions and 49 deletions

View File

@ -50,7 +50,7 @@ public class FmlParser extends ParserBase {
ByteArrayInputStream stream = new ByteArrayInputStream(content);
String text = TextFile.streamToString(stream);
List<ValidatedFragment> result = new ArrayList<>();
ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "fml", content);
ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "fml", content, false);
focusFragment.setElement(parse(focusFragment.getErrors(), text));
result.add(focusFragment);
return result;

View File

@ -122,7 +122,7 @@ public class JsonParser extends ParserBase {
public List<ValidatedFragment> parse(InputStream inStream) throws IOException, FHIRException {
// long start = System.currentTimeMillis();
byte[] content = TextFile.streamToBytes(inStream);
ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "json", content);
ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "json", content, false);
ByteArrayInputStream stream = new ByteArrayInputStream(content);

View File

@ -83,7 +83,7 @@ public class SHCParser extends ParserBase {
byte[] content = TextFile.streamToBytes(inStream);
ByteArrayInputStream stream = new ByteArrayInputStream(content);
List<ValidatedFragment> res = new ArrayList<>();
ValidatedFragment shc = new ValidatedFragment("shc", "json", content);
ValidatedFragment shc = new ValidatedFragment("shc", "json", content, false);
res.add(shc);
String src = TextFile.streamToString(stream).trim();
@ -165,7 +165,7 @@ public class SHCParser extends ParserBase {
return res;
}
// ok. all checks passed, we can now validate the bundle
ValidatedFragment bnd = new ValidatedFragment(path, "json", org.hl7.fhir.utilities.json.parser.JsonParser.composeBytes(cs.getJsonObject("fhirBundle")));
ValidatedFragment bnd = new ValidatedFragment(path, "json", org.hl7.fhir.utilities.json.parser.JsonParser.composeBytes(cs.getJsonObject("fhirBundle")), true);
res.add(bnd);
bnd.setElement(jsonParser.parse(bnd.getErrors(), cs.getJsonObject("fhirBundle")));
}

View File

@ -280,7 +280,7 @@ public class SHLParser extends ParserBase {
}
private ValidatedFragment addNamedElement(List<ValidatedFragment> res, String name, String type, byte[] content) {
ValidatedFragment result = new ValidatedFragment(name, type, content);
ValidatedFragment result = new ValidatedFragment(name, type, content, true);
res.add(result);
return result;
}

View File

@ -82,7 +82,7 @@ public class TurtleParser extends ParserBase {
@Override
public List<ValidatedFragment> parse(InputStream inStream) throws IOException, FHIRException {
byte[] content = TextFile.streamToBytes(inStream);
ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "ttl", content);
ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "ttl", content, false);
ByteArrayInputStream stream = new ByteArrayInputStream(content);
Turtle src = new Turtle();

View File

@ -3,57 +3,50 @@ package org.hl7.fhir.r5.elementmodel;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import org.hl7.fhir.utilities.validation.ValidationMessage;
public class ValidatedFragment {
@Getter
private String name;
@Getter
private String extension;
@Getter @Setter
private Element element;
@Getter @Setter
private byte[] content;
@Getter
private final boolean isDerivedContent;
public final static String FOCUS_NAME = "focus";
@Getter
private List<ValidationMessage> errors = new ArrayList<>();
public ValidatedFragment(String name, String extension, Element element, byte[] content) {
public ValidatedFragment(String name, String extension, Element element, byte[] content, boolean isDerivedContent) {
super();
this.name = name;
this.element = element;
this.content = content;
this.extension = extension;
this.isDerivedContent = isDerivedContent;
}
public ValidatedFragment(String name, String extension, byte[] content) {
public ValidatedFragment(String name, String extension, byte[] content, boolean isDerivedContent) {
super();
this.name = name;
this.content = content;
this.extension = extension;
this.isDerivedContent = isDerivedContent;
}
public String getName() {
return name;
}
public Element getElement() {
return element;
}
public byte[] getContent() {
return content;
}
public List<ValidationMessage> getErrors() {
return errors;
}
public void setElement(Element element) {
this.element = element;
}
public String getFilename() {
return name+"."+extension;
}
public String getExtension() {
return extension;
}
}

View File

@ -465,7 +465,7 @@ public class VerticalBarParser extends ParserBase {
while (!reader.isFinished()) // && (getOptions().getSegmentLimit() == 0 || getOptions().getSegmentLimit() > message.getSegments().size()))
readSegment(message, reader);
List<ValidatedFragment> res = new ArrayList<>();
res.add(new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "hl7", message, content));
res.add(new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "hl7", message, content, false));
return res;
}

View File

@ -114,7 +114,7 @@ public class XmlParser extends ParserBase {
public List<ValidatedFragment> parse(InputStream inStream) throws FHIRFormatError, DefinitionException, FHIRException, IOException {
byte[] content = TextFile.streamToBytes(inStream);
ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "xml", content);
ValidatedFragment focusFragment = new ValidatedFragment(ValidatedFragment.FOCUS_NAME, "xml", content, false);
ByteArrayInputStream stream = new ByteArrayInputStream(content);
Document doc = null;

View File

@ -127,7 +127,17 @@ public class ValidationService {
List<ValidatedFragment> validatedFragments = validator.validateAsFragments(fileToValidate.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fileToValidate.getFileType()),
request.getCliContext().getProfiles(), messages);
// TODO this chunk does not work for multi-file validation, as the fileName is overwritten
if (validatedFragments.size() == 1 && !validatedFragments.get(0).isDerivedContent()) {
ValidatedFragment validatedFragment = validatedFragments.get(0);
ValidationOutcome outcome = new ValidationOutcome();
FileInfo fileInfo = new FileInfo(
fileToValidate.getFileName(),
new String(validatedFragment.getContent()),
validatedFragment.getExtension());
outcome.setMessages(validatedFragment.getErrors());
outcome.setFileInfo(fileInfo);
response.addOutcome(outcome);
} else {
for (ValidatedFragment validatedFragment : validatedFragments) {
ValidationOutcome outcome = new ValidationOutcome();
FileInfo fileInfo = new FileInfo(
@ -138,16 +148,7 @@ public class ValidationService {
outcome.setFileInfo(fileInfo);
response.addOutcome(outcome);
}
//TODO the code below works correctly for multi-file validation.
/*
validator.validate(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()),
request.getCliContext().getProfiles(), messages);
ValidationOutcome outcome = new ValidationOutcome().setFileInfo(fp);
messages.forEach(outcome::addMessage);
response.addOutcome(outcome);
*/
}
}
System.out.println(" Max Memory: "+Runtime.getRuntime().maxMemory());
return response;