Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anton Romanov 2018-11-21 12:46:42 +04:00
commit ef32bba684
3 changed files with 19 additions and 4 deletions

View File

@ -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<Event> 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<Event> getParents() {
return parents;
}
public void setParents(List<Event> parents) {
this.parents = parents;
}
}

View File

@ -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)));
}
}

View File

@ -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);
}