From db81f3322ffa459d320f88da0794e18996bc7fac Mon Sep 17 00:00:00 2001 From: Olaniyan Folajimi Date: Fri, 2 May 2025 08:35:12 +0100 Subject: [PATCH 1/6] feat: add streaming events import --- src/main/java/org/hisp/dhis/Dhis2.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/org/hisp/dhis/Dhis2.java b/src/main/java/org/hisp/dhis/Dhis2.java index f9f9bc04..5e57e12c 100644 --- a/src/main/java/org/hisp/dhis/Dhis2.java +++ b/src/main/java/org/hisp/dhis/Dhis2.java @@ -2391,6 +2391,27 @@ public EventResponse saveEvents(Events events) { EventResponse.class); } + /** + * Saves an {@link Events}. The operation is synchronous. + * + *

Requires DHIS 2 version 2.40 or later. + * + * @param inputStream the input stream representing the data value set JSON payload. + * @return {@link EventResponse} holding information about the operation. + */ + public EventResponse saveEvents(InputStream inputStream) { + URIBuilder builder = config.getResolvedUriBuilder().appendPath("tracker"); + + HttpPost request = + getPostRequest( + HttpUtils.build(builder), + new InputStreamEntity(inputStream, ContentType.APPLICATION_JSON)); + + Dhis2AsyncRequest asyncRequest = new Dhis2AsyncRequest(config, httpClient, objectMapper); + + return asyncRequest.post(request, EventResponse.class); + } + /** * Retrieves an {@link Event}. * From 01924d2901e63885ec603eec97ffb83167ebb170 Mon Sep 17 00:00:00 2001 From: Olaniyan Folajimi Date: Fri, 2 May 2025 08:36:46 +0100 Subject: [PATCH 2/6] chore: Bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2f3e9a2b..5e3297f0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.hisp dhis2-java-client - 2.1.7-SNAPSHOT + 2.1.7 jar DHIS 2 API client for Java From 0ffbff446e1d5cecd81a8209d176bd195c56f392 Mon Sep 17 00:00:00 2001 From: Olaniyan Folajimi Date: Fri, 2 May 2025 08:46:54 +0100 Subject: [PATCH 3/6] chore: Bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5e3297f0..7ce83da6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.hisp dhis2-java-client - 2.1.7 + 2.1.8-SNAPSHOT jar DHIS 2 API client for Java From 3a395cd462c8d50873abc62f1bd0823cf0d74f20 Mon Sep 17 00:00:00 2001 From: Olaniyan Folajimi Date: Fri, 2 May 2025 08:51:35 +0100 Subject: [PATCH 4/6] chore: Bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b47fc259..f8f60b21 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.hisp dhis2-java-client - 2.1.8-SNAPSHOT + 2.1.8 jar DHIS 2 API client for Java From c6b903158b3275d59e0d8316dd9dbf107717fb8f Mon Sep 17 00:00:00 2001 From: Olaniyan Folajimi Date: Mon, 5 May 2025 09:43:36 +0100 Subject: [PATCH 5/6] fix: Tracker job import bug --- pom.xml | 2 +- src/main/java/org/hisp/dhis/Dhis2.java | 2 +- .../java/org/hisp/dhis/Dhis2AsyncRequest.java | 29 ++++++++++++++++++- .../hisp/dhis/response/job/JobCategory.java | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) 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, From a8b3fe28f589183cf1ec67e6817e81b8708f40d1 Mon Sep 17 00:00:00 2001 From: Olaniyan Folajimi Date: Mon, 5 May 2025 09:57:17 +0100 Subject: [PATCH 6/6] fix: version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8b8cd6ee..d7b1ad90 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.hisp dhis2-java-client - 2.1.9 + 2.2.0-SNAPSHOT jar DHIS 2 API client for Java