#32 add deadlines on timeline page

This commit is contained in:
T-Midnight 2019-05-06 00:32:28 +04:00
parent 114f6769ac
commit da382b659a
6 changed files with 76 additions and 2 deletions

View File

@ -91,6 +91,7 @@ public class Grant extends BaseEntity implements UserContainer {
@JoinTable(name = "grants_papers", @JoinTable(name = "grants_papers",
joinColumns = {@JoinColumn(name = "grant_id")}, joinColumns = {@JoinColumn(name = "grant_id")},
inverseJoinColumns = {@JoinColumn(name = "paper_id")}) inverseJoinColumns = {@JoinColumn(name = "paper_id")})
@Fetch(FetchMode.SUBSELECT)
private List<Paper> papers = new ArrayList<>(); private List<Paper> papers = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)

View File

@ -15,6 +15,7 @@ import ru.ulstu.paper.service.PaperService;
import ru.ulstu.project.model.Project; import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.project.service.ProjectService; import ru.ulstu.project.service.ProjectService;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
@ -39,19 +40,22 @@ public class GrantService {
private final FileService fileService; private final FileService fileService;
private final UserService userService; private final UserService userService;
private final PaperService paperService; private final PaperService paperService;
private final EventService eventService;
public GrantService(GrantRepository grantRepository, public GrantService(GrantRepository grantRepository,
FileService fileService, FileService fileService,
DeadlineService deadlineService, DeadlineService deadlineService,
ProjectService projectService, ProjectService projectService,
UserService userService, UserService userService,
PaperService paperService) { PaperService paperService,
EventService eventService) {
this.grantRepository = grantRepository; this.grantRepository = grantRepository;
this.fileService = fileService; this.fileService = fileService;
this.deadlineService = deadlineService; this.deadlineService = deadlineService;
this.projectService = projectService; this.projectService = projectService;
this.userService = userService; this.userService = userService;
this.paperService = paperService; this.paperService = paperService;
this.eventService = eventService;
} }
public List<Grant> findAll() { public List<Grant> findAll() {
@ -72,6 +76,7 @@ public class GrantService {
public Integer create(GrantDto grantDto) throws IOException { public Integer create(GrantDto grantDto) throws IOException {
Grant newGrant = copyFromDto(new Grant(), grantDto); Grant newGrant = copyFromDto(new Grant(), grantDto);
newGrant = grantRepository.save(newGrant); newGrant = grantRepository.save(newGrant);
eventService.createFromGrant(newGrant);
return newGrant.getId(); return newGrant.getId();
} }
@ -115,6 +120,7 @@ public class GrantService {
} }
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove); grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
grantRepository.save(copyFromDto(grant, grantDto)); grantRepository.save(copyFromDto(grant, grantDto));
eventService.updateGrantDeadlines(grant);
return grant.getId(); return grant.getId();
} }
@ -140,6 +146,9 @@ public class GrantService {
grant.setLeader(user); grant.setLeader(user);
grant.getPapers().add(paper); grant.getPapers().add(paper);
grant = grantRepository.save(grant); grant = grantRepository.save(grant);
eventService.createFromGrant(grant);
return grant; return grant;
} }

View File

@ -3,6 +3,7 @@ package ru.ulstu.timeline.model;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
@ -82,6 +83,10 @@ public class Event extends BaseEntity {
@JoinColumn(name = "conference_id") @JoinColumn(name = "conference_id")
private Conference conference; private Conference conference;
@ManyToOne
@JoinColumn(name = "grant_id")
private Grant grant;
public String getTitle() { public String getTitle() {
return title; return title;
} }
@ -177,4 +182,12 @@ public class Event extends BaseEntity {
public void setConference(Conference conference) { public void setConference(Conference conference) {
this.conference = conference; this.conference = conference;
} }
public Grant getGrant() {
return grant;
}
public void setGrant(Grant grant) {
this.grant = grant;
}
} }

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
@ -27,6 +28,7 @@ public class EventDto {
private final List<UserDto> recipients; private final List<UserDto> recipients;
private PaperDto paperDto; private PaperDto paperDto;
private ConferenceDto conferenceDto; private ConferenceDto conferenceDto;
private GrantDto grantDto;
@JsonCreator @JsonCreator
public EventDto(@JsonProperty("id") Integer id, public EventDto(@JsonProperty("id") Integer id,
@ -39,7 +41,8 @@ public class EventDto {
@JsonProperty("description") String description, @JsonProperty("description") String description,
@JsonProperty("paperDto") PaperDto paperDto, @JsonProperty("paperDto") PaperDto paperDto,
@JsonProperty("recipients") List<UserDto> recipients, @JsonProperty("recipients") List<UserDto> recipients,
@JsonProperty("conferenceDto") ConferenceDto conferenceDto) { @JsonProperty("conferenceDto") ConferenceDto conferenceDto,
@JsonProperty("grantDto") GrantDto grantDto) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.period = period; this.period = period;
@ -51,6 +54,7 @@ public class EventDto {
this.recipients = recipients; this.recipients = recipients;
this.paperDto = paperDto; this.paperDto = paperDto;
this.conferenceDto = conferenceDto; this.conferenceDto = conferenceDto;
this.grantDto = grantDto;
} }
public EventDto(Event event) { public EventDto(Event event) {
@ -69,6 +73,9 @@ public class EventDto {
if (conferenceDto != null) { if (conferenceDto != null) {
this.conferenceDto = new ConferenceDto(event.getConference()); this.conferenceDto = new ConferenceDto(event.getConference());
} }
if (grantDto != null) {
this.grantDto = new GrantDto(event.getGrant());
}
} }
public Integer getId() { public Integer getId() {
@ -122,4 +129,12 @@ public class EventDto {
public void setConferenceDto(ConferenceDto conferenceDto) { public void setConferenceDto(ConferenceDto conferenceDto) {
this.conferenceDto = conferenceDto; this.conferenceDto = conferenceDto;
} }
public GrantDto getGrantDto() {
return grantDto;
}
public void setGrantDto(GrantDto grantDto) {
this.grantDto = grantDto;
}
} }

View File

@ -3,6 +3,7 @@ package ru.ulstu.timeline.repository;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
@ -18,4 +19,6 @@ public interface EventRepository extends JpaRepository<Event, Integer> {
List<Event> findAllByPaper(Paper paper); List<Event> findAllByPaper(Paper paper);
List<Event> findAllByConference(Conference conference); List<Event> findAllByConference(Conference conference);
List<Event> findAllByGrant(Grant grant);
} }

View File

@ -6,6 +6,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.Event;
import ru.ulstu.timeline.model.EventDto; import ru.ulstu.timeline.model.EventDto;
@ -170,4 +171,36 @@ public class EventService {
eventRepository.delete(eventRepository.findAllByConference(conference)); eventRepository.delete(eventRepository.findAllByConference(conference));
createFromConference(conference); createFromConference(conference);
} }
public void createFromGrant(Grant newGrant) {
List<Timeline> 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);
}
} }