#32 add deadlines on timeline page

merge-requests/83/head
T-Midnight 5 years ago
parent 114f6769ac
commit da382b659a

@ -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<Paper> papers = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)

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

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

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

@ -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<Event, Integer> {
List<Event> findAllByPaper(Paper paper);
List<Event> findAllByConference(Conference conference);
List<Event> findAllByGrant(Grant grant);
}

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

Loading…
Cancel
Save