From 8a7117d713e4d547d6b6e4e706def91f9a220b32 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 4 Apr 2019 09:38:18 +0400 Subject: [PATCH 01/15] #42 Add leader and authors --- .../grant/controller/GrantController.java | 10 +++ src/main/java/ru/ulstu/grant/model/Grant.java | 39 ++++++++- .../java/ru/ulstu/grant/model/GrantDto.java | 52 +++++++++++- .../ru/ulstu/grant/service/GrantService.java | 26 ++++-- .../db/changelog-20190402_000000-schema.xml | 26 ++++++ src/main/resources/public/css/grant.css | 12 +++ .../grants/fragments/grantLineFragment.html | 2 +- .../grants/fragments/grantStatusFragment.html | 2 +- .../resources/templates/grants/grant.html | 81 +++++++++++++++++-- 9 files changed, 233 insertions(+), 17 deletions(-) create mode 100644 src/main/resources/db/changelog-20190402_000000-schema.xml create mode 100644 src/main/resources/public/css/grant.css diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index c786ffa..8481c07 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.user.model.User; import javax.validation.Valid; import java.io.IOException; @@ -57,9 +58,13 @@ public class GrantController { @PostMapping(value = "/grant", params = "save") public String save(@Valid GrantDto grantDto, Errors errors) throws IOException { filterEmptyDeadlines(grantDto); + // фильтр авторов if (grantDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } +// if (grantDto.getLeader().getId().equals(null)) { +// errors.rejectValue("leader", "errorCode", "Укажите руководителя"); +// } hasErrors(errors, GRANT_PAGE); grantService.save(grantDto); return String.format(REDIRECT_TO, GRANTS_PAGE); @@ -91,6 +96,11 @@ public class GrantController { return grantService.getGrantStatuses(); } + @ModelAttribute("allAuthors") + public List getAllAuthors() { + return grantService.getGrantAuthors(); + } + 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 685a1d5..9b1e8fe 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -2,28 +2,35 @@ package ru.ulstu.grant.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.project.model.Project; +import ru.ulstu.user.model.User; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.OrderBy; import javax.persistence.Table; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Comparator; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; @Entity @Table(name = "grants") -public class Grant extends BaseEntity { +public class Grant extends BaseEntity implements UserContainer { public enum GrantStatus { APPLICATION("Заявка"), ON_COMPETITION("Отправлен на конкурс"), @@ -52,6 +59,7 @@ public class Grant extends BaseEntity { @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "grant_id") + @OrderBy("date") private List deadlines = new ArrayList<>(); //Описание гранта @@ -67,6 +75,14 @@ public class Grant extends BaseEntity { @JoinColumn(name = "project_id") private Project project; + @ManyToMany(fetch = FetchType.EAGER) + private Set authors = new HashSet<>(); + + @NotNull + @ManyToOne + @JoinColumn(name = "leader_id") + private User leader; + public GrantStatus getStatus() { return status; } @@ -115,6 +131,27 @@ public class Grant extends BaseEntity { this.project = project; } + public Set getAuthors() { + return authors; + } + + public void setAuthors(Set authors) { + this.authors = authors; + } + + @Override + public Set getUsers() { + return getAuthors(); + } + + public User getLeader() { + return leader; + } + + public void setLeader(User leader) { + this.leader = leader; + } + 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 fb29164..cc0f2da 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -2,14 +2,22 @@ package ru.ulstu.grant.model; import com.fasterxml.jackson.annotation.JsonCreator; 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.project.model.ProjectDto; +import ru.ulstu.user.model.UserDto; import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static ru.ulstu.core.util.StreamApiUtils.convert; public class GrantDto { + private final static int MAX_AUTHORS_LENGTH = 60; + private Integer id; @NotEmpty private String title; @@ -18,6 +26,9 @@ public class GrantDto { private String comment; private String applicationFileName; private ProjectDto project; + private Set authorIds; + private Set authors; + private Integer leaderId; public GrantDto() { deadlines.add(new Deadline()); @@ -29,7 +40,10 @@ public class GrantDto { @JsonProperty("status") Grant.GrantStatus status, @JsonProperty("deadlines") List deadlines, @JsonProperty("comment") String comment, - @JsonProperty("project") ProjectDto project) { + @JsonProperty("project") ProjectDto project, + @JsonProperty("authorIds") Set authorIds, + @JsonProperty("authors") Set authors, + @JsonProperty("leader") Integer leaderId) { this.id = id; this.title = title; this.status = status; @@ -37,6 +51,8 @@ public class GrantDto { this.comment = comment; this.applicationFileName = null; this.project = project; + this.authors = authors; + this.leaderId = leaderId; } public GrantDto(Grant grant) { @@ -47,6 +63,9 @@ public class GrantDto { this.comment = grant.getComment(); this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject()); this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName(); + this.authorIds = convert(grant.getAuthors(), user -> user.getId()); + this.authors = convert(grant.getAuthors(), UserDto::new); + this.leaderId = grant.getLeader().getId(); } public Integer getId() { @@ -104,4 +123,35 @@ public class GrantDto { public void setApplicationFileName(String applicationFileName) { this.applicationFileName = applicationFileName; } + + public Set getAuthorIds() { + return authorIds; + } + + public void setAuthorIds(Set authorIds) { + this.authorIds = authorIds; + } + + public Set getAuthors() { + return authors; + } + + public void setAuthors(Set authors) { + this.authors = authors; + } + + public String getAuthorsString() { + return StringUtils.abbreviate(authors + .stream() + .map(author -> author.getLastName()) + .collect(Collectors.joining(", ")), MAX_AUTHORS_LENGTH); + } + + public Integer getLeaderId() { + return leaderId; + } + + public void setLeaderId(Integer leaderId) { + this.leaderId = leaderId; + } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index d5beec3..cbf37ce 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -12,6 +12,8 @@ import ru.ulstu.grant.repository.GrantRepository; 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 ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Arrays; @@ -30,15 +32,18 @@ public class GrantService { private final ProjectService projectService; private final DeadlineService deadlineService; private final FileService fileService; + private final UserService userService; public GrantService(GrantRepository grantRepository, FileService fileService, DeadlineService deadlineService, - ProjectService projectService) { + ProjectService projectService, + UserService userService) { this.grantRepository = grantRepository; - this.projectService = projectService; this.fileService = fileService; this.deadlineService = deadlineService; + this.projectService = projectService; + this.userService = userService; } public List findAll() { @@ -73,6 +78,13 @@ public class GrantService { if (grantDto.getApplicationFileName() != null) { grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName())); } + grant.getAuthors().clear(); + if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) { + grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds))); + } + if (grantDto.getLeaderId() != null) { + grant.setLeader(userService.findById(grantDto.getLeaderId())); + } return grant; } @@ -84,7 +96,6 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { Grant grant = grantRepository.findOne(grantDto.getId()); - Grant.GrantStatus oldStatus = grant.getStatus(); if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) { fileService.deleteFile(grant.getApplication()); } @@ -98,7 +109,6 @@ public class GrantService { if (grant.getApplication() != null) { fileService.deleteFile(grant.getApplication()); } - //возможно при удалении гранта будет удаляться и проект, к нему привязанный grantRepository.delete(grant); } @@ -107,13 +117,15 @@ public class GrantService { } @Transactional - public Grant create(String title, Project projectId, Date deadlineDate) { + public Grant create(String title, Project projectId, Date deadlineDate, User user) { Grant grant = new Grant(); grant.setTitle(title); grant.setComment("Комментарий к гранту 1"); grant.setProject(projectId); grant.setStatus(APPLICATION); grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); + grant.getAuthors().add(user); + grant.setLeader(user); grant = grantRepository.save(grant); return grant; } @@ -125,4 +137,8 @@ public class GrantService { update(grantDto); } } + + public List getGrantAuthors() { + return userService.findAll(); + } } diff --git a/src/main/resources/db/changelog-20190402_000000-schema.xml b/src/main/resources/db/changelog-20190402_000000-schema.xml new file mode 100644 index 0000000..70a7991 --- /dev/null +++ b/src/main/resources/db/changelog-20190402_000000-schema.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/public/css/grant.css b/src/main/resources/public/css/grant.css new file mode 100644 index 0000000..2c95628 --- /dev/null +++ b/src/main/resources/public/css/grant.css @@ -0,0 +1,12 @@ +.div-deadline-date { + padding-right: 0px; +} + +.form-deadline-date{ + padding-right: 3px; +} + +.div-deadline-description{ + padding-left: 5px; + padding-right: 5px; +} \ No newline at end of file diff --git a/src/main/resources/templates/grants/fragments/grantLineFragment.html b/src/main/resources/templates/grants/fragments/grantLineFragment.html index 1048897..dda0e8d 100644 --- a/src/main/resources/templates/grants/fragments/grantLineFragment.html +++ b/src/main/resources/templates/grants/fragments/grantLineFragment.html @@ -9,7 +9,7 @@ - + - +
diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index fc2878d..aae3b02 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -3,7 +3,7 @@ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> - + @@ -17,6 +17,7 @@
+
+
+
-
- +
-
+
@@ -72,8 +75,8 @@ class="alert alert-danger">Incorrect title

- +
@@ -82,15 +85,77 @@
+
+ +
+ +
+
+
+ + +
+
+ + +
+
+
+
+ +
+
+
+ + +
+
+
+
+ +
+
+
+ + +
+
+
+
+
+ + +
+
+ + +

Incorrect member

+
diff --git a/src/main/resources/templates/students/task.html b/src/main/resources/templates/students/task.html index 533c8f6..22b27e6 100644 --- a/src/main/resources/templates/students/task.html +++ b/src/main/resources/templates/students/task.html @@ -1,9 +1,10 @@ + layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> - + @@ -44,12 +45,13 @@
- +
- +
@@ -64,16 +66,18 @@
-
-
+
-
diff --git a/src/main/resources/templates/students/tasks.html b/src/main/resources/templates/students/tasks.html index 076f7ba..acb726c 100644 --- a/src/main/resources/templates/students/tasks.html +++ b/src/main/resources/templates/students/tasks.html @@ -27,30 +27,30 @@
Фильтр:
- + -
From 7465803162b6ecad6771c5ef60122f9c4abedb07 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 5 Apr 2019 22:06:16 +0400 Subject: [PATCH 03/15] #42 add columns 'birth_date'&'degree' to User --- src/main/java/ru/ulstu/user/model/User.java | 40 +++++++++++++++++++ .../java/ru/ulstu/user/model/UserDto.java | 27 +++++++++++++ .../db/changelog-20190404_000000-schema.xml | 13 ++++++ 3 files changed, 80 insertions(+) create mode 100644 src/main/resources/db/changelog-20190404_000000-schema.xml diff --git a/src/main/java/ru/ulstu/user/model/User.java b/src/main/java/ru/ulstu/user/model/User.java index de9f028..40f1f45 100644 --- a/src/main/java/ru/ulstu/user/model/User.java +++ b/src/main/java/ru/ulstu/user/model/User.java @@ -7,6 +7,8 @@ import ru.ulstu.core.model.BaseEntity; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; @@ -83,6 +85,28 @@ public class User extends BaseEntity { @BatchSize(size = 20) private Set roles; + @Size(max = 4) + @Column(name = "birth_year", length = 4) + private Integer birthYear; + + public enum UserDegree { + CANDIDATE("Кандидат технических наук"), + DOCTOR("Доктор технических наук"); + + private String degreeName; + + UserDegree(String degreeName) { + this.degreeName = degreeName; + } + + public String getDegreeName() { + return degreeName; + } + } + + @Enumerated(value = EnumType.STRING) + private UserDegree degree; + public User() { roles = new HashSet<>(); activated = false; @@ -186,4 +210,20 @@ public class User extends BaseEntity { public void setPatronymic(String patronymic) { this.patronymic = patronymic; } + + public Integer getBirthYear() { + return birthYear; + } + + public void setBirthYear(Integer birthYear) { + this.birthYear = birthYear; + } + + public UserDegree getDegree() { + return degree; + } + + public void setDegree(UserDegree degree) { + this.degree = degree; + } } diff --git a/src/main/java/ru/ulstu/user/model/UserDto.java b/src/main/java/ru/ulstu/user/model/UserDto.java index c98e0bb..dadfe99 100644 --- a/src/main/java/ru/ulstu/user/model/UserDto.java +++ b/src/main/java/ru/ulstu/user/model/UserDto.java @@ -70,6 +70,13 @@ public class UserDto implements OdinDto { @Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50) private String passwordConfirm; + @OdinCaption("Год рождения") + @Size(max = 4) + private Integer birthYear; + + @OdinCaption("Ученая степень") + private User.UserDegree degree; + public UserDto() { activated = false; roles = new LinkedHashSet<>(); @@ -86,6 +93,8 @@ public class UserDto implements OdinDto { this.roles.addAll(user.getRoles().stream() .map(UserRoleDto::new) .collect(Collectors.toList())); + this.birthYear = user.getBirthYear(); + this.degree = user.getDegree(); } public Integer getId() { @@ -163,6 +172,22 @@ public class UserDto implements OdinDto { return passwordConfirm; } + public Integer getBirthYear() { + return birthYear; + } + + public void setBirthYear(Integer birthYear) { + this.birthYear = birthYear; + } + + public User.UserDegree getDegree() { + return degree; + } + + public void setDegree(User.UserDegree degree) { + this.degree = degree; + } + @JsonIgnore public boolean isPasswordsValid() { if (StringUtils.isEmpty(password) || StringUtils.isEmpty(passwordConfirm)) { @@ -188,6 +213,8 @@ public class UserDto implements OdinDto { ", roles=" + roles + ", password='" + password + '\'' + ", passwordConfirm='" + passwordConfirm + '\'' + + ", birthYear='" + birthYear + '\'' + + ", degree='" + degree + '\'' + '}'; } } diff --git a/src/main/resources/db/changelog-20190404_000000-schema.xml b/src/main/resources/db/changelog-20190404_000000-schema.xml new file mode 100644 index 0000000..251905c --- /dev/null +++ b/src/main/resources/db/changelog-20190404_000000-schema.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + From e2e10477ac0ab5071782b88104ebbeea92165811 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 9 Apr 2019 21:31:23 +0400 Subject: [PATCH 04/15] #42 delete GrantStatusDto --- .../ru/ulstu/grant/model/GrantStatusDto.java | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/main/java/ru/ulstu/grant/model/GrantStatusDto.java diff --git a/src/main/java/ru/ulstu/grant/model/GrantStatusDto.java b/src/main/java/ru/ulstu/grant/model/GrantStatusDto.java deleted file mode 100644 index 34676d6..0000000 --- a/src/main/java/ru/ulstu/grant/model/GrantStatusDto.java +++ /dev/null @@ -1,19 +0,0 @@ -package ru.ulstu.grant.model; - -public class GrantStatusDto { - private final String id; - private final String name; - - public GrantStatusDto(Grant.GrantStatus status) { - this.id = status.name(); - this.name = status.getStatusName(); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } -} From 51c755ac077dce549be9f0bfc7b9ba5fbc86d8d5 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 10 Apr 2019 09:39:07 +0400 Subject: [PATCH 05/15] #42 method hasErrors didn't work, return to the previous state --- .../grant/controller/GrantController.java | 19 ++++++++++++------- .../ru/ulstu/grant/controller/Navigation.java | 9 --------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 98ddd70..2928fe2 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -25,7 +25,6 @@ import static org.springframework.util.StringUtils.isEmpty; import static ru.ulstu.grant.controller.Navigation.GRANTS_PAGE; import static ru.ulstu.grant.controller.Navigation.GRANT_PAGE; import static ru.ulstu.grant.controller.Navigation.REDIRECT_TO; -import static ru.ulstu.grant.controller.Navigation.hasErrors; @Controller() @@ -64,10 +63,12 @@ public class GrantController { if (grantDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } -// if (grantDto.getLeader().getId().equals(null)) { -// errors.rejectValue("leader", "errorCode", "Укажите руководителя"); -// } - hasErrors(errors, GRANT_PAGE); + if (grantDto.getLeaderId().equals(null)) { + errors.rejectValue("leader", "errorCode", "Укажите руководителя"); + } + if (errors.hasErrors()) { + return GRANT_PAGE; + } grantService.save(grantDto); return String.format(REDIRECT_TO, GRANTS_PAGE); } @@ -75,14 +76,18 @@ public class GrantController { @PostMapping(value = "/grant", params = "addDeadline") public String addDeadline(@Valid GrantDto grantDto, Errors errors) { filterEmptyDeadlines(grantDto); - hasErrors(errors, GRANT_PAGE); + if (errors.hasErrors()) { + return GRANT_PAGE; + } grantDto.getDeadlines().add(new Deadline()); return GRANT_PAGE; } @PostMapping(value = "/grant", params = "createProject") public String createProject(@Valid GrantDto grantDto, Errors errors) { - hasErrors(errors, GRANT_PAGE); + if (errors.hasErrors()) { + return GRANT_PAGE; + } grantService.createProject(grantDto); return GRANT_PAGE; } diff --git a/src/main/java/ru/ulstu/grant/controller/Navigation.java b/src/main/java/ru/ulstu/grant/controller/Navigation.java index bf1626f..8ee49bc 100644 --- a/src/main/java/ru/ulstu/grant/controller/Navigation.java +++ b/src/main/java/ru/ulstu/grant/controller/Navigation.java @@ -1,16 +1,7 @@ package ru.ulstu.grant.controller; -import org.springframework.validation.Errors; - public class Navigation { public static final String REDIRECT_TO = "redirect:%s"; public static final String GRANTS_PAGE = "/grants/grants"; public static final String GRANT_PAGE = "/grants/grant"; - - public static String hasErrors(Errors errors, String page) { - if (errors.hasErrors()) { - return page; - } - return null; - } } From e8461e26eb4554189e27ca9f48803eedae6711d3 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 10 Apr 2019 10:09:41 +0400 Subject: [PATCH 06/15] #42 fix birthDate and degree to User --- src/main/java/ru/ulstu/user/model/User.java | 10 +++++----- src/main/java/ru/ulstu/user/model/UserDto.java | 10 ++++------ .../resources/db/changelog-20190404_000000-schema.xml | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/ulstu/user/model/User.java b/src/main/java/ru/ulstu/user/model/User.java index 40f1f45..974ca82 100644 --- a/src/main/java/ru/ulstu/user/model/User.java +++ b/src/main/java/ru/ulstu/user/model/User.java @@ -85,9 +85,9 @@ public class User extends BaseEntity { @BatchSize(size = 20) private Set roles; - @Size(max = 4) - @Column(name = "birth_year", length = 4) - private Integer birthYear; + @Column(name = "birth_year") + @Temporal(TemporalType.TIMESTAMP) + private Date birthYear; public enum UserDegree { CANDIDATE("Кандидат технических наук"), @@ -211,11 +211,11 @@ public class User extends BaseEntity { this.patronymic = patronymic; } - public Integer getBirthYear() { + public Date getBirthYear() { return birthYear; } - public void setBirthYear(Integer birthYear) { + public void setBirthYear(Date birthYear) { this.birthYear = birthYear; } diff --git a/src/main/java/ru/ulstu/user/model/UserDto.java b/src/main/java/ru/ulstu/user/model/UserDto.java index dadfe99..8157b63 100644 --- a/src/main/java/ru/ulstu/user/model/UserDto.java +++ b/src/main/java/ru/ulstu/user/model/UserDto.java @@ -15,6 +15,7 @@ import ru.ulstu.user.controller.UserController; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import java.util.Collection; +import java.util.Date; import java.util.LinkedHashSet; import java.util.Objects; import java.util.Set; @@ -70,11 +71,8 @@ public class UserDto implements OdinDto { @Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50) private String passwordConfirm; - @OdinCaption("Год рождения") - @Size(max = 4) - private Integer birthYear; + private Date birthYear; - @OdinCaption("Ученая степень") private User.UserDegree degree; public UserDto() { @@ -172,11 +170,11 @@ public class UserDto implements OdinDto { return passwordConfirm; } - public Integer getBirthYear() { + public Date getBirthYear() { return birthYear; } - public void setBirthYear(Integer birthYear) { + public void setBirthYear(Date birthYear) { this.birthYear = birthYear; } diff --git a/src/main/resources/db/changelog-20190404_000000-schema.xml b/src/main/resources/db/changelog-20190404_000000-schema.xml index 251905c..a92a99d 100644 --- a/src/main/resources/db/changelog-20190404_000000-schema.xml +++ b/src/main/resources/db/changelog-20190404_000000-schema.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> - + From f7d766f02df969b8764c3d8fc91d61452d1ffec4 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 11 Apr 2019 21:37:24 +0400 Subject: [PATCH 07/15] #42 rename birth_date column --- src/main/java/ru/ulstu/user/model/User.java | 12 ++++++------ src/main/java/ru/ulstu/user/model/UserDto.java | 14 +++++++------- .../db/changelog-20190404_000000-schema.xml | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/user/model/User.java b/src/main/java/ru/ulstu/user/model/User.java index 974ca82..7c8eaf3 100644 --- a/src/main/java/ru/ulstu/user/model/User.java +++ b/src/main/java/ru/ulstu/user/model/User.java @@ -85,9 +85,9 @@ public class User extends BaseEntity { @BatchSize(size = 20) private Set roles; - @Column(name = "birth_year") + @Column(name = "birth_date") @Temporal(TemporalType.TIMESTAMP) - private Date birthYear; + private Date birthDate; public enum UserDegree { CANDIDATE("Кандидат технических наук"), @@ -211,12 +211,12 @@ public class User extends BaseEntity { this.patronymic = patronymic; } - public Date getBirthYear() { - return birthYear; + public Date getBirthDate() { + return birthDate; } - public void setBirthYear(Date birthYear) { - this.birthYear = birthYear; + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; } public UserDegree getDegree() { diff --git a/src/main/java/ru/ulstu/user/model/UserDto.java b/src/main/java/ru/ulstu/user/model/UserDto.java index 8157b63..39ff913 100644 --- a/src/main/java/ru/ulstu/user/model/UserDto.java +++ b/src/main/java/ru/ulstu/user/model/UserDto.java @@ -71,7 +71,7 @@ public class UserDto implements OdinDto { @Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50) private String passwordConfirm; - private Date birthYear; + private Date birthDate; private User.UserDegree degree; @@ -91,7 +91,7 @@ public class UserDto implements OdinDto { this.roles.addAll(user.getRoles().stream() .map(UserRoleDto::new) .collect(Collectors.toList())); - this.birthYear = user.getBirthYear(); + this.birthDate = user.getBirthDate(); this.degree = user.getDegree(); } @@ -170,12 +170,12 @@ public class UserDto implements OdinDto { return passwordConfirm; } - public Date getBirthYear() { - return birthYear; + public Date getBirthDate() { + return birthDate; } - public void setBirthYear(Date birthYear) { - this.birthYear = birthYear; + public void setBirthDate(Date birthDate) { + this.birthDate = birthDate; } public User.UserDegree getDegree() { @@ -211,7 +211,7 @@ public class UserDto implements OdinDto { ", roles=" + roles + ", password='" + password + '\'' + ", passwordConfirm='" + passwordConfirm + '\'' + - ", birthYear='" + birthYear + '\'' + + ", birthDate='" + birthDate + '\'' + ", degree='" + degree + '\'' + '}'; } diff --git a/src/main/resources/db/changelog-20190404_000000-schema.xml b/src/main/resources/db/changelog-20190404_000000-schema.xml index a92a99d..0f45e31 100644 --- a/src/main/resources/db/changelog-20190404_000000-schema.xml +++ b/src/main/resources/db/changelog-20190404_000000-schema.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> - + From bd3513118c3804fad2fb7cbea0045e6104c1c5c6 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 11 Apr 2019 21:42:28 +0400 Subject: [PATCH 08/15] #42 this don't work --- .../grant/controller/GrantController.java | 25 +++++++-- .../ulstu/grant/model/GrantUserFilterDto.java | 54 +++++++++++++++++++ .../grant/repository/GrantRepository.java | 21 ++++++++ .../ru/ulstu/grant/service/GrantService.java | 7 +++ .../resources/templates/grants/grant.html | 42 +++++++++++---- 5 files changed, 136 insertions(+), 13 deletions(-) create mode 100644 src/main/java/ru/ulstu/grant/model/GrantUserFilterDto.java diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 2928fe2..76f3ed9 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; +import ru.ulstu.grant.model.GrantUserFilterDto; import ru.ulstu.grant.service.GrantService; import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; @@ -48,23 +49,30 @@ public class GrantController { } @GetMapping("/grant") - public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) { + public void getGrant(ModelMap modelMap, GrantUserFilterDto grantUserFilterDto, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { modelMap.put("grantDto", grantService.findOneDto(id)); } else { modelMap.put("grantDto", new GrantDto()); } + modelMap.put("filteredAuthors", new GrantUserFilterDto(grantService.filterUsers(grantUserFilterDto), false, false, false)); } @PostMapping(value = "/grant", params = "save") - public String save(@Valid GrantDto grantDto, Errors errors) throws IOException { + public String save(@Valid GrantDto grantDto, GrantUserFilterDto grantUserFilterDto, Errors errors, ModelMap modelMap /*@ModelAttribute List allAuthors*/) + throws IOException { filterEmptyDeadlines(grantDto); - // фильтр авторов + modelMap.put("filteredAuthors", new GrantUserFilterDto(grantService.filterUsers(grantUserFilterDto), + grantUserFilterDto.isLeader(), + grantUserFilterDto.isBirthDate(), + grantUserFilterDto.isDegree())); if (grantDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } if (grantDto.getLeaderId().equals(null)) { errors.rejectValue("leader", "errorCode", "Укажите руководителя"); +// } else { +// allAuthors.remove(grantDto.getLeaderId()); } if (errors.hasErrors()) { return GRANT_PAGE; @@ -92,6 +100,12 @@ public class GrantController { return GRANT_PAGE; } +// @PostMapping(value = "/grant", params = "updateAuthors") +// public String updateAuthors(@ModelAttribute List allAuthors, @Valid GrantDto grantDto) { +// allAuthors.remove(grantDto.getLeaderId()); +// return GRANT_PAGE; +// } + @GetMapping("/delete/{grant-id}") public String delete(@PathVariable("grant-id") Integer grantId) throws IOException { grantService.delete(grantId); @@ -108,6 +122,11 @@ public class GrantController { return grantService.getGrantAuthors(); } +// @ModelAttribute("allLeaders") +// public List getAllLeaders() { +// return grantService.getGrantAuthors(); +// } + 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/GrantUserFilterDto.java b/src/main/java/ru/ulstu/grant/model/GrantUserFilterDto.java new file mode 100644 index 0000000..36f88f6 --- /dev/null +++ b/src/main/java/ru/ulstu/grant/model/GrantUserFilterDto.java @@ -0,0 +1,54 @@ +package ru.ulstu.grant.model; + +import ru.ulstu.user.model.UserDto; + +import java.util.List; + +public class GrantUserFilterDto { + private List users; + private boolean leader; + private boolean birthDate; + private boolean degree; + + public GrantUserFilterDto() { + } + + public GrantUserFilterDto(List users, boolean leader, boolean birthDate, boolean degree) { + this.users = users; + this.leader = leader; + this.birthDate = birthDate; + this.degree = degree; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } + + public boolean isLeader() { + return leader; + } + + public void setLeader(boolean leader) { + this.leader = leader; + } + + public boolean isBirthDate() { + return birthDate; + } + + public void setBirthDate(boolean birthDate) { + this.birthDate = birthDate; + } + + public boolean isDegree() { + return degree; + } + + public void setDegree(boolean degree) { + this.degree = degree; + } +} diff --git a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java index 92dec43..1b2e64d 100644 --- a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java +++ b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java @@ -1,8 +1,29 @@ package ru.ulstu.grant.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import ru.ulstu.grant.model.Grant; +import ru.ulstu.user.model.User; + +import java.util.List; public interface GrantRepository extends JpaRepository { +// @Query(value = "SELECT u.last_name " + +// "FROM users u, grants g " + +// "WHERE (g.leader_id = u.id) " + +// "AND (u.birth_date < 35) " + +// "AND (u.degree = 'CANDIDATE')" + +// "Group by u.last_name", +// nativeQuery = true) +// List filter(@Param("leader") Integer leader, @Param("birthYear") Date birthYear, @Param("degree") String degree); + + @Query("SELECT u.lastName FROM User u, Grant g WHERE (g.leader = u.id OR :leader IS FALSE) " + + "AND (extract(year from interval (age(birth_date::date))) < 35 OR :birthDate IS FALSE) " + + "AND (u.degree = 'CANDIDATE' OR :degree IS FALSE)" + + "GROUP BY u.lastName") + List filterUsers(@Param("leader") boolean leader, + @Param("birthDate") boolean birthDate, + @Param("degree") boolean degree); } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index cbf37ce..197c4f2 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -8,11 +8,13 @@ import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; +import ru.ulstu.grant.model.GrantUserFilterDto; import ru.ulstu.grant.repository.GrantRepository; 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 ru.ulstu.user.model.UserDto; import ru.ulstu.user.service.UserService; import java.io.IOException; @@ -141,4 +143,9 @@ public class GrantService { public List getGrantAuthors() { return userService.findAll(); } + + public List filterUsers(GrantUserFilterDto filterDto) { + return convert(grantRepository.filterUsers( + filterDto.isLeader(), filterDto.isBirthDate(), filterDto.isDegree()), UserDto::new); + } } diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index aae3b02..ed9036d 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -9,7 +9,7 @@
-
+
@@ -94,17 +94,22 @@
- + +
- +
- +
@@ -125,27 +130,30 @@

+
-
+
-

Incorrect member

+ From cafb3abcee2255bb97c2b5270abc4642b9d940d0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 11 Apr 2019 22:37:32 +0400 Subject: [PATCH 09/15] #4--2 merge with dev --- .gitlab-ci.yml | 31 +-- .gitlab/issue_templates/feature.md | 50 +++++ build.gradle | 4 + .../java/ru/ulstu/NgTrackerApplication.java | 17 ++ .../controller/ConferenceController.java | 64 +++++- .../ru/ulstu/conference/model/Conference.java | 132 ++++++++++++ .../ulstu/conference/model/ConferenceDto.java | 193 ++++++++++++++++++ .../conference/model/ConferenceFilterDto.java | 43 ++++ .../conference/service/ConferenceService.java | 67 ++++++ .../configuration/ApplicationProperties.java | 12 ++ .../core/controller/AdviceController.java | 8 +- .../ru/ulstu/core/controller/Navigation.java | 19 ++ .../grant/controller/GrantController.java | 7 +- .../ru/ulstu/grant/controller/Navigation.java | 7 - .../grant/repository/GrantRepository.java | 17 +- .../ru/ulstu/grant/service/GrantService.java | 18 +- .../paper/controller/PaperController.java | 2 +- .../paper/controller/PaperRestController.java | 5 + .../ru/ulstu/paper/service/PaperService.java | 31 ++- src/main/java/ru/ulstu/user/model/User.java | 9 + .../ulstu/user/repository/UserRepository.java | 9 + .../ru/ulstu/user/service/UserService.java | 4 + src/main/resources/application.properties | 3 +- .../db/changelog-20190402_000000-schema.xml | 6 +- src/main/resources/db/changelog-master.xml | 2 + src/main/resources/public/css/agency.css | 14 ++ .../templates/conferences/conference.html | 44 ++-- .../templates/conferences/conferences.html | 6 +- .../fragments/confLineFragment.html | 5 +- .../fragments/confNavigationFragment.html | 2 +- 30 files changed, 746 insertions(+), 85 deletions(-) create mode 100644 .gitlab/issue_templates/feature.md create mode 100644 src/main/java/ru/ulstu/core/controller/Navigation.java delete mode 100644 src/main/java/ru/ulstu/grant/controller/Navigation.java diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b2fe64..6709891 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,16 +1,11 @@ -image: ubuntu:18.04 - -cache: - key: "$CI_PROJECT_ID" - paths: - - .gradle/ +image: romanov73/is:ng-tracker-container variables: GRADLE_OPTS: "-Dorg.gradle.daemon=false" before_script: - - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' - - apt-get install openjdk-8-jdk git -y + - service postgresql stop + - service postgresql start - eval $(ssh-agent -s) - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null - mkdir -p ~/.ssh @@ -20,12 +15,14 @@ before_script: build: stage: build script: ./gradlew assemble - cache: - key: "$CI_PROJECT_ID" - policy: push - paths: - - build - - .gradle + +checkRun: + stage: test + script: ./gradlew bootRun -Dng-tracker.check-run=true + +checkStyle: + stage: test + script: ./gradlew check deploy: stage: deploy @@ -33,12 +30,6 @@ deploy: - sh deploy/gdccloud/deploy.sh only: - dev - cache: - key: "$CI_PROJECT_ID" - policy: pull - paths: - - build - - .gradle environment: name: staging url: http://193.110.3.124:8080 diff --git a/.gitlab/issue_templates/feature.md b/.gitlab/issue_templates/feature.md new file mode 100644 index 0000000..ba3e298 --- /dev/null +++ b/.gitlab/issue_templates/feature.md @@ -0,0 +1,50 @@ +## Краткое описание задачи +``` +Что требуется сделать +``` + +## `Опционально` Список верстаемых страниц +``` +Будут затронуты страницы: +* page1.html +* page2.html +* page3.html +``` + +## `Опционально` Список затрагиваемых модулей +``` +При реализации задачи потребуется также реализовать методы контроллера +``` + +## `Опционально` Список реализуемых функций +``` +После выполнения задачи станет доступным: +* просмотр `entity_name` +* редактирование `entity_name` +* валидация `entity_name` +``` + +## `Опционально` Сценарии работы +``` +Сценарий просмотра: +1. Зайти на главную страницу приложения +2. Перейти в раздел `section_name` +3. Перейти к списку `entity_name` +4. Выбрать нужную `entity_name` и нажать на нее + +Сценарий редактирования: +1. Зайти на главную страницу приложения +2. Перейти в раздел `section_name` +3. Перейти к списку `entity_name` +4. Выбрать нужную `entity_name` и нажать на нее +5. Внести нужные правки в поля и сохранить +``` + +## Описание конечного результата, дающего возможность проверки выполнения задачи: компоненты проекта, сценарии работы +``` +* Сверстаны страницы page1.hml, page2.hml, page3.hml +* Реализован контроллер для обслуживания страниц +* Сохранение в БД еще не реализовано +* Валидация происходит по полям `field1, field2` +* Сценарий просмотра проверяется при ручном внечении записей в БД +``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4e0e9cb..ffc7d0a 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,10 @@ bootRun.dependsOn checkstyleMain sourceCompatibility = 1.8 targetCompatibility = 1.8 +bootRun { + systemProperties = System.properties +} + checkstyle { project.ext.checkstyleVersion = '8.8' diff --git a/src/main/java/ru/ulstu/NgTrackerApplication.java b/src/main/java/ru/ulstu/NgTrackerApplication.java index 5e6ee4f..fbe3a2f 100644 --- a/src/main/java/ru/ulstu/NgTrackerApplication.java +++ b/src/main/java/ru/ulstu/NgTrackerApplication.java @@ -2,13 +2,30 @@ package ru.ulstu; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import ru.ulstu.configuration.ApplicationProperties; import ru.ulstu.core.repository.JpaDetachableRepositoryImpl; @SpringBootApplication @EnableJpaRepositories(repositoryBaseClass = JpaDetachableRepositoryImpl.class) public class NgTrackerApplication { + private final ApplicationProperties applicationProperties; + + public NgTrackerApplication(ApplicationProperties applicationProperties) { + this.applicationProperties = applicationProperties; + } + public static void main(String[] args) { SpringApplication.run(NgTrackerApplication.class, args); } + + @EventListener(ApplicationReadyEvent.class) + public void doSomethingAfterStartup() { + System.out.println("hello world, I have just started up"); + if (applicationProperties.isCheckRun()) { + System.exit(0); + } + } } diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index aa871ba..006a1de 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -2,10 +2,28 @@ package ru.ulstu.conference.controller; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.conference.model.ConferenceDto; +import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.service.ConferenceService; +import ru.ulstu.deadline.model.Deadline; import springfox.documentation.annotations.ApiIgnore; +import javax.validation.Valid; +import java.io.IOException; +import java.util.stream.Collectors; + +import static org.springframework.util.StringUtils.isEmpty; +import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE; +import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE; +import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; + + @Controller() @RequestMapping(value = "/conferences") @ApiIgnore @@ -13,7 +31,49 @@ public class ConferenceController { private final ConferenceService conferenceService; - public ConferenceController(ConferenceService paperService) { - this.conferenceService = paperService; + public ConferenceController(ConferenceService conferenceService) { + this.conferenceService = conferenceService; + } + + @GetMapping("/conferences") + public void getConferences(ModelMap modelMap) { + modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto())); + } + + @GetMapping("/conference") + public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) { + if (id != null && id > 0) { + modelMap.put("conferenceDto", conferenceService.findOneDto(id)); + } else { + modelMap.put("conferenceDto", new ConferenceDto()); + } + } + + @PostMapping(value = "/conference", params = "save") + public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { + filterEmptyDeadlines(conferenceDto); + if (conferenceDto.getDeadlines().isEmpty()) { + errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); + } + if (errors.hasErrors()) + return CONFERENCE_PAGE; + conferenceService.save(conferenceDto); + return String.format(REDIRECT_TO, CONFERENCES_PAGE); + + } + + @PostMapping(value = "/conference", params = "addDeadline") + public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) { + filterEmptyDeadlines(conferenceDto); + if (errors.hasErrors()) + return CONFERENCE_PAGE; + conferenceDto.getDeadlines().add(new Deadline()); + return CONFERENCE_PAGE; + } + + private void filterEmptyDeadlines(ConferenceDto conferenceDto) { + conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() + .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) + .collect(Collectors.toList())); } } diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index b2851ed..1c824b3 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -1,11 +1,143 @@ package ru.ulstu.conference.model; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.validator.constraints.NotBlank; +import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.user.model.User; +import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import javax.persistence.OrderBy; import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; @Entity @Table(name = "conference") public class Conference extends BaseEntity { + + @NotBlank + private String title; + + private String description; + + private String url; + + private int ping; + + @Column(name = "begin_date") + @Temporal(TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date beginDate; + + @Column(name = "end_date") + @Temporal(TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date endDate; + + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "conference_id", unique = true) + @Fetch(FetchMode.SUBSELECT) + @OrderBy("date") + private List deadlines = new ArrayList<>(); + + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "paper_conference", + joinColumns = {@JoinColumn(name = "conference_id")}, + inverseJoinColumns = {@JoinColumn(name = "paper_id")}) + private Set papers = new HashSet<>(); + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "users_conference", + joinColumns = {@JoinColumn(name = "conference_id")}, + inverseJoinColumns = {@JoinColumn(name = "users_id")}) + private Set users = new HashSet<>(); + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getPing() { + return ping; + } + + public void setPing(int ping) { + this.ping = ping; + } + + public Date getBeginDate() { + return beginDate; + } + + public void setBeginDate(Date beginDate) { + this.beginDate = beginDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public List getDeadlines() { + return deadlines; + } + + public void setDeadlines(List deadlines) { + this.deadlines = deadlines; + } + + public Set getPapers() { + return papers; + } + + public void setPapers(Set papers) { + this.papers = papers; + } + + public Set getUsers() { + return users; + } + + public void setUsers(Set users) { + this.users = users; + } } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index e3f757e..277e783 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -1,4 +1,197 @@ package ru.ulstu.conference.model; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.format.annotation.DateTimeFormat; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.user.model.UserDto; + +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.Size; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static ru.ulstu.core.util.StreamApiUtils.convert; + public class ConferenceDto { + + private Integer id; + @NotEmpty + @Size(min = 2, max = 400) + private String title; + @Size(max = 500) + private String description = ""; + @Size(max = 255) + private String url = ""; + private int ping = 0; + @Temporal(TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date beginDate = new Date(); + @Temporal(TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date endDate = new Date(); + @NotEmpty + private List deadlines = new ArrayList<>(); + private Set userIds = new HashSet<>(); + private Set paperIds = new HashSet<>(); + private Set papers = new HashSet<>(); + private Set users = new HashSet<>(); + private Integer filterUserId; + + public ConferenceDto() { + deadlines.add(new Deadline()); + } + + @JsonCreator + public ConferenceDto(@JsonProperty("id") Integer id, + @JsonProperty("title") String title, + @JsonProperty("description") String description, + @JsonProperty("url") String url, + @JsonProperty("ping") Integer ping, + @JsonProperty("beginDate") Date beginDate, + @JsonProperty("endDate") Date endDate, + @JsonProperty("deadlines") List deadlines, + @JsonProperty("userIds") Set userIds, + @JsonProperty("paperIds") Set paperIds, + @JsonProperty("users") Set users, + @JsonProperty("papers") Set papers) { + this.id = id; + this.title = title; + this.description = description; + this.url = url; + this.ping = ping; + this.beginDate = beginDate; + this.endDate = endDate; + this.deadlines = deadlines; + this.userIds = userIds; + this.paperIds = paperIds; + this.users = users; + this.papers = papers; + } + + public ConferenceDto(Conference conference) { + this.id = conference.getId(); + this.title = conference.getTitle(); + this.description = conference.getDescription(); + this.url = conference.getUrl(); + this.ping = conference.getPing(); + this.beginDate = conference.getBeginDate(); + this.endDate = conference.getEndDate(); + this.deadlines = conference.getDeadlines(); + this.userIds = convert(conference.getUsers(), user -> user.getId()); + this.paperIds = convert(conference.getPapers(), paper -> paper.getId()); + this.users = convert(conference.getUsers(), UserDto::new); + this.papers = convert(conference.getPapers(), PaperDto::new); + + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getPing() { + return ping; + } + + public void setPing(int ping) { + this.ping = ping; + } + + public Date getBeginDate() { + return beginDate; + } + + public void setBeginDate(Date beginDate) { + this.beginDate = beginDate; + } + + public Date getEndDate() { + return endDate; + } + + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + public List getDeadlines() { + return deadlines; + } + + public void setDeadlines(List deadlines) { + this.deadlines = deadlines; + } + + public Set getUserIds() { + return userIds; + } + + public void setUserIds(Set userIds) { + this.userIds = userIds; + } + + public Set getPaperIds() { + return paperIds; + } + + public void setPaperIds(Set paperIds) { + this.paperIds = paperIds; + } + + public Set getPapers() { + return papers; + } + + public void setPapers(Set papers) { + this.papers = papers; + } + + public Set getUsers() { + return users; + } + + public void setUsers(Set users) { + this.users = users; + } + + public Integer getFilterUserId() { + return filterUserId; + } + + public void setFilterUserId(Integer filterUserId) { + this.filterUserId = filterUserId; + } } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java index 379c8b6..37878b2 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceFilterDto.java @@ -1,4 +1,47 @@ package ru.ulstu.conference.model; +import java.util.List; + public class ConferenceFilterDto { + + private List conferences; + private Integer filterAuthorId; + private Integer year; + + public ConferenceFilterDto() { + } + + public ConferenceFilterDto(List conferenceDtos, Integer filterAuthorId, Integer year) { + this.conferences = conferenceDtos; + this.filterAuthorId = filterAuthorId; + this.year = year; + } + + public ConferenceFilterDto(List conferenceDtos) { + this(conferenceDtos, null, null); + } + + public List getConferences() { + return conferences; + } + + public void setConferences(List conferences) { + this.conferences = conferences; + } + + public Integer getFilterAuthorId() { + return filterAuthorId; + } + + public void setFilterAuthorId(Integer filterAuthorId) { + this.filterAuthorId = filterAuthorId; + } + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index a8147c9..c28c637 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -1,11 +1,23 @@ package ru.ulstu.conference.service; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.service.DeadlineService; +import java.io.IOException; +import java.util.List; + +import static org.springframework.util.ObjectUtils.isEmpty; +import static ru.ulstu.core.util.StreamApiUtils.convert; + @Service public class ConferenceService { + private final static int MAX_DISPLAY_SIZE = 40; + private final ConferenceRepository conferenceRepository; private final DeadlineService deadlineService; @@ -14,4 +26,59 @@ public class ConferenceService { this.conferenceRepository = conferenceRepository; this.deadlineService = deadlineService; } + + public List findAll() { + return conferenceRepository.findAll(); + } + + public List findAllDto() { + List conferences = convert(findAll(), ConferenceDto::new); + conferences.forEach(conferenceDto -> conferenceDto.setTitle(StringUtils.abbreviate(conferenceDto.getTitle(), MAX_DISPLAY_SIZE))); + return conferences; + } + + public ConferenceDto findOneDto(Integer id) { + return new ConferenceDto(conferenceRepository.findOne(id)); + } + + public void save(ConferenceDto conferenceDto) throws IOException { + if (isEmpty(conferenceDto.getId())) { + create(conferenceDto); + } else { + update(conferenceDto); + } + } + + @Transactional + public Integer create(ConferenceDto conferenceDto) throws IOException { + Conference newConference = copyFromDto(new Conference(), conferenceDto); + newConference = conferenceRepository.save(newConference); + + + return newConference.getId(); + } + + @Transactional + public Integer update(ConferenceDto conferenceDto) throws IOException { + Conference conference = conferenceRepository.findOne(conferenceDto.getId()); + + conferenceRepository.save(copyFromDto(conference, conferenceDto)); + + return conference.getId(); + } + + private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { + conference.setTitle(conferenceDto.getTitle()); + conference.setDescription(conferenceDto.getDescription()); + conference.setUrl(conferenceDto.getUrl()); + conference.setPing(0); + conference.setBeginDate(conferenceDto.getBeginDate()); + conference.setEndDate(conferenceDto.getEndDate()); + + conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); + + return conference; + } + + } diff --git a/src/main/java/ru/ulstu/configuration/ApplicationProperties.java b/src/main/java/ru/ulstu/configuration/ApplicationProperties.java index 8615cb2..f75f53f 100644 --- a/src/main/java/ru/ulstu/configuration/ApplicationProperties.java +++ b/src/main/java/ru/ulstu/configuration/ApplicationProperties.java @@ -11,12 +11,16 @@ import org.springframework.validation.annotation.Validated; public class ApplicationProperties { @NotBlank private String baseUrl; + @NotBlank private String undeadUserLogin; + private boolean devMode; private boolean useHttps; + private boolean checkRun; + public boolean isUseHttps() { return useHttps; } @@ -48,4 +52,12 @@ public class ApplicationProperties { public void setDevMode(boolean devMode) { this.devMode = devMode; } + + public boolean isCheckRun() { + return checkRun; + } + + public void setCheckRun(boolean checkRun) { + this.checkRun = checkRun; + } } diff --git a/src/main/java/ru/ulstu/core/controller/AdviceController.java b/src/main/java/ru/ulstu/core/controller/AdviceController.java index 1c71df1..8238797 100644 --- a/src/main/java/ru/ulstu/core/controller/AdviceController.java +++ b/src/main/java/ru/ulstu/core/controller/AdviceController.java @@ -20,7 +20,6 @@ import ru.ulstu.user.error.UserNotActivatedException; import ru.ulstu.user.error.UserNotFoundException; import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException; import ru.ulstu.user.error.UserResetKeyError; -import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.util.Set; @@ -28,7 +27,6 @@ import java.util.stream.Collectors; @ControllerAdvice public class AdviceController { - private final static String USER_NAME_TEMPLATE = "%s %s %s"; private final Logger log = LoggerFactory.getLogger(AdviceController.class); private final UserService userService; @@ -38,11 +36,7 @@ public class AdviceController { @ModelAttribute("currentUser") public String getCurrentUser() { - User user = userService.getCurrentUser(); - return String.format(USER_NAME_TEMPLATE, - user.getLastName(), - user.getFirstName().substring(0, 1), - user.getPatronymic().substring(0, 1)); + return userService.getCurrentUser().getUserAbbreviate(); } private Response handleException(ErrorConstants error) { diff --git a/src/main/java/ru/ulstu/core/controller/Navigation.java b/src/main/java/ru/ulstu/core/controller/Navigation.java new file mode 100644 index 0000000..caea429 --- /dev/null +++ b/src/main/java/ru/ulstu/core/controller/Navigation.java @@ -0,0 +1,19 @@ +package ru.ulstu.core.controller; + +import org.springframework.validation.Errors; + +public class Navigation { + public static final String REDIRECT_TO = "redirect:%s"; + public static final String GRANTS_PAGE = "/grants/grants"; + public static final String GRANT_PAGE = "/grants/grant"; + + public static final String CONFERENCES_PAGE = "/conferences/conferences"; + public static final String CONFERENCE_PAGE = "/conferences/conference"; + + public static String hasErrors(Errors errors, String page) { + if (errors.hasErrors()) { + return page; + } + return null; + } +} diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 76f3ed9..4978132 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -23,10 +23,9 @@ import java.util.List; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; -import static ru.ulstu.grant.controller.Navigation.GRANTS_PAGE; -import static ru.ulstu.grant.controller.Navigation.GRANT_PAGE; -import static ru.ulstu.grant.controller.Navigation.REDIRECT_TO; - +import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE; +import static ru.ulstu.core.controller.Navigation.GRANT_PAGE; +import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; @Controller() @RequestMapping(value = "/grants") diff --git a/src/main/java/ru/ulstu/grant/controller/Navigation.java b/src/main/java/ru/ulstu/grant/controller/Navigation.java deleted file mode 100644 index 8ee49bc..0000000 --- a/src/main/java/ru/ulstu/grant/controller/Navigation.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.ulstu.grant.controller; - -public class Navigation { - public static final String REDIRECT_TO = "redirect:%s"; - public static final String GRANTS_PAGE = "/grants/grants"; - public static final String GRANT_PAGE = "/grants/grant"; -} diff --git a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java index 1b2e64d..68b31a6 100644 --- a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java +++ b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java @@ -9,21 +9,6 @@ import ru.ulstu.user.model.User; import java.util.List; public interface GrantRepository extends JpaRepository { -// @Query(value = "SELECT u.last_name " + -// "FROM users u, grants g " + -// "WHERE (g.leader_id = u.id) " + -// "AND (u.birth_date < 35) " + -// "AND (u.degree = 'CANDIDATE')" + -// "Group by u.last_name", -// nativeQuery = true) -// List filter(@Param("leader") Integer leader, @Param("birthYear") Date birthYear, @Param("degree") String degree); - - @Query("SELECT u.lastName FROM User u, Grant g WHERE (g.leader = u.id OR :leader IS FALSE) " + - "AND (extract(year from interval (age(birth_date::date))) < 35 OR :birthDate IS FALSE) " + - "AND (u.degree = 'CANDIDATE' OR :degree IS FALSE)" + - "GROUP BY u.lastName") - List filterUsers(@Param("leader") boolean leader, - @Param("birthDate") boolean birthDate, - @Param("degree") boolean degree); + List findByStatus(Grant.GrantStatus status); } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 197c4f2..5474089 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -145,7 +146,20 @@ public class GrantService { } public List filterUsers(GrantUserFilterDto filterDto) { - return convert(grantRepository.filterUsers( - filterDto.isLeader(), filterDto.isBirthDate(), filterDto.isDegree()), UserDto::new); + List filteredUsers = userService.filterByAgeAndDegree(filterDto.isBirthDate(), filterDto.isDegree()); + if (filterDto.isLeader()) { + filteredUsers = filteredUsers + .stream() + .filter(getCompletedGrantLeaders()::contains) + .collect(Collectors.toList()); + } + return convert(filteredUsers, UserDto::new); + } + + private List getCompletedGrantLeaders() { + return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED) + .stream() + .map(Grant::getLeader) + .collect(Collectors.toList()); } } diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 9169bd9..27fec4e 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -51,7 +51,7 @@ public class PaperController { @GetMapping("/dashboard") public void getDashboard(ModelMap modelMap) { - modelMap.put("papers", paperService.findAllActive()); + modelMap.put("papers", paperService.findAllActiveDto()); } @GetMapping("/paper") diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java index 5dd6b9f..2bd8384 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -61,4 +61,9 @@ public class PaperRestController { public Response> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { return new Response<>(paperService.filter(paperFilterDto)); } + + @GetMapping("formatted-list") + public Response> getFormattedPaperList() { + return new Response<>(paperService.getFormattedPaperList()); + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index aab62d1..a93c9c6 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; @@ -34,6 +35,7 @@ import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION; @Service public class PaperService { private final static int MAX_DISPLAY_SIZE = 40; + private final static String PAPER_FORMATTED_TEMPLATE = "%s %s"; private final PaperNotificationService paperNotificationService; private final PaperRepository paperRepository; @@ -66,13 +68,17 @@ public class PaperService { return papers; } - public List findAllActive() { - return findAllDto() + public List findAllActive() { + return findAll() .stream() .filter(paper -> paper.getStatus() != COMPLETED && paper.getStatus() != FAILED) .collect(toList()); } + public List findAllActiveDto() { + return convert(findAllActive(), PaperDto::new); + } + public PaperDto findOneDto(Integer id) { return new PaperDto(paperRepository.findOne(id)); } @@ -212,4 +218,25 @@ public class PaperService { public List getPaperAuthors() { return userService.findAll(); } + + public List getFormattedPaperList() { + return findAllCompleted() + .stream() + .map(paper -> String.format(PAPER_FORMATTED_TEMPLATE, paper.getTitle(), getAuthors(paper))) + .collect(toList()); + } + + private List findAllCompleted() { + return findAll() + .stream() + .filter(paper -> paper.getStatus() == COMPLETED) + .collect(toList()); + } + + private String getAuthors(Paper paper) { + return paper.getAuthors() + .stream() + .map(User::getUserAbbreviate) + .collect(Collectors.joining(", ")); + } } diff --git a/src/main/java/ru/ulstu/user/model/User.java b/src/main/java/ru/ulstu/user/model/User.java index 7c8eaf3..7946f04 100644 --- a/src/main/java/ru/ulstu/user/model/User.java +++ b/src/main/java/ru/ulstu/user/model/User.java @@ -26,6 +26,8 @@ import java.util.Set; @Entity @Table(name = "users") public class User extends BaseEntity { + private final static String USER_ABBREVIATE_TEMPLATE = "%s %s%s"; + @NotNull @Pattern(regexp = Constants.LOGIN_REGEX) @Size(min = 1, max = 50) @@ -226,4 +228,11 @@ public class User extends BaseEntity { public void setDegree(UserDegree degree) { this.degree = degree; } + + public String getUserAbbreviate() { + return String.format(USER_ABBREVIATE_TEMPLATE, + lastName == null ? "" : lastName, + firstName == null ? "" : firstName.substring(0, 1) + ".", + patronymic == null ? "" : patronymic.substring(0, 1) + "."); + } } diff --git a/src/main/java/ru/ulstu/user/repository/UserRepository.java b/src/main/java/ru/ulstu/user/repository/UserRepository.java index 2edc8aa..fc7a42c 100644 --- a/src/main/java/ru/ulstu/user/repository/UserRepository.java +++ b/src/main/java/ru/ulstu/user/repository/UserRepository.java @@ -2,6 +2,8 @@ package ru.ulstu.user.repository; import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import ru.ulstu.user.model.User; import java.util.Date; @@ -25,4 +27,11 @@ public interface UserRepository extends JpaRepository { @EntityGraph(attributePaths = "roles") User findOneWithRolesByLogin(String login); + + @Query("SELECT u FROM User u " + + "WHERE (YEAR(u.birthDate) - YEAR(CURRENT_DATE) < 35 OR :hasAge = FALSE) " + + "AND (u.degree = 'CANDIDATE' OR :hasDegree = FALSE)" + + "ORDER BY u.lastName") + List filterByAgeAndDegree(@Param("hasAge") boolean hasAge, + @Param("hasDegree") boolean hasDegree); } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 25d8e95..c98e4b7 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -324,4 +324,8 @@ public class UserService implements UserDetailsService { } return user; } + + public List filterByAgeAndDegree(boolean hasDegree, boolean hasAge) { + return userRepository.filterByAgeAndDegree(hasDegree, hasAge); + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fb1b116..038ddcf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -35,4 +35,5 @@ liquibase.change-log=classpath:db/changelog-master.xml ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.undead-user-login=admin ng-tracker.dev-mode=true -ng-tracker.use-https=false \ No newline at end of file +ng-tracker.use-https=false +ng-tracker.check-run=false \ No newline at end of file diff --git a/src/main/resources/db/changelog-20190402_000000-schema.xml b/src/main/resources/db/changelog-20190402_000000-schema.xml index 70a7991..1bbb256 100644 --- a/src/main/resources/db/changelog-20190402_000000-schema.xml +++ b/src/main/resources/db/changelog-20190402_000000-schema.xml @@ -14,12 +14,12 @@ - + - diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 800b2f1..22ba79a 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -24,4 +24,6 @@ + + \ No newline at end of file diff --git a/src/main/resources/public/css/agency.css b/src/main/resources/public/css/agency.css index 24680aa..e1cc226 100644 --- a/src/main/resources/public/css/agency.css +++ b/src/main/resources/public/css/agency.css @@ -777,11 +777,25 @@ ul.social-buttons li a:active, ul.social-buttons li a:focus, ul.social-buttons l box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05); } +@media (min-width: 1500px) { + .col-xl-3 { + max-width: 20%; + } + + .container { + max-width: 1340px; + } +} + .toolbar-button { width: 100%; margin: 5px; } +.img-fluid { + width: 100% !important; +} + /* --------------------------------------------------- FEEDBACK STYLE ----------------------------------------------------- */ diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 59545b5..cbc0019 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -18,47 +18,61 @@
- +
- +
- +

Incorrect title

+

-
-
- -
+
+ - + placeholder="Описание" + th:field="*{deadlines[__${rowStat.index}__].description}"/> + Удалить + alt="Удалить" + th:onclick="|$('#deadlines${rowStat.index}\\.description').val(''); + $('#deadlines${rowStat.index}\\.date').val(''); + $('#addDeadline').click();|"/>
-
+

Incorrect title

+

+
-
@@ -70,11 +84,13 @@
- +
- +
diff --git a/src/main/resources/templates/conferences/conferences.html b/src/main/resources/templates/conferences/conferences.html index c725f2b..fa88aaf 100644 --- a/src/main/resources/templates/conferences/conferences.html +++ b/src/main/resources/templates/conferences/conferences.html @@ -7,7 +7,7 @@
- +
@@ -19,7 +19,9 @@
- + +
+
diff --git a/src/main/resources/templates/conferences/fragments/confLineFragment.html b/src/main/resources/templates/conferences/fragments/confLineFragment.html index f54a777..317da03 100644 --- a/src/main/resources/templates/conferences/fragments/confLineFragment.html +++ b/src/main/resources/templates/conferences/fragments/confLineFragment.html @@ -6,9 +6,8 @@ From 1756f29505810ea8c65bd9ff41d7ae705f1f78da Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sat, 13 Apr 2019 12:39:53 +0400 Subject: [PATCH 10/15] #42 filter authors by leader and degree --- .../grant/controller/GrantController.java | 33 ++++-------- .../java/ru/ulstu/grant/model/GrantDto.java | 38 ++++++++++++- .../ulstu/grant/model/GrantUserFilterDto.java | 54 ------------------- .../grant/repository/GrantRepository.java | 3 -- .../ru/ulstu/grant/service/GrantService.java | 14 ++--- .../resources/templates/grants/grant.html | 25 ++++----- 6 files changed, 61 insertions(+), 106 deletions(-) delete mode 100644 src/main/java/ru/ulstu/grant/model/GrantUserFilterDto.java diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 638e013..82fc80e 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; -import ru.ulstu.grant.model.GrantUserFilterDto; import ru.ulstu.grant.service.GrantService; import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; @@ -26,7 +25,6 @@ import static org.springframework.util.StringUtils.isEmpty; import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE; import static ru.ulstu.core.controller.Navigation.GRANT_PAGE; import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; -import static ru.ulstu.core.controller.Navigation.hasErrors; @Controller() @@ -50,30 +48,23 @@ public class GrantController { } @GetMapping("/grant") - public void getGrant(ModelMap modelMap, GrantUserFilterDto grantUserFilterDto, @RequestParam(value = "id") Integer id) { + public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { modelMap.put("grantDto", grantService.findOneDto(id)); } else { modelMap.put("grantDto", new GrantDto()); } - modelMap.put("filteredAuthors", new GrantUserFilterDto(grantService.filterUsers(grantUserFilterDto), false, false, false)); } @PostMapping(value = "/grant", params = "save") - public String save(@Valid GrantDto grantDto, GrantUserFilterDto grantUserFilterDto, Errors errors, ModelMap modelMap /*@ModelAttribute List allAuthors*/) + public String save(@Valid GrantDto grantDto, Errors errors) throws IOException { filterEmptyDeadlines(grantDto); - modelMap.put("filteredAuthors", new GrantUserFilterDto(grantService.filterUsers(grantUserFilterDto), - grantUserFilterDto.isLeader(), - grantUserFilterDto.isBirthDate(), - grantUserFilterDto.isDegree())); if (grantDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } if (grantDto.getLeaderId().equals(null)) { errors.rejectValue("leader", "errorCode", "Укажите руководителя"); -// } else { -// allAuthors.remove(grantDto.getLeaderId()); } if (errors.hasErrors()) { return GRANT_PAGE; @@ -82,6 +73,11 @@ public class GrantController { return String.format(REDIRECT_TO, GRANTS_PAGE); } + @PostMapping(value = "/grant", params = "filterUsers") + public String filterUsers() { + return GRANT_PAGE; + } + @PostMapping(value = "/grant", params = "addDeadline") public String addDeadline(@Valid GrantDto grantDto, Errors errors) { filterEmptyDeadlines(grantDto); @@ -101,12 +97,6 @@ public class GrantController { return GRANT_PAGE; } -// @PostMapping(value = "/grant", params = "updateAuthors") -// public String updateAuthors(@ModelAttribute List allAuthors, @Valid GrantDto grantDto) { -// allAuthors.remove(grantDto.getLeaderId()); -// return GRANT_PAGE; -// } - @GetMapping("/delete/{grant-id}") public String delete(@PathVariable("grant-id") Integer grantId) throws IOException { grantService.delete(grantId); @@ -119,15 +109,10 @@ public class GrantController { } @ModelAttribute("allAuthors") - public List getAllAuthors() { - return grantService.getGrantAuthors(); + public List getAllAuthors(GrantDto grantDto) { + return grantService.getGrantAuthors(grantDto); } -// @ModelAttribute("allLeaders") -// public List getAllLeaders() { -// return grantService.getGrantAuthors(); -// } - 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/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index cc0f2da..1a3a2e0 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -29,6 +29,9 @@ public class GrantDto { private Set authorIds; private Set authors; private Integer leaderId; + private boolean leader; + private boolean birthDate; + private boolean degree; public GrantDto() { deadlines.add(new Deadline()); @@ -43,7 +46,10 @@ public class GrantDto { @JsonProperty("project") ProjectDto project, @JsonProperty("authorIds") Set authorIds, @JsonProperty("authors") Set authors, - @JsonProperty("leader") Integer leaderId) { + @JsonProperty("leader") Integer leaderId, + @JsonProperty("leader") boolean leader, + @JsonProperty("birthDate") boolean birthDate, + @JsonProperty("degree") boolean degree) { this.id = id; this.title = title; this.status = status; @@ -53,6 +59,9 @@ public class GrantDto { this.project = project; this.authors = authors; this.leaderId = leaderId; + this.leader = leader; + this.birthDate = birthDate; + this.degree = degree; } public GrantDto(Grant grant) { @@ -66,6 +75,9 @@ public class GrantDto { this.authorIds = convert(grant.getAuthors(), user -> user.getId()); this.authors = convert(grant.getAuthors(), UserDto::new); this.leaderId = grant.getLeader().getId(); + this.leader = false; + this.birthDate = false; + this.degree = false; } public Integer getId() { @@ -154,4 +166,28 @@ public class GrantDto { public void setLeaderId(Integer leaderId) { this.leaderId = leaderId; } + + public boolean isLeader() { + return leader; + } + + public void setLeader(boolean leader) { + this.leader = leader; + } + + public boolean isBirthDate() { + return birthDate; + } + + public void setBirthDate(boolean birthDate) { + this.birthDate = birthDate; + } + + public boolean isDegree() { + return degree; + } + + public void setDegree(boolean degree) { + this.degree = degree; + } } diff --git a/src/main/java/ru/ulstu/grant/model/GrantUserFilterDto.java b/src/main/java/ru/ulstu/grant/model/GrantUserFilterDto.java deleted file mode 100644 index 36f88f6..0000000 --- a/src/main/java/ru/ulstu/grant/model/GrantUserFilterDto.java +++ /dev/null @@ -1,54 +0,0 @@ -package ru.ulstu.grant.model; - -import ru.ulstu.user.model.UserDto; - -import java.util.List; - -public class GrantUserFilterDto { - private List users; - private boolean leader; - private boolean birthDate; - private boolean degree; - - public GrantUserFilterDto() { - } - - public GrantUserFilterDto(List users, boolean leader, boolean birthDate, boolean degree) { - this.users = users; - this.leader = leader; - this.birthDate = birthDate; - this.degree = degree; - } - - public List getUsers() { - return users; - } - - public void setUsers(List users) { - this.users = users; - } - - public boolean isLeader() { - return leader; - } - - public void setLeader(boolean leader) { - this.leader = leader; - } - - public boolean isBirthDate() { - return birthDate; - } - - public void setBirthDate(boolean birthDate) { - this.birthDate = birthDate; - } - - public boolean isDegree() { - return degree; - } - - public void setDegree(boolean degree) { - this.degree = degree; - } -} diff --git a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java index 68b31a6..44c2cc0 100644 --- a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java +++ b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java @@ -1,10 +1,7 @@ package ru.ulstu.grant.repository; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import ru.ulstu.grant.model.Grant; -import ru.ulstu.user.model.User; import java.util.List; diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 5474089..aa8ffac 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -8,13 +8,11 @@ import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; -import ru.ulstu.grant.model.GrantUserFilterDto; import ru.ulstu.grant.repository.GrantRepository; 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 ru.ulstu.user.model.UserDto; import ru.ulstu.user.service.UserService; import java.io.IOException; @@ -141,19 +139,15 @@ public class GrantService { } } - public List getGrantAuthors() { - return userService.findAll(); - } - - public List filterUsers(GrantUserFilterDto filterDto) { - List filteredUsers = userService.filterByAgeAndDegree(filterDto.isBirthDate(), filterDto.isDegree()); - if (filterDto.isLeader()) { + public List getGrantAuthors(GrantDto grantDto) { + List filteredUsers = userService.filterByAgeAndDegree(grantDto.isBirthDate(), grantDto.isDegree()); + if (grantDto.isLeader()) { filteredUsers = filteredUsers .stream() .filter(getCompletedGrantLeaders()::contains) .collect(Collectors.toList()); } - return convert(filteredUsers, UserDto::new); + return filteredUsers; } private List getCompletedGrantLeaders() { diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index ed9036d..05b2a03 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -8,7 +8,6 @@
-
@@ -95,22 +94,20 @@
- + th:field="*{leader}" th:onclick="|$('#filter').click();|"/>
+ th:field="*{birthDate}" th:onclick="|$('#filter').click();|"/>
-
+ th:field="*{degree}" th:onclick="|$('#filter').click();|"/> +
@@ -128,6 +125,8 @@
+
@@ -135,7 +134,7 @@ @@ -146,7 +145,7 @@ @@ -209,15 +208,13 @@
From 8b2a559d37452070792e049844fd32beac257f1e Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 13 Apr 2019 23:56:24 +0400 Subject: [PATCH 11/15] #42 fix thymeleaf expressions --- src/main/java/ru/ulstu/grant/model/GrantDto.java | 16 ++++++++-------- .../ru/ulstu/grant/service/GrantService.java | 2 +- .../ru/ulstu/user/repository/UserRepository.java | 2 +- src/main/resources/templates/grants/grant.html | 13 +++++++------ 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index 1a3a2e0..9ad9d21 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -29,7 +29,7 @@ public class GrantDto { private Set authorIds; private Set authors; private Integer leaderId; - private boolean leader; + private boolean wasLeader; private boolean birthDate; private boolean degree; @@ -47,7 +47,7 @@ public class GrantDto { @JsonProperty("authorIds") Set authorIds, @JsonProperty("authors") Set authors, @JsonProperty("leader") Integer leaderId, - @JsonProperty("leader") boolean leader, + @JsonProperty("wasLeader") boolean wasLeader, @JsonProperty("birthDate") boolean birthDate, @JsonProperty("degree") boolean degree) { this.id = id; @@ -59,7 +59,7 @@ public class GrantDto { this.project = project; this.authors = authors; this.leaderId = leaderId; - this.leader = leader; + this.wasLeader = wasLeader; this.birthDate = birthDate; this.degree = degree; } @@ -75,7 +75,7 @@ public class GrantDto { this.authorIds = convert(grant.getAuthors(), user -> user.getId()); this.authors = convert(grant.getAuthors(), UserDto::new); this.leaderId = grant.getLeader().getId(); - this.leader = false; + this.wasLeader = false; this.birthDate = false; this.degree = false; } @@ -167,12 +167,12 @@ public class GrantDto { this.leaderId = leaderId; } - public boolean isLeader() { - return leader; + public boolean isWasLeader() { + return wasLeader; } - public void setLeader(boolean leader) { - this.leader = leader; + public void setWasLeader(boolean wasLeader) { + this.wasLeader = wasLeader; } public boolean isBirthDate() { diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index aa8ffac..98b95c3 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -141,7 +141,7 @@ public class GrantService { public List getGrantAuthors(GrantDto grantDto) { List filteredUsers = userService.filterByAgeAndDegree(grantDto.isBirthDate(), grantDto.isDegree()); - if (grantDto.isLeader()) { + if (grantDto.isWasLeader()) { filteredUsers = filteredUsers .stream() .filter(getCompletedGrantLeaders()::contains) diff --git a/src/main/java/ru/ulstu/user/repository/UserRepository.java b/src/main/java/ru/ulstu/user/repository/UserRepository.java index fc7a42c..f6fbc62 100644 --- a/src/main/java/ru/ulstu/user/repository/UserRepository.java +++ b/src/main/java/ru/ulstu/user/repository/UserRepository.java @@ -29,7 +29,7 @@ public interface UserRepository extends JpaRepository { User findOneWithRolesByLogin(String login); @Query("SELECT u FROM User u " + - "WHERE (YEAR(u.birthDate) - YEAR(CURRENT_DATE) < 35 OR :hasAge = FALSE) " + + "WHERE (YEAR(CURRENT_DATE) - YEAR(u.birthDate) < 35 OR :hasAge = FALSE) " + "AND (u.degree = 'CANDIDATE' OR :hasDegree = FALSE)" + "ORDER BY u.lastName") List filterByAgeAndDegree(@Param("hasAge") boolean hasAge, diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 05b2a03..4a45cad 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -85,16 +85,17 @@
-
- -
+ +
+ th:field="*{wasLeader}" th:onclick="|$('#filter').click();|"/>
From 1e6b3cba3acc74c7777e27ef43f4cfe2e5509c12 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 17 Apr 2019 13:25:10 +0400 Subject: [PATCH 12/15] #42 delete blank lines, fix js, fix leaderId validation --- .../grant/controller/GrantController.java | 6 ++-- .../resources/templates/grants/grant.html | 28 ++++++++----------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 82fc80e..0731188 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -61,10 +61,10 @@ public class GrantController { throws IOException { filterEmptyDeadlines(grantDto); if (grantDto.getDeadlines().isEmpty()) { - errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); + errors.rejectValue("deadlines", "errorCode", "Не может быть пусто"); } - if (grantDto.getLeaderId().equals(null)) { - errors.rejectValue("leader", "errorCode", "Укажите руководителя"); + if (grantDto.getLeaderId().equals(-1)) { + errors.rejectValue("leaderId", "errorCode", "Укажите руководителя"); } if (errors.hasErrors()) { return GRANT_PAGE; diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 4a45cad..91a9c6d 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -33,7 +33,6 @@ class="alert alert-danger">Incorrect title

-
-
-
@@ -77,7 +74,6 @@
-
@@ -91,7 +87,8 @@ aria-expanded="false" aria-controls="collapse-filter">Фильтр рабочей группы -
+

-
- +

Choose leader

+

-
-

Incorrect member

-

Добавить статью

-
-
@@ -212,10 +208,8 @@ $("#authors").val('default'); $("#authors").selectpicker("refresh"); $("#authors").children('option:disabled').prop('disabled', false); - - var lid = document.getElementById("leader"); - var aut = document.getElementById("authors"); - aut.options[lid.selectedIndex].disabled="disabled"; + var lid = $("#leaderId option:selected").val(); + $("#authors [value='" + lid + "']").attr("disabled", "disabled"); }
From 506fa01fabb266d645e5389f2dcdbb81e2a30de4 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 17 Apr 2019 13:42:22 +0400 Subject: [PATCH 13/15] Revert: #42 merge with dev --- src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8a3366e..038ddcf 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ # Server Settings spring.main.banner-mode=off server.port=8443 -server.http.port=8888 +server.http.port=8080 spring.http.multipart.maxFileSize=20MB spring.http.multipart.maxRequestSize=20MB # Thymeleaf Settings @@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact # JPA Settings spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.username=postgres -spring.datasource.password=superuser +spring.datasource.password=postgres spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate # Liquibase Settings From e2842982005f2cf05ce62d9199c78a220df0d20b Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 18 Apr 2019 13:09:50 +0400 Subject: [PATCH 14/15] #42 rename variables --- .../java/ru/ulstu/grant/model/GrantDto.java | 32 +++++++++---------- .../ru/ulstu/grant/service/GrantService.java | 2 +- .../resources/templates/grants/grant.html | 6 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index 9ad9d21..aa8634b 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -30,8 +30,8 @@ public class GrantDto { private Set authors; private Integer leaderId; private boolean wasLeader; - private boolean birthDate; - private boolean degree; + private boolean hasAge; + private boolean hasDegree; public GrantDto() { deadlines.add(new Deadline()); @@ -48,8 +48,8 @@ public class GrantDto { @JsonProperty("authors") Set authors, @JsonProperty("leader") Integer leaderId, @JsonProperty("wasLeader") boolean wasLeader, - @JsonProperty("birthDate") boolean birthDate, - @JsonProperty("degree") boolean degree) { + @JsonProperty("hasAge") boolean hasAge, + @JsonProperty("hasDegree") boolean hasDegree) { this.id = id; this.title = title; this.status = status; @@ -60,8 +60,8 @@ public class GrantDto { this.authors = authors; this.leaderId = leaderId; this.wasLeader = wasLeader; - this.birthDate = birthDate; - this.degree = degree; + this.hasAge = hasAge; + this.hasDegree = hasDegree; } public GrantDto(Grant grant) { @@ -76,8 +76,8 @@ public class GrantDto { this.authors = convert(grant.getAuthors(), UserDto::new); this.leaderId = grant.getLeader().getId(); this.wasLeader = false; - this.birthDate = false; - this.degree = false; + this.hasAge = false; + this.hasDegree = false; } public Integer getId() { @@ -175,19 +175,19 @@ public class GrantDto { this.wasLeader = wasLeader; } - public boolean isBirthDate() { - return birthDate; + public boolean isHasAge() { + return hasAge; } - public void setBirthDate(boolean birthDate) { - this.birthDate = birthDate; + public void setHasAge(boolean hasAge) { + this.hasAge = hasAge; } - public boolean isDegree() { - return degree; + public boolean isHasDegree() { + return hasDegree; } - public void setDegree(boolean degree) { - this.degree = degree; + public void setHasDegree(boolean hasDegree) { + this.hasDegree = hasDegree; } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 98b95c3..8427da3 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -140,7 +140,7 @@ public class GrantService { } public List getGrantAuthors(GrantDto grantDto) { - List filteredUsers = userService.filterByAgeAndDegree(grantDto.isBirthDate(), grantDto.isDegree()); + List filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree()); if (grantDto.isWasLeader()) { filteredUsers = filteredUsers .stream() diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 91a9c6d..86dbde1 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -87,7 +87,7 @@ aria-expanded="false" aria-controls="collapse-filter">Фильтр рабочей группы -
@@ -97,14 +97,14 @@
+ th:field="*{hasAge}" th:onclick="|$('#filter').click();|"/>
+ th:field="*{hasDegree}" th:onclick="|$('#filter').click();|"/>
From 958a0d461b9cfe94081f178e97487a8469355310 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 18 Apr 2019 22:35:07 +0400 Subject: [PATCH 15/15] #42 merge with dev --- src/main/resources/templates/projects/project.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index 3d356a7..0e40e87 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -1,7 +1,7 @@ + layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> @@ -19,7 +19,8 @@
-
@@ -55,7 +56,7 @@
- +
@@ -88,7 +89,8 @@ class="alert alert-danger">Incorrect title

-
@@ -107,7 +109,8 @@ type="submit"> Сохранить -
@@ -135,6 +138,7 @@ $('.selectpicker').selectpicker(); }); /*]]>*/ +