From a878f8c22ca04636449f0d33feb99354cd213540 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 31 May 2019 09:06:21 +0400 Subject: [PATCH] fix remove older events --- .../ru/ulstu/timeline/service/EventService.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index f9b88f3..328014a 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -17,6 +17,8 @@ import ru.ulstu.user.model.UserDto; import ru.ulstu.user.service.UserService; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -103,9 +105,13 @@ public class EventService { } public void createFromPaper(Paper newPaper) { + createFromPaper(newPaper, Collections.emptyList()); + } + + public void createFromPaper(Paper newPaper, List events) { List timelines = timelineService.findAll(); Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); - timeline.getEvents().removeAll(newPaper.getEvents()); + timeline.getEvents().removeAll(events); for (Deadline deadline : newPaper.getDeadlines() .stream() .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) @@ -125,8 +131,9 @@ public class EventService { } public void updatePaperDeadlines(Paper paper) { - eventRepository.delete(eventRepository.findAllByPaper(paper)); - createFromPaper(paper); + List foundEvents = eventRepository.findAllByPaper(paper); + eventRepository.delete(foundEvents); + createFromPaper(paper, foundEvents); } public List findByCurrentDate() {