Skip to content

Commit

Permalink
Issue #2296 - miscellaneous updates (#2393)
Browse files Browse the repository at this point in the history
* Issue #2296 - miscellaneous updates

Signed-off-by: John T.E. Timm <johntimm@us.ibm.com>

* Issue #2296 - changed visibility of cache config

Signed-off-by: John T.E. Timm <johntimm@us.ibm.com>
  • Loading branch information
JohnTimm committed May 19, 2021
1 parent 1444f70 commit b3f10c8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions fhir-cache/src/main/java/com/ibm/fhir/cache/CacheKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public boolean equals(Object obj) {
return Arrays.deepEquals(values, other.values);
}

@Override
public String toString() {
return Arrays.deepToString(values);
}

/**
* A factory method for creating CacheKey instances from one or more values
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class ResolveFunction extends FHIRPathAbstractFunction {
public static final String RESOLVE_RELATIVE_REFERENCES = "resolveRelativeReferences";
public static final boolean DEFAULT_RESOLVE_RELATIVE_REFERENCES = true;
public static final boolean DEFAULT_RESOLVE_RELATIVE_REFERENCES = false;

private static final int BASE_URL_GROUP = 1;
private static final int RESOURCE_TYPE_GROUP = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.ibm.fhir.server.registry;

import static com.ibm.fhir.cache.CacheKey.key;
import static com.ibm.fhir.cache.util.CacheSupport.createCacheAsMap;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
Expand All @@ -24,6 +23,8 @@
import java.util.stream.Collectors;

import com.ibm.fhir.cache.CacheKey;
import com.ibm.fhir.cache.CacheManager;
import com.ibm.fhir.cache.CacheManager.Configuration;
import com.ibm.fhir.config.FHIRRequestContext;
import com.ibm.fhir.model.resource.Resource;
import com.ibm.fhir.model.resource.SearchParameter;
Expand All @@ -44,9 +45,10 @@
public class ServerRegistryResourceProvider extends AbstractRegistryResourceProvider {
public static final Logger log = Logger.getLogger(ServerRegistryResourceProvider.class.getName());

private final PersistenceHelper persistenceHelper;
public static final String REGISTRY_RESOURCE_CACHE_NAME = "com.ibm.fhir.server.registry.ServerRegistryResourceProvider.registryResourceCache";
public static final Configuration REGISTRY_RESOURCE_CACHE_CONFIGURATION = Configuration.of(1024, Duration.of(1, ChronoUnit.MINUTES));

private final Map<CacheKey, List<FHIRRegistryResource>> registryResourceCache = createCacheAsMap(1024, Duration.of(1, ChronoUnit.MINUTES));
private final PersistenceHelper persistenceHelper;

public ServerRegistryResourceProvider(PersistenceHelper persistenceHelper) {
try {
Expand All @@ -58,10 +60,10 @@ public ServerRegistryResourceProvider(PersistenceHelper persistenceHelper) {

@Override
protected List<FHIRRegistryResource> getRegistryResources(Class<? extends Resource> resourceType, String url) {
String tenantId = FHIRRequestContext.get().getTenantId();
String dataStoreId = FHIRRequestContext.get().getDataStoreId();
CacheKey key = key(tenantId, dataStoreId, url);
return registryResourceCache.computeIfAbsent(key, k -> computeRegistryResources(resourceType, url));
CacheKey key = key(dataStoreId, url);
Map<CacheKey, List<FHIRRegistryResource>> cacheAsMap = CacheManager.getCacheAsMap(REGISTRY_RESOURCE_CACHE_NAME, REGISTRY_RESOURCE_CACHE_CONFIGURATION);
return cacheAsMap.computeIfAbsent(key, k -> computeRegistryResources(resourceType, url));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import com.ibm.fhir.search.util.ReferenceUtil;

public class ServerResolveFunction extends ResolveFunction {
public static final Logger log = Logger.getLogger(ServerResolveFunction.class.getName());
private static final Logger log = Logger.getLogger(ServerResolveFunction.class.getName());

public static final String RESOURCE_CACHE_NAME = "com.ibm.fhir.server.resolve.ServerResolveFunction.resourceCache";
public static final Configuration RESOURCE_CACHE_CONFIGURATION = Configuration.of(Duration.of(1, ChronoUnit.MINUTES));

private static final Configuration RESOURCE_CACHE_CONFIGURATION = Configuration.of(Duration.of(1, ChronoUnit.MINUTES));
private static final String VREAD = "vread";
private static final String READ = "read";
private static final Object NULL = new Object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public void testServerResolveFunction() throws Exception {
FHIRPathEvaluator evaluator = FHIRPathEvaluator.evaluator();
EvaluationContext evaluationContext = new EvaluationContext(observation);

evaluationContext.setExternalConstant(ResolveFunction.RESOLVE_RELATIVE_REFERENCES, FHIRPathBooleanValue.TRUE);
Collection<FHIRPathNode> nodes = evaluator.evaluate(evaluationContext, "subject.resolve() is Patient");
assertEquals(nodes, SINGLETON_TRUE);

Expand Down Expand Up @@ -201,6 +202,7 @@ public void testServerResolveFunction() throws Exception {
.build())
.build();
evaluationContext = new EvaluationContext(observation);
evaluationContext.setExternalConstant(ResolveFunction.RESOLVE_RELATIVE_REFERENCES, FHIRPathBooleanValue.TRUE);
nodes = evaluator.evaluate(evaluationContext, "subject.resolve() is Patient");
assertEquals(nodes, SINGLETON_TRUE);

Expand All @@ -215,6 +217,7 @@ public void testServerResolveFunction() throws Exception {
.build())
.build();
evaluationContext = new EvaluationContext(observation);
evaluationContext.setExternalConstant(ResolveFunction.RESOLVE_RELATIVE_REFERENCES, FHIRPathBooleanValue.TRUE);
nodes = evaluator.evaluate(evaluationContext, "subject.resolve() is Patient");
assertEquals(nodes, SINGLETON_TRUE);

Expand All @@ -229,6 +232,7 @@ public void testServerResolveFunction() throws Exception {
.build())
.build();
evaluationContext = new EvaluationContext(observation);
evaluationContext.setExternalConstant(ResolveFunction.RESOLVE_RELATIVE_REFERENCES, FHIRPathBooleanValue.TRUE);
nodes = evaluator.evaluate(evaluationContext, "subject.resolve() is Patient");
assertEquals(nodes, SINGLETON_TRUE);

Expand All @@ -243,6 +247,7 @@ public void testServerResolveFunction() throws Exception {
.build())
.build();
evaluationContext = new EvaluationContext(observation);
evaluationContext.setExternalConstant(ResolveFunction.RESOLVE_RELATIVE_REFERENCES, FHIRPathBooleanValue.TRUE);
nodes = evaluator.evaluate(evaluationContext, "subject.resolve() is Patient");
assertEquals(nodes, SINGLETON_TRUE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import com.ibm.fhir.model.type.code.IssueSeverity;
import com.ibm.fhir.model.type.code.IssueType;
import com.ibm.fhir.model.util.ModelSupport;
import com.ibm.fhir.path.FHIRPathBooleanValue;
import com.ibm.fhir.path.FHIRPathElementNode;
import com.ibm.fhir.path.FHIRPathNode;
import com.ibm.fhir.path.FHIRPathResourceNode;
import com.ibm.fhir.path.FHIRPathTree;
import com.ibm.fhir.path.evaluator.FHIRPathEvaluator;
import com.ibm.fhir.path.evaluator.FHIRPathEvaluator.EvaluationContext;
import com.ibm.fhir.path.function.ResolveFunction;
import com.ibm.fhir.path.visitor.FHIRPathDefaultNodeVisitor;
import com.ibm.fhir.profile.ProfileSupport;
import com.ibm.fhir.registry.FHIRRegistry;
Expand Down Expand Up @@ -168,6 +170,7 @@ public List<Issue> validate(EvaluationContext evaluationContext, boolean include
throw new IllegalArgumentException("Root must be resource node");
}
try {
evaluationContext.setExternalConstant(ResolveFunction.RESOLVE_RELATIVE_REFERENCES, FHIRPathBooleanValue.TRUE);
List<Issue> issues = new ArrayList<>();
validateProfileReferences(evaluationContext.getTree().getRoot().asResourceNode(), Arrays.asList(profiles), false, issues);
issues.addAll(visitor.validate(evaluationContext, includeResourceAssertedProfiles, profiles));
Expand Down

0 comments on commit b3f10c8

Please sign in to comment.