diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/export/job/GroupBulkItemReader.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/export/job/GroupBulkItemReader.java index ca6e3cbe699..6b49a2134b7 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/export/job/GroupBulkItemReader.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/export/job/GroupBulkItemReader.java @@ -55,8 +55,6 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import static ca.uhn.fhir.jpa.model.util.JpaConstants.ALL_PARTITIONS_NAME; - /** * Bulk Item reader for the Group Bulk Export job. * Instead of performing a normal query on the resource type using type filters, we instead @@ -121,8 +119,7 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade Set patientPidsToExport = new HashSet<>(pidsOrThrowException); if (myMdmEnabled) { - SystemRequestDetails srd = new SystemRequestDetails(); - srd.setTenantId(ALL_PARTITIONS_NAME); + SystemRequestDetails srd = SystemRequestDetails.newSystemRequestAllPartitions(); IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), srd); Long pidOrNull = myIdHelperService.getPidOrNull(group); List goldenPidSourcePidTuple = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH); @@ -183,8 +180,7 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade * @return A list of strings representing the Patient IDs of the members (e.g. ["P1", "P2", "P3"] */ private List getMembers() { - SystemRequestDetails requestDetails = new SystemRequestDetails(); - requestDetails.setTenantId(ALL_PARTITIONS_NAME); + SystemRequestDetails requestDetails = SystemRequestDetails.newSystemRequestAllPartitions(); IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), requestDetails); List evaluate = myContext.newFhirPath().evaluate(group, "member.entity.reference", IPrimitiveType.class); return evaluate.stream().map(IPrimitiveType::getValueAsString).collect(Collectors.toList()); @@ -199,9 +195,8 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade */ private Set expandAllPatientPidsFromGroup() { Set expandedIds = new HashSet<>(); - SystemRequestDetails requestDetails = new SystemRequestDetails(); - requestDetails.setTenantId(ALL_PARTITIONS_NAME); - IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), new SystemRequestDetails()); + SystemRequestDetails requestDetails = SystemRequestDetails.newSystemRequestAllPartitions(); + IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), requestDetails); Long pidOrNull = myIdHelperService.getPidOrNull(group); //Attempt to perform MDM Expansion of membership diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/RequestPartitionHelperSvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/RequestPartitionHelperSvc.java index 7e4bf4434eb..4bcf6b1ddb5 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/RequestPartitionHelperSvc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/RequestPartitionHelperSvc.java @@ -143,8 +143,7 @@ public class RequestPartitionHelperSvc implements IRequestPartitionHelperSvc { RequestPartitionId requestPartitionId; requestPartitionId = getSystemRequestPartitionId(theRequest); if (theNonPartitionableResource && !requestPartitionId.isDefaultPartition()) { - ourLog.warn("System call is attempting to write a non-partitionable resource to a partition! This is a bug in your code! Setting partition to DEFAULT"); - requestPartitionId = RequestPartitionId.defaultPartition(); + throw new InternalErrorException("System call is attempting to write a non-partitionable resource to a partition! This is a bug!") } return requestPartitionId; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/SystemRequestDetails.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/SystemRequestDetails.java index c2b3361eb0c..f194a1d8f73 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/SystemRequestDetails.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/SystemRequestDetails.java @@ -35,17 +35,15 @@ import ca.uhn.fhir.rest.server.IRestfulServerDefaults; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableListMultimap; -import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ListMultimap; -import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.nio.charset.Charset; import java.util.List; -import java.util.Optional; + +import static ca.uhn.fhir.jpa.model.util.JpaConstants.ALL_PARTITIONS_NAME; /** * A default RequestDetails implementation that can be used for system calls to @@ -104,6 +102,11 @@ public class SystemRequestDetails extends RequestDetails { } myHeaders.put(theName, theValue); } + public static SystemRequestDetails newSystemRequestAllPartitions() { + SystemRequestDetails systemRequestDetails = new SystemRequestDetails(); + systemRequestDetails.setTenantId(ALL_PARTITIONS_NAME); + return systemRequestDetails; + } @Override diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImplR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImplR4Test.java index ede4c871584..701de70bb04 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImplR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImplR4Test.java @@ -18,7 +18,6 @@ import ca.uhn.fhir.jpa.entity.BulkExportCollectionEntity; import ca.uhn.fhir.jpa.entity.BulkExportCollectionFileEntity; import ca.uhn.fhir.jpa.entity.BulkExportJobEntity; import ca.uhn.fhir.jpa.entity.MdmLink; -import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.jpa.partition.SystemRequestDetails; import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum; import ca.uhn.fhir.mdm.api.MdmMatchResultEnum; @@ -1115,8 +1114,7 @@ public class BulkDataExportSvcImplR4Test extends BaseBatchJobR4Test { //Manually create a golden record Patient goldenPatient = new Patient(); goldenPatient.setId("PAT999"); - SystemRequestDetails srd = new SystemRequestDetails(); - srd.setTenantId(JpaConstants.ALL_PARTITIONS_NAME); + SystemRequestDetails srd = SystemRequestDetails.newSystemRequestAllPartitions(); DaoMethodOutcome g1Outcome = myPatientDao.update(goldenPatient, srd); Long goldenPid = myIdHelperService.getPidOrNull(g1Outcome.getResource());