From 1e0981b4161bb849e2c054e3cb294a5166882eb6 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Fri, 19 Feb 2021 13:39:50 -0500 Subject: [PATCH] job call --- .../bulk/provider/BulkDataExportProvider.java | 51 +++++++++++++++++++ .../jpa/bulk/BulkDataExportProviderTest.java | 3 +- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/provider/BulkDataExportProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/provider/BulkDataExportProvider.java index fc52ad767cc..9c3fa464007 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/provider/BulkDataExportProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/bulk/provider/BulkDataExportProvider.java @@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.bulk.provider; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.bulk.api.BulkDataExportOptions; +import ca.uhn.fhir.jpa.bulk.api.GroupBulkDataExportOptions; import ca.uhn.fhir.jpa.bulk.api.IBulkDataExportSvc; import ca.uhn.fhir.jpa.bulk.model.BulkExportResponseJson; import ca.uhn.fhir.jpa.model.util.JpaConstants; @@ -178,4 +179,54 @@ public class BulkDataExportProvider { return StringUtils.removeEnd(theRequestDetails.getServerBaseForRequest(), "/"); } + /** + * Group/Id/$export + */ + @Operation(name = JpaConstants.OPERATION_EXPORT, manualResponse = true, idempotent = true, typeName = "Group") + public void groupExport( + @OperationParam(name = JpaConstants.PARAM_EXPORT_OUTPUT_FORMAT, min = 0, max = 1, typeName = "string") IPrimitiveType theOutputFormat, + @OperationParam(name = JpaConstants.PARAM_EXPORT_TYPE, min = 0, max = 1, typeName = "string") IPrimitiveType theType, + @OperationParam(name = JpaConstants.PARAM_EXPORT_SINCE, min = 0, max = 1, typeName = "instant") IPrimitiveType theSince, + @OperationParam(name = JpaConstants.PARAM_EXPORT_TYPE_FILTER, min = 0, max = 1, typeName = "string") IPrimitiveType theTypeFilter, + ServletRequestDetails theRequestDetails + ) { + + String preferHeader = theRequestDetails.getHeader(Constants.HEADER_PREFER); + PreferHeader prefer = RestfulServerUtils.parsePreferHeader(null, preferHeader); + if (prefer.getRespondAsync() == false) { + throw new InvalidRequestException("Must request async processing for $export"); + } + + String outputFormat = theOutputFormat != null ? theOutputFormat.getValueAsString() : null; + + Set resourceTypes = null; + if (theType != null) { + resourceTypes = ArrayUtil.commaSeparatedListToCleanSet(theType.getValueAsString()); + } + + Date since = null; + if (theSince != null) { + since = theSince.getValue(); + } + + Set filters = null; + if (theTypeFilter != null) { + filters = ArrayUtil.commaSeparatedListToCleanSet(theTypeFilter.getValueAsString()); + } + // FIXME set this + String groupId = "FIXME"; + IBulkDataExportSvc.JobInfo outcome = myBulkDataExportSvc.submitJob(new GroupBulkDataExportOptions(outputFormat, resourceTypes, since, filters, groupId)); + + String serverBase = getServerBase(theRequestDetails); + String pollLocation = serverBase + "/" + JpaConstants.OPERATION_EXPORT_POLL_STATUS + "?" + JpaConstants.PARAM_EXPORT_POLL_STATUS_JOB_ID + "=" + outcome.getJobId(); + + HttpServletResponse response = theRequestDetails.getServletResponse(); + + // Add standard headers + theRequestDetails.getServer().addHeadersToResponse(response); + + // Successful 202 Accepted + response.addHeader(Constants.HEADER_CONTENT_LOCATION, pollLocation); + response.setStatus(Constants.STATUS_HTTP_202_ACCEPTED); + } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportProviderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportProviderTest.java index 1d401b9fcf1..79ddbf3fdaf 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportProviderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportProviderTest.java @@ -64,7 +64,7 @@ public class BulkDataExportProviderTest { private static final String GROUP_ID = "G2401"; private static final String G_JOB_ID = "0000000-GGGGGG"; private Server myServer; - private FhirContext myCtx = FhirContext.forCached(FhirVersionEnum.R4); + private final FhirContext myCtx = FhirContext.forCached(FhirVersionEnum.R4); private int myPort; @Mock private IBulkDataExportSvc myBulkDataExportSvc; @@ -315,7 +315,6 @@ public class BulkDataExportProviderTest { ourLog.info("Request: {}", post); try (CloseableHttpResponse response = myClient.execute(post)) { ourLog.info("Response: {}", response.toString()); - assertEquals(202, response.getStatusLine().getStatusCode()); assertEquals("Accepted", response.getStatusLine().getReasonPhrase()); assertEquals("http://localhost:" + myPort + "/$export-poll-status?_jobId=" + G_JOB_ID, response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue());