Search in sources :

Example 1 with ImportSummaryErrorException

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();
    }
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) Conflict(org.hisp.dhis.client.sdk.models.common.importsummary.Conflict) ImportSummaryErrorException(org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException) ImportSummary(org.hisp.dhis.client.sdk.models.common.importsummary.ImportSummary)

Aggregations

Survey (org.eyeseetea.malariacare.data.database.model.Survey)1 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)1 ImportSummaryErrorException (org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException)1 Conflict (org.hisp.dhis.client.sdk.models.common.importsummary.Conflict)1 ImportSummary (org.hisp.dhis.client.sdk.models.common.importsummary.ImportSummary)1