From 2fda4875553e61161a63849477590cbc305a56f2 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 5 May 2018 14:49:34 +0400 Subject: [PATCH] add paper authors --- src/main/java/ru/ulstu/paper/model/Paper.java | 13 +++++++++++++ src/main/java/ru/ulstu/paper/model/PaperDto.java | 14 +++++++++++++- .../db/changelog-20180505_000000-schema.xml | 12 ++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 7be132f..ac65f50 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -3,9 +3,11 @@ package ru.ulstu.paper.model; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.file.model.FileData; +import ru.ulstu.user.model.User; import javax.persistence.*; import java.util.Date; +import java.util.List; @Entity public class Paper extends BaseEntity { @@ -43,6 +45,9 @@ public class Paper extends BaseEntity { @JoinColumn(name = "file_id") private FileData fileData; + @ManyToMany + private List authors; + public PaperStatus getStatus() { return status; } @@ -98,4 +103,12 @@ public class Paper extends BaseEntity { public void setTitle(String title) { this.title = title; } + + public List getAuthors() { + return authors; + } + + public void setAuthors(List authors) { + this.authors = authors; + } } diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index c9929e6..d7fb8f2 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -2,8 +2,12 @@ package ru.ulstu.paper.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import ru.ulstu.user.model.UserDto; import java.util.Date; +import java.util.List; + +import static ru.ulstu.core.util.StreamApiUtils.convert; public class PaperDto { private final Integer id; @@ -17,6 +21,7 @@ public class PaperDto { private final Integer fileId; private final String fileName; private final Date fileCreateDate; + private final List authors; @JsonCreator public PaperDto(@JsonProperty("id") Integer id, @@ -26,7 +31,8 @@ public class PaperDto { @JsonProperty("updateDate") Date updateDate, @JsonProperty("comment") String comment, @JsonProperty("locked") Boolean locked, - @JsonProperty("tmpFileName") String tmpFileName) { + @JsonProperty("tmpFileName") String tmpFileName, + @JsonProperty("authors") List authors) { this.id = id; this.title = title; this.status = status; @@ -38,6 +44,7 @@ public class PaperDto { this.fileId = null; this.fileName = null; this.fileCreateDate = null; + this.authors = authors; } public PaperDto(Paper paper) { @@ -52,6 +59,7 @@ public class PaperDto { this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId(); this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName(); this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate(); + this.authors = convert(paper.getAuthors(), UserDto::new); } public Integer getId() { @@ -97,4 +105,8 @@ public class PaperDto { public Date getFileCreateDate() { return fileCreateDate; } + + public List getAuthors() { + return authors; + } } diff --git a/src/main/resources/db/changelog-20180505_000000-schema.xml b/src/main/resources/db/changelog-20180505_000000-schema.xml index b66721f..8f5240d 100644 --- a/src/main/resources/db/changelog-20180505_000000-schema.xml +++ b/src/main/resources/db/changelog-20180505_000000-schema.xml @@ -34,4 +34,16 @@ constraintName="fk_paper_file" referencedTableName="file" referencedColumnNames="id"/> + + + + + + + +