From 5a1dfba236f1e90b00e79738f52d7367ab65bfaa Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 4 Mar 2019 13:17:30 +1100 Subject: [PATCH] Improve error message when running transforms --- .../hl7/fhir/dstu2016may/utils/StructureMapUtilities.java | 2 +- .../java/org/hl7/fhir/dstu2016may/utils/Transformer.java | 2 +- .../main/java/org/hl7/fhir/r4/context/BaseWorkerContext.java | 2 +- .../java/org/hl7/fhir/r4/context/SimpleWorkerContext.java | 4 ++++ .../main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java | 2 +- .../java/org/hl7/fhir/r5/context/SimpleWorkerContext.java | 4 ++++ .../src/main/java/org/hl7/fhir/utilities/Utilities.java | 5 +++++ .../java/org/hl7/fhir/r4/validation/ValidationEngine.java | 5 ++++- .../java/org/hl7/fhir/r5/validation/ValidationEngine.java | 2 +- 9 files changed, 22 insertions(+), 6 deletions(-) diff --git a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/StructureMapUtilities.java b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/StructureMapUtilities.java index bd0426192..bbd3a54f3 100644 --- a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/StructureMapUtilities.java +++ b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/StructureMapUtilities.java @@ -816,7 +816,7 @@ public class StructureMapUtilities { for (UriType imp : map.getImport()) { StructureMap impMap = library.get(imp.getValue()); if (impMap == null) - throw new FHIRException("Unable to find map "+imp.getValue()); + throw new FHIRException("Unable to find map "+imp.getValue()+" (Known Maps = "+Utilities.listCanonicalUrls(library.keySet())+")"); for (StructureMapGroupComponent grp : impMap.getGroup()) { if (grp.getName().equals(dependent.getName())) { if (targetMap == null) { diff --git a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/Transformer.java b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/Transformer.java index 2322e523a..54acd2129 100644 --- a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/Transformer.java +++ b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/Transformer.java @@ -109,7 +109,7 @@ public class Transformer { Bundle bundle = new Bundle(); StructureMap map = scu.getLibrary().get(mapUri); if (map == null) - throw new Error("Unable to find map "+mapUri); + throw new Error("Unable to find map "+mapUri+" (Known Maps = "+Utilities.listCanonicalUrls(scu.getLibrary().keySet())+")"); scu.transform(null, e, map, bundle); new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(output), bundle); return true; diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/BaseWorkerContext.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/BaseWorkerContext.java index cee43d1ff..020f1efa5 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/BaseWorkerContext.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/BaseWorkerContext.java @@ -91,7 +91,7 @@ public abstract class BaseWorkerContext implements IWorkerContext { private Set supportedCodeSystems = new HashSet(); private Map valueSets = new HashMap(); private Map maps = new HashMap(); - private Map transforms = new HashMap(); + protected Map transforms = new HashMap(); private Map structures = new HashMap(); private Map guides = new HashMap(); private Map searchParameters = new HashMap(); diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/SimpleWorkerContext.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/SimpleWorkerContext.java index 9acc77158..42fa46cce 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/SimpleWorkerContext.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/context/SimpleWorkerContext.java @@ -601,6 +601,10 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon this.ignoreProfileErrors = ignoreProfileErrors; } + public String listMapUrls() { + return Utilities.listCanonicalUrls(transforms.keySet()); + } + diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java index 9f6a6986c..71142cb85 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java @@ -91,7 +91,7 @@ public abstract class BaseWorkerContext implements IWorkerContext { private Set supportedCodeSystems = new HashSet(); private Map valueSets = new HashMap(); private Map maps = new HashMap(); - private Map transforms = new HashMap(); + protected Map transforms = new HashMap(); private Map structures = new HashMap(); private Map guides = new HashMap(); private Map searchParameters = new HashMap(); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java index af92e0b10..e425cd8d7 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java @@ -601,6 +601,10 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon this.ignoreProfileErrors = ignoreProfileErrors; } + public String listMapUrls() { + return Utilities.listCanonicalUrls(transforms.keySet()); + } + diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java index 729d0ef5e..3308f3ad7 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java @@ -66,6 +66,7 @@ import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import javax.sound.sampled.AudioFormat; @@ -1156,5 +1157,9 @@ public class Utilities { } + public static String listCanonicalUrls(Set keys) { + return keys.toString(); + } + } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/ValidationEngine.java index 89396fe2f..a768d79db 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r4/validation/ValidationEngine.java @@ -619,6 +619,8 @@ public class ValidationEngine { return FhirFormat.TURTLE; if (Utilities.existsInList(ext, "map")) return FhirFormat.TEXT; + if (Utilities.existsInList(ext, "txt")) + return FhirFormat.TEXT; return checkIsResource(new FileInputStream(path)); } @@ -656,6 +658,7 @@ public class ValidationEngine { for (Entry t : source.entrySet()) { String fn = t.getKey(); if (!exemptFile(fn)) { + System.out.print(" ..file: "+fn); Resource r = null; try { if (version.equals("3.0.1") || version.equals("3.0.0")) { @@ -962,7 +965,7 @@ public class ValidationEngine { org.hl7.fhir.r4.elementmodel.Element src = Manager.parse(context, new ByteArrayInputStream(source), cntType); StructureMap map = context.getTransform(mapUri); if (map == null) - throw new Error("Unable to find map "+mapUri); + throw new Error("Unable to find map "+mapUri+" (Known Maps = "+context.listMapUrls()+")"); scu.transform(null, src, map, null); if (outputs.size() == 0) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java index a1c5e98e4..f7dde7e75 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java @@ -972,7 +972,7 @@ public class ValidationEngine { org.hl7.fhir.r5.elementmodel.Element src = Manager.parse(context, new ByteArrayInputStream(source), cntType); StructureMap map = context.getTransform(mapUri); if (map == null) - throw new Error("Unable to find map "+mapUri); + throw new Error("Unable to find map "+mapUri+" (Known Maps = "+context.listMapUrls()+")"); scu.transform(null, src, map, null); if (outputs.size() == 0)