From 2dc0b4e27c8476f0d8ddbf5af92c55732273ecf8 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 19 Nov 2018 07:46:02 +0400 Subject: [PATCH 1/2] fix event create conditions --- src/main/java/ru/ulstu/timeline/service/EventScheduler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/timeline/service/EventScheduler.java b/src/main/java/ru/ulstu/timeline/service/EventScheduler.java index 7a0bc66..6df7fcb 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventScheduler.java +++ b/src/main/java/ru/ulstu/timeline/service/EventScheduler.java @@ -40,7 +40,8 @@ public class EventScheduler { @Scheduled(cron = "0 0 * * * ?") public void checkPeriodEvents() { log.debug("EventScheduler.checkPeriodEvents started"); - for (Event event : eventService.findAllFuture()) { + //TODO: filter + for (Event event : eventService.findAll()) { if (halfOfThePeriodHasPassed(event)) { eventService.createBasedOn(event, DateUtils.addDays(event.getExecuteDate(), getShiftInDays(event.getPeriod()))); } @@ -67,6 +68,6 @@ public class EventScheduler { private boolean halfOfThePeriodHasPassed(Event event) { return event.getPeriod() != null && event.getChild() == null && new Date().after( - DateUtils.addDays(event.getExecuteDate(), (int) -Math.round((double) getShiftInDays(event.getPeriod()) / 2))); + DateUtils.addDays(event.getExecuteDate(), (int) Math.round((double) getShiftInDays(event.getPeriod()) / 2))); } } From 58299d749dc600b3dc64a67acfae1c19a8b44749 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 19 Nov 2018 08:21:22 +0400 Subject: [PATCH 2/2] fix for remove event --- src/main/java/ru/ulstu/timeline/model/Event.java | 13 +++++++++++++ .../ru/ulstu/timeline/service/EventService.java | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index 7ae715d..290f136 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -4,6 +4,7 @@ import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.user.model.User; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -66,6 +67,10 @@ public class Event extends BaseEntity { @JoinColumn(name = "child_id") private Event child; + @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "child_id") + private List parents; + public String getTitle() { return title; } @@ -137,4 +142,12 @@ public class Event extends BaseEntity { public void setChild(Event child) { this.child = child; } + + public List getParents() { + return parents; + } + + public void setParents(List parents) { + this.parents = parents; + } } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index da32474..ca95b9a 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -57,8 +57,9 @@ public class EventService { } @Transactional - public void delete(Integer timelineId) { - Event event = eventRepository.findOne(timelineId); + public void delete(Integer eventId) { + Event event = eventRepository.findOne(eventId); + event.setParents(null); eventRepository.delete(event); }