diff --git a/pom.xml b/pom.xml index e9710bee..8b8cd6ee 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.hisp dhis2-java-client - 2.1.9-SNAPSHOT + 2.1.9 jar DHIS 2 API client for Java diff --git a/src/main/java/org/hisp/dhis/Dhis2.java b/src/main/java/org/hisp/dhis/Dhis2.java index 5e57e12c..f13836b2 100644 --- a/src/main/java/org/hisp/dhis/Dhis2.java +++ b/src/main/java/org/hisp/dhis/Dhis2.java @@ -2409,7 +2409,7 @@ public EventResponse saveEvents(InputStream inputStream) { Dhis2AsyncRequest asyncRequest = new Dhis2AsyncRequest(config, httpClient, objectMapper); - return asyncRequest.post(request, EventResponse.class); + return asyncRequest.postEvent(request, EventResponse.class); } /** diff --git a/src/main/java/org/hisp/dhis/Dhis2AsyncRequest.java b/src/main/java/org/hisp/dhis/Dhis2AsyncRequest.java index 54c3bc61..529b2315 100644 --- a/src/main/java/org/hisp/dhis/Dhis2AsyncRequest.java +++ b/src/main/java/org/hisp/dhis/Dhis2AsyncRequest.java @@ -44,6 +44,7 @@ import org.apache.hc.core5.http.io.entity.EntityUtils; import org.hisp.dhis.response.BaseHttpResponse; import org.hisp.dhis.response.Dhis2ClientException; +import org.hisp.dhis.response.job.JobCategory; import org.hisp.dhis.response.job.JobInfo; import org.hisp.dhis.response.job.JobInfoResponse; import org.hisp.dhis.response.job.JobNotification; @@ -89,11 +90,37 @@ public T post(HttpPost request, Class klass) { JobInfo jobInfo = message.getResponse(); + return getJobSummary(klass, message, jobInfo); + } + + /** + * Executes the given HTTP POST request. The request must be a DHIS 2 async request. The method + * will use the DHIS 2 tasks and task summary API endpoints to poll for the task status, and + * eventually return a task summary when the task is complete. The DHIS 2 /tracker async response + * does not include the JobCategory. We need to inject it here. + * + * @param request the {@link HttpPost}. + * @param klass the class type. + * @param the class type. + * @return a response message. + * @throws Dhis2ClientException if the POST operation failed. + */ + public T postEvent(HttpPost request, Class klass) { + JobInfoResponse message = postAsyncRequest(request); + + JobInfo jobInfo = message.getResponse(); + + jobInfo.setJobType(JobCategory.TRACKER_IMPORT_JOB); + + return getJobSummary(klass, message, jobInfo); + } + + private T getJobSummary(Class klass, JobInfoResponse message, JobInfo jobInfo) { log.info( "Push response: '{}', '{}', job: '{}'", message.getHttpStatus(), message.getMessage(), - jobInfo); + jobInfo); JobNotification notification = waitForCompletion(jobInfo); diff --git a/src/main/java/org/hisp/dhis/response/job/JobCategory.java b/src/main/java/org/hisp/dhis/response/job/JobCategory.java index a15a16f2..6d8addf3 100644 --- a/src/main/java/org/hisp/dhis/response/job/JobCategory.java +++ b/src/main/java/org/hisp/dhis/response/job/JobCategory.java @@ -35,6 +35,7 @@ public enum JobCategory { DATA_SYNC, PROGRAM_DATA_SYNC, TRACKER_PROGRAMS_DATA_SYNC, + TRACKER_IMPORT_JOB, EVENT_PROGRAMS_DATA_SYNC, FILE_RESOURCE_CLEANUP, IMAGE_PROCESSING,