From d2ce6d604e4ef228a28be0fbe2ac865f0061bcda Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 31 May 2019 08:46:21 +0400 Subject: [PATCH] fix merging collection --- .../java/ru/ulstu/timeline/service/EventService.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index 8c68291..f9b88f3 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -105,7 +105,7 @@ public class EventService { public void createFromPaper(Paper newPaper) { List timelines = timelineService.findAll(); Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); - + timeline.getEvents().removeAll(newPaper.getEvents()); for (Deadline deadline : newPaper.getDeadlines() .stream() .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) @@ -119,16 +119,13 @@ public class EventService { newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); newEvent.setPaper(newPaper); - eventRepository.save(newEvent); - - timeline.getEvents().add(newEvent); - timelineService.save(timeline); + timeline.getEvents().add(eventRepository.save(newEvent)); } + timelineService.save(timeline); } public void updatePaperDeadlines(Paper paper) { eventRepository.delete(eventRepository.findAllByPaper(paper)); - createFromPaper(paper); }