From f29d31b840d5b07e59b8b4d218542f3025bf45f9 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 19 Apr 2019 17:45:22 +0400 Subject: [PATCH 1/5] #41 create changelog --- .../db/changelog-20190419_000000-schema.xml | 17 +++++++++++++++++ src/main/resources/db/changelog-master.xml | 1 + 2 files changed, 18 insertions(+) create mode 100644 src/main/resources/db/changelog-20190419_000000-schema.xml diff --git a/src/main/resources/db/changelog-20190419_000000-schema.xml b/src/main/resources/db/changelog-20190419_000000-schema.xml new file mode 100644 index 0000000..b56f322 --- /dev/null +++ b/src/main/resources/db/changelog-20190419_000000-schema.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index e39b9b1..9baf3e7 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -29,4 +29,5 @@ + \ No newline at end of file From eec739a49fa0fe8ea7938c96f1a00123a51a6752 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 19 Apr 2019 17:49:36 +0400 Subject: [PATCH 2/5] #41 create simple attach of articles --- .../grant/controller/GrantController.java | 6 +++++ src/main/java/ru/ulstu/grant/model/Grant.java | 16 +++++++++++ .../java/ru/ulstu/grant/model/GrantDto.java | 27 ++++++++++++++++++- .../ru/ulstu/grant/service/GrantService.java | 20 ++++++++++++-- .../resources/templates/grants/grant.html | 13 ++++++--- 5 files changed, 76 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 0731188..7777be6 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -13,6 +13,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.service.GrantService; +import ru.ulstu.paper.model.Paper; import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; @@ -113,6 +114,11 @@ public class GrantController { return grantService.getGrantAuthors(grantDto); } + @ModelAttribute("allPapers") + public List getGrantPapers() { + return grantService.getGrantPapers(); + } + private void filterEmptyDeadlines(GrantDto grantDto) { grantDto.setDeadlines(grantDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 9b1e8fe..c8bdd8a 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -5,6 +5,7 @@ import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; +import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.Project; import ru.ulstu.user.model.User; @@ -14,6 +15,7 @@ import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -83,6 +85,12 @@ public class Grant extends BaseEntity implements UserContainer { @JoinColumn(name = "leader_id") private User leader; + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "grants_papers", + joinColumns = {@JoinColumn(name = "grant_id")}, + inverseJoinColumns = {@JoinColumn(name = "paper_id")}) + private List papers = new ArrayList<>(); + public GrantStatus getStatus() { return status; } @@ -152,6 +160,14 @@ public class Grant extends BaseEntity implements UserContainer { this.leader = leader; } + public List getPapers() { + return papers; + } + + public void setPapers(List papers) { + this.papers = papers; + } + public Optional getNextDeadline() { return deadlines .stream() diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index aa8634b..a9071a9 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.paper.model.PaperDto; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.user.model.UserDto; @@ -32,6 +33,8 @@ public class GrantDto { private boolean wasLeader; private boolean hasAge; private boolean hasDegree; + private List paperIds = new ArrayList<>(); + private List papers = new ArrayList<>(); public GrantDto() { deadlines.add(new Deadline()); @@ -49,7 +52,9 @@ public class GrantDto { @JsonProperty("leader") Integer leaderId, @JsonProperty("wasLeader") boolean wasLeader, @JsonProperty("hasAge") boolean hasAge, - @JsonProperty("hasDegree") boolean hasDegree) { + @JsonProperty("hasDegree") boolean hasDegree, + @JsonProperty("paperIds") List paperIds, + @JsonProperty("papers") List papers) { this.id = id; this.title = title; this.status = status; @@ -62,6 +67,8 @@ public class GrantDto { this.wasLeader = wasLeader; this.hasAge = hasAge; this.hasDegree = hasDegree; + this.paperIds = paperIds; + this.papers = papers; } public GrantDto(Grant grant) { @@ -78,6 +85,8 @@ public class GrantDto { this.wasLeader = false; this.hasAge = false; this.hasDegree = false; + this.paperIds = convert(grant.getPapers(), paper -> paper.getId()); + this.papers = convert(grant.getPapers(), PaperDto::new); } public Integer getId() { @@ -190,4 +199,20 @@ public class GrantDto { public void setHasDegree(boolean hasDegree) { this.hasDegree = hasDegree; } + + public List getPaperIds() { + return paperIds; + } + + public void setPaperIds(List paperIds) { + this.paperIds = paperIds; + } + + public List getPapers() { + return papers; + } + + public void setPapers(List papers) { + this.papers = papers; + } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 8427da3..1625604 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -9,6 +9,8 @@ import ru.ulstu.file.service.FileService; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.service.PaperService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; @@ -34,17 +36,20 @@ public class GrantService { private final DeadlineService deadlineService; private final FileService fileService; private final UserService userService; + private final PaperService paperService; public GrantService(GrantRepository grantRepository, FileService fileService, DeadlineService deadlineService, ProjectService projectService, - UserService userService) { + UserService userService, + PaperService paperService) { this.grantRepository = grantRepository; this.fileService = fileService; this.deadlineService = deadlineService; this.projectService = projectService; this.userService = userService; + this.paperService = paperService; } public List findAll() { @@ -86,6 +91,11 @@ public class GrantService { if (grantDto.getLeaderId() != null) { grant.setLeader(userService.findById(grantDto.getLeaderId())); } + grant.getPapers().clear(); + if (grantDto.getPaperIds() != null && !grantDto.getAuthorIds().isEmpty()) { + grantDto.getPaperIds().forEach(paperIds -> + grant.getPapers().add(paperService.findEntityById(paperIds))); + } return grant; } @@ -118,7 +128,7 @@ public class GrantService { } @Transactional - public Grant create(String title, Project projectId, Date deadlineDate, User user) { + public Grant create(String title, Project projectId, Date deadlineDate, User user, Paper paper) { Grant grant = new Grant(); grant.setTitle(title); grant.setComment("Комментарий к гранту 1"); @@ -127,6 +137,7 @@ public class GrantService { grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); grant.getAuthors().add(user); grant.setLeader(user); + grant.getPapers().add(paper); grant = grantRepository.save(grant); return grant; } @@ -156,4 +167,9 @@ public class GrantService { .map(Grant::getLeader) .collect(Collectors.toList()); } + + public List getGrantPapers() { + return paperService.findAll(); + } + } diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 86dbde1..99e9704 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -144,7 +144,7 @@
- +
From d3b8be2cf15f919f19a777474c80b3f34a220b68 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 23 Apr 2019 13:21:13 +0400 Subject: [PATCH 3/5] #107 add view of the selected papers --- .../grant/controller/GrantController.java | 19 ++++- .../java/ru/ulstu/grant/model/GrantDto.java | 12 ++-- .../ru/ulstu/grant/service/GrantService.java | 12 ++-- .../paper/repository/PaperRepository.java | 2 + .../ru/ulstu/paper/service/PaperService.java | 4 ++ .../resources/templates/grants/grant.html | 69 ++++++++++++++++--- 6 files changed, 94 insertions(+), 24 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 7777be6..1b6de6c 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -51,7 +51,9 @@ public class GrantController { @GetMapping("/grant") public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { - modelMap.put("grantDto", grantService.findOneDto(id)); + GrantDto grantDto = grantService.findOneDto(id); + attachPaper(grantDto); + modelMap.put("grantDto", grantDto); } else { modelMap.put("grantDto", new GrantDto()); } @@ -79,6 +81,17 @@ public class GrantController { return GRANT_PAGE; } + @PostMapping(value = "/grant", params = "attachPaper") + public String attachPaper(GrantDto grantDto) { + if (!grantDto.getPaperIds().isEmpty()) { + grantDto.getPapers().clear(); + grantDto.setPapers(grantService.getGrantPapers(grantDto.getPaperIds())); + } else { + grantDto.getPapers().clear(); + } + return GRANT_PAGE; + } + @PostMapping(value = "/grant", params = "addDeadline") public String addDeadline(@Valid GrantDto grantDto, Errors errors) { filterEmptyDeadlines(grantDto); @@ -115,8 +128,8 @@ public class GrantController { } @ModelAttribute("allPapers") - public List getGrantPapers() { - return grantService.getGrantPapers(); + public List getAllPapers() { + return grantService.getAllPapers(); } private void filterEmptyDeadlines(GrantDto grantDto) { diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index a9071a9..d979e23 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.user.model.UserDto; @@ -34,7 +34,7 @@ public class GrantDto { private boolean hasAge; private boolean hasDegree; private List paperIds = new ArrayList<>(); - private List papers = new ArrayList<>(); + private List papers = new ArrayList<>(); public GrantDto() { deadlines.add(new Deadline()); @@ -54,7 +54,7 @@ public class GrantDto { @JsonProperty("hasAge") boolean hasAge, @JsonProperty("hasDegree") boolean hasDegree, @JsonProperty("paperIds") List paperIds, - @JsonProperty("papers") List papers) { + @JsonProperty("papers") List papers) { this.id = id; this.title = title; this.status = status; @@ -86,7 +86,7 @@ public class GrantDto { this.hasAge = false; this.hasDegree = false; this.paperIds = convert(grant.getPapers(), paper -> paper.getId()); - this.papers = convert(grant.getPapers(), PaperDto::new); + this.papers = grant.getPapers(); } public Integer getId() { @@ -208,11 +208,11 @@ public class GrantDto { this.paperIds = paperIds; } - public List getPapers() { + public List getPapers() { return papers; } - public void setPapers(List papers) { + public void setPapers(List papers) { this.papers = papers; } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 1625604..57f9821 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -92,9 +92,8 @@ public class GrantService { grant.setLeader(userService.findById(grantDto.getLeaderId())); } grant.getPapers().clear(); - if (grantDto.getPaperIds() != null && !grantDto.getAuthorIds().isEmpty()) { - grantDto.getPaperIds().forEach(paperIds -> - grant.getPapers().add(paperService.findEntityById(paperIds))); + if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) { + grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findEntityById(paperIds))); } return grant; } @@ -168,7 +167,12 @@ public class GrantService { .collect(Collectors.toList()); } - public List getGrantPapers() { + public List getGrantPapers(List paperIds) { + return paperService.findAllSelect(paperIds); + + } + + public List getAllPapers() { return paperService.findAll(); } diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index 343e9e2..cab9b1a 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -14,4 +14,6 @@ public interface PaperRepository extends JpaRepository { List filter(@Param("author") User author, @Param("year") Integer year); List findByIdNotIn(List paperIds); + + List findAllByIdIn(List paperIds); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index a10d941..a484a63 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -229,6 +229,10 @@ public class PaperService { } + public List findAllSelect(List paperIds) { + return sortPapers(paperRepository.findAllByIdIn(paperIds)); + } + public List getPaperAuthors() { return userService.findAll(); } diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 99e9704..6a2beb8 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -146,7 +146,7 @@ - - - +
+
+ +
+ + +
+
+ +
+
+ +
+ + + Статус статьи + +
+
+
+
@@ -219,6 +250,22 @@ $("#authors [value='" + lid + "']").attr("disabled", "disabled"); } + +
From 546b0dc323c9686a81d3b6a45fadd44b19955f3d Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 23 Apr 2019 14:51:51 +0400 Subject: [PATCH 4/5] #107 add styles --- src/main/resources/public/css/grant.css | 15 +++++++++++++++ src/main/resources/templates/grants/grant.html | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/resources/public/css/grant.css b/src/main/resources/public/css/grant.css index 2c95628..2176acf 100644 --- a/src/main/resources/public/css/grant.css +++ b/src/main/resources/public/css/grant.css @@ -9,4 +9,19 @@ .div-deadline-description{ padding-left: 5px; padding-right: 5px; +} + +.div-view-paper { + margin-top: 6px; +} + +.div-selected-papers { + border: 0px; + padding-left: 12px; +} + +.icon-paper { + height: 22px; + width: 22px; + margin: 3px; } \ No newline at end of file diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 6a2beb8..322fbc9 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -165,7 +165,7 @@
-
+
-
+
+ Название статьи From 26969dba5b6830593bd039b0c28d03d70d89998d Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 23 Apr 2019 15:02:41 +0400 Subject: [PATCH 5/5] #107 merge with dev --- .../java/ru/ulstu/project/controller/ProjectController.java | 2 -- .../templates/papers/fragments/paperFilesListFragment.html | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 1d0272d..affdaec 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.grant.model.GrantDto; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; @@ -21,7 +20,6 @@ import java.util.List; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; -import static ru.ulstu.core.controller.Navigation.hasErrors; @Controller() @RequestMapping(value = "/projects") diff --git a/src/main/resources/templates/papers/fragments/paperFilesListFragment.html b/src/main/resources/templates/papers/fragments/paperFilesListFragment.html index 5934c59..b4de456 100644 --- a/src/main/resources/templates/papers/fragments/paperFilesListFragment.html +++ b/src/main/resources/templates/papers/fragments/paperFilesListFragment.html @@ -8,7 +8,8 @@
- +