Rework package generator

This commit is contained in:
jamesagnew 2020-06-02 18:16:08 -04:00
parent 6534a5358b
commit 20fab5e047
2 changed files with 18 additions and 7 deletions

View File

@ -11,10 +11,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public abstract class BasePackageCacheManager implements IPackageCacheManager {
private static final Logger ourLog = LoggerFactory.getLogger(BasePackageCacheManager.class);
private List<String> myPackageServers = new ArrayList<>();
private Function<String, PackageClient> myClientFactory = address -> new CachingPackageClient(address);
/**
* Constructor
@ -23,6 +25,14 @@ public abstract class BasePackageCacheManager implements IPackageCacheManager {
super();
}
/**
* Provide a new client factory implementation
*/
public void setClientFactory(Function<String, PackageClient> theClientFactory) {
Validate.notNull(theClientFactory, "theClientFactory must not be null");
myClientFactory = theClientFactory;
}
public List<String> getPackageServers() {
return myPackageServers;
}
@ -53,7 +63,7 @@ public abstract class BasePackageCacheManager implements IPackageCacheManager {
protected InputStreamWithSrc loadFromPackageServer(String id, String version) {
for (String nextPackageServer : getPackageServers()) {
CachingPackageClient packageClient = new CachingPackageClient(nextPackageServer);
PackageClient packageClient = myClientFactory.apply(nextPackageServer);
try {
if (Utilities.noString(version)) {
version = packageClient.getLatestVersion(id);
@ -92,8 +102,8 @@ public abstract class BasePackageCacheManager implements IPackageCacheManager {
private String getPackageUrl(String packageId, String server) throws IOException {
CachingPackageClient pc = new CachingPackageClient(server);
List<CachingPackageClient.PackageInfo> res = pc.search(packageId, null, null, false);
PackageClient pc = myClientFactory.apply(server);
List<PackageClient.PackageInfo> res = pc.search(packageId, null, null, false);
if (res.size() == 0) {
return null;
} else {
@ -117,13 +127,13 @@ public abstract class BasePackageCacheManager implements IPackageCacheManager {
}
private String getPackageId(String canonical, String server) throws IOException {
CachingPackageClient pc = new CachingPackageClient(server);
List<CachingPackageClient.PackageInfo> res = pc.search(null, canonical, null, false);
PackageClient pc = myClientFactory.apply(server);
List<PackageClient.PackageInfo> res = pc.search(null, canonical, null, false);
if (res.size() == 0) {
return null;
} 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 (CachingPackageClient.PackageInfo pi : res) {
for (PackageClient.PackageInfo pi : res) {
if (canonical.equals(pi.getCanonical())) {
return pi.getId();
}

View File

@ -100,7 +100,8 @@ public class PackageGenerator {
}
public PackageGenerator name(String value) {
object.addProperty("name", "@fhir/"+value);
// NOTE: I removed a prefix of "@fhir/" here. What was this for? -JA
object.addProperty("name", value);
return this;
}