use of org.hl7.fhir.utilities.TimeTracker in project Gravity-SDOH-Exchange-RI by FHIR.
the class ConvertService method initValidationEngine.
@EventListener(ApplicationReadyEvent.class)
protected void initValidationEngine() throws IOException, URISyntaxException {
String definitions = VersionUtilities.packageForVersion(PACKAGE_VERSION) + "#" + VersionUtilities.getCurrentVersion(PACKAGE_VERSION);
this.validationEngine = new ValidationEngine(definitions, FhirPublication.R4, PACKAGE_VERSION, new TimeTracker());
// Loading structure definitions from official package and uploading custom definitions if needed from resources
this.validationEngine.loadPackage(SDOH_CLINICAL_CARE_PACKAGE, SDOH_CLINICAL_CARE_VERSION);
// Loading custom structure definitions, copying all resources from jar to local folder to be able for HAPI to
// upload them. Just passing resources folder is not working for "in jar" files.
loadStructureDefinitions();
}
use of org.hl7.fhir.utilities.TimeTracker in project org.hl7.fhir.core by hapifhir.
the class ValidationService method validateSources.
public ValidationResponse validateSources(ValidationRequest request) throws Exception {
if (request.getCliContext().getSv() == null) {
String sv = determineVersion(request.getCliContext(), request.sessionId);
request.getCliContext().setSv(sv);
}
String definitions = VersionUtilities.packageForVersion(request.getCliContext().getSv()) + "#" + VersionUtilities.getCurrentVersion(request.getCliContext().getSv());
String sessionId = initializeValidator(request.getCliContext(), definitions, new TimeTracker(), request.sessionId);
ValidationEngine validator = sessionCache.fetchSessionValidatorEngine(sessionId);
if (request.getCliContext().getProfiles().size() > 0) {
System.out.println(" .. validate " + request.listSourceFiles() + " against " + request.getCliContext().getProfiles().toString());
} else {
System.out.println(" .. validate " + request.listSourceFiles());
}
ValidationResponse response = new ValidationResponse().setSessionId(sessionId);
for (FileInfo fp : request.getFilesToValidate()) {
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);
}
System.out.println(" Max Memory: " + Runtime.getRuntime().maxMemory());
return response;
}
use of org.hl7.fhir.utilities.TimeTracker in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method loadCoreDefinitions.
/**
* @param src
* @param recursive
* @param terminologyCachePath
* @param userAgent
* @param tt
* @param loggingService
* @throws FHIRException
* @throws IOException
*
* @see IgLoader#loadIgSource(String, boolean, boolean) loadIgSource for detailed description of the src parameter
*/
private void loadCoreDefinitions(String src, boolean recursive, String terminologyCachePath, String userAgent, TimeTracker tt, IWorkerContext.ILoggingService loggingService) throws FHIRException, IOException {
NpmPackage npm = getPcm().loadPackage(src, null);
if (npm != null) {
version = npm.fhirVersion();
SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder().withLoggingService(loggingService);
if (terminologyCachePath != null)
contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
if (userAgent != null) {
contextBuilder.withUserAgent(userAgent);
}
context = contextBuilder.fromPackage(npm, ValidatorUtils.loaderForVersion(version));
} else {
Map<String, byte[]> source = igLoader.loadIgSource(src, recursive, true);
if (version == null) {
version = getVersionFromPack(source);
}
SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder();
if (terminologyCachePath != null)
contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
if (userAgent != null) {
contextBuilder.withUserAgent(userAgent);
}
context = contextBuilder.fromDefinitions(source, ValidatorUtils.loaderForVersion(version), new PackageVersion(src, new Date()));
ValidatorUtils.grabNatives(getBinaries(), source, "http://hl7.org/fhir");
}
// on https://chat.fhir.org/#narrow/stream/179167-hapi
try {
ClassLoader classLoader = ValidationEngine.class.getClassLoader();
InputStream ue = classLoader.getResourceAsStream("ucum-essence.xml");
context.setUcumService(new UcumEssenceService(ue));
} catch (Exception e) {
throw new FHIRException("Error loading UCUM from embedded ucum-essence.xml: " + e.getMessage(), e);
}
initContext(tt);
}
use of org.hl7.fhir.utilities.TimeTracker in project org.hl7.fhir.core by hapifhir.
the class ValidationEngine method initContext.
protected void initContext(TimeTracker tt) throws IOException {
context.setCanNoTS(true);
context.setCacheId(UUID.randomUUID().toString());
// because of Forge
context.setAllowLoadingDuplicates(true);
context.setExpansionProfile(makeExpProfile());
if (tt != null) {
context.setClock(tt);
}
NpmPackage npmX = getPcm().loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
context.loadFromPackage(npmX, null);
this.fhirPathEngine = new FHIRPathEngine(context);
}
use of org.hl7.fhir.utilities.TimeTracker in project org.hl7.fhir.core by hapifhir.
the class ValidatorCli method main.
public static void main(String[] args) throws Exception {
TimeTracker tt = new TimeTracker();
TimeTracker.Session tts = tt.start("Loading");
args = preProcessArgs(args);
Display.displayVersion();
Display.displaySystemInfo();
if (Params.hasParam(args, Params.PROXY)) {
assert Params.getParam(args, Params.PROXY) != null : "PROXY arg passed in was NULL";
String[] p = Params.getParam(args, Params.PROXY).split(":");
System.setProperty(HTTP_PROXY_HOST, p[0]);
System.setProperty(HTTP_PROXY_PORT, p[1]);
}
if (Params.hasParam(args, Params.PROXY_AUTH)) {
assert Params.getParam(args, Params.PROXY) != null : "Cannot set PROXY_AUTH without setting PROXY...";
assert Params.getParam(args, Params.PROXY_AUTH) != null : "PROXY_AUTH arg passed in was NULL...";
String[] p = Params.getParam(args, Params.PROXY_AUTH).split(":");
String authUser = p[0];
String authPass = p[1];
/*
* For authentication, use java.net.Authenticator to set proxy's configuration and set the system properties
* http.proxyUser and http.proxyPassword
*/
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(authUser, authPass.toCharArray());
}
});
System.setProperty(HTTP_PROXY_USER, authUser);
System.setProperty(HTTP_PROXY_PASS, authPass);
System.setProperty(JAVA_USE_SYSTEM_PROXIES, "true");
/*
* For Java 1.8 and higher you must set
* -Djdk.http.auth.tunneling.disabledSchemes=
* to make proxies with Basic Authorization working with https along with Authenticator
*/
System.setProperty(JAVA_DISABLED_TUNNELING_SCHEMES, "");
System.setProperty(JAVA_DISABLED_PROXY_SCHEMES, "");
}
CliContext cliContext = Params.loadCliContext(args);
if (Params.hasParam(args, Params.TEST)) {
Common.runValidationEngineTests();
} else if (shouldDisplayHelpToUser(args)) {
Display.displayHelpDetails();
} else if (Params.hasParam(args, Params.COMPARE)) {
if (destinationDirectoryValid(Params.getParam(args, Params.DESTINATION))) {
doLeftRightComparison(args, cliContext, tt);
}
} else {
Display.printCliArgumentsAndInfo(args);
doValidation(tt, tts, cliContext);
}
}
Aggregations