From dbcdb96dbf066655ebe4ff30048a7c38321902cc Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 26 Apr 2019 15:12:34 +0400 Subject: [PATCH] #70 added event method, don't work, because trying to find null entity --- .../ru/ulstu/conference/model/Conference.java | 1 + .../conference/service/ConferenceService.java | 1 + src/main/java/ru/ulstu/timeline/model/Event.java | 13 +++++++++++++ .../java/ru/ulstu/timeline/model/EventDto.java | 15 ++++++++++++++- .../timeline/repository/EventRepository.java | 3 +++ .../ru/ulstu/timeline/service/EventService.java | 13 +++++++++---- 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 9c91a7e..7e18ac0 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -59,6 +59,7 @@ public class Conference extends BaseEntity { @JoinTable(name = "paper_conference", joinColumns = {@JoinColumn(name = "conference_id")}, inverseJoinColumns = {@JoinColumn(name = "paper_id")}) + @Fetch(FetchMode.SUBSELECT) private List papers = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 6550814..0c1d37d 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -114,6 +114,7 @@ public class ConferenceService { Date oldBeginDate = conference.getBeginDate(); Date oldEndDate = conference.getEndDate(); conferenceRepository.save(copyFromDto(conference, conferenceDto)); + eventService.updateConferenceDeadlines(conference); sendNotificationAfterUpdate(conference, oldDeadlines, oldBeginDate, oldEndDate); conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove); return conference.getId(); diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index ef0a4b8..f53a52d 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -1,6 +1,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.paper.model.Paper; import ru.ulstu.user.model.User; @@ -76,6 +77,10 @@ public class Event extends BaseEntity { @JoinColumn(name = "paper_id") private Paper paper; + @ManyToOne + @JoinColumn(name = "conference_id") + private Conference conference; + public String getTitle() { return title; } @@ -163,4 +168,12 @@ public class Event extends BaseEntity { public void setPaper(Paper paper) { this.paper = paper; } + + public Conference getConference() { + return conference; + } + + public void setConference(Conference conference) { + this.conference = conference; + } } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index 6a4a90b..1d2a29a 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -3,6 +3,7 @@ package ru.ulstu.timeline.model; 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.paper.model.PaperDto; import ru.ulstu.user.model.UserDto; @@ -25,6 +26,7 @@ public class EventDto { private final String description; private final List recipients; private PaperDto paperDto; + private ConferenceDto conferenceDto; @JsonCreator public EventDto(@JsonProperty("id") Integer id, @@ -36,7 +38,8 @@ public class EventDto { @JsonProperty("updateDate") Date updateDate, @JsonProperty("description") String description, @JsonProperty("paperDto") PaperDto paperDto, - @JsonProperty("recipients") List recipients) { + @JsonProperty("recipients") List recipients, + @JsonProperty("paperDto") ConferenceDto conferenceDto) { this.id = id; this.title = title; this.period = period; @@ -47,6 +50,7 @@ public class EventDto { this.description = description; this.recipients = recipients; this.paperDto = paperDto; + this.conferenceDto = conferenceDto; } public EventDto(Event event) { @@ -60,6 +64,7 @@ public class EventDto { this.description = event.getDescription(); this.paperDto = new PaperDto(event.getPaper()); this.recipients = convert(event.getRecipients(), UserDto::new); + this.conferenceDto = new ConferenceDto(event.getConference()); } public Integer getId() { @@ -105,4 +110,12 @@ public class EventDto { public void setPaperDto(PaperDto paperDto) { this.paperDto = paperDto; } + + public ConferenceDto getConferenceDto() { + return conferenceDto; + } + + public void setConferenceDto(ConferenceDto conferenceDto) { + this.conferenceDto = conferenceDto; + } } diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java index eb5c08b..a4b1e47 100644 --- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java +++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java @@ -2,6 +2,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.paper.model.Paper; import ru.ulstu.timeline.model.Event; @@ -15,4 +16,6 @@ public interface EventRepository extends JpaRepository { List findAllFuture(); List findAllByPaper(Paper paper); + + List findAllByConference(Conference conference); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index d0e50a9..f4e2873 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -151,18 +151,23 @@ public class EventService { .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) .collect(Collectors.toList())) { Event newEvent = new Event(); - newEvent.setTitle("Дедлайн статьи"); + newEvent.setTitle("Дедлайн конференции"); newEvent.setStatus(Event.EventStatus.NEW); newEvent.setExecuteDate(deadline.getDate()); newEvent.setCreateDate(new Date()); newEvent.setUpdateDate(new Date()); -// newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); -// newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); -// newEvent.setConference(newConference); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' конференции '" + newConference.getTitle() + "'"); + newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser())); + newEvent.setConference(newConference); eventRepository.save(newEvent); timeline.getEvents().add(newEvent); timelineService.save(timeline); } } + + public void updateConferenceDeadlines(Conference conference) { + eventRepository.delete(eventRepository.findAllByConference(conference)); + createFromConference(conference); + } }