Search in sources :

Example 1 with IAsyncExecutor

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

the class ProgressActivity method initializeDependencies.

private void initializeDependencies() {
    AuthenticationManager authenticationManager = new AuthenticationManager(this);
    IPullController pullController = new PullController(this);
    IAsyncExecutor asyncExecutor = new AsyncExecutor();
    IMainExecutor mainExecutor = new UIThreadExecutor();
    mLogoutUseCase = new LogoutUseCase(authenticationManager);
    mPullUseCase = new PullUseCase(pullController, asyncExecutor, mainExecutor);
}
Also used : AuthenticationManager(org.eyeseetea.malariacare.data.authentication.AuthenticationManager) IPullController(org.eyeseetea.malariacare.domain.boundary.IPullController) PullUseCase(org.eyeseetea.malariacare.domain.usecase.pull.PullUseCase) UIThreadExecutor(org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) LogoutUseCase(org.eyeseetea.malariacare.domain.usecase.LogoutUseCase) PullController(org.eyeseetea.malariacare.data.sync.importer.PullController) IPullController(org.eyeseetea.malariacare.domain.boundary.IPullController) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) AsyncExecutor(org.eyeseetea.malariacare.presentation.executors.AsyncExecutor) IMainExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor)

Example 2 with IAsyncExecutor

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

the class SplashScreenActivity method init.

private void init() {
    LocationMemory.getInstance().init(getApplicationContext());
    D2.init(this);
    SdkQueries.createDBIndexes();
    // Added to execute a query in DB, because DBFLow doesn't do any migration until a query
    // is executed
    PopulateDB.initDBQuery();
    try {
        PostMigration.launchPostMigration();
    } catch (PostMigrationException e) {
        new AlertDialog.Builder(this).setTitle(getApplicationContext().getString(R.string.error_message)).setCancelable(false).setMessage(getApplicationContext().getString(R.string.db_migration_error)).setNeutralButton(android.R.string.ok, null).create().show();
    }
    if (!BuildConfig.multiuser) {
        Log.i(TAG, "Pull on SplashScreen ...");
        PullController pullController = new PullController(getApplication().getApplicationContext());
        IAsyncExecutor asyncExecutor = new AsyncExecutor();
        IMainExecutor mainExecutor = new UIThreadExecutor();
        PullUseCase pullUseCase = new PullUseCase(pullController, asyncExecutor, mainExecutor);
        PullFilters pullFilters = new PullFilters();
        pullFilters.setDemo(true);
        pullUseCase.execute(pullFilters, new PullUseCase.Callback() {

            @Override
            public void onComplete() {
                Log.d(this.getClass().getSimpleName(), "pull complete");
                try {
                    NavigationBuilder.getInstance().buildController(Tab.getFirstTab());
                } catch (LoadingNavigationControllerException ex) {
                    onError(ex.getMessage());
                }
            }

            @Override
            public void onStep(PullStep step) {
                Log.d(this.getClass().getSimpleName(), step.toString());
            }

            @Override
            public void onError(String message) {
                Log.e(this.getClass().getSimpleName(), message);
            }

            @Override
            public void onNetworkError() {
                Log.e(this.getClass().getSimpleName(), "Network Error");
            }

            @Override
            public void onPullConversionError() {
                Log.e(this.getClass().getSimpleName(), "Pull Conversion Error");
            }

            @Override
            public void onCancel() {
                Log.e(this.getClass().getSimpleName(), "Pull oncancel");
            }
        });
    }
}
Also used : AlertDialog(android.app.AlertDialog) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) PullStep(org.eyeseetea.malariacare.domain.usecase.pull.PullStep) PullController(org.eyeseetea.malariacare.data.sync.importer.PullController) IMainExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor) LoadingNavigationControllerException(org.eyeseetea.malariacare.domain.exception.LoadingNavigationControllerException) PullUseCase(org.eyeseetea.malariacare.domain.usecase.pull.PullUseCase) PostMigrationException(org.eyeseetea.malariacare.domain.exception.PostMigrationException) UIThreadExecutor(org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor) PullFilters(org.eyeseetea.malariacare.domain.usecase.pull.PullFilters) AsyncExecutor(org.eyeseetea.malariacare.presentation.executors.AsyncExecutor) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)

Example 3 with IAsyncExecutor

use of org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor 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 4 with IAsyncExecutor

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

the class PushServiceStrategy method push.

@Override
public void push() {
    IAuthenticationManager authenticationManager = new AuthenticationManager(PreferencesState.getInstance().getContext());
    IMainExecutor mainExecutor = new UIThreadExecutor();
    IAsyncExecutor asyncExecutor = new AsyncExecutor();
    ICredentialsRepository credentialsLocalDataSoruce = new CredentialsLocalDataSource();
    IOrganisationUnitRepository organisationDataSource = new OrganisationUnitRepository();
    IInvalidLoginAttemptsRepository iInvalidLoginAttemptsRepository = new InvalidLoginAttemptsRepositoryLocalDataSource();
    LoginUseCase loginUseCase = new LoginUseCase(authenticationManager, mainExecutor, asyncExecutor, organisationDataSource, credentialsLocalDataSoruce, iInvalidLoginAttemptsRepository);
    final Credentials oldCredentials = credentialsLocalDataSoruce.getOrganisationCredentials();
    loginUseCase.execute(oldCredentials, new ALoginUseCase.Callback() {

        @Override
        public void onLoginSuccess() {
            PushServiceStrategy.this.onCorrectCredentials();
        }

        @Override
        public void onServerURLNotValid() {
            Log.e(TAG, "Error getting user credentials: URL not valid ");
        }

        @Override
        public void onInvalidCredentials() {
            logout();
        }

        @Override
        public void onNetworkError() {
            Log.e(TAG, "Error getting user credentials: NetworkError");
        }

        @Override
        public void onConfigJsonInvalid() {
            Log.e(TAG, "Error getting user credentials: JsonInvalid");
        }

        @Override
        public void onUnexpectedError() {
            Log.e(TAG, "Error getting user credentials: unexpectedError ");
        }

        @Override
        public void onMaxLoginAttemptsReachedError() {
        }
    });
}
Also used : OrganisationUnitRepository(org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) ALoginUseCase(org.eyeseetea.malariacare.domain.usecase.ALoginUseCase) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) LoginUseCase(org.eyeseetea.malariacare.domain.usecase.LoginUseCase) ALoginUseCase(org.eyeseetea.malariacare.domain.usecase.ALoginUseCase) CredentialsLocalDataSource(org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource) IMainExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor) ICredentialsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository) IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) AuthenticationManager(org.eyeseetea.malariacare.data.authentication.AuthenticationManager) UIThreadExecutor(org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) InvalidLoginAttemptsRepositoryLocalDataSource(org.eyeseetea.malariacare.data.database.InvalidLoginAttemptsRepositoryLocalDataSource) IInvalidLoginAttemptsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IInvalidLoginAttemptsRepository) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) AsyncExecutor(org.eyeseetea.malariacare.presentation.executors.AsyncExecutor)

Example 5 with IAsyncExecutor

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

the class LoginActivityStrategy method initLoginUseCase.

public void initLoginUseCase(IAuthenticationManager authenticationManager) {
    IMainExecutor mainExecutor = new UIThreadExecutor();
    IAsyncExecutor asyncExecutor = new AsyncExecutor();
    ICredentialsRepository credentialsLocalDataSoruce = new CredentialsLocalDataSource();
    IOrganisationUnitRepository organisationDataSource = new OrganisationUnitRepository();
    IInvalidLoginAttemptsRepository iInvalidLoginAttemptsRepository = new InvalidLoginAttemptsRepositoryLocalDataSource();
    loginActivity.mLoginUseCase = new LoginUseCase(authenticationManager, mainExecutor, asyncExecutor, organisationDataSource, credentialsLocalDataSoruce, iInvalidLoginAttemptsRepository);
}
Also used : OrganisationUnitRepository(org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) UIThreadExecutor(org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) InvalidLoginAttemptsRepositoryLocalDataSource(org.eyeseetea.malariacare.data.database.InvalidLoginAttemptsRepositoryLocalDataSource) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) LoginUseCase(org.eyeseetea.malariacare.domain.usecase.LoginUseCase) CredentialsLocalDataSource(org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource) IInvalidLoginAttemptsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IInvalidLoginAttemptsRepository) IMainExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor) IAsyncExecutor(org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor) AsyncExecutor(org.eyeseetea.malariacare.presentation.executors.AsyncExecutor) ICredentialsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)

Aggregations

IAsyncExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)9 IMainExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor)9 AsyncExecutor (org.eyeseetea.malariacare.presentation.executors.AsyncExecutor)9 UIThreadExecutor (org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor)9 OrganisationUnitRepository (org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository)4 IOrganisationUnitRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository)4 InvalidLoginAttemptsRepositoryLocalDataSource (org.eyeseetea.malariacare.data.database.InvalidLoginAttemptsRepositoryLocalDataSource)3 PullController (org.eyeseetea.malariacare.data.sync.importer.PullController)3 IInvalidLoginAttemptsRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IInvalidLoginAttemptsRepository)3 PullUseCase (org.eyeseetea.malariacare.domain.usecase.pull.PullUseCase)3 AuthenticationManager (org.eyeseetea.malariacare.data.authentication.AuthenticationManager)2 CredentialsLocalDataSource (org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource)2 SurveyLocalDataSource (org.eyeseetea.malariacare.data.database.datasources.SurveyLocalDataSource)2 ICredentialsRepository (org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)2 ISurveyRepository (org.eyeseetea.malariacare.domain.boundary.repositories.ISurveyRepository)2 ApiCallException (org.eyeseetea.malariacare.domain.exception.ApiCallException)2 LoginUseCase (org.eyeseetea.malariacare.domain.usecase.LoginUseCase)2 PullFilters (org.eyeseetea.malariacare.domain.usecase.pull.PullFilters)2 PullStep (org.eyeseetea.malariacare.domain.usecase.pull.PullStep)2 PushUseCase (org.eyeseetea.malariacare.domain.usecase.push.PushUseCase)2