If file type is inferred to be null, return error instead of just throwing exception and never returning.
This commit is contained in:
parent
4ffe900fb3
commit
05e3c76426
|
@ -110,14 +110,38 @@ public class ValidationService {
|
||||||
fileToValidate.getFileContent().getBytes(),
|
fileToValidate.getFileContent().getBytes(),
|
||||||
fileToValidate.getFileName(),
|
fileToValidate.getFileName(),
|
||||||
false);
|
false);
|
||||||
|
if (format != null) {
|
||||||
fileToValidate.setFileType(format.getExtension());
|
fileToValidate.setFileType(format.getExtension());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<ValidationMessage> messages = new ArrayList<>();
|
List<ValidationMessage> messages = new ArrayList<>();
|
||||||
|
|
||||||
|
if (fileToValidate.getFileType() == null) {
|
||||||
|
ValidationOutcome outcome = getValidationOutcomeForUnknownFileFormat(
|
||||||
|
new FileInfo(fileToValidate.getFileName(), fileToValidate.getFileContent(), null));
|
||||||
|
response.addOutcome(outcome);
|
||||||
|
} else {
|
||||||
ValidatedFragments validatedFragments = validator.validateAsFragments(fileToValidate.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fileToValidate.getFileType()),
|
ValidatedFragments validatedFragments = validator.validateAsFragments(fileToValidate.getFileContent().getBytes(), Manager.FhirFormat.getFhirFormat(fileToValidate.getFileType()),
|
||||||
request.getCliContext().getProfiles(), messages);
|
request.getCliContext().getProfiles(), messages);
|
||||||
|
|
||||||
|
List<ValidationOutcome> validationOutcomes = getValidationOutcomesFromValidatedFragments(fileToValidate, validatedFragments);
|
||||||
|
for (ValidationOutcome validationOutcome : validationOutcomes) {
|
||||||
|
response.addOutcome(validationOutcome);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.getCliContext().isShowTimes()) {
|
||||||
|
response.getValidationTimes().put(fileToValidate.getFileName(), validatedFragments.getValidationTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(" Max Memory: "+Runtime.getRuntime().maxMemory());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ValidationOutcome> getValidationOutcomesFromValidatedFragments(FileInfo fileToValidate, ValidatedFragments validatedFragments) {
|
||||||
|
List<ValidationOutcome> outcomes = new LinkedList<>();
|
||||||
if (validatedFragments.getValidatedFragments().size() == 1 && !validatedFragments.getValidatedFragments().get(0).isDerivedContent()) {
|
if (validatedFragments.getValidatedFragments().size() == 1 && !validatedFragments.getValidatedFragments().get(0).isDerivedContent()) {
|
||||||
ValidatedFragment validatedFragment = validatedFragments.getValidatedFragments().get(0);
|
ValidatedFragment validatedFragment = validatedFragments.getValidatedFragments().get(0);
|
||||||
ValidationOutcome outcome = new ValidationOutcome();
|
ValidationOutcome outcome = new ValidationOutcome();
|
||||||
|
@ -127,7 +151,7 @@ public class ValidationService {
|
||||||
validatedFragment.getExtension());
|
validatedFragment.getExtension());
|
||||||
outcome.setMessages(validatedFragment.getErrors());
|
outcome.setMessages(validatedFragment.getErrors());
|
||||||
outcome.setFileInfo(fileInfo);
|
outcome.setFileInfo(fileInfo);
|
||||||
response.addOutcome(outcome);
|
outcomes.add(outcome);
|
||||||
} else {
|
} else {
|
||||||
for (ValidatedFragment validatedFragment : validatedFragments.getValidatedFragments()) {
|
for (ValidatedFragment validatedFragment : validatedFragments.getValidatedFragments()) {
|
||||||
ValidationOutcome outcome = new ValidationOutcome();
|
ValidationOutcome outcome = new ValidationOutcome();
|
||||||
|
@ -137,17 +161,22 @@ public class ValidationService {
|
||||||
validatedFragment.getExtension());
|
validatedFragment.getExtension());
|
||||||
outcome.setMessages(validatedFragment.getErrors());
|
outcome.setMessages(validatedFragment.getErrors());
|
||||||
outcome.setFileInfo(fileInfo);
|
outcome.setFileInfo(fileInfo);
|
||||||
response.addOutcome(outcome);
|
outcomes.add(outcome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return outcomes;
|
||||||
|
}
|
||||||
|
|
||||||
if (request.getCliContext().isShowTimes()) {
|
private ValidationOutcome getValidationOutcomeForUnknownFileFormat(FileInfo fileInfo) {
|
||||||
response.getValidationTimes().put(fileToValidate.getFileName(), validatedFragments.getValidationTime());
|
ValidationOutcome outcome = new ValidationOutcome();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println(" Max Memory: "+Runtime.getRuntime().maxMemory());
|
List<ValidationMessage> errorList = new ArrayList<>() {{
|
||||||
return response;
|
add(new ValidationMessage().setType(ValidationMessage.IssueType.EXCEPTION).setLevel(ValidationMessage.IssueSeverity.FATAL).setMessage("Unable to infer format from file. Please check that your file is in a valid FHIR format."));
|
||||||
|
|
||||||
|
} };
|
||||||
|
outcome.setMessages(errorList);
|
||||||
|
outcome.setFileInfo(fileInfo);
|
||||||
|
return outcome;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VersionSourceInformation scanForVersions(CliContext cliContext) throws Exception {
|
public VersionSourceInformation scanForVersions(CliContext cliContext) throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue