add search on IG registry to PackageClient
This commit is contained in:
parent
46d1987cd0
commit
2e8953a81d
|
@ -911,33 +911,4 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//public List<String> getUrls() throws IOException {
|
||||
// if (allUrls == null)
|
||||
// {
|
||||
// IniFile ini = new IniFile(Utilities.path(cacheFolder, "packages.ini"));
|
||||
// allUrls = new ArrayList<>();
|
||||
// for (String s : ini.getPropertyNames("urls"))
|
||||
// allUrls.add(ini.getStringProperty("urls", s));
|
||||
// try {
|
||||
// URL url = new URL("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json?nocache=" + System.currentTimeMillis());
|
||||
// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
// connection.setRequestMethod("GET");
|
||||
// InputStream json = connection.getInputStream();
|
||||
// JsonObject packages = (JsonObject) new com.google.gson.JsonParser().parse(TextFile.streamToString(json));
|
||||
// JsonArray guides = packages.getAsJsonArray("guides");
|
||||
// for (JsonElement g : guides) {
|
||||
// JsonObject gi = (JsonObject) g;
|
||||
// if (gi.has("canonical"))
|
||||
// if (!allUrls.contains(gi.get("canonical").getAsString()))
|
||||
// allUrls.add(gi.get("canonical").getAsString());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Listing known Implementation Guides failed: "+e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// return allUrls;
|
||||
//}
|
||||
}
|
|
@ -8,6 +8,7 @@ import org.hl7.fhir.utilities.TextFile;
|
|||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.utilities.json.JSONUtil;
|
||||
import org.hl7.fhir.utilities.json.JsonTrackingParser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -223,4 +224,46 @@ public class PackageClient {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public List<PackageInfo> listFromRegistry(String name, String canonical, String fhirVersion) throws IOException {
|
||||
List<PackageInfo> result = new ArrayList<>();
|
||||
JsonObject packages = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json?nocache=" + System.currentTimeMillis());
|
||||
for (JsonObject o : JSONUtil.objects(packages, "guides")) {
|
||||
if (o.has("canonical")) {
|
||||
String id = JSONUtil.str(o, "npm-name");
|
||||
String pname = JSONUtil.str(o, "name");
|
||||
String pcanonical = JSONUtil.str(o, "canonical");
|
||||
String description = JSONUtil.str(o, "description");
|
||||
boolean ok = true;
|
||||
if (ok && !Utilities.noString(name)) {
|
||||
ok = (pname != null && pname.contains(name)) || (description != null && description.contains(name)) || (id != null && id.contains(name));
|
||||
}
|
||||
if (ok && !Utilities.noString(canonical)) {
|
||||
ok = pcanonical.contains(canonical);
|
||||
}
|
||||
String version = null;
|
||||
String fVersion = null;
|
||||
String url = null;
|
||||
|
||||
if (ok) {
|
||||
// if we can find something...
|
||||
for (JsonObject e : JSONUtil.objects(o, "editions")) {
|
||||
if (fhirVersion == null || fhirVersion.equals(JSONUtil.str(e, "fhir-version"))) {
|
||||
String v = JSONUtil.str(e, "ig-version");
|
||||
if (version == null || VersionUtilities.isThisOrLater(version, v)) {
|
||||
version = v;
|
||||
fVersion = e.getAsJsonArray("fhir-version").get(0).getAsString();
|
||||
url = JSONUtil.str(e, "url");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (version != null) {
|
||||
result.add(new PackageInfo(id, version, fVersion, description, url, pcanonical));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -104,4 +104,12 @@ public class CachingPackageClientTests {
|
|||
List<PackageInfo> matches = client.getVersions("Simplifier.Core.STU3X");
|
||||
Assertions.assertTrue(matches.size() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegistry() throws IOException {
|
||||
CachingPackageClient client = new CachingPackageClient("http://packages.fhir.org/packages");
|
||||
List<PackageInfo> matches1 = client.listFromRegistry(null, null, null);
|
||||
List<PackageInfo> matches2 = client.listFromRegistry(null, null, "4.0.1");
|
||||
Assertions.assertTrue(matches1.size() > matches2.size());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue