use of org.eyeseetea.malariacare.domain.exception.push.PushValueException 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);
}
}
}
use of org.eyeseetea.malariacare.domain.exception.push.PushValueException in project pictureapp by EyeSeeTea.
the class WSPushController method checkPushResult.
private void checkPushResult(SurveyWSResult surveyWSResult) {
for (SurveyWSResponseAction responseAction : surveyWSResult.getActions()) {
if (!responseAction.isSuccess()) {
String message = String.format(PreferencesState.getInstance().getContext().getString(R.string.survey_error), responseAction.getActionId(), responseAction.getMessage(), responseAction.getResponse().getMsg());
mCallback.onInformativeError(new PushValueException(message));
}
}
for (Survey survey : mSurveys) {
survey.setStatus(Constants.SURVEY_SENT);
survey.save();
}
mCallback.onComplete();
}
Aggregations