Search in sources :

Example 1 with ICredentialsRepository

use of org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository 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 2 with ICredentialsRepository

use of org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository 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)

Example 3 with ICredentialsRepository

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

the class PullControllerStrategy method onPullDataComplete.

@Override
public void onPullDataComplete(final IPullController.Callback callback) {
    ICredentialsRepository credentialsLocalDataSource = new CredentialsLocalDataSource();
    IOrganisationUnitRepository orgUnitDataSource = new OrganisationUnitRepository();
    IProgramRepository programLocalDataSource = new ProgramLocalDataSource();
    try {
        org.eyeseetea.malariacare.domain.entity.OrganisationUnit orgUnit = orgUnitDataSource.getUserOrgUnit(credentialsLocalDataSource.getOrganisationCredentials());
        org.eyeseetea.malariacare.domain.entity.Program program = orgUnit.getProgram();
        programLocalDataSource.saveUserProgramId(program);
    } catch (Exception e) {
        e.printStackTrace();
        callback.onError(e);
    }
    mPullController.convertData(callback);
}
Also used : OrganisationUnitRepository(org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) IProgramRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IProgramRepository) ProgramLocalDataSource(org.eyeseetea.malariacare.data.database.datasources.ProgramLocalDataSource) IOrganisationUnitRepository(org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository) CredentialsLocalDataSource(org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource) ICredentialsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)

Example 4 with ICredentialsRepository

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

the class LoginActivityStrategy method checkCredentials.

@Override
public void checkCredentials(Credentials credentials, final Callback callback) {
    ICredentialsRepository credentialsLocalDataSource = new CredentialsLocalDataSource();
    Credentials savedCredentials = credentialsLocalDataSource.getOrganisationCredentials();
    if (savedCredentials == null || savedCredentials.isEmpty() || savedCredentials.getUsername().equals(credentials.getUsername()) && (!savedCredentials.getPassword().equals(credentials.getPassword()) || !savedCredentials.getServerURL().equals(credentials.getServerURL()))) {
        callback.onSuccessDoLogin();
    } else if (savedCredentials.getUsername().equals(credentials.getUsername()) && savedCredentials.getPassword().equals(credentials.getPassword()) && savedCredentials.getServerURL().equals(credentials.getServerURL())) {
        callback.onSuccess();
    } else {
        IAuthenticationManager iAuthenticationManager = new AuthenticationManager(loginActivity);
        LogoutUseCase logoutUseCase = new LogoutUseCase(iAuthenticationManager);
        AlarmPushReceiver.cancelPushAlarm(loginActivity);
        logoutUseCase.execute(new LogoutUseCase.Callback() {

            @Override
            public void onLogoutSuccess() {
                callback.onSuccessDoLogin();
            }

            @Override
            public void onLogoutError(String message) {
                callback.onError();
            }
        });
    }
}
Also used : IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) AuthenticationManager(org.eyeseetea.malariacare.data.authentication.AuthenticationManager) IAuthenticationManager(org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager) LogoutUseCase(org.eyeseetea.malariacare.domain.usecase.LogoutUseCase) CredentialsLocalDataSource(org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource) Credentials(org.eyeseetea.malariacare.domain.entity.Credentials) ICredentialsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)

Example 5 with ICredentialsRepository

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

the class DashboardActivityStrategy method onCreate.

@Override
public void onCreate() {
    ICredentialsRepository iCredentialsRepository = new CredentialsLocalDataSource();
    mGetUrlForWebViewsUseCase = new GetUrlForWebViewsUseCase(mDashboardActivity, iCredentialsRepository);
}
Also used : GetUrlForWebViewsUseCase(org.eyeseetea.malariacare.domain.usecase.GetUrlForWebViewsUseCase) CredentialsLocalDataSource(org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource) ICredentialsRepository(org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)

Aggregations

CredentialsLocalDataSource (org.eyeseetea.malariacare.data.database.CredentialsLocalDataSource)5 ICredentialsRepository (org.eyeseetea.malariacare.domain.boundary.repositories.ICredentialsRepository)5 OrganisationUnitRepository (org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository)3 IOrganisationUnitRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IOrganisationUnitRepository)3 AuthenticationManager (org.eyeseetea.malariacare.data.authentication.AuthenticationManager)2 InvalidLoginAttemptsRepositoryLocalDataSource (org.eyeseetea.malariacare.data.database.InvalidLoginAttemptsRepositoryLocalDataSource)2 IAuthenticationManager (org.eyeseetea.malariacare.domain.boundary.IAuthenticationManager)2 IAsyncExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IAsyncExecutor)2 IMainExecutor (org.eyeseetea.malariacare.domain.boundary.executors.IMainExecutor)2 IInvalidLoginAttemptsRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IInvalidLoginAttemptsRepository)2 Credentials (org.eyeseetea.malariacare.domain.entity.Credentials)2 LoginUseCase (org.eyeseetea.malariacare.domain.usecase.LoginUseCase)2 AsyncExecutor (org.eyeseetea.malariacare.presentation.executors.AsyncExecutor)2 UIThreadExecutor (org.eyeseetea.malariacare.presentation.executors.UIThreadExecutor)2 ProgramLocalDataSource (org.eyeseetea.malariacare.data.database.datasources.ProgramLocalDataSource)1 IProgramRepository (org.eyeseetea.malariacare.domain.boundary.repositories.IProgramRepository)1 ALoginUseCase (org.eyeseetea.malariacare.domain.usecase.ALoginUseCase)1 GetUrlForWebViewsUseCase (org.eyeseetea.malariacare.domain.usecase.GetUrlForWebViewsUseCase)1 LogoutUseCase (org.eyeseetea.malariacare.domain.usecase.LogoutUseCase)1