Search in sources :

Example 1 with ConversionException

use of org.eyeseetea.malariacare.domain.exception.ConversionException in project pictureapp by EyeSeeTea.

the class PushController method push.

public void push(final IPushControllerCallback callback) {
    if (!ServerAPIController.isNetworkAvailable()) {
        Log.d(TAG, "No network");
        callback.onError(new NetworkException());
    } else {
        Log.d(TAG, "Network connected");
        List<Survey> surveys = Survey.getAllCompletedSurveysNoReceiptReset();
        //Fixme Check if is necessary other conditions
        if (surveys == null || surveys.size() == 0) {
            Log.d("DpBlank", "Sets of Surveys to push");
            callback.onError(new SurveysToPushNotFoundException());
        } else {
            for (Survey srv : surveys) {
                Log.d("DpBlank", "Survey to push " + srv.toString());
                for (Value dv : srv.getValuesFromDB()) {
                    Log.d("DpBlank", "Values to push " + dv.toString());
                }
            }
            mPushDhisSDKDataSource.wipeEvents();
            try {
                convertToSDK(surveys);
            } catch (Exception ex) {
                callback.onError(new ConversionException(ex));
            }
            if (EventExtended.getAllEvents().size() == 0) {
                callback.onError(new ConversionException());
            } else {
                pushData(callback);
            }
        }
    }
}
Also used : ConversionException(org.eyeseetea.malariacare.domain.exception.ConversionException) Survey(org.eyeseetea.malariacare.data.database.model.Survey) SurveysToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException) Value(org.eyeseetea.malariacare.data.database.model.Value) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) ImportSummaryErrorException(org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException) SurveysToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException) ConversionException(org.eyeseetea.malariacare.domain.exception.ConversionException)

Aggregations

Survey (org.eyeseetea.malariacare.data.database.model.Survey)1 Value (org.eyeseetea.malariacare.data.database.model.Value)1 ConversionException (org.eyeseetea.malariacare.domain.exception.ConversionException)1 ImportSummaryErrorException (org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException)1 NetworkException (org.eyeseetea.malariacare.domain.exception.NetworkException)1 SurveysToPushNotFoundException (org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException)1