From beb334f2fa2e21c508b86aac0f3ae54fb160fa12 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sat, 4 May 2019 23:59:03 +0400 Subject: [PATCH 1/3] #32 add variable "events" --- src/main/java/ru/ulstu/grant/model/Grant.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index d6f9f0c..ac8ac19 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -9,6 +9,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.Project; +import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; @@ -92,6 +93,10 @@ public class Grant extends BaseEntity implements UserContainer { inverseJoinColumns = {@JoinColumn(name = "paper_id")}) private List papers = new ArrayList<>(); + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @JoinColumn(name = "grant_id") + private List events = new ArrayList<>(); + public GrantStatus getStatus() { return status; } @@ -169,6 +174,14 @@ public class Grant extends BaseEntity implements UserContainer { this.papers = papers; } + public List getEvents() { + return events; + } + + public void setEvents(List events) { + this.events = events; + } + public Optional getNextDeadline() { return deadlines .stream() From 114f6769ac95a280381663ded00bdfe3fe3039d7 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sun, 5 May 2019 23:54:02 +0400 Subject: [PATCH 2/3] #32 create changelog --- .../db/changelog-20190505_000000-schema.xml | 14 ++++++++++++++ src/main/resources/db/changelog-master.xml | 1 + 2 files changed, 15 insertions(+) create mode 100644 src/main/resources/db/changelog-20190505_000000-schema.xml diff --git a/src/main/resources/db/changelog-20190505_000000-schema.xml b/src/main/resources/db/changelog-20190505_000000-schema.xml new file mode 100644 index 0000000..ac8707a --- /dev/null +++ b/src/main/resources/db/changelog-20190505_000000-schema.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 3cc05ae..83ff280 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -37,4 +37,5 @@ + \ No newline at end of file From da382b659a003906aaf4a2ddd6b5b5b28d2fd959 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Mon, 6 May 2019 00:32:28 +0400 Subject: [PATCH 3/3] #32 add deadlines on timeline page --- src/main/java/ru/ulstu/grant/model/Grant.java | 1 + .../ru/ulstu/grant/service/GrantService.java | 11 ++++++- .../java/ru/ulstu/timeline/model/Event.java | 13 ++++++++ .../ru/ulstu/timeline/model/EventDto.java | 17 +++++++++- .../timeline/repository/EventRepository.java | 3 ++ .../ulstu/timeline/service/EventService.java | 33 +++++++++++++++++++ 6 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index ac8ac19..760895e 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -91,6 +91,7 @@ public class Grant extends BaseEntity implements UserContainer { @JoinTable(name = "grants_papers", joinColumns = {@JoinColumn(name = "grant_id")}, inverseJoinColumns = {@JoinColumn(name = "paper_id")}) + @Fetch(FetchMode.SUBSELECT) private List papers = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index cb86b7a..9cff4b6 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -15,6 +15,7 @@ import ru.ulstu.paper.service.PaperService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; +import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -39,19 +40,22 @@ public class GrantService { private final FileService fileService; private final UserService userService; private final PaperService paperService; + private final EventService eventService; public GrantService(GrantRepository grantRepository, FileService fileService, DeadlineService deadlineService, ProjectService projectService, UserService userService, - PaperService paperService) { + PaperService paperService, + EventService eventService) { this.grantRepository = grantRepository; this.fileService = fileService; this.deadlineService = deadlineService; this.projectService = projectService; this.userService = userService; this.paperService = paperService; + this.eventService = eventService; } public List findAll() { @@ -72,6 +76,7 @@ public class GrantService { public Integer create(GrantDto grantDto) throws IOException { Grant newGrant = copyFromDto(new Grant(), grantDto); newGrant = grantRepository.save(newGrant); + eventService.createFromGrant(newGrant); return newGrant.getId(); } @@ -115,6 +120,7 @@ public class GrantService { } grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove); grantRepository.save(copyFromDto(grant, grantDto)); + eventService.updateGrantDeadlines(grant); return grant.getId(); } @@ -140,6 +146,9 @@ public class GrantService { grant.setLeader(user); grant.getPapers().add(paper); grant = grantRepository.save(grant); + + eventService.createFromGrant(grant); + return grant; } diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index 9409f21..9252cec 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -3,6 +3,7 @@ package ru.ulstu.timeline.model; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; import ru.ulstu.user.model.User; @@ -82,6 +83,10 @@ public class Event extends BaseEntity { @JoinColumn(name = "conference_id") private Conference conference; + @ManyToOne + @JoinColumn(name = "grant_id") + private Grant grant; + public String getTitle() { return title; } @@ -177,4 +182,12 @@ public class Event extends BaseEntity { public void setConference(Conference conference) { this.conference = conference; } + + public Grant getGrant() { + return grant; + } + + public void setGrant(Grant grant) { + this.grant = grant; + } } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index ccce25a..89df5d8 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.conference.model.ConferenceDto; +import ru.ulstu.grant.model.GrantDto; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.user.model.UserDto; @@ -27,6 +28,7 @@ public class EventDto { private final List recipients; private PaperDto paperDto; private ConferenceDto conferenceDto; + private GrantDto grantDto; @JsonCreator public EventDto(@JsonProperty("id") Integer id, @@ -39,7 +41,8 @@ public class EventDto { @JsonProperty("description") String description, @JsonProperty("paperDto") PaperDto paperDto, @JsonProperty("recipients") List recipients, - @JsonProperty("conferenceDto") ConferenceDto conferenceDto) { + @JsonProperty("conferenceDto") ConferenceDto conferenceDto, + @JsonProperty("grantDto") GrantDto grantDto) { this.id = id; this.title = title; this.period = period; @@ -51,6 +54,7 @@ public class EventDto { this.recipients = recipients; this.paperDto = paperDto; this.conferenceDto = conferenceDto; + this.grantDto = grantDto; } public EventDto(Event event) { @@ -69,6 +73,9 @@ public class EventDto { if (conferenceDto != null) { this.conferenceDto = new ConferenceDto(event.getConference()); } + if (grantDto != null) { + this.grantDto = new GrantDto(event.getGrant()); + } } public Integer getId() { @@ -122,4 +129,12 @@ public class EventDto { public void setConferenceDto(ConferenceDto conferenceDto) { this.conferenceDto = conferenceDto; } + + public GrantDto getGrantDto() { + return grantDto; + } + + public void setGrantDto(GrantDto grantDto) { + this.grantDto = grantDto; + } } diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java index a4b1e47..e01037a 100644 --- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java +++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java @@ -3,6 +3,7 @@ package ru.ulstu.timeline.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import ru.ulstu.conference.model.Conference; +import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; import ru.ulstu.timeline.model.Event; @@ -18,4 +19,6 @@ public interface EventRepository extends JpaRepository { List findAllByPaper(Paper paper); List findAllByConference(Conference conference); + + List findAllByGrant(Grant grant); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index d2fa510..b935f16 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -6,6 +6,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.conference.model.Conference; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.EventDto; @@ -170,4 +171,36 @@ public class EventService { eventRepository.delete(eventRepository.findAllByConference(conference)); createFromConference(conference); } + + public void createFromGrant(Grant newGrant) { + List timelines = timelineService.findAll(); + Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); + + for (Deadline deadline : newGrant.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн гранта"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' гранта '" + newGrant.getTitle() + "'"); + if (newGrant.getAuthors() != null) { + newEvent.setRecipients(new ArrayList(newGrant.getAuthors())); + } + newEvent.getRecipients().add(newGrant.getLeader()); + newEvent.setGrant(newGrant); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + } + + public void updateGrantDeadlines(Grant grant) { + eventRepository.delete(eventRepository.findAllByGrant(grant)); + createFromGrant(grant); + } }