use of org.eyeseetea.malariacare.domain.exception.push.PushReportException 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));
}
});
}
use of org.eyeseetea.malariacare.domain.exception.push.PushReportException in project pictureapp by EyeSeeTea.
the class ConvertToSDKVisitor method saveSurveyStatus.
/**
* Saves changes in the survey (supposedly after a successful push)
*/
public void saveSurveyStatus(Map<String, PushReport> pushReportMap, final IPushController.IPushControllerCallback callback) {
Log.d(TAG, String.format("pushReportMap %d surveys savedSurveyStatus", surveys.size()));
for (int i = 0; i < surveys.size(); i++) {
Survey iSurvey = surveys.get(i);
// Sets the survey status as quarantine to prevent wrong reports on unexpected exception.
// F.E. if the app crash unexpected this survey will be checked again in the future push to prevent the duplicates
// in the server.
iSurvey.setStatus(Constants.SURVEY_QUARANTINE);
iSurvey.save();
Log.d(TAG, "saveSurveyStatus: Starting saving survey Set Survey status as QUARANTINE" + iSurvey.getId_survey() + " eventuid: " + iSurvey.getEventUid());
EventExtended iEvent = new EventExtended(events.get(iSurvey.getId_survey()));
PushReport pushReport = pushReportMap.get(iEvent.getEvent().getUId());
if (pushReport == null) {
// the survey was saved as quarantine.
new PushReportException("Error saving survey: report is null for this survey: " + iSurvey.getId_survey());
// The loop should continue without throw the Exception.
continue;
}
List<PushConflict> pushConflicts = pushReport.getPushConflicts();
// never resend, the survey is saved as survey in conflict.
if (pushConflicts != null && pushConflicts.size() > 0) {
Log.d(TAG, "saveSurveyStatus: survey conflicts not null " + iSurvey.getId_survey());
for (PushConflict pushConflict : pushConflicts) {
iSurvey.setStatus(Constants.SURVEY_CONFLICT);
iSurvey.save();
if (pushConflict.getUid() != null) {
Log.d(TAG, "saveSurveyStatus: PUSH process...Conflict in " + pushConflict.getUid() + " with error " + pushConflict.getValue() + " dataElement pushing survey: " + iSurvey.getId_survey());
callback.onInformativeError(new PushValueException(String.format(context.getString(R.string.error_conflict_message), iEvent.getEvent().getUId(), pushConflict.getUid(), pushConflict.getValue()) + ""));
}
}
continue;
}
// No errors -> Save and next
if (pushReport != null && !pushReport.hasPushErrors()) {
Log.d(TAG, "saveSurveyStatus: report without errors and status ok " + iSurvey.getId_survey());
if (iEvent.getEventDate() == null || iEvent.getEventDate().equals("")) {
// If eventDate is null the event is invalid. The event is sent but we need
// inform to the user.
callback.onInformativeError(new NullEventDateException(String.format(context.getString(R.string.error_message_push), iEvent.getEvent())));
}
saveSurveyFromImportSummary(iSurvey);
}
}
}
Aggregations