use of org.hl7.fhir.utilities.validation.ValidationMessage.Source 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.Source in project kindling by HL7.
the class Publisher method stripXsd.
private InputStream stripXsd(InputStream source) throws Exception {
byte[] src = IOUtils.toByteArray(source);
try {
byte[] xslt = IOUtils.toByteArray(new FileInputStream(Utilities.path(page.getFolders().rootDir, "implementations", "xmltools", "AnnotationStripper.xslt")));
String scrs = new String(src);
String xslts = new String(xslt);
return new ByteArrayInputStream(XsltUtilities.transform(new HashMap<String, byte[]>(), src, xslt));
} catch (Exception e) {
if (web) {
e.printStackTrace();
throw e;
} else
return new ByteArrayInputStream(src);
}
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware(false);
// DocumentBuilder builder = factory.newDocumentBuilder();
// Document doc = builder.parse(source);
// stripElement(doc.getDocumentElement(), "annotation");
// TransformerFactory transformerFactory = TransformerFactory.newInstance();
// Transformer transformer = transformerFactory.newTransformer();
// ByteArrayOutputStream bo = new ByteArrayOutputStream();
// DOMSource src = new DOMSource(doc);erent
// StreamResult streamResult = new StreamResult(bo);
// transformer.transform(src, streamResult);
// bo.close();
// return new ByteArrayInputStream(bo.toByteArray());
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.
the class Publisher method stripJson.
private InputStream stripJson(InputStream source) throws Exception {
JsonParser p = new JsonParser();
Resource r = p.parse(source);
minify(r);
ByteArrayOutputStream bo = new ByteArrayOutputStream();
p.compose(bo, r);
bo.close();
return new ByteArrayInputStream(bo.toByteArray());
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.
the class Publisher method copyStaticContent.
private void copyStaticContent() throws IOException, Exception {
if (page.getIni().getPropertyNames("support") != null)
for (String n : page.getIni().getPropertyNames("support")) {
Utilities.copyFile(new CSFile(page.getFolders().srcDir + n), new CSFile(page.getFolders().dstDir + n));
page.getHTMLChecker().registerFile(n, "Support File", HTMLLinkChecker.determineType(n), true);
}
for (String n : page.getIni().getPropertyNames("images")) {
copyImage(page.getFolders().imgDir, n);
}
for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
for (String n : ig.getImageList()) {
copyIgImage(ig, n);
}
}
for (String n : page.getIni().getPropertyNames("files")) {
Utilities.copyFile(new CSFile(page.getFolders().rootDir + n), new CSFile(page.getFolders().dstDir + page.getIni().getStringProperty("files", n)));
page.getHTMLChecker().registerFile(page.getIni().getStringProperty("files", n), "Support File", HTMLLinkChecker.determineType(page.getIni().getStringProperty("files", n)), true);
}
page.log("Copy HTML templates", LogMessageType.Process);
Utilities.copyDirectory(page.getFolders().rootDir + page.getIni().getStringProperty("html", "source"), page.getFolders().dstDir, page.getHTMLChecker());
TextFile.stringToFile("\r\n[FHIR]\r\nFhirVersion=" + page.getVersion() + "-" + page.getBuildId() + "\r\nversion=" + page.getVersion().toCode() + "\r\nbuildId=" + page.getBuildId() + "\r\ndate=" + new SimpleDateFormat("yyyyMMddHHmmss").format(page.getGenDate().getTime()), Utilities.path(page.getFolders().dstDir, "version.info"), false);
for (String n : page.getDefinitions().getDiagrams().keySet()) {
page.log(" ...diagram " + n, LogMessageType.Process);
page.getSvgs().put(n, TextFile.fileToString(page.getFolders().srcDir + page.getDefinitions().getDiagrams().get(n)));
}
}
use of org.hl7.fhir.utilities.validation.ValidationMessage.Source in project kindling by HL7.
the class PageProcessor method mapOnPageProfile.
private String mapOnPageProfile(StructureDefinition source) {
if (source.getMapping().size() < 2)
return "";
StringBuilder b = new StringBuilder();
b.append("<div class=\"itoc\">\r\n<p>Mappings:</p>\r\n");
for (StructureDefinitionMappingComponent map : source.getMapping()) {
b.append("<p class=\"link\"><a href=\"#").append(map.getIdentity()).append("\">").append(map.getName()).append("</a></p>");
}
b.append("</div>\r\n");
return b.toString();
}
Aggregations