use of org.eyeseetea.malariacare.domain.exception.ApiCallException in project pictureapp by EyeSeeTea.
the class PushServiceStrategy method executePush.
protected void executePush() {
IPushController pushController;
try {
pushController = new WSPushController();
} catch (IllegalArgumentException e) {
e.printStackTrace();
showInDialog(PreferencesState.getInstance().getContext().getString(R.string.webservice_url_error_title), String.format(PreferencesState.getInstance().getContext().getString(R.string.webservice_url_error), e.getMessage()));
return;
}
IAsyncExecutor asyncExecutor = new AsyncExecutor();
IMainExecutor mainExecutor = new UIThreadExecutor();
ISurveyRepository surveyRepository = new SurveyLocalDataSource();
IOrganisationUnitRepository orgUnitRepository = new OrganisationUnitRepository();
SurveysThresholds surveysThresholds = new SurveysThresholds(BuildConfig.LimitSurveysCount, BuildConfig.LimitSurveysTimeHours);
PushUseCase pushUseCase = new PushUseCase(pushController, asyncExecutor, mainExecutor, surveysThresholds, surveyRepository, orgUnitRepository);
SurveyChecker.launchQuarantineChecker();
pushUseCase.execute(new PushUseCase.Callback() {
@Override
public void onComplete() {
Log.d(TAG, "PUSHUSECASE WITHOUT ERROR push complete");
mPushService.onPushFinished();
}
@Override
public void onPushInProgressError() {
Log.d(TAG, "PUSHUSECASE ERROR Push stopped, There is already a push in progress");
}
@Override
public void onPushError() {
onError("PUSHUSECASE ERROR Unexpected error has occurred in push process");
}
@Override
public void onSurveysNotFoundError() {
onError("PUSHUSECASE ERROR Pending surveys not found");
}
@Override
public void onConversionError() {
showInDialog(PreferencesState.getInstance().getContext().getString(R.string.error_conflict_title), PreferencesState.getInstance().getContext().getString(R.string.ws_conversion_error));
}
@Override
public void onNetworkError() {
onError("PUSHUSECASE ERROR Network not available");
}
@Override
public void onInformativeError(String message) {
showInDialog(PreferencesState.getInstance().getContext().getString(R.string.error_conflict_title), "PUSHUSECASE ERROR " + message + PreferencesState.getInstance().isPushInProgress());
}
@Override
public void onBannedOrgUnit() {
showInDialog("", PreferencesState.getInstance().getContext().getString(R.string.exception_org_unit_banned));
}
@Override
public void onReOpenOrgUnit() {
showInDialog("", String.format(PreferencesState.getInstance().getContext().getString(R.string.dialog_reopen_org_unit), PreferencesState.getInstance().getOrgUnit()));
}
@Override
public void onApiCallError() {
onError("API call error");
}
@Override
public void onApiCallError(ApiCallException e) {
onError("PUSHUSECASE ERROR " + e.getMessage());
e.printStackTrace();
}
@Override
public void onClosedUser() {
onError("PUSHUSECASE ERROR on closedUser " + PreferencesState.getInstance().isPushInProgress());
closeUserLogout();
}
});
}
use of org.eyeseetea.malariacare.domain.exception.ApiCallException in project pictureapp by EyeSeeTea.
the class ServerAPIController method patchDescriptionClosedDate.
static void patchDescriptionClosedDate(String url, String orgUnitUID, String orgUnitDescription) throws ApiCallException {
// https://malariacare.psi.org/api/organisationUnits/u5jlxuod8xQ/closedDate
try {
String urlPathClosedDescription = getPatchClosedDescriptionUrl(url, orgUnitUID);
JSONObject data = prepareClosingDescriptionValue(orgUnitDescription);
Response response = ServerApiCallExecution.executeCall(data, urlPathClosedDescription, "PATCH");
ServerApiUtils.checkResponse(response, null);
} catch (JSONException e) {
throw new ApiCallException(e);
}
}
use of org.eyeseetea.malariacare.domain.exception.ApiCallException in project pictureapp by EyeSeeTea.
the class ServerAPIController method patchClosedDate.
/**
* Updates the orgUnit adding a closedDate
*/
static void patchClosedDate(String url, String orgUnitUID) throws ApiCallException {
// https://malariacare.psi.org/api/organisationUnits/u5jlxuod8xQ/closedDate
try {
String urlPathClosedDate = getPatchClosedDateUrl(url, orgUnitUID);
JSONObject data = prepareTodayDateValue();
Response response = ServerApiCallExecution.executeCall(data, urlPathClosedDate, "PATCH");
ServerApiUtils.checkResponse(response, null);
} catch (JSONException e) {
throw new ApiCallException(e);
}
}
use of org.eyeseetea.malariacare.domain.exception.ApiCallException in project pictureapp by EyeSeeTea.
the class SurveyChecker method checkAllQuarantineSurveys.
/**
* Download the related events. and checks all the quarantine surveys.
* If a survey is in the server, the survey should be set as sent. Else, the survey should be
* set as completed and it will be resend.
*/
public static void checkAllQuarantineSurveys() {
List<Program> programs = Program.getAllPrograms();
for (Program program : programs) {
for (OrgUnit orgUnit : Survey.getQuarantineOrgUnits(program.getId_program())) {
List<Survey> quarantineSurveys = Survey.getAllQuarantineSurveysByProgramAndOrgUnit(program, orgUnit);
if (quarantineSurveys.size() == 0) {
continue;
}
Date minDate = Survey.getMinQuarantineCompletionDateByProgramAndOrgUnit(program, orgUnit);
Date maxDate = Survey.getMaxQuarantineEventDateByProgramAndOrgUnit(program, orgUnit);
List<EventExtended> events;
try {
events = getEvents(program.getUid(), orgUnit.getUid(), minDate, maxDate);
} catch (ApiCallException e) {
e.printStackTrace();
return;
}
if (events == null) {
return;
}
for (Survey survey : quarantineSurveys) {
if (events.size() > 0) {
updateQuarantineSurveysStatus(events, survey);
} else {
changeSurveyStatusFromQuarantineTo(survey, Constants.SURVEY_COMPLETED);
}
}
}
}
}
use of org.eyeseetea.malariacare.domain.exception.ApiCallException in project pictureapp by EyeSeeTea.
the class SurveyChecker method getEvents.
/**
* Get events filtered by program orgUnit and between dates.
*/
public static List<EventExtended> getEvents(String program, String orgUnit, Date minDate, Date maxDate) throws ApiCallException {
Response response;
String DHIS_URL = PreferencesState.getInstance().getDhisURL();
String startDate = EventExtended.format(minDate, EventExtended.AMERICAN_DATE_FORMAT);
String endDate = EventExtended.format(new Date(maxDate.getTime() + (8 * 24 * 60 * 60 * 1000)), EventExtended.AMERICAN_DATE_FORMAT);
String url = SurveyCheckerStrategy.getApiEventUrl(DHIS_URL, program, orgUnit, startDate, endDate);
Log.d(TAG, url);
url = ServerApiUtils.encodeBlanks(url);
response = ServerApiCallExecution.executeCall(null, url, "GET");
JSONObject events = null;
try {
events = new JSONObject(ServerApiUtils.getReadableBodyResponse(response));
} catch (JSONException ex) {
throw new ApiCallException(ex);
}
JsonNode jsonNode = ServerApiUtils.getJsonNodeMappedResponse(events);
return getEvents(jsonNode);
}
Aggregations