@Test public void testForEach() { DslBuilderImpl.dslMethodName.set("test"); var user = new UserSessionImpl(new UserImpl("user", UUID.randomUUID().toString(), "", "")); var collectedNumbers = new ArrayList<Integer>(); var dslBuilder = forEach(ImmutableList.of(1, 2), i -> eval(s -> collectedNumbers.add(i))); dslBuilder.materializer().materialize(user).block(); assertEquals(2, collectedNumbers.size()); assertEquals(1, (int) collectedNumbers.get(0)); assertEquals(2, (int) collectedNumbers.get(1)); }
@Override public Mono<UserSession> materialize(final UserSession session) { final R iterable; try { iterable = Optional.ofNullable(dslItem.getIterableSupplier().apply(session)) .orElseThrow(() -> new IllegalArgumentException("forEach() failed.")); } catch (SessionObjectNotFoundException keyNotFound) { LOG.error(keyNotFound.getMessage()); return Mono.error(keyNotFound); } return Flux.fromIterable(iterable) .flatMap(s -> Flux.fromIterable(dslItem.getForEachFunctions()).map(a -> a.apply(s))) .map(childDsl -> populateToChildren(dslItem, childDsl)) .flatMap(childDsl -> childDsl.materializer().materialize(session)) .reduce((s1, s2) -> s1) .doOnError(e -> LOG.error("Unexpected error: ", e)); }
ForEachDslMaterializer implements DslMaterializer { @Override public Mono<UserSession> materialize(final UserSession session) { final R iterable; try { iterable = Optional.ofNullable(dslItem.getIterableSupplier().apply(session)) .orElseThrow(() -> new IllegalArgumentException("forEach() failed.")); } catch (SessionObjectNotFoundException keyNotFound) { LOG.error(keyNotFound.getMessage()); return Mono.error(keyNotFound); } return Flux.fromIterable(iterable) .flatMap(s -> Flux.fromIterable(dslItem.getForEachFunctions()).map(a -> a.apply(s))) .map(childDsl -> populateToChildren(dslItem, childDsl)) .flatMap(childDsl -> childDsl.materializer().materialize(session)) .reduce((s1, s2) -> s1) .doOnError(e -> LOG.error("Unexpected error: ", e)); } }
ForEachDslMaterializer implements DslMaterializer { @Override public Mono<UserSession> materialize(final UserSession session) { final R iterable; try { iterable = Optional.ofNullable(dslItem.getIterableSupplier().apply(session)) .orElseThrow(() -> new IllegalArgumentException("forEach() failed.")); } catch (SessionObjectNotFoundException keyNotFound) { LOG.error(keyNotFound.getMessage()); return Mono.error(keyNotFound); } return Flux.fromIterable(iterable) .flatMap(s -> Flux.fromIterable(dslItem.getForEachFunctions()).map(a -> a.apply(s))) .map(childDsl -> populateToChildren(dslItem, childDsl)) .flatMap(childDsl -> childDsl.materializer().materialize(session)) .reduce((s1, s2) -> s1) .doOnError(e -> LOG.error("Unexpected error: ", e)); } ForEachDslMaterializer(ForEachDsl<S, R> dslItem); }
ForEachDslMaterializer implements DslMaterializer { @Override public Mono<UserSession> materialize(final UserSession session) { final R iterable; try { iterable = Optional.ofNullable(dslItem.getIterableSupplier().apply(session)) .orElseThrow(() -> new IllegalArgumentException("forEach() failed.")); } catch (SessionObjectNotFoundException keyNotFound) { LOG.error(keyNotFound.getMessage()); return Mono.error(keyNotFound); } return Flux.fromIterable(iterable) .flatMap(s -> Flux.fromIterable(dslItem.getForEachFunctions()).map(a -> a.apply(s))) .map(childDsl -> populateToChildren(dslItem, childDsl)) .flatMap(childDsl -> childDsl.materializer().materialize(session)) .reduce((s1, s2) -> s1) .doOnError(e -> LOG.error("Unexpected error: ", e)); } ForEachDslMaterializer(ForEachDsl<S, R> dslItem); @Override Mono<UserSession> materialize(final UserSession session); }
ForEachDslMaterializer implements DslMaterializer { @Override public Mono<UserSession> materialize(final UserSession session) { final R iterable; try { iterable = Optional.ofNullable(dslItem.getIterableSupplier().apply(session)) .orElseThrow(() -> new IllegalArgumentException("forEach() failed.")); } catch (SessionObjectNotFoundException keyNotFound) { LOG.error(keyNotFound.getMessage()); return Mono.error(keyNotFound); } return Flux.fromIterable(iterable) .flatMap(s -> Flux.fromIterable(dslItem.getForEachFunctions()).map(a -> a.apply(s))) .map(childDsl -> populateToChildren(dslItem, childDsl)) .flatMap(childDsl -> childDsl.materializer().materialize(session)) .reduce((s1, s2) -> s1) .doOnError(e -> LOG.error("Unexpected error: ", e)); } ForEachDslMaterializer(ForEachDsl<S, R> dslItem); @Override Mono<UserSession> materialize(final UserSession session);  }