rework xig into 3 steps

This commit is contained in:
Grahame Grieve 2023-10-04 03:16:07 +03:00
parent fb7ad19218
commit 64403db109
2 changed files with 81 additions and 65 deletions

View File

@ -72,6 +72,7 @@ public class PackageVisitor {
private FilesystemPackageCacheManager pcm; private FilesystemPackageCacheManager pcm;
private PackageClient pc; private PackageClient pc;
private String cache; private String cache;
private int step;
public List<String> getResourceTypes() { public List<String> getResourceTypes() {
return resourceTypes; return resourceTypes;
@ -164,15 +165,17 @@ public class PackageVisitor {
if (pid != null) { if (pid != null) {
if (!cpidSet.contains(pid)) { if (!cpidSet.contains(pid)) {
cpidSet.add(pid); cpidSet.add(pid);
List<String> vList = listVersions(pid); if (step == 0 || step == 3) {
if (oldVersions) { List<String> vList = listVersions(pid);
for (String v : vList) { if (oldVersions) {
processPackage(pid, v, i, pidList.size()); for (String v : vList) {
processPackage(pid, v, i, pidList.size());
}
} else if (vList.isEmpty()) {
System.out.println("No Packages for "+pid);
} else {
processPackage(pid, vList.get(vList.size() - 1), i, pidList.size());
} }
} else if (vList.isEmpty()) {
System.out.println("No Packages for "+pid);
} else {
processPackage(pid, vList.get(vList.size() - 1), i, pidList.size());
} }
} else { } else {
processor.alreadyVisited(pid); processor.alreadyVisited(pid);
@ -180,76 +183,81 @@ public class PackageVisitor {
i++; i++;
} }
} }
JsonObject json = JsonParser.parseObjectFromUrl("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json");
i = 0; if (step == 0 || step == 3) {
List<JsonObject> objects = json.getJsonObjects("guides"); JsonObject json = JsonParser.parseObjectFromUrl("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json");
for (JsonObject o : objects) { i = 0;
String pid = o.asString("npm-name"); List<JsonObject> objects = json.getJsonObjects("guides");
if (pid != null && !cpidSet.contains(pid)) { for (JsonObject o : objects) {
cpidSet.add(pid); String pid = o.asString("npm-name");
List<String> vList = listVersions(pid); if (pid != null && !cpidSet.contains(pid)) {
if (oldVersions) { cpidSet.add(pid);
for (String v : vList) { List<String> vList = listVersions(pid);
processPackage(pid, v, i, objects.size()); if (oldVersions) {
for (String v : vList) {
processPackage(pid, v, i, objects.size());
}
} else if (vList.isEmpty()) {
System.out.println("No Packages for "+pid);
} else {
processPackage(pid, vList.get(vList.size() - 1), i, objects.size());
} }
} else if (vList.isEmpty()) {
System.out.println("No Packages for "+pid);
} else {
processPackage(pid, vList.get(vList.size() - 1), i, objects.size());
} }
i++;
} }
i++;
} }
} }
private void processCurrentPackage(String url, String pid, Set<String> cpidSet, int i, int t) { private void processCurrentPackage(String url, String pid, Set<String> cpidSet, int i, int t) {
try { try {
long ms1 = System.currentTimeMillis();
String[] p = url.split("\\/");
String repo = "https://build.fhir.org/ig/"+p[0]+"/"+p[1];
JsonObject manifest = JsonParser.parseObjectFromUrl(repo+"/package.manifest.json");
File co = new File(Utilities.path(cache, pid+"."+manifest.asString("date")+".tgz"));
if (!co.exists()) {
SimpleHTTPClient fetcher = new SimpleHTTPClient();
HTTPResult res = fetcher.get(repo+"/package.tgz?nocache=" + System.currentTimeMillis());
res.checkThrowException();
TextFile.bytesToFile(res.getContent(), co);
}
NpmPackage npm = NpmPackage.fromPackage(new FileInputStream(co));
String fv = npm.fhirVersion();
cpidSet.add(pid); cpidSet.add(pid);
long ms2 = System.currentTimeMillis(); if (step == 0 || (step == 1 && i < t/2) || (step == 2 && i >= t/2)) {
long ms1 = System.currentTimeMillis();
String[] p = url.split("\\/");
String repo = "https://build.fhir.org/ig/"+p[0]+"/"+p[1];
JsonObject manifest = JsonParser.parseObjectFromUrl(repo+"/package.manifest.json");
File co = new File(Utilities.path(cache, pid+"."+manifest.asString("date")+".tgz"));
if (!co.exists()) {
SimpleHTTPClient fetcher = new SimpleHTTPClient();
HTTPResult res = fetcher.get(repo+"/package.tgz?nocache=" + System.currentTimeMillis());
res.checkThrowException();
TextFile.bytesToFile(res.getContent(), co);
}
NpmPackage npm = NpmPackage.fromPackage(new FileInputStream(co));
String fv = npm.fhirVersion();
long ms2 = System.currentTimeMillis();
if (corePackages || !corePackage(npm)) { if (corePackages || !corePackage(npm)) {
if (fv != null && (versions.isEmpty() || versions.contains(fv))) { if (fv != null && (versions.isEmpty() || versions.contains(fv))) {
PackageContext ctxt = new PackageContext(pid+"#current", npm, fv); PackageContext ctxt = new PackageContext(pid+"#current", npm, fv);
boolean ok = false; boolean ok = false;
Object context = null; Object context = null;
try { try {
context = processor.startPackage(ctxt); context = processor.startPackage(ctxt);
ok = true; ok = true;
} catch (Exception e) { } catch (Exception e) {
System.out.println("####### Error loading "+pid+"#current["+fv+"]: ####### "+e.getMessage()); System.out.println("####### Error loading "+pid+"#current["+fv+"]: ####### "+e.getMessage());
// e.printStackTrace(); // e.printStackTrace();
} }
if (ok) { if (ok) {
int c = 0; int c = 0;
for (String type : resourceTypes) { for (String type : resourceTypes) {
for (String s : npm.listResources(type)) { for (String s : npm.listResources(type)) {
c++; c++;
try { try {
processor.processResource(ctxt, context, type, s, TextFile.streamToBytes(npm.load("package", s))); processor.processResource(ctxt, context, type, s, TextFile.streamToBytes(npm.load("package", s)));
} catch (Exception e) { } catch (Exception e) {
System.out.println("####### Error loading "+pid+"#current["+fv+"]/"+type+" ####### "+e.getMessage()); System.out.println("####### Error loading "+pid+"#current["+fv+"]/"+type+" ####### "+e.getMessage());
// e.printStackTrace(); // e.printStackTrace();
}
} }
} }
processor.finishPackage(ctxt);
System.out.println("Processed: "+pid+"#current: "+c+" resources ("+i+" of "+t+", "+(ms2-ms1)+"/"+(System.currentTimeMillis()-ms2)+"ms)");
} }
processor.finishPackage(ctxt); } else {
System.out.println("Processed: "+pid+"#current: "+c+" resources ("+i+" of "+t+", "+(ms2-ms1)+"/"+(System.currentTimeMillis()-ms2)+"ms)"); System.out.println("Ignored: "+pid+"#current: no version");
} }
} else {
System.out.println("Ignored: "+pid+"#current: no version");
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -370,4 +378,12 @@ public class PackageVisitor {
npm.name().startsWith("hl7.fhir.r5.")); npm.name().startsWith("hl7.fhir.r5."));
} }
public int getStep() {
return step;
}
public void setStep(int step) {
this.step = step;
}
} }

View File

@ -4507,7 +4507,7 @@ public class ProfileUtilities extends TranslatingUtilities {
public static boolean isModifierExtension(StructureDefinition sd) { public static boolean isModifierExtension(StructureDefinition sd) {
ElementDefinition defn = sd.getSnapshot().getElementByPath("Extension"); ElementDefinition defn = sd.getSnapshot().getElementByPath("Extension");
return defn.getIsModifier(); return defn != null && defn.getIsModifier();
} }
public boolean isForPublication() { public boolean isForPublication() {