Skip to content

Commit c207b49

Browse files
fil512michaelabuckleyjamesagnew
authored
fix default partition setting on resource (hapifhir#5617)
* fix default partition setting on resource * changelog * Handle DEFAULT partition in rule checker. * Fix spotless --------- Co-authored-by: Michael Buckley <[email protected]> Co-authored-by: James Agnew <[email protected]>
1 parent 4aa3b97 commit c207b49

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: fix
3+
issue: 5617
4+
title: "Resource UserData RESOURCE_PARTITION_ID was incorrectly being set to null for the default partition.
5+
This has been corrected to use RequestPartitionId.defaultPartition()"

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaStorageResourceParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import ca.uhn.fhir.context.FhirVersionEnum;
2424
import ca.uhn.fhir.context.RuntimeResourceDefinition;
2525
import ca.uhn.fhir.i18n.Msg;
26+
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
2627
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
2728
import ca.uhn.fhir.jpa.api.dao.IDao;
2829
import ca.uhn.fhir.jpa.dao.data.IResourceHistoryTableDao;
@@ -248,7 +249,7 @@ private <R extends IBaseResource> void populateResourcePartitionInformation(
248249
myPartitionLookupSvc.getPartitionById(partitionId.getPartitionId());
249250
retVal.setUserData(Constants.RESOURCE_PARTITION_ID, persistedPartition.toRequestPartitionId());
250251
} else {
251-
retVal.setUserData(Constants.RESOURCE_PARTITION_ID, null);
252+
retVal.setUserData(Constants.RESOURCE_PARTITION_ID, RequestPartitionId.defaultPartition());
252253
}
253254
}
254255
}

hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public class JpaConstants {
263263
/**
264264
* The name of the default partition
265265
*/
266-
public static final String DEFAULT_PARTITION_NAME = "DEFAULT";
266+
public static final String DEFAULT_PARTITION_NAME = ProviderConstants.DEFAULT_PARTITION_NAME;
267267

268268
/**
269269
* The name of the collection of all partitions

hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import ca.uhn.fhir.rest.api.Constants;
2626
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
2727
import ca.uhn.fhir.rest.api.server.RequestDetails;
28+
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
2829
import com.google.common.collect.Lists;
2930
import jakarta.annotation.Nonnull;
3031
import org.apache.commons.lang3.Validate;
@@ -234,6 +235,11 @@ private boolean matchesResource(IBaseResource theResource) {
234235
RequestPartitionId partitionId =
235236
(RequestPartitionId) theResource.getUserData(Constants.RESOURCE_PARTITION_ID);
236237
if (partitionId != null) {
238+
if (partitionId.hasDefaultPartitionId()
239+
&& myTenantIds.contains(ProviderConstants.DEFAULT_PARTITION_NAME)) {
240+
return myOutcome;
241+
}
242+
237243
String partitionNameOrNull = partitionId.getFirstPartitionNameOrNull();
238244
if (partitionNameOrNull == null || !myTenantIds.contains(partitionNameOrNull)) {
239245
return !myOutcome;

hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/provider/ProviderConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class ProviderConstants {
5252
public static final String PARTITION_MANAGEMENT_PARTITION_NAME = "name";
5353
public static final String PARTITION_MANAGEMENT_PARTITION_DESC = "description";
5454

55+
public static final String DEFAULT_PARTITION_NAME = "DEFAULT";
56+
5557
/**
5658
* Operation name: diff
5759
*/

0 commit comments

Comments
 (0)