rework validation output + fix up package loading in validator
This commit is contained in:
parent
3fad39620b
commit
ef2ad7ce21
|
@ -90,7 +90,7 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
|
|||
// private static final String SECONDARY_SERVER = "http://local.fhir.org:960/packages";
|
||||
public static final String PACKAGE_REGEX = "^[a-z][a-z0-9\\_\\-]*(\\.[a-z0-9\\_\\-]+)+$";
|
||||
public static final String PACKAGE_VERSION_REGEX = "^[a-z][a-z0-9\\_\\-]*(\\.[a-z0-9\\_\\-]+)+\\#[a-z0-9\\-\\_]+(\\.[a-z0-9\\-\\_]+)*$";
|
||||
public static final String PACKAGE_VERSION_REGEX_OPT = "^[a-z][a-z0-9\\_\\-]*(\\.[a-z0-9\\_\\-]+)+(\\#[a-z0-9\\-\\_]+(\\.[a-z0-9\\-\\_]+)*)$";
|
||||
public static final String PACKAGE_VERSION_REGEX_OPT = "^[a-z][a-z0-9\\_\\-]*(\\.[a-z0-9\\_\\-]+)+(\\#[a-z0-9\\-\\_]+(\\.[a-z0-9\\-\\_]+)*)?$";
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(FilesystemPackageCacheManager.class);
|
||||
private static final String CACHE_VERSION = "3"; // second version - see wiki page
|
||||
private String cacheFolder;
|
||||
|
@ -862,7 +862,38 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
|
|||
}
|
||||
}
|
||||
|
||||
public boolean packageExists(String id, String ver) throws IOException {
|
||||
if (packageInstalled(id, ver)) {
|
||||
return true;
|
||||
}
|
||||
for (String s : getPackageServers()) {
|
||||
if (new PackageClient(s).exists(id, ver)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean packageInstalled(String id, String version) {
|
||||
for (NpmPackage p : temporaryPackages) {
|
||||
if (p.name().equals(id) && ("current".equals(version) || "dev".equals(version) || p.version().equals(version))) {
|
||||
return true;
|
||||
}
|
||||
if (p.name().equals(id) && Utilities.noString(version)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String f : sorted(new File(cacheFolder).list())) {
|
||||
if (f.equals(id + "#" + version) || (Utilities.noString(version) && f.startsWith(id + "#"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ("dev".equals(version))
|
||||
return packageInstalled(id, "current");
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import com.google.gson.JsonObject;
|
|||
public class PackageHacker {
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException, IOException {
|
||||
new PackageHacker().edit("M:\\web\\hl7.org\\fhir\\2020Sep\\hl7.fhir.r5.expansions.tgz");
|
||||
new PackageHacker().edit("M:\\web\\hl7.org\\fhir\\uv\\cdisc-lab\\package.tgz");
|
||||
}
|
||||
|
||||
private void edit(String name) throws FileNotFoundException, IOException {
|
||||
|
@ -57,10 +57,10 @@ public class PackageHacker {
|
|||
|
||||
private void change(JsonObject npm, Map<String, byte[]> content) throws FileNotFoundException, IOException {
|
||||
fixVersions(npm);
|
||||
// npm.remove("url");
|
||||
// npm.addProperty("url", url);
|
||||
npm.remove("version");
|
||||
npm.addProperty("version", "4.5.0");
|
||||
npm.remove("url");
|
||||
npm.addProperty("url", "http://hl7.org/fhir/uv/cdisc-lab/STU1");
|
||||
npm.remove("name");
|
||||
npm.addProperty("name", "hl7.fhir.uv.cdisc-lab");
|
||||
// npm.remove("canonical");
|
||||
// npm.addProperty("canonical", "http://hl7.org/fhir/us/davinci-drug-formulary");
|
||||
//// npm.remove("description");
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.hl7.fhir.validation.cli.services.StandAloneValidatorFetcher.IPackageI
|
|||
import org.hl7.fhir.validation.instance.InstanceValidator;
|
||||
import org.hl7.fhir.utilities.IniFile;
|
||||
import org.hl7.fhir.utilities.TextFile;
|
||||
import org.hl7.fhir.utilities.TimeTracker;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.utilities.cache.NpmPackage;
|
||||
|
@ -351,8 +352,8 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
context = SimpleWorkerContext.fromNothing();
|
||||
}
|
||||
|
||||
public void setTerminologyServer(String src, String log, FhirPublication version) throws FHIRException, URISyntaxException {
|
||||
connectToTSServer(src, log, version);
|
||||
public String setTerminologyServer(String src, String log, FhirPublication version) throws FHIRException, URISyntaxException {
|
||||
return connectToTSServer(src, log, version);
|
||||
}
|
||||
|
||||
public boolean isHintAboutNonMustSupport() {
|
||||
|
@ -382,7 +383,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
|
||||
public ValidationEngine(String src, String txsrvr, String txLog, FhirPublication version, boolean canRunWithoutTerminologyServer, String vString) throws FHIRException, IOException, URISyntaxException {
|
||||
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||
loadCoreDefinitions(src, false);
|
||||
loadCoreDefinitions(src, false, null);
|
||||
context.setCanRunWithoutTerminology(canRunWithoutTerminologyServer);
|
||||
setTerminologyServer(txsrvr, txLog, version);
|
||||
this.version = vString;
|
||||
|
@ -390,13 +391,20 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
|
||||
public ValidationEngine(String src, String txsrvr, String txLog, FhirPublication version, String vString) throws FHIRException, IOException, URISyntaxException {
|
||||
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||
loadCoreDefinitions(src, false);
|
||||
loadCoreDefinitions(src, false, null);
|
||||
setTerminologyServer(txsrvr, txLog, version);
|
||||
this.version = vString;
|
||||
}
|
||||
|
||||
public ValidationEngine(String src, FhirPublication version, String vString, TimeTracker tt) throws FHIRException, IOException, URISyntaxException {
|
||||
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||
loadCoreDefinitions(src, false, tt);
|
||||
this.version = vString;
|
||||
}
|
||||
|
||||
|
||||
public ValidationEngine(String src) throws FHIRException, IOException {
|
||||
loadCoreDefinitions(src, false);
|
||||
loadCoreDefinitions(src, false, null);
|
||||
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||
}
|
||||
|
||||
|
@ -408,7 +416,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
this.language = language;
|
||||
}
|
||||
|
||||
private void loadCoreDefinitions(String src, boolean recursive) throws FHIRException, IOException {
|
||||
private void loadCoreDefinitions(String src, boolean recursive, TimeTracker tt) throws FHIRException, IOException {
|
||||
if (pcm == null) {
|
||||
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||
}
|
||||
|
@ -427,6 +435,9 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
context.setCacheId(UUID.randomUUID().toString());
|
||||
context.setAllowLoadingDuplicates(true); // because of Forge
|
||||
context.setExpansionProfile(makeExpProfile());
|
||||
if (tt != null) {
|
||||
context.setClock(tt);
|
||||
}
|
||||
NpmPackage npmX = pcm.loadPackage("hl7.fhir.xver-extensions", "0.0.4");
|
||||
context.loadFromPackage(npmX, null);
|
||||
}
|
||||
|
@ -912,16 +923,17 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
return checkIsResource(TextFile.fileToBytes(path), path);
|
||||
}
|
||||
|
||||
public void connectToTSServer(String url, String log, FhirPublication version) throws URISyntaxException, FHIRException {
|
||||
public String connectToTSServer(String url, String log, FhirPublication version) throws URISyntaxException, FHIRException {
|
||||
context.setTlogging(false);
|
||||
if (url == null) {
|
||||
context.setCanRunWithoutTerminology(true);
|
||||
return "n/a: No Terminology Server";
|
||||
} else {
|
||||
try {
|
||||
context.connectToTSServer(TerminologyClientFactory.makeClient(url, version), log);
|
||||
return context.connectToTSServer(TerminologyClientFactory.makeClient(url, version), log);
|
||||
} catch (Exception e) {
|
||||
if (context.isCanRunWithoutTerminology()) {
|
||||
System.out.println("Running without Terminology Server (error: "+e.getMessage()+")");
|
||||
return "n/a: Running without Terminology Server (error: "+e.getMessage()+")";
|
||||
} else
|
||||
throw e;
|
||||
}
|
||||
|
@ -956,9 +968,16 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
}
|
||||
}
|
||||
}
|
||||
context.loadFromPackage(npm, loaderForVersion(npm.fhirVersion()));
|
||||
System.out.print(" Load " + src);
|
||||
if (!src.contains("#")) {
|
||||
System.out.print("#"+npm.version());
|
||||
}
|
||||
int count = context.loadFromPackage(npm, loaderForVersion(npm.fhirVersion()));
|
||||
System.out.println(" - "+count+" resources ("+context.clock().milestone()+")");
|
||||
} else {
|
||||
System.out.print(" Load " + src);
|
||||
String canonical = null;
|
||||
int count = 0;
|
||||
Map<String, byte[]> source = loadIgSource(src, recursive, true);
|
||||
String version = Constants.VERSION;
|
||||
if (this.version != null) {
|
||||
|
@ -972,6 +991,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
if (!exemptFile(fn)) {
|
||||
Resource r = loadFileWithErrorChecking(version, t, fn);
|
||||
if (r != null) {
|
||||
count++;
|
||||
context.cacheResource(r);
|
||||
if (r instanceof ImplementationGuide) {
|
||||
canonical = ((ImplementationGuide) r).getUrl();
|
||||
|
@ -988,6 +1008,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
if (canonical != null) {
|
||||
grabNatives(source, canonical);
|
||||
}
|
||||
System.out.println(" - "+count+" resources ("+context.clock().milestone()+")");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1247,22 +1268,27 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
}
|
||||
|
||||
public Resource validate(List<String> sources, List<String> profiles) throws FHIRException, IOException {
|
||||
if (profiles.size() > 0) {
|
||||
System.out.println(" Profiles: "+profiles);
|
||||
}
|
||||
List<String> refs = new ArrayList<String>();
|
||||
boolean asBundle = handleSources(sources, refs);
|
||||
Bundle results = new Bundle();
|
||||
results.setType(Bundle.BundleType.COLLECTION);
|
||||
for (String ref : refs) {
|
||||
TimeTracker.Session tts = context.clock().start("validation");
|
||||
context.clock().milestone();
|
||||
System.out.print(" Validate " + ref);
|
||||
Content cnt = loadContent(ref, "validate");
|
||||
if (refs.size() > 1)
|
||||
System.out.println("Validate "+ref);
|
||||
try {
|
||||
OperationOutcome outcome = validate(ref, cnt.focus, cnt.cntType, profiles);
|
||||
ToolingExtensions.addStringExtension(outcome, ToolingExtensions.EXT_OO_FILE, ref);
|
||||
if (refs.size() > 1)
|
||||
produceValidationSummary(outcome);
|
||||
System.out.println(" " + context.clock().milestone());
|
||||
results.addEntry().setResource(outcome);
|
||||
tts.end();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Validation Infrastructure fail validating "+ref+": "+e.getMessage());
|
||||
tts.end();
|
||||
throw new FHIRException(e);
|
||||
}
|
||||
}
|
||||
|
@ -1271,14 +1297,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
else
|
||||
return results.getEntryFirstRep().getResource();
|
||||
}
|
||||
|
||||
private void produceValidationSummary(OperationOutcome oo) {
|
||||
for (OperationOutcomeIssueComponent iss : oo.getIssue()) {
|
||||
if (iss.getSeverity() == org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity.ERROR || iss.getSeverity() == org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity.FATAL) {
|
||||
System.out.println(" "+iss.getSeverity().toCode()+": "+iss.getDetails().getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public OperationOutcome validateString(String location, String source, FhirFormat format, List<String> profiles) throws FHIRException, IOException, EOperationOutcome, SAXException {
|
||||
return validate(location, source.getBytes(), format, profiles);
|
||||
|
@ -2361,14 +2380,6 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
return TextFile.streamToBytes(c.getInputStream());
|
||||
}
|
||||
|
||||
public void doneLoading(long loadStart) {
|
||||
if (showTimes) {
|
||||
String s = String.format("Load Time (ms): %d", (System.nanoTime() - loadStart) / 1000000);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public FilesystemPackageCacheManager getPcm() {
|
||||
return pcm;
|
||||
}
|
||||
|
@ -2377,5 +2388,13 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
|
|||
return bundleValidationRules;
|
||||
}
|
||||
|
||||
public boolean packageExists(String id, String ver) throws IOException, FHIRException {
|
||||
return pcm.packageExists(id, ver);
|
||||
}
|
||||
|
||||
|
||||
public void loadPackage(String id, String ver) throws IOException, FHIRException {
|
||||
loadIg(id+(ver == null ? "" : "#"+ver), true);
|
||||
}
|
||||
|
||||
}
|
|
@ -63,6 +63,7 @@ import java.net.URI;
|
|||
|
||||
import org.hl7.fhir.r5.model.ImplementationGuide;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.utilities.TimeTracker;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.validation.ValidationEngine.VersionSourceInformation;
|
||||
|
@ -131,10 +132,11 @@ public class Validator {
|
|||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
TimeTracker tt = new TimeTracker();
|
||||
TimeTracker.Session tts = tt.start("Loading");
|
||||
|
||||
long loadStart = System.nanoTime();
|
||||
System.out.println("FHIR Validation tool " + VersionUtil.getVersionString());
|
||||
System.out.println("Detected Java version: " + System.getProperty("java.version") + " from " + System.getProperty("java.home") + " on " + System.getProperty("os.arch") + " (" + System.getProperty("sun.arch.data.model") + "bit). " + toMB(Runtime.getRuntime().maxMemory()) + "MB available");
|
||||
System.out.println(" Java: " + System.getProperty("java.version") + " from " + System.getProperty("java.home") + " on " + System.getProperty("os.arch") + " (" + System.getProperty("sun.arch.data.model") + "bit). " + toMB(Runtime.getRuntime().maxMemory()) + "MB available");
|
||||
String proxy = getNamedParam(args, Params.PROXY);
|
||||
if (!Utilities.noString(proxy)) {
|
||||
String[] p = proxy.split("\\:");
|
||||
|
@ -146,7 +148,7 @@ public class Validator {
|
|||
cliContext = Params.loadCliContext(args);
|
||||
String v = Common.getVersion(args);
|
||||
String definitions = VersionUtilities.packageForVersion(v) + "#" + v;
|
||||
ValidationEngine validationEngine = Common.getValidationEngine(v, definitions, cliContext.getTxLog());
|
||||
ValidationEngine validationEngine = Common.getValidationEngine(v, definitions, cliContext.getTxLog(), null);
|
||||
ValidatorGui.start(cliContext, validationEngine, true);
|
||||
} else if (Params.hasParam(args, Params.TEST)) {
|
||||
Common.runValidationEngineTests();
|
||||
|
@ -167,7 +169,7 @@ public class Validator {
|
|||
}
|
||||
String v = VersionUtilities.getCurrentVersion(cliContext.getSv());
|
||||
String definitions = VersionUtilities.packageForVersion(v) + "#" + v;
|
||||
ValidationEngine validator = ValidationService.getValidator(cliContext, definitions);
|
||||
ValidationEngine validator = ValidationService.getValidator(cliContext, definitions, tt);
|
||||
ComparisonService.doLeftRightComparison(args, dest, validator);
|
||||
}
|
||||
} else {
|
||||
|
@ -178,9 +180,11 @@ public class Validator {
|
|||
cliContext.setSv(determineVersion(cliContext));
|
||||
}
|
||||
|
||||
System.out.println("Loading");
|
||||
// Comment this out because definitions filename doesn't necessarily contain version (and many not even be 14 characters long). Version gets spit out a couple of lines later after we've loaded the context
|
||||
String definitions = VersionUtilities.packageForVersion(cliContext.getSv()) + "#" + VersionUtilities.getCurrentVersion(cliContext.getSv());
|
||||
ValidationEngine validator = ValidationService.getValidator(cliContext, definitions);
|
||||
ValidationEngine validator = ValidationService.getValidator(cliContext, definitions, tt);
|
||||
tts.end();
|
||||
if (cliContext.getMode() == EngineMode.VERSION) {
|
||||
|
||||
ValidationService.transformVersion(cliContext, validator);
|
||||
|
@ -194,22 +198,21 @@ public class Validator {
|
|||
ValidationService.convertSources(cliContext, validator);
|
||||
} else if (cliContext.getMode() == EngineMode.FHIRPATH) {
|
||||
ValidationService.evaluateFhirpath(cliContext, validator);
|
||||
} else {
|
||||
if (definitions == null) {
|
||||
throw new Exception("Must provide a defn when doing validation");
|
||||
}
|
||||
} else {
|
||||
for (String s : cliContext.getProfiles()) {
|
||||
if (!validator.getContext().hasResource(StructureDefinition.class, s) && !validator.getContext().hasResource(ImplementationGuide.class, s)) {
|
||||
System.out.println("Fetch Profile from " + s);
|
||||
System.out.println(" Fetch Profile from " + s);
|
||||
validator.loadProfile(cliContext.getLocations().getOrDefault(s, s));
|
||||
}
|
||||
}
|
||||
System.out.println("Validating");
|
||||
if (cliContext.getMode() == EngineMode.SCAN) {
|
||||
ValidationService.validateScan(cliContext, validator);
|
||||
} else {
|
||||
ValidationService.validateSources(cliContext, validator, loadStart);
|
||||
ValidationService.validateSources(cliContext, validator);
|
||||
}
|
||||
}
|
||||
System.out.println("Done. "+tt.report());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ValidatorGui {
|
|||
CliContext cliContext = new CliContext();
|
||||
String v = Common.getVersion(args);
|
||||
String definitions = VersionUtilities.packageForVersion(v) + "#" + v;
|
||||
ValidationEngine validationEngine = Common.getValidationEngine(v, definitions, cliContext.getTxLog());
|
||||
ValidationEngine validationEngine = Common.getValidationEngine(v, definitions, cliContext.getTxLog(), null);
|
||||
start(new CliContext(), validationEngine, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ import org.hl7.fhir.validation.cli.services.StandAloneValidatorFetcher.IPackageI
|
|||
public class StandAloneValidatorFetcher implements IValidatorResourceFetcher {
|
||||
|
||||
public interface IPackageInstaller {
|
||||
public void loadIg(String src, boolean recursive) throws IOException, FHIRException;
|
||||
public boolean packageExists(String id, String ver) throws IOException, FHIRException;
|
||||
public void loadPackage(String id, String ver) throws IOException, FHIRException;
|
||||
}
|
||||
|
||||
private BasePackageCacheManager pcm;
|
||||
|
@ -63,13 +64,13 @@ public class StandAloneValidatorFetcher implements IValidatorResourceFetcher {
|
|||
// ok maybe it's a reference to a package we know
|
||||
String base = findBaseUrl(url);
|
||||
String pid = pcm.getPackageId(base);
|
||||
if (url.contains("|")) {
|
||||
pid = pid+"#"+url.substring(url.indexOf("|")+1);
|
||||
}
|
||||
String ver = url.contains("|") ? url.substring(url.indexOf("|")+1) : null;
|
||||
if (pid != null) {
|
||||
installer.loadIg(pid, false);
|
||||
NpmPackage pi = pcm.loadPackage(pid);
|
||||
return pi.hasCanonical(url);
|
||||
if (installer.packageExists(pid, ver)) {
|
||||
installer.loadPackage(pid, ver);
|
||||
NpmPackage pi = pcm.loadPackage(pid);
|
||||
return pi.hasCanonical(url);
|
||||
}
|
||||
}
|
||||
|
||||
if (!url.startsWith("http://hl7.org/fhir")) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.hl7.fhir.r5.model.*;
|
|||
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
|
||||
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.validation.ValidationEngine;
|
||||
import org.hl7.fhir.validation.ValidationEngine.VersionSourceInformation;
|
||||
|
@ -36,7 +37,6 @@ public class ValidationService {
|
|||
} else {
|
||||
System.out.println(" .. validate " + request.listSourceFiles());
|
||||
}
|
||||
validator.prepare(); // generate any missing snapshots
|
||||
|
||||
ValidationResponse response = new ValidationResponse();
|
||||
for (FileInfo fp : request.getFilesToValidate()) {
|
||||
|
@ -62,22 +62,19 @@ public class ValidationService {
|
|||
ve.scanForVersions(cliContext.getSources(), versions);
|
||||
return versions;
|
||||
}
|
||||
public static void validateSources(CliContext cliContext, ValidationEngine validator, long loadStart) throws Exception {
|
||||
validator.doneLoading(loadStart);
|
||||
if (cliContext.getProfiles().size() > 0) {
|
||||
System.out.println(" .. validate " + cliContext.getSources() + " against " + cliContext.getProfiles().toString());
|
||||
} else {
|
||||
System.out.println(" .. validate " + cliContext.getSources());
|
||||
}
|
||||
validator.prepare(); // generate any missing snapshots
|
||||
|
||||
public static void validateSources(CliContext cliContext, ValidationEngine validator) throws Exception {
|
||||
Resource r = validator.validate(cliContext.getSources(), cliContext.getProfiles());
|
||||
int ec = 0;
|
||||
System.out.println("Done. "+validator.getContext().clock().report());
|
||||
System.out.println();
|
||||
|
||||
if (cliContext.getOutput() == null) {
|
||||
if (r instanceof Bundle)
|
||||
for (Bundle.BundleEntryComponent e : ((Bundle) r).getEntry())
|
||||
ec = displayOperationOutcome((OperationOutcome) e.getResource()) + ec;
|
||||
ec = ec + displayOperationOutcome((OperationOutcome) e.getResource(), ((Bundle) r).getEntry().size() > 1) + ec;
|
||||
else
|
||||
ec = displayOperationOutcome((OperationOutcome) r);
|
||||
ec = displayOperationOutcome((OperationOutcome) r, false);
|
||||
} else {
|
||||
IParser x;
|
||||
if (cliContext.getOutput() != null && cliContext.getOutput().endsWith(".json")) {
|
||||
|
@ -193,16 +190,20 @@ public class ValidationService {
|
|||
}
|
||||
}
|
||||
|
||||
public static ValidationEngine getValidator(CliContext cliContext, String definitions) throws Exception {
|
||||
System.out.println(" .. FHIR Version " + cliContext.getSv() + ", definitions from " + definitions);
|
||||
System.out.println(" .. connect to tx server @ " + cliContext.getTxServer());
|
||||
ValidationEngine validator = new ValidationEngine(definitions, cliContext.getTxServer(), cliContext.getTxLog(), FhirPublication.fromCode(cliContext.getSv()), cliContext.getSv());
|
||||
public static ValidationEngine getValidator(CliContext cliContext, String definitions, TimeTracker tt) throws Exception {
|
||||
tt.milestone();
|
||||
System.out.print(" Load FHIR v" + cliContext.getSv() + " from " + definitions);
|
||||
FhirPublication ver = FhirPublication.fromCode(cliContext.getSv());
|
||||
ValidationEngine validator = new ValidationEngine(definitions, ver, cliContext.getSv(), tt);
|
||||
System.out.println(" - "+validator.getContext().countAllCaches()+" resources ("+tt.milestone()+")");
|
||||
System.out.print(" Terminology server " + cliContext.getTxServer());
|
||||
String txver = validator.setTerminologyServer(cliContext.getTxServer(), cliContext.getTxLog(), ver);
|
||||
System.out.println(" - Version "+txver+" ("+tt.milestone()+")");
|
||||
validator.setDebug(cliContext.isDoDebug());
|
||||
System.out.println(" (v" + validator.getContext().getVersion() + ")");
|
||||
for (String src : cliContext.getIgs()) {
|
||||
System.out.println("+ .. load IG from " + src);
|
||||
validator.loadIg(src, cliContext.isRecursive());
|
||||
}
|
||||
System.out.print(" Get set... ");
|
||||
validator.setQuestionnaires(cliContext.getQuestionnaires());
|
||||
validator.setNative(cliContext.isDoNative());
|
||||
validator.setHintAboutNonMustSupport(cliContext.isHintAboutNonMustSupport());
|
||||
|
@ -218,10 +219,13 @@ public class ValidationService {
|
|||
validator.setFetcher(new StandAloneValidatorFetcher(validator.getPcm(), validator.getContext(), validator));
|
||||
validator.getBundleValidationRules().addAll(cliContext.getBundleValidationRules());
|
||||
TerminologyCache.setNoCaching(cliContext.isNoInternalCaching());
|
||||
validator.prepare(); // generate any missing snapshots
|
||||
System.out.println(" go ("+tt.milestone()+")");
|
||||
|
||||
return validator;
|
||||
}
|
||||
|
||||
public static int displayOperationOutcome(OperationOutcome oo) {
|
||||
public static int displayOperationOutcome(OperationOutcome oo, boolean hasMultiples) {
|
||||
int error = 0;
|
||||
int warn = 0;
|
||||
int info = 0;
|
||||
|
@ -235,12 +239,24 @@ public class ValidationService {
|
|||
else
|
||||
info++;
|
||||
}
|
||||
|
||||
System.out.println((error == 0 ? "Success..." : "*FAILURE* ") + "validating " + file + ": " + " error:" + Integer.toString(error) + " warn:" + Integer.toString(warn) + " info:" + Integer.toString(info));
|
||||
|
||||
if (hasMultiples) {
|
||||
System.out.print("-- ");
|
||||
System.out.print(file);
|
||||
System.out.print(" --");
|
||||
System.out.println(Utilities.padLeft("", '-', Integer.max(38, file.length()+6)));
|
||||
}
|
||||
System.out.println((error == 0 ? "Success" : "*FAILURE*") + ": " + Integer.toString(error) + " errors, " + Integer.toString(warn) + " warnings, " + Integer.toString(info)+" notes");
|
||||
for (OperationOutcome.OperationOutcomeIssueComponent issue : oo.getIssue()) {
|
||||
System.out.println(getIssueSummary(issue));
|
||||
}
|
||||
System.out.println();
|
||||
if (hasMultiples) {
|
||||
System.out.print("---");
|
||||
System.out.print(Utilities.padLeft("", '-', file.length()));
|
||||
System.out.print("---");
|
||||
System.out.println(Utilities.padLeft("", '-', Integer.max(38, file.length()+6)));
|
||||
System.out.println();
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.hl7.fhir.validation.cli.utils;
|
|||
|
||||
import org.hl7.fhir.r5.model.Constants;
|
||||
import org.hl7.fhir.r5.model.FhirPublication;
|
||||
import org.hl7.fhir.utilities.TimeTracker;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.validation.ValidationEngine;
|
||||
|
||||
|
@ -80,13 +81,15 @@ public class Common {
|
|||
/**
|
||||
* Default validation engine will point to "http://tx.fhir.org" terminology server.
|
||||
*/
|
||||
public static ValidationEngine getValidationEngine(String version, String definitions, String txLog) throws Exception {
|
||||
return getValidationEngine(version, DEFAULT_TX_SERVER, definitions, txLog);
|
||||
public static ValidationEngine getValidationEngine(String version, String definitions, String txLog, TimeTracker tt) throws Exception {
|
||||
return getValidationEngine(version, DEFAULT_TX_SERVER, definitions, txLog, tt);
|
||||
}
|
||||
|
||||
public static ValidationEngine getValidationEngine(String version, String txServer, String definitions, String txLog) throws Exception {
|
||||
public static ValidationEngine getValidationEngine(String version, String txServer, String definitions, String txLog, TimeTracker tt) throws Exception {
|
||||
System.out.println("Loading (v = " + version + ", tx server -> " + txServer + ")");
|
||||
return new ValidationEngine(definitions, txServer, txLog, FhirPublication.fromCode(version), version);
|
||||
ValidationEngine ve = new ValidationEngine(definitions, FhirPublication.fromCode(version), version, tt);
|
||||
ve.connectToTSServer(txServer, txLog, FhirPublication.fromCode(version));
|
||||
return ve;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,12 +15,12 @@ import java.io.IOException;
|
|||
public class Display {
|
||||
|
||||
public static void printCliArgumentsAndInfo(String[] args) throws IOException {
|
||||
System.out.print("Arguments:");
|
||||
System.out.println(" Paths: Current = " + System.getProperty("user.dir") + ", Package Cache = " + new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).getFolder());
|
||||
System.out.print(" Params:");
|
||||
for (String s : args) {
|
||||
System.out.print(s.contains(" ") ? " \"" + s + "\"" : " " + s);
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println("Directories: Current = " + System.getProperty("user.dir") + ", Package Cache = " + new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).getFolder());
|
||||
}
|
||||
|
||||
public static void displayHelpDetails() {
|
||||
|
|
|
@ -4,16 +4,21 @@ import org.hl7.fhir.r5.elementmodel.Element;
|
|||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
public class ValidatorHostContext {
|
||||
|
||||
private Object appContext;
|
||||
private Element container; // bundle, or parameters
|
||||
private Element resource;
|
||||
|
||||
// the resource we are actually validating right now
|
||||
private Element resource;
|
||||
// the resource that is the scope of id resolution - either the same as resource, or the resource the contains that resource. This can only be one level deep.
|
||||
private Element rootResource;
|
||||
|
||||
private StructureDefinition profile; // the profile that contains the content being validated
|
||||
private boolean checkSpecials = true;
|
||||
private Map<String, List<ValidationMessage>> sliceRecords;
|
||||
|
@ -26,6 +31,7 @@ public class ValidatorHostContext {
|
|||
this.appContext = appContext;
|
||||
this.resource = element;
|
||||
this.rootResource = element;
|
||||
// no container
|
||||
}
|
||||
|
||||
public Object getAppContext() {
|
||||
|
@ -37,15 +43,6 @@ public class ValidatorHostContext {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Element getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
public ValidatorHostContext setContainer(Element container) {
|
||||
this.container = container;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ValidatorHostContext setResource(Element resource) {
|
||||
this.resource = resource;
|
||||
return this;
|
||||
|
@ -98,7 +95,6 @@ public class ValidatorHostContext {
|
|||
ValidatorHostContext res = new ValidatorHostContext(appContext);
|
||||
res.rootResource = resource;
|
||||
res.resource = element;
|
||||
res.container = resource;
|
||||
res.profile = profile;
|
||||
return res;
|
||||
}
|
||||
|
@ -107,7 +103,6 @@ public class ValidatorHostContext {
|
|||
ValidatorHostContext res = new ValidatorHostContext(appContext);
|
||||
res.rootResource = element;
|
||||
res.resource = element;
|
||||
res.container = resource;
|
||||
res.profile = profile;
|
||||
return res;
|
||||
}
|
||||
|
@ -116,7 +111,6 @@ public class ValidatorHostContext {
|
|||
ValidatorHostContext res = new ValidatorHostContext(appContext);
|
||||
res.resource = resource;
|
||||
res.rootResource = rootResource;
|
||||
res.container = container;
|
||||
res.profile = profile;
|
||||
res.sliceRecords = sliceRecords != null ? sliceRecords : new HashMap<String, List<ValidationMessage>>();
|
||||
return res;
|
||||
|
@ -126,7 +120,6 @@ public class ValidatorHostContext {
|
|||
ValidatorHostContext res = new ValidatorHostContext(appContext);
|
||||
res.resource = resource;
|
||||
res.rootResource = resource;
|
||||
res.container = container;
|
||||
res.profile = profile;
|
||||
res.checkSpecials = false;
|
||||
return res;
|
||||
|
@ -136,7 +129,6 @@ public class ValidatorHostContext {
|
|||
ValidatorHostContext res = new ValidatorHostContext(appContext);
|
||||
res.resource = resource;
|
||||
res.rootResource = resource;
|
||||
res.container = resource;
|
||||
res.profile = profile;
|
||||
res.checkSpecials = false;
|
||||
return res;
|
||||
|
@ -146,7 +138,6 @@ public class ValidatorHostContext {
|
|||
ValidatorHostContext res = new ValidatorHostContext(appContext);
|
||||
res.resource = resource;
|
||||
res.rootResource = resource;
|
||||
res.container = resource;
|
||||
res.profile = profile;
|
||||
res.checkSpecials = false;
|
||||
res.sliceRecords = new HashMap<String, List<ValidationMessage>>();
|
||||
|
|
Loading…
Reference in New Issue