Reputation: 41
Im really new with reactive programming. Im trying to figure out what to do here
i have written the following code:
templateService.getTemplate(id)
.map(this::setTemplate)
.map(c -> convertDTOToBO(dto, c))
.flatMap(templateService::toPdf)
.map(content -> ResponseEntity.ok()
.header("Content-Disposition", "attachment; filename=\"test_" + NAMEPROPERTYHERE + ".pdf\"")
.body(content));
I need to get a value that is on the object that returns from templateService.getTemplateById(id)
, need to take the property 'name' to put on the 'filename' (where i write NAMEPROPERTYHERE). I just cant figure out how i can do it.
the problem is that when it gets to the last map, the object is not the same anymore and i cant get the value i need.
Im so used to the traditional way of programming that i can only think to pass it to a variable.. what the best way to do that?
Upvotes: 0
Views: 808
Reputation: 5972
You could just shift logic "one-level down" to get access to the template
templateService.getTemplate(id)
.map(template ->
setTemplate(template)
.map(c -> convertDTOToBO(dto, c))
.flatMap(templateService::toPdf)
.map(content -> ResponseEntity.ok()
.header("Content-Disposition", "attachment; filename=\"test_" + template.getName() + ".pdf\"")
.body(content))
);
Upvotes: 1