job call
This commit is contained in:
parent
00a8e3897a
commit
1e0981b416
|
@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.bulk.provider;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.jpa.bulk.api.BulkDataExportOptions;
|
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.api.IBulkDataExportSvc;
|
||||||
import ca.uhn.fhir.jpa.bulk.model.BulkExportResponseJson;
|
import ca.uhn.fhir.jpa.bulk.model.BulkExportResponseJson;
|
||||||
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
import ca.uhn.fhir.jpa.model.util.JpaConstants;
|
||||||
|
@ -178,4 +179,54 @@ public class BulkDataExportProvider {
|
||||||
return StringUtils.removeEnd(theRequestDetails.getServerBaseForRequest(), "/");
|
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<String> theOutputFormat,
|
||||||
|
@OperationParam(name = JpaConstants.PARAM_EXPORT_TYPE, min = 0, max = 1, typeName = "string") IPrimitiveType<String> theType,
|
||||||
|
@OperationParam(name = JpaConstants.PARAM_EXPORT_SINCE, min = 0, max = 1, typeName = "instant") IPrimitiveType<Date> theSince,
|
||||||
|
@OperationParam(name = JpaConstants.PARAM_EXPORT_TYPE_FILTER, min = 0, max = 1, typeName = "string") IPrimitiveType<String> 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<String> resourceTypes = null;
|
||||||
|
if (theType != null) {
|
||||||
|
resourceTypes = ArrayUtil.commaSeparatedListToCleanSet(theType.getValueAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Date since = null;
|
||||||
|
if (theSince != null) {
|
||||||
|
since = theSince.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class BulkDataExportProviderTest {
|
||||||
private static final String GROUP_ID = "G2401";
|
private static final String GROUP_ID = "G2401";
|
||||||
private static final String G_JOB_ID = "0000000-GGGGGG";
|
private static final String G_JOB_ID = "0000000-GGGGGG";
|
||||||
private Server myServer;
|
private Server myServer;
|
||||||
private FhirContext myCtx = FhirContext.forCached(FhirVersionEnum.R4);
|
private final FhirContext myCtx = FhirContext.forCached(FhirVersionEnum.R4);
|
||||||
private int myPort;
|
private int myPort;
|
||||||
@Mock
|
@Mock
|
||||||
private IBulkDataExportSvc myBulkDataExportSvc;
|
private IBulkDataExportSvc myBulkDataExportSvc;
|
||||||
|
@ -315,7 +315,6 @@ public class BulkDataExportProviderTest {
|
||||||
ourLog.info("Request: {}", post);
|
ourLog.info("Request: {}", post);
|
||||||
try (CloseableHttpResponse response = myClient.execute(post)) {
|
try (CloseableHttpResponse response = myClient.execute(post)) {
|
||||||
ourLog.info("Response: {}", response.toString());
|
ourLog.info("Response: {}", response.toString());
|
||||||
|
|
||||||
assertEquals(202, response.getStatusLine().getStatusCode());
|
assertEquals(202, response.getStatusLine().getStatusCode());
|
||||||
assertEquals("Accepted", response.getStatusLine().getReasonPhrase());
|
assertEquals("Accepted", response.getStatusLine().getReasonPhrase());
|
||||||
assertEquals("http://localhost:" + myPort + "/$export-poll-status?_jobId=" + G_JOB_ID, response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue());
|
assertEquals("http://localhost:" + myPort + "/$export-poll-status?_jobId=" + G_JOB_ID, response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue());
|
||||||
|
|
Loading…
Reference in New Issue