Skip to content

Commit 867488a

Browse files
authored
Ensure that generic partition ID computation work for ServletRequestDetails. (#7377)
* Ensure that generic partition ID computation work for ServlertRequestDetails. * Add test that proves this works and fails if I revert the production code. * Add changelog.
1 parent f293b48 commit 867488a

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
type: fix
3+
issue: 7378
4+
title: "The STORAGE_PARTITION_IDENTIFY_ANY hook was recently removed from RequestTenantPartitionInterceptor which caused BaseRequestPartitionHelperSvc.determineGenericPartitionForRequest() to fail in Request Tenant mode. This change restores the functionality of BaseRequestPartitionHelperSvc.determineGenericPartitionForRequest() by falling back to STORAGE_PARTITION_IDENTIFY_READ if STORAGE_PARTITION_IDENTIFY_ANY is not set."

hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/interceptor/model/ReadPartitionIdRequestDetails.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
2323
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
24+
import ca.uhn.fhir.rest.api.server.RequestDetails;
2425
import jakarta.annotation.Nonnull;
2526
import jakarta.annotation.Nullable;
2627
import org.hl7.fhir.instance.model.api.IBaseResource;
@@ -67,6 +68,17 @@ private ReadPartitionIdRequestDetails(
6768
myExtendedOperationName = theExtendedOperationName;
6869
}
6970

71+
public static ReadPartitionIdRequestDetails forGeneric(RequestDetails theRequestDetails) {
72+
return new ReadPartitionIdRequestDetails(
73+
theRequestDetails.getResourceName(),
74+
theRequestDetails.getRestOperationType(),
75+
theRequestDetails.getId(),
76+
null,
77+
null,
78+
null,
79+
null);
80+
}
81+
7082
@Nullable
7183
public String getExtendedOperationName() {
7284
return myExtendedOperationName;

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantServerR4Test.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import ca.uhn.fhir.batch2.model.JobInstance;
66
import ca.uhn.fhir.batch2.model.StatusEnum;
77
import ca.uhn.fhir.i18n.Msg;
8+
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
89
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
910
import ca.uhn.fhir.jpa.api.model.BulkExportJobResults;
1011
import ca.uhn.fhir.jpa.batch.models.Batch2JobStartResponse;
@@ -16,9 +17,11 @@
1617
import ca.uhn.fhir.jpa.model.dao.JpaPid;
1718
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
1819
import ca.uhn.fhir.jpa.model.util.JpaConstants;
20+
import ca.uhn.fhir.jpa.partition.IRequestPartitionHelperSvc;
1921
import ca.uhn.fhir.jpa.util.MemoryCacheService;
2022
import ca.uhn.fhir.model.api.Include;
2123
import ca.uhn.fhir.rest.api.Constants;
24+
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
2225
import ca.uhn.fhir.rest.api.server.RequestDetails;
2326
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
2427
import ca.uhn.fhir.rest.api.server.bulk.BulkExportJobParameters;
@@ -66,6 +69,7 @@
6669
import org.mockito.Captor;
6770
import org.mockito.InjectMocks;
6871
import org.mockito.Mock;
72+
import org.springframework.beans.factory.annotation.Autowired;
6973
import org.springframework.boot.test.mock.mockito.SpyBean;
7074
import org.springframework.mock.web.MockHttpServletRequest;
7175

@@ -111,6 +115,9 @@ public class MultitenantServerR4Test extends BaseMultitenantResourceProviderR4T
111115
@SpyBean
112116
private MemoryCacheService myMemoryCacheService;
113117

118+
@Autowired
119+
IRequestPartitionHelperSvc myRequestPartitionHelperSvc;
120+
114121
@Override
115122
@AfterEach
116123
public void after() throws Exception {
@@ -876,6 +883,19 @@ public void testIncludeInTenantWithAutoGeneratedID() {
876883
assertThat(response.getEntry()).hasSize(2);
877884
}
878885

886+
@Test
887+
public void testDetermineGenericPartitionForRequest() {
888+
ServletRequestDetails request = mock(ServletRequestDetails.class);
889+
when(request.getResourceName()).thenReturn("MeasureReport");
890+
when(request.getRestOperationType()).thenReturn(RestOperationTypeEnum.CREATE);
891+
when(request.getId()).thenReturn(new IdType("Measure", "123"));
892+
when(request.getTenantId()).thenReturn(TENANT_A);
893+
RequestPartitionId result = myRequestPartitionHelperSvc.determineGenericPartitionForRequest(request);
894+
assertThat(result).isNotNull();
895+
assertThat(result.getPartitionIds()).contains(1);
896+
assertThat(result.getPartitionNames()).contains(TENANT_A);
897+
}
898+
879899
private void createConditionWithAllowedUnqualified(IIdType idA) {
880900
myPartitionSettings.setAllowReferencesAcrossPartitions(PartitionSettings.CrossPartitionReferenceMode.ALLOWED_UNQUALIFIED);
881901
IIdType idB = createResource("Condition", withTenant(TENANT_A), withObservationCode("http://cs", "A"));

hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/partition/BaseRequestPartitionHelperSvc.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ && systemRequestHasExplicitPartition(systemRequestDetails)) {
220220
myInterceptorBroadcaster, theRequestDetails);
221221
if (compositeBroadcaster.hasHooks(Pointcut.STORAGE_PARTITION_IDENTIFY_ANY)) {
222222
requestPartitionId = callAnyPointcut(compositeBroadcaster, theRequestDetails);
223+
} else if (compositeBroadcaster.hasHooks(Pointcut.STORAGE_PARTITION_IDENTIFY_READ)) {
224+
ReadPartitionIdRequestDetails readDetails = ReadPartitionIdRequestDetails.forGeneric(theRequestDetails);
225+
requestPartitionId = callReadPointcut(compositeBroadcaster, theRequestDetails, readDetails);
223226
}
224227
}
225228

0 commit comments

Comments
 (0)