fix package subsystem for challenge with hl7.fhir.au.base setup

This commit is contained in:
Grahame Grieve 2020-02-22 08:01:01 +11:00
parent 550aeffb9a
commit da2a59cf1a
2 changed files with 18 additions and 4 deletions

View File

@ -175,6 +175,7 @@ public class PackageCacheManager {
private static final String PRIMARY_SERVER = "http://packages.fhir.org"; private static final String PRIMARY_SERVER = "http://packages.fhir.org";
private static final String SECONDARY_SERVER = "http://test.fhir.org/packages"; private static final String SECONDARY_SERVER = "http://test.fhir.org/packages";
// private static final String SECONDARY_SERVER = "http://local.fhir.org:960/packages";
public static final String PACKAGE_REGEX = "^[a-z][a-z0-9\\_\\-]*(\\.[a-z0-9\\_\\-]+)+$"; public static final String PACKAGE_REGEX = "^[a-z][a-z0-9\\_\\-]*(\\.[a-z0-9\\_\\-]+)+$";
public static final String PACKAGE_VERSION_REGEX = "^[a-z][a-z0-9\\_\\-]*(\\.[a-z0-9\\_\\-]+)+\\#[a-z0-9\\-\\_]+(\\.[a-z0-9\\-\\_]+)*$"; public static final String PACKAGE_VERSION_REGEX = "^[a-z][a-z0-9\\_\\-]*(\\.[a-z0-9\\_\\-]+)+\\#[a-z0-9\\-\\_]+(\\.[a-z0-9\\-\\_]+)*$";
private static final String CACHE_VERSION = "3"; // second version - see wiki page private static final String CACHE_VERSION = "3"; // second version - see wiki page
@ -281,6 +282,12 @@ public class PackageCacheManager {
if (res.size() == 0) { if (res.size() == 0) {
return null; return null;
} else { } else {
// this is driven by HL7 Australia (http://hl7.org.au/fhir/ is the canonical url for the base package, and the root for all the others)
for (PackageInfo pi : res) {
if (canonical.equals(pi.getCanonical())) {
return pi.getId();
}
}
return res.get(0).getId(); return res.get(0).getId();
} }
} }

View File

@ -29,13 +29,16 @@ public class PackageClient {
private String fhirVersion; private String fhirVersion;
private String description; private String description;
private String url; private String url;
public PackageInfo(String id, String version, String fhirVersion, String description, String url) { private String canonical;
public PackageInfo(String id, String version, String fhirVersion, String description, String url, String canonical) {
super(); super();
this.id = id; this.id = id;
this.version = version; this.version = version;
this.fhirVersion = fhirVersion; this.fhirVersion = fhirVersion;
this.description = description; this.description = description;
this.url = url; this.url = url;
this.canonical = canonical;
} }
public String getId() { public String getId() {
return id; return id;
@ -52,9 +55,13 @@ public class PackageClient {
public String getUrl() { public String getUrl() {
return url; return url;
} }
public String getCanonical() {
return canonical;
}
@Override @Override
public String toString() { public String toString() {
return id+"#"+(version == null ? "??" : version)+(fhirVersion == null ? "": "for FHIR "+fhirVersion)+(url == null ? "" : " @"+url)+(description == null ? "" : " '"+description+"'"); return id+"#"+(version == null ? "??" : version)+(fhirVersion == null ? "": " ("+canonical+") for FHIR "+fhirVersion)+(url == null ? "" : " @"+url)+(description == null ? "" : " '"+description+"'");
} }
} }
@ -97,7 +104,7 @@ public class PackageClient {
if (versions != null) { if (versions != null) {
for (String v : sorted(versions.keySet())) { for (String v : sorted(versions.keySet())) {
JsonObject obj = versions.getAsJsonObject(v); JsonObject obj = versions.getAsJsonObject(v);
res.add(new PackageInfo(JSONUtil.str(obj, "name"), JSONUtil.str(obj, "version"), JSONUtil.str(obj, "FhirVersion"), JSONUtil.str(obj, "description"), JSONUtil.str(obj, "url"))); res.add(new PackageInfo(JSONUtil.str(obj, "name"), JSONUtil.str(obj, "version"), JSONUtil.str(obj, "FhirVersion"), JSONUtil.str(obj, "description"), JSONUtil.str(obj, "url"), JSONUtil.str(obj, "canonical")));
} }
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -131,7 +138,7 @@ public class PackageClient {
JsonArray json = fetchJsonArray(Utilities.pathURL(address, "catalog?")+params.toString()); JsonArray json = fetchJsonArray(Utilities.pathURL(address, "catalog?")+params.toString());
for (JsonElement e : json) { for (JsonElement e : json) {
JsonObject obj = (JsonObject) e; JsonObject obj = (JsonObject) e;
res.add(new PackageInfo(JSONUtil.str(obj, "Name"), null, JSONUtil.str(obj, "FhirVersion"), JSONUtil.str(obj, "Description"), null)); res.add(new PackageInfo(JSONUtil.str(obj, "Name", "name"), JSONUtil.str(obj, "Version", "version"), JSONUtil.str(obj, "FhirVersion", "fhirVersion"), JSONUtil.str(obj, "Description", "description"), JSONUtil.str(obj, "url"), JSONUtil.str(obj, "canonical")));
} }
} catch (IOException e1) { } catch (IOException e1) {
} }