I have the Roo-generated project in STS and try to customise update/delete methods to work with MongoDB (for cascade update and delete). I created service methods to update (delete) childs when the parent is updated (deleted):
public class NoteServiceImpl implements NoteService {
@Autowired
MongoTemplate mongoTemplate;
public void updateNotesWithNoteBook(Notebook notebook) {
Update update = new Update().set("notebook.name", notebook.getName())
.set("notebook.author", notebook.getAuthor());
Query query = Query.query(Criteria.where("notebook._id").is(
new ObjectId(notebook.getId().toString(16))));
mongoTemplate.updateMulti(query, update, Note.class);
}
...the similar for delete action
NoteService interface is Roo-generated and looks as follows:
@RooService(domainTypes = { org.dp.mongo.shortnotes.domain.Note.class })
public interface NoteService {
}
Than I made push-in refactor of update and detete methods from Roo controller*.aj of the parent entity Notebook to the Notebook controller class, and added calls to the child' service methods:
@RequestMapping("/notebooks")
@Controller
@RooWebScaffold(path = "notebooks", formBackingObject = Notebook.class)
public class NotebookController {
@Autowired
private NoteService noteService;
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@Valid Notebook notebook, BindingResult bindingResult,
Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
populateEditForm(uiModel, notebook);
return "notebooks/update";
}
uiModel.asMap().clear();
notebookService.updateNotebook(notebook);
**noteService.updateNotesWithNoteBook(notebook);**
return "redirect:/notebooks/"
+ encodeUrlPathSegment(notebook.getId().toString(),
httpServletRequest);
}
the similar for delete method...
And finally got errors that noteService doesn't have method updateNotesWithNoteBook and delete method. How to fix them?