Rework package generator
This commit is contained in:
parent
6534a5358b
commit
20fab5e047
|
@ -11,10 +11,12 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public abstract class BasePackageCacheManager implements IPackageCacheManager {
|
public abstract class BasePackageCacheManager implements IPackageCacheManager {
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(BasePackageCacheManager.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(BasePackageCacheManager.class);
|
||||||
private List<String> myPackageServers = new ArrayList<>();
|
private List<String> myPackageServers = new ArrayList<>();
|
||||||
|
private Function<String, PackageClient> myClientFactory = address -> new CachingPackageClient(address);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -23,6 +25,14 @@ public abstract class BasePackageCacheManager implements IPackageCacheManager {
|
||||||
super();
|
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() {
|
public List<String> getPackageServers() {
|
||||||
return myPackageServers;
|
return myPackageServers;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +63,7 @@ public abstract class BasePackageCacheManager implements IPackageCacheManager {
|
||||||
protected InputStreamWithSrc loadFromPackageServer(String id, String version) {
|
protected InputStreamWithSrc loadFromPackageServer(String id, String version) {
|
||||||
|
|
||||||
for (String nextPackageServer : getPackageServers()) {
|
for (String nextPackageServer : getPackageServers()) {
|
||||||
CachingPackageClient packageClient = new CachingPackageClient(nextPackageServer);
|
PackageClient packageClient = myClientFactory.apply(nextPackageServer);
|
||||||
try {
|
try {
|
||||||
if (Utilities.noString(version)) {
|
if (Utilities.noString(version)) {
|
||||||
version = packageClient.getLatestVersion(id);
|
version = packageClient.getLatestVersion(id);
|
||||||
|
@ -92,8 +102,8 @@ public abstract class BasePackageCacheManager implements IPackageCacheManager {
|
||||||
|
|
||||||
|
|
||||||
private String getPackageUrl(String packageId, String server) throws IOException {
|
private String getPackageUrl(String packageId, String server) throws IOException {
|
||||||
CachingPackageClient pc = new CachingPackageClient(server);
|
PackageClient pc = myClientFactory.apply(server);
|
||||||
List<CachingPackageClient.PackageInfo> res = pc.search(packageId, null, null, false);
|
List<PackageClient.PackageInfo> res = pc.search(packageId, null, null, false);
|
||||||
if (res.size() == 0) {
|
if (res.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,13 +127,13 @@ public abstract class BasePackageCacheManager implements IPackageCacheManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPackageId(String canonical, String server) throws IOException {
|
private String getPackageId(String canonical, String server) throws IOException {
|
||||||
CachingPackageClient pc = new CachingPackageClient(server);
|
PackageClient pc = myClientFactory.apply(server);
|
||||||
List<CachingPackageClient.PackageInfo> res = pc.search(null, canonical, null, false);
|
List<PackageClient.PackageInfo> res = pc.search(null, canonical, null, false);
|
||||||
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)
|
// 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())) {
|
if (canonical.equals(pi.getCanonical())) {
|
||||||
return pi.getId();
|
return pi.getId();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,8 @@ public class PackageGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PackageGenerator name(String value) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue