use of org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException 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, ImportSummary> importSummaryMap, final IPushController.IPushControllerCallback callback) {
Log.d(TAG, String.format("ImportSummary %d surveys savedSurveyStatus", surveys.size()));
for (int i = 0; i < surveys.size(); i++) {
Survey iSurvey = surveys.get(i);
iSurvey.setStatus(Constants.SURVEY_QUARANTINE);
Log.d(TAG, "saveSurveyStatus: Starting saving survey Set Survey status as QUARANTINE" + iSurvey.getId_survey() + " eventuid: " + iSurvey.getEventUid());
iSurvey.save();
if (importSummaryMap == null) {
continue;
}
EventExtended iEvent = new EventExtended(events.get(iSurvey.getId_survey()));
ImportSummary importSummary = importSummaryMap.get(iEvent.getEvent().getUId());
List<Conflict> conflicts = importSummary.getConflicts();
// never resend, the survey is saved as survey in conflict.
if (conflicts != null && conflicts.size() > 0) {
for (Conflict conflict : conflicts) {
Log.d(TAG, "saveSurveyStatus: Faileditem not null " + iSurvey.getId_survey());
if (conflict.getObject() != null) {
Log.d(TAG, "saveSurveyStatus: PUSH process...Conflict in " + conflict.getObject() + " with error " + conflict.getValue() + " dataelement pushing survey: " + iSurvey.getId_survey());
callback.onError(new ImportSummaryErrorException(String.format(context.getString(R.string.error_conflict_message), iEvent.getEvent().getUId(), conflict.getObject(), conflict.getValue()) + ""));
iSurvey.setStatus(Constants.SURVEY_CONFLICT);
}
}
iSurvey.save();
continue;
} else if (importSummary != null && importSummary.getStatus() == ImportSummary.Status.ERROR) {
Log.d(TAG, "saveSurveyStatus: PUSH error process..." + importSummary.getDescription() + " dataelement pushing survey: " + iSurvey.getId_survey());
callback.onError(new ImportSummaryErrorException(importSummary.getDescription() + ""));
iSurvey.setStatus(Constants.SURVEY_CONFLICT);
iSurvey.save();
}
if (importSummary == null) {
Log.d(TAG, "saveSurveyStatus: importSummary null " + iSurvey.getId_survey());
//Saved as quarantine
continue;
} else {
Log.d(TAG, "saveSurveyStatus: " + importSummary.toString());
}
//No errors -> Save and next
if (!hasImportSummaryErrors(importSummary)) {
Log.d(TAG, "saveSurveyStatus: importSummary without errors and status ok " + iSurvey.getId_survey());
saveSurveyFromImportSummary(iSurvey);
continue;
}
//Generated event must be remove too
iEvent.delete();
}
}
Aggregations