refactor how types are handled loading packages
This commit is contained in:
parent
2e36c8147a
commit
19cb639d37
|
@ -1,6 +1,8 @@
|
|||
package org.hl7.fhir.convertors.loaders.loaderR5;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.r5.conformance.profile.ProfileUtilities;
|
||||
|
@ -36,12 +38,12 @@ public abstract class BaseLoaderR5 implements IContextResourceLoader {
|
|||
protected final String URL_ELEMENT_DEF_NAMESPACE = "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace";
|
||||
protected boolean patchUrls;
|
||||
@Getter @Setter protected boolean killPrimitives;
|
||||
@Getter protected String[] types;
|
||||
@Getter protected List<String> types = new ArrayList<>();
|
||||
protected ILoaderKnowledgeProviderR5 lkp;
|
||||
|
||||
public BaseLoaderR5(String[] types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
public BaseLoaderR5(List<String> types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
super();
|
||||
this.types = types;
|
||||
this.types.addAll(types);
|
||||
this.lkp = lkp;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class R2016MayToR5Loader extends BaseLoaderR5 {
|
|||
|
||||
private final BaseAdvisor_14_50 advisor = new BaseAdvisor_14_50();
|
||||
|
||||
public R2016MayToR5Loader(String[] types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
public R2016MayToR5Loader(List<String> types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
super(types, lkp);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class R2ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
|
|||
|
||||
private final BaseAdvisor_10_50 advisor = new BaseAdvisor_10_50();
|
||||
|
||||
public R2ToR5Loader(String[] types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
public R2ToR5Loader(List<String> types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
super(types, lkp);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class R3ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
|
|||
|
||||
private final BaseAdvisor_30_50 advisor = new BaseAdvisor_30_50();
|
||||
|
||||
public R3ToR5Loader(String[] types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
public R3ToR5Loader(List<String> types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
super(types, lkp);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ public class R4BToR5Loader extends BaseLoaderR5 implements IContextResourceLoade
|
|||
private final BaseAdvisor_40_50 advisor = new BaseAdvisor_40_50();
|
||||
private String version;
|
||||
|
||||
public R4BToR5Loader(String[] types, ILoaderKnowledgeProviderR5 lkp, String version) { // might be 4B
|
||||
public R4BToR5Loader(List<String> types, ILoaderKnowledgeProviderR5 lkp, String version) { // might be 4B
|
||||
super(types, lkp);
|
||||
this.version = version;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class R4ToR5Loader extends BaseLoaderR5 implements IContextResourceLoader
|
|||
private final BaseAdvisor_40_50 advisor = new BaseAdvisor_40_50();
|
||||
private String version;
|
||||
|
||||
public R4ToR5Loader(String[] types, ILoaderKnowledgeProviderR5 lkp, String version) { // might be 4B
|
||||
public R4ToR5Loader(List<String> types, ILoaderKnowledgeProviderR5 lkp, String version) { // might be 4B
|
||||
super(types, lkp);
|
||||
this.version = version;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class R5ToR5Loader extends BaseLoaderR5 {
|
|||
// TODO Grahame, will this ever be populated? No conversion is being done?
|
||||
private final List<CodeSystem> cslist = new ArrayList<>();
|
||||
|
||||
public R5ToR5Loader(String[] types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
public R5ToR5Loader(List<String> types, ILoaderKnowledgeProviderR5 lkp) {
|
||||
super(types, lkp);
|
||||
}
|
||||
|
||||
|
|
|
@ -274,7 +274,7 @@ public interface IWorkerContext {
|
|||
/**
|
||||
* @return List of the resource types that should be loaded
|
||||
*/
|
||||
String[] getTypes();
|
||||
List<String> getTypes();
|
||||
|
||||
/**
|
||||
* Request to actually load the resources and do whatever is required
|
||||
|
@ -804,7 +804,7 @@ public interface IWorkerContext {
|
|||
* @return the number of resources loaded
|
||||
*/
|
||||
@Deprecated
|
||||
int loadFromPackage(NpmPackage pi, IContextResourceLoader loader, String[] types) throws FileNotFoundException, IOException, FHIRException;
|
||||
int loadFromPackage(NpmPackage pi, IContextResourceLoader loader, List<String> types) throws FileNotFoundException, IOException, FHIRException;
|
||||
|
||||
/**
|
||||
* Load relevant resources of the appropriate types (as specified by the loader) from the nominated package
|
||||
|
|
|
@ -423,16 +423,16 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
return loadFromPackageInt(pi, loader, loader == null ? defaultTypesToLoad() : loader.getTypes());
|
||||
}
|
||||
|
||||
public static String[] defaultTypesToLoad() {
|
||||
public static List<String> defaultTypesToLoad() {
|
||||
// there's no penalty for listing resources that don't exist, so we just all the relevant possibilities for all versions
|
||||
return new String[] {"CodeSystem", "ValueSet", "ConceptMap", "NamingSystem",
|
||||
return Utilities.strings("CodeSystem", "ValueSet", "ConceptMap", "NamingSystem",
|
||||
"StructureDefinition", "StructureMap",
|
||||
"SearchParameter", "OperationDefinition", "CapabilityStatement", "Conformance",
|
||||
"Questionnaire", "ImplementationGuide", "Measure" };
|
||||
"Questionnaire", "ImplementationGuide", "Measure" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int loadFromPackage(NpmPackage pi, IContextResourceLoader loader, String[] types) throws IOException, FHIRException {
|
||||
public int loadFromPackage(NpmPackage pi, IContextResourceLoader loader, List<String> types) throws IOException, FHIRException {
|
||||
return loadFromPackageInt(pi, loader, types);
|
||||
}
|
||||
|
||||
|
@ -457,7 +457,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
}
|
||||
|
||||
|
||||
public int loadFromPackageInt(NpmPackage pi, IContextResourceLoader loader, String... types) throws IOException, FHIRException {
|
||||
public int loadFromPackageInt(NpmPackage pi, IContextResourceLoader loader, List<String> types) throws IOException, FHIRException {
|
||||
int t = 0;
|
||||
if (progress) {
|
||||
System.out.println("Load Package "+pi.name()+"#"+pi.version());
|
||||
|
@ -471,13 +471,13 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
packageTracker.packageLoaded(pi.id(), pi.version());
|
||||
}
|
||||
|
||||
if ((types == null || types.length == 0) && loader != null) {
|
||||
if ((types == null || types.size() == 0) && loader != null) {
|
||||
types = loader.getTypes();
|
||||
}
|
||||
if (VersionUtilities.isR2Ver(pi.fhirVersion()) || !pi.canLazyLoad() || !allowLazyLoading) {
|
||||
// can't lazy load R2 because of valueset/codesystem implementation
|
||||
if (types.length == 0) {
|
||||
types = new String[] { "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
|
||||
if (types == null || types.size() == 0) {
|
||||
types = Utilities.strings("StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" );
|
||||
}
|
||||
for (String s : pi.listResources(types)) {
|
||||
try {
|
||||
|
@ -488,8 +488,8 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (types.length == 0) {
|
||||
types = new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem", "Measures" };
|
||||
if (types == null || types.size() == 0) {
|
||||
types = Utilities.strings("StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem", "Measures" );
|
||||
}
|
||||
for (PackageResourceInformation pri : pi.listIndexedResources(types)) {
|
||||
if (!pri.getFilename().contains("ig-r4")) {
|
||||
|
|
|
@ -16,9 +16,9 @@ import org.hl7.fhir.utilities.npm.NpmPackage;
|
|||
|
||||
public class TestPackageLoader implements IContextResourceLoader {
|
||||
|
||||
private String[] types;
|
||||
private List<String> types;
|
||||
|
||||
public TestPackageLoader(String[] types) {
|
||||
public TestPackageLoader(List<String> types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class TestPackageLoader implements IContextResourceLoader {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String[] getTypes() {
|
||||
public List<String> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
|
|
|
@ -126,12 +126,12 @@ public class TestingUtilities extends BaseTestingUtilities {
|
|||
if (!fcontext.hasPackage("hl7.terminology.r5", null)) {
|
||||
NpmPackage utg = pcm.loadPackage("hl7.terminology.r5");
|
||||
System.out.println("Loading THO: "+utg.name()+"#"+utg.version());
|
||||
fcontext.loadFromPackage(utg, new TestPackageLoader(new String[]{"CodeSystem", "ValueSet"}));
|
||||
fcontext.loadFromPackage(utg, new TestPackageLoader(Utilities.strings("CodeSystem", "ValueSet")));
|
||||
}
|
||||
if (!fcontext.hasPackage("hl7.fhir.uv.extensions", null)) {
|
||||
NpmPackage ext = pcm.loadPackage("hl7.fhir.uv.extensions", "current");
|
||||
System.out.println("Loading Extensions: "+ext.name()+"#"+ext.version());
|
||||
fcontext.loadFromPackage(ext, new TestPackageLoader(new String[]{"CodeSystem", "ValueSet", "StructureDefinition"}));
|
||||
fcontext.loadFromPackage(ext, new TestPackageLoader(Utilities.strings("CodeSystem", "ValueSet", "StructureDefinition")));
|
||||
}
|
||||
R5Hacker.fixR5BrokenResources(fcontext);
|
||||
return fcontext;
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
|
|||
import org.hl7.fhir.r5.profilemodel.PEInstance.PEInstanceDataKind;
|
||||
import org.hl7.fhir.r5.test.utils.TestPackageLoader;
|
||||
import org.hl7.fhir.r5.test.utils.TestingUtilities;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
|
||||
import org.hl7.fhir.utilities.npm.NpmPackage;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
@ -38,7 +39,7 @@ public class PETests {
|
|||
ctxt = TestingUtilities.getSharedWorkerContext();
|
||||
FilesystemPackageCacheManager pc = new FilesystemPackageCacheManager(true);
|
||||
NpmPackage npm = pc.loadPackage("hl7.fhir.us.core", "5.0.0");
|
||||
ctxt.loadFromPackage(npm, new TestPackageLoader(new String[] { "StructureDefinition" }));
|
||||
ctxt.loadFromPackage(npm, new TestPackageLoader(Utilities.strings("StructureDefinition" )));
|
||||
|
||||
ctxt.cacheResource(new JsonParser().parse(TestingUtilities.loadTestResource("r5", "profiles", "pe-extension-simple.json")));
|
||||
ctxt.cacheResource(new JsonParser().parse(TestingUtilities.loadTestResource("r5", "profiles", "pe-extension-complex.json")));
|
||||
|
|
|
@ -215,7 +215,7 @@ public class NarrativeGenerationTests {
|
|||
context = TestingUtilities.getSharedWorkerContext("5.0.0");
|
||||
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true);
|
||||
NpmPackage ips = pcm.loadPackage("hl7.fhir.uv.ips#1.1.0");
|
||||
context.loadFromPackage(ips, new TestPackageLoader(new String[] { "StructureDefinition", "ValueSet" }));
|
||||
context.loadFromPackage(ips, new TestPackageLoader(Utilities.strings("StructureDefinition", "ValueSet" )));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{index}: file {0}")
|
||||
|
|
|
@ -536,7 +536,7 @@ public class SnapShotGenerationTests {
|
|||
pu.setAllowUnknownProfile(test.allow);
|
||||
if (!TestingUtilities.getSharedWorkerContext().hasPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER)) {
|
||||
NpmPackage npm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
|
||||
TestingUtilities.getSharedWorkerContext().loadFromPackage(npm, new TestPackageLoader(new String[]{"StructureDefinition"}), new String[]{"StructureDefinition"});
|
||||
TestingUtilities.getSharedWorkerContext().loadFromPackage(npm, new TestPackageLoader(Utilities.strings("StructureDefinition")), Utilities.strings("StructureDefinition"));
|
||||
}
|
||||
pu.setXver(new XVerExtensionManager(TestingUtilities.getSharedWorkerContext()));
|
||||
if (test.isSort()) {
|
||||
|
|
|
@ -1994,6 +1994,14 @@ public class Utilities {
|
|||
}
|
||||
}
|
||||
|
||||
public static List<String> strings(String... members) {
|
||||
List<String> ret = new ArrayList<>();
|
||||
for (String m : members) {
|
||||
ret.add(m);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//public static boolean !isWhitespace(String s) {
|
||||
|
|
|
@ -548,9 +548,13 @@ public class NpmPackage {
|
|||
}
|
||||
|
||||
public List<String> listResources(String... types) throws IOException {
|
||||
return listResources(Utilities.strings(types));
|
||||
}
|
||||
|
||||
public List<String> listResources(List<String> types) throws IOException {
|
||||
List<String> res = new ArrayList<String>();
|
||||
NpmPackageFolder folder = folders.get("package");
|
||||
if (types.length == 0) {
|
||||
if (types.size() == 0) {
|
||||
for (String s : folder.types.keySet()) {
|
||||
if (folder.types.containsKey(s)) {
|
||||
res.addAll(folder.types.get(s));
|
||||
|
@ -568,6 +572,10 @@ public class NpmPackage {
|
|||
}
|
||||
|
||||
public List<PackageResourceInformation> listIndexedResources(String... types) throws IOException {
|
||||
return listIndexedResources(Utilities.strings(types));
|
||||
}
|
||||
|
||||
public List<PackageResourceInformation> listIndexedResources(List<String> types) throws IOException {
|
||||
List<PackageResourceInformation> res = new ArrayList<PackageResourceInformation>();
|
||||
for (NpmPackageFolder folder : folders.values()) {
|
||||
if (folder.index != null) {
|
||||
|
|
|
@ -105,13 +105,13 @@ public class UtilitiesXTests {
|
|||
if (Utilities.noString(version))
|
||||
return null;
|
||||
if (version.startsWith("1.0"))
|
||||
return new R2ToR5Loader(new String[] { "Conformance", "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5());
|
||||
return new R2ToR5Loader(Utilities.strings("Conformance", "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5());
|
||||
if (version.startsWith("1.4"))
|
||||
return new R2016MayToR5Loader(new String[] { "Conformance", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5()); // special case
|
||||
return new R2016MayToR5Loader(Utilities.strings("Conformance", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5()); // special case
|
||||
if (version.startsWith("3.0"))
|
||||
return new R3ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5());
|
||||
return new R3ToR5Loader(Utilities.strings("CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5());
|
||||
if (version.startsWith("4.0"))
|
||||
return new R4ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5(), version);
|
||||
return new R4ToR5Loader(Utilities.strings("CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5(), version);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue