diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/svc/BulkDataExportSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/svc/BulkDataExportSvcImpl.java index f8800437abe..14be984a072 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/svc/BulkDataExportSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/svc/BulkDataExportSvcImpl.java @@ -139,10 +139,8 @@ public class BulkDataExportSvcImpl implements IBulkDataExportSvc { BulkExportJobEntity bulkExportJobEntity = jobToProcessOpt.get(); String jobUuid = bulkExportJobEntity.getJobId(); - String theGroupId = getGroupIdIfPresent(bulkExportJobEntity.getRequest()); - String theMdmExpand= getMdmIfPresent(bulkExportJobEntity.getRequest()); try { - processJob(jobUuid, theGroupId, theMdmExpand); + processJob(bulkExportJobEntity); } catch (Exception e) { ourLog.error("Failure while preparing bulk export extract", e); myTxTemplate.execute(t -> { @@ -158,25 +156,17 @@ public class BulkDataExportSvcImpl implements IBulkDataExportSvc { } } - private String getGroupIdIfPresent(String theRequestString) { + + private String getQueryParameterIfPresent(String theRequestString, String theParameter) { Map stringMap = UrlUtil.parseQueryString(theRequestString); if (stringMap != null) { - String[] strings = stringMap.get(JpaConstants.PARAM_EXPORT_GROUP_ID); - if (strings != null) { - return String.join(",", strings); - } - } - return null; - } - private String getMdmIfPresent(String theRequestString) { - Map stringMap = UrlUtil.parseQueryString(theRequestString); - if (stringMap != null) { - String[] strings = stringMap.get(JpaConstants.PARAM_EXPORT_MDM); + String[] strings = stringMap.get(theParameter); if (strings != null) { return String.join(",", strings); } } return null; + } @@ -227,7 +217,8 @@ public class BulkDataExportSvcImpl implements IBulkDataExportSvc { } - private void processJob(String theJobUuid, String theGroupId, String theExpandMdm) { + private void processJob(BulkExportJobEntity theBulkExportJobEntity) { + String theJobUuid = theBulkExportJobEntity.getJobId(); JobParametersBuilder parameters = new JobParametersBuilder() .addString(BulkExportJobConfig.JOB_UUID_PARAMETER, theJobUuid) .addLong(BulkExportJobConfig.READ_CHUNK_PARAMETER, READ_CHUNK_SIZE); @@ -235,9 +226,8 @@ public class BulkDataExportSvcImpl implements IBulkDataExportSvc { ourLog.info("Submitting bulk export job {} to job scheduler", theJobUuid); try { - if (!StringUtils.isBlank(theGroupId)) { - parameters.addString(BulkExportJobConfig.GROUP_ID_PARAMETER, theGroupId); - parameters.addString(BulkExportJobConfig.EXPAND_MDM_PARAMETER, theExpandMdm); + if (isGroupBulkJob(theBulkExportJobEntity)) { + enhanceBulkParametersWithGroupParameters(theBulkExportJobEntity, parameters); myJobSubmitter.runJob(myGroupBulkExportJob, parameters.toJobParameters()); } else { myJobSubmitter.runJob(myBulkExportJob, parameters.toJobParameters()); @@ -247,6 +237,17 @@ public class BulkDataExportSvcImpl implements IBulkDataExportSvc { } } + private void enhanceBulkParametersWithGroupParameters(BulkExportJobEntity theBulkExportJobEntity, JobParametersBuilder theParameters) { + String theGroupId = getQueryParameterIfPresent(theBulkExportJobEntity.getRequest(), JpaConstants.PARAM_EXPORT_GROUP_ID); + String expandMdm = getQueryParameterIfPresent(theBulkExportJobEntity.getRequest(), JpaConstants.PARAM_EXPORT_MDM); + theParameters.addString(BulkExportJobConfig.GROUP_ID_PARAMETER, theGroupId); + theParameters.addString(BulkExportJobConfig.EXPAND_MDM_PARAMETER, expandMdm); + } + + private boolean isGroupBulkJob(BulkExportJobEntity theBulkExportJobEntity) { + return getQueryParameterIfPresent(theBulkExportJobEntity.getRequest(), JpaConstants.PARAM_EXPORT_GROUP_ID) != null; + } + @SuppressWarnings("unchecked") private IFhirResourceDao getBinaryDao() { return myDaoRegistry.getResourceDao("Binary"); diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java index 75e58debb17..3cf09bb4efc 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java @@ -187,7 +187,7 @@ public class JpaConstants { /** * The [id] of the group when $export is called on /Group/[id]/$export */ - public static final Object PARAM_EXPORT_GROUP_ID = "_groupId"; + public static final String PARAM_EXPORT_GROUP_ID = "_groupId"; /** * Whether mdm should be performed on group export items to expand the group items to linked items before performing the export