Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.hisp</groupId>
<artifactId>dhis2-java-client</artifactId>
<version>2.1.9-SNAPSHOT</version>
<version>2.1.9</version>
<packaging>jar</packaging>

<name>DHIS 2 API client for Java</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/hisp/dhis/Dhis2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/org/hisp/dhis/Dhis2AsyncRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,11 +90,37 @@ public <T extends BaseHttpResponse> T post(HttpPost request, Class<T> 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 <T> the class type.
* @return a response message.
* @throws Dhis2ClientException if the POST operation failed.
*/
public <T extends BaseHttpResponse> T postEvent(HttpPost request, Class<T> klass) {
JobInfoResponse message = postAsyncRequest(request);

JobInfo jobInfo = message.getResponse();

jobInfo.setJobType(JobCategory.TRACKER_IMPORT_JOB);

return getJobSummary(klass, message, jobInfo);
}

private <T extends BaseHttpResponse> T getJobSummary(Class<T> klass, JobInfoResponse message, JobInfo jobInfo) {
log.info(
"Push response: '{}', '{}', job: '{}'",
message.getHttpStatus(),
message.getMessage(),
jobInfo);
jobInfo);

JobNotification notification = waitForCompletion(jobInfo);

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/hisp/dhis/response/job/JobCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down