add paper authors

pull/128/head
Anton Romanov 6 years ago
parent e465651eb2
commit 2fda487555

@ -3,9 +3,11 @@ package ru.ulstu.paper.model;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileData;
import ru.ulstu.user.model.User;
import javax.persistence.*; import javax.persistence.*;
import java.util.Date; import java.util.Date;
import java.util.List;
@Entity @Entity
public class Paper extends BaseEntity { public class Paper extends BaseEntity {
@ -43,6 +45,9 @@ public class Paper extends BaseEntity {
@JoinColumn(name = "file_id") @JoinColumn(name = "file_id")
private FileData fileData; private FileData fileData;
@ManyToMany
private List<User> authors;
public PaperStatus getStatus() { public PaperStatus getStatus() {
return status; return status;
} }
@ -98,4 +103,12 @@ public class Paper extends BaseEntity {
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }
public List<User> getAuthors() {
return authors;
}
public void setAuthors(List<User> authors) {
this.authors = authors;
}
} }

@ -2,8 +2,12 @@ package ru.ulstu.paper.model;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import ru.ulstu.user.model.UserDto;
import java.util.Date; import java.util.Date;
import java.util.List;
import static ru.ulstu.core.util.StreamApiUtils.convert;
public class PaperDto { public class PaperDto {
private final Integer id; private final Integer id;
@ -17,6 +21,7 @@ public class PaperDto {
private final Integer fileId; private final Integer fileId;
private final String fileName; private final String fileName;
private final Date fileCreateDate; private final Date fileCreateDate;
private final List<UserDto> authors;
@JsonCreator @JsonCreator
public PaperDto(@JsonProperty("id") Integer id, public PaperDto(@JsonProperty("id") Integer id,
@ -26,7 +31,8 @@ public class PaperDto {
@JsonProperty("updateDate") Date updateDate, @JsonProperty("updateDate") Date updateDate,
@JsonProperty("comment") String comment, @JsonProperty("comment") String comment,
@JsonProperty("locked") Boolean locked, @JsonProperty("locked") Boolean locked,
@JsonProperty("tmpFileName") String tmpFileName) { @JsonProperty("tmpFileName") String tmpFileName,
@JsonProperty("authors") List<UserDto> authors) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.status = status; this.status = status;
@ -38,6 +44,7 @@ public class PaperDto {
this.fileId = null; this.fileId = null;
this.fileName = null; this.fileName = null;
this.fileCreateDate = null; this.fileCreateDate = null;
this.authors = authors;
} }
public PaperDto(Paper paper) { public PaperDto(Paper paper) {
@ -52,6 +59,7 @@ public class PaperDto {
this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId(); this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId();
this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName(); this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName();
this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate(); this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate();
this.authors = convert(paper.getAuthors(), UserDto::new);
} }
public Integer getId() { public Integer getId() {
@ -97,4 +105,8 @@ public class PaperDto {
public Date getFileCreateDate() { public Date getFileCreateDate() {
return fileCreateDate; return fileCreateDate;
} }
public List<UserDto> getAuthors() {
return authors;
}
} }

@ -34,4 +34,16 @@
constraintName="fk_paper_file" referencedTableName="file" constraintName="fk_paper_file" referencedTableName="file"
referencedColumnNames="id"/> referencedColumnNames="id"/>
</changeSet> </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> </databaseChangeLog>

Loading…
Cancel
Save