Skip to content

Commit

Permalink
Jm improve test server helper (hapifhir#6281)
Browse files Browse the repository at this point in the history
* Improve docs as indexing is not the only function using extraction

* Add providers map which to be able to add any kind of provider dynamically

---------

Co-authored-by: juan.marchionatto <[email protected]>
  • Loading branch information
jmarchionatto and juan.marchionatto authored Sep 13, 2024
1 parent ab2ba05 commit 699f863
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public interface ISearchParamExtractor {

/**
* Constant for the {@literal theSearchParamFilter} parameters on this interface
* indicating that all search parameters should be indexed.
* indicating that all search parameters should be extracted.
*/
ISearchParamFilter ALL_PARAMS = t -> t;

/**
* Constant for the {@literal theSearchParamFilter} parameters on this interface
* indicating that no search parameters should be indexed.
* indicating that no search parameters should be extracted.
*/
ISearchParamFilter NO_PARAMS = t -> Collections.emptyList();

Expand Down Expand Up @@ -155,7 +155,7 @@ ResourceIndexedSearchParamToken createSearchParamForCoding(
interface ISearchParamFilter {

/**
* Given the list of search parameters for indexing, an implementation of this
* Given the list of search parameters for extracting, an implementation of this
* interface may selectively remove any that it wants to remove (or can add if desired).
* <p>
* Implementations must not modify the list that is passed in. If changes are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,28 @@ public void setConceptMapResourceProvider(HashMapResourceProvider<ConceptMap> th
myRestServer.setConceptMapResourceProvider(theResourceProvider);
}

public <T extends IBaseResource> HashMapResourceProvider<T> getResourceProvider(Class<T> theResourceType) {
@SuppressWarnings("unchecked")
HashMapResourceProvider<T> resourceProvider = (HashMapResourceProvider<T>) myRestServer.myResourceProvidersMap.get(theResourceType);
assert resourceProvider != null : "No resource provider defined for resource type: '" + theResourceType + "'" ;
return resourceProvider;
}

public <T extends IBaseResource> void setResourceProvider(HashMapResourceProvider<T> theResourceProvider) {
assert theResourceProvider.getResourceType() != null : "resourceProvider doesn't have a resourceType";
@SuppressWarnings("unchecked")
HashMapResourceProvider<T> resourceProvider = (HashMapResourceProvider<T>) myRestServer.myResourceProvidersMap.get(theResourceProvider.getResourceType());

if (resourceProvider != null) {
resourceProvider.getStoredResources().forEach(theResourceProvider::store);
myRestServer.unregisterProvider(resourceProvider);
}

registerProvider(theResourceProvider);
myRestServer.myResourceProvidersMap.put(theResourceProvider.getResourceType(), theResourceProvider);
}


public void setPagingProvider(IPagingProvider thePagingProvider) {
myPagingProvider = thePagingProvider;
}
Expand Down Expand Up @@ -295,6 +317,8 @@ private static class MyRestfulServer extends RestfulServer {
private HashMapResourceProvider<ConceptMap> myConceptMapResourceProvider;
private RestServerDstu3Helper.MyPlainProvider myPlainProvider;

private final Map<Class<?>, HashMapResourceProvider<?>> myResourceProvidersMap = new HashMap<>();

private final boolean myInitialTransactionLatchEnabled;

private PagingHttpMethodEnum myPagingHttpMethod = PagingHttpMethodEnum.GET;
Expand Down

0 comments on commit 699f863

Please sign in to comment.