@Ignore("TODO fix") @Test @Rollback(false) @Transactional public void testUpdate() { System.out.println("update test"); Integer entryId = EntryServiceImplTest.entryId; Entry entry = new Entry(); entry.setTitle("update test"); entry.setContents("This contents is updated!"); entry.setFormat("md"); entry.setPublished(true); List<Category> category = Lists.newArrayList(new Category(entryId, 1, "xx"), new Category(entryId, 2, "yy"), new Category(entryId, 3, "zz")); entry.setCategory(category); System.out.println(entry.getCategory().size() + " count: " + entry.getCategory()); System.out.println("do update"); Entry updated = entryService.update(entryId, entry, true, true); System.out.println(updated); assertThat(updated.getEntryId(), is(entryId)); assertThat(updated.getTitle(), is("update test")); assertThat(updated.getContents(), is("This contents is updated!")); assertThat(updated.getFormat(), is("md")); assertThat(updated.isPublished(), is(true)); assertThat(updated.getCategory(), is(category)); }
@Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) public Entry update(Integer entryId, Entry updatedEntry, boolean updateLastModifiedDate, boolean saveInHistory) { Assert.notNull(updatedEntry, "entry must not be null"); Entry entry = findOne(entryId); if (saveInHistory) { log.info("save history for entryId={}", entryId); EntryHistory history = beanMapper.map(entry, EntryHistory.class); history.setEntry(entry); entryHistoryRepository.save(history); } if (updateLastModifiedDate) { DateTime now = dateFactory.newDateTime(); updatedEntry.setLastModifiedDate(now); } Set<Tag> reduced = Sets.difference(entry.getTags(), updatedEntry.getTags()); houseKeepTag(reduced); beanMapper.map(updatedEntry, entry); entryRepository.save(entry); return entry; }
EntryServiceImpl implements EntryService { @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) public Entry update(Integer entryId, Entry updatedEntry, boolean updateLastModifiedDate, boolean saveInHistory) { Assert.notNull(updatedEntry, "entry must not be null"); Entry entry = findOne(entryId); if (saveInHistory) { log.info("save history for entryId={}", entryId); EntryHistory history = beanMapper.map(entry, EntryHistory.class); history.setEntry(entry); entryHistoryRepository.save(history); } if (updateLastModifiedDate) { DateTime now = dateFactory.newDateTime(); updatedEntry.setLastModifiedDate(now); } Set<Tag> reduced = Sets.difference(entry.getTags(), updatedEntry.getTags()); houseKeepTag(reduced); beanMapper.map(updatedEntry, entry); entryRepository.save(entry); return entry; } }
EntryServiceImpl implements EntryService { @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) public Entry update(Integer entryId, Entry updatedEntry, boolean updateLastModifiedDate, boolean saveInHistory) { Assert.notNull(updatedEntry, "entry must not be null"); Entry entry = findOne(entryId); if (saveInHistory) { log.info("save history for entryId={}", entryId); EntryHistory history = beanMapper.map(entry, EntryHistory.class); history.setEntry(entry); entryHistoryRepository.save(history); } if (updateLastModifiedDate) { DateTime now = dateFactory.newDateTime(); updatedEntry.setLastModifiedDate(now); } Set<Tag> reduced = Sets.difference(entry.getTags(), updatedEntry.getTags()); houseKeepTag(reduced); beanMapper.map(updatedEntry, entry); entryRepository.save(entry); return entry; }  }
EntryServiceImpl implements EntryService { @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) public Entry update(Integer entryId, Entry updatedEntry, boolean updateLastModifiedDate, boolean saveInHistory) { Assert.notNull(updatedEntry, "entry must not be null"); Entry entry = findOne(entryId); if (saveInHistory) { log.info("save history for entryId={}", entryId); EntryHistory history = beanMapper.map(entry, EntryHistory.class); history.setEntry(entry); entryHistoryRepository.save(history); } if (updateLastModifiedDate) { DateTime now = dateFactory.newDateTime(); updatedEntry.setLastModifiedDate(now); } Set<Tag> reduced = Sets.difference(entry.getTags(), updatedEntry.getTags()); houseKeepTag(reduced); beanMapper.map(updatedEntry, entry); entryRepository.save(entry); return entry; }  @Override Entry findOne(Integer entryId); @Override @Cacheable("entry") Entry findOnePublished(Integer entryId); @Override Page<Entry> findPage(Pageable pageable); @Override @Cacheable("entry") Page<Entry> findPagePublished(Pageable pageable); @Override @Cacheable("recentPost") List<Entry> findAllPublishedUpdatedRecently(); @Override Page<Entry> findPagePublishedByCategoryNameAndCategoryOrder(
            String categoryName, Integer categoryOrder, Pageable pageable); @Override Page<Entry> findPagePublishedByCreatedBy(String createdBy, Pageable pageable); @Override Page<Entry> findPagePublishedByTagName(String tagName, Pageable pageable); @Override Page<Entry> findPageByTagName(String tagName, Pageable pageable); @Override Page<Entry> searchPageByKeyword(String keyword, Pageable pageable); @Override Page<Entry> searchPagePublishedByKeyword(String keyword, Pageable pageable); @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) Entry create(Entry entry, List<Category> category); @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) Entry update(Integer entryId, Entry updatedEntry,
                        boolean updateLastModifiedDate, boolean saveInHistory); @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) void delete(Integer entryId); }
EntryServiceImpl implements EntryService { @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) public Entry update(Integer entryId, Entry updatedEntry, boolean updateLastModifiedDate, boolean saveInHistory) { Assert.notNull(updatedEntry, "entry must not be null"); Entry entry = findOne(entryId); if (saveInHistory) { log.info("save history for entryId={}", entryId); EntryHistory history = beanMapper.map(entry, EntryHistory.class); history.setEntry(entry); entryHistoryRepository.save(history); } if (updateLastModifiedDate) { DateTime now = dateFactory.newDateTime(); updatedEntry.setLastModifiedDate(now); } Set<Tag> reduced = Sets.difference(entry.getTags(), updatedEntry.getTags()); houseKeepTag(reduced); beanMapper.map(updatedEntry, entry); entryRepository.save(entry); return entry; }  @Override Entry findOne(Integer entryId); @Override @Cacheable("entry") Entry findOnePublished(Integer entryId); @Override Page<Entry> findPage(Pageable pageable); @Override @Cacheable("entry") Page<Entry> findPagePublished(Pageable pageable); @Override @Cacheable("recentPost") List<Entry> findAllPublishedUpdatedRecently(); @Override Page<Entry> findPagePublishedByCategoryNameAndCategoryOrder(
            String categoryName, Integer categoryOrder, Pageable pageable); @Override Page<Entry> findPagePublishedByCreatedBy(String createdBy, Pageable pageable); @Override Page<Entry> findPagePublishedByTagName(String tagName, Pageable pageable); @Override Page<Entry> findPageByTagName(String tagName, Pageable pageable); @Override Page<Entry> searchPageByKeyword(String keyword, Pageable pageable); @Override Page<Entry> searchPagePublishedByKeyword(String keyword, Pageable pageable); @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) Entry create(Entry entry, List<Category> category); @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) Entry update(Integer entryId, Entry updatedEntry,
                        boolean updateLastModifiedDate, boolean saveInHistory); @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) void delete(Integer entryId);  }