changing validator cli return obj to include more information on error location (#329)
Co-authored-by: Grahame Grieve <grahameg@gmail.com>
This commit is contained in:
parent
aae995b72c
commit
3a30f0e780
|
@ -1353,8 +1353,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
return isBundle;
|
||||
}
|
||||
|
||||
public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles) throws FHIRException, IOException, EOperationOutcome {
|
||||
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
|
||||
public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
|
||||
InstanceValidator validator = getValidator();
|
||||
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
|
||||
return messagesToOutcome(messages);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.hl7.fhir.validation.cli.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.hl7.fhir.r5.model.OperationOutcome;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -11,13 +11,14 @@ public class ValidationOutcome {
|
|||
@JsonProperty("fileInfo")
|
||||
private FileInfo fileInfo;
|
||||
@JsonProperty("issues")
|
||||
private List<ValidationIssue> issues = new ArrayList<>();
|
||||
private List<ValidationMessage> messages = new ArrayList<>();
|
||||
|
||||
public ValidationOutcome() {}
|
||||
public ValidationOutcome() {
|
||||
}
|
||||
|
||||
public ValidationOutcome(FileInfo fileInfo, List<ValidationIssue> issues) {
|
||||
public ValidationOutcome(FileInfo fileInfo, List<ValidationMessage> issues) {
|
||||
this.fileInfo = fileInfo;
|
||||
this.issues = issues;
|
||||
this.messages = issues;
|
||||
}
|
||||
|
||||
@JsonProperty("fileInfo")
|
||||
|
@ -32,20 +33,18 @@ public class ValidationOutcome {
|
|||
}
|
||||
|
||||
@JsonProperty("issues")
|
||||
public List<ValidationIssue> getIssues() {
|
||||
return issues;
|
||||
public List<ValidationMessage> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
@JsonProperty("issues")
|
||||
public ValidationOutcome setIssues(List<ValidationIssue> issues) {
|
||||
this.issues = issues;
|
||||
public ValidationOutcome setIssues(List<ValidationMessage> issues) {
|
||||
this.messages = issues;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ValidationOutcome addIssue(OperationOutcome.OperationOutcomeIssueComponent outcome) {
|
||||
String text = outcome.getDetails().getText();
|
||||
text.replace("\'", "\"");
|
||||
issues.add(new ValidationIssue(outcome.getSeverity().getDisplay(), outcome.getDetails().getText()));
|
||||
public ValidationOutcome addMessage(ValidationMessage message) {
|
||||
messages.add(message);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,12 +11,14 @@ import org.hl7.fhir.r5.utils.ToolingExtensions;
|
|||
import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.TimeTracker;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
import org.hl7.fhir.validation.ValidationEngine;
|
||||
import org.hl7.fhir.validation.ValidationEngine.VersionSourceInformation;
|
||||
import org.hl7.fhir.validation.cli.model.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -40,14 +42,11 @@ public class ValidationService {
|
|||
|
||||
ValidationResponse response = new ValidationResponse();
|
||||
for (FileInfo fp : request.getFilesToValidate()) {
|
||||
OperationOutcome operationOutcome = validator.validate(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()),
|
||||
request.getCliContext().getProfiles());
|
||||
ValidationOutcome outcome = new ValidationOutcome();
|
||||
|
||||
// Need to set file content to null as server can't handle json in json
|
||||
//fp.setFileContent(null);
|
||||
outcome.setFileInfo(fp);
|
||||
operationOutcome.getIssue().forEach(outcome::addIssue);
|
||||
List<ValidationMessage> messages = new ArrayList<>();
|
||||
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);
|
||||
}
|
||||
return response;
|
||||
|
@ -143,7 +142,7 @@ public class ValidationService {
|
|||
List<StructureDefinition> structures = validator.getContext().allStructures();
|
||||
for (StructureDefinition sd : structures) {
|
||||
if (!sd.hasSnapshot()) {
|
||||
if (sd.getKind()!=null && sd.getKind() == StructureDefinitionKind.LOGICAL) {
|
||||
if (sd.getKind() != null && sd.getKind() == StructureDefinitionKind.LOGICAL) {
|
||||
validator.getContext().generateSnapshot(sd, true);
|
||||
} else {
|
||||
validator.getContext().generateSnapshot(sd, false);
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
package org.hl7.fhir.validation.cli;
|
||||
|
||||
import io.github.bonigarcia.wdm.WebDriverManager;
|
||||
import org.hl7.fhir.r5.elementmodel.Manager;
|
||||
import org.hl7.fhir.r5.model.FhirPublication;
|
||||
import org.hl7.fhir.r5.model.OperationOutcome;
|
||||
import org.hl7.fhir.r5.test.utils.TestingUtilities;
|
||||
import org.hl7.fhir.r5.utils.EOperationOutcome;
|
||||
import org.hl7.fhir.validation.ValidationEngine;
|
||||
import org.hl7.fhir.validation.cli.model.CliContext;
|
||||
import org.hl7.fhir.validation.cli.model.FileInfo;
|
||||
import org.hl7.fhir.validation.cli.model.ValidationRequest;
|
||||
import org.hl7.fhir.validation.cli.model.ValidationResponse;
|
||||
import org.hl7.fhir.validation.cli.services.ValidationService;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -10,9 +20,13 @@ import org.openqa.selenium.chrome.ChromeDriver;
|
|||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
|
||||
class ValidatorGuiTest {
|
||||
|
||||
private static final String DEF_TX = "http://tx.fhir.org";
|
||||
private final String HTML_TITLE_TAG = "<title>FHIR HL7 Resrouce Validator GUI</title>";
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue