Search in sources :

Example 1 with CompletableObserver

use of io.reactivex.CompletableObserver in project talk-android by nextcloud.

the class AccountRemovalJob method onRunJob.

@NonNull
@Override
protected Result onRunJob(Params params) {
    NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
    PushConfigurationState pushConfigurationState;
    for (Object userEntityObject : userUtils.getUsersScheduledForDeletion()) {
        UserEntity userEntity = (UserEntity) userEntityObject;
        try {
            if (!TextUtils.isEmpty(userEntity.getPushConfigurationState())) {
                pushConfigurationState = LoganSquare.parse(userEntity.getPushConfigurationState(), PushConfigurationState.class);
                PushConfigurationState finalPushConfigurationState = pushConfigurationState;
                ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
                ncApi.unregisterDeviceForNotificationsWithNextcloud(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlNextcloudPush(userEntity.getBaseUrl())).subscribe(new Observer<GenericOverall>() {

                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onNext(GenericOverall genericOverall) {
                        if (genericOverall.getOcs().getMeta().getStatusCode() == 200 || genericOverall.getOcs().getMeta().getStatusCode() == 202) {
                            HashMap<String, String> queryMap = new HashMap<>();
                            queryMap.put("deviceIdentifier", finalPushConfigurationState.deviceIdentifier);
                            queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey());
                            queryMap.put("deviceIdentifierSignature", finalPushConfigurationState.getDeviceIdentifierSignature());
                            ncApi.unregisterDeviceForNotificationsWithProxy(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlPushProxy(), queryMap).subscribe(new Observer<Void>() {

                                @Override
                                public void onSubscribe(Disposable d) {
                                }

                                @Override
                                public void onNext(Void aVoid) {
                                    userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {

                                        @Override
                                        public void onSubscribe(Disposable d) {
                                        }

                                        @Override
                                        public void onComplete() {
                                        }

                                        @Override
                                        public void onError(Throwable e) {
                                        }
                                    });
                                }

                                @Override
                                public void onError(Throwable e) {
                                }

                                @Override
                                public void onComplete() {
                                }
                            });
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                    }

                    @Override
                    public void onComplete() {
                    }
                });
            } else {
                userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {

                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onComplete() {
                    }

                    @Override
                    public void onError(Throwable e) {
                    }
                });
            }
        } catch (IOException e) {
            Log.d(TAG, "Something went wrong while removing job at parsing PushConfigurationState");
            userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {

                @Override
                public void onSubscribe(Disposable d) {
                }

                @Override
                public void onComplete() {
                }

                @Override
                public void onError(Throwable e) {
                }
            });
        }
    }
    return Result.SUCCESS;
}
Also used : JavaNetCookieJar(okhttp3.JavaNetCookieJar) Disposable(io.reactivex.disposables.Disposable) HashMap(java.util.HashMap) IOException(java.io.IOException) UserEntity(com.nextcloud.talk.models.database.UserEntity) PushConfigurationState(com.nextcloud.talk.models.json.push.PushConfigurationState) CompletableObserver(io.reactivex.CompletableObserver) Observer(io.reactivex.Observer) CompletableObserver(io.reactivex.CompletableObserver) NcApi(com.nextcloud.talk.api.NcApi) GenericOverall(com.nextcloud.talk.models.json.generic.GenericOverall) CookieManager(java.net.CookieManager) NonNull(android.support.annotation.NonNull)

Example 2 with CompletableObserver

use of io.reactivex.CompletableObserver in project resilience4j by resilience4j.

the class BulkheadCompletableObserverTest method shouldNotReleaseBulkheadWhenWasDisposedAfterNotPermittedSubscribe.

@Test
public void shouldNotReleaseBulkheadWhenWasDisposedAfterNotPermittedSubscribe() throws Exception {
    // Given
    Disposable disposable = mock(Disposable.class);
    CompletableObserver childObserver = mock(CompletableObserver.class);
    CompletableObserver decoratedObserver = BulkheadOperator.of(bulkhead).apply(childObserver);
    bulkhead.isCallPermitted();
    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
    decoratedObserver.onSubscribe(disposable);
    // When
    ((Disposable) decoratedObserver).dispose();
    // Then
    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
}
Also used : Disposable(io.reactivex.disposables.Disposable) CompletableObserver(io.reactivex.CompletableObserver) Test(org.junit.Test)

Example 3 with CompletableObserver

use of io.reactivex.CompletableObserver in project resilience4j by resilience4j.

the class BulkheadCompletableObserverTest method shouldHonorDisposedWhenCallingOnComplete.

@Test
public void shouldHonorDisposedWhenCallingOnComplete() throws Exception {
    // Given
    Disposable disposable = mock(Disposable.class);
    CompletableObserver childObserver = mock(CompletableObserver.class);
    CompletableObserver decoratedObserver = BulkheadOperator.of(bulkhead).apply(childObserver);
    decoratedObserver.onSubscribe(disposable);
    // When
    ((Disposable) decoratedObserver).dispose();
    decoratedObserver.onComplete();
    // Then
    verify(childObserver, never()).onComplete();
    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}
Also used : Disposable(io.reactivex.disposables.Disposable) CompletableObserver(io.reactivex.CompletableObserver) Test(org.junit.Test)

Example 4 with CompletableObserver

use of io.reactivex.CompletableObserver in project resilience4j by resilience4j.

the class CircuitBreakerCompletableObserverTest method shouldNotAffectCircuitBreakerWhenWasDisposedAfterNotPermittedSubscribe.

@Test
public void shouldNotAffectCircuitBreakerWhenWasDisposedAfterNotPermittedSubscribe() throws Exception {
    // Given
    Disposable disposable = mock(Disposable.class);
    CompletableObserver childObserver = mock(CompletableObserver.class);
    CompletableObserver decoratedObserver = CircuitBreakerOperator.of(circuitBreaker).apply(childObserver);
    circuitBreaker.transitionToOpenState();
    decoratedObserver.onSubscribe(disposable);
    // When
    ((Disposable) decoratedObserver).dispose();
    // Then
    assertNoRegisteredCall();
}
Also used : Disposable(io.reactivex.disposables.Disposable) CompletableObserver(io.reactivex.CompletableObserver) Test(org.junit.Test)

Example 5 with CompletableObserver

use of io.reactivex.CompletableObserver in project talk-android by nextcloud.

the class AccountVerificationController method abortVerification.

private void abortVerification() {
    dispose(null);
    if (!isAccountImport) {
        userUtils.deleteUser(username, baseUrl).subscribe(new CompletableObserver() {

            @Override
            public void onSubscribe(Disposable d) {
            }

            @Override
            public void onComplete() {
                new Handler().postDelayed(() -> getRouter().popToRoot(), 7500);
            }

            @Override
            public void onError(Throwable e) {
            }
        });
    } else {
        ApplicationWideMessageHolder.getInstance().setMessageType(ApplicationWideMessageHolder.MessageType.FAILED_TO_IMPORT_ACCOUNT);
        new Handler().postDelayed(() -> {
            if (getRouter().hasRootController()) {
                getRouter().popToRoot();
            } else {
                if (userUtils.anyUserExists()) {
                    getRouter().setRoot(RouterTransaction.with(new MagicBottomNavigationController()).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new HorizontalChangeHandler()));
                } else {
                    getRouter().setRoot(RouterTransaction.with(new ServerSelectionController()).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new HorizontalChangeHandler()));
                }
            }
        }, 7500);
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) Handler(android.os.Handler) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) CompletableObserver(io.reactivex.CompletableObserver) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)

Aggregations

CompletableObserver (io.reactivex.CompletableObserver)10 Disposable (io.reactivex.disposables.Disposable)10 Test (org.junit.Test)8 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 HorizontalChangeHandler (com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)1 NcApi (com.nextcloud.talk.api.NcApi)1 UserEntity (com.nextcloud.talk.models.database.UserEntity)1 GenericOverall (com.nextcloud.talk.models.json.generic.GenericOverall)1 PushConfigurationState (com.nextcloud.talk.models.json.push.PushConfigurationState)1 Observer (io.reactivex.Observer)1 IOException (java.io.IOException)1 CookieManager (java.net.CookieManager)1 HashMap (java.util.HashMap)1 JavaNetCookieJar (okhttp3.JavaNetCookieJar)1