WIP track derived content for ValidatedFragment
This commit is contained in:
parent
c79fa08473
commit
d850944057
|
@ -50,7 +50,7 @@ public class FmlParser extends ParserBase {
|
||||||
ByteArrayInputStream stream = new ByteArrayInputStream(content);
|
ByteArrayInputStream stream = new ByteArrayInputStream(content);
|
||||||
String text = TextFile.streamToString(stream);
|
String text = TextFile.streamToString(stream);
|
||||||
List<ValidatedFragment> result = new ArrayList<>();
|
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));
|
focusFragment.setElement(parse(focusFragment.getErrors(), text));
|
||||||
result.add(focusFragment);
|
result.add(focusFragment);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class JsonParser extends ParserBase {
|
||||||
public List<ValidatedFragment> parse(InputStream inStream) throws IOException, FHIRException {
|
public List<ValidatedFragment> parse(InputStream inStream) throws IOException, FHIRException {
|
||||||
// long start = System.currentTimeMillis();
|
// long start = System.currentTimeMillis();
|
||||||
byte[] content = TextFile.streamToBytes(inStream);
|
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);
|
ByteArrayInputStream stream = new ByteArrayInputStream(content);
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class SHCParser extends ParserBase {
|
||||||
byte[] content = TextFile.streamToBytes(inStream);
|
byte[] content = TextFile.streamToBytes(inStream);
|
||||||
ByteArrayInputStream stream = new ByteArrayInputStream(content);
|
ByteArrayInputStream stream = new ByteArrayInputStream(content);
|
||||||
List<ValidatedFragment> res = new ArrayList<>();
|
List<ValidatedFragment> res = new ArrayList<>();
|
||||||
ValidatedFragment shc = new ValidatedFragment("shc", "json", content);
|
ValidatedFragment shc = new ValidatedFragment("shc", "json", content, false);
|
||||||
res.add(shc);
|
res.add(shc);
|
||||||
|
|
||||||
String src = TextFile.streamToString(stream).trim();
|
String src = TextFile.streamToString(stream).trim();
|
||||||
|
@ -165,7 +165,7 @@ public class SHCParser extends ParserBase {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
// ok. all checks passed, we can now validate the bundle
|
// 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);
|
res.add(bnd);
|
||||||
bnd.setElement(jsonParser.parse(bnd.getErrors(), cs.getJsonObject("fhirBundle")));
|
bnd.setElement(jsonParser.parse(bnd.getErrors(), cs.getJsonObject("fhirBundle")));
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,7 +280,7 @@ public class SHLParser extends ParserBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValidatedFragment addNamedElement(List<ValidatedFragment> res, String name, String type, byte[] content) {
|
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);
|
res.add(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class TurtleParser extends ParserBase {
|
||||||
@Override
|
@Override
|
||||||
public List<ValidatedFragment> parse(InputStream inStream) throws IOException, FHIRException {
|
public List<ValidatedFragment> parse(InputStream inStream) throws IOException, FHIRException {
|
||||||
byte[] content = TextFile.streamToBytes(inStream);
|
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);
|
ByteArrayInputStream stream = new ByteArrayInputStream(content);
|
||||||
|
|
||||||
Turtle src = new Turtle();
|
Turtle src = new Turtle();
|
||||||
|
|
|
@ -3,57 +3,50 @@ package org.hl7.fhir.r5.elementmodel;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||||
|
|
||||||
public class ValidatedFragment {
|
public class ValidatedFragment {
|
||||||
|
|
||||||
|
@Getter
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@Getter
|
||||||
private String extension;
|
private String extension;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
private Element element;
|
private Element element;
|
||||||
|
|
||||||
|
@Getter @Setter
|
||||||
private byte[] content;
|
private byte[] content;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final boolean isDerivedContent;
|
||||||
public final static String FOCUS_NAME = "focus";
|
public final static String FOCUS_NAME = "focus";
|
||||||
|
|
||||||
|
@Getter
|
||||||
private List<ValidationMessage> errors = new ArrayList<>();
|
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();
|
super();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.element = element;
|
this.element = element;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
this.extension = extension;
|
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();
|
super();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
this.extension = extension;
|
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() {
|
public String getFilename() {
|
||||||
return name+"."+extension;
|
return name+"."+extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExtension() {
|
|
||||||
return extension;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -465,7 +465,7 @@ public class VerticalBarParser extends ParserBase {
|
||||||
while (!reader.isFinished()) // && (getOptions().getSegmentLimit() == 0 || getOptions().getSegmentLimit() > message.getSegments().size()))
|
while (!reader.isFinished()) // && (getOptions().getSegmentLimit() == 0 || getOptions().getSegmentLimit() > message.getSegments().size()))
|
||||||
readSegment(message, reader);
|
readSegment(message, reader);
|
||||||
List<ValidatedFragment> res = new ArrayList<>();
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class XmlParser extends ParserBase {
|
||||||
public List<ValidatedFragment> parse(InputStream inStream) throws FHIRFormatError, DefinitionException, FHIRException, IOException {
|
public List<ValidatedFragment> parse(InputStream inStream) throws FHIRFormatError, DefinitionException, FHIRException, IOException {
|
||||||
|
|
||||||
byte[] content = TextFile.streamToBytes(inStream);
|
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);
|
ByteArrayInputStream stream = new ByteArrayInputStream(content);
|
||||||
Document doc = null;
|
Document doc = null;
|
||||||
|
|
|
@ -127,27 +127,28 @@ public class ValidationService {
|
||||||
List<ValidatedFragment> validatedFragments = validator.validateAsFragments(fileToValidate.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fileToValidate.getFileType()),
|
List<ValidatedFragment> validatedFragments = validator.validateAsFragments(fileToValidate.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fileToValidate.getFileType()),
|
||||||
request.getCliContext().getProfiles(), messages);
|
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()) {
|
||||||
for (ValidatedFragment validatedFragment : validatedFragments) {
|
ValidatedFragment validatedFragment = validatedFragments.get(0);
|
||||||
ValidationOutcome outcome = new ValidationOutcome();
|
ValidationOutcome outcome = new ValidationOutcome();
|
||||||
FileInfo fileInfo = new FileInfo(
|
FileInfo fileInfo = new FileInfo(
|
||||||
validatedFragment.getFilename(),
|
fileToValidate.getFileName(),
|
||||||
new String(validatedFragment.getContent()),
|
new String(validatedFragment.getContent()),
|
||||||
validatedFragment.getExtension());
|
validatedFragment.getExtension());
|
||||||
outcome.setMessages(validatedFragment.getErrors());
|
outcome.setMessages(validatedFragment.getErrors());
|
||||||
outcome.setFileInfo(fileInfo);
|
outcome.setFileInfo(fileInfo);
|
||||||
response.addOutcome(outcome);
|
response.addOutcome(outcome);
|
||||||
|
} else {
|
||||||
|
for (ValidatedFragment validatedFragment : validatedFragments) {
|
||||||
|
ValidationOutcome outcome = new ValidationOutcome();
|
||||||
|
FileInfo fileInfo = new FileInfo(
|
||||||
|
validatedFragment.getFilename(),
|
||||||
|
new String(validatedFragment.getContent()),
|
||||||
|
validatedFragment.getExtension());
|
||||||
|
outcome.setMessages(validatedFragment.getErrors());
|
||||||
|
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());
|
System.out.println(" Max Memory: "+Runtime.getRuntime().maxMemory());
|
||||||
return response;
|
return response;
|
||||||
|
|
Loading…
Reference in New Issue