Search in sources :

Example 1 with PushValueException

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);
        }
    }
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) PushReport(org.eyeseetea.malariacare.domain.entity.pushsummary.PushReport) NullEventDateException(org.eyeseetea.malariacare.domain.exception.push.NullEventDateException) PushValueException(org.eyeseetea.malariacare.domain.exception.push.PushValueException) PushConflict(org.eyeseetea.malariacare.domain.entity.pushsummary.PushConflict) PushReportException(org.eyeseetea.malariacare.domain.exception.push.PushReportException)

Example 2 with PushValueException

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();
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) PushValueException(org.eyeseetea.malariacare.domain.exception.push.PushValueException) SurveyWSResponseAction(org.eyeseetea.malariacare.data.sync.exporter.model.SurveyWSResponseAction)

Aggregations

Survey (org.eyeseetea.malariacare.data.database.model.Survey)2 PushValueException (org.eyeseetea.malariacare.domain.exception.push.PushValueException)2 SurveyWSResponseAction (org.eyeseetea.malariacare.data.sync.exporter.model.SurveyWSResponseAction)1 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)1 PushConflict (org.eyeseetea.malariacare.domain.entity.pushsummary.PushConflict)1 PushReport (org.eyeseetea.malariacare.domain.entity.pushsummary.PushReport)1 NullEventDateException (org.eyeseetea.malariacare.domain.exception.push.NullEventDateException)1 PushReportException (org.eyeseetea.malariacare.domain.exception.push.PushReportException)1