add paper authors

This commit is contained in:
Anton Romanov 2018-05-05 14:49:34 +04:00
parent e465651eb2
commit 2fda487555
3 changed files with 38 additions and 1 deletions

View File

@ -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<User> 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<User> getAuthors() {
return authors;
}
public void setAuthors(List<User> authors) {
this.authors = authors;
}
}

View File

@ -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<UserDto> 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<UserDto> 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<UserDto> getAuthors() {
return authors;
}
}

View File

@ -34,4 +34,16 @@
constraintName="fk_paper_file" referencedTableName="file"
referencedColumnNames="id"/>
</changeSet>
<changeSet author="orion" id="20180505_000000-2">
<createTable tableName="paper_authors">
<column name="paper_id" type="integer"/>
<column name="authors_id" type="integer"/>
</createTable>
<addForeignKeyConstraint baseTableName="paper_authors" baseColumnNames="paper_id"
constraintName="fk_paper_paper_authors" referencedTableName="paper"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="paper_authors" baseColumnNames="authors_id"
constraintName="fk_user_paper_authors" referencedTableName="users"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>