rework package info handling in IWorkerContext
This commit is contained in:
parent
1aaf086c55
commit
91de7ec65b
|
@ -53,6 +53,7 @@ import org.hl7.fhir.exceptions.NoTerminologyServiceException;
|
|||
import org.hl7.fhir.exceptions.TerminologyServiceException;
|
||||
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
||||
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory;
|
||||
import org.hl7.fhir.r5.context.TerminologyCache.CacheToken;
|
||||
import org.hl7.fhir.r5.model.BooleanType;
|
||||
|
@ -159,7 +160,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
}
|
||||
|
||||
private Object lock = new Object(); // used as a lock for the data that follows
|
||||
protected String version;
|
||||
protected String version; // although the internal resources are all R5, the version of FHIR they describe may not be
|
||||
private String cacheId;
|
||||
private boolean isTxCaching;
|
||||
private Set<String> cached = new HashSet<>();
|
||||
|
@ -266,10 +267,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
}
|
||||
}
|
||||
|
||||
public void cachePackage(PackageVersion packageDetails, List<PackageVersion> dependencies) {
|
||||
// nothing yet
|
||||
}
|
||||
|
||||
|
||||
public void cacheResource(Resource r) throws FHIRException {
|
||||
cacheResourceFromPackage(r, null);
|
||||
}
|
||||
|
@ -1317,6 +1315,65 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
}
|
||||
}
|
||||
|
||||
public PackageVersion getPackageForUrl(String uri) {
|
||||
if (uri == null) {
|
||||
return null;
|
||||
}
|
||||
uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs());
|
||||
|
||||
synchronized (lock) {
|
||||
|
||||
String version = null;
|
||||
if (uri.contains("|")) {
|
||||
version = uri.substring(uri.lastIndexOf("|")+1);
|
||||
uri = uri.substring(0, uri.lastIndexOf("|"));
|
||||
}
|
||||
if (uri.contains("#")) {
|
||||
uri = uri.substring(0, uri.indexOf("#"));
|
||||
}
|
||||
if (structures.has(uri)) {
|
||||
return structures.getPackageInfo(uri, version);
|
||||
}
|
||||
if (guides.has(uri)) {
|
||||
return guides.getPackageInfo(uri, version);
|
||||
}
|
||||
if (capstmts.has(uri)) {
|
||||
return capstmts.getPackageInfo(uri, version);
|
||||
}
|
||||
if (measures.has(uri)) {
|
||||
return measures.getPackageInfo(uri, version);
|
||||
}
|
||||
if (libraries.has(uri)) {
|
||||
return libraries.getPackageInfo(uri, version);
|
||||
}
|
||||
if (valueSets.has(uri)) {
|
||||
return valueSets.getPackageInfo(uri, version);
|
||||
}
|
||||
if (codeSystems.has(uri)) {
|
||||
return codeSystems.getPackageInfo(uri, version);
|
||||
}
|
||||
if (operations.has(uri)) {
|
||||
return operations.getPackageInfo(uri, version);
|
||||
}
|
||||
if (searchParameters.has(uri)) {
|
||||
return searchParameters.getPackageInfo(uri, version);
|
||||
}
|
||||
if (plans.has(uri)) {
|
||||
return plans.getPackageInfo(uri, version);
|
||||
}
|
||||
if (maps.has(uri)) {
|
||||
return maps.getPackageInfo(uri, version);
|
||||
}
|
||||
if (transforms.has(uri)) {
|
||||
return transforms.getPackageInfo(uri, version);
|
||||
}
|
||||
if (questionnaires.has(uri)) {
|
||||
return questionnaires.getPackageInfo(uri, version);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Resource> T fetchResourceWithException(String cls, String uri, CanonicalResource source) throws FHIRException {
|
||||
if (uri == null) {
|
||||
|
|
|
@ -292,6 +292,20 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
|
|||
return map.containsKey(url) ? map.get(url).getResource() : null;
|
||||
}
|
||||
|
||||
public PackageVersion getPackageInfo(String system, String version) {
|
||||
if (version == null) {
|
||||
return map.containsKey(system) ? map.get(system).getPackageInfo() : null;
|
||||
} else {
|
||||
if (map.containsKey(system+"|"+version))
|
||||
return map.get(system+"|"+version).getPackageInfo();
|
||||
String mm = VersionUtilities.getMajMin(version);
|
||||
if (mm != null && map.containsKey(system+"|"+mm))
|
||||
return map.get(system+"|"+mm).getPackageInfo();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean has(String url) {
|
||||
return map.containsKey(url);
|
||||
}
|
||||
|
|
|
@ -170,6 +170,27 @@ public interface IWorkerContext {
|
|||
}
|
||||
}
|
||||
|
||||
public class PackageDetails extends PackageVersion {
|
||||
private String name;
|
||||
private String canonical;
|
||||
private String web;
|
||||
public PackageDetails(String id, String version, String name, String canonical, String web) {
|
||||
super(id, version);
|
||||
this.name = name;
|
||||
this.canonical = canonical;
|
||||
this.web = web;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getCanonical() {
|
||||
return canonical;
|
||||
}
|
||||
public String getWeb() {
|
||||
return web;
|
||||
}
|
||||
|
||||
}
|
||||
public interface ICanonicalResourceLocator {
|
||||
void findResource(Object caller, String url); // if it can be found, put it in the context
|
||||
}
|
||||
|
@ -387,7 +408,7 @@ public interface IWorkerContext {
|
|||
*
|
||||
* @param packageInfo
|
||||
*/
|
||||
public void cachePackage(PackageVersion packageDetails, List<PackageVersion> dependencies);
|
||||
public void cachePackage(PackageDetails packageDetails, List<PackageVersion> dependencies);
|
||||
|
||||
// -- profile services ---------------------------------------------------------
|
||||
|
||||
|
@ -779,10 +800,14 @@ public interface IWorkerContext {
|
|||
*/
|
||||
int loadFromPackageAndDependencies(NpmPackage pi, IContextResourceLoader loader, BasePackageCacheManager pcm) throws FileNotFoundException, IOException, FHIRException;
|
||||
|
||||
public boolean hasPackage(String id, String ver);
|
||||
public boolean hasPackage(String id, String ver);
|
||||
public boolean hasPackage(PackageVersion pack);
|
||||
public PackageDetails getPackage(PackageVersion pack);
|
||||
|
||||
public int getClientRetryCount();
|
||||
public IWorkerContext setClientRetryCount(int value);
|
||||
|
||||
public TimeTracker clock();
|
||||
|
||||
public PackageVersion getPackageForUrl(String url);
|
||||
}
|
|
@ -54,6 +54,7 @@ import org.hl7.fhir.exceptions.FHIRFormatError;
|
|||
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
||||
import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider;
|
||||
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory;
|
||||
import org.hl7.fhir.r5.context.SimpleWorkerContext.PackageResourceLoader;
|
||||
import org.hl7.fhir.r5.formats.IParser;
|
||||
|
@ -810,15 +811,6 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
this.progress = progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPackage(String id, String ver) {
|
||||
return loadedPackages.contains(id+"#"+ver);
|
||||
}
|
||||
|
||||
public boolean hasPackage(String idAndver) {
|
||||
return loadedPackages.contains(idAndver);
|
||||
}
|
||||
|
||||
public void setClock(TimeTracker tt) {
|
||||
clock = tt;
|
||||
}
|
||||
|
@ -837,5 +829,34 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
}
|
||||
return xverManager;
|
||||
}
|
||||
|
||||
public void cachePackage(PackageVersion packageDetails, List<PackageVersion> dependencies) {
|
||||
// nothing yet
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPackage(String id, String ver) {
|
||||
return loadedPackages.contains(id+"#"+ver);
|
||||
}
|
||||
|
||||
public boolean hasPackage(String idAndver) {
|
||||
return loadedPackages.contains(idAndver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cachePackage(PackageDetails packageDetails, List<PackageVersion> dependencies) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPackage(PackageVersion pack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageDetails getPackage(PackageVersion pack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue