use of org.eyeseetea.malariacare.domain.entity.UserAccount 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);
}
});
}
}
Aggregations