Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ef32bba684
@ -4,6 +4,7 @@ import org.hibernate.validator.constraints.NotBlank;
|
|||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
@ -66,6 +67,10 @@ public class Event extends BaseEntity {
|
|||||||
@JoinColumn(name = "child_id")
|
@JoinColumn(name = "child_id")
|
||||||
private Event child;
|
private Event child;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "child_id")
|
||||||
|
private List<Event> parents;
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
@ -137,4 +142,12 @@ public class Event extends BaseEntity {
|
|||||||
public void setChild(Event child) {
|
public void setChild(Event child) {
|
||||||
this.child = child;
|
this.child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Event> getParents() {
|
||||||
|
return parents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParents(List<Event> parents) {
|
||||||
|
this.parents = parents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,8 @@ public class EventScheduler {
|
|||||||
@Scheduled(cron = "0 0 * * * ?")
|
@Scheduled(cron = "0 0 * * * ?")
|
||||||
public void checkPeriodEvents() {
|
public void checkPeriodEvents() {
|
||||||
log.debug("EventScheduler.checkPeriodEvents started");
|
log.debug("EventScheduler.checkPeriodEvents started");
|
||||||
for (Event event : eventService.findAllFuture()) {
|
//TODO: filter
|
||||||
|
for (Event event : eventService.findAll()) {
|
||||||
if (halfOfThePeriodHasPassed(event)) {
|
if (halfOfThePeriodHasPassed(event)) {
|
||||||
eventService.createBasedOn(event, DateUtils.addDays(event.getExecuteDate(), getShiftInDays(event.getPeriod())));
|
eventService.createBasedOn(event, DateUtils.addDays(event.getExecuteDate(), getShiftInDays(event.getPeriod())));
|
||||||
}
|
}
|
||||||
@ -67,6 +68,6 @@ public class EventScheduler {
|
|||||||
private boolean halfOfThePeriodHasPassed(Event event) {
|
private boolean halfOfThePeriodHasPassed(Event event) {
|
||||||
return event.getPeriod() != null && event.getChild() == null
|
return event.getPeriod() != null && event.getChild() == null
|
||||||
&& new Date().after(
|
&& 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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,9 @@ public class EventService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer timelineId) {
|
public void delete(Integer eventId) {
|
||||||
Event event = eventRepository.findOne(timelineId);
|
Event event = eventRepository.findOne(eventId);
|
||||||
|
event.setParents(null);
|
||||||
eventRepository.delete(event);
|
eventRepository.delete(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user