From 7388e12e3f5d50ab6278f99e96ff0d49046b9ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 27 May 2019 18:19:31 +0300 Subject: [PATCH] #98 edited project executors --- .../project/controller/ProjectController.java | 6 +++++ .../java/ru/ulstu/project/model/Project.java | 9 ++++++- .../ru/ulstu/project/model/ProjectDto.java | 24 ++++++++++++++++++- .../ulstu/project/service/ProjectService.java | 13 +++++++++- .../resources/templates/projects/project.html | 9 +++++-- 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 14b8736..88f0c7a 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -13,6 +13,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; +import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; @@ -92,6 +93,11 @@ public class ProjectController { return String.format("redirect:%s", "/projects/projects"); } + @ModelAttribute("allExecutors") + public List getAllExecutors(ProjectDto projectDto) { + return projectService.getProjectExecutors(projectDto); + } + private void filterEmptyDeadlines(ProjectDto projectDto) { projectDto.setDeadlines(projectDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index acf0d0f..f061221 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -2,6 +2,7 @@ package ru.ulstu.project.model; import org.hibernate.validator.constraints.NotBlank; 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.grant.model.Grant; @@ -23,7 +24,8 @@ import java.util.List; import java.util.Set; @Entity -public class Project extends BaseEntity { +public class Project extends BaseEntity implements UserContainer { + public enum ProjectStatus { APPLICATION("Заявка"), ON_COMPETITION("Отправлен на конкурс"), @@ -133,4 +135,9 @@ public class Project extends BaseEntity { public void setExecutors(Set executors) { this.executors = executors; } + + @Override + public Set getUsers() { + return getExecutors(); + } } diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index 0f86e1a..0292f1f 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -29,6 +29,8 @@ public class ProjectDto { private List removedDeadlineIds = new ArrayList<>(); private Set executorIds; private Set executors; + private boolean hasAge; + private boolean hasDegree; private final static int MAX_EXECUTORS_LENGTH = 40; @@ -48,7 +50,9 @@ public class ProjectDto { @JsonProperty("repository") String repository, @JsonProperty("deadlines") List deadlines, @JsonProperty("executorIds") Set executorIds, - @JsonProperty("executors") Set executors) { + @JsonProperty("executors") Set executors, + @JsonProperty("hasAge") boolean hasAge, + @JsonProperty("hasDegree") boolean hasDegree) { this.id = id; this.title = title; this.status = status; @@ -59,6 +63,8 @@ public class ProjectDto { this.applicationFileName = null; this.executorIds = executorIds; this.executors = executors; + this.hasAge = hasAge; + this.hasDegree = hasDegree; } @@ -163,6 +169,22 @@ public class ProjectDto { this.executors = executors; } + public boolean isHasAge() { + return hasAge; + } + + public void setHasAge(boolean hasAge) { + this.hasAge = hasAge; + } + + public boolean isHasDegree() { + return hasDegree; + } + + public void setHasDegree(boolean hasDegree) { + this.hasDegree = hasDegree; + } + public String getExecutorsString() { return StringUtils.abbreviate(executors .stream() diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 4a79e6c..2f6473b 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -5,10 +5,13 @@ import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; +import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.repository.ProjectRepository; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Arrays; @@ -26,15 +29,18 @@ public class ProjectService { private final DeadlineService deadlineService; private final GrantRepository grantRepository; private final FileService fileService; + private final UserService userService; public ProjectService(ProjectRepository projectRepository, DeadlineService deadlineService, GrantRepository grantRepository, - FileService fileService) { + FileService fileService, + UserService userService) { this.projectRepository = projectRepository; this.deadlineService = deadlineService; this.grantRepository = grantRepository; this.fileService = fileService; + this.userService = userService; } public List findAll() { @@ -115,4 +121,9 @@ public class ProjectService { return projectRepository.findOne(id); } + public List getProjectExecutors(ProjectDto projectDto) { + List filteredUsers = userService.filterByAgeAndDegree(projectDto.isHasAge(), projectDto.isHasDegree()); + return filteredUsers; + } + } diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index 8385694..304fed0 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -92,8 +92,13 @@
- +