#70 added event method, don't work, because trying to find null entity
This commit is contained in:
parent
51877023d1
commit
dbcdb96dbf
@ -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<Paper> papers = new ArrayList<>();
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<UserDto> 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<UserDto> recipients) {
|
||||
@JsonProperty("recipients") List<UserDto> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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<Event, Integer> {
|
||||
List<Event> findAllFuture();
|
||||
|
||||
List<Event> findAllByPaper(Paper paper);
|
||||
|
||||
List<Event> findAllByConference(Conference conference);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user