fix to package infrastructure

This commit is contained in:
Grahame Grieve 2019-11-17 19:07:16 +11:00
parent 0e1674d712
commit e5986a31fb
3 changed files with 96 additions and 19 deletions

View File

@ -374,13 +374,13 @@ public class NpmPackage {
return npm.get("version").getAsString(); return npm.get("version").getAsString();
else { else {
JsonObject dep = npm.getAsJsonObject("dependencies"); JsonObject dep = npm.getAsJsonObject("dependencies");
if (dep == null) if (dep != null) {
throw new FHIRException("no dependencies found in the Package definition"); for (Entry<String, JsonElement> e : dep.entrySet()) {
for (Entry<String, JsonElement> e : dep.entrySet()) { if (Utilities.existsInList(e.getKey(), "hl7.fhir.r2.core", "hl7.fhir.r2b.core", "hl7.fhir.r3.core", "hl7.fhir.r4.core"))
if (Utilities.existsInList(e.getKey(), "hl7.fhir.r2.core", "hl7.fhir.r2b.core", "hl7.fhir.r3.core", "hl7.fhir.r4.core")) return e.getValue().getAsString();
return e.getValue().getAsString(); if (Utilities.existsInList(e.getKey(), "hl7.fhir.core")) // while all packages are updated
if (Utilities.existsInList(e.getKey(), "hl7.fhir.core")) // while all packages are updated return e.getValue().getAsString();
return e.getValue().getAsString(); }
} }
if (npm.has("fhirVersions")) { if (npm.has("fhirVersions")) {
return npm.getAsJsonArray("fhirVersions").get(0).getAsString(); return npm.getAsJsonArray("fhirVersions").get(0).getAsString();
@ -408,7 +408,10 @@ public class NpmPackage {
} }
public String type() { public String type() {
return npm.get("type").getAsString(); if (npm.has("type"))
return npm.get("type").getAsString();
else
return null;
} }
public String description() { public String description() {
@ -563,5 +566,51 @@ public class NpmPackage {
} }
return res; return res;
} }
public String homepage() {
if (npm.has("homepage"))
return npm.get("homepage").getAsString();
else
return null;
}
public String url() {
if (npm.has("url"))
return npm.get("url").getAsString();
else
return null;
}
public String title() {
if (npm.has("title"))
return npm.get("title").getAsString();
else
return null;
}
public String toolsVersion() {
if (npm.has("tools-version"))
return npm.get("tools-version").getAsString();
else
return null;
}
public String license() {
if (npm.has("license"))
return npm.get("license").getAsString();
else
return null;
}
public Map<String, List<String>> getTypes() {
return types;
}
public Map<String, String> getUrls() {
return urls;
}
} }

View File

@ -327,6 +327,8 @@ public class PackageCacheManager {
save = checkIniHasMapping("hl7.fhir.uv.phd", "http://hl7.org/fhir/devices", ini) || save; save = checkIniHasMapping("hl7.fhir.uv.phd", "http://hl7.org/fhir/devices", ini) || save;
save = checkIniHasMapping("hl7.fhir.uv.vhdir", "http://hl7.org/fhir/ig/vhdir", ini) || save; save = checkIniHasMapping("hl7.fhir.uv.vhdir", "http://hl7.org/fhir/ig/vhdir", ini) || save;
save = checkIniHasMapping("hl7.fhir.vn.base", "http://hl7.org/fhir/ig/vietnam", ini) || save; save = checkIniHasMapping("hl7.fhir.vn.base", "http://hl7.org/fhir/ig/vietnam", ini) || save;
save = checkIniHasMapping("hl7.fhir.uv.bulkdata", "http://hl7.org/fhir/uv/bulkdata", ini) || save;
save = checkIniHasMapping("hl7.fhir.us.bulkdata", "http://hl7.org/fhir/uv/bulkdata", ini) || save;
save = checkIniHasMapping("hl7.fhir.vocabpoc", "http://hl7.org/fhir/ig/vocab-poc", ini) || save; save = checkIniHasMapping("hl7.fhir.vocabpoc", "http://hl7.org/fhir/ig/vocab-poc", ini) || save;
return save; return save;
} }

View File

@ -5,8 +5,11 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
@ -22,7 +25,7 @@ import com.google.gson.JsonObject;
public class PackageHacker { public class PackageHacker {
public static void main(String[] args) throws FileNotFoundException, IOException { public static void main(String[] args) throws FileNotFoundException, IOException {
new PackageHacker().edit("C:\\work\\fhir.org\\web-source\\source\\guides\\argonaut\\questionnaire\\package.tgz"); new PackageHacker().edit("C:\\web\\hl7.org\\fhir\\uv\\pocd\\2018Jan\\package.tgz");
} }
private void edit(String name) throws FileNotFoundException, IOException { private void edit(String name) throws FileNotFoundException, IOException {
@ -53,16 +56,39 @@ public class PackageHacker {
return new GsonBuilder().setPrettyPrinting().create().toJson(json); return new GsonBuilder().setPrettyPrinting().create().toJson(json);
} }
private void change(JsonObject npm, Map<String, byte[]> content) { private void change(JsonObject npm, Map<String, byte[]> content) throws FileNotFoundException, IOException {
npm.remove("name"); // addContentFrom("C:\\web\\hl7.org\\fhir\\us\\meds", content);
npm.addProperty("name", "fhir.argonaut.questionnaire"); fixNames(content);
// JsonArray fhirVersions = new JsonArray(); // setProperty(npm, "homepage", "http://hl7.org/fhir");
// fhirVersions.add("1.9.0");
// npm.add("fhirVersions", fhirVersions); }
// JsonObject dependencies = new JsonObject();
// dependencies.addProperty("hl7.fhir.r3.core", "3.0.2"); private void setProperty(JsonObject npm, String name, String value) {
// npm.remove("dependencies"); npm.remove("homepage");
// npm.add("dependencies", dependencies); npm.addProperty("homepage", "http://hl7.org/fhir");
}
private void fixNames(Map<String, byte[]> content) {
List<String> names = new ArrayList<>();
names.addAll(content.keySet());
for (String s : names) {
if (s.endsWith("json") && !s.endsWith(".json")) {
String n = s.substring(0, s.length()-4)+".json";
content.put(n, content.get(s));
content.remove(s);
}
}
}
private void addContentFrom(String folder, Map<String, byte[]> content) throws FileNotFoundException, IOException {
for (File f : new File(folder).listFiles()) {
if (f.getName().endsWith(".json") && !f.getName().endsWith(".canonical.json")) {
String cnt = TextFile.fileToString(f);
if (cnt.contains("\"resourceType\"")) {
content.put("package/"+f.getName(), TextFile.fileToBytes(f));
}
}
}
} }
} }