From dc5abe1508da5cc72a235eac1e1ee525d95cf0c1 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 18 Dec 2018 19:23:15 +0400 Subject: [PATCH] show authors --- .../paper/controller/PaperController.java | 5 + .../java/ru/ulstu/paper/model/PaperDto.java | 128 ++++++++++-------- .../ru/ulstu/paper/service/PaperService.java | 4 +- .../resources/templates/papers/dashboard.html | 5 +- .../fragments/paperDashboardFragment.html | 43 ++++++ .../papers/fragments/paperLineFragment.html | 5 +- .../resources/templates/papers/paper.html | 6 +- 7 files changed, 134 insertions(+), 62 deletions(-) create mode 100644 src/main/resources/templates/papers/fragments/paperDashboardFragment.html diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 7042e1f..01e5b85 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -37,6 +37,11 @@ public class PaperController { modelMap.put("papers", paperService.findAllDto()); } + @GetMapping("/dashboard") + public void getDashboard(ModelMap modelMap) { + modelMap.put("papers", paperService.findAllDto()); + } + @GetMapping("/paper") public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 9064b5a..de3c8df 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -4,12 +4,14 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.DeadlineDto; +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 java.util.stream.Collectors; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -29,7 +31,8 @@ public class PaperDto { private Integer fileId; private String fileName; private Date fileCreateDate; - private Set authors; + private Set authorIds; + private Set authors; public PaperDto() { deadlines.add(new DeadlineDto()); @@ -45,7 +48,8 @@ public class PaperDto { @JsonProperty("comment") String comment, @JsonProperty("locked") Boolean locked, @JsonProperty("tmpFileName") String tmpFileName, - @JsonProperty("authors") Set authors) { + @JsonProperty("authorIds") Set authorIds, + @JsonProperty("authors") Set authors) { this.id = id; this.title = title; this.status = status; @@ -74,110 +78,126 @@ 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(), user -> user.getId()); + this.authorIds = convert(paper.getAuthors(), user -> user.getId()); + this.authors = convert(paper.getAuthors(), UserDto::new); } public Integer getId() { return id; } - public String getTitle() { - return title; - } - - public Paper.PaperStatus getStatus() { - return status; - } - - public Date getCreateDate() { - return createDate; - } - - public Date getUpdateDate() { - return updateDate; - } - - public List getDeadlines() { - return deadlines; - } - - public String getComment() { - return comment; - } - - public Boolean getLocked() { - return locked; - } - - public String getTmpFileName() { - return tmpFileName; - } - - public Integer getFileId() { - return fileId; - } - - public String getFileName() { - return fileName; - } - - public Date getFileCreateDate() { - return fileCreateDate; - } - - public Set getAuthors() { - return authors; - } - public void setId(Integer id) { this.id = id; } + public String getTitle() { + return title; + } + public void setTitle(String title) { this.title = title; } + public Paper.PaperStatus getStatus() { + return status; + } + public void setStatus(Paper.PaperStatus status) { this.status = status; } + public Date getCreateDate() { + return createDate; + } + public void setCreateDate(Date createDate) { this.createDate = createDate; } + public Date getUpdateDate() { + return updateDate; + } + public void setUpdateDate(Date updateDate) { this.updateDate = updateDate; } + public List getDeadlines() { + return deadlines; + } + + public void setDeadlines(List deadlines) { + this.deadlines = deadlines; + } + + public String getComment() { + return comment; + } + public void setComment(String comment) { this.comment = comment; } + public Boolean getLocked() { + return locked; + } + public void setLocked(Boolean locked) { this.locked = locked; } + public String getTmpFileName() { + return tmpFileName; + } + public void setTmpFileName(String tmpFileName) { this.tmpFileName = tmpFileName; } + public Integer getFileId() { + return fileId; + } + public void setFileId(Integer fileId) { this.fileId = fileId; } + public String getFileName() { + return fileName; + } + public void setFileName(String fileName) { this.fileName = fileName; } + public Date getFileCreateDate() { + return fileCreateDate; + } + public void setFileCreateDate(Date fileCreateDate) { this.fileCreateDate = fileCreateDate; } - public void setAuthors(Set authors) { + public Set getAuthors() { + return authors; + } + + public void setAuthors(Set authors) { this.authors = authors; } - public void setDeadlines(List deadlines) { - this.deadlines = deadlines; + public Set getAuthorIds() { + return authorIds; + } + + public void setAuthorIds(Set authorIds) { + this.authorIds = authorIds; + } + + public String getAuthorsString() { + return authors + .stream() + .map(author -> author.getLastName()) + .collect(Collectors.joining(", ")); } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index b7cd9a3..0553047 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -83,8 +83,8 @@ public class PaperService { if (paperDto.getTmpFileName() != null) { paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName())); } - if (paperDto.getAuthors() != null && !paperDto.getAuthors().isEmpty()) { - paperDto.getAuthors().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds))); + if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) { + paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds))); } else { paper.getAuthors().clear(); } diff --git a/src/main/resources/templates/papers/dashboard.html b/src/main/resources/templates/papers/dashboard.html index 5f6f524..45457d5 100644 --- a/src/main/resources/templates/papers/dashboard.html +++ b/src/main/resources/templates/papers/dashboard.html @@ -13,10 +13,11 @@

Статьи

-
- + +
+
diff --git a/src/main/resources/templates/papers/fragments/paperDashboardFragment.html b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html new file mode 100644 index 0000000..edbcd30 --- /dev/null +++ b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html @@ -0,0 +1,43 @@ + + + + + + +
+
+
+ + +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ title +

authors

+
+
+
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/papers/fragments/paperLineFragment.html b/src/main/resources/templates/papers/fragments/paperLineFragment.html index b71c1b3..bb66aab 100644 --- a/src/main/resources/templates/papers/fragments/paperLineFragment.html +++ b/src/main/resources/templates/papers/fragments/paperLineFragment.html @@ -29,7 +29,10 @@ - + + + + diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index a3345c1..0b6957e 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -101,12 +101,12 @@ -

Incorrect title