From e3bbade40bb1552277e19130a526df5c9ad68cdc Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 4 Apr 2019 17:39:28 +0400 Subject: [PATCH] #55 added ConferenceDto --- .../ru/ulstu/conference/model/Conference.java | 10 +- .../ulstu/conference/model/ConferenceDto.java | 185 ++++++++++++++++++ 2 files changed, 194 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 10cc709..8cb1c64 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -13,6 +13,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import javax.persistence.OrderBy; @@ -42,7 +43,7 @@ public class Conference extends BaseEntity { @Temporal(TemporalType.TIMESTAMP) private Date beginDate = new Date(); - @Column(name = "end_date") + @Temporal(TemporalType.TIMESTAMP) private Date endDate = new Date(); @@ -52,10 +53,17 @@ public class Conference extends BaseEntity { @OrderBy("date") private List deadlines = new ArrayList<>(); + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "paper_conference", + joinColumns = {@JoinColumn(name = "conference_id")}, + inverseJoinColumns = {@JoinColumn(name = "paper_id")}) private Set papers = new HashSet<>(); @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "users_conference", + joinColumns = {@JoinColumn(name = "conference_id")}, + inverseJoinColumns = {@JoinColumn(name = "users_id")}) private Set users = new HashSet<>(); public String getTitle() { diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index e3f757e..d5c586f 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -1,4 +1,189 @@ package ru.ulstu.conference.model; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.hibernate.validator.constraints.NotEmpty; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.user.model.UserDto; + +import javax.validation.constraints.Size; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import static ru.ulstu.core.util.StreamApiUtils.convert; + public class ConferenceDto { + + private Integer id; + @NotEmpty + @Size(min = 2, max = 400) + private String title; + @Size(max = 500) + private String description; + @Size(max = 255) + private String url; + private int ping; + private Date beginDate; + private Date endDate; + @NotEmpty + private List deadlines = new ArrayList<>(); + private Set userIds; + private Set paperIds; + private Set papers; + private Set users; + private Integer filterUserId; + + public ConferenceDto() { + deadlines.add(new Deadline()); + } + + @JsonCreator + public ConferenceDto(@JsonProperty("id") Integer id, + @JsonProperty("title") String title, + @JsonProperty("description") String description, + @JsonProperty("url") String url, + @JsonProperty("ping") Integer ping, + @JsonProperty("beginDate") Date beginDate, + @JsonProperty("endDate") Date endDate, + @JsonProperty("deadlines") List deadlines, + @JsonProperty("userIds") Set userIds, + @JsonProperty("paperIds") Set paperIds, + @JsonProperty("users") Set users, + @JsonProperty("papers") Set papers) { + this.id = id; + this.title = title; + this.description = description; + this.url = url; + this.ping = ping; + this.beginDate = beginDate; + this.endDate = endDate; + this.deadlines = deadlines; + this.userIds = userIds; + this.paperIds = paperIds; + this.users = users; + this.papers = papers; + } + + public ConferenceDto(Conference conference) { + this.id = conference.getId(); + this.title = conference.getTitle(); + this.description = conference.getDescription(); + this.url = conference.getUrl(); + this.ping = conference.getPing(); + this.beginDate = conference.getBeginDate(); + this.endDate = conference.getEndDate(); + this.deadlines = conference.getDeadlines(); + this.userIds = convert(conference.getUsers(), user -> user.getId()); + this.paperIds = convert(conference.getPapers(), paper -> paper.getId()); + this.users = convert(conference.getUsers(), UserDto::new); + this.papers = convert(conference.getPapers(), PaperDto::new); + + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getPing() { + return ping; + } + + public void setPing(int ping) { + this.ping = ping; + } + + public Date getBeginDate() { + return beginDate; + } + + public void setBeginDate(Date beginDate) { + this.beginDate = beginDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public List getDeadlines() { + return deadlines; + } + + public void setDeadlines(List deadlines) { + this.deadlines = deadlines; + } + + public Set getUserIds() { + return userIds; + } + + public void setUserIds(Set userIds) { + this.userIds = userIds; + } + + public Set getPaperIds() { + return paperIds; + } + + public void setPaperIds(Set paperIds) { + this.paperIds = paperIds; + } + + public Set getPapers() { + return papers; + } + + public void setPapers(Set papers) { + this.papers = papers; + } + + public Set getUsers() { + return users; + } + + public void setUsers(Set users) { + this.users = users; + } + + public Integer getFilterUserId() { + return filterUserId; + } + + public void setFilterUserId(Integer filterUserId) { + this.filterUserId = filterUserId; + } }