@Test @Rollback(false) @Transactional public void testCreate() { Entry entry = new Entry(); entry.setTitle("My first entry"); entry.setContents("Hi, This is duke."); entry.setFormat("md"); entry.setPublished(true); entry.setCreatedDate(new DateTime(1984, 4, 12, 0, 0)); List<Category> category = Arrays.asList(new Category(null, 1, "aaa"), new Category(null, 2, "bbb"), new Category(null, 3, "ccc")); Entry created = entryService.create(entry, category); EntryServiceImplTest.entryId = created.getEntryId(); }
@Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) public Entry create(Entry entry, List<Category> category) { Assert.notNull(entry, "entry must not be null"); Assert.isNull(entry.getCategory(), "entry.category must be null"); Assert.notNull(category, "category must not be null or empty"); Assert.notNull(entry.getTags(), "category must not be null"); tagRepository.save(entry.getTags().stream() .filter(tag -> !tagRepository.exists(tag.getTagName())) .collect(Collectors.toList())); DateTime now = dateFactory.newDateTime(); entry.setCreatedDate(now); entry.setLastModifiedDate(now); entryRepository.saveAndFlush(entry); Integer entryId = entry.getEntryId(); for (Category c : category) { c.getCategoryPK().setEntryId(entryId); } entry.setCategory(category); return entry; }
EntryServiceImpl implements EntryService { @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) public Entry create(Entry entry, List<Category> category) { Assert.notNull(entry, "entry must not be null"); Assert.isNull(entry.getCategory(), "entry.category must be null"); Assert.notNull(category, "category must not be null or empty"); Assert.notNull(entry.getTags(), "category must not be null"); tagRepository.save(entry.getTags().stream() .filter(tag -> !tagRepository.exists(tag.getTagName())) .collect(Collectors.toList())); DateTime now = dateFactory.newDateTime(); entry.setCreatedDate(now); entry.setLastModifiedDate(now); entryRepository.saveAndFlush(entry); Integer entryId = entry.getEntryId(); for (Category c : category) { c.getCategoryPK().setEntryId(entryId); } entry.setCategory(category); return entry; } }
EntryServiceImpl implements EntryService { @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) public Entry create(Entry entry, List<Category> category) { Assert.notNull(entry, "entry must not be null"); Assert.isNull(entry.getCategory(), "entry.category must be null"); Assert.notNull(category, "category must not be null or empty"); Assert.notNull(entry.getTags(), "category must not be null"); tagRepository.save(entry.getTags().stream() .filter(tag -> !tagRepository.exists(tag.getTagName())) .collect(Collectors.toList())); DateTime now = dateFactory.newDateTime(); entry.setCreatedDate(now); entry.setLastModifiedDate(now); entryRepository.saveAndFlush(entry); Integer entryId = entry.getEntryId(); for (Category c : category) { c.getCategoryPK().setEntryId(entryId); } entry.setCategory(category); return entry; }  }
EntryServiceImpl implements EntryService { @Override @Transactional @CacheEvict(value = {"recentPost", "entry"}, allEntries = true) public Entry create(Entry entry, List<Category> category) { Assert.notNull(entry, "entry must not be null"); Assert.isNull(entry.getCategory(), "entry.category must be null"); Assert.notNull(category, "category must not be null or empty"); Assert.notNull(entry.getTags(), "category must not be null"); tagRepository.save(entry.getTags().stream() .filter(tag -> !tagRepository.exists(tag.getTagName())) .collect(Collectors.toList())); DateTime now = dateFactory.newDateTime(); entry.setCreatedDate(now); entry.setLastModifiedDate(now); entryRepository.saveAndFlush(entry); Integer entryId = entry.getEntryId(); for (Category c : category) { c.getCategoryPK().setEntryId(entryId); } entry.setCategory(category); 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 create(Entry entry, List<Category> category) { Assert.notNull(entry, "entry must not be null"); Assert.isNull(entry.getCategory(), "entry.category must be null"); Assert.notNull(category, "category must not be null or empty"); Assert.notNull(entry.getTags(), "category must not be null"); tagRepository.save(entry.getTags().stream() .filter(tag -> !tagRepository.exists(tag.getTagName())) .collect(Collectors.toList())); DateTime now = dateFactory.newDateTime(); entry.setCreatedDate(now); entry.setLastModifiedDate(now); entryRepository.saveAndFlush(entry); Integer entryId = entry.getEntryId(); for (Category c : category) { c.getCategoryPK().setEntryId(entryId); } entry.setCategory(category); 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);  }