@Transactional @CacheEvict( value = {Caches.BLOG_ENTRY_TOS, Caches.GLOBAL_PAGE_CACHE}, allEntries = true) @RequestMapping(method = RequestMethod.POST) @ResponseBody public void createOrUpdateBlogEntry(@RequestBody CreateOrUpdateBlogEntryTO createNewBlogEntryTO) { final BlogEntry newEntry; if (createNewBlogEntryTO.getId() != null) { newEntry = blogEntryRepository.findOne(createNewBlogEntryTO.getId()); newEntry.setId(createNewBlogEntryTO.getId()); } else { newEntry = new BlogEntry(); newEntry.setAuthor( userRepository.findOne( ((DynamicSaltedUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()) .getUsername())); // TODO more generic? } newEntry.setContent(createNewBlogEntryTO.getContent()); newEntry.setTitle(createNewBlogEntryTO.getTitle()); blogEntryRepository.save(newEntry); }
@Transactional @CacheEvict( value = {Caches.BLOG_ENTRY_TOS, Caches.GLOBAL_PAGE_CACHE}, allEntries = true) public void addComment(BlogEntryTO entry, BlogEntryCommentTO newComment) { BlogEntry blogEntry = blogEntryRepository.findOne(entry.getId()); blogEntry.getComments().add(newComment.toBlogEntryComment()); blogEntryRepository.save(blogEntry); }
@Cacheable(value = Caches.BLOG_ENTRY_TOS, key = "'blogEntry'.concat(#entryId)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public BlogEntryTO getEntry(@PathVariable("id") Long entryId) { return new BlogEntryTO(blogEntryRepository.findOne(entryId)); }