Search in sources :

Example 1 with ClosedUserPushException

use of org.eyeseetea.malariacare.domain.exception.ClosedUserPushException 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();
        Boolean isUserClosed = false;
        User loggedUser = User.getLoggedUser();
        if (loggedUser != null && loggedUser.getUid() != null) {
            try {
                isUserClosed = ServerAPIController.isUserClosed(User.getLoggedUser().getUid());
            } catch (ApiCallException e) {
                isUserClosed = null;
            }
        }
        if (isUserClosed == null) {
            callback.onError(new ApiCallException("The user api call returns a exception"));
            return;
        }
        if (isUserClosed) {
            Log.d(TAG, "The user is closed, Surveys not sent");
            callback.onError(new ClosedUserPushException());
        } else {
            if (surveys == null || surveys.size() == 0) {
                callback.onError(new SurveysToPushNotFoundException("Null surveys"));
                return;
            }
            Log.d(TAG, "wipe events");
            mPushDhisSDKDataSource.wipeEvents();
            try {
                Log.d(TAG, "convert surveys to sdk");
                convertToSDK(surveys);
            } catch (Exception ex) {
                callback.onError(new ConversionException(ex));
                return;
            }
            if (EventExtended.getAllEvents().size() == 0) {
                callback.onError(new ConvertedEventsToPushNotFoundException());
                return;
            } else {
                Log.d(TAG, "push data");
                pushData(callback);
            }
        }
    }
}
Also used : ConversionException(org.eyeseetea.malariacare.domain.exception.ConversionException) Survey(org.eyeseetea.malariacare.data.database.model.Survey) User(org.eyeseetea.malariacare.data.database.model.User) ApiCallException(org.eyeseetea.malariacare.domain.exception.ApiCallException) SurveysToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException) ClosedUserPushException(org.eyeseetea.malariacare.domain.exception.ClosedUserPushException) ConvertedEventsToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.ConvertedEventsToPushNotFoundException) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) ApiCallException(org.eyeseetea.malariacare.domain.exception.ApiCallException) ClosedUserPushException(org.eyeseetea.malariacare.domain.exception.ClosedUserPushException) ConvertedEventsToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.ConvertedEventsToPushNotFoundException) PushReportException(org.eyeseetea.malariacare.domain.exception.push.PushReportException) SurveysToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException) ConversionException(org.eyeseetea.malariacare.domain.exception.ConversionException) PushDhisException(org.eyeseetea.malariacare.domain.exception.push.PushDhisException)

Aggregations

Survey (org.eyeseetea.malariacare.data.database.model.Survey)1 User (org.eyeseetea.malariacare.data.database.model.User)1 ApiCallException (org.eyeseetea.malariacare.domain.exception.ApiCallException)1 ClosedUserPushException (org.eyeseetea.malariacare.domain.exception.ClosedUserPushException)1 ConversionException (org.eyeseetea.malariacare.domain.exception.ConversionException)1 ConvertedEventsToPushNotFoundException (org.eyeseetea.malariacare.domain.exception.ConvertedEventsToPushNotFoundException)1 NetworkException (org.eyeseetea.malariacare.domain.exception.NetworkException)1 SurveysToPushNotFoundException (org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException)1 PushDhisException (org.eyeseetea.malariacare.domain.exception.push.PushDhisException)1 PushReportException (org.eyeseetea.malariacare.domain.exception.push.PushReportException)1