I am trying to call multiple services (using Java Reactor) and the output of one service would determine whether the next service should be called or not.
The line
.filter(details -> details != null && StringUtils.isNotBlank(details.getFName))
gives error since "details" is being interpreted as a Mono.
If I change the code to use flatMap instead of Map, it works fine but I want a synchronous response as I need to wait for everything to complete before I can generate credentials.
.map(session -> dao.getDetails(session.getLogin()))
.filter(details -> details != null && StringUtils.isNotBlank(details.getFName))
Below is the code having issue.
Mono<Credentials> response = dao.validateSession(sessionId)
.filter(session -> session != null && StringUtils.isNotBlank(session.getLogin()))
.map(session -> dao.getDetails(session.getLogin()))
.filter(details -> details != null && StringUtils.isNotBlank(details.getFName))
.map(details -> dao.generateCredentials())
.cast(Credentials.class);
You can simplify like this:
Mono<Credentials> response = dao.validateSession(sessionId)
.filter(session -> StringUtils.isNotBlank(session.getLogin()))
.flatMap(session -> dao.getDetails(session.getLogin()))
.filter(details -> StringUtils.isNotBlank(details.getFName))
.flatMap(details -> dao.generateCredentials());
I've changed the operator used to simplify, but I think the last step require the details
object to be used as arguments of generateCredentials
method.