From 8fbce550286d4dcd6ba02dce5104690653f8cdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Wed, 17 Apr 2019 11:04:35 +0300 Subject: [PATCH 001/251] #86 projects main page --- .../project/controller/ProjectController.java | 39 +++++++++++++++++++ .../ulstu/project/service/ProjectService.java | 9 +++++ src/main/resources/templates/index.html | 2 +- .../templates/projects/dashboard.html | 24 ++++++++++++ .../fragments/projectNavigationFragment.html | 26 +++++++++++++ .../templates/projects/projects.html | 33 ++++++++++++++++ 6 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/ulstu/project/controller/ProjectController.java create mode 100644 src/main/resources/templates/projects/dashboard.html create mode 100644 src/main/resources/templates/projects/fragments/projectNavigationFragment.html create mode 100644 src/main/resources/templates/projects/projects.html diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java new file mode 100644 index 0000000..5b5eb4a --- /dev/null +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -0,0 +1,39 @@ +package ru.ulstu.project.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.*; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.project.model.Project; +import ru.ulstu.project.model.ProjectDto; +import ru.ulstu.project.service.ProjectService; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; + +import static liquibase.util.StringUtils.isEmpty; + +@Controller() +@RequestMapping(value = "/projects") +@ApiIgnore +public class ProjectController { + private final ProjectService projectService; + + public ProjectController(ProjectService projectService) { + this.projectService = projectService; + } + + @GetMapping("/dashboard") + public void getDashboard(ModelMap modelMap) { + modelMap.put("projects", projectService.findAllDto()); + } + + @GetMapping("/projects") + public void getProjects(ModelMap modelMap) { + modelMap.put("projects", projectService.findAllDto()); + } +} diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index b54a60a..78a9d3c 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -2,6 +2,7 @@ package ru.ulstu.project.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -10,9 +11,11 @@ import ru.ulstu.project.repository.ProjectRepository; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; +import static ru.ulstu.core.util.StreamApiUtils.convert; @Service public class ProjectService { + private final static int MAX_DISPLAY_SIZE = 40; private final ProjectRepository projectRepository; private final DeadlineService deadlineService; @@ -27,6 +30,12 @@ public class ProjectService { return projectRepository.findAll(); } + public List findAllDto() { + List projects = convert(findAll(), ProjectDto::new); + projects.forEach(projectDto -> projectDto.setTitle(StringUtils.abbreviate(projectDto.getTitle(), MAX_DISPLAY_SIZE))); + return projects; + } + @Transactional public Project create(ProjectDto projectDto) { Project newProject = copyFromDto(new Project(), projectDto); diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 2d86945..6ca1c12 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -46,7 +46,7 @@
- +
diff --git a/src/main/resources/templates/projects/dashboard.html b/src/main/resources/templates/projects/dashboard.html new file mode 100644 index 0000000..882c202 --- /dev/null +++ b/src/main/resources/templates/projects/dashboard.html @@ -0,0 +1,24 @@ + + + + + +
+
+
+
+

Проекты

+
+
+
+ +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/fragments/projectNavigationFragment.html b/src/main/resources/templates/projects/fragments/projectNavigationFragment.html new file mode 100644 index 0000000..c26d8b8 --- /dev/null +++ b/src/main/resources/templates/projects/fragments/projectNavigationFragment.html @@ -0,0 +1,26 @@ + + + + + + +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/projects.html b/src/main/resources/templates/projects/projects.html new file mode 100644 index 0000000..0336770 --- /dev/null +++ b/src/main/resources/templates/projects/projects.html @@ -0,0 +1,33 @@ + + + + + +
+
+ +
+
+
+
+

Проекты

+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ + From 9da227ab34ae7a8b9ab38843b645cd4618025f32 Mon Sep 17 00:00:00 2001 From: ASH Date: Thu, 18 Apr 2019 21:38:55 +0400 Subject: [PATCH 002/251] #76 fixing dashboard --- src/main/resources/templates/students/dashboard.html | 7 +++---- .../templates/students/fragments/taskStatusFragment.html | 3 --- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/resources/templates/students/dashboard.html b/src/main/resources/templates/students/dashboard.html index 94ea121..78e749c 100644 --- a/src/main/resources/templates/students/dashboard.html +++ b/src/main/resources/templates/students/dashboard.html @@ -14,10 +14,9 @@

-
- - - + +
+
diff --git a/src/main/resources/templates/students/fragments/taskStatusFragment.html b/src/main/resources/templates/students/fragments/taskStatusFragment.html index 77fd529..d8ef4f4 100644 --- a/src/main/resources/templates/students/fragments/taskStatusFragment.html +++ b/src/main/resources/templates/students/fragments/taskStatusFragment.html @@ -6,9 +6,6 @@ - - -
From 59887e5141b343d578f9f391d9fb457c8180aa77 Mon Sep 17 00:00:00 2001 From: ASH Date: Thu, 18 Apr 2019 21:57:56 +0400 Subject: [PATCH 003/251] #76 delete function added --- .../java/ru/ulstu/students/controller/TaskController.java | 7 +++++++ src/main/java/ru/ulstu/students/service/TaskService.java | 6 ++++-- src/main/resources/public/js/tasks.js | 2 +- src/main/resources/templates/students/tasks.html | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/students/controller/TaskController.java b/src/main/java/ru/ulstu/students/controller/TaskController.java index 8fd9575..ef602e2 100644 --- a/src/main/java/ru/ulstu/students/controller/TaskController.java +++ b/src/main/java/ru/ulstu/students/controller/TaskController.java @@ -71,6 +71,13 @@ public class TaskController { return TASK_PAGE; } + @GetMapping("/delete/{task-id}") + public String delete(@PathVariable("task-id") Integer taskId) throws IOException { + taskService.delete(taskId); + return String.format(REDIRECT_TO, TASKS_PAGE); + } + + @ModelAttribute("allStatuses") public List getTaskStatuses() { return taskService.getTaskStatuses(); diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index 7b67a44..d400fa6 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -76,8 +76,10 @@ public class TaskService { @Transactional public void delete(Integer taskId) throws IOException { - Task task = taskRepository.findOne(taskId); - taskRepository.delete(task); + if (taskRepository.exists(taskId)) { + taskRepository.delete(taskId); + } + } public void save(TaskDto taskDto) throws IOException { diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index b333c31..f756199 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -90,7 +90,7 @@ $(document).ready(function () { '
-
+
+ +

+
+
From d4b514a9b0631d287314d990ea21f685497f5c27 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 21:24:32 +0400 Subject: [PATCH 034/251] #68 added ping in db --- .../ru/ulstu/conference/repository/ConferenceRepository.java | 5 +++++ .../java/ru/ulstu/conference/service/ConferenceService.java | 4 ++-- src/main/java/ru/ulstu/ping/model/Ping.java | 2 -- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index cb8a488..25a481c 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -1,6 +1,7 @@ package ru.ulstu.conference.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; @@ -16,4 +17,8 @@ public interface ConferenceRepository extends JpaRepository @Query("SELECT c FROM Conference c WHERE c.beginDate > :date") List findAllActive(@Param("date") Date date); + + @Modifying + @Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id") + int updatePingConference(@Param("id") Integer id); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 0287e31..370d7d6 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -146,7 +146,6 @@ public class ConferenceService { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); - Integer pingCount = conferenceDto.getPing() - conference.getPing(); // for notification conference.setPing(conference.getPing()); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); @@ -180,9 +179,10 @@ public class ConferenceService { return conferenceRepository.findAllActive(new Date()); } + @Transactional public void ping(ConferenceDto conferenceDto) throws IOException { pingService.addPing(findOne(conferenceDto.getId())); -// conferenceDto.setPing(conferenceDto.getPing() + 1); + conferenceRepository.updatePingConference(conferenceDto.getId()); } public Conference findOne(Integer conferenceId) { diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java index 5ab0860..c7e4c5e 100644 --- a/src/main/java/ru/ulstu/ping/model/Ping.java +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -1,7 +1,6 @@ package ru.ulstu.ping.model; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sun.istack.internal.Nullable; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; @@ -26,7 +25,6 @@ public class Ping extends BaseEntity { @JoinColumn(name = "users_id") private User user; - @Nullable @ManyToOne(optional = false) @JoinColumn(name = "conference_id") private Conference conference; From 70d260c34b7196f3921c0ad092d17f90def836a4 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 21:52:13 +0400 Subject: [PATCH 035/251] #68 ping but style --- .../conference/controller/ConferenceController.java | 2 +- src/main/resources/public/css/conference.css | 10 ++++++++++ .../resources/templates/conferences/conference.html | 7 ++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 01eac3b..8da0cce 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -126,7 +126,7 @@ public class ConferenceController { return CONFERENCE_PAGE; } - @PostMapping(value = "/conference", params = "ping") + @PostMapping(value = "/conference", params = "pingConference") public String ping(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { if (errors.hasErrors()) { return CONFERENCE_PAGE; diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index ad06b3c..8572b08 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -77,6 +77,16 @@ body { border-right: 1px solid #ced4da; } +#ping-button[disabled=disabled] { + background-color: #ced4da; + border-color: #c2c5c7; +} + +#ping-button[disabled=disabled]:hover { + background-color: #737475 !important; + border-color: #5d5e5f !important; +} + #take-part[disabled=disabled] { background-color: #ced4da; border-color: #c2c5c7; diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 26fa695..9cd9c38 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -122,9 +122,10 @@
- - + + Date: Wed, 24 Apr 2019 22:34:56 +0400 Subject: [PATCH 036/251] #68 added dashboard-card styles depending on the conference.ping count --- src/main/resources/public/css/conference.css | 16 ++++++++++++++++ .../fragments/confDashboardFragment.html | 11 ++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index 8572b08..5a50b65 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -163,6 +163,22 @@ body { float: right; } +.note-1 { + background-color: #bfffce; +} + +.note-2 { + background-color: #eaffb4; +} + +.note-3 { + background-color: #fff69f; +} + +.note-4 { + background-color: #ff9973; +} + @media (max-width: 1199px) and (min-width: 768px){ .paper-control { display: block!important; diff --git a/src/main/resources/templates/conferences/fragments/confDashboardFragment.html b/src/main/resources/templates/conferences/fragments/confDashboardFragment.html index 17f4aa6..5aabef2 100644 --- a/src/main/resources/templates/conferences/fragments/confDashboardFragment.html +++ b/src/main/resources/templates/conferences/fragments/confDashboardFragment.html @@ -4,12 +4,13 @@ -
+
-
- -
-
+

From 8ced83ad2b6509341058a11a2c9621f3dac8e72d Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 25 Apr 2019 13:23:36 +0400 Subject: [PATCH 037/251] #116 delete annotation --- src/main/java/ru/ulstu/grant/model/Grant.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index c8bdd8a..abd61ac 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -64,8 +64,6 @@ public class Grant extends BaseEntity implements UserContainer { @OrderBy("date") private List deadlines = new ArrayList<>(); - //Описание гранта - @NotNull private String comment; //Заявка на грант From 7c5a0826c5aaac19a356922d47e8d2e21ed84e7a Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 25 Apr 2019 13:24:36 +0400 Subject: [PATCH 038/251] #116 add new variable --- src/main/java/ru/ulstu/grant/model/GrantDto.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index d979e23..3fb77c5 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -35,6 +35,7 @@ public class GrantDto { private boolean hasDegree; private List paperIds = new ArrayList<>(); private List papers = new ArrayList<>(); + private List removedDeadlineIds = new ArrayList<>(); public GrantDto() { deadlines.add(new Deadline()); @@ -215,4 +216,12 @@ public class GrantDto { public void setPapers(List papers) { this.papers = papers; } + + public List getRemovedDeadlineIds() { + return removedDeadlineIds; + } + + public void setRemovedDeadlineIds(List removedDeadlineIds) { + this.removedDeadlineIds = removedDeadlineIds; + } } From 4fa0c14ae62904f2e4509c5784c44752d6f8fb6a Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 25 Apr 2019 13:25:32 +0400 Subject: [PATCH 039/251] #116 add removeDeadline method --- .../java/ru/ulstu/grant/controller/GrantController.java | 8 ++++++++ src/main/java/ru/ulstu/grant/service/GrantService.java | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 92ce826..85a0cd9 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -97,6 +97,14 @@ public class GrantController { return GRANT_PAGE; } + @PostMapping(value = "/grant", params = "removeDeadline") + public String removeDeadline(GrantDto grantDto, + @RequestParam(value = "removeDeadline") Integer deadlineId) { + grantService.removeDeadline(grantDto, deadlineId); + return GRANT_PAGE; + } + + @PostMapping(value = "/grant", params = "createProject") public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException { if (errors.hasErrors()) { diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 1f0b6ce..cabed80 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -109,6 +109,7 @@ public class GrantService { if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) { fileService.deleteFile(grant.getApplication()); } + grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove); grantRepository.save(copyFromDto(grant, grantDto)); return grant.getId(); } @@ -184,4 +185,12 @@ public class GrantService { grantDto.getPapers().clear(); } } + + public void removeDeadline(GrantDto grantDto, Integer deadlineId) { + if (grantDto.getDeadlines().get(deadlineId).getId() != null) { + grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId()); + } + grantDto.getDeadlines().remove((int) deadlineId); + } + } From 2bb5189fff7e80b2921857e996346d0d02410903 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 25 Apr 2019 13:25:56 +0400 Subject: [PATCH 040/251] #116 update view --- src/main/resources/templates/grants/grant.html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index f66c74c..8ac81ab 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -48,6 +48,7 @@
+
@@ -59,12 +60,14 @@ th:field="*{deadlines[__${rowStat.index}__].description}"/>
- - +

Date: Thu, 25 Apr 2019 13:26:40 +0400 Subject: [PATCH 041/251] #116 add style for delete icon --- src/main/resources/public/css/grant.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/resources/public/css/grant.css b/src/main/resources/public/css/grant.css index 2176acf..3c0cfc8 100644 --- a/src/main/resources/public/css/grant.css +++ b/src/main/resources/public/css/grant.css @@ -24,4 +24,8 @@ height: 22px; width: 22px; margin: 3px; +} + +.btn-delete-deadline { + color: black; } \ No newline at end of file From c489ebbf9149da82f7ab1364b52c883131c02c24 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 25 Apr 2019 17:12:39 +0400 Subject: [PATCH 042/251] #70 added create notification for all users about new conference --- .../ru/ulstu/conference/model/Conference.java | 20 +++++ .../ConferenceNotificationService.java | 73 +++++++++++++++++++ .../conference/service/ConferenceService.java | 6 +- .../conferenceCreateNotification.html | 30 ++++++++ .../templates/conferences/conference.html | 5 +- 5 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/mail_templates/conferenceCreateNotification.html diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 3f77699..126c1bc 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -21,8 +21,10 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import java.util.ArrayList; +import java.util.Comparator; import java.util.Date; import java.util.List; +import java.util.Optional; @Entity @Table(name = "conference") @@ -135,4 +137,22 @@ public class Conference extends BaseEntity { public void setUsers(List users) { this.users = users; } + + public Optional getNextDeadline() { + return deadlines + .stream() + .filter(deadline -> deadline.getDate() != null) + .sorted(Comparator.comparing(Deadline::getDate)) + .filter(d -> d.getDate().after(new Date())) + .findFirst(); + } + + public boolean lastDeadlineFailed() { + return !deadlines + .stream() + .filter(deadline -> deadline.getDate() != null) + .filter(d -> d.getDate().after(new Date())) + .findAny() + .isPresent(); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index ff9f69a..c69d862 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -1,7 +1,80 @@ package ru.ulstu.conference.service; +import com.google.common.collect.ImmutableMap; import org.springframework.stereotype.Service; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.core.util.DateUtils; +import ru.ulstu.user.service.MailService; +import ru.ulstu.user.service.UserService; + +import java.util.Date; +import java.util.List; +import java.util.Map; @Service public class ConferenceNotificationService { + + private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; + private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification"; + private final static String TEMPLATE_CREATE_CONFERENCE = "conferenceCreateNotification"; + private final static String TEMPLATE_STATUS_CHANGED = "conferenceChangeNotification"; + private final static String TEMPLATE_FAILED = "conferenceFailedNotification"; + + private final static String TITLE_DEADLINE = "Приближается дедлайн конференции"; + private final static String TITLE_CREATE = "Создана новая конференция: %s"; + private final static String TITLE_STATUS_CHANGED = "Изменения в конференции"; + private final static String TITLE_FAILED = "Статья провалена"; + + + private final MailService mailService; + private final UserService userService; + + public ConferenceNotificationService(MailService mailService, + UserService userService) { + this.mailService = mailService; + this.userService = userService; + } + + public void sendDeadlineNotifications(List conferences, boolean isDeadlineBeforeWeek) { + Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION); + conferences + .stream() + .filter(conference -> needToSendDeadlineNotification(conference, now, isDeadlineBeforeWeek)) + .forEach(conference -> sendMessageDeadline(conference)); + } + + private boolean needToSendDeadlineNotification(Conference conference, Date compareDate, boolean isDeadlineBeforeWeek) { + return (conference.getNextDeadline().isPresent()) + && (compareDate.before(conference.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek + || compareDate.after(conference.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek) + && conference.getNextDeadline().get().getDate().after(new Date()); + } + + private void sendMessageDeadline(Conference conference) { + Map variables = ImmutableMap.of("conference", conference); + sendForAllParticipals(variables, conference, TEMPLATE_DEADLINE, TITLE_DEADLINE); + } + + public void sendCreateNotification(Conference conference) { + Map variables = ImmutableMap.of("conference", conference); + sendForAllUsers(variables, TEMPLATE_CREATE_CONFERENCE, String.format(TITLE_CREATE, conference.getTitle())); + } + + // public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) { +// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); +// sendForAllParticipals(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED); +// } +// +// public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) { +// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); +// sendForAllParticipals(variables, paper, TEMPLATE_FAILED, TITLE_FAILED); +// } + + private void sendForAllUsers(Map variables, String template, String title) { + userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, template, title)); + } + + private void sendForAllParticipals(Map variables, Conference conference, String template, String title) { + conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title)); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 905c208..bed0deb 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -36,19 +36,22 @@ public class ConferenceService { private final PaperService paperService; private final UserService userService; private final PingService pingService; + private final ConferenceNotificationService conferenceNotificationService; public ConferenceService(ConferenceRepository conferenceRepository, ConferenceUserService conferenceUserService, DeadlineService deadlineService, PaperService paperService, UserService userService, - PingService pingService) { + PingService pingService, + ConferenceNotificationService conferenceNotificationService) { this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; this.paperService = paperService; this.userService = userService; this.pingService = pingService; + this.conferenceNotificationService = conferenceNotificationService; } public ConferenceDto getExistConferenceById(Integer id) { @@ -91,6 +94,7 @@ public class ConferenceService { public Integer create(ConferenceDto conferenceDto) throws IOException { Conference newConference = copyFromDto(new Conference(), conferenceDto); newConference = conferenceRepository.save(newConference); + conferenceNotificationService.sendCreateNotification(newConference); return newConference.getId(); } diff --git a/src/main/resources/mail_templates/conferenceCreateNotification.html b/src/main/resources/mail_templates/conferenceCreateNotification.html new file mode 100644 index 0000000..055e85d --- /dev/null +++ b/src/main/resources/mail_templates/conferenceCreateNotification.html @@ -0,0 +1,30 @@ + + + + Уведомление о создании конференции + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Была создана новая конференция: " + Title". +
+ Спешите принять участие! +

+

+ Даты проведения: + + - + . +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 2d93a5e..69c754a 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -1,7 +1,7 @@ + layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> @@ -135,7 +135,6 @@
-
@@ -148,8 +147,6 @@ Имя статьи - - From 16e9bf1fb56c092e6a57fc7afa45306f18a6f406 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 25 Apr 2019 19:15:19 +0400 Subject: [PATCH 043/251] #70 added update notification for all participants --- .../ConferenceNotificationService.java | 25 ++++++++---- .../conference/service/ConferenceService.java | 40 +++++++++++++++++++ .../conferenceUpdateDatesNotification.html | 31 ++++++++++++++ ...conferenceUpdateDeadlinesNotification.html | 24 +++++++++++ 4 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/mail_templates/conferenceUpdateDatesNotification.html create mode 100644 src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index c69d862..39472aa 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -16,15 +16,14 @@ public class ConferenceNotificationService { private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification"; - private final static String TEMPLATE_CREATE_CONFERENCE = "conferenceCreateNotification"; - private final static String TEMPLATE_STATUS_CHANGED = "conferenceChangeNotification"; - private final static String TEMPLATE_FAILED = "conferenceFailedNotification"; + private final static String TEMPLATE_CREATE = "conferenceCreateNotification"; + private final static String TEMPLATE_UPDATE_DEADLINES = "conferenceUpdateDeadlinesNotification"; + private final static String TEMPLATE_UPDATE_DATES = "conferenceUpdateDatesNotification"; private final static String TITLE_DEADLINE = "Приближается дедлайн конференции"; private final static String TITLE_CREATE = "Создана новая конференция: %s"; - private final static String TITLE_STATUS_CHANGED = "Изменения в конференции"; - private final static String TITLE_FAILED = "Статья провалена"; - + private final static String TITLE_UPDATE_DEADLINES = "Изменения дедлайнов в конференции: %s"; + private final static String TITLE_UPDATE_DATES = "Изменение дат проведения конференции: %s"; private final MailService mailService; private final UserService userService; @@ -57,7 +56,17 @@ public class ConferenceNotificationService { public void sendCreateNotification(Conference conference) { Map variables = ImmutableMap.of("conference", conference); - sendForAllUsers(variables, TEMPLATE_CREATE_CONFERENCE, String.format(TITLE_CREATE, conference.getTitle())); + sendForAllUsers(variables, TEMPLATE_CREATE, String.format(TITLE_CREATE, conference.getTitle())); + } + + public void updateDeadlineNotification(Conference conference) { + Map variables = ImmutableMap.of("conference", conference); + sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DEADLINES, String.format(TITLE_UPDATE_DEADLINES, conference.getTitle())); + } + + public void updateConferencesDatesNotification(Conference conference, Date oldBeginDate, Date oldEndDate) { + Map variables = ImmutableMap.of("conference", conference, "oldBeginDate", oldBeginDate, "oldEndDate", oldEndDate); + sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle())); } // public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) { @@ -77,4 +86,6 @@ public class ConferenceNotificationService { private void sendForAllParticipals(Map variables, Conference conference, String template, String title) { conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title)); } + + } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index bed0deb..af43ae9 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -10,6 +10,7 @@ import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; +import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; @@ -22,6 +23,7 @@ import java.util.ArrayList; 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; @@ -101,7 +103,13 @@ public class ConferenceService { @Transactional public Integer update(ConferenceDto conferenceDto) throws IOException { Conference conference = conferenceRepository.findOne(conferenceDto.getId()); + List oldDeadlines = conference.getDeadlines().stream() + .map(this::copyDeadline) + .collect(Collectors.toList()); + Date oldBeginDate = conference.getBeginDate(); + Date oldEndDate = conference.getEndDate(); conferenceRepository.save(copyFromDto(conference, conferenceDto)); + sendNotificationAfterUpdate(conference, oldDeadlines, oldBeginDate, oldEndDate); conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove); return conference.getId(); } @@ -228,4 +236,36 @@ public class ConferenceService { modelMap.addAttribute("nearshoreSales", nearshoreSales); modelMap.addAttribute("offshoreSales", offshoreSales); } + + public void sendNotificationAfterUpdate(Conference conference, List oldDeadlines, Date oldBeginDate, Date oldEndDate) { + boolean isSendNotificationAboutDeadlines = false; + if (oldDeadlines.size() != conference.getDeadlines().size()) { + isSendNotificationAboutDeadlines = true; + } + for (Deadline deadline : conference.getDeadlines()) { + if (isSendNotificationAboutDeadlines) { + break; + } + for (Deadline oldDeadline : oldDeadlines) { + if (deadline.getId().equals(oldDeadline.getId())) { + if (!deadline.getDescription().equals(oldDeadline.getDescription()) || !deadline.getDate().equals(oldDeadline.getDate())) { + isSendNotificationAboutDeadlines = true; + break; + } + } + } + } + if (isSendNotificationAboutDeadlines) { + conferenceNotificationService.updateDeadlineNotification(conference); + } + if (!conference.getBeginDate().equals(oldBeginDate) || !conference.getEndDate().equals(oldEndDate)) { + conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate); + } + } + + public Deadline copyDeadline(Deadline oldDeadline) { + Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription()); + newDeadline.setId(oldDeadline.getId()); + return newDeadline; + } } diff --git a/src/main/resources/mail_templates/conferenceUpdateDatesNotification.html b/src/main/resources/mail_templates/conferenceUpdateDatesNotification.html new file mode 100644 index 0000000..479336f --- /dev/null +++ b/src/main/resources/mail_templates/conferenceUpdateDatesNotification.html @@ -0,0 +1,31 @@ + + + + Уведомление об изменении дат проведения конференции + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Даты проведения конференции " + Title" изменились с
+ "oldBeginDate" + - + "oldEndDate" +
+ + на
+ "" + - + "". +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file diff --git a/src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html b/src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html new file mode 100644 index 0000000..f010fb8 --- /dev/null +++ b/src/main/resources/mail_templates/conferenceUpdateDeadlinesNotification.html @@ -0,0 +1,24 @@ + + + + Уведомление об изменении дедлайнов конференции + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Дедлайны конференции " + Title" притерпели изменения. +
+ Ознакомтесь с изменениями. +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file From 34925b81ffc1fc03cbfa7ca5c798921483447b7d Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 25 Apr 2019 21:17:48 +0400 Subject: [PATCH 044/251] #70 added schedule for deadline of conference --- .../ConferenceNotificationService.java | 12 +----- .../service/ConferenceScheduler.java | 37 +++++++++++++++++++ .../conferenceDeadlineNotification.html | 29 +++++++++++++++ 3 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java create mode 100644 src/main/resources/mail_templates/conferenceDeadlineNotification.html diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index 39472aa..54faa49 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -39,7 +39,7 @@ public class ConferenceNotificationService { conferences .stream() .filter(conference -> needToSendDeadlineNotification(conference, now, isDeadlineBeforeWeek)) - .forEach(conference -> sendMessageDeadline(conference)); + .forEach(this::sendMessageDeadline); } private boolean needToSendDeadlineNotification(Conference conference, Date compareDate, boolean isDeadlineBeforeWeek) { @@ -69,16 +69,6 @@ public class ConferenceNotificationService { sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle())); } - // public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) { -// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); -// sendForAllParticipals(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED); -// } -// -// public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) { -// Map variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus); -// sendForAllParticipals(variables, paper, TEMPLATE_FAILED, TITLE_FAILED); -// } - private void sendForAllUsers(Map variables, String template, String title) { userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, template, title)); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java new file mode 100644 index 0000000..ead2913 --- /dev/null +++ b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java @@ -0,0 +1,37 @@ +package ru.ulstu.conference.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class ConferenceScheduler { + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; + + private final Logger log = LoggerFactory.getLogger(ConferenceScheduler.class); + + private final ConferenceNotificationService conferenceNotificationService; + private final ConferenceService conferenceService; + + public ConferenceScheduler(ConferenceNotificationService conferenceNotificationService, + ConferenceService conferenceService) { + this.conferenceNotificationService = conferenceNotificationService; + this.conferenceService = conferenceService; + } + + + @Scheduled(cron = "0 0 21-22 * * *", zone = "Europe/Samara") + public void checkDeadlineBeforeWeek() { + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); + conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); + } + + @Scheduled(cron = "0 0 21-22 * * ?", zone = "Europe/Samara") + public void checkDeadlineAfterWeek() { + log.debug("ConferenceScheduler.checkDeadlineAfterWeek started"); + conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("ConferenceScheduler.checkDeadlineAfterWeek finished"); + } +} diff --git a/src/main/resources/mail_templates/conferenceDeadlineNotification.html b/src/main/resources/mail_templates/conferenceDeadlineNotification.html new file mode 100644 index 0000000..77c89b1 --- /dev/null +++ b/src/main/resources/mail_templates/conferenceDeadlineNotification.html @@ -0,0 +1,29 @@ + + + + Уведомление о дедлайне конференции + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Приближается дедлайн конференции " + Title". +

+

+ Срок исполнения: . +

+ +

+ Примечание: . +

+

+ Regards, +
+ NG-tracker. +

+ + From 71ec7bb7261d708e7a3aaf8bf934dd54157f2709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Thu, 25 Apr 2019 22:08:24 +0400 Subject: [PATCH 045/251] #108 add reference dto --- .../ru/ulstu/paper/model/ReferenceDto.java | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/main/java/ru/ulstu/paper/model/ReferenceDto.java diff --git a/src/main/java/ru/ulstu/paper/model/ReferenceDto.java b/src/main/java/ru/ulstu/paper/model/ReferenceDto.java new file mode 100644 index 0000000..8d71ae5 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/model/ReferenceDto.java @@ -0,0 +1,129 @@ +package ru.ulstu.paper.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ReferenceDto { + public enum ReferenceType { + ARTICLE("Статья"), + BOOK("Книга"); + + private String typeName; + + ReferenceType(String name) { + this.typeName = name; + } + + public String getTypeName() { + return typeName; + } + } + + public enum FormatStandard { + GOST("ГОСТ"), + SPRINGER("Springer"); + + private String standardName; + + FormatStandard(String name) { + this.standardName = name; + } + + public String getStandardName() { + return standardName; + } + } + + private String authors; + private String publicationTitle; + private Integer publicationYear; + private String publisher; + private String pages; + private String journalOrCollectionTitle; + private ReferenceType referenceType; + private FormatStandard formatStandard; + + @JsonCreator + public ReferenceDto( + @JsonProperty("authors") String authors, + @JsonProperty("publicationTitle") String publicationTitle, + @JsonProperty("publicationYear") Integer publicationYear, + @JsonProperty("publisher") String publisher, + @JsonProperty("pages") String pages, + @JsonProperty("journalOrCollectionTitle") String journalOrCollectionTitle, + @JsonProperty("referenceType") ReferenceType referenceType, + @JsonProperty("formatStandard") FormatStandard formatStandard) { + this.authors = authors; + this.publicationTitle = publicationTitle; + this.publicationYear = publicationYear; + this.publisher = publisher; + this.pages = pages; + this.journalOrCollectionTitle = journalOrCollectionTitle; + this.referenceType = referenceType; + this.formatStandard = formatStandard; + } + + public String getAuthors() { + return authors; + } + + public void setAuthors(String authors) { + this.authors = authors; + } + + public String getPublicationTitle() { + return publicationTitle; + } + + public void setPublicationTitle(String publicationTitle) { + this.publicationTitle = publicationTitle; + } + + public Integer getPublicationYear() { + return publicationYear; + } + + public void setPublicationYear(Integer publicationYear) { + this.publicationYear = publicationYear; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + public String getPages() { + return pages; + } + + public void setPages(String pages) { + this.pages = pages; + } + + public String getJournalOrCollectionTitle() { + return journalOrCollectionTitle; + } + + public void setJournalOrCollectionTitle(String journalOrCollectionTitle) { + this.journalOrCollectionTitle = journalOrCollectionTitle; + } + + public ReferenceType getReferenceType() { + return referenceType; + } + + public void setReferenceType(ReferenceType referenceType) { + this.referenceType = referenceType; + } + + public FormatStandard getFormatStandard() { + return formatStandard; + } + + public void setFormatStandard(FormatStandard formatStandard) { + this.formatStandard = formatStandard; + } +} From 8f3e3fd9a780dbe9b576eceea89dd97c553199f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Fri, 26 Apr 2019 00:00:01 +0400 Subject: [PATCH 046/251] #108 add formatting methods --- .../paper/controller/PaperRestController.java | 6 ++++ .../ru/ulstu/paper/service/PaperService.java | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java index d98ba98..6da009f 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -12,6 +12,7 @@ import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.Response; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; +import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.service.PaperService; import javax.validation.Valid; @@ -66,4 +67,9 @@ public class PaperRestController { public Response> getFormattedPaperList() { return new Response<>(paperService.getFormattedPaperList()); } + + @PostMapping("/getFormattedReference") + public Response getFormattedReference(@RequestBody @Valid ReferenceDto referenceDto) { + return new Response<>(paperService.getFormattedReference(referenceDto)); + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 325e377..3db7c84 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -10,12 +10,14 @@ import ru.ulstu.file.service.FileService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; +import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.text.MessageFormat; import java.util.Arrays; import java.util.Date; import java.util.HashSet; @@ -32,6 +34,9 @@ import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT; import static ru.ulstu.paper.model.Paper.PaperStatus.FAILED; import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION; import static ru.ulstu.paper.model.Paper.PaperType.OTHER; +import static ru.ulstu.paper.model.ReferenceDto.FormatStandard.GOST; +import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.ARTICLE; +import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.BOOK; @Service public class PaperService { @@ -272,4 +277,30 @@ public class PaperService { .map(User::getUserAbbreviate) .collect(Collectors.joining(", ")); } + + public String getFormattedReference(ReferenceDto referenceDto) { + return referenceDto.getFormatStandard() == GOST + ? getGostReference(referenceDto) + : getSpringerReference(referenceDto); + } + + public String getGostReference(ReferenceDto referenceDto) { + return MessageFormat.format(referenceDto.getReferenceType() == BOOK ? "{0} {1} - {2}{3}. - {4}с." : "{0} {1}{5} {2}{3}. С. {4}.", + referenceDto.getAuthors(), + referenceDto.getPublicationTitle(), + StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ", + referenceDto.getPublicationYear().toString(), + referenceDto.getPages(), + StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + "."); + } + + public String getSpringerReference(ReferenceDto referenceDto) { + return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}", + referenceDto.getAuthors(), + referenceDto.getPublicationYear().toString(), + referenceDto.getPublicationTitle(), + referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "", + StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ", + referenceDto.getPages()); + } } From 51e121ae249325615a3f378fe61595f9c25edcb6 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 26 Apr 2019 00:29:20 +0400 Subject: [PATCH 047/251] #117 add BAK papers filter --- .../java/ru/ulstu/grant/model/GrantDto.java | 18 +++++++++++ .../ru/ulstu/grant/service/GrantService.java | 32 +++++++++++++++++-- .../paper/repository/PaperRepository.java | 2 ++ .../ru/ulstu/paper/service/PaperService.java | 7 ++++ .../resources/templates/grants/grant.html | 9 ++++-- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index 3fb77c5..b60aec0 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -33,6 +33,8 @@ public class GrantDto { private boolean wasLeader; private boolean hasAge; private boolean hasDegree; + private boolean hasBAKPapers; + private boolean hasScopusPapers; private List paperIds = new ArrayList<>(); private List papers = new ArrayList<>(); private List removedDeadlineIds = new ArrayList<>(); @@ -224,4 +226,20 @@ public class GrantDto { public void setRemovedDeadlineIds(List removedDeadlineIds) { this.removedDeadlineIds = removedDeadlineIds; } + + public boolean isHasBAKPapers() { + return hasBAKPapers; + } + + public void setHasBAKPapers(boolean hasBAKPapers) { + this.hasBAKPapers = hasBAKPapers; + } + + public boolean isHasScopusPapers() { + return hasScopusPapers; + } + + public void setHasScopusPapers(boolean hasScopusPapers) { + this.hasScopusPapers = hasScopusPapers; + } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index cabed80..ba6e1e9 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -18,11 +18,12 @@ import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; -import java.util.stream.Collectors; +import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @@ -156,8 +157,15 @@ public class GrantService { filteredUsers = filteredUsers .stream() .filter(getCompletedGrantLeaders()::contains) - .collect(Collectors.toList()); + .collect(toList()); } + if (grantDto.isHasBAKPapers()) { + filteredUsers = filteredUsers + .stream() + .filter(getCompletedBAKPapersAuthors()::contains) + .collect(toList()); + } + return filteredUsers; } @@ -165,7 +173,7 @@ public class GrantService { return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED) .stream() .map(Grant::getLeader) - .collect(Collectors.toList()); + .collect(toList()); } public List getGrantPapers(List paperIds) { @@ -193,4 +201,22 @@ public class GrantService { grantDto.getDeadlines().remove((int) deadlineId); } + private List getCompletedBAKPapersAuthors() { + List papers = paperService.findCompletedVAKPapers() + .stream() + .filter(paper -> paper.getAuthors() != null) + .collect(toList()); + + List users = new ArrayList<>(); + for (Paper p : papers) { + p.getAuthors() + .stream() + .forEach(users::add); + } + + return users + .stream() + .distinct() + .collect(toList()); + } } diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index cab9b1a..8bc59ce 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -16,4 +16,6 @@ public interface PaperRepository extends JpaRepository { List findByIdNotIn(List paperIds); List findAllByIdIn(List paperIds); + + List findByType(Paper.PaperType type); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 325e377..648dbc9 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -272,4 +272,11 @@ public class PaperService { .map(User::getUserAbbreviate) .collect(Collectors.joining(", ")); } + + public List findCompletedVAKPapers() { + return paperRepository.findByType(Paper.PaperType.VAK) + .stream() + .filter(findAllCompleted()::contains) + .collect(toList()); + } } diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 9c0736d..da59248 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -90,7 +90,8 @@ aria-expanded="false" aria-controls="collapse-filter">Фильтр рабочей группы -
@@ -111,14 +112,16 @@
- +
- +
From 51877023d122a5ea98198ce254ef57af5d4f245f Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 26 Apr 2019 09:28:20 +0400 Subject: [PATCH 048/251] #70 added new column to event --- .../ru/ulstu/conference/model/Conference.java | 9 ------- .../service/ConferenceScheduler.java | 4 +-- .../conference/service/ConferenceService.java | 7 +++++- .../ulstu/timeline/service/EventService.java | 25 +++++++++++++++++++ .../db/changelog-20190426_000000-schema.xml | 13 ++++++++++ src/main/resources/db/changelog-master.xml | 1 + 6 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 src/main/resources/db/changelog-20190426_000000-schema.xml diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 126c1bc..9c91a7e 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -146,13 +146,4 @@ public class Conference extends BaseEntity { .filter(d -> d.getDate().after(new Date())) .findFirst(); } - - public boolean lastDeadlineFailed() { - return !deadlines - .stream() - .filter(deadline -> deadline.getDate() != null) - .filter(d -> d.getDate().after(new Date())) - .findAny() - .isPresent(); - } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java index ead2913..863abb5 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java @@ -21,14 +21,14 @@ public class ConferenceScheduler { } - @Scheduled(cron = "0 0 21-22 * * *", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara") public void checkDeadlineBeforeWeek() { log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); } - @Scheduled(cron = "0 0 21-22 * * ?", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara") public void checkDeadlineAfterWeek() { log.debug("ConferenceScheduler.checkDeadlineAfterWeek started"); conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index af43ae9..6550814 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -15,6 +15,7 @@ import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.ping.service.PingService; +import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -39,6 +40,7 @@ public class ConferenceService { private final UserService userService; private final PingService pingService; private final ConferenceNotificationService conferenceNotificationService; + private final EventService eventService; public ConferenceService(ConferenceRepository conferenceRepository, ConferenceUserService conferenceUserService, @@ -46,7 +48,8 @@ public class ConferenceService { PaperService paperService, UserService userService, PingService pingService, - ConferenceNotificationService conferenceNotificationService) { + ConferenceNotificationService conferenceNotificationService, + EventService eventService) { this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; @@ -54,6 +57,7 @@ public class ConferenceService { this.userService = userService; this.pingService = pingService; this.conferenceNotificationService = conferenceNotificationService; + this.eventService = eventService; } public ConferenceDto getExistConferenceById(Integer id) { @@ -97,6 +101,7 @@ public class ConferenceService { Conference newConference = copyFromDto(new Conference(), conferenceDto); newConference = conferenceRepository.save(newConference); conferenceNotificationService.sendCreateNotification(newConference); + eventService.createFromConference(newConference); return newConference.getId(); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index 2d2b83d..d0e50a9 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.time.DateUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.conference.model.Conference; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; import ru.ulstu.timeline.model.Event; @@ -140,4 +141,28 @@ public class EventService { public List findAllFutureDto() { return convert(findAllFuture(), EventDto::new); } + + public void createFromConference(Conference newConference) { + List timelines = timelineService.findAll(); + Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); + + for (Deadline deadline : newConference.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн статьи"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); +// newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); +// newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); +// newEvent.setConference(newConference); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + } } diff --git a/src/main/resources/db/changelog-20190426_000000-schema.xml b/src/main/resources/db/changelog-20190426_000000-schema.xml new file mode 100644 index 0000000..5304032 --- /dev/null +++ b/src/main/resources/db/changelog-20190426_000000-schema.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 68b294a..f5a1451 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -34,4 +34,5 @@ + \ No newline at end of file From a8fbf98d8520dcdf3c7fe049d33f783577e34a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Fri, 26 Apr 2019 10:37:50 +0400 Subject: [PATCH 049/251] #118 check if next deadline present --- .../resources/mail_templates/paperCreateNotification.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/resources/mail_templates/paperCreateNotification.html b/src/main/resources/mail_templates/paperCreateNotification.html index 2758143..82362bd 100644 --- a/src/main/resources/mail_templates/paperCreateNotification.html +++ b/src/main/resources/mail_templates/paperCreateNotification.html @@ -12,9 +12,11 @@

Вам нужно поработать над статьей "Title".

-

- Срок исполнения: . -

+
+

+ Срок исполнения: . +

+

Regards,
From dbcdb96dbf066655ebe4ff30048a7c38321902cc Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 26 Apr 2019 15:12:34 +0400 Subject: [PATCH 050/251] #70 added event method, don't work, because trying to find null entity --- .../ru/ulstu/conference/model/Conference.java | 1 + .../conference/service/ConferenceService.java | 1 + src/main/java/ru/ulstu/timeline/model/Event.java | 13 +++++++++++++ .../java/ru/ulstu/timeline/model/EventDto.java | 15 ++++++++++++++- .../timeline/repository/EventRepository.java | 3 +++ .../ru/ulstu/timeline/service/EventService.java | 13 +++++++++---- 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 9c91a7e..7e18ac0 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -59,6 +59,7 @@ public class Conference extends BaseEntity { @JoinTable(name = "paper_conference", joinColumns = {@JoinColumn(name = "conference_id")}, inverseJoinColumns = {@JoinColumn(name = "paper_id")}) + @Fetch(FetchMode.SUBSELECT) private List papers = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 6550814..0c1d37d 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -114,6 +114,7 @@ public class ConferenceService { Date oldBeginDate = conference.getBeginDate(); Date oldEndDate = conference.getEndDate(); conferenceRepository.save(copyFromDto(conference, conferenceDto)); + eventService.updateConferenceDeadlines(conference); sendNotificationAfterUpdate(conference, oldDeadlines, oldBeginDate, oldEndDate); conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove); return conference.getId(); diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index ef0a4b8..f53a52d 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -1,6 +1,7 @@ package ru.ulstu.timeline.model; import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.paper.model.Paper; import ru.ulstu.user.model.User; @@ -76,6 +77,10 @@ public class Event extends BaseEntity { @JoinColumn(name = "paper_id") private Paper paper; + @ManyToOne + @JoinColumn(name = "conference_id") + private Conference conference; + public String getTitle() { return title; } @@ -163,4 +168,12 @@ public class Event extends BaseEntity { public void setPaper(Paper paper) { this.paper = paper; } + + public Conference getConference() { + return conference; + } + + public void setConference(Conference conference) { + this.conference = conference; + } } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index 6a4a90b..1d2a29a 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -3,6 +3,7 @@ package ru.ulstu.timeline.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.user.model.UserDto; @@ -25,6 +26,7 @@ public class EventDto { private final String description; private final List recipients; private PaperDto paperDto; + private ConferenceDto conferenceDto; @JsonCreator public EventDto(@JsonProperty("id") Integer id, @@ -36,7 +38,8 @@ public class EventDto { @JsonProperty("updateDate") Date updateDate, @JsonProperty("description") String description, @JsonProperty("paperDto") PaperDto paperDto, - @JsonProperty("recipients") List recipients) { + @JsonProperty("recipients") List recipients, + @JsonProperty("paperDto") ConferenceDto conferenceDto) { this.id = id; this.title = title; this.period = period; @@ -47,6 +50,7 @@ public class EventDto { this.description = description; this.recipients = recipients; this.paperDto = paperDto; + this.conferenceDto = conferenceDto; } public EventDto(Event event) { @@ -60,6 +64,7 @@ public class EventDto { this.description = event.getDescription(); this.paperDto = new PaperDto(event.getPaper()); this.recipients = convert(event.getRecipients(), UserDto::new); + this.conferenceDto = new ConferenceDto(event.getConference()); } public Integer getId() { @@ -105,4 +110,12 @@ public class EventDto { public void setPaperDto(PaperDto paperDto) { this.paperDto = paperDto; } + + public ConferenceDto getConferenceDto() { + return conferenceDto; + } + + public void setConferenceDto(ConferenceDto conferenceDto) { + this.conferenceDto = conferenceDto; + } } diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java index eb5c08b..a4b1e47 100644 --- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java +++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java @@ -2,6 +2,7 @@ package ru.ulstu.timeline.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import ru.ulstu.conference.model.Conference; import ru.ulstu.paper.model.Paper; import ru.ulstu.timeline.model.Event; @@ -15,4 +16,6 @@ public interface EventRepository extends JpaRepository { List findAllFuture(); List findAllByPaper(Paper paper); + + List findAllByConference(Conference conference); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index d0e50a9..f4e2873 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -151,18 +151,23 @@ public class EventService { .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) .collect(Collectors.toList())) { Event newEvent = new Event(); - newEvent.setTitle("Дедлайн статьи"); + newEvent.setTitle("Дедлайн конференции"); newEvent.setStatus(Event.EventStatus.NEW); newEvent.setExecuteDate(deadline.getDate()); newEvent.setCreateDate(new Date()); newEvent.setUpdateDate(new Date()); -// newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'"); -// newEvent.setRecipients(new ArrayList(newPaper.getAuthors())); -// newEvent.setConference(newConference); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' конференции '" + newConference.getTitle() + "'"); + newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser())); + newEvent.setConference(newConference); eventRepository.save(newEvent); timeline.getEvents().add(newEvent); timelineService.save(timeline); } } + + public void updateConferenceDeadlines(Conference conference) { + eventRepository.delete(eventRepository.findAllByConference(conference)); + createFromConference(conference); + } } From 39f3c6947925f9999e2d58ec16ff1e698b971f6c Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 26 Apr 2019 15:16:04 +0400 Subject: [PATCH 051/251] #117 add scopus papers filter --- .../ru/ulstu/grant/service/GrantService.java | 34 +++++++++++++++---- .../ru/ulstu/paper/service/PaperService.java | 4 +-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index ba6e1e9..dbf9972 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -20,6 +20,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -162,10 +163,15 @@ public class GrantService { if (grantDto.isHasBAKPapers()) { filteredUsers = filteredUsers .stream() - .filter(getCompletedBAKPapersAuthors()::contains) + .filter(getBAKAuthors()::contains) + .collect(toList()); + } + if (grantDto.isHasScopusPapers()) { + filteredUsers = filteredUsers + .stream() + .filter(getScopusAuthors()::contains) .collect(toList()); } - return filteredUsers; } @@ -201,22 +207,36 @@ public class GrantService { grantDto.getDeadlines().remove((int) deadlineId); } - private List getCompletedBAKPapersAuthors() { - List papers = paperService.findCompletedVAKPapers() - .stream() + private List getCompletedPapersAuthors(Paper.PaperType type) { + List papers = paperService.findAllCompletedByType(type); + papers.stream() .filter(paper -> paper.getAuthors() != null) .collect(toList()); - List users = new ArrayList<>(); for (Paper p : papers) { p.getAuthors() .stream() .forEach(users::add); } + return users; + } - return users + private List getBAKAuthors() { + return getCompletedPapersAuthors(Paper.PaperType.VAK) .stream() .distinct() .collect(toList()); } + + private List getScopusAuthors() { + List oldAuthors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS); + List newAuthors = new ArrayList<>(); + oldAuthors.forEach(author -> { + int count = Collections.frequency(oldAuthors, author); + if (count > 3) { + newAuthors.add(author); + } + }); + return newAuthors; + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 648dbc9..ae9056b 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -273,8 +273,8 @@ public class PaperService { .collect(Collectors.joining(", ")); } - public List findCompletedVAKPapers() { - return paperRepository.findByType(Paper.PaperType.VAK) + public List findAllCompletedByType(Paper.PaperType type) { + return paperRepository.findByType(type) .stream() .filter(findAllCompleted()::contains) .collect(toList()); From e178cd163909119693001cf225a96dc8eee71bc3 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sat, 27 Apr 2019 09:45:47 +0400 Subject: [PATCH 052/251] #70 added checking empty fields of deadline, fix bug on EventDto --- .../ulstu/conference/controller/ConferenceController.java | 6 ++++++ src/main/java/ru/ulstu/timeline/model/EventDto.java | 8 ++++++-- src/main/resources/templates/conferences/conference.html | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 4c5ea91..d324eb4 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -78,6 +78,12 @@ public class ConferenceController { @PostMapping(value = "/conference", params = "save") public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { filterEmptyDeadlines(conferenceDto); + for (Deadline deadline : conferenceDto.getDeadlines()) { + if (deadline.getDate() == null || deadline.getDescription().isEmpty()) { + errors.rejectValue("deadlines", "errorCode", "Все поля дедлайна должны быть заполнены"); + return CONFERENCE_PAGE; + } + } if (errors.hasErrors()) { return CONFERENCE_PAGE; } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index 1d2a29a..e92d2cb 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -62,9 +62,13 @@ public class EventDto { this.createDate = event.getCreateDate(); this.updateDate = event.getUpdateDate(); this.description = event.getDescription(); - this.paperDto = new PaperDto(event.getPaper()); this.recipients = convert(event.getRecipients(), UserDto::new); - this.conferenceDto = new ConferenceDto(event.getConference()); + if (paperDto != null) { + this.paperDto = new PaperDto(event.getPaper()); + } + if (conferenceDto != null) { + this.conferenceDto = new ConferenceDto(event.getConference()); + } } public Integer getId() { diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 69c754a..d5906b6 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -150,10 +150,10 @@ + Имя статьи - From 0e8752e4607dbf4b2561668b8e657be57df37495 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sat, 27 Apr 2019 20:34:49 +0400 Subject: [PATCH 053/251] #70 style fixes --- .../java/ru/ulstu/timeline/model/EventDto.java | 2 +- src/main/resources/public/css/conference.css | 18 ++++++++++++++++-- .../fragments/confLineFragment.html | 6 +----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index e92d2cb..ccce25a 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -39,7 +39,7 @@ public class EventDto { @JsonProperty("description") String description, @JsonProperty("paperDto") PaperDto paperDto, @JsonProperty("recipients") List recipients, - @JsonProperty("paperDto") ConferenceDto conferenceDto) { + @JsonProperty("conferenceDto") ConferenceDto conferenceDto) { this.id = id; this.title = title; this.period = period; diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index 6018b9c..73a96ae 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -7,6 +7,10 @@ body { border-radius: .25rem; } +.conference-row .d-flex:hover .icon-delete { + visibility: visible; +} + .filter-option-inner-inner { color: white; } @@ -17,10 +21,20 @@ body { .conference-row .d-flex .text-decoration { text-decoration: none; + margin: 0; } .conference-row .d-flex .text-decoration:nth-child(1) { - margin-left: 10px; + margin-left: 5px; +} + +.conference-row .d-flex .icon-delete { + width: 29px; + height: 29px; + margin: auto; + border: none; + visibility: hidden; + background-color: transparent; } @@ -159,7 +173,7 @@ body { } .icon-delete:hover { - background-color: #ff0000; + background-color: #ff0000 !important; transition: background-color .15s ease-in-out; } diff --git a/src/main/resources/templates/conferences/fragments/confLineFragment.html b/src/main/resources/templates/conferences/fragments/confLineFragment.html index ecd166d..21b4191 100644 --- a/src/main/resources/templates/conferences/fragments/confLineFragment.html +++ b/src/main/resources/templates/conferences/fragments/confLineFragment.html @@ -7,17 +7,13 @@

- + - - - -
From b4c11a7f90cd8dd6733959a8e15dd7ea478f389c Mon Sep 17 00:00:00 2001 From: ASH Date: Sun, 28 Apr 2019 23:58:35 +0400 Subject: [PATCH 054/251] #79 year generation --- .../students/repository/TaskRepository.java | 5 +++ .../service/TaskGenerationService.java | 25 ++++++++++++++ .../ulstu/students/service/TaskService.java | 33 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/main/java/ru/ulstu/students/service/TaskGenerationService.java diff --git a/src/main/java/ru/ulstu/students/repository/TaskRepository.java b/src/main/java/ru/ulstu/students/repository/TaskRepository.java index ee49ab8..0b17691 100644 --- a/src/main/java/ru/ulstu/students/repository/TaskRepository.java +++ b/src/main/java/ru/ulstu/students/repository/TaskRepository.java @@ -15,4 +15,9 @@ public interface TaskRepository extends JpaRepository { @Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC") List filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag); + + @Query("SELECT t FROM Task t WHERE (EXTRACT(DAY FROM t.createDate) = :day) AND (EXTRACT(MONTH FROM t.createDate) = :month) AND (EXTRACT" + + "(YEAR FROM t.createDate) = :year)") + List findToGenerate(@Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year); + } diff --git a/src/main/java/ru/ulstu/students/service/TaskGenerationService.java b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java new file mode 100644 index 0000000..d347140 --- /dev/null +++ b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java @@ -0,0 +1,25 @@ +package ru.ulstu.students.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class TaskGenerationService { + + private final Logger log = LoggerFactory.getLogger(TaskGenerationService.class); + private final TaskService taskService; + + public TaskGenerationService(TaskService taskService) { + + this.taskService = taskService; + } + + @Scheduled(cron = "0 * * ? * *", zone = "Europe/Samara") + public void generateYearTasks() { + log.debug("TaskService.generateYearTasks started"); + taskService.generateYearTasks(); + log.debug("TaskService.generateYearTasks finished"); + } +} diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index a8747c7..d35720d 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; @@ -14,8 +15,10 @@ import ru.ulstu.tags.service.TagService; import java.io.IOException; import java.util.Arrays; +import java.util.Calendar; 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; @@ -105,6 +108,36 @@ public class TaskService { } } + public Task copyYearTask(Task task) { + + Task newTask = new Task(); + newTask.setTitle(task.getTitle()); + newTask.setTags(tagService.saveOrCreate(task.getTags())); + newTask.setCreateDate(new Date()); + newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS); + newTask.setDeadlines(task.getDeadlines() + .stream() + .map(deadline -> { + Deadline newDeadline = new Deadline(); + Calendar cal = Calendar.getInstance(); + cal.setTime(deadline.getDate()); + cal.add(Calendar.YEAR, 1); + newDeadline.setDescription(deadline.getDescription()); + newDeadline.setDate(cal.getTime()); + return deadlineService.create(newDeadline); + }).collect(Collectors.toList())); + + return newTask; + } + + public void generateYearTasks() { + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + List tasks = taskRepository.findToGenerate(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); + System.out.println(cal.get(Calendar.DAY_OF_MONTH) + " " + cal.get(Calendar.MONTH)); + tasks.forEach(task -> taskRepository.save(copyYearTask(task))); + } + public List getTaskStatuses() { return Arrays.asList(Task.TaskStatus.values()); } From 5c677a975c29d024a326b459e093440b6e88268c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Tue, 30 Apr 2019 01:01:30 +0300 Subject: [PATCH 055/251] #114 changelog edited --- .../resources/db/changelog-20190428_000000-schema.xml | 10 ++++++++++ src/main/resources/db/changelog-master.xml | 1 + 2 files changed, 11 insertions(+) create mode 100644 src/main/resources/db/changelog-20190428_000000-schema.xml diff --git a/src/main/resources/db/changelog-20190428_000000-schema.xml b/src/main/resources/db/changelog-20190428_000000-schema.xml new file mode 100644 index 0000000..b44691d --- /dev/null +++ b/src/main/resources/db/changelog-20190428_000000-schema.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 68b294a..07b0ca2 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -34,4 +34,5 @@ + \ No newline at end of file From 9edcf353389d453389dcc5e897564a822fb2cbb5 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 30 Apr 2019 10:43:36 +0400 Subject: [PATCH 056/251] #70 added ping notification --- .../ConferenceNotificationService.java | 34 +++++++++++++++++-- .../service/ConferenceScheduler.java | 9 ++++- .../ulstu/ping/repository/PingRepository.java | 6 ++++ .../ru/ulstu/ping/service/PingService.java | 8 +++++ .../conferencePingNotification.html | 25 ++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/mail_templates/conferencePingNotification.html diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java index 54faa49..9449b12 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap; import org.springframework.stereotype.Service; import ru.ulstu.conference.model.Conference; import ru.ulstu.core.util.DateUtils; +import ru.ulstu.ping.service.PingService; import ru.ulstu.user.service.MailService; import ru.ulstu.user.service.UserService; @@ -14,24 +15,30 @@ import java.util.Map; @Service public class ConferenceNotificationService { + private final static int YESTERDAY = 0; private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; + private final static String TEMPLATE_PING = "conferencePingNotification"; private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification"; private final static String TEMPLATE_CREATE = "conferenceCreateNotification"; private final static String TEMPLATE_UPDATE_DEADLINES = "conferenceUpdateDeadlinesNotification"; private final static String TEMPLATE_UPDATE_DATES = "conferenceUpdateDatesNotification"; - private final static String TITLE_DEADLINE = "Приближается дедлайн конференции"; + private final static String TITLE_PING = "Обратите внимание на конференцию: %s"; + private final static String TITLE_DEADLINE = "Приближается дедлайн конференции: %s"; private final static String TITLE_CREATE = "Создана новая конференция: %s"; private final static String TITLE_UPDATE_DEADLINES = "Изменения дедлайнов в конференции: %s"; private final static String TITLE_UPDATE_DATES = "Изменение дат проведения конференции: %s"; private final MailService mailService; private final UserService userService; + private final PingService pingService; public ConferenceNotificationService(MailService mailService, - UserService userService) { + UserService userService, + PingService pingService) { this.mailService = mailService; this.userService = userService; + this.pingService = pingService; } public void sendDeadlineNotifications(List conferences, boolean isDeadlineBeforeWeek) { @@ -78,4 +85,27 @@ public class ConferenceNotificationService { } + public void sendPingNotifications(List conferences) { + Date yesterday = DateUtils.addDays(new Date(), YESTERDAY); + conferences + .stream() + .filter(conference -> { + Integer pingCount = pingService.countPingYesterday(conference, yesterday); + return needToSendPingNotification(conference, pingCount); + }) + .forEach(this::sendMessagePing); + } + + private boolean needToSendPingNotification(Conference conference, Integer pingCount) { + if (pingCount > 0) { + conference.setPing((Integer) pingCount); + return true; + } + return false; + } + + private void sendMessagePing(Conference conference) { + Map variables = ImmutableMap.of("conference", conference); + sendForAllParticipals(variables, conference, TEMPLATE_PING, String.format(TITLE_PING, conference.getTitle())); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java index 863abb5..f55f885 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java @@ -21,7 +21,7 @@ public class ConferenceScheduler { } - @Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara") public void checkDeadlineBeforeWeek() { log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); @@ -34,4 +34,11 @@ public class ConferenceScheduler { conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); log.debug("ConferenceScheduler.checkDeadlineAfterWeek finished"); } + + @Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara") + public void checkNewPing() { + log.debug("ConferenceScheduler.checkPing started"); + conferenceNotificationService.sendPingNotifications(conferenceService.findAll()); + log.debug("ConferenceScheduler.checkPing finished"); + } } diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java index ebafc0c..8e69111 100644 --- a/src/main/java/ru/ulstu/ping/repository/PingRepository.java +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -1,7 +1,13 @@ package ru.ulstu.ping.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.conference.model.Conference; import ru.ulstu.ping.model.Ping; public interface PingRepository extends JpaRepository { + + @Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (p.conference = :conference)") + long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month); } diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index ff0d249..3152e5a 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -8,6 +8,7 @@ import ru.ulstu.ping.repository.PingRepository; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.util.Calendar; import java.util.Date; @Service @@ -27,4 +28,11 @@ public class PingService { newPing.setConference(conference); pingRepository.save(newPing); } + + public Integer countPingYesterday(Conference conference, Date yesterday) { + Calendar cal = Calendar.getInstance(); + cal.setTime(yesterday); + + return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1)); + } } diff --git a/src/main/resources/mail_templates/conferencePingNotification.html b/src/main/resources/mail_templates/conferencePingNotification.html new file mode 100644 index 0000000..a80a3f2 --- /dev/null +++ b/src/main/resources/mail_templates/conferencePingNotification.html @@ -0,0 +1,25 @@ + + + + Обратите внимание на конференциию + + + + +

+ Уважаемый(ая) Ivan Ivanov +

+

+ Конференция " + Title" была пропингована + раз. +
+ Обратите внимание. +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file From 0e062f133707716faa6843f73164f415adf8d34e Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 30 Apr 2019 11:41:36 +0400 Subject: [PATCH 057/251] #70 fast fix --- src/main/java/ru/ulstu/ping/repository/PingRepository.java | 4 ++-- src/main/java/ru/ulstu/ping/service/PingService.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java index 8e69111..de79dd7 100644 --- a/src/main/java/ru/ulstu/ping/repository/PingRepository.java +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -8,6 +8,6 @@ import ru.ulstu.ping.model.Ping; public interface PingRepository extends JpaRepository { - @Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (p.conference = :conference)") - long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month); + @Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (YEAR(p.date) = :year) AND (p.conference = :conference)") + long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year); } diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index 3152e5a..f24ed9d 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -33,6 +33,7 @@ public class PingService { Calendar cal = Calendar.getInstance(); cal.setTime(yesterday); - return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1)); + return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, cal.get(Calendar.DAY_OF_MONTH), + cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR))); } } From 7ce8b20841e8a16740aa1ec319737ee1283637a6 Mon Sep 17 00:00:00 2001 From: ASH Date: Tue, 30 Apr 2019 22:05:57 +0400 Subject: [PATCH 058/251] #79 fixing bug --- src/main/java/ru/ulstu/students/service/TaskService.java | 9 ++++++--- src/main/resources/public/js/tasks.js | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index d35720d..0fab0be 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -130,12 +130,15 @@ public class TaskService { return newTask; } + @Transactional public void generateYearTasks() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); - List tasks = taskRepository.findToGenerate(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); - System.out.println(cal.get(Calendar.DAY_OF_MONTH) + " " + cal.get(Calendar.MONTH)); - tasks.forEach(task -> taskRepository.save(copyYearTask(task))); + List tasks = taskRepository.findToGenerate(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR) - 1); + tasks.forEach(task -> { + Task newTask = copyYearTask(task); + taskRepository.save(newTask); + }); } public List getTaskStatuses() { diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index f756199..0eb2da6 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -21,6 +21,14 @@ $(document).ready(function () { $("#input-tag").keyup(function (event) { if(event.keyCode == 13 || event.keyCode == 188) { var tagNumber = $("#tags .tag").length; + if(length != 0) { + tagNumber = $("#tags .tag").last() + .children('input') + .attr("name") + .split(']')[0] + .split('[')[1]; + tagNumber++; + } var tagName = $.trim($(this).val()); var addTag = true; // проверка, добавлен ли этот тег From 2ebd61016d1b6ea4216726aa2f57f0abd81c1edd Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 30 Apr 2019 23:40:40 +0400 Subject: [PATCH 059/251] #38 add variable "files" --- src/main/java/ru/ulstu/grant/model/Grant.java | 19 ++++++++------ .../java/ru/ulstu/grant/model/GrantDto.java | 25 ++++++++++-------- .../ru/ulstu/grant/service/GrantService.java | 26 +++++++++---------- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index abd61ac..d6f9f0c 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -1,5 +1,7 @@ package ru.ulstu.grant.model; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; @@ -66,10 +68,11 @@ public class Grant extends BaseEntity implements UserContainer { private String comment; - //Заявка на грант - @ManyToOne - @JoinColumn(name = "file_id") - private FileData application; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "grant_id", unique = true) + @Fetch(FetchMode.SUBSELECT) + private List files = new ArrayList<>(); + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "project_id") @@ -113,12 +116,12 @@ public class Grant extends BaseEntity implements UserContainer { this.comment = comment; } - public FileData getApplication() { - return application; + public List getFiles() { + return files; } - public void setApplication(FileData application) { - this.application = application; + public void setFiles(List files) { + this.files = files; } public String getTitle() { diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index 3fb77c5..6866f41 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.StringUtils; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.user.model.UserDto; @@ -25,7 +26,7 @@ public class GrantDto { private Grant.GrantStatus status; private List deadlines = new ArrayList<>(); private String comment; - private String applicationFileName; + private List files = new ArrayList<>(); private ProjectDto project; private Set authorIds; private Set authors; @@ -47,6 +48,7 @@ public class GrantDto { @JsonProperty("status") Grant.GrantStatus status, @JsonProperty("deadlines") List deadlines, @JsonProperty("comment") String comment, + @JsonProperty("files") List files, @JsonProperty("project") ProjectDto project, @JsonProperty("authorIds") Set authorIds, @JsonProperty("authors") Set authors, @@ -61,8 +63,9 @@ public class GrantDto { this.status = status; this.deadlines = deadlines; this.comment = comment; - this.applicationFileName = null; + this.files = files; this.project = project; + this.authorIds = authorIds; this.authors = authors; this.leaderId = leaderId; this.wasLeader = wasLeader; @@ -78,8 +81,8 @@ public class GrantDto { this.status = grant.getStatus(); this.deadlines = grant.getDeadlines(); this.comment = grant.getComment(); + this.files = convert(grant.getFiles(), FileDataDto::new); 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(); @@ -130,6 +133,14 @@ public class GrantDto { this.comment = comment; } + public List getFiles() { + return files; + } + + public void setFiles(List files) { + this.files = files; + } + public ProjectDto getProject() { return project; } @@ -138,14 +149,6 @@ public class GrantDto { this.project = project; } - public String getApplicationFileName() { - return applicationFileName; - } - - public void setApplicationFileName(String applicationFileName) { - this.applicationFileName = applicationFileName; - } - public Set getAuthorIds() { return authorIds; } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index cabed80..0c1d68e 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; @@ -21,8 +22,8 @@ import java.io.IOException; import java.util.Arrays; import java.util.Date; import java.util.List; -import java.util.stream.Collectors; +import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @@ -81,9 +82,10 @@ public class GrantService { grant.setProject(projectService.findById(grantDto.getProject().getId())); } grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines())); - if (grantDto.getApplicationFileName() != null) { - grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName())); - } + + grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream() + .filter(f -> !f.isDeleted()) + .collect(toList()))); grant.getAuthors().clear(); if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) { grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds))); @@ -106,8 +108,11 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { Grant grant = grantRepository.findOne(grantDto.getId()); - if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) { - fileService.deleteFile(grant.getApplication()); + + for (FileDataDto file : grantDto.getFiles().stream() + .filter(f -> f.isDeleted() && f.getId() != null) + .collect(toList())) { + fileService.delete(file.getId()); } grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove); grantRepository.save(copyFromDto(grant, grantDto)); @@ -117,9 +122,6 @@ public class GrantService { @Transactional public void delete(Integer grantId) throws IOException { Grant grant = grantRepository.findOne(grantId); - if (grant.getApplication() != null) { - fileService.deleteFile(grant.getApplication()); - } grantRepository.delete(grant); } @@ -156,7 +158,7 @@ public class GrantService { filteredUsers = filteredUsers .stream() .filter(getCompletedGrantLeaders()::contains) - .collect(Collectors.toList()); + .collect(toList()); } return filteredUsers; } @@ -165,12 +167,11 @@ public class GrantService { return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED) .stream() .map(Grant::getLeader) - .collect(Collectors.toList()); + .collect(toList()); } public List getGrantPapers(List paperIds) { return paperService.findAllSelect(paperIds); - } public List getAllPapers() { @@ -192,5 +193,4 @@ public class GrantService { } grantDto.getDeadlines().remove((int) deadlineId); } - } From 6442a67ff108ca538aeb742f09002478e9df6b15 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 30 Apr 2019 23:41:51 +0400 Subject: [PATCH 060/251] #38 update view --- .../fragments/grantFilesListFragment.html | 37 ++++++ .../resources/templates/grants/grant.html | 111 ++++++++++++++---- 2 files changed, 125 insertions(+), 23 deletions(-) create mode 100644 src/main/resources/templates/grants/fragments/grantFilesListFragment.html diff --git a/src/main/resources/templates/grants/fragments/grantFilesListFragment.html b/src/main/resources/templates/grants/fragments/grantFilesListFragment.html new file mode 100644 index 0000000..2547c80 --- /dev/null +++ b/src/main/resources/templates/grants/fragments/grantFilesListFragment.html @@ -0,0 +1,37 @@ + + + + + + +
+ + +
+ + + + +
+ + +
+
+ + + +
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 9c0736d..d33015c 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -61,7 +61,7 @@
-
- +
+
-
+
+
+