Include Validation time in ValidationResponse
This commit is contained in:
parent
8fe88a320e
commit
6916854071
|
@ -90,6 +90,8 @@ import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
|
||||||
import org.hl7.fhir.validation.BaseValidator.ValidationControl;
|
import org.hl7.fhir.validation.BaseValidator.ValidationControl;
|
||||||
import org.hl7.fhir.validation.ValidatorUtils.SourceFile;
|
import org.hl7.fhir.validation.ValidatorUtils.SourceFile;
|
||||||
import org.hl7.fhir.validation.cli.model.HtmlInMarkdownCheck;
|
import org.hl7.fhir.validation.cli.model.HtmlInMarkdownCheck;
|
||||||
|
import org.hl7.fhir.validation.cli.model.ValidatedFragments;
|
||||||
|
import org.hl7.fhir.validation.cli.model.ValidationTime;
|
||||||
import org.hl7.fhir.validation.cli.services.IPackageInstaller;
|
import org.hl7.fhir.validation.cli.services.IPackageInstaller;
|
||||||
import org.hl7.fhir.validation.cli.utils.ProfileLoader;
|
import org.hl7.fhir.validation.cli.utils.ProfileLoader;
|
||||||
import org.hl7.fhir.validation.cli.utils.QuestionnaireMode;
|
import org.hl7.fhir.validation.cli.utils.QuestionnaireMode;
|
||||||
|
@ -632,10 +634,11 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<ValidatedFragment> validateAsFragments(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
|
public ValidatedFragments validateAsFragments(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
|
||||||
InstanceValidator validator = getValidator(cntType);
|
InstanceValidator validator = getValidator(cntType);
|
||||||
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
|
validator.validate(null, messages, new ByteArrayInputStream(source), cntType, asSdList(profiles));
|
||||||
return validator.validatedContent;
|
return new ValidatedFragments(validator.validatedContent,
|
||||||
|
ValidationTime.fromTimeTracker(validator.timeTracker));
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
|
public OperationOutcome validate(byte[] source, FhirFormat cntType, List<String> profiles, List<ValidationMessage> messages) throws FHIRException, IOException, EOperationOutcome {
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package org.hl7.fhir.validation.cli.model;
|
||||||
|
|
||||||
|
import org.hl7.fhir.r5.elementmodel.ValidatedFragment;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ValidatedFragments {
|
||||||
|
|
||||||
|
public List<ValidatedFragment> getValidatedFragments() {
|
||||||
|
return validatedFragments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidationTime getValidationTime() {
|
||||||
|
return validationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ValidatedFragment> validatedFragments;
|
||||||
|
|
||||||
|
private ValidationTime validationTime;
|
||||||
|
|
||||||
|
public ValidatedFragments(List<ValidatedFragment> validatedFragments, ValidationTime validationTime) {
|
||||||
|
this.validatedFragments = validatedFragments;
|
||||||
|
this.validationTime = validationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -13,6 +13,9 @@ public class ValidationResponse {
|
||||||
@JsonProperty("sessionId")
|
@JsonProperty("sessionId")
|
||||||
public String sessionId;
|
public String sessionId;
|
||||||
|
|
||||||
|
@JsonProperty("validationTime")
|
||||||
|
public ValidationTime validationTime;
|
||||||
|
|
||||||
public ValidationResponse() {}
|
public ValidationResponse() {}
|
||||||
|
|
||||||
public ValidationResponse(List<ValidationOutcome> outcomes) {
|
public ValidationResponse(List<ValidationOutcome> outcomes) {
|
||||||
|
@ -54,4 +57,15 @@ public class ValidationResponse {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty("validationTime")
|
||||||
|
public ValidationTime getValidationTime() {
|
||||||
|
return validationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("validationTime")
|
||||||
|
public ValidationResponse setValidationTime(ValidationTime validationTime) {
|
||||||
|
this.validationTime = validationTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package org.hl7.fhir.validation.cli.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import org.hl7.fhir.validation.TimeTracker;
|
||||||
|
|
||||||
|
public class ValidationTime {
|
||||||
|
|
||||||
|
|
||||||
|
@JsonProperty("overall")
|
||||||
|
private long overall = 0;
|
||||||
|
|
||||||
|
@JsonProperty("terminology")
|
||||||
|
private long txTime = 0;
|
||||||
|
|
||||||
|
@JsonProperty("structureDefinition")
|
||||||
|
private long sdTime = 0;
|
||||||
|
|
||||||
|
@JsonProperty("resourceParse")
|
||||||
|
private long loadTime = 0;
|
||||||
|
|
||||||
|
@JsonProperty("fhirPath")
|
||||||
|
private long fpeTime = 0;
|
||||||
|
|
||||||
|
@JsonProperty("checkingSpecials")
|
||||||
|
private long specTime = 0;
|
||||||
|
|
||||||
|
@JsonProperty("terminology")
|
||||||
|
public long getTxTime() {
|
||||||
|
return txTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("terminology")
|
||||||
|
public ValidationTime setTxTime(long txTime) {
|
||||||
|
this.txTime = txTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("structureDefinition")
|
||||||
|
public long getSdTime() {
|
||||||
|
return sdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("structureDefinition")
|
||||||
|
public ValidationTime setSdTime(long sdTime) {
|
||||||
|
this.sdTime = sdTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("resourceParse")
|
||||||
|
public long getLoadTime() {
|
||||||
|
return loadTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("resourceParse")
|
||||||
|
public ValidationTime setLoadTime(long loadTime) {
|
||||||
|
this.loadTime = loadTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("fhirPath")
|
||||||
|
public long getFpeTime() {
|
||||||
|
return fpeTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("fhirPath")
|
||||||
|
public ValidationTime setFpeTime(long fpeTime) {
|
||||||
|
this.fpeTime = fpeTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("checkingSpecials")
|
||||||
|
public long getSpecTime() {
|
||||||
|
return specTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("checkingSpecials")
|
||||||
|
public ValidationTime setSpecTime(long specTime) {
|
||||||
|
this.specTime = specTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("overall")
|
||||||
|
public long getOverall() {
|
||||||
|
return overall;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty("overall")
|
||||||
|
public ValidationTime setOverall(long overall) {
|
||||||
|
this.overall = overall;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ValidationTime fromTimeTracker(TimeTracker timeTracker) {
|
||||||
|
return new ValidationTime()
|
||||||
|
.setSdTime(timeTracker.getSdTime())
|
||||||
|
.setTxTime(timeTracker.getTxTime())
|
||||||
|
.setSpecTime(timeTracker.getSpecTime())
|
||||||
|
.setFpeTime(timeTracker.getFpeTime())
|
||||||
|
.setOverall(timeTracker.getOverall())
|
||||||
|
.setLoadTime(timeTracker.getLoadTime());
|
||||||
|
}
|
||||||
|
}
|
|
@ -64,11 +64,7 @@ import org.hl7.fhir.utilities.npm.NpmPackage;
|
||||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||||
import org.hl7.fhir.validation.*;
|
import org.hl7.fhir.validation.*;
|
||||||
import org.hl7.fhir.validation.ValidatorUtils.SourceFile;
|
import org.hl7.fhir.validation.ValidatorUtils.SourceFile;
|
||||||
import org.hl7.fhir.validation.cli.model.CliContext;
|
import org.hl7.fhir.validation.cli.model.*;
|
||||||
import org.hl7.fhir.validation.cli.model.FileInfo;
|
|
||||||
import org.hl7.fhir.validation.cli.model.ValidationOutcome;
|
|
||||||
import org.hl7.fhir.validation.cli.model.ValidationRequest;
|
|
||||||
import org.hl7.fhir.validation.cli.model.ValidationResponse;
|
|
||||||
import org.hl7.fhir.validation.cli.renderers.CSVRenderer;
|
import org.hl7.fhir.validation.cli.renderers.CSVRenderer;
|
||||||
import org.hl7.fhir.validation.cli.renderers.CompactRenderer;
|
import org.hl7.fhir.validation.cli.renderers.CompactRenderer;
|
||||||
import org.hl7.fhir.validation.cli.renderers.DefaultRenderer;
|
import org.hl7.fhir.validation.cli.renderers.DefaultRenderer;
|
||||||
|
@ -101,7 +97,8 @@ public class ValidationService {
|
||||||
|
|
||||||
String definitions = VersionUtilities.packageForVersion(request.getCliContext().getSv()) + "#" + VersionUtilities.getCurrentVersion(request.getCliContext().getSv());
|
String definitions = VersionUtilities.packageForVersion(request.getCliContext().getSv()) + "#" + VersionUtilities.getCurrentVersion(request.getCliContext().getSv());
|
||||||
|
|
||||||
String sessionId = initializeValidator(request.getCliContext(), definitions, new TimeTracker(), request.sessionId);
|
TimeTracker timeTracker = new TimeTracker();
|
||||||
|
String sessionId = initializeValidator(request.getCliContext(), definitions, timeTracker, request.sessionId);
|
||||||
ValidationEngine validator = sessionCache.fetchSessionValidatorEngine(sessionId);
|
ValidationEngine validator = sessionCache.fetchSessionValidatorEngine(sessionId);
|
||||||
|
|
||||||
if (request.getCliContext().getProfiles().size() > 0) {
|
if (request.getCliContext().getProfiles().size() > 0) {
|
||||||
|
@ -124,11 +121,11 @@ public class ValidationService {
|
||||||
|
|
||||||
List<ValidationMessage> messages = new ArrayList<>();
|
List<ValidationMessage> messages = new ArrayList<>();
|
||||||
|
|
||||||
List<ValidatedFragment> 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);
|
||||||
|
|
||||||
if (validatedFragments.size() == 1 && !validatedFragments.get(0).isDerivedContent()) {
|
if (validatedFragments.getValidatedFragments().size() == 1 && !validatedFragments.getValidatedFragments().get(0).isDerivedContent()) {
|
||||||
ValidatedFragment validatedFragment = validatedFragments.get(0);
|
ValidatedFragment validatedFragment = validatedFragments.getValidatedFragments().get(0);
|
||||||
ValidationOutcome outcome = new ValidationOutcome();
|
ValidationOutcome outcome = new ValidationOutcome();
|
||||||
FileInfo fileInfo = new FileInfo(
|
FileInfo fileInfo = new FileInfo(
|
||||||
fileToValidate.getFileName(),
|
fileToValidate.getFileName(),
|
||||||
|
@ -138,7 +135,7 @@ public class ValidationService {
|
||||||
outcome.setFileInfo(fileInfo);
|
outcome.setFileInfo(fileInfo);
|
||||||
response.addOutcome(outcome);
|
response.addOutcome(outcome);
|
||||||
} else {
|
} else {
|
||||||
for (ValidatedFragment validatedFragment : validatedFragments) {
|
for (ValidatedFragment validatedFragment : validatedFragments.getValidatedFragments()) {
|
||||||
ValidationOutcome outcome = new ValidationOutcome();
|
ValidationOutcome outcome = new ValidationOutcome();
|
||||||
FileInfo fileInfo = new FileInfo(
|
FileInfo fileInfo = new FileInfo(
|
||||||
validatedFragment.getFilename(),
|
validatedFragment.getFilename(),
|
||||||
|
@ -149,7 +146,13 @@ public class ValidationService {
|
||||||
response.addOutcome(outcome);
|
response.addOutcome(outcome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.getCliContext().isShowTimes())
|
||||||
|
response.setValidationTime(validatedFragments.getValidationTime()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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