fix merging collection

This commit is contained in:
Anton Romanov 2019-05-31 08:46:21 +04:00
parent b4b7b9087e
commit d2ce6d604e

View File

@ -105,7 +105,7 @@ public class EventService {
public void createFromPaper(Paper newPaper) { public void createFromPaper(Paper newPaper) {
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());
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()))
@ -119,16 +119,13 @@ public class EventService {
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'");
newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); newEvent.setRecipients(new ArrayList(newPaper.getAuthors()));
newEvent.setPaper(newPaper); newEvent.setPaper(newPaper);
eventRepository.save(newEvent); timeline.getEvents().add(eventRepository.save(newEvent));
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
} }
timelineService.save(timeline);
} }
public void updatePaperDeadlines(Paper paper) { public void updatePaperDeadlines(Paper paper) {
eventRepository.delete(eventRepository.findAllByPaper(paper)); eventRepository.delete(eventRepository.findAllByPaper(paper));
createFromPaper(paper); createFromPaper(paper);
} }