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() {
}
});
}
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);
}
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);
}
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();
}
});
}
}
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);
}
Aggregations