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:
Mark Iantorno 2020-09-01 16:02:28 -04:00 committed by GitHub
parent aae995b72c
commit 3a30f0e780
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 25 deletions

View File

@ -1353,8 +1353,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
return isBundle; return isBundle;
} }
public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles) throws FHIRException, IOException, EOperationOutcome { public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
InstanceValidator validator = getValidator(); InstanceValidator validator = getValidator();
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles)); validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
return messagesToOutcome(messages); return messagesToOutcome(messages);

View File

@ -1,7 +1,7 @@
package org.hl7.fhir.validation.cli.model; package org.hl7.fhir.validation.cli.model;
import com.fasterxml.jackson.annotation.JsonProperty; 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.ArrayList;
import java.util.List; import java.util.List;
@ -11,13 +11,14 @@ public class ValidationOutcome {
@JsonProperty("fileInfo") @JsonProperty("fileInfo")
private FileInfo fileInfo; private FileInfo fileInfo;
@JsonProperty("issues") @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.fileInfo = fileInfo;
this.issues = issues; this.messages = issues;
} }
@JsonProperty("fileInfo") @JsonProperty("fileInfo")
@ -32,20 +33,18 @@ public class ValidationOutcome {
} }
@JsonProperty("issues") @JsonProperty("issues")
public List<ValidationIssue> getIssues() { public List<ValidationMessage> getMessages() {
return issues; return messages;
} }
@JsonProperty("issues") @JsonProperty("issues")
public ValidationOutcome setIssues(List<ValidationIssue> issues) { public ValidationOutcome setIssues(List<ValidationMessage> issues) {
this.issues = issues; this.messages = issues;
return this; return this;
} }
public ValidationOutcome addIssue(OperationOutcome.OperationOutcomeIssueComponent outcome) { public ValidationOutcome addMessage(ValidationMessage message) {
String text = outcome.getDetails().getText(); messages.add(message);
text.replace("\'", "\"");
issues.add(new ValidationIssue(outcome.getSeverity().getDisplay(), outcome.getDetails().getText()));
return this; return this;
} }

View File

@ -11,12 +11,14 @@ import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.TimeTracker; import org.hl7.fhir.utilities.TimeTracker;
import org.hl7.fhir.utilities.Utilities; 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;
import org.hl7.fhir.validation.ValidationEngine.VersionSourceInformation; import org.hl7.fhir.validation.ValidationEngine.VersionSourceInformation;
import org.hl7.fhir.validation.cli.model.*; import org.hl7.fhir.validation.cli.model.*;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -40,14 +42,11 @@ public class ValidationService {
ValidationResponse response = new ValidationResponse(); ValidationResponse response = new ValidationResponse();
for (FileInfo fp : request.getFilesToValidate()) { for (FileInfo fp : request.getFilesToValidate()) {
OperationOutcome operationOutcome = validator.validate(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()), List<ValidationMessage> messages = new ArrayList<>();
request.getCliContext().getProfiles()); validator.validate(fp.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fp.getFileType()),
ValidationOutcome outcome = new ValidationOutcome(); request.getCliContext().getProfiles(), messages);
ValidationOutcome outcome = new ValidationOutcome().setFileInfo(fp);
// Need to set file content to null as server can't handle json in json messages.forEach(outcome::addMessage);
//fp.setFileContent(null);
outcome.setFileInfo(fp);
operationOutcome.getIssue().forEach(outcome::addIssue);
response.addOutcome(outcome); response.addOutcome(outcome);
} }
return response; return response;
@ -143,7 +142,7 @@ public class ValidationService {
List<StructureDefinition> structures = validator.getContext().allStructures(); List<StructureDefinition> structures = validator.getContext().allStructures();
for (StructureDefinition sd : structures) { for (StructureDefinition sd : structures) {
if (!sd.hasSnapshot()) { if (!sd.hasSnapshot()) {
if (sd.getKind()!=null && sd.getKind() == StructureDefinitionKind.LOGICAL) { if (sd.getKind() != null && sd.getKind() == StructureDefinitionKind.LOGICAL) {
validator.getContext().generateSnapshot(sd, true); validator.getContext().generateSnapshot(sd, true);
} else { } else {
validator.getContext().generateSnapshot(sd, false); validator.getContext().generateSnapshot(sd, false);

View File

@ -1,7 +1,17 @@
package org.hl7.fhir.validation.cli; package org.hl7.fhir.validation.cli;
import io.github.bonigarcia.wdm.WebDriverManager; 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.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.Assertions;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -10,9 +20,13 @@ import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.chrome.ChromeOptions;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Arrays;
class ValidatorGuiTest { 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>"; private final String HTML_TITLE_TAG = "<title>FHIR HL7 Resrouce Validator GUI</title>";
@Test @Test