I have a complex data graph I need to save. Basically a questionnaire which has questions, questions have options and those options can have questions.
My naive attempt obviously doesn’t work. I get the warning Value is never used as a publisher
on the inner flatMap
‘s. I don’t care if this function is blocking but would prefer to do it correctly. The functional wouldn’t be called very often.
Without moving to MVC what is the idiomatic way to accomplish this? This is learning on my part. Trying to back to Java and wanted to try reactive programming. I’ve gone through a few iterations of this without much luck. Any pointer would be appreciated.
public Mono<QuestionnaireResp> create(Questionnaire questionnaire) {
.
.
.
return questionnaireRepo.save(questionnaire).flatMap((qq) -> {
questionRepo.saveAll(finalGraph.questions()).flatMap((q) -> {
questionOptionRepo.saveAll(finalGraph.questionOptions()).flatMap((qo) -> {
questionOptionQuestionRepo.saveAll(finalGraph.questionOptionQuestions()).flatMap((qoq) -> {
return Mono.just(qr);
});
return Mono.just(qr);
});
return Mono.just(qr);
});
return Mono.just(qr);
});