use of org.eyeseetea.malariacare.domain.exception.NetworkException in project pictureapp by EyeSeeTea.
the class AuthenticationDhisSDKDataSource method login.
@Override
public void login(final Credentials credentials, final IDataSourceCallback<UserAccount> callback) {
boolean isNetworkAvailable = isNetworkAvailable();
if (!isNetworkAvailable) {
callback.onError(new NetworkException());
} else {
Configuration configuration = new Configuration(credentials.getServerURL());
D2.configure(configuration).flatMap(new Func1<Void, Observable<org.hisp.dhis.client.sdk.models.user.UserAccount>>() {
@Override
public Observable<org.hisp.dhis.client.sdk.models.user.UserAccount> call(Void aVoid) {
return D2.me().signIn(credentials.getUsername(), credentials.getPassword());
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<org.hisp.dhis.client.sdk.models.user.UserAccount>() {
@Override
public void call(org.hisp.dhis.client.sdk.models.user.UserAccount dhisUserAccount) {
UserAccount userAccount = new UserAccount(credentials.getUsername(), credentials.isDemoCredentials());
callback.onSuccess(userAccount);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Throwable throwableResult = mapThrowable(throwable);
callback.onError(throwableResult);
}
});
}
}
use of org.eyeseetea.malariacare.domain.exception.NetworkException in project pictureapp by EyeSeeTea.
the class PushController method push.
public void push(final IPushControllerCallback callback) {
if (!ServerAPIController.isNetworkAvailable()) {
Log.d(TAG, "No network");
callback.onError(new NetworkException());
} else {
Log.d(TAG, "Network connected");
List<Survey> surveys = Survey.getAllCompletedSurveysNoReceiptReset();
//Fixme Check if is necessary other conditions
if (surveys == null || surveys.size() == 0) {
Log.d("DpBlank", "Sets of Surveys to push");
callback.onError(new SurveysToPushNotFoundException());
} else {
for (Survey srv : surveys) {
Log.d("DpBlank", "Survey to push " + srv.toString());
for (Value dv : srv.getValuesFromDB()) {
Log.d("DpBlank", "Values to push " + dv.toString());
}
}
mPushDhisSDKDataSource.wipeEvents();
try {
convertToSDK(surveys);
} catch (Exception ex) {
callback.onError(new ConversionException(ex));
}
if (EventExtended.getAllEvents().size() == 0) {
callback.onError(new ConversionException());
} else {
pushData(callback);
}
}
}
}
use of org.eyeseetea.malariacare.domain.exception.NetworkException in project pictureapp by EyeSeeTea.
the class PullDhisSDKDataSource method pullData.
public void pullData(PullFilters pullFilters, List<OrganisationUnit> organisationUnits, IDataSourceCallback<List<Event>> callback) {
boolean isNetworkAvailable = isNetworkAvailable();
if (!isNetworkAvailable) {
callback.onError(new NetworkException());
} else {
try {
List<Event> events = new ArrayList<>();
for (OrganisationUnit organisationUnit : organisationUnits) {
Scheduler pullEventsThread = Schedulers.newThread();
EventFilters eventFilters = new EventFilters();
eventFilters.setStartDate(pullFilters.getStartDate());
eventFilters.setEndDate(pullFilters.getEndDate());
eventFilters.setMaxEvents(pullFilters.getMaxEvents());
eventFilters.setOrganisationUnitUId(organisationUnit.getUId());
mPullDhisSDKDataSourceStrategy.setEventFilters(eventFilters);
List<Event> eventsByOrgUnit = D2.events().pull(eventFilters).subscribeOn(pullEventsThread).observeOn(pullEventsThread).toBlocking().single();
events.addAll(eventsByOrgUnit);
}
callback.onSuccess(events);
} catch (Exception e) {
callback.onError(e);
}
}
}
Aggregations