use of org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository 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();
}
});
}
use of org.eyeseetea.malariacare.data.repositories.OrganisationUnitRepository 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.data.repositories.OrganisationUnitRepository 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.data.repositories.OrganisationUnitRepository 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.data.repositories.OrganisationUnitRepository 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");
}
});
}
Aggregations