rework version loading when validating
This commit is contained in:
parent
3524b16172
commit
1d193e7c87
|
@ -192,6 +192,19 @@ public class TextFile {
|
||||||
return streamToBytes(new FileInputStream(new CSFile(srcFile)));
|
return streamToBytes(new FileInputStream(new CSFile(srcFile)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* fileToBytes insists in case correctness to ensure that stuff works across linux and windows, but it's not always appropriate to ceheck case (e.g. validator parameters)
|
||||||
|
*
|
||||||
|
* @param srcFile
|
||||||
|
* @return
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static byte[] fileToBytesNCS(String srcFile) throws FileNotFoundException, IOException {
|
||||||
|
return streamToBytes(new FileInputStream(new File(srcFile)));
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] fileToBytes(File file) throws FileNotFoundException, IOException {
|
public static byte[] fileToBytes(File file) throws FileNotFoundException, IOException {
|
||||||
return streamToBytes(new FileInputStream(file));
|
return streamToBytes(new FileInputStream(file));
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ public class VersionUtilities {
|
||||||
if (isR4Ver(v)) {
|
if (isR4Ver(v)) {
|
||||||
return "hl7.fhir.r4.core";
|
return "hl7.fhir.r4.core";
|
||||||
}
|
}
|
||||||
|
if ("current".equals(v)) {
|
||||||
|
return "hl7.fhir.r5.core";
|
||||||
|
}
|
||||||
if (v != null && v.startsWith(CURRENT_VERSION)) {
|
if (v != null && v.startsWith(CURRENT_VERSION)) {
|
||||||
return "hl7.fhir.r5.core";
|
return "hl7.fhir.r5.core";
|
||||||
}
|
}
|
||||||
|
@ -59,10 +62,30 @@ public class VersionUtilities {
|
||||||
return "4.0.1";
|
return "4.0.1";
|
||||||
}
|
}
|
||||||
if (v != null && v.startsWith(CURRENT_VERSION)) {
|
if (v != null && v.startsWith(CURRENT_VERSION)) {
|
||||||
return "Constants.VERSION";
|
return "current";
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getCurrentPackageVersion(String v) {
|
||||||
|
if (isR2Ver(v)) {
|
||||||
|
return "1.0";
|
||||||
|
}
|
||||||
|
if (isR2BVer(v)) {
|
||||||
|
return "1.4";
|
||||||
|
}
|
||||||
|
if (isR3Ver(v)) {
|
||||||
|
return "3.0";
|
||||||
|
}
|
||||||
|
if (isR4Ver(v)) {
|
||||||
|
return "4.0";
|
||||||
|
}
|
||||||
|
if (v != null && v.startsWith(CURRENT_VERSION)) {
|
||||||
|
return "current";
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isSupportedVersion(String version) {
|
public static boolean isSupportedVersion(String version) {
|
||||||
return Utilities.existsInList(version, "1.0.2", "1.4.0", "3.0.2", "4.0.1", CURRENT_FULL_VERSION);
|
return Utilities.existsInList(version, "1.0.2", "1.4.0", "3.0.2", "4.0.1", CURRENT_FULL_VERSION);
|
||||||
}
|
}
|
||||||
|
|
|
@ -516,7 +516,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||||
FhirFormat fmt = checkIsResource(src);
|
FhirFormat fmt = checkIsResource(src);
|
||||||
if (fmt != null) {
|
if (fmt != null) {
|
||||||
Map<String, byte[]> res = new HashMap<String, byte[]>();
|
Map<String, byte[]> res = new HashMap<String, byte[]>();
|
||||||
res.put(Utilities.changeFileExt(src, "."+fmt.getExtension()), TextFile.fileToBytes(src));
|
res.put(Utilities.changeFileExt(src, "."+fmt.getExtension()), TextFile.fileToBytesNCS(src));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} else if ((src.matches(PackageCacheManager.PACKAGE_REGEX) || src.matches(PackageCacheManager.PACKAGE_VERSION_REGEX)) && !src.endsWith(".zip") && !src.endsWith(".tgz")) {
|
} else if ((src.matches(PackageCacheManager.PACKAGE_REGEX) || src.matches(PackageCacheManager.PACKAGE_VERSION_REGEX)) && !src.endsWith(".zip") && !src.endsWith(".tgz")) {
|
||||||
|
@ -1586,7 +1586,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||||
return true; // we don't bother with those.
|
return true; // we don't bother with those.
|
||||||
if (context.fetchResource(Resource.class, url) != null)
|
if (context.fetchResource(Resource.class, url) != null)
|
||||||
return true;
|
return true;
|
||||||
throw new Error("Not done yet - resolve "+url);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,13 +261,42 @@ public class Validator {
|
||||||
else {
|
else {
|
||||||
// first, prepare the context
|
// first, prepare the context
|
||||||
String v = getParam(args, "-version");
|
String v = getParam(args, "-version");
|
||||||
if (v == null) v = Constants.VERSION;
|
if (v == null) {
|
||||||
else if ("1.0".equals(v)) v = "1.0.2";
|
v = "current";
|
||||||
else if ("1.4".equals(v)) v = "1.4.0";
|
for (int i = 0; i < args.length; i++) {
|
||||||
else if ("3.0".equals(v)) v = "3.0.2";
|
if ("-ig".equals(args[i])) {
|
||||||
else if ("4.0".equals(v)) v = "4.0.1";
|
if (i+1 == args.length)
|
||||||
else if (v.startsWith(Constants.VERSION)) v = Constants.VERSION;
|
throw new Error("Specified -ig without indicating ig file");
|
||||||
String definitions = "hl7.fhir.core#"+v;
|
else {
|
||||||
|
String n = args[i+1];
|
||||||
|
if (n.startsWith("hl7.fhir.core#")) {
|
||||||
|
v = VersionUtilities.getCurrentPackageVersion(n.substring(14));
|
||||||
|
} else if (n.startsWith("hl7.fhir.r2.core#") || n.equals("hl7.fhir.r2.core")) {
|
||||||
|
v = "1.0";
|
||||||
|
} else if (n.startsWith("hl7.fhir.r2b.core#") || n.equals("hl7.fhir.r2b.core")) {
|
||||||
|
v = "1.4";
|
||||||
|
} else if (n.startsWith("hl7.fhir.r3.core#") || n.equals("hl7.fhir.r3.core")) {
|
||||||
|
v = "3.0";
|
||||||
|
} else if (n.startsWith("hl7.fhir.r4.core#") || n.equals("hl7.fhir.r4.core")) {
|
||||||
|
v = "4.0";
|
||||||
|
} else if (n.startsWith("hl7.fhir.r5.core#") || n.equals("hl7.fhir.r5.core")) {
|
||||||
|
v = "current";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ("1.0".equals(v)) {
|
||||||
|
v = "1.0";
|
||||||
|
} else if ("1.4".equals(v)) {
|
||||||
|
v = "1.4";
|
||||||
|
} else if ("3.0".equals(v)) {
|
||||||
|
v = "3.0";
|
||||||
|
} else if ("4.0".equals(v)) {
|
||||||
|
v = "4.0";
|
||||||
|
} else if (v.startsWith(Constants.VERSION)) {
|
||||||
|
v = "current";
|
||||||
|
}
|
||||||
|
String definitions = VersionUtilities.packageForVersion(v)+"#"+v;
|
||||||
System.out.println("Loading (v = "+v+", tx server http://tx.fhir.org)");
|
System.out.println("Loading (v = "+v+", tx server http://tx.fhir.org)");
|
||||||
ValidationEngine validator = new ValidationEngine(definitions, "http://tx.fhir.org", null, FhirPublication.fromCode(v));
|
ValidationEngine validator = new ValidationEngine(definitions, "http://tx.fhir.org", null, FhirPublication.fromCode(v));
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
@ -344,7 +373,6 @@ public class Validator {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("Directories: Current = "+System.getProperty("user.dir")+", Package Cache = "+PackageCacheManager.userDir());
|
System.out.println("Directories: Current = "+System.getProperty("user.dir")+", Package Cache = "+PackageCacheManager.userDir());
|
||||||
|
|
||||||
String definitions = "hl7.fhir.core#current";
|
|
||||||
String map = null;
|
String map = null;
|
||||||
List<String> igs = new ArrayList<String>();
|
List<String> igs = new ArrayList<String>();
|
||||||
List<String> questionnaires = new ArrayList<String>();
|
List<String> questionnaires = new ArrayList<String>();
|
||||||
|
@ -358,7 +386,7 @@ public class Validator {
|
||||||
String output = null;
|
String output = null;
|
||||||
List<String> sources= new ArrayList<String>();
|
List<String> sources= new ArrayList<String>();
|
||||||
Map<String, String> locations = new HashMap<String, String>();
|
Map<String, String> locations = new HashMap<String, String>();
|
||||||
String sv = null;
|
String sv = "current";
|
||||||
String txLog = null;
|
String txLog = null;
|
||||||
String mapLog = null;
|
String mapLog = null;
|
||||||
String lang = null;
|
String lang = null;
|
||||||
|
@ -366,39 +394,15 @@ public class Validator {
|
||||||
|
|
||||||
// load the parameters - so order doesn't matter
|
// load the parameters - so order doesn't matter
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if (args[i].equals("-defn"))
|
if (args[i].equals("-version")) {
|
||||||
if (i+1 == args.length)
|
|
||||||
throw new Error("Specified -defn without indicating definition file");
|
|
||||||
else
|
|
||||||
definitions = args[++i];
|
|
||||||
else if (args[i].equals("-version")) {
|
|
||||||
sv = args[++i];
|
sv = args[++i];
|
||||||
if (sv.startsWith("1.0")) {
|
sv = VersionUtilities.getCurrentPackageVersion(sv);
|
||||||
sv = "1.0.2";
|
} else if (args[i].equals("-output")) {
|
||||||
definitions = "hl7.fhir.r2.core#"+sv;
|
|
||||||
}
|
|
||||||
if (sv.startsWith("1.4")) {
|
|
||||||
sv = "1.4.0";
|
|
||||||
definitions = "hl7.fhir.r2b.core#"+sv;
|
|
||||||
}
|
|
||||||
if (sv.startsWith("3.0")) {
|
|
||||||
sv = "3.0.2";
|
|
||||||
definitions = "hl7.fhir.r3.core#"+sv;
|
|
||||||
}
|
|
||||||
if (sv.startsWith("4.0")) {
|
|
||||||
sv = "4.0.1";
|
|
||||||
definitions = "hl7.fhir.r4.core#"+sv;
|
|
||||||
}
|
|
||||||
if (sv.startsWith(Constants.VERSION)) {
|
|
||||||
sv = Constants.VERSION;
|
|
||||||
definitions = "hl7.fhir.r5.core#"+sv;
|
|
||||||
}
|
|
||||||
} else if (args[i].equals("-output"))
|
|
||||||
if (i+1 == args.length)
|
if (i+1 == args.length)
|
||||||
throw new Error("Specified -output without indicating output file");
|
throw new Error("Specified -output without indicating output file");
|
||||||
else
|
else
|
||||||
output = args[++i];
|
output = args[++i];
|
||||||
else if (args[i].equals("-profile")) {
|
} else if (args[i].equals("-profile")) {
|
||||||
String p = null;
|
String p = null;
|
||||||
if (i+1 == args.length)
|
if (i+1 == args.length)
|
||||||
throw new Error("Specified -profile without indicating profile source");
|
throw new Error("Specified -profile without indicating profile source");
|
||||||
|
@ -413,79 +417,95 @@ public class Validator {
|
||||||
else
|
else
|
||||||
locations.put(p, args[++i]);
|
locations.put(p, args[++i]);
|
||||||
}
|
}
|
||||||
} else if (args[i].equals("-questionnaire"))
|
} else if (args[i].equals("-questionnaire")) {
|
||||||
if (i+1 == args.length)
|
if (i+1 == args.length)
|
||||||
throw new Error("Specified -questionnaire without indicating questionnaire file");
|
throw new Error("Specified -questionnaire without indicating questionnaire file");
|
||||||
else
|
else
|
||||||
questionnaires.add(args[++i]);
|
questionnaires.add(args[++i]);
|
||||||
else if (args[i].equals("-native"))
|
} else if (args[i].equals("-native")) {
|
||||||
doNative = true;
|
doNative = true;
|
||||||
else if (args[i].equals("-debug"))
|
} else if (args[i].equals("-debug")) {
|
||||||
doDebug = true;
|
doDebug = true;
|
||||||
else if (args[i].equals("-recurse"))
|
} else if (args[i].equals("-recurse")) {
|
||||||
recursive = true;
|
recursive = true;
|
||||||
else if (args[i].equals("-strictExtensions"))
|
} else if (args[i].equals("-strictExtensions")) {
|
||||||
anyExtensionsAllowed = false;
|
anyExtensionsAllowed = false;
|
||||||
else if (args[i].equals("-hintAboutNonMustSupport"))
|
} else if (args[i].equals("-hintAboutNonMustSupport")) {
|
||||||
hintAboutNonMustSupport = true;
|
hintAboutNonMustSupport = true;
|
||||||
else if (args[i].equals("-transform")) {
|
} else if (args[i].equals("-transform")) {
|
||||||
map = args[++i];
|
map = args[++i];
|
||||||
mode = EngineMode.TRANSFORM;
|
mode = EngineMode.TRANSFORM;
|
||||||
} else if (args[i].equals("-narrative"))
|
} else if (args[i].equals("-narrative")) {
|
||||||
mode = EngineMode.NARRATIVE;
|
mode = EngineMode.NARRATIVE;
|
||||||
else if (args[i].equals("-snapshot"))
|
} else if (args[i].equals("-snapshot")) {
|
||||||
mode = EngineMode.SNAPSHOT;
|
mode = EngineMode.SNAPSHOT;
|
||||||
else if (args[i].equals("-scan"))
|
} else if (args[i].equals("-scan")) {
|
||||||
mode = EngineMode.SCAN;
|
mode = EngineMode.SCAN;
|
||||||
else if (args[i].equals("-tx"))
|
} else if (args[i].equals("-tx")) {
|
||||||
if (i+1 == args.length)
|
if (i+1 == args.length)
|
||||||
throw new Error("Specified -tx without indicating terminology server");
|
throw new Error("Specified -tx without indicating terminology server");
|
||||||
else
|
else
|
||||||
txServer = "n/a".equals(args[++i]) ? null : args[i];
|
txServer = "n/a".equals(args[++i]) ? null : args[i];
|
||||||
else if (args[i].equals("-txLog"))
|
} else if (args[i].equals("-txLog")) {
|
||||||
if (i+1 == args.length)
|
if (i+1 == args.length)
|
||||||
throw new Error("Specified -txLog without indicating file");
|
throw new Error("Specified -txLog without indicating file");
|
||||||
else
|
else
|
||||||
txLog = args[++i];
|
txLog = args[++i];
|
||||||
else if (args[i].equals("-log"))
|
} else if (args[i].equals("-log")) {
|
||||||
if (i+1 == args.length)
|
if (i+1 == args.length)
|
||||||
throw new Error("Specified -log without indicating file");
|
throw new Error("Specified -log without indicating file");
|
||||||
else
|
else
|
||||||
mapLog = args[++i];
|
mapLog = args[++i];
|
||||||
else if (args[i].equals("-language"))
|
} else if (args[i].equals("-language")) {
|
||||||
if (i+1 == args.length)
|
if (i+1 == args.length)
|
||||||
throw new Error("Specified -language without indicating language");
|
throw new Error("Specified -language without indicating language");
|
||||||
else
|
else
|
||||||
lang = args[++i];
|
lang = args[++i];
|
||||||
else if (args[i].equals("-ig"))
|
} else if (args[i].equals("-ig") || args[i].equals("-defn")) {
|
||||||
if (i+1 == args.length)
|
if (i+1 == args.length)
|
||||||
throw new Error("Specified -ig without indicating ig file");
|
throw new Error("Specified "+args[i]+" without indicating ig file");
|
||||||
else {
|
else {
|
||||||
String s = args[++i];
|
String s = args[++i];
|
||||||
if (s.startsWith("hl7.fhir.core-"))
|
if (s.equals("hl7.fhir.core")) {
|
||||||
definitions = s;
|
sv = "current";
|
||||||
|
} else if (s.startsWith("hl7.fhir.core#")) {
|
||||||
|
sv = VersionUtilities.getCurrentPackageVersion(s.substring(14));
|
||||||
|
} else if (s.startsWith("hl7.fhir.r2.core#") || s.equals("hl7.fhir.r2.core")) {
|
||||||
|
sv = "1.0";
|
||||||
|
} else if (s.startsWith("hl7.fhir.r2b.core#") || s.equals("hl7.fhir.r2b.core")) {
|
||||||
|
sv = "1.4";
|
||||||
|
} else if (s.startsWith("hl7.fhir.r3.core#") || s.equals("hl7.fhir.r3.core")) {
|
||||||
|
sv = "3.0";
|
||||||
|
} else if (s.startsWith("hl7.fhir.r4.core#") || s.equals("hl7.fhir.r4.core")) {
|
||||||
|
sv = "4.0";
|
||||||
|
} else if (s.startsWith("hl7.fhir.r5.core#") || s.equals("hl7.fhir.r5.core")) {
|
||||||
|
sv = "current";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
igs.add(s);
|
igs.add(s);
|
||||||
}
|
}
|
||||||
else if (args[i].equals("-map"))
|
} else if (args[i].equals("-map")) {
|
||||||
if (map == null)
|
if (map == null) {
|
||||||
if (i+1 == args.length)
|
if (i+1 == args.length)
|
||||||
throw new Error("Specified -map without indicating map file");
|
throw new Error("Specified -map without indicating map file");
|
||||||
else
|
else
|
||||||
map = args[++i];
|
map = args[++i];
|
||||||
else
|
} else {
|
||||||
throw new Exception("Can only nominate a single -map parameter");
|
throw new Exception("Can only nominate a single -map parameter");
|
||||||
else if (args[i].startsWith("-x"))
|
}
|
||||||
|
} else if (args[i].startsWith("-x")) {
|
||||||
i++;
|
i++;
|
||||||
else
|
} else {
|
||||||
sources.add(args[i]);
|
sources.add(args[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (sources.isEmpty())
|
if (sources.isEmpty())
|
||||||
throw new Exception("Must provide at least one source file");
|
throw new Exception("Must provide at least one source file");
|
||||||
|
|
||||||
// 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
|
// 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(sv)+"#"+VersionUtilities.getCurrentVersion(sv);
|
||||||
|
System.out.println(" .. FHIR Version "+sv+", definitions from "+definitions);
|
||||||
System.out.println(" .. connect to tx server @ "+txServer);
|
System.out.println(" .. connect to tx server @ "+txServer);
|
||||||
System.out.println(" .. definitions from "+definitions);
|
|
||||||
ValidationEngine validator = new ValidationEngine(definitions, txServer, txLog, FhirPublication.fromCode(sv));
|
ValidationEngine validator = new ValidationEngine(definitions, txServer, txLog, FhirPublication.fromCode(sv));
|
||||||
validator.setDebug(doDebug);
|
validator.setDebug(doDebug);
|
||||||
System.out.println(" (v"+validator.getContext().getVersion()+")");
|
System.out.println(" (v"+validator.getContext().getVersion()+")");
|
||||||
|
|
Loading…
Reference in New Issue