Search in sources :

Example 1 with EValidationFailed

use of org.hl7.fhir.tools.publisher.ExampleInspector.EValidationFailed 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);
    }
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) IniFile(org.hl7.fhir.utilities.IniFile) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EValidationFailed(org.hl7.fhir.tools.publisher.ExampleInspector.EValidationFailed) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 TransformerException (javax.xml.transform.TransformerException)1 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 EValidationFailed (org.hl7.fhir.tools.publisher.ExampleInspector.EValidationFailed)1 CSFile (org.hl7.fhir.utilities.CSFile)1 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)1 IniFile (org.hl7.fhir.utilities.IniFile)1 TextFile (org.hl7.fhir.utilities.TextFile)1 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)1