Java Code Examples for io.reactivex.Maybe#just()

The following examples show how to use io.reactivex.Maybe#just() . 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: CertificateManagerImpl.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public Maybe<CertificateProvider> findByAlgorithm(String algorithm) {

    if(algorithm==null || algorithm.trim().isEmpty()) {
        return Maybe.empty();
    }

    Optional<CertificateProvider> certificate = this
            .providers()
            .stream()
            .filter(certificateProvider ->
                    certificateProvider!=null && certificateProvider.getProvider()!=null &&
                    algorithm.equals(certificateProvider.getProvider().signatureAlgorithm())
            )
            .findFirst();

    return certificate.isPresent()?Maybe.just(certificate.get()):Maybe.empty();
}
 
Example 2
Source File: JWKServiceImpl.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Override
public Maybe<JWK> getKey(JWKSet jwkSet, String kid) {

    if(jwkSet==null || jwkSet.getKeys().isEmpty() || kid==null || kid.trim().isEmpty()) {
        return Maybe.empty();
    }

    //Else return matching key
    Optional<JWK> jwk = jwkSet.getKeys().stream().filter(key -> kid.equals(key.getKid())).findFirst();
    if(jwk.isPresent()) {
        return Maybe.just(jwk.get());
    }

    //No matching key found in JWKs...
    return Maybe.empty();
}
 
Example 3
Source File: RxJavaTest.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
@Test
public void createMultiFromRx() {
    // tag::multi-create[]
    Completable completable = Completable.complete();
    Single<String> single = Single.just("hello");
    Maybe<String> maybe = Maybe.just("hello");
    Maybe<String> emptyMaybe = Maybe.empty();
    Observable<String> observable = Observable.fromArray("a", "b", "c");
    Flowable<String> flowable = Flowable.fromArray("a", "b", "c");

    Multi<Void> multiFromCompletable = Multi.createFrom()
            .converter(MultiRxConverters.fromCompletable(), completable);
    Multi<String> multiFromSingle = Multi.createFrom().converter(MultiRxConverters.fromSingle(), single);
    Multi<String> multiFromMaybe = Multi.createFrom().converter(MultiRxConverters.fromMaybe(), maybe);
    Multi<String> multiFromEmptyMaybe = Multi.createFrom().converter(MultiRxConverters.fromMaybe(), emptyMaybe);
    Multi<String> multiFromObservable = Multi.createFrom()
            .converter(MultiRxConverters.fromObservable(), observable);
    Multi<String> multiFromFlowable = Multi.createFrom().converter(MultiRxConverters.fromFlowable(), flowable);
    Multi<String> multiFromPublisher = Multi.createFrom().publisher(flowable);
    // end::multi-create[]

    assertThat(multiFromCompletable.collectItems().first().await().indefinitely()).isNull();
    assertThat(multiFromSingle.collectItems().first().await().indefinitely()).isEqualTo("hello");
    assertThat(multiFromMaybe.collectItems().first().await().indefinitely()).isEqualTo("hello");
    assertThat(multiFromEmptyMaybe.collectItems().first().await().indefinitely()).isNull();
    assertThat(multiFromObservable.collectItems().asList().await().indefinitely()).containsExactly("a", "b", "c");
    assertThat(multiFromFlowable.collectItems().asList().await().indefinitely()).containsExactly("a", "b", "c");
    assertThat(multiFromPublisher.collectItems().asList().await().indefinitely()).containsExactly("a", "b", "c");
}
 
Example 4
Source File: ClientSyncServiceImpl.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public Maybe<Client> findByDomainAndClientId(String domain, String clientId) {
    final Optional<Client> optClient = clientManager.entities()
            .stream()
            .filter(client -> !client.isTemplate() && client.getDomain().equals(domain) && client.getClientId().equals(clientId))
            .findFirst();
    return optClient.isPresent() ? Maybe.just(optClient.get()) : Maybe.empty();
}
 
Example 5
Source File: ClientAssertionServiceImpl.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
/**
 * This method will parse the JWT bearer then ensure that all requested claims are set as required
 * <a href="https://tools.ietf.org/html/rfc7523#section-3">here</a>
 * @param assertion jwt as string value.
 * @return
 */
private Maybe<JWT> validateJWT(String assertion, String basePath) {
    try {
        JWT jwt = JWTParser.parse(assertion);

        String iss = jwt.getJWTClaimsSet().getIssuer();
        String sub = jwt.getJWTClaimsSet().getSubject();
        List<String> aud = jwt.getJWTClaimsSet().getAudience();
        Date exp = jwt.getJWTClaimsSet().getExpirationTime();

        if  (iss == null || iss.isEmpty() || sub == null || sub.isEmpty() || aud == null || aud.isEmpty() || exp == null) {
            return Maybe.error(NOT_VALID);
        }

        if (exp.before(Date.from(Instant.now()))) {
            return Maybe.error(new InvalidClientException("assertion has expired"));
        }

        //Check audience, here we expect to have absolute token endpoint path.
        OpenIDProviderMetadata discovery = openIDDiscoveryService.getConfiguration(basePath);
        if (discovery == null || discovery.getTokenEndpoint() == null) {
            return Maybe.error(new ServerErrorException("Unable to retrieve discovery token endpoint."));
        }

        if (aud.stream().filter(discovery.getTokenEndpoint()::equals).count()==0) {
            return Maybe.error(NOT_VALID);
        }

        return Maybe.just(jwt);
    } catch (ParseException pe) {
        return Maybe.error(NOT_VALID);
    }
}
 
Example 6
Source File: InAppMessageStreamManager.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
private Maybe<ThickContent> getContentIfNotRateLimited(String event, ThickContent content) {
  if (!content.getIsTestCampaign() && isAppForegroundEvent(event)) {
    return rateLimiterClient
        .isRateLimited(appForegroundRateLimit)
        .doOnSuccess(
            isRateLimited -> Logging.logi("App foreground rate limited ? : " + isRateLimited))
        .onErrorResumeNext(Single.just(false)) // Absorb rate limit errors
        .filter(isRateLimited -> !isRateLimited)
        .map(isRateLimited -> content);
  }
  return Maybe.just(content);
}
 
Example 7
Source File: Maybes.java    From cyclops with Apache License 2.0 5 votes vote down vote up
public static <T, R> Maybe< R> tailRec(T initial, Function<? super T, ? extends Maybe<? extends Either<T, R>>> fn) {
    Maybe<? extends Either<T, R>> next[] = new Maybe[1];
    next[0] = Maybe.just(Either.left(initial));
    boolean cont = true;
    do {
        cont = next[0].map(p -> p.fold(s -> {
            next[0] = fn.apply(s);
            return true;
        }, pr -> false)).blockingGet(false);
    } while (cont);
    return next[0].map(e->e.orElse(null));
}
 
Example 8
Source File: IdentityProviderManagerImpl.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Override
public Maybe<UserProvider> getUserProvider(String userProvider) {
    if (userProvider == null) {
        return Maybe.empty();
    }
    UserProvider userProvider1 = userProviders.get(userProvider);
    return (userProvider1 != null) ? Maybe.just(userProvider1) : Maybe.empty();
}
 
Example 9
Source File: UserServiceImpl.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
private MaybeSource<Optional<Client>> clientSource(String audience) {
    if (audience == null) {
        return Maybe.just(Optional.empty());
    }

    return clientSyncService.findById(audience)
            .map(client -> Optional.of(client))
            .defaultIfEmpty(Optional.empty());
}
 
Example 10
Source File: AsyncResultTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testMaybe() {
  Promise<String> promise = Promise.promise();
  try {
    Maybe justMe = Maybe.just("me");
    RxJavaPlugins.setOnMaybeAssembly(single -> justMe);
    Maybe<String> maybe = AsyncResultMaybe.toMaybe(promise.future()::onComplete);
    assertSame(maybe, justMe);
  } finally {
    RxJavaPlugins.reset();
  }
}
 
Example 11
Source File: Maybes.java    From rxjava2-extras with Apache License 2.0 5 votes vote down vote up
public static <T> Maybe<T> fromNullable(T t) {
    if (t == null) {
        return Maybe.empty();
    } else {
        return Maybe.just(t);
    }
}
 
Example 12
Source File: IdentityProviderManagerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public Maybe<IdentityProvider> getIdentityProvider(String id) {
    IdentityProvider identityProvider = identities.get(id);
    return (identityProvider != null) ? Maybe.just(identityProvider) : Maybe.empty();
}
 
Example 13
Source File: IdentityProviderManagerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public Maybe<AuthenticationProvider> get(String id) {
    AuthenticationProvider authenticationProvider = providers.get(id);
    return (authenticationProvider != null) ? Maybe.just(authenticationProvider) : Maybe.empty();
}
 
Example 14
Source File: MaybeResourceTest.java    From rx-jersey with MIT License 4 votes vote down vote up
@GET
@Path("echo")
public Maybe<String> echo(@QueryParam("message") String message) {
    return Maybe.just(message);
}
 
Example 15
Source File: MissingBodyWriterTest.java    From rx-jersey with MIT License 4 votes vote down vote up
@GET
@Path("writeXml")
public Maybe<Message> writeXml() {
    return Maybe.just(new Message("hello"));
}
 
Example 16
Source File: RxWebsocket.java    From rxWebSocket with Apache License 2.0 4 votes vote down vote up
public Open(Response response) {
    this.response = Maybe.just(response);
}
 
Example 17
Source File: IdentityProviderManagerImpl.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Override
public Maybe<UserProvider> getUserProvider(String id) {
    UserProvider userProvider = userProviders.get(id);
    return (userProvider != null) ? Maybe.just(userProvider) : Maybe.empty();
}
 
Example 18
Source File: RateLimiterClient.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
private void initInMemCache(RateLimitProto.RateLimit rateLimits) {
  cachedRateLimts = Maybe.just(rateLimits);
}
 
Example 19
Source File: MockPolicyViewRepository.java    From micronaut-microservices-poc with Apache License 2.0 4 votes vote down vote up
@Override
public Maybe<List<PolicyView>> findAll(FindPolicyQuery query) {
    return Maybe.just(new ArrayList<>(policyMap.values()));
}
 
Example 20
Source File: ITWriteQueryReactiveApi.java    From influxdb-client-java with MIT License 3 votes vote down vote up
@Test
void writeRecord() {

    String bucketName = bucket.getName();

    writeClient = influxDBClient.getWriteReactiveApi();

    String lineProtocol = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1";
    Maybe<String> record = Maybe.just(lineProtocol);

    writeClient
            .listenEvents(WriteSuccessEvent.class)
            .subscribe(event -> {

                Assertions.assertThat(event).isNotNull();
                Assertions.assertThat(event.getBucket()).isEqualTo(bucket.getName());
                Assertions.assertThat(event.getOrganization()).isEqualTo(organization.getId());
                Assertions.assertThat(event.getLineProtocol()).isEqualTo(lineProtocol);

                countDownLatch.countDown();
            });

    writeClient.writeRecord(bucketName, organization.getId(), WritePrecision.NS, record);

    waitToCallback();

    Assertions.assertThat(countDownLatch.getCount()).isEqualTo(0);

    Flowable<FluxRecord> result = queryClient.query("from(bucket:\"" + bucketName + "\") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()", organization.getId());

    result.test().assertValueCount(1).assertValue(fluxRecord -> {

        Assertions.assertThat(fluxRecord.getMeasurement()).isEqualTo("h2o_feet");
        Assertions.assertThat(fluxRecord.getValue()).isEqualTo(1.0D);
        Assertions.assertThat(fluxRecord.getField()).isEqualTo("level water_level");
        Assertions.assertThat(fluxRecord.getTime()).isEqualTo(Instant.ofEpochSecond(0, 1));

        return true;
    });
}