improve cahcing on client and also txServer

This commit is contained in:
Grahame Grieve 2020-11-30 17:58:29 +11:00
parent 65a17e6bd8
commit bdf783e9e0
2 changed files with 26 additions and 13 deletions

View File

@ -597,10 +597,12 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
Parameters p = expParameters.copy();
p.setParameter("includeDefinition", false);
p.setParameter("excludeNested", !hierarchical);
if (isTxCaching && cacheId != null) {
boolean cached = addDependentResources(p, vs);
if (cached) {
p.addParameter().setName("cache-id").setValue(new StringType(cacheId));
}
addDependentResources(p, vs);
;
if (noTerminologyServer) {
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE);
@ -672,10 +674,10 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
// if that failed, we try to expand on the server
if (isTxCaching && cacheId != null) {
if (addDependentResources(p, vs)) {
p.addParameter().setName("cache-id").setValue(new StringType(cacheId));
}
addDependentResources(p, vs);
if (noTerminologyServer) {
return new ValueSetExpansionOutcome(formatMessage(I18nConstants.ERROR_EXPANDING_VALUESET_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE, allErrors);
}
@ -808,6 +810,9 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
BundleEntryComponent r = resp.getEntry().get(i);
if (r.getResource() instanceof Parameters) {
t.setResult(processValidationResult((Parameters) r.getResource()));
if (txCache != null) {
txCache.cacheValidation(t.getCacheToken(), t.getResult(), TerminologyCache.PERMANENT);
}
} else {
t.setResult(new ValidationResult(IssueSeverity.ERROR, getResponseText(r.getResource())).setTxLink(txLog == null ? null : txLog.getLastId()));
}
@ -939,9 +944,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
private ValidationResult validateOnServer(ValueSet vs, Parameters pin) throws FHIRException {
if (isTxCaching && cacheId != null) {
pin.addParameter().setName("cache-id").setValue(new StringType(cacheId));
}
boolean cache = false;
if (vs != null) {
if (isTxCaching && cacheId != null && cached.contains(vs.getUrl()+"|"+vs.getVersion())) {
pin.addParameter().setName("url").setValue(new UriType(vs.getUrl()+"|"+vs.getVersion()));
@ -949,8 +952,12 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
pin.addParameter().setName("valueSet").setResource(vs);
cached.add(vs.getUrl()+"|"+vs.getVersion());
}
cache = true;
addDependentResources(pin, vs);
}
if (cache) {
pin.addParameter().setName("cache-id").setValue(new StringType(cacheId));
}
for (ParametersParameterComponent pp : pin.getParameter()) {
if (pp.getName().equals("profile")) {
throw new Error(formatMessage(I18nConstants.CAN_ONLY_SPECIFY_PROFILE_IN_THE_CONTEXT));
@ -975,22 +982,26 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
return processValidationResult(pOut);
}
private void addDependentResources(Parameters pin, ValueSet vs) {
private boolean addDependentResources(Parameters pin, ValueSet vs) {
boolean cache = false;
for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
addDependentResources(pin, inc);
cache = addDependentResources(pin, inc) || cache;
}
for (ConceptSetComponent inc : vs.getCompose().getExclude()) {
addDependentResources(pin, inc);
cache = addDependentResources(pin, inc) || cache;
}
return cache;
}
private void addDependentResources(Parameters pin, ConceptSetComponent inc) {
private boolean addDependentResources(Parameters pin, ConceptSetComponent inc) {
boolean cache = false;
for (CanonicalType c : inc.getValueSet()) {
ValueSet vs = fetchResource(ValueSet.class, c.getValue());
if (vs != null) {
if (isTxCaching && cacheId == null || !cached.contains(vs.getVUrl())) {
pin.addParameter().setName("tx-resource").setResource(vs);
cached.add(vs.getVUrl());
cache = true;
}
addDependentResources(pin, vs);
}
@ -1000,9 +1011,11 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
if (isTxCaching && cacheId == null || !cached.contains(cs.getVUrl())) {
pin.addParameter().setName("tx-resource").setResource(cs);
cached.add(cs.getVUrl());
cache = true;
}
// todo: supplements
}
}
return cache;
}
public ValidationResult processValidationResult(Parameters pOut) {

View File

@ -19,7 +19,7 @@
<properties>
<hapi_fhir_version>5.1.0</hapi_fhir_version>
<validator_test_case_version>1.1.52-SNAPSHOT</validator_test_case_version>
<validator_test_case_version>1.1.53-SNAPSHOT</validator_test_case_version>
<junit_jupiter_version>5.6.2</junit_jupiter_version>
<maven_surefire_version>3.0.0-M4</maven_surefire_version>
<jacoco_version>0.8.5</jacoco_version>