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);
}
}
}
}
Aggregations