Search in sources :

Example 1 with PushConflict

use of org.eyeseetea.malariacare.domain.entity.pushsummary.PushConflict in project pictureapp by EyeSeeTea.

the class PushReportMapper method mapFromImportSummaryToPushReport.

public static PushReport mapFromImportSummaryToPushReport(ImportSummary importSummary, String importSummaryKey) {
    PushReport pushReport = new PushReport();
    List<PushConflict> conflictList = new ArrayList<>();
    if (importSummary.getConflicts() != null) {
        for (Conflict conflict : importSummary.getConflicts()) {
            conflictList.add(new PushConflict(conflict.getObject(), conflict.getValue()));
        }
    }
    pushReport.setPushConflicts(conflictList);
    pushReport.setDescription(importSummary.getDescription());
    pushReport.setHref(importSummary.getHref());
    ImportCount importCount = importSummary.getImportCount();
    if (importCount != null) {
        pushReport.setPushedValuesCount(new PushedValuesCount(importCount.getImported(), importCount.getUpdated(), importCount.getIgnored(), importCount.getDeleted()));
    }
    pushReport.setReference(importSummary.getReference());
    if (importSummary.getStatus() == ImportSummary.Status.ERROR) {
        pushReport.setStatus(PushReport.Status.ERROR);
    }
    if (importSummary.getStatus() == ImportSummary.Status.OK) {
        pushReport.setStatus(PushReport.Status.OK);
    }
    if (importSummary.getStatus() == ImportSummary.Status.SUCCESS) {
        pushReport.setStatus(PushReport.Status.SUCCESS);
    }
    pushReport.setEventUid(importSummaryKey);
    return pushReport;
}
Also used : PushedValuesCount(org.eyeseetea.malariacare.domain.entity.pushsummary.PushedValuesCount) PushReport(org.eyeseetea.malariacare.domain.entity.pushsummary.PushReport) PushConflict(org.eyeseetea.malariacare.domain.entity.pushsummary.PushConflict) Conflict(org.hisp.dhis.client.sdk.models.common.importsummary.Conflict) ImportCount(org.hisp.dhis.client.sdk.models.common.importsummary.ImportCount) PushConflict(org.eyeseetea.malariacare.domain.entity.pushsummary.PushConflict) ArrayList(java.util.ArrayList)

Example 2 with PushConflict

use of org.eyeseetea.malariacare.domain.entity.pushsummary.PushConflict 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)

Aggregations

PushConflict (org.eyeseetea.malariacare.domain.entity.pushsummary.PushConflict)2 PushReport (org.eyeseetea.malariacare.domain.entity.pushsummary.PushReport)2 ArrayList (java.util.ArrayList)1 Survey (org.eyeseetea.malariacare.data.database.model.Survey)1 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)1 PushedValuesCount (org.eyeseetea.malariacare.domain.entity.pushsummary.PushedValuesCount)1 NullEventDateException (org.eyeseetea.malariacare.domain.exception.push.NullEventDateException)1 PushReportException (org.eyeseetea.malariacare.domain.exception.push.PushReportException)1 PushValueException (org.eyeseetea.malariacare.domain.exception.push.PushValueException)1 Conflict (org.hisp.dhis.client.sdk.models.common.importsummary.Conflict)1 ImportCount (org.hisp.dhis.client.sdk.models.common.importsummary.ImportCount)1