use of org.hl7.fhir.utilities.validation.ValidationMessage in project kindling by HL7.
the class Publisher method checkFragment.
public void checkFragment(Fragment f) {
try {
// System.out.println(" "+f.page+"/"+f.id);
String xml = f.getXml();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
Document doc = builder.parse(is);
org.w3c.dom.Element base = doc.getDocumentElement();
String type = base.getAttribute("fragment");
if (!page.getDefinitions().hasPrimitiveType(type)) {
if (f.isJson()) {
org.hl7.fhir.r5.elementmodel.JsonParser p = new org.hl7.fhir.r5.elementmodel.JsonParser(page.getWorkerContext());
p.setupValidation(ValidationPolicy.QUICK, null);
p.parse(base.getTextContent(), type);
} else {
org.hl7.fhir.r5.elementmodel.XmlParser p = new org.hl7.fhir.r5.elementmodel.XmlParser(page.getWorkerContext());
p.setupValidation(ValidationPolicy.QUICK, null);
p.parse(XMLUtil.getFirstChild(base), type);
}
}
} catch (Exception e) {
page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.STRUCTURE, f.getPage(), "Fragment Error in page " + f.getPage() + (f.id != null ? "#" + f.id : "") + ": " + e.getMessage(), IssueSeverity.ERROR));
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage in project kindling by HL7.
the class Publisher method checkBundleURLs.
/**
* This is not true of bundles generally, but it is true of all the
* conformance bundles produced by the spec:
*
* all entries must have a fullUrl, and it must equal http://hl7.org/fhir/[type]/[id]
*
* @param bnd - the bundle to check
*/
private void checkBundleURLs(Bundle bnd) {
int i = 0;
for (BundleEntryComponent e : bnd.getEntry()) {
i++;
if (!e.getResource().hasUserData("external.url")) {
if (!e.hasFullUrl())
page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "Bundle " + bnd.getId(), "no Full URL on entry " + Integer.toString(i), IssueSeverity.ERROR));
else if (!e.getFullUrl().endsWith("/" + e.getResource().getResourceType().toString() + "/" + e.getResource().getId()) && e.getResource().getResourceType() != ResourceType.CodeSystem)
page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "Bundle " + bnd.getId(), "URL doesn't match resource and id on entry " + Integer.toString(i) + " : " + e.getFullUrl() + " should end with /" + e.getResource().getResourceType().toString() + "/" + e.getResource().getId(), IssueSeverity.ERROR));
else if (!e.getFullUrl().equals("http://hl7.org/fhir/" + e.getResource().getResourceType().toString() + "/" + e.getResource().getId()) && e.getResource().getResourceType() != ResourceType.CodeSystem)
page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "Bundle " + bnd.getId(), "URL is non-FHIR " + Integer.toString(i) + " : " + e.getFullUrl() + " should start with http://hl7.org/fhir/ for HL7-defined artifacts", IssueSeverity.WARNING));
if (e.getResource() instanceof CanonicalResource) {
CanonicalResource m = (CanonicalResource) e.getResource();
String url = m.getUrl();
if (url != null && url.startsWith("http://hl7.org/fhir") && !SIDUtilities.isKnownSID(url)) {
if (!page.getVersion().toCode().equals(m.getVersion()))
page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "Bundle " + bnd.getId(), "definitions in FHIR space should have the correct version (url = " + url + ", version = " + m.getVersion() + ")", IssueSeverity.ERROR));
}
}
}
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage in project kindling by HL7.
the class Publisher method execute.
/**
* Entry point to the publisher. This classes Java Main() calls this function
* to actually produce the specification
*
* @param folder
* @throws IOException
*/
public void execute(String folder) throws IOException {
tester = new PublisherTestSuites();
page.log("Publish FHIR in folder " + folder + " @ " + Config.DATE_FORMAT().format(page.getGenDate().getTime()), LogMessageType.Process);
if (web)
page.log("Build final copy for HL7 web site", LogMessageType.Process);
else
page.log("Build local copy", LogMessageType.Process);
if (outputdir != null) {
page.log("Create output in " + outputdir, LogMessageType.Process);
}
page.log("Detected Java version: " + System.getProperty("java.version") + " from " + System.getProperty("java.home") + " on " + System.getProperty("os.arch"), LogMessageType.Process);
try {
tester.initialTests();
page.setFolders(new FolderManager(folder, outputdir));
if (!initialize(folder))
throw new Exception("Unable to publish as preconditions aren't met");
cache = new IniFile(page.getFolders().rootDir + "temp" + File.separator + "build.cache");
loadSuppressedMessages(page.getFolders().rootDir);
boolean doAny = false;
for (String n : dates.keySet()) {
Long d = cache.getLongProperty("dates", n);
boolean b = d == null || (dates.get(n) > d);
cache.setLongProperty("dates", n, dates.get(n).longValue(), null);
buildFlags.put(n.toLowerCase(), b);
doAny = doAny || b;
}
cache.save();
if (noPartialBuild || !doAny || !(new File(page.getFolders().dstDir + "qa.html").exists()))
// nothing - build all
buildFlags.put("all", true);
if (singlePage != null) {
for (String n : buildFlags.keySet()) buildFlags.put(n, false);
buildFlags.put("page-" + singlePage.toLowerCase(), true);
} else if (singleResource != null) {
for (String n : buildFlags.keySet()) buildFlags.put(n, false);
buildFlags.put(singleResource.toLowerCase(), true);
}
if (!buildFlags.get("all")) {
if (!noSound) {
AudioUtilities.tone(1000, 10);
AudioUtilities.tone(1400, 10);
AudioUtilities.tone(1800, 10);
AudioUtilities.tone(1000, 10);
AudioUtilities.tone(1400, 10);
AudioUtilities.tone(1800, 10);
}
page.log("Partial Build (if you want a full build, just run the build again)", LogMessageType.Process);
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (String n : buildFlags.keySet()) if (buildFlags.get(n))
b.append(n);
page.log(" Build: " + b.toString(), LogMessageType.Process);
} else {
if (!noSound)
AudioUtilities.tone(1200, 30);
page.log("Full Build", LogMessageType.Process);
}
if (isGenerate && page.getBuildId() == null)
page.setBuildId(getGitBuildId());
page.log("Version " + page.getVersion() + "-" + page.getBuildId(), LogMessageType.Hint);
Utilities.createDirectory(page.getFolders().dstDir);
Utilities.deleteTempFiles();
page.getBreadCrumbManager().parse(page.getFolders().srcDir + "hierarchy.xml");
page.loadSnomed();
page.loadLoinc();
page.loadUcum();
buildFeedsAndMaps();
prsr.setExternals(externals);
prsr.parse(page.getGenDate(), page.getValidationErrors());
for (String n : page.getDefinitions().sortedResourceNames()) if (!page.getBreadCrumbManager().knowsResource(n))
page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "hierarchy.xml", "Resource not found: " + n, IssueSeverity.ERROR));
for (String n : prsr.getErrors()) page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "source spreadsheets", n, IssueSeverity.ERROR));
if (web) {
page.log("Clear Directory", LogMessageType.Process);
Utilities.clearDirectory(page.getFolders().dstDir);
}
if (web || (isGenerate && buildFlags.get("all"))) {
Utilities.createDirectory(page.getFolders().dstDir + "html");
Utilities.createDirectory(page.getFolders().dstDir + "examples");
}
for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) if (!ig.isCore())
Utilities.createDirectory(page.getFolders().dstDir + ig.getCode());
if (buildFlags.get("all")) {
copyStaticContent();
}
page.makeRenderingContext();
loadValueSets1();
prsr.getRegistry().commit();
generateSCMaps();
validate();
processProfiles();
checkAllOk();
if (isGenerate) {
produceSpecification();
checkAllOk();
}
if (doValidate)
validationProcess();
page.saveSnomed();
page.getWorkerContext().saveCache();
processWarnings(false);
if (isGenerate && buildFlags.get("all"))
produceQA();
if (!buildFlags.get("all")) {
page.log("This was a Partial Build", LogMessageType.Process);
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (String n : buildFlags.keySet()) if (buildFlags.get(n))
b.append(n);
page.log(" Build: " + b.toString(), LogMessageType.Process);
} else
page.log("This was a Full Build", LogMessageType.Process);
if (!noSound) {
AudioUtilities.tone(800, 10);
AudioUtilities.tone(1000, 10);
AudioUtilities.tone(1200, 10);
AudioUtilities.tone(1000, 10);
AudioUtilities.tone(800, 10);
}
page.log("Finished publishing FHIR @ " + Config.DATE_FORMAT().format(Calendar.getInstance().getTime()), LogMessageType.Process);
} catch (Exception e) {
if (!(e instanceof NullPointerException)) {
// because NullPointerException is unexpected...
try {
processWarnings(e instanceof EValidationFailed);
} catch (Exception e2) {
page.log(" ERROR: Unable to process warnings: " + e2.getMessage(), LogMessageType.Error);
e2.printStackTrace();
}
}
if (buildFlags.containsKey("all") && !buildFlags.get("all")) {
page.log("This was a Partial Build", LogMessageType.Process);
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (String n : buildFlags.keySet()) if (buildFlags.get(n))
b.append(n);
page.log(" Build: " + b.toString(), LogMessageType.Process);
} else
page.log("This was a Full Build", LogMessageType.Process);
if (!noSound) {
AudioUtilities.tone(800, 20);
AudioUtilities.tone(1000, 20);
AudioUtilities.tone(1200, 20);
}
try {
Thread.sleep(50);
} catch (InterruptedException e1) {
}
if (!noSound) {
AudioUtilities.tone(800, 20);
AudioUtilities.tone(1000, 20);
AudioUtilities.tone(1200, 20);
}
try {
Thread.sleep(50);
} catch (InterruptedException e1) {
}
if (!noSound) {
AudioUtilities.tone(800, 20);
AudioUtilities.tone(1000, 20);
AudioUtilities.tone(1200, 20);
}
page.log("FHIR build failure @ " + Config.DATE_FORMAT().format(Calendar.getInstance().getTime()), LogMessageType.Process);
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
TextFile.stringToFile(StringUtils.defaultString(e.getMessage()), Utilities.path(folder, "publish", "simple-error.txt"));
System.exit(1);
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage in project kindling by HL7.
the class Publisher method processWarnings.
private void processWarnings(boolean showOnlyErrors) throws Exception {
String xslt = Utilities.path(page.getFolders().rootDir, "implementations", "xmltools", "OwnerResources.xslt");
OutputStreamWriter s = new OutputStreamWriter(new FileOutputStream(page.getFolders().dstDir + "warnings.xml"), "UTF-8");
s.write("<warnings>");
for (WorkGroup wg : page.getDefinitions().getWorkgroups().values()) {
s.write("<wg code=\"" + wg.getCode() + "\" name=\"" + wg.getName() + "\" url=\"" + wg.getUrl() + "\"/>\r\n");
}
for (PageInformation pn : page.getDefinitions().getPageInfo().values()) {
s.write("<page name=\"" + pn.getName() + "\" wg=\"" + pn.getWgCode() + "\" fmm=\"" + pn.getFmm() + "\"/>\r\n");
}
try {
s.write(new String(XsltUtilities.saxonTransform(page.getFolders().dstDir + "profiles-resources.xml", xslt)));
s.write(new String(XsltUtilities.saxonTransform(page.getFolders().dstDir + "profiles-types.xml", xslt)));
s.write(new String(XsltUtilities.saxonTransform(page.getFolders().dstDir + "profiles-others.xml", xslt)));
} catch (Exception e) {
for (ValidationMessage err : page.getValidationErrors()) {
if (!page.getSuppressedMessages().contains(err.getDisplay()))
System.out.println(err.summary());
}
System.out.println("WARNING: Unable to create warnings file - one or more profiles-* files unavailable or invalid");
System.out.println("To determine the cause of the build failure, look in the log prior to the warning and information messages immediately above");
}
for (ValidationMessage e : page.getValidationErrors()) {
if (!page.getSuppressedMessages().contains(e.getDisplay()))
s.write(e.toXML());
}
s.write("</warnings>");
s.flush();
s.close();
String xslt2 = Utilities.path(page.getFolders().rootDir, "implementations", "xmltools", "CategorizeWarnings.xslt");
FileOutputStream s2 = new FileOutputStream(page.getFolders().dstDir + "work-group-warnings.xml");
try {
s2.write(XsltUtilities.saxonTransform(page.getFolders().dstDir + "warnings.xml", xslt2).getBytes("UTF8"));
} catch (Exception e) {
// nothing - do not want to know.
}
s2.flush();
s2.close();
String xslt3 = Utilities.path(page.getFolders().rootDir, "implementations", "xmltools", "RenderWarnings.xslt");
try {
String hw = XsltUtilities.saxonTransform(page.getFolders().dstDir + "work-group-warnings.xml", xslt3);
if (!showOnlyErrors)
page.log(hw, LogMessageType.Process);
} catch (Exception e) {
// nothing - do not want to know.
}
int i = 0;
int w = 0;
int ee = 0;
for (ValidationMessage e : page.getValidationErrors()) {
if (e.getLevel() == IssueSeverity.ERROR || e.getLevel() == IssueSeverity.FATAL) {
ee++;
page.log(e.summary(), LogMessageType.Hint);
} else if (e.getLevel() == IssueSeverity.WARNING) {
w++;
} else if (e.getLevel() == IssueSeverity.INFORMATION) {
i++;
}
}
page.getQa().setCounts(ee, w, i);
}
use of org.hl7.fhir.utilities.validation.ValidationMessage in project kindling by HL7.
the class PageProcessor method resolveBinding.
public BindingResolution resolveBinding(StructureDefinition profile, String ref, String description, String path) throws FHIRException {
BindingResolution br = new BindingResolution();
if (ref.contains("|"))
ref = ref.substring(0, ref.indexOf("|"));
if (ref.startsWith("http://terminology.hl7.org/ValueSet/v3-") || ref.startsWith("http://terminology.hl7.org/ValueSet/v2-")) {
ValueSet vs = workerContext.fetchResource(ValueSet.class, ref);
if (vs == null) {
br.url = "v3/" + ref.substring(39) + "/vs.html";
br.display = ref.substring(39);
} else {
br.url = vs.getUserString("path");
br.display = vs.present();
}
} else if (definitions.getValuesets().has(ref)) {
ValueSet vs = definitions.getValuesets().get(ref);
br.url = vs.getUserString("path");
br.display = vs.present();
} else if (ref.startsWith("ValueSet/")) {
ValueSet vs = definitions.getValuesets().get(ref.substring(8));
if (vs == null) {
br.url = ref.substring(9) + ".html";
br.display = ref.substring(9);
} else {
br.url = vs.getUserString("path");
br.display = vs.present();
}
} else if (ref.startsWith("http://hl7.org/fhir/ValueSet/")) {
ValueSet vs = definitions.getValuesets().get(ref);
if (vs == null)
vs = definitions.getExtraValuesets().get(ref);
if (vs != null) {
br.url = vs.getUserString("path");
if (Utilities.noString(br.url))
br.url = ref.substring(23) + ".html";
br.display = vs.present();
} else if (ref.substring(23).equals("use-context")) {
// special case because this happens before the value set is created
br.url = "valueset-" + ref.substring(23) + ".html";
br.display = "Context of Use ValueSet";
} else if (ref.startsWith("http://terminology.hl7.org/ValueSet/v3-")) {
br.url = "v3/" + ref.substring(26) + "/index.html";
br.display = ref.substring(26);
} else if (ref.startsWith("http://terminology.hl7.org/ValueSet/v2-")) {
br.url = "v2/" + ref.substring(26) + "/index.html";
br.display = ref.substring(26);
} else if (ref.startsWith("#")) {
br.url = null;
br.display = ref;
} else {
br.url = ref;
br.display = "????";
getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.NOTFOUND, -1, -1, path, "Unresolved Value set " + ref, IssueSeverity.WARNING));
}
} else {
br.url = ref;
if (ref.equals("http://tools.ietf.org/html/bcp47"))
br.display = "IETF BCP-47";
else if (ref.equals("http://www.rfc-editor.org/bcp/bcp13.txt"))
br.display = "IETF BCP-13";
else if (ref.equals("http://www.ncbi.nlm.nih.gov/nuccore?db=nuccore"))
br.display = "NucCore";
else if (ref.equals("https://rtmms.nist.gov/rtmms/index.htm#!rosetta"))
br.display = "Rosetta";
else if (ref.equals("http://www.iso.org/iso/country_codes.htm"))
br.display = "ISO Country Codes";
else if (ref.equals("http://www.ncbi.nlm.nih.gov/clinvar/variation"))
br.display = "ClinVar";
else if (!Utilities.noString(description))
br.display = description;
else
br.display = "????";
}
return br;
}
Aggregations