Allow empty request details in JPA (#2343)

* Allow empty request details in JPA

* Test fixes
This commit is contained in:
James Agnew 2021-02-02 11:00:14 -05:00 committed by GitHub
parent 54fac48cc0
commit 0f31d106e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 234 additions and 38 deletions

View File

@ -1245,7 +1245,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> extends BaseStora
// Notify interceptors
ActionRequestDetails requestDetails;
if (theRequestDetails != null) {
if (theRequestDetails != null && theRequestDetails.getServer() != null) {
requestDetails = new ActionRequestDetails(theRequestDetails, theResource, theResourceId.getResourceType(), theResourceId);
notifyInterceptors(RestOperationTypeEnum.UPDATE, requestDetails);
}
@ -1467,13 +1467,13 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> extends BaseStora
return retVal.toString();
}
public static void clearRequestAsProcessingSubRequest(ServletRequestDetails theRequestDetails) {
public static void clearRequestAsProcessingSubRequest(RequestDetails theRequestDetails) {
if (theRequestDetails != null) {
theRequestDetails.getUserData().remove(PROCESSING_SUB_REQUEST);
}
}
public static void markRequestAsProcessingSubRequest(ServletRequestDetails theRequestDetails) {
public static void markRequestAsProcessingSubRequest(RequestDetails theRequestDetails) {
if (theRequestDetails != null) {
theRequestDetails.getUserData().put(PROCESSING_SUB_REQUEST, Boolean.TRUE);
}

View File

@ -1078,7 +1078,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
assert TransactionSynchronizationManager.isActualTransactionActive();
// Notify interceptors
if (theRequest != null) {
if (theRequest != null && theRequest.getServer() != null) {
ActionRequestDetails requestDetails = new ActionRequestDetails(theRequest, getResourceName(), theId);
RestOperationTypeEnum operationType = theId.hasVersionIdPart() ? RestOperationTypeEnum.VREAD : RestOperationTypeEnum.READ;
notifyInterceptors(operationType, requestDetails);

View File

@ -55,6 +55,7 @@ import ca.uhn.fhir.rest.server.RestfulServerUtils;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import ca.uhn.fhir.rest.server.exceptions.NotModifiedException;
import ca.uhn.fhir.rest.server.exceptions.PayloadTooLargeException;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
@ -141,13 +142,13 @@ public abstract class BaseTransactionProcessor {
}
public <BUNDLE extends IBaseBundle> BUNDLE transaction(RequestDetails theRequestDetails, BUNDLE theRequest) {
if (theRequestDetails != null && myDao != null) {
if (theRequestDetails != null && theRequestDetails.getServer() != null && myDao != null) {
IServerInterceptor.ActionRequestDetails requestDetails = new IServerInterceptor.ActionRequestDetails(theRequestDetails, theRequest, "Bundle", null);
myDao.notifyInterceptors(RestOperationTypeEnum.TRANSACTION, requestDetails);
}
String actionName = "Transaction";
IBaseBundle response = processTransactionAsSubRequest((ServletRequestDetails) theRequestDetails, theRequest, actionName);
IBaseBundle response = processTransactionAsSubRequest((RequestDetails) theRequestDetails, theRequest, actionName);
List<IBase> entries = myVersionAdapter.getEntries(response);
for (int i = 0; i < entries.size(); i++) {
@ -198,7 +199,7 @@ public abstract class BaseTransactionProcessor {
}
private void handleTransactionCreateOrUpdateOutcome(Map<IIdType, IIdType> idSubstitutions, Map<IIdType, DaoMethodOutcome> idToPersistedOutcome, IIdType nextResourceId, DaoMethodOutcome outcome,
IBase newEntry, String theResourceType, IBaseResource theRes, ServletRequestDetails theRequestDetails) {
IBase newEntry, String theResourceType, IBaseResource theRes, RequestDetails theRequestDetails) {
IIdType newId = outcome.getId().toUnqualified();
IIdType resourceId = isPlaceholder(nextResourceId) ? nextResourceId : nextResourceId.toUnqualifiedVersionless();
if (newId.equals(resourceId) == false) {
@ -268,7 +269,7 @@ public abstract class BaseTransactionProcessor {
myDao = theDao;
}
private IBaseBundle processTransactionAsSubRequest(ServletRequestDetails theRequestDetails, IBaseBundle theRequest, String theActionName) {
private IBaseBundle processTransactionAsSubRequest(RequestDetails theRequestDetails, IBaseBundle theRequest, String theActionName) {
BaseHapiFhirDao.markRequestAsProcessingSubRequest(theRequestDetails);
try {
return processTransaction(theRequestDetails, theRequest, theActionName);
@ -334,7 +335,7 @@ public abstract class BaseTransactionProcessor {
return resp;
}
private IBaseBundle processTransaction(final ServletRequestDetails theRequestDetails, final IBaseBundle theRequest, final String theActionName) {
private IBaseBundle processTransaction(final RequestDetails theRequestDetails, final IBaseBundle theRequest, final String theActionName) {
validateDependencies();
String transactionType = myVersionAdapter.getBundleType(theRequest);
@ -447,6 +448,12 @@ public abstract class BaseTransactionProcessor {
transactionStopWatch.startTask("Process " + getEntries.size() + " GET entries");
}
for (IBase nextReqEntry : getEntries) {
if (!(theRequestDetails instanceof ServletRequestDetails)) {
throw new MethodNotAllowedException("Can not call transaction GET methods from this context");
}
ServletRequestDetails srd = (ServletRequestDetails)theRequestDetails;
Integer originalOrder = originalRequestOrder.get(nextReqEntry);
IBase nextRespEntry = (IBase) myVersionAdapter.getEntries(response).get(originalOrder);
@ -454,11 +461,11 @@ public abstract class BaseTransactionProcessor {
String transactionUrl = extractTransactionUrlOrThrowException(nextReqEntry, "GET");
ServletSubRequestDetails requestDetails = ServletRequestUtil.getServletSubRequestDetails(theRequestDetails, transactionUrl, paramValues);
ServletSubRequestDetails requestDetails = ServletRequestUtil.getServletSubRequestDetails(srd, transactionUrl, paramValues);
String url = requestDetails.getRequestPath();
BaseMethodBinding<?> method = theRequestDetails.getServer().determineResourceMethod(requestDetails, url);
BaseMethodBinding<?> method = srd.getServer().determineResourceMethod(requestDetails, url);
if (method == null) {
throw new IllegalArgumentException("Unable to handle GET " + url);
}
@ -479,7 +486,7 @@ public abstract class BaseTransactionProcessor {
BaseResourceReturningMethodBinding methodBinding = (BaseResourceReturningMethodBinding) method;
requestDetails.setRestOperationType(methodBinding.getRestOperationType());
IBaseResource resource = methodBinding.doInvokeServer(theRequestDetails.getServer(), requestDetails);
IBaseResource resource = methodBinding.doInvokeServer(srd.getServer(), requestDetails);
if (paramValues.containsKey(Constants.PARAM_SUMMARY) || paramValues.containsKey(Constants.PARAM_CONTENT)) {
resource = filterNestedBundle(requestDetails, resource);
}
@ -543,7 +550,7 @@ public abstract class BaseTransactionProcessor {
}
private Map<IBase, IBasePersistedResource> doTransactionWriteOperations(final ServletRequestDetails theRequest, String theActionName, TransactionDetails theTransactionDetails, Set<IIdType> theAllIds,
private Map<IBase, IBasePersistedResource> doTransactionWriteOperations(final RequestDetails theRequest, String theActionName, TransactionDetails theTransactionDetails, Set<IIdType> theAllIds,
Map<IIdType, IIdType> theIdSubstitutions, Map<IIdType, DaoMethodOutcome> theIdToPersistedOutcome, IBaseBundle theResponse, IdentityHashMap<IBase, Integer> theOriginalRequestOrder, List<IBase> theEntries, StopWatch theTransactionStopWatch) {
theTransactionDetails.beginAcceptingDeferredInterceptorBroadcasts(

View File

@ -34,6 +34,7 @@ import ca.uhn.fhir.jpa.model.entity.NpmPackageEntity;
import ca.uhn.fhir.jpa.model.entity.NpmPackageVersionEntity;
import ca.uhn.fhir.jpa.model.entity.NpmPackageVersionResourceEntity;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.partition.SystemRequestDetails;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.EncodingEnum;
@ -329,8 +330,9 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac
private ResourceTable createResourceBinary(IBaseBinary theResourceBinary) {
if (myPartitionSettings.isPartitioningEnabled()) {
SystemRequestDetails myRequestDetails = new SystemRequestDetails();
return (ResourceTable) getBinaryDao().create(theResourceBinary, myRequestDetails).getEntity();
SystemRequestDetails requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
return (ResourceTable) getBinaryDao().create(theResourceBinary, requestDetails).getEntity();
} else {
return (ResourceTable) getBinaryDao().create(theResourceBinary).getEntity();
}
@ -642,9 +644,10 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac
private void deleteAndExpungeResourceBinary(IIdType theResourceBinaryId, ExpungeOptions theOptions) {
if (myPartitionSettings.isPartitioningEnabled()) {
SystemRequestDetails myRequestDetails = new SystemRequestDetails();
getBinaryDao().delete(theResourceBinaryId, myRequestDetails).getEntity();
getBinaryDao().forceExpungeInExistingTransaction(theResourceBinaryId, theOptions, myRequestDetails);
SystemRequestDetails requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
getBinaryDao().delete(theResourceBinaryId, requestDetails).getEntity();
getBinaryDao().forceExpungeInExistingTransaction(theResourceBinaryId, theOptions, requestDetails);
} else {
getBinaryDao().delete(theResourceBinaryId).getEntity();
getBinaryDao().forceExpungeInExistingTransaction(theResourceBinaryId, theOptions, null);

View File

@ -33,6 +33,7 @@ import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
import ca.uhn.fhir.jpa.dao.data.INpmPackageVersionDao;
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.jpa.model.entity.NpmPackageVersionEntity;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.partition.SystemRequestDetails;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
@ -342,8 +343,9 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc {
private IBundleProvider searchResource(IFhirResourceDao theDao, SearchParameterMap theMap) {
if (myPartitionSettings.isPartitioningEnabled()) {
SystemRequestDetails myRequestDetails = new SystemRequestDetails();
return theDao.search(theMap, myRequestDetails);
SystemRequestDetails requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
return theDao.search(theMap, requestDetails);
} else {
return theDao.search(theMap);
}
@ -351,8 +353,9 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc {
private void createResource(IFhirResourceDao theDao, IBaseResource theResource) {
if (myPartitionSettings.isPartitioningEnabled()) {
SystemRequestDetails myRequestDetails = new SystemRequestDetails();
theDao.create(theResource, myRequestDetails);
SystemRequestDetails requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
theDao.create(theResource, requestDetails);
} else {
theDao.create(theResource);
}
@ -360,8 +363,9 @@ public class PackageInstallerSvcImpl implements IPackageInstallerSvc {
private DaoMethodOutcome updateResource(IFhirResourceDao theDao, IBaseResource theResource) {
if (myPartitionSettings.isPartitioningEnabled()) {
SystemRequestDetails myRequestDetails = new SystemRequestDetails();
return theDao.update(theResource, myRequestDetails);
SystemRequestDetails requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
return theDao.update(theResource, requestDetails);
} else {
return theDao.update(theResource);
}

View File

@ -97,7 +97,7 @@ public class RequestPartitionHelperSvc implements IRequestPartitionHelperSvc {
if (myPartitionSettings.isPartitioningEnabled()) {
// Handle system requests
if ((theRequest == null && myPartitioningBlacklist.contains(theResourceType)) || theRequest instanceof SystemRequestDetails) {
if ((theRequest == null && myPartitioningBlacklist.contains(theResourceType))) {
return RequestPartitionId.defaultPartition();
}
@ -129,7 +129,7 @@ public class RequestPartitionHelperSvc implements IRequestPartitionHelperSvc {
if (myPartitionSettings.isPartitioningEnabled()) {
// Handle system requests
if ((theRequest == null && myPartitioningBlacklist.contains(theResourceType)) || theRequest instanceof SystemRequestDetails) {
if ((theRequest == null && myPartitioningBlacklist.contains(theResourceType))) {
return RequestPartitionId.defaultPartition();
}

View File

@ -49,8 +49,9 @@ public abstract class BaseMultitenantResourceProviderR4Test extends BaseResource
public void before() throws Exception {
super.before();
myInterceptorRegistry.registerInterceptor(myRequestTenantPartitionInterceptor);
myPartitionSettings.setPartitioningEnabled(true);
ourRestServer.registerInterceptor(myRequestTenantPartitionInterceptor);
ourRestServer.registerProvider(myPartitionManagementProvider);
ourRestServer.setTenantIdentificationStrategy(new UrlBaseTenantIdentificationStrategy());

View File

@ -3,8 +3,12 @@ package ca.uhn.fhir.jpa.provider.r4;
import ca.uhn.fhir.jpa.entity.PartitionEntity;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.partition.SystemRequestDetails;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.test.utilities.ITestDataBuilder;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CapabilityStatement;
@ -157,6 +161,169 @@ public class MultitenantServerR4Test extends BaseMultitenantResourceProviderR4Te
myTenantClientInterceptor.setTenantId(TENANT_A);
Bundle response = myClient.transaction().withBundle(input).execute();
IdType idA = new IdType(response.getEntry().get(0).getResponse().getLocation());
IdType idB = new IdType(response.getEntry().get(1).getResponse().getLocation());
runInTransaction(() -> {
ResourceTable resourceTable = myResourceTableDao.findById(idA.getIdPartAsLong()).orElseThrow(() -> new IllegalStateException());
assertEquals(1, resourceTable.getPartitionId().getPartitionId());
resourceTable = myResourceTableDao.findById(idB.getIdPartAsLong()).orElseThrow(() -> new IllegalStateException());
assertEquals(1, resourceTable.getPartitionId().getPartitionId());
});
}
@Test
public void testDirectDaoAccess_PartitionInRequestDetails_Create() {
// Create patients
IBaseResource patientA = buildPatient(withActiveTrue());
SystemRequestDetails requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
IIdType idA = myPatientDao.create((Patient) patientA, requestDetails).getId();
IBaseResource patientB = buildPatient(withActiveFalse());
requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(TENANT_B);
IIdType idB = myPatientDao.create((Patient) patientB, requestDetails).getId();
runInTransaction(() -> {
ResourceTable resourceTable = myResourceTableDao.findById(idA.getIdPartAsLong()).orElseThrow(() -> new IllegalStateException());
assertNull(resourceTable.getPartitionId());
resourceTable = myResourceTableDao.findById(idB.getIdPartAsLong()).orElseThrow(() -> new IllegalStateException());
assertEquals(2, resourceTable.getPartitionId().getPartitionId());
});
// Now read back
myTenantClientInterceptor.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
Patient response = myClient.read().resource(Patient.class).withId(idA).execute();
assertTrue(response.getActive());
myTenantClientInterceptor.setTenantId(TENANT_B);
response = myClient.read().resource(Patient.class).withId(idB).execute();
assertFalse(response.getActive());
// Read back using DAO
requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
response = myPatientDao.read(idA, requestDetails);
assertTrue(response.getActive());
requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(TENANT_B);
response = myPatientDao.read(idB, requestDetails);
assertFalse(response.getActive());
}
@Test
public void testDirectDaoAccess_PartitionInRequestDetails_Update() {
IIdType idA = createPatient(withTenant(JpaConstants.DEFAULT_PARTITION_NAME), withActiveFalse()).toVersionless();
IIdType idB = createPatient(withTenant(TENANT_B), withActiveTrue()).toVersionless();
// Create patients
IBaseResource patientA = buildPatient(withId(idA), withActiveTrue());
RequestDetails requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
myPatientDao.update((Patient) patientA, requestDetails);
IBaseResource patientB = buildPatient(withId(idB), withActiveFalse());
requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(TENANT_B);
myPatientDao.update((Patient) patientB, requestDetails);
runInTransaction(() -> {
ResourceTable resourceTable = myResourceTableDao.findById(idA.getIdPartAsLong()).orElseThrow(() -> new IllegalStateException());
assertNull(resourceTable.getPartitionId());
resourceTable = myResourceTableDao.findById(idB.getIdPartAsLong()).orElseThrow(() -> new IllegalStateException());
assertEquals(2, resourceTable.getPartitionId().getPartitionId());
});
// Now read back
myTenantClientInterceptor.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
Patient response = myClient.read().resource(Patient.class).withId(idA).execute();
assertTrue(response.getActive());
myTenantClientInterceptor.setTenantId(TENANT_B);
response = myClient.read().resource(Patient.class).withId(idB).execute();
assertFalse(response.getActive());
// Read back using DAO
requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(JpaConstants.DEFAULT_PARTITION_NAME);
response = myPatientDao.read(idA, requestDetails);
assertTrue(response.getActive());
requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(TENANT_B);
response = myPatientDao.read(idB, requestDetails);
assertFalse(response.getActive());
}
@Test
public void testDirectDaoAccess_PartitionInRequestDetails_Transaction() {
Bundle input = new Bundle();
input.setType(Bundle.BundleType.TRANSACTION);
Organization org = new Organization();
org.setId(IdType.newRandomUuid());
org.setName("org");
input.addEntry()
.setFullUrl(org.getId())
.setResource(org)
.getRequest().setUrl("Organization").setMethod(Bundle.HTTPVerb.POST);
Patient p = new Patient();
p.getMeta().addTag("http://system", "code", "diisplay");
p.addName().setFamily("FAM");
p.addIdentifier().setSystem("system").setValue("value");
p.setBirthDate(new Date());
p.getManagingOrganization().setReference(org.getId());
input.addEntry()
.setFullUrl(p.getId())
.setResource(p)
.getRequest().setUrl("Patient").setMethod(Bundle.HTTPVerb.POST);
RequestDetails requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(TENANT_A);
Bundle response = mySystemDao.transaction(requestDetails, input);
IdType idA = new IdType(response.getEntry().get(0).getResponse().getLocation());
IdType idB = new IdType(response.getEntry().get(1).getResponse().getLocation());
runInTransaction(() -> {
ResourceTable resourceTable = myResourceTableDao.findById(idA.getIdPartAsLong()).orElseThrow(() -> new IllegalStateException());
assertEquals(1, resourceTable.getPartitionId().getPartitionId());
resourceTable = myResourceTableDao.findById(idB.getIdPartAsLong()).orElseThrow(() -> new IllegalStateException());
assertEquals(1, resourceTable.getPartitionId().getPartitionId());
});
}
@Test
public void testDirectDaoAccess_PartitionInRequestDetails_TransactionWithGet() {
Bundle input = new Bundle();
input.setType(Bundle.BundleType.TRANSACTION);
input.addEntry()
.getRequest().setUrl("Patient").setMethod(Bundle.HTTPVerb.GET);
try {
RequestDetails requestDetails = new SystemRequestDetails();
requestDetails.setTenantId(TENANT_A);
mySystemDao.transaction(requestDetails, input);
fail();
} catch (MethodNotAllowedException e) {
assertEquals("Can not call transaction GET methods from this context", e.getMessage());
}
}
}

View File

@ -32,7 +32,6 @@ public class TerminologyLoaderSvcLoincJpaTest extends BaseJpaR4Test {
// Load LOINC marked as version 2.67
TerminologyLoaderSvcLoincTest.addLoincMandatoryFilesWithPropertiesFileToZip(myFiles, "v267_loincupload.properties");
// FIXME: maybe add a count queries test?
mySvc.loadLoinc(myFiles.getFiles(), mySrd);
myTerminologyDeferredStorageSvc.saveAllDeferred();

View File

@ -38,7 +38,7 @@ public class JpaInterceptorBroadcaster {
if (theInterceptorBroadcaster != null) {
retVal = theInterceptorBroadcaster.callHooks(thePointcut, theParams);
}
if (theRequestDetails != null && retVal) {
if (theRequestDetails != null && theRequestDetails.getInterceptorBroadcaster() != null && retVal) {
IInterceptorBroadcaster interceptorBroadcaster = theRequestDetails.getInterceptorBroadcaster();
interceptorBroadcaster.callHooks(thePointcut, theParams);
}
@ -54,7 +54,7 @@ public class JpaInterceptorBroadcaster {
if (theInterceptorBroadcaster != null) {
retVal = theInterceptorBroadcaster.callHooksAndReturnObject(thePointcut, theParams);
}
if (theRequestDetails != null && retVal == null) {
if (theRequestDetails != null && theRequestDetails.getInterceptorBroadcaster() != null && retVal == null) {
IInterceptorBroadcaster interceptorBroadcaster = theRequestDetails.getInterceptorBroadcaster();
retVal = interceptorBroadcaster.callHooksAndReturnObject(thePointcut, theParams);
}
@ -65,6 +65,8 @@ public class JpaInterceptorBroadcaster {
if (theInterceptorBroadcaster != null && theInterceptorBroadcaster.hasHooks(thePointcut)) {
return true;
}
return theRequestDetails != null && theRequestDetails.getInterceptorBroadcaster().hasHooks(thePointcut);
return theRequestDetails != null &&
theRequestDetails.getInterceptorBroadcaster() != null &&
theRequestDetails.getInterceptorBroadcaster().hasHooks(thePointcut);
}
}

View File

@ -437,6 +437,9 @@ public interface IServerInterceptor {
requestDetails.setId(getId());
IInterceptorService interceptorService = server.getInterceptorService();
if (interceptorService == null) {
return;
}
HookParams params = new HookParams();
params.add(RestOperationTypeEnum.class, theOperationType);

View File

@ -24,6 +24,7 @@ import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.Interceptor;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.rest.server.tenant.ITenantIdentificationStrategy;
@ -47,17 +48,17 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
public class RequestTenantPartitionInterceptor {
@Hook(Pointcut.STORAGE_PARTITION_IDENTIFY_CREATE)
public RequestPartitionId PartitionIdentifyCreate(ServletRequestDetails theRequestDetails) {
public RequestPartitionId PartitionIdentifyCreate(RequestDetails theRequestDetails) {
return extractPartitionIdFromRequest(theRequestDetails);
}
@Hook(Pointcut.STORAGE_PARTITION_IDENTIFY_READ)
public RequestPartitionId PartitionIdentifyRead(ServletRequestDetails theRequestDetails) {
public RequestPartitionId PartitionIdentifyRead(RequestDetails theRequestDetails) {
return extractPartitionIdFromRequest(theRequestDetails);
}
@Nonnull
protected RequestPartitionId extractPartitionIdFromRequest(ServletRequestDetails theRequestDetails) {
protected RequestPartitionId extractPartitionIdFromRequest(RequestDetails theRequestDetails) {
// We will use the tenant ID that came from the request as the partition name
String tenantId = theRequestDetails.getTenantId();

View File

@ -132,6 +132,10 @@ public interface ITestDataBuilder {
return createResource("Observation", theModifiers);
}
default IBaseResource buildPatient(Consumer<IBaseResource>... theModifiers) {
return buildResource("Patient", theModifiers);
}
default IIdType createPatient(Consumer<IBaseResource>... theModifiers) {
return createResource("Patient", theModifiers);
}
@ -141,10 +145,7 @@ public interface ITestDataBuilder {
}
default IIdType createResource(String theResourceType, Consumer<IBaseResource>[] theModifiers) {
IBaseResource resource = getFhirContext().getResourceDefinition(theResourceType).newInstance();
for (Consumer<IBaseResource> next : theModifiers) {
next.accept(resource);
}
IBaseResource resource = buildResource(theResourceType, theModifiers);
if (isNotBlank(resource.getIdElement().getValue())) {
return doUpdateResource(resource);
@ -153,6 +154,14 @@ public interface ITestDataBuilder {
}
}
default IBaseResource buildResource(String theResourceType, Consumer<IBaseResource>[] theModifiers) {
IBaseResource resource = getFhirContext().getResourceDefinition(theResourceType).newInstance();
for (Consumer<IBaseResource> next : theModifiers) {
next.accept(resource);
}
return resource;
}
default Consumer<IBaseResource> withSubject(@Nullable IIdType theSubject) {
return t -> {