Java Code Examples for io.reactivex.Completable#complete()

The following examples show how to use io.reactivex.Completable#complete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserAuthenticationManagerImpl.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
private Completable postAuthentication(Client client, Authentication authentication, String source, UserAuthentication userAuthentication) {
    final AccountSettings accountSettings = getAccountSettings(domain, client);
    if (accountSettings != null && accountSettings.isLoginAttemptsDetectionEnabled()) {
        LoginAttemptCriteria criteria = new LoginAttemptCriteria.Builder()
                .domain(domain.getId())
                .client(client.getId())
                .identityProvider(source)
                .username((String) authentication.getPrincipal())
                .build();
        // no exception clear login attempt
        if (userAuthentication.getLastException() == null) {
            return loginAttemptService.loginSucceeded(criteria);
        } else if (userAuthentication.getLastException() instanceof BadCredentialsException){
            return loginAttemptService.loginFailed(criteria, accountSettings);
        }
    }
    return Completable.complete();
}
 
Example 2
Source File: RxBleConnectionMock.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@NonNull
private Completable setupCharacteristicNotification(
        final UUID bluetoothGattCharacteristicUUID,
        final NotificationSetupMode setupMode,
        final boolean enabled,
        final boolean isIndication
) {
    if (setupMode == NotificationSetupMode.DEFAULT) {
        final byte[] enableValue = isIndication ? ENABLE_INDICATION_VALUE : ENABLE_NOTIFICATION_VALUE;
        return getClientConfigurationDescriptor(bluetoothGattCharacteristicUUID)
                .flatMapCompletable(new Function<BluetoothGattDescriptor, Completable>() {
                    @Override
                    public Completable apply(BluetoothGattDescriptor bluetoothGattDescriptor) {
                        return writeDescriptor(bluetoothGattDescriptor, enabled ? enableValue : DISABLE_NOTIFICATION_VALUE);
                    }
                });
    } else {
        return Completable.complete();
    }

}
 
Example 3
Source File: ReentrantTransaction.java    From xian with Apache License 2.0 6 votes vote down vote up
@Override
public Completable commit() {
    LOG.info("================commit" + count.get());
    Completable completable;
    count.decrementAndGet();
    if (count.intValue() == 0) {
        if (connection != null && !connection.isClosed()) {
            completable = doCommit();
            /*.andThen(clear())  let dao unit close this transaction*/
        } else {
            LOG.error("database connection is already closed while you are commit a transaction.");
            /*.andThen(clear())  let dao unit close this transaction*/
            completable = Completable.complete();
        }
    } else {
        LOG.debug(String.format("嵌套的数据库事务不需要提交,嵌套了%s层", count));
        completable = Completable.complete();
    }
    return completable;
}
 
Example 4
Source File: ReentrantTransaction.java    From xian with Apache License 2.0 6 votes vote down vote up
@Override
public Completable close() {
    LOG.info("===============close" + count.get());
    Completable completable;
    if (count.intValue() == 0 || isRollbacked()) {
        if (connection != null && !connection.isClosed()) {
            completable = doClose();
        } else {
            LOG.warn("Connection is already closed or no connection for you to close");
            completable = Completable.complete();
        }
        //close and clear transaction
        completable.concatWith(clear());
    } else {
        LOG.warn(new RuntimeException("外层事务还存在,现在还不是关闭数据库连接的时候...,如果想强制关闭数据库连接,请先回滚/提交事务..."));
        completable = Completable.complete();
    }
    return completable;
}
 
Example 5
Source File: MovieCollection.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Completable load() {
    if (isLoading && loadCompletable != null) {
        return loadCompletable;
    }

    if (isLoaded()) {
        return Completable.complete();
    }

    isLoading = true;
    loadCompletable = getFirstPage()
            .doFinally(() -> isLoading = false)
            .map(resultHandler)
            .toCompletable();
    return loadCompletable;
}
 
Example 6
Source File: DeviceLocationDataStore.java    From Track-My-Location with GNU General Public License v3.0 6 votes vote down vote up
public Completable stopShareMyLocation() {
    if (mShareLocDisposable != null && !mShareLocDisposable.isDisposed()) {
        mShareLocDisposable.dispose();
        mShareLocDisposable = null;

        if (mShareLocDocRef != null) {
            return Completable.create(emitter -> {
                mShareLocDocRef.delete()
                        .addOnSuccessListener(aVoid -> emitter.onComplete())
                        .addOnFailureListener(emitter::onError);
                mShareLocDocRef = null;
            });
        }
    }

    return Completable.complete();
}
 
Example 7
Source File: ShoppingCart.java    From mosby with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a product to the shopping cart
 */
public Completable addProduct(Product product) {
  List<Product> updatedShoppingCart = new ArrayList<>();
  updatedShoppingCart.addAll(itemsInShoppingCart.getValue());
  updatedShoppingCart.add(product);
  itemsInShoppingCart.onNext(updatedShoppingCart);
  return Completable.complete();
}
 
Example 8
Source File: FCMNotificationServiceFacade.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Completable unsubscribe() {
    String unsubscribeTransactionJson = settings.getUnsubscribeFcmTransaction();
    if (unsubscribeTransactionJson == null || unsubscribeTransactionJson.isEmpty()) {
        //TODO: Обязательно проверь в тестах кейс с выходом
        return Completable.complete();
    }

    try {

        Transaction<TransactionChatAsset> transaction = gson.fromJson(
                unsubscribeTransactionJson,
                new TypeToken<Transaction<TransactionChatAsset>>() {}.getType()
        );

        AdamantPushSubscriptionMessageFactory subscribeFactory = (AdamantPushSubscriptionMessageFactory)messageFactoryProvider
                .getFactoryByType(SupportedMessageListContentType.ADAMANT_SUBSCRIBE_ON_NOTIFICATION);
        MessageProcessor<AdamantPushSubscriptionMessage> messageProcessor = subscribeFactory.getMessageProcessor();

        return messageProcessor
                .sendTransaction(Single.just(transaction))
                .ignoreElement()
                .doOnComplete(() -> {
                    settings.setNotificationToken("");
                    settings.setUnsubscribeFcmTransaction("");
                });
    } catch (Exception ex) {
        return Completable.error(ex);
    }

}
 
Example 9
Source File: UserValidator.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
public static Completable validate(User user) {

        if (!isValid(user.getUsername(), USERNAME_PATTERN_COMPILED)) {
            return Completable.error(new InvalidUserException(String.format("Username [%s] is not a valid value", user.getUsername())));
        }

        if (!EmailValidator.isValid(user.getEmail())) {
            return Completable.error(new EmailFormatInvalidException(user.getEmail()));
        }

        if (!isValid(user.getFirstName(), NAME_STRICT_PATTERN_COMPILED)) {
            return Completable.error(new InvalidUserException(String.format("First name [%s] is not a valid value", user.getFirstName())));
        }

        if (!isValid(user.getLastName(), NAME_STRICT_PATTERN_COMPILED)) {
            return Completable.error(new InvalidUserException(String.format("Last name [%s] is not a valid value", user.getLastName())));
        }

        if (!isValid(user.getDisplayName(), NAME_LAX_PATTERN_COMPILED)) {
            return Completable.error(new InvalidUserException(String.format("Display name [%s] is not a valid value", user.getDisplayName())));
        }

        if (!isValid(user.getNickName(), NAME_LAX_PATTERN_COMPILED)) {
            return Completable.error(new InvalidUserException(String.format("Nick name [%s] is not a valid value", user.getNickName())));
        }

        if (user.getExternalId() != null && user.getExternalId().length() > DEFAULT_MAX_LENGTH) {
            return Completable.error(new InvalidUserException(String.format("External id [%s] is not a valid value", user.getExternalId())));
        }

        return Completable.complete();
    }
 
Example 10
Source File: PahoObservableMqttClientTest.java    From rxmqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void whenDisconnectIsCalledThenCreateIsCalled() {
    final Builder builder = this.builderWithMocks("clientId");
    final DisconnectFactory factory = builder.getDisconnectFactory();
    final Completable expected = Completable.complete();
    Mockito.when(factory.create()).thenReturn(expected);
    final PahoObservableMqttClient target = builder.build();
    final Completable actual = target.disconnect();
    Mockito.verify(factory).create();
    Assert.assertEquals(expected, actual);
}
 
Example 11
Source File: PahoObservableMqttClientTest.java    From rxmqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void whenConnectIsCalledThenCreateIsCalled() {
    final Builder builder = this.builderWithMocks("clientId");
    final ConnectFactory factory = builder.getConnectFactory();
    final Completable expected = Completable.complete();
    Mockito.when(factory.create()).thenReturn(expected);
    final PahoObservableMqttClient target = builder.build();
    final Completable actual = target.connect();
    Mockito.verify(factory).create();
    Assert.assertEquals(expected, actual);
}
 
Example 12
Source File: TestResource.java    From redpipe with Apache License 2.0 4 votes vote down vote up
@GET
@Path("completable")
public Completable returnCompletable() {
    return Completable.complete(); // should be 204
}
 
Example 13
Source File: MockLocalDbRepository.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Completable updateDataSetSubmissionState(String dataSet, String orgUnit, String period, String attributeOptionComboUid, State state) {
    return Completable.complete();
}
 
Example 14
Source File: RelationshipConverter.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Completable updateSubmissionState(State state) {
    // there is no submission state update for RelationShip
    return Completable.complete();
}
 
Example 15
Source File: InterceptorsTest.java    From rx-jersey with MIT License 4 votes vote down vote up
@Override
public Completable intercept(ContainerRequestContext requestContext) {
    return Completable.complete();
}
 
Example 16
Source File: FavoriteMovieCollection.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Completable loadNextPage() {
    return Completable.complete();
}
 
Example 17
Source File: HeaderInterceptor.java    From rx-jersey with MIT License 4 votes vote down vote up
public Completable intercept(ContainerRequestContext requestContext) {
    return Completable.complete();
}
 
Example 18
Source File: RxProcess.java    From RxShell with Apache License 2.0 4 votes vote down vote up
public synchronized Completable close() {
    if (RXSDebug.isDebug()) Timber.tag(TAG).v("close()");
    if (session == null) return Completable.complete();
    else return session.flatMapCompletable(s -> s.destroy().andThen(s.waitFor().ignoreElement()));
}
 
Example 19
Source File: Plugin.java    From redpipe with Apache License 2.0 votes vote down vote up
public Completable postRoute() { return Completable.complete(); } 
Example 20
Source File: Plugin.java    From redpipe with Apache License 2.0 votes vote down vote up
public Completable preRoute() { return Completable.complete(); }