Search in sources :

Example 16 with ApiCallException

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

the class ServerApiUtils method getJSONObjectFromString.

protected static JSONObject getJSONObjectFromString(String readableBodyResponse) throws ApiCallException {
    try {
        JSONObject jsonResponse = new JSONObject(readableBodyResponse);
        Log.i(TAG, "parseResponse: " + jsonResponse);
        return jsonResponse;
    } catch (JSONException e) {
        throw new ApiCallException(e);
    }
}
Also used : JSONObject(org.json.JSONObject) ApiCallException(org.eyeseetea.malariacare.domain.exception.ApiCallException) JSONException(org.json.JSONException)

Example 17 with ApiCallException

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

the class LoginUseCase method pullOrganisationCredentials.

private void pullOrganisationCredentials() {
    Credentials orgUnitCredentials = null;
    try {
        OrganisationUnit orgUnit = mOrgUnitDataSource.getUserOrgUnit(insertedCredentials);
        if (orgUnit == null) {
            notifyInvalidCredentials();
            return;
        }
        orgUnitCredentials = new Credentials(insertedCredentials.getServerURL(), orgUnit.getCode(), orgUnit.getPin());
    } catch (ApiCallException e) {
        if (e.getCause() instanceof IOException) {
            notifyUnexpectedError();
        } else {
            e.printStackTrace();
            notifyConfigJsonNotPresent();
        }
    } catch (NetworkException e) {
        e.printStackTrace();
        checkUserCredentialsWithOrgUnit(mCredentialsLocalDataSource.getOrganisationCredentials(), true);
    }
    mCredentialsLocalDataSource.saveOrganisationCredentials(orgUnitCredentials);
    checkUserCredentialsWithOrgUnit(orgUnitCredentials, false);
}
Also used : OrganisationUnit(org.eyeseetea.malariacare.domain.entity.OrganisationUnit) ApiCallException(org.eyeseetea.malariacare.domain.exception.ApiCallException) IOException(java.io.IOException) ConfigJsonIOException(org.eyeseetea.malariacare.domain.exception.ConfigJsonIOException) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials)

Example 18 with ApiCallException

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

the class APushServiceStrategy method executePush.

protected void executePush() {
    PushController pushController = new PushController(mPushService);
    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() {
            onError("PUSHUSECASE ERROR An error has occurred to the conversion in push process");
        }

        @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(ApiCallException e) {
            onError("PUSHUSECASE ERROR " + e.getMessage());
        }

        @Override
        public void onClosedUser() {
            onError("PUSHUSECASE ERROR on closedUser " + PreferencesState.getInstance().isPushInProgress());
            closeUserLogout();
        }

        @Override
        public void onApiCallError() {
            onError("onApiCallError");
        }
    });
}
Also used : OrganisationUnitRepository(org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) PushController(org.eyeseetea.malariacare.data.sync.exporter.PushController) PushUseCase(org.eyeseetea.malariacare.domain.usecase.push.PushUseCase) ApiCallException(org.eyeseetea.malariacare.domain.exception.ApiCallException) SurveyLocalDataSource(org.eyeseetea.malariacare.data.database.datasources.SurveyLocalDataSource) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) IMainExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor) UIThreadExecutor(org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) ISurveyRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ISurveyRepository) SurveysThresholds(org.eyeseetea.malariacare.domain.usecase.push.SurveysThresholds) AsyncExecutor(org.eyeseetea.malariacare.presentation.executors.AsyncExecutor) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)

Aggregations

ApiCallException (org.eyeseetea.malariacare.domain.exception.ApiCallException)18 JSONException (org.json.JSONException)10 JSONObject (org.json.JSONObject)10 Response (com.squareup.okhttp.Response)8 NetworkException (org.eyeseetea.malariacare.domain.exception.NetworkException)4 IOException (java.io.IOException)3 Date (java.util.Date)3 OrganisationUnit (org.eyeseetea.malariacare.domain.entity.OrganisationUnit)3 ConfigJsonIOException (org.eyeseetea.malariacare.domain.exception.ConfigJsonIOException)3 JSONArray (org.json.JSONArray)3 OkHttpClient (com.squareup.okhttp.OkHttpClient)2 Request (com.squareup.okhttp.Request)2 RequestBody (com.squareup.okhttp.RequestBody)2 SurveyLocalDataSource (org.eyeseetea.malariacare.data.database.datasources.SurveyLocalDataSource)2 Program (org.eyeseetea.malariacare.data.database.model.Program)2 Survey (org.eyeseetea.malariacare.data.database.model.Survey)2 OrganisationUnitRepository (org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository)2 IAsyncExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)2 IMainExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor)2 IOrganisationUnitRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository)2