From b4b7b9087e024617a83e29fb6d62644bd6c4b2fc Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 31 May 2019 08:12:57 +0400 Subject: [PATCH 1/3] fix npe --- src/main/java/ru/ulstu/grant/service/GrantService.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 86f8f1b..3243ace 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -232,10 +232,8 @@ public class GrantService extends BaseService { private boolean checkSameDeadline(GrantDto grantDto, Integer id) { Date date = grantDto.getDeadlines().get(0).getDate(); //дата с сайта киас - if (deadlineService.findByGrantIdAndDate(id, date).compareTo(date) == 0) { //если есть такая строка с датой - return true; - } - return false; + Date foundGrantDate = deadlineService.findByGrantIdAndDate(id, date); + return foundGrantDate != null && foundGrantDate.compareTo(date) == 0; } public List getGrantAuthors(GrantDto grantDto) { From d2ce6d604e4ef228a28be0fbe2ac865f0061bcda Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 31 May 2019 08:46:21 +0400 Subject: [PATCH 2/3] 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); } From a878f8c22ca04636449f0d33feb99354cd213540 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 31 May 2019 09:06:21 +0400 Subject: [PATCH 3/3] 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() {