From 35a08ab451f593f809d4bb1b68dfb7d6a5cc3fe6 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 5 Dec 2018 18:08:47 +0400 Subject: [PATCH] save authors --- build.gradle | 1 + .../paper/controller/PaperController.java | 6 ++++ .../java/ru/ulstu/paper/model/PaperDto.java | 15 +++------ .../ru/ulstu/paper/service/PaperService.java | 8 ++++- src/main/resources/templates/default.html | 2 ++ .../resources/templates/papers/paper.html | 31 ++++++++++++++----- 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/build.gradle b/build.gradle index d09505e..4e0e9cb 100644 --- a/build.gradle +++ b/build.gradle @@ -116,6 +116,7 @@ dependencies { compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7' compile group: 'org.webjars', name: 'bootstrap', version: '4.1.0' + compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.3' compile group: 'org.webjars', name: 'jquery', version: '3.3.1-1' compile group: 'org.webjars.npm', name: 'jquery.easing', version: '1.4.1' compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0' diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 41d8fbc..01f337d 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -15,6 +15,7 @@ import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperFilterDto; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.user.model.User; import javax.validation.Valid; import java.io.IOException; @@ -64,6 +65,11 @@ public class PaperController { return paperService.getPaperStatuses(); } + @ModelAttribute("allAuthors") + public List getAllAuthors() { + return paperService.getPaperAuthors(); + } + @PostMapping("/filter") public Response> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { return new Response<>(paperService.filter(paperFilterDto)); diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 7ea239d..e611ab9 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -30,7 +30,7 @@ public class PaperDto { private Integer fileId; private String fileName; private Date fileCreateDate; - private Set authors; + private Set authors; public PaperDto() { } @@ -48,7 +48,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); + this.authors = convert(paper.getAuthors(), user -> user.getId()); } public Integer getId() { @@ -99,7 +99,7 @@ public class PaperDto { return fileCreateDate; } - public Set getAuthors() { + public Set getAuthors() { return authors; } @@ -151,14 +151,7 @@ public class PaperDto { this.fileCreateDate = fileCreateDate; } - public void setAuthors(Set authors) { + public void setAuthors(Set authors) { this.authors = authors; } - - public String getAuthorsString() { - return authors - .stream() - .map(author -> author.getLastName() + author.getFirstName()) - .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 1eb4d2a..aa7a94a 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -80,7 +80,9 @@ public class PaperService { paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName())); } if (paperDto.getAuthors() != null && !paperDto.getAuthors().isEmpty()) { - paperDto.getAuthors().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds.getId()))); + paperDto.getAuthors().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds))); + } else { + paper.getAuthors().clear(); } return paper; } @@ -162,4 +164,8 @@ public class PaperService { public PaperDto findById(Integer paperId) { return new PaperDto(paperRepository.findOne(paperId)); } + + public List getPaperAuthors() { + return userService.findAll(); + } } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index a571cb7..5bb5c14 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -12,6 +12,7 @@ + @@ -25,6 +26,7 @@ + diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 224a9b5..318dcb7 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -82,17 +82,26 @@ text -

Редактировать - авторов - статьи

+
+ + +

Incorrect title

+