fix remove older events

This commit is contained in:
Anton Romanov 2019-05-31 09:06:21 +04:00
parent d2ce6d604e
commit a878f8c22c

View File

@ -17,6 +17,8 @@ import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -103,9 +105,13 @@ public class EventService {
} }
public void createFromPaper(Paper newPaper) { public void createFromPaper(Paper newPaper) {
createFromPaper(newPaper, Collections.emptyList());
}
public void createFromPaper(Paper newPaper, List<Event> events) {
List<Timeline> timelines = timelineService.findAll(); List<Timeline> timelines = timelineService.findAll();
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
timeline.getEvents().removeAll(newPaper.getEvents()); timeline.getEvents().removeAll(events);
for (Deadline deadline : newPaper.getDeadlines() for (Deadline deadline : newPaper.getDeadlines()
.stream() .stream()
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) .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) { public void updatePaperDeadlines(Paper paper) {
eventRepository.delete(eventRepository.findAllByPaper(paper)); List<Event> foundEvents = eventRepository.findAllByPaper(paper);
createFromPaper(paper); eventRepository.delete(foundEvents);
createFromPaper(paper, foundEvents);
} }
public List<Event> findByCurrentDate() { public List<Event> findByCurrentDate() {