Search in sources :

Example 1 with IPushController

use of org.eyeseetea.malariacare.domain.boundary.IPushController 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();
        }
    });
}
Also used : OrganisationUnitRepository(org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) 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) IPushController(org.eyeseetea.malariacare.domain.boundary.IPushController) UIThreadExecutor(org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) WSPushController(org.eyeseetea.malariacare.data.sync.exporter.WSPushController) ISurveyRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ISurveyRepository) SurveysThresholds(org.eyeseetea.malariacare.domain.usecase.push.SurveysThresholds) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) AsyncExecutor(org.eyeseetea.malariacare.presentation.executors.AsyncExecutor)

Example 2 with IPushController

use of org.eyeseetea.malariacare.domain.boundary.IPushController in project pictureapp by EyeSeeTea.

the class APushUseCaseStrategy method run.

public void run(PushUseCase.Callback callback) {
    mCallback = callback;
    IPushController pushController = mPushController;
    if (pushController.isPushInProgress()) {
        notifyPushInProgressError();
        return;
    }
    pushController.changePushInProgress(true);
    try {
        configureBanOrgUnitChangeListener();
        boolean isBanned = isOrgUnitBanned();
        if (isBanned) {
            pushController.changePushInProgress(false);
        } else {
            runPush();
        }
    } catch (Exception e) {
        pushController.changePushInProgress(false);
        notifyPushError();
    }
}
Also used : IPushController(org.eyeseetea.malariacare.domain.boundary.IPushController) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) ApiCallException(org.eyeseetea.malariacare.domain.exception.ApiCallException) ClosedUserPushException(org.eyeseetea.malariacare.domain.exception.ClosedUserPushException) SurveysToPushNotFoundException(org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException) ConversionException(org.eyeseetea.malariacare.domain.exception.ConversionException)

Example 3 with IPushController

use of org.eyeseetea.malariacare.domain.boundary.IPushController in project pictureapp by EyeSeeTea.

the class PushUseCaseStrategy method run.

@Override
public void run(PushUseCase.Callback callback) {
    mCallback = callback;
    IPushController pushController = mPushController;
    if (pushController.isPushInProgress()) {
        notifyPushInProgressError();
    } else {
        pushController.changePushInProgress(true);
        runPush();
    }
}
Also used : IPushController(org.eyeseetea.malariacare.domain.boundary.IPushController)

Aggregations

IPushController (org.eyeseetea.malariacare.domain.boundary.IPushController)3 ApiCallException (org.eyeseetea.malariacare.domain.exception.ApiCallException)2 SurveyLocalDataSource (org.eyeseetea.malariacare.data.database.datasources.SurveyLocalDataSource)1 OrganisationUnitRepository (org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository)1 WSPushController (org.eyeseetea.malariacare.data.sync.exporter.WSPushController)1 IAsyncExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)1 IMainExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor)1 IOrganisationUnitRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository)1 ISurveyRepository (org.eyeseetea.malariacare.domain.boundary.repositories.ISurveyRepository)1 ClosedUserPushException (org.eyeseetea.malariacare.domain.exception.ClosedUserPushException)1 ConversionException (org.eyeseetea.malariacare.domain.exception.ConversionException)1 NetworkException (org.eyeseetea.malariacare.domain.exception.NetworkException)1 SurveysToPushNotFoundException (org.eyeseetea.malariacare.domain.exception.SurveysToPushNotFoundException)1 PushUseCase (org.eyeseetea.malariacare.domain.usecase.push.PushUseCase)1 SurveysThresholds (org.eyeseetea.malariacare.domain.usecase.push.SurveysThresholds)1 AsyncExecutor (org.eyeseetea.malariacare.presentation.executors.AsyncExecutor)1 UIThreadExecutor (org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor)1