Search in sources :

Example 1 with PushDhisException

use of org.eyeseetea.malariacare.domain.exception.push.PushDhisException in project pictureapp by EyeSeeTea.

the class PushDhisSDKDataSource method pushEvents.

private void pushEvents(final IDataSourceCallback<Map<String, PushReport>> callback) {
    final Set<String> eventUids = getEventUidToBePushed();
    if (eventUids.isEmpty() || eventUids.size() == 0) {
        callback.onError(new ConvertedEventsToPushNotFoundException());
        return;
    }
    Observable<Map<String, ImportSummary>> eventObserver = D2.events().push(eventUids);
    eventObserver.subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).subscribe(new Action1<Map<String, ImportSummary>>() {

        @Override
        public void call(Map<String, ImportSummary> mapEventsImportSummary) {
            if (mapEventsImportSummary == null) {
                callback.onError(new PushReportException("Error during push"));
                return;
            }
            Log.d(TAG, "Push of events finish. Number of events: " + mapEventsImportSummary.size());
            try {
                callback.onSuccess(PushReportMapper.mapFromImportSummariesToPushReports(mapEventsImportSummary));
            } catch (NullPointerException e) {
                callback.onError(new PushReportException(e));
            }
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            callback.onError(new PushDhisException(throwable));
        }
    });
}
Also used : ImportSummary(org.hisp.dhis.client.sdk.models.common.importsummary.ImportSummary) ConvertedEventsToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.ConvertedEventsToPushNotFoundException) PushDhisException(org.eyeseetea.malariacare.domain.exception.push.PushDhisException) Map(java.util.Map) PushReportException(org.eyeseetea.malariacare.domain.exception.push.PushReportException)

Aggregations

Map (java.util.Map)1 ConvertedEventsToPushNotFoundException (org.eyeseetea.malariacare.domain.exception.ConvertedEventsToPushNotFoundException)1 PushDhisException (org.eyeseetea.malariacare.domain.exception.push.PushDhisException)1 PushReportException (org.eyeseetea.malariacare.domain.exception.push.PushReportException)1 ImportSummary (org.hisp.dhis.client.sdk.models.common.importsummary.ImportSummary)1