Address code review comments. Create new static builder for all partitions SRD

This commit is contained in:
Tadgh 2021-04-18 17:36:55 -04:00
parent 3075a9b5e6
commit 77e2768a14
4 changed files with 13 additions and 18 deletions

View File

@ -55,8 +55,6 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; 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. * Bulk Item reader for the Group Bulk Export job.
* Instead of performing a normal query on the resource type using type filters, we instead * 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<Long> patientPidsToExport = new HashSet<>(pidsOrThrowException); Set<Long> patientPidsToExport = new HashSet<>(pidsOrThrowException);
if (myMdmEnabled) { if (myMdmEnabled) {
SystemRequestDetails srd = new SystemRequestDetails(); SystemRequestDetails srd = SystemRequestDetails.newSystemRequestAllPartitions();
srd.setTenantId(ALL_PARTITIONS_NAME);
IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), srd); IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), srd);
Long pidOrNull = myIdHelperService.getPidOrNull(group); Long pidOrNull = myIdHelperService.getPidOrNull(group);
List<IMdmLinkDao.MdmPidTuple> goldenPidSourcePidTuple = myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(pidOrNull, MdmMatchResultEnum.MATCH); List<IMdmLinkDao.MdmPidTuple> 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"] * @return A list of strings representing the Patient IDs of the members (e.g. ["P1", "P2", "P3"]
*/ */
private List<String> getMembers() { private List<String> getMembers() {
SystemRequestDetails requestDetails = new SystemRequestDetails(); SystemRequestDetails requestDetails = SystemRequestDetails.newSystemRequestAllPartitions();
requestDetails.setTenantId(ALL_PARTITIONS_NAME);
IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), requestDetails); IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), requestDetails);
List<IPrimitiveType> evaluate = myContext.newFhirPath().evaluate(group, "member.entity.reference", IPrimitiveType.class); List<IPrimitiveType> evaluate = myContext.newFhirPath().evaluate(group, "member.entity.reference", IPrimitiveType.class);
return evaluate.stream().map(IPrimitiveType::getValueAsString).collect(Collectors.toList()); return evaluate.stream().map(IPrimitiveType::getValueAsString).collect(Collectors.toList());
@ -199,9 +195,8 @@ public class GroupBulkItemReader extends BaseBulkItemReader implements ItemReade
*/ */
private Set<String> expandAllPatientPidsFromGroup() { private Set<String> expandAllPatientPidsFromGroup() {
Set<String> expandedIds = new HashSet<>(); Set<String> expandedIds = new HashSet<>();
SystemRequestDetails requestDetails = new SystemRequestDetails(); SystemRequestDetails requestDetails = SystemRequestDetails.newSystemRequestAllPartitions();
requestDetails.setTenantId(ALL_PARTITIONS_NAME); IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), requestDetails);
IBaseResource group = myDaoRegistry.getResourceDao("Group").read(new IdDt(myGroupId), new SystemRequestDetails());
Long pidOrNull = myIdHelperService.getPidOrNull(group); Long pidOrNull = myIdHelperService.getPidOrNull(group);
//Attempt to perform MDM Expansion of membership //Attempt to perform MDM Expansion of membership

View File

@ -143,8 +143,7 @@ public class RequestPartitionHelperSvc implements IRequestPartitionHelperSvc {
RequestPartitionId requestPartitionId; RequestPartitionId requestPartitionId;
requestPartitionId = getSystemRequestPartitionId(theRequest); requestPartitionId = getSystemRequestPartitionId(theRequest);
if (theNonPartitionableResource && !requestPartitionId.isDefaultPartition()) { 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"); throw new InternalErrorException("System call is attempting to write a non-partitionable resource to a partition! This is a bug!")
requestPartitionId = RequestPartitionId.defaultPartition();
} }
return requestPartitionId; return requestPartitionId;
} }

View File

@ -35,17 +35,15 @@ import ca.uhn.fhir.rest.server.IRestfulServerDefaults;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ListMultimap; 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.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.List; 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 * 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); myHeaders.put(theName, theValue);
} }
public static SystemRequestDetails newSystemRequestAllPartitions() {
SystemRequestDetails systemRequestDetails = new SystemRequestDetails();
systemRequestDetails.setTenantId(ALL_PARTITIONS_NAME);
return systemRequestDetails;
}
@Override @Override

View File

@ -18,7 +18,6 @@ import ca.uhn.fhir.jpa.entity.BulkExportCollectionEntity;
import ca.uhn.fhir.jpa.entity.BulkExportCollectionFileEntity; import ca.uhn.fhir.jpa.entity.BulkExportCollectionFileEntity;
import ca.uhn.fhir.jpa.entity.BulkExportJobEntity; import ca.uhn.fhir.jpa.entity.BulkExportJobEntity;
import ca.uhn.fhir.jpa.entity.MdmLink; 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.jpa.partition.SystemRequestDetails;
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum; import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum; import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
@ -1115,8 +1114,7 @@ public class BulkDataExportSvcImplR4Test extends BaseBatchJobR4Test {
//Manually create a golden record //Manually create a golden record
Patient goldenPatient = new Patient(); Patient goldenPatient = new Patient();
goldenPatient.setId("PAT999"); goldenPatient.setId("PAT999");
SystemRequestDetails srd = new SystemRequestDetails(); SystemRequestDetails srd = SystemRequestDetails.newSystemRequestAllPartitions();
srd.setTenantId(JpaConstants.ALL_PARTITIONS_NAME);
DaoMethodOutcome g1Outcome = myPatientDao.update(goldenPatient, srd); DaoMethodOutcome g1Outcome = myPatientDao.update(goldenPatient, srd);
Long goldenPid = myIdHelperService.getPidOrNull(g1Outcome.getResource()); Long goldenPid = myIdHelperService.getPidOrNull(g1Outcome.getResource());