From e1f53eec47ef191d65c970388c27f47e976251a6 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 2 Sep 2020 16:34:06 +1000 Subject: [PATCH] Mark packages as unsuitable for publication --- .../fhir/r5/utils/NPMPackageGenerator.java | 49 +++++++++++++------ .../hl7/fhir/utilities/cache/NpmPackage.java | 4 ++ 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NPMPackageGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NPMPackageGenerator.java index 22a5d0c54..0a46a7fcf 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NPMPackageGenerator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NPMPackageGenerator.java @@ -104,17 +104,17 @@ public class NPMPackageGenerator { private NpmPackageIndexBuilder indexer; - public NPMPackageGenerator(String destFile, String canonical, String url, PackageType kind, ImplementationGuide ig, Date date) throws FHIRException, IOException { + public NPMPackageGenerator(String destFile, String canonical, String url, PackageType kind, ImplementationGuide ig, Date date, boolean notForPublication) throws FHIRException, IOException { super(); this.destFile = destFile; start(); List fhirVersion = new ArrayList<>(); for (Enumeration v : ig.getFhirVersion()) fhirVersion.add(v.asStringValue()); - buildPackageJson(canonical, kind, url, date, ig, fhirVersion); + buildPackageJson(canonical, kind, url, date, ig, fhirVersion, notForPublication); } - public static NPMPackageGenerator subset(NPMPackageGenerator master, String destFile, String id, String name, Date date) throws FHIRException, IOException { + public static NPMPackageGenerator subset(NPMPackageGenerator master, String destFile, String id, String name, Date date, boolean notForPublication) throws FHIRException, IOException { JsonObject p = master.packageJ.deepCopy(); p.remove("name"); p.addProperty("name", id); @@ -122,24 +122,30 @@ public class NPMPackageGenerator { p.addProperty("type", PackageType.SUBSET.getCode()); p.remove("title"); p.addProperty("title", name); + if (notForPublication) { + p.addProperty("notForPublication", true); + } - return new NPMPackageGenerator(destFile, p, date); + return new NPMPackageGenerator(destFile, p, date, notForPublication); } - public NPMPackageGenerator(String destFile, String canonical, String url, PackageType kind, ImplementationGuide ig, Date date, List fhirVersion) throws FHIRException, IOException { + public NPMPackageGenerator(String destFile, String canonical, String url, PackageType kind, ImplementationGuide ig, Date date, List fhirVersion, boolean notForPublication) throws FHIRException, IOException { super(); this.destFile = destFile; start(); - buildPackageJson(canonical, kind, url, date, ig, fhirVersion); + buildPackageJson(canonical, kind, url, date, ig, fhirVersion, notForPublication); } - public NPMPackageGenerator(String destFile, JsonObject npm, Date date) throws FHIRException, IOException { + public NPMPackageGenerator(String destFile, JsonObject npm, Date date, boolean notForPublication) throws FHIRException, IOException { super(); String dt = new SimpleDateFormat("yyyyMMddHHmmss").format(date); packageJ = npm; packageManifest = new JsonObject(); packageManifest.addProperty("version", npm.get("version").getAsString()); packageManifest.addProperty("date", dt); + if (notForPublication) { + packageManifest.addProperty("notForPublication", true); + } npm.addProperty("date", dt); packageManifest.addProperty("name", npm.get("name").getAsString()); this.destFile = destFile; @@ -152,19 +158,23 @@ public class NPMPackageGenerator { } } - private void buildPackageJson(String canonical, PackageType kind, String web, Date date, ImplementationGuide ig, List fhirVersion) throws FHIRException, IOException { + private void buildPackageJson(String canonical, PackageType kind, String web, Date date, ImplementationGuide ig, List fhirVersion, boolean notForPublication) throws FHIRException, IOException { String dtHuman = new SimpleDateFormat("EEE, MMM d, yyyy HH:mmZ", new Locale("en", "US")).format(date); String dt = new SimpleDateFormat("yyyyMMddHHmmss").format(date); CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder(); - if (!ig.hasPackageId()) + if (!ig.hasPackageId()) { b.append("packageId"); - if (!ig.hasVersion()) + } + if (!ig.hasVersion()) { b.append("version"); - if (!ig.hasFhirVersion()) + } + if (!ig.hasFhirVersion()) { b.append("fhirVersion"); - if (!ig.hasLicense()) + } + if (!ig.hasLicense()) { b.append("license"); + } for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) { if (!d.hasVersion()) { b.append("dependsOn.version("+d.getUri()+")"); @@ -177,14 +187,20 @@ public class NPMPackageGenerator { npm.addProperty("tools-version", ToolsVersion.TOOLS_VERSION); npm.addProperty("type", kind.getCode()); npm.addProperty("date", dt); - if (ig.hasLicense()) + if (ig.hasLicense()) { npm.addProperty("license", ig.getLicense().toCode()); + } npm.addProperty("canonical", canonical); + if (notForPublication) { + npm.addProperty("notForPublication", true); + } npm.addProperty("url", web); - if (ig.hasTitle()) + if (ig.hasTitle()) { npm.addProperty("title", ig.getTitle()); - if (ig.hasDescription()) + } + if (ig.hasDescription()) { npm.addProperty("description", ig.getDescription()+ " (built "+dtHuman+timezone()+")"); + } JsonArray vl = new JsonArray(); npm.add("fhirVersions", vl); @@ -205,8 +221,9 @@ public class NPMPackageGenerator { dep.addProperty(d.getPackageId(), d.getVersion()); } } - if (ig.hasPublisher()) + if (ig.hasPublisher()) { npm.addProperty("author", ig.getPublisher()); + } JsonArray m = new JsonArray(); for (ContactDetail t : ig.getContact()) { String email = email(t.getTelecom()); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/NpmPackage.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/NpmPackage.java index 75d298867..b87b60818 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/NpmPackage.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/cache/NpmPackage.java @@ -1091,6 +1091,10 @@ public class NpmPackage { } return true; } + + public boolean isNotForPublication() { + return JSONUtil.bool(npm, "notForPublication"); + } } \ No newline at end of file