Refactor SimpleWorkerContext and ValidationEngine
This commit is contained in:
parent
5092be9a1d
commit
847ede5f88
|
@ -18,8 +18,9 @@ public class OIDBasedValueSetImporter {
|
|||
protected void init() throws FHIRException, IOException {
|
||||
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||
NpmPackage npm = pcm.loadPackage("hl7.fhir.r5.core", "current");
|
||||
SimpleWorkerContext ctxt = SimpleWorkerContext.fromPackage(npm);
|
||||
ctxt.setAllowLoadingDuplicates(true);
|
||||
SimpleWorkerContext ctxt = new SimpleWorkerContext.SimpleWorkerContextBuilder().withAllowDuplicates(true).fromPackage(npm);
|
||||
//DIRTY
|
||||
// ctxt.setAllowLoadingDuplicates(true);
|
||||
ctxt.loadFromPackage(pcm.loadPackage("hl7.terminology"), null);
|
||||
context = ctxt;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.hl7.fhir.dstu3.utils.ResourceUtilities;
|
|||
import org.hl7.fhir.dstu3.utils.client.EFhirClientException;
|
||||
import org.hl7.fhir.dstu3.utils.client.ResourceFormat;
|
||||
import org.hl7.fhir.utilities.ToolingClientLogger;
|
||||
import org.hl7.fhir.utilities.TxInterceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -163,7 +162,6 @@ public class FhirRequestBuilder {
|
|||
|
||||
return okHttpClient.newBuilder()
|
||||
.addInterceptor(new RetryInterceptor(retryCount))
|
||||
.addInterceptor(TxInterceptor.getInstance())
|
||||
.connectTimeout(timeout, timeoutUnit)
|
||||
.writeTimeout(timeout, timeoutUnit)
|
||||
.readTimeout(timeout, timeoutUnit)
|
||||
|
|
|
@ -11,12 +11,8 @@ import org.hl7.fhir.r4.model.Resource;
|
|||
import org.hl7.fhir.r4.utils.ResourceUtilities;
|
||||
import org.hl7.fhir.r4.utils.client.EFhirClientException;
|
||||
import org.hl7.fhir.r4.utils.client.ResourceFormat;
|
||||
import org.hl7.fhir.utilities.ToolingClientLogger;
|
||||
import org.hl7.fhir.utilities.TxInterceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -165,7 +161,6 @@ public class FhirRequestBuilder {
|
|||
OkHttpClient.Builder builder = okHttpClient.newBuilder();
|
||||
if (logger != null) builder.addInterceptor(logger);
|
||||
builder.addInterceptor(new RetryInterceptor(retryCount));
|
||||
builder.addInterceptor(TxInterceptor.getInstance());
|
||||
|
||||
return builder.connectTimeout(timeout, timeoutUnit)
|
||||
.addInterceptor(new RetryInterceptor(retryCount))
|
||||
|
|
|
@ -163,7 +163,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
|
||||
public class MetadataResourceVersionComparator<T extends CanonicalResource> implements Comparator<T> {
|
||||
|
||||
private List<T> list;
|
||||
final private List<T> list;
|
||||
|
||||
public MetadataResourceVersionComparator(List<T> list) {
|
||||
this.list = list;
|
||||
|
@ -197,26 +197,26 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
private boolean isTxCaching;
|
||||
@Getter
|
||||
private int serverQueryCount = 0;
|
||||
private Set<String> cached = new HashSet<>();
|
||||
private final Set<String> cached = new HashSet<>();
|
||||
|
||||
private Map<String, Map<String, ResourceProxy>> allResourcesById = new HashMap<String, Map<String, ResourceProxy>>();
|
||||
// all maps are to the full URI
|
||||
private CanonicalResourceManager<CodeSystem> codeSystems = new CanonicalResourceManager<CodeSystem>(false);
|
||||
private Set<String> supportedCodeSystems = new HashSet<String>();
|
||||
private Set<String> unsupportedCodeSystems = new HashSet<String>(); // know that the terminology server doesn't support them
|
||||
private final Set<String> supportedCodeSystems = new HashSet<String>();
|
||||
private final Set<String> unsupportedCodeSystems = new HashSet<String>(); // know that the terminology server doesn't support them
|
||||
private CanonicalResourceManager<ValueSet> valueSets = new CanonicalResourceManager<ValueSet>(false);
|
||||
private CanonicalResourceManager<ConceptMap> maps = new CanonicalResourceManager<ConceptMap>(false);
|
||||
protected CanonicalResourceManager<StructureMap> transforms = new CanonicalResourceManager<StructureMap>(false);
|
||||
private CanonicalResourceManager<StructureDefinition> structures = new CanonicalResourceManager<StructureDefinition>(false);
|
||||
private CanonicalResourceManager<Measure> measures = new CanonicalResourceManager<Measure>(false);
|
||||
private CanonicalResourceManager<Library> libraries = new CanonicalResourceManager<Library>(false);
|
||||
private final CanonicalResourceManager<Measure> measures = new CanonicalResourceManager<Measure>(false);
|
||||
private final CanonicalResourceManager<Library> libraries = new CanonicalResourceManager<Library>(false);
|
||||
private CanonicalResourceManager<ImplementationGuide> guides = new CanonicalResourceManager<ImplementationGuide>(false);
|
||||
private CanonicalResourceManager<CapabilityStatement> capstmts = new CanonicalResourceManager<CapabilityStatement>(false);
|
||||
private CanonicalResourceManager<SearchParameter> searchParameters = new CanonicalResourceManager<SearchParameter>(false);
|
||||
private CanonicalResourceManager<Questionnaire> questionnaires = new CanonicalResourceManager<Questionnaire>(false);
|
||||
private CanonicalResourceManager<OperationDefinition> operations = new CanonicalResourceManager<OperationDefinition>(false);
|
||||
private CanonicalResourceManager<PlanDefinition> plans = new CanonicalResourceManager<PlanDefinition>(false);
|
||||
private CanonicalResourceManager<NamingSystem> systems = new CanonicalResourceManager<NamingSystem>(false);
|
||||
private final CanonicalResourceManager<CapabilityStatement> capstmts = new CanonicalResourceManager<CapabilityStatement>(false);
|
||||
private final CanonicalResourceManager<SearchParameter> searchParameters = new CanonicalResourceManager<SearchParameter>(false);
|
||||
private final CanonicalResourceManager<Questionnaire> questionnaires = new CanonicalResourceManager<Questionnaire>(false);
|
||||
private final CanonicalResourceManager<OperationDefinition> operations = new CanonicalResourceManager<OperationDefinition>(false);
|
||||
private final CanonicalResourceManager<PlanDefinition> plans = new CanonicalResourceManager<PlanDefinition>(false);
|
||||
private final CanonicalResourceManager<NamingSystem> systems = new CanonicalResourceManager<NamingSystem>(false);
|
||||
|
||||
private UcumService ucumService;
|
||||
protected Map<String, byte[]> binaries = new HashMap<String, byte[]>();
|
||||
|
@ -228,7 +228,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
private boolean allowLoadingDuplicates;
|
||||
|
||||
protected TerminologyClient txClient;
|
||||
private Set<String> codeSystemsUsed = new HashSet<>();
|
||||
private final Set<String> codeSystemsUsed = new HashSet<>();
|
||||
protected ToolingClientLogger txLog;
|
||||
private TerminologyCapabilities txcaps;
|
||||
private boolean canRunWithoutTerminology;
|
||||
|
@ -245,19 +245,17 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
private ICanonicalResourceLocator locator;
|
||||
protected String userAgent;
|
||||
|
||||
public BaseWorkerContext() throws FileNotFoundException, IOException, FHIRException {
|
||||
txCache = new TerminologyCache(lock, null);
|
||||
protected BaseWorkerContext() throws FileNotFoundException, IOException, FHIRException {
|
||||
setValidationMessageLanguage(getLocale());
|
||||
clock = new TimeTracker();
|
||||
}
|
||||
|
||||
public BaseWorkerContext(Locale locale) throws FileNotFoundException, IOException, FHIRException {
|
||||
txCache = new TerminologyCache(lock, null);
|
||||
protected BaseWorkerContext(Locale locale) throws FileNotFoundException, IOException, FHIRException {
|
||||
setValidationMessageLanguage(locale);
|
||||
clock = new TimeTracker();
|
||||
}
|
||||
|
||||
public BaseWorkerContext(CanonicalResourceManager<CodeSystem> codeSystems, CanonicalResourceManager<ValueSet> valueSets, CanonicalResourceManager<ConceptMap> maps, CanonicalResourceManager<StructureDefinition> profiles,
|
||||
protected BaseWorkerContext(CanonicalResourceManager<CodeSystem> codeSystems, CanonicalResourceManager<ValueSet> valueSets, CanonicalResourceManager<ConceptMap> maps, CanonicalResourceManager<StructureDefinition> profiles,
|
||||
CanonicalResourceManager<ImplementationGuide> guides) throws FileNotFoundException, IOException, FHIRException {
|
||||
this();
|
||||
this.codeSystems = codeSystems;
|
||||
|
@ -1255,8 +1253,8 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
|
||||
// --------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public void initTS(String cachePath) throws IOException {
|
||||
if (!new File(cachePath).exists()) {
|
||||
protected void initTS(String cachePath) throws IOException {
|
||||
if (cachePath != null && !new File(cachePath).exists()) {
|
||||
Utilities.createDirectory(cachePath);
|
||||
}
|
||||
txCache = new TerminologyCache(lock, cachePath);
|
||||
|
@ -2245,7 +2243,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||
return userAgent;
|
||||
}
|
||||
|
||||
public void setUserAgent(String userAgent) {
|
||||
protected void setUserAgent(String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
if (txClient != null)
|
||||
txClient.setUserAgent(userAgent);
|
||||
|
|
|
@ -47,6 +47,10 @@ import java.util.Set;
|
|||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import com.google.errorprone.annotations.CompatibleWith;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.With;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.exceptions.DefinitionException;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
|
@ -142,20 +146,20 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
private boolean canNoTS;
|
||||
private XVerExtensionManager xverManager;
|
||||
|
||||
public SimpleWorkerContext() throws FileNotFoundException, IOException, FHIRException {
|
||||
private SimpleWorkerContext() throws FileNotFoundException, IOException, FHIRException {
|
||||
super();
|
||||
}
|
||||
|
||||
public SimpleWorkerContext(Locale locale) throws FileNotFoundException, IOException, FHIRException {
|
||||
private SimpleWorkerContext(Locale locale) throws FileNotFoundException, IOException, FHIRException {
|
||||
super(locale);
|
||||
}
|
||||
|
||||
public SimpleWorkerContext(SimpleWorkerContext other) throws FileNotFoundException, IOException, FHIRException {
|
||||
private SimpleWorkerContext(SimpleWorkerContext other) throws FileNotFoundException, IOException, FHIRException {
|
||||
super();
|
||||
copy(other);
|
||||
}
|
||||
|
||||
public SimpleWorkerContext(SimpleWorkerContext other, Locale locale) throws FileNotFoundException, IOException, FHIRException {
|
||||
private SimpleWorkerContext(SimpleWorkerContext other, Locale locale) throws FileNotFoundException, IOException, FHIRException {
|
||||
super(locale);
|
||||
copy(other);
|
||||
}
|
||||
|
@ -176,91 +180,98 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
|
|||
}
|
||||
|
||||
// -- Initializations
|
||||
/**
|
||||
* Load the working context from the validation pack
|
||||
*
|
||||
* @param path
|
||||
* filename of the validation pack
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws FileNotFoundException
|
||||
* @throws FHIRException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static SimpleWorkerContext fromPack(String path) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.loadFromPack(path, null);
|
||||
return res;
|
||||
}
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public static class SimpleWorkerContextBuilder {
|
||||
|
||||
public static SimpleWorkerContext fromPackage(NpmPackage pi, boolean allowDuplicates) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.setAllowLoadingDuplicates(allowDuplicates);
|
||||
res.loadFromPackage(pi, null);
|
||||
return res;
|
||||
}
|
||||
final SimpleWorkerContext context;
|
||||
@With
|
||||
private String terminologyCachePath;
|
||||
@With
|
||||
private boolean cacheTerminologyClientErrors;
|
||||
@With
|
||||
private boolean alwaysUseTerminologyServer;
|
||||
@With
|
||||
private boolean readOnlyCache;
|
||||
|
||||
public static SimpleWorkerContext fromPackage(NpmPackage pi) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.loadFromPackage(pi, null);
|
||||
return res;
|
||||
}
|
||||
@With
|
||||
private String userAgent;
|
||||
|
||||
public static SimpleWorkerContext fromPackage(NpmPackage pi, IContextResourceLoader loader) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.setAllowLoadingDuplicates(true);
|
||||
res.version = pi.getNpm().get("version").getAsString();
|
||||
res.loadFromPackage(pi, loader);
|
||||
res.finishLoading();
|
||||
return res;
|
||||
}
|
||||
@With
|
||||
boolean allowDuplicates;
|
||||
|
||||
public static SimpleWorkerContext fromPack(String path, boolean allowDuplicates) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.setAllowLoadingDuplicates(allowDuplicates);
|
||||
res.loadFromPack(path, null);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static SimpleWorkerContext fromPack(String path, IContextResourceLoader loader) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.loadFromPack(path, loader);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static SimpleWorkerContext fromClassPath() throws IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.loadFromStream(SimpleWorkerContext.class.getResourceAsStream("validation.json.zip"), null);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static SimpleWorkerContext fromClassPath(String name) throws IOException, FHIRException {
|
||||
return fromClassPath(name, false);
|
||||
}
|
||||
public static SimpleWorkerContext fromClassPath(String name, boolean allowDuplicates) throws IOException, FHIRException {
|
||||
InputStream s = SimpleWorkerContext.class.getResourceAsStream("/" + name);
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
res.setAllowLoadingDuplicates(allowDuplicates);
|
||||
res.loadFromStream(s, null);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static SimpleWorkerContext fromDefinitions(Map<String, byte[]> source, IContextResourceLoader loader, PackageVersion pi) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
for (String name : source.keySet()) {
|
||||
try {
|
||||
res.loadDefinitionItem(name, new ByteArrayInputStream(source.get(name)), loader, null, pi);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error loading "+name+": "+e.getMessage());
|
||||
throw new FHIRException("Error loading "+name+": "+e.getMessage(), e);
|
||||
}
|
||||
public SimpleWorkerContextBuilder() throws IOException {
|
||||
context = new SimpleWorkerContext();
|
||||
terminologyCachePath = null;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static SimpleWorkerContext fromNothing() throws FileNotFoundException, FHIRException, IOException {
|
||||
SimpleWorkerContext res = new SimpleWorkerContext();
|
||||
return res;
|
||||
public SimpleWorkerContext build() throws IOException {
|
||||
context.initTS(terminologyCachePath);
|
||||
context.setUserAgent(userAgent);
|
||||
return context;
|
||||
}
|
||||
|
||||
public SimpleWorkerContext fromPackage(NpmPackage pi) throws IOException, FHIRException {
|
||||
context.setAllowLoadingDuplicates(allowDuplicates);
|
||||
context.loadFromPackage(pi, null);
|
||||
return build();
|
||||
}
|
||||
|
||||
public SimpleWorkerContext fromPackage(NpmPackage pi, IContextResourceLoader loader) throws FileNotFoundException, IOException, FHIRException {
|
||||
context.setAllowLoadingDuplicates(true);
|
||||
context.version = pi.getNpm().get("version").getAsString();
|
||||
context.loadFromPackage(pi, loader);
|
||||
context.finishLoading();
|
||||
return build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the working context from the validation pack
|
||||
*
|
||||
* @param path
|
||||
* filename of the validation pack
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws FileNotFoundException
|
||||
* @throws FHIRException
|
||||
* @throws Exception
|
||||
*/
|
||||
public SimpleWorkerContext fromPack(String path) throws IOException, FHIRException {
|
||||
context.setAllowLoadingDuplicates(allowDuplicates);
|
||||
context.loadFromPack(path, null);
|
||||
return build();
|
||||
}
|
||||
|
||||
public SimpleWorkerContext fromPack(String path, IContextResourceLoader loader) throws IOException, FHIRException {
|
||||
context.loadFromPack(path, loader);
|
||||
return build();
|
||||
}
|
||||
|
||||
public SimpleWorkerContext fromClassPath() throws IOException, FHIRException {
|
||||
context.loadFromStream(SimpleWorkerContext.class.getResourceAsStream("validation.json.zip"), null);
|
||||
return build();
|
||||
}
|
||||
|
||||
public SimpleWorkerContext fromClassPath(String name) throws IOException, FHIRException {
|
||||
InputStream s = SimpleWorkerContext.class.getResourceAsStream("/" + name);
|
||||
context.setAllowLoadingDuplicates(allowDuplicates);
|
||||
context.loadFromStream(s, null);
|
||||
return build();
|
||||
}
|
||||
|
||||
public SimpleWorkerContext fromDefinitions(Map<String, byte[]> source, IContextResourceLoader loader, PackageVersion pi) throws FileNotFoundException, IOException, FHIRException {
|
||||
for (String name : source.keySet()) {
|
||||
try {
|
||||
context.loadDefinitionItem(name, new ByteArrayInputStream(source.get(name)), loader, null, pi);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error loading "+name+": "+e.getMessage());
|
||||
throw new FHIRException("Error loading "+name+": "+e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return build();
|
||||
}
|
||||
public SimpleWorkerContext fromNothing() throws FileNotFoundException, FHIRException, IOException {
|
||||
return build();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadDefinitionItem(String name, InputStream stream, IContextResourceLoader loader, ILoadFilter filter, PackageVersion pi) throws IOException, FHIRException {
|
||||
|
|
|
@ -52,7 +52,7 @@ import com.google.gson.JsonObject;
|
|||
public class Tester {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
IWorkerContext context = SimpleWorkerContext.fromPack(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", "validation-min.xml.zip"));
|
||||
IWorkerContext context = new SimpleWorkerContext.SimpleWorkerContextBuilder().fromPack(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", "validation-min.xml.zip"));
|
||||
int t = 0;
|
||||
int ok = 0;
|
||||
for (String f : new File("C:\\work\\org.hl7.fhir\\build\\publish").list()) {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package org.hl7.fhir.r5.test.utils;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.lang.String;
|
||||
|
||||
public class TestConstants {
|
||||
public static final java.lang.String TX_CACHE = Paths.get("src","test","resources", "txCache").toAbsolutePath().toString();
|
||||
public static final String TX_CACHE = Paths.get("src","test","resources", "txCache").toAbsolutePath().toString();
|
||||
public static final String USER_AGENT = "fhir/r5-test-cases";
|
||||
}
|
||||
|
|
|
@ -105,18 +105,14 @@ public class TestingUtilities extends BaseTestingUtilities {
|
|||
}
|
||||
|
||||
public static SimpleWorkerContext getWorkerContext(NpmPackage npmPackage) throws Exception {
|
||||
SimpleWorkerContext swc = SimpleWorkerContext.fromPackage(npmPackage);
|
||||
swc.initTS(TestConstants.TX_CACHE);
|
||||
SimpleWorkerContext swc = new SimpleWorkerContext.SimpleWorkerContextBuilder().withUserAgent(TestConstants.USER_AGENT).withTerminologyCachePath(TestConstants.TX_CACHE).fromPackage(npmPackage);
|
||||
TerminologyCache.setCacheErrors(true);
|
||||
swc.setUserAgent("fhir/r5-test-cases");
|
||||
return swc;
|
||||
}
|
||||
|
||||
public static SimpleWorkerContext getWorkerContext(NpmPackage npmPackage, IWorkerContext.IContextResourceLoader loader) throws Exception {
|
||||
SimpleWorkerContext swc = SimpleWorkerContext.fromPackage(npmPackage, loader);
|
||||
swc.initTS(TestConstants.TX_CACHE);
|
||||
SimpleWorkerContext swc = new SimpleWorkerContext.SimpleWorkerContextBuilder().withUserAgent(TestConstants.USER_AGENT).withTerminologyCachePath(TestConstants.TX_CACHE).fromPackage(npmPackage, loader);
|
||||
TerminologyCache.setCacheErrors(true);
|
||||
swc.setUserAgent("fhir/r5-test-cases");
|
||||
return swc;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ import org.hl7.fhir.r5.model.Resource;
|
|||
import org.hl7.fhir.r5.utils.ResourceUtilities;
|
||||
import org.hl7.fhir.r5.utils.client.EFhirClientException;
|
||||
import org.hl7.fhir.r5.utils.client.ResourceFormat;
|
||||
import org.hl7.fhir.utilities.TxInterceptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
@ -162,7 +161,6 @@ public class FhirRequestBuilder {
|
|||
OkHttpClient.Builder builder = okHttpClient.newBuilder();
|
||||
if (logger != null) builder.addInterceptor(logger);
|
||||
builder.addInterceptor(new RetryInterceptor(retryCount));
|
||||
builder.addInterceptor(TxInterceptor.getInstance());
|
||||
return builder.connectTimeout(timeout, timeoutUnit)
|
||||
.writeTimeout(timeout, timeoutUnit)
|
||||
.readTimeout(timeout, timeoutUnit)
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ValidationTestConvertor {
|
|||
* @throws FileNotFoundException
|
||||
*/
|
||||
public static void main(String[] args) throws FileNotFoundException, IOException, FHIRException {
|
||||
SimpleWorkerContext context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
|
||||
SimpleWorkerContext context = new SimpleWorkerContext.SimpleWorkerContextBuilder().fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
|
||||
for (File f : new File("C:\\work\\org.hl7.fhir\\build\\tests\\validation-examples").listFiles()) {
|
||||
if (f.getAbsolutePath().endsWith(".xml")) {
|
||||
File t = new File(Utilities.changeFileExt(f.getAbsolutePath(), ".ttl"));
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package org.hl7.fhir.utilities;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* An {@link Interceptor} for {@link okhttp3.OkHttpClient} that tracks visits to specific urls
|
||||
*/
|
||||
public class TxInterceptor implements Interceptor {
|
||||
|
||||
private String getKey(String method, String url) {
|
||||
return method + " " + url;
|
||||
}
|
||||
|
||||
private static TxInterceptor instance;
|
||||
|
||||
public static TxInterceptor getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new TxInterceptor();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
final Map<String, Integer> queriedUrls;
|
||||
|
||||
private TxInterceptor() {
|
||||
queriedUrls = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Interceptor.Chain chain) throws IOException {
|
||||
Response response = chain.proceed(chain.request());
|
||||
|
||||
final String key = getKey(response.request().method(), response.request().url().toString());
|
||||
final int count = queriedUrls.containsKey(key) ? queriedUrls.get(key) : 1;
|
||||
|
||||
queriedUrls.put(key, count+1);
|
||||
System.out.print("");
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
|
@ -137,7 +137,7 @@ public class NativeHostServices {
|
|||
* @throws Exception
|
||||
*/
|
||||
public void init(String pack) throws Exception {
|
||||
validator = new ValidationEngine(pack);
|
||||
validator = new ValidationEngine.ValidationEngineBuilder().fromSource(pack);
|
||||
validator.getContext().setAllowLoadingDuplicates(true);
|
||||
igLoader = new IgLoader(validator.getPcm(), validator.getContext(), validator.getVersion(), validator.isDebug());
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package org.hl7.fhir.validation;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import org.fhir.ucum.UcumEssenceService;
|
||||
import org.fhir.ucum.UcumException;
|
||||
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50;
|
||||
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50;
|
||||
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50;
|
||||
|
@ -183,60 +181,106 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
*/
|
||||
@Getter @Setter private Map<String, ValidationControl> validationControl = new HashMap<>();
|
||||
|
||||
public ValidationEngine() throws IOException {
|
||||
setContext(SimpleWorkerContext.fromNothing());
|
||||
initContext(null);
|
||||
igLoader = new IgLoader(getPcm(), getContext(), getVersion(), isDebug());
|
||||
private ValidationEngine() {
|
||||
|
||||
}
|
||||
|
||||
public ValidationEngine(String src) throws FHIRException, IOException {
|
||||
loadCoreDefinitions(src, false, null);
|
||||
igLoader = new IgLoader(getPcm(), getContext(), getVersion(), isDebug());
|
||||
public static class ValidationEngineBuilder {
|
||||
|
||||
@With
|
||||
private final String terminologyCachePath;
|
||||
|
||||
@With
|
||||
private final String userAgent;
|
||||
|
||||
@With
|
||||
private final String version;
|
||||
|
||||
//All three of these may be required to instantiate a txServer
|
||||
private final String txServer;
|
||||
private final String txLog;
|
||||
private final FhirPublication txVersion;
|
||||
|
||||
@With
|
||||
private final TimeTracker timeTracker;
|
||||
|
||||
@With
|
||||
private final boolean canRunWithoutTerminologyServer;
|
||||
|
||||
public ValidationEngineBuilder() {
|
||||
terminologyCachePath = null;
|
||||
userAgent = null;
|
||||
version = null;
|
||||
txServer = null;
|
||||
txLog = null;
|
||||
txVersion = null;
|
||||
timeTracker = null;
|
||||
canRunWithoutTerminologyServer = false;
|
||||
}
|
||||
|
||||
public ValidationEngineBuilder(String terminologyCachePath, String userAgent, String version, String txServer, String txLog, FhirPublication txVersion, TimeTracker timeTracker, boolean canRunWithoutTerminologyServer) {
|
||||
this.terminologyCachePath = terminologyCachePath;
|
||||
this.userAgent = userAgent;
|
||||
this.version = version;
|
||||
this.txServer = txServer;
|
||||
this.txLog = txLog;
|
||||
this.txVersion = txVersion;
|
||||
this.timeTracker = timeTracker;
|
||||
this.canRunWithoutTerminologyServer = canRunWithoutTerminologyServer;
|
||||
}
|
||||
|
||||
public ValidationEngineBuilder withTxServer(String txServer, String txLog, FhirPublication txVersion) {
|
||||
return new ValidationEngineBuilder(terminologyCachePath, userAgent, version, txServer, txLog, txVersion,timeTracker, canRunWithoutTerminologyServer);
|
||||
}
|
||||
|
||||
public ValidationEngine fromNothing() throws IOException {
|
||||
ValidationEngine engine = new ValidationEngine();
|
||||
SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder();
|
||||
if (terminologyCachePath != null)
|
||||
contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
|
||||
engine.setContext(contextBuilder.build());
|
||||
engine.initContext(timeTracker);
|
||||
engine.setIgLoader(new IgLoader(engine.getPcm(), engine.getContext(), engine.getVersion(), engine.isDebug()));
|
||||
return engine;
|
||||
}
|
||||
|
||||
public ValidationEngine fromSource(String src) throws IOException, URISyntaxException {
|
||||
ValidationEngine engine = new ValidationEngine();
|
||||
engine.loadCoreDefinitions(src, false, terminologyCachePath, userAgent, timeTracker);
|
||||
engine.getContext().setCanRunWithoutTerminology(canRunWithoutTerminologyServer);
|
||||
|
||||
if (txServer != null) {
|
||||
engine.setTerminologyServer(txServer, txLog, txVersion);
|
||||
}
|
||||
engine.setVersion(version);
|
||||
engine.setIgLoader(new IgLoader(engine.getPcm(), engine.getContext(), engine.getVersion(), engine.isDebug()));
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
|
||||
public ValidationEngine(String src, String txsrvr, String txLog, FhirPublication version, boolean canRunWithoutTerminologyServer, String vString, String userAgent) throws FHIRException, IOException, URISyntaxException {
|
||||
this(src, txsrvr, txLog, null, version, canRunWithoutTerminologyServer, vString, userAgent);
|
||||
}
|
||||
|
||||
public ValidationEngine(String src, String txsrvr, String txLog, String txCachePath, FhirPublication version, boolean canRunWithoutTerminologyServer, String vString, String userAgent) throws FHIRException, IOException, URISyntaxException {
|
||||
loadCoreDefinitions(src, false, null);
|
||||
getContext().setUserAgent(userAgent);
|
||||
getContext().setCanRunWithoutTerminology(canRunWithoutTerminologyServer);
|
||||
setTerminologyServer(txsrvr, txLog, txCachePath, version);
|
||||
setVersion(vString);
|
||||
igLoader = new IgLoader(getPcm(), getContext(), getVersion(), isDebug());
|
||||
}
|
||||
|
||||
public ValidationEngine(String src, String txsrvr, String txLog, FhirPublication version, String vString, String userAgent) throws FHIRException, IOException, URISyntaxException {
|
||||
this(src, txsrvr, txLog, null, version, vString, userAgent);
|
||||
}
|
||||
|
||||
public ValidationEngine(String src, String txsrvr, String txLog, String txCachePath, FhirPublication version, String vString, String userAgent) throws FHIRException, IOException, URISyntaxException {
|
||||
loadCoreDefinitions(src, false, null);
|
||||
getContext().setUserAgent(userAgent);
|
||||
setTerminologyServer(txsrvr, txLog, txCachePath, version);
|
||||
setVersion(vString);
|
||||
igLoader = new IgLoader(getPcm(), getContext(), getVersion(), isDebug());
|
||||
}
|
||||
|
||||
public ValidationEngine(String src, String vString, TimeTracker tt, String userAgent) throws FHIRException, IOException, URISyntaxException {
|
||||
loadCoreDefinitions(src, false, tt);
|
||||
getContext().setUserAgent(userAgent);
|
||||
setVersion(vString);
|
||||
igLoader = new IgLoader(getPcm(), getContext(), getVersion(), isDebug());
|
||||
}
|
||||
|
||||
private void loadCoreDefinitions(String src, boolean recursive, TimeTracker tt) throws FHIRException, IOException {
|
||||
private void loadCoreDefinitions(String src, boolean recursive, String terminologyCachePath, String userAgent, TimeTracker tt) throws FHIRException, IOException {
|
||||
NpmPackage npm = getPcm().loadPackage(src, null);
|
||||
if (npm != null) {
|
||||
version = npm.fhirVersion();
|
||||
context = SimpleWorkerContext.fromPackage(npm, ValidatorUtils.loaderForVersion(version));
|
||||
SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder();
|
||||
if (terminologyCachePath != null)
|
||||
contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
|
||||
if (userAgent != null) {
|
||||
contextBuilder.withUserAgent(userAgent);
|
||||
}
|
||||
context = contextBuilder.fromPackage(npm, ValidatorUtils.loaderForVersion(version));
|
||||
} else {
|
||||
Map<String, byte[]> source = igLoader.loadIgSource(src, recursive, true);
|
||||
if (version == null) {
|
||||
version = getVersionFromPack(source);
|
||||
}
|
||||
context = SimpleWorkerContext.fromDefinitions(source, ValidatorUtils.loaderForVersion(version), new PackageVersion(src));
|
||||
SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder();
|
||||
if (terminologyCachePath != null)
|
||||
contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
|
||||
if (userAgent != null) {
|
||||
contextBuilder.withUserAgent(userAgent);
|
||||
}
|
||||
context = contextBuilder.fromDefinitions(source, ValidatorUtils.loaderForVersion(version), new PackageVersion(src));
|
||||
ValidatorUtils.grabNatives(getBinaries(), source, "http://hl7.org/fhir");
|
||||
}
|
||||
// ucum-essence.xml should be in the class path. if it's not, ask about how to sort this out
|
||||
|
@ -251,7 +295,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
initContext(tt);
|
||||
}
|
||||
|
||||
public void initContext(TimeTracker tt) throws IOException {
|
||||
protected void initContext(TimeTracker tt) throws IOException {
|
||||
context.setCanNoTS(true);
|
||||
context.setCacheId(UUID.randomUUID().toString());
|
||||
context.setAllowLoadingDuplicates(true); // because of Forge
|
||||
|
@ -300,10 +344,6 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
return "n/a: No Terminology Server";
|
||||
} else {
|
||||
try {
|
||||
//FIXME this can fail for a different reason than connectToTSServer
|
||||
if (txCachePath != null) {
|
||||
context.initTS(txCachePath);
|
||||
}
|
||||
return context.connectToTSServer(TerminologyClientFactory.makeClient(url, context.getUserAgent(), version), log);
|
||||
} catch (Exception e) {
|
||||
if (context.isCanRunWithoutTerminology()) {
|
||||
|
@ -710,12 +750,8 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
|
|||
throw new FHIRException("Source/Target version not supported: " + version + " -> " + targetVer);
|
||||
}
|
||||
|
||||
public String setTerminologyServer(String src, String log, FhirPublication version) throws FHIRException, IOException, URISyntaxException {
|
||||
return setTerminologyServer(src, log, null, version);
|
||||
}
|
||||
|
||||
public String setTerminologyServer(String src, String log, String txCachePath, FhirPublication version) throws FHIRException, IOException, URISyntaxException {
|
||||
return connectToTSServer(src, log, txCachePath, version);
|
||||
public String setTerminologyServer(String src, String log, FhirPublication version) throws FHIRException, URISyntaxException, IOException {
|
||||
return connectToTSServer(src, log, version);
|
||||
}
|
||||
|
||||
public ValidationEngine setMapLog(String mapLog) throws FileNotFoundException {
|
||||
|
|
|
@ -91,7 +91,7 @@ public class ValidationService {
|
|||
VersionSourceInformation versions = new VersionSourceInformation();
|
||||
IgLoader igLoader = new IgLoader(
|
||||
new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION),
|
||||
SimpleWorkerContext.fromNothing(),
|
||||
new SimpleWorkerContext.SimpleWorkerContextBuilder().fromNothing(),
|
||||
null);
|
||||
for (String src : cliContext.getIgs()) {
|
||||
igLoader.scanForIgVersion(src, cliContext.isRecursive(), versions);
|
||||
|
@ -317,7 +317,10 @@ public class ValidationService {
|
|||
System.out.println("No such cached session exists for session id " + sessionId + ", re-instantiating validator.");
|
||||
}
|
||||
System.out.print(" Load FHIR v" + cliContext.getSv() + " from " + definitions);
|
||||
ValidationEngine validator = new ValidationEngine(definitions, cliContext.getSv(), tt, "fhir/validator");
|
||||
//DIRTY
|
||||
//ValidationEngine validator = new ValidationEngine.ValidationEngineBuilder(definitions, cliContext.getSv(), tt, "fhir/validator");
|
||||
ValidationEngine validator = new ValidationEngine.ValidationEngineBuilder().withVersion(cliContext.getSv()).withTimeTracker(tt).withUserAgent("fhir/validator").fromSource(definitions);
|
||||
|
||||
sessionId = sessionCache.cacheSession(validator);
|
||||
|
||||
FhirPublication ver = FhirPublication.fromCode(cliContext.getSv());
|
||||
|
@ -325,7 +328,7 @@ public class ValidationService {
|
|||
System.out.println(" - " + validator.getContext().countAllCaches() + " resources (" + tt.milestone() + ")");
|
||||
igLoader.loadIg(validator.getIgs(), validator.getBinaries(), "hl7.terminology", false);
|
||||
System.out.print(" Terminology server " + cliContext.getTxServer());
|
||||
String txver = validator.setTerminologyServer(cliContext.getTxServer(), cliContext.getTxLog(), cliContext.getTxCache(), ver);
|
||||
String txver = validator.setTerminologyServer(cliContext.getTxServer(), cliContext.getTxLog(), ver);
|
||||
System.out.println(" - Version " + txver + " (" + tt.milestone() + ")");
|
||||
validator.setDebug(cliContext.isDoDebug());
|
||||
for (String src : cliContext.getIgs()) {
|
||||
|
|
|
@ -87,7 +87,9 @@ public class Common {
|
|||
|
||||
public static ValidationEngine getValidationEngine(String version, String txServer, String definitions, String txLog, TimeTracker tt) throws Exception {
|
||||
System.out.println("Loading (v = " + version + ", tx server -> " + txServer + ")");
|
||||
ValidationEngine ve = new ValidationEngine(definitions, version, tt, "fhir/validator");
|
||||
//DIRTY
|
||||
//ValidationEngine ve = new ValidationEngine(definitions, version, tt, "fhir/validator");
|
||||
ValidationEngine ve = new ValidationEngine.ValidationEngineBuilder().withVersion(version).withTimeTracker(tt).withUserAgent("fhir/validator").fromSource(definitions);
|
||||
ve.connectToTSServer(txServer, txLog, FhirPublication.fromCode(version));
|
||||
return ve;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class FHIRMappingLanguageTests {
|
|||
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
validationEngine = new ValidationEngine("hl7.fhir.r4.core#4.0.1");
|
||||
validationEngine = new ValidationEngine.ValidationEngineBuilder().fromSource("hl7.fhir.r4.core#4.0.1");
|
||||
context = validationEngine.getContext();
|
||||
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "any.xml"), "any.xml", null);
|
||||
context.loadFromFile(TestingUtilities.loadTestResourceStream("validator", "cda", "ii.xml"), "ii.xml", null);
|
||||
|
|
|
@ -16,7 +16,7 @@ class SessionCacheTest {
|
|||
void expiredSession() throws IOException, InterruptedException {
|
||||
final long EXPIRE_TIME = 5L;
|
||||
SessionCache cache = new SessionCache(EXPIRE_TIME, TimeUnit.SECONDS);
|
||||
ValidationEngine testEngine = new ValidationEngine();
|
||||
ValidationEngine testEngine = new ValidationEngine.ValidationEngineBuilder().fromNothing();
|
||||
String sessionId = cache.cacheSession(testEngine);
|
||||
TimeUnit.SECONDS.sleep(EXPIRE_TIME + 1L);
|
||||
Assertions.assertNull(cache.fetchSessionValidatorEngine(sessionId));
|
||||
|
@ -27,7 +27,7 @@ class SessionCacheTest {
|
|||
void cachedSession() throws IOException {
|
||||
final long EXPIRE_TIME = 5L;
|
||||
SessionCache cache = new SessionCache(EXPIRE_TIME, TimeUnit.SECONDS);
|
||||
ValidationEngine testEngine = new ValidationEngine();
|
||||
ValidationEngine testEngine = new ValidationEngine.ValidationEngineBuilder().fromNothing();
|
||||
String sessionId = cache.cacheSession(testEngine);
|
||||
Assertions.assertEquals(testEngine, cache.fetchSessionValidatorEngine(sessionId));
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class SessionCacheTest {
|
|||
@DisplayName("test session exists")
|
||||
void sessionExists() throws IOException {
|
||||
SessionCache cache = new SessionCache();
|
||||
ValidationEngine testEngine = new ValidationEngine();
|
||||
ValidationEngine testEngine = new ValidationEngine.ValidationEngineBuilder().fromNothing();
|
||||
String sessionId = cache.cacheSession(testEngine);
|
||||
Assertions.assertTrue(cache.sessionExists(sessionId));
|
||||
Assertions.assertFalse(cache.sessionExists(UUID.randomUUID().toString()));
|
||||
|
|
|
@ -21,7 +21,7 @@ public class LoadIgTests {
|
|||
final String fhirSpecVersion = "4.0";
|
||||
final String definitions = VersionUtilities.packageForVersion(fhirSpecVersion) + "#" + VersionUtilities.getCurrentVersion(fhirSpecVersion);
|
||||
|
||||
ValidationEngine hl7Validator = new ValidationEngine(definitions);
|
||||
ValidationEngine hl7Validator = new ValidationEngine.ValidationEngineBuilder().fromSource(definitions);
|
||||
hl7Validator.setDoNative(false);
|
||||
hl7Validator.setAnyExtensionsAllowed(true);
|
||||
hl7Validator.prepare();
|
||||
|
@ -52,7 +52,7 @@ public class LoadIgTests {
|
|||
final String fhirSpecVersion = "4.0";
|
||||
final String definitions = VersionUtilities.packageForVersion(fhirSpecVersion) + "#" + VersionUtilities.getCurrentVersion(fhirSpecVersion);
|
||||
|
||||
ValidationEngine hl7Validator = new ValidationEngine(definitions);
|
||||
ValidationEngine hl7Validator = new ValidationEngine.ValidationEngineBuilder().fromSource(definitions);
|
||||
hl7Validator.setDoNative(false);
|
||||
hl7Validator.setAnyExtensionsAllowed(true);
|
||||
hl7Validator.prepare();
|
||||
|
|
|
@ -30,7 +30,7 @@ public class ValidationEngineTests {
|
|||
public void testCurrentXml() throws Exception {
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("TestCurrentXml: Validate patient-example.xml in Current version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1", "fhir/test-cases");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, FhirPublication.R4, "4.0.1");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient-example.xml"), null);
|
||||
|
@ -53,7 +53,7 @@ public class ValidationEngineTests {
|
|||
public void testCurrentJson() throws Exception {
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("TestCurrentJson: Validate patient-example.json in Current version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, null, FhirPublication.R4, "4.0.1", "fhir/test-cases");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", DEF_TX, FhirPublication.R4, "4.0.1");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
OperationOutcome op = ve.validate(FhirFormat.JSON, TestingUtilities.loadTestResourceStream("validator", "patient-example.json"), null);
|
||||
|
@ -76,7 +76,7 @@ public class ValidationEngineTests {
|
|||
}
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("Test140: Validate patient-example.xml in v1.4.0 version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", DEF_TX, null, FhirPublication.DSTU2016May, "1.4.0", "fhir/test-cases");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", DEF_TX, FhirPublication.DSTU2016May, "1.4.0");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
OperationOutcome op = ve.validate(FhirFormat.XML, TestingUtilities.loadTestResourceStream("validator", "patient140.xml"), null);
|
||||
|
@ -103,7 +103,7 @@ public class ValidationEngineTests {
|
|||
}
|
||||
if (!org.hl7.fhir.validation.tests.utilities.TestUtilities.silent)
|
||||
System.out.println("Test102: Validate patient-example.xml in v1.0.2 version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, null, FhirPublication.DSTU2, "1.0.2", "fhir/test-cases");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, FhirPublication.DSTU2, "1.0.2");
|
||||
ve.setNoInvariantChecks(true);
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
|
@ -131,7 +131,7 @@ public class ValidationEngineTests {
|
|||
}
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("TestObs102: Validate patient-example.xml in v1.0.2 version");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, null, FhirPublication.DSTU2, "1.0.2", "fhir/test-cases");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", DEF_TX, FhirPublication.DSTU2, "1.0.2");
|
||||
ve.setNoInvariantChecks(true);
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
|
@ -156,7 +156,7 @@ public class ValidationEngineTests {
|
|||
public void test301() throws Exception {
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("Test301: Validate observation301.xml against Core");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, null, FhirPublication.STU3, "3.0.2", "fhir/test-cases");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, FhirPublication.STU3, "3.0.2");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
if (!TestUtilities.silent)
|
||||
|
@ -178,7 +178,7 @@ public class ValidationEngineTests {
|
|||
public void test301USCore() throws Exception {
|
||||
if (!TestUtilities.silent)
|
||||
System.out.println("Test301USCore: Validate patient300.xml against US-Core");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, null, FhirPublication.STU3, "3.0.2", "fhir/test-cases");
|
||||
ValidationEngine ve = TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", DEF_TX, FhirPublication.STU3, "3.0.2");
|
||||
CacheVerificationLogger logger = new CacheVerificationLogger();
|
||||
ve.getContext().getTxClient().setLogger(logger);
|
||||
IgLoader igLoader = new IgLoader(ve.getPcm(), ve.getContext(), ve.getVersion(), true);
|
||||
|
|
|
@ -78,7 +78,6 @@ import com.google.gson.JsonArray;
|
|||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class ValidationTests implements IEvaluationContext, IValidatorResourceFetcher, IValidationPolicyAdvisor {
|
||||
|
@ -145,17 +144,17 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
|
|||
version = VersionUtilities.getMajMin(version);
|
||||
if (!ve.containsKey(version)) {
|
||||
if (version.startsWith("5.0"))
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r5.core#4.5.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R5, true, "4.5.0", "fhir/test-cases"));
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r5.core#4.5.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R5, true, "4.5.0"));
|
||||
else if (version.startsWith("4.3"))
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r4b.core#4.3.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4B, true, "4.3.0", "fhir/test-cases"));
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r4b.core#4.3.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4B, true, "4.3.0"));
|
||||
else if (version.startsWith("4.0"))
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4, true, "4.0.1", "fhir/test-cases"));
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4, true, "4.0.1"));
|
||||
else if (version.startsWith("3.0"))
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.STU3, true, "3.0.2", "fhir/test-cases"));
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.STU3, true, "3.0.2"));
|
||||
else if (version.startsWith("1.4"))
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2016May, true, "1.4.0", "fhir/test-cases"));
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2016May, true, "1.4.0"));
|
||||
else if (version.startsWith("1.0"))
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2, true, "1.0.2", "fhir/test-cases"));
|
||||
ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2, true, "1.0.2"));
|
||||
else
|
||||
throw new Exception("unknown version " + version);
|
||||
}
|
||||
|
|
|
@ -6,4 +6,6 @@ public class TestConstants {
|
|||
public static final java.lang.String TX_CACHE = Paths.get("src","test","resources", "txCache").toAbsolutePath().toString();
|
||||
|
||||
public static final java.lang.String TX_CACHE_LOG = Paths.get(System.getProperty("user.dir"), "tx.log.html").toAbsolutePath().toString();
|
||||
|
||||
public static final String USER_AGENT = "fhir/test-cases";
|
||||
}
|
||||
|
|
|
@ -13,19 +13,33 @@ public class TestUtilities {
|
|||
// public static String resourceNameToFile(String name) throws IOException {
|
||||
// return org.hl7.fhir.utilities.Utilities.path(System.getProperty("user.dir"), "src", "test", "resources", name);
|
||||
// }
|
||||
public static final ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txsrvr, java.lang.String txLog, FhirPublication version, boolean canRunWithoutTerminologyServer, java.lang.String vString, java.lang.String userAgent) throws Exception {
|
||||
txLog = TestConstants.TX_CACHE_LOG;
|
||||
final ValidationEngine validationEngine = new ValidationEngine(src, txsrvr, txLog, Paths.get(TestConstants.TX_CACHE, vString).toString(), version, canRunWithoutTerminologyServer, vString, userAgent);
|
||||
public static final ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txServer, String txLog, FhirPublication version, boolean canRunWithoutTerminologyServer, java.lang.String vString) throws Exception {
|
||||
|
||||
//DIRTY
|
||||
// final ValidationEngine validationEngine = new ValidationEngine(src, txsrvr, txLog, Paths.get(TestConstants.TX_CACHE, vString).toString(), version, canRunWithoutTerminologyServer, vString, userAgent);
|
||||
final ValidationEngine validationEngine = new ValidationEngine.ValidationEngineBuilder()
|
||||
.withCanRunWithoutTerminologyServer(canRunWithoutTerminologyServer)
|
||||
.withVersion(vString)
|
||||
.withUserAgent(TestConstants.USER_AGENT)
|
||||
.withTerminologyCachePath(Paths.get(TestConstants.TX_CACHE, vString).toString())
|
||||
.withTxServer(txServer, txLog, version)
|
||||
.fromSource(src);
|
||||
|
||||
TerminologyCache.setCacheErrors(true);
|
||||
validationEngine.getContext().setUserAgent("fhir/test-cases");
|
||||
return validationEngine;
|
||||
}
|
||||
|
||||
public static ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txsrvr, java.lang.String txLog, FhirPublication version, java.lang.String vString, java.lang.String userAgent) throws Exception {
|
||||
txLog = TestConstants.TX_CACHE_LOG;
|
||||
final ValidationEngine validationEngine = new ValidationEngine(src, txsrvr, txLog, Paths.get(TestConstants.TX_CACHE, vString).toString(), version, vString, userAgent);
|
||||
public static ValidationEngine getValidationEngine(java.lang.String src, java.lang.String txServer, FhirPublication version, java.lang.String vString) throws Exception {
|
||||
//DIRTY
|
||||
// final ValidationEngine validationEngine = new ValidationEngine(src, txsrvr, txLog, Paths.get(TestConstants.TX_CACHE, vString).toString(), version, vString, userAgent);
|
||||
final ValidationEngine validationEngine = new ValidationEngine.ValidationEngineBuilder()
|
||||
.withVersion(vString)
|
||||
.withUserAgent(TestConstants.USER_AGENT)
|
||||
.withTerminologyCachePath(Paths.get(TestConstants.TX_CACHE, vString).toString())
|
||||
.withTxServer(txServer, TestConstants.TX_CACHE_LOG, version)
|
||||
.fromSource(src);
|
||||
TerminologyCache.setCacheErrors(true);
|
||||
validationEngine.getContext().setUserAgent("fhir/test-cases");
|
||||
|
||||
return validationEngine;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue