From 9da227ab34ae7a8b9ab38843b645cd4618025f32 Mon Sep 17 00:00:00 2001 From: ASH Date: Thu, 18 Apr 2019 21:38:55 +0400 Subject: [PATCH 001/105] #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 002/105] #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 033/105] #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 034/105] #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 035/105] #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 036/105] #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 037/105] #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 038/105] #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 039/105] #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 040/105] #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 041/105] #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 042/105] #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 043/105] #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 044/105] #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 045/105] #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 046/105] #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 047/105] #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 048/105] #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 049/105] #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 050/105] #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 051/105] #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 052/105] #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 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 053/105] #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 054/105] #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 055/105] #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 2ebd61016d1b6ea4216726aa2f57f0abd81c1edd Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 30 Apr 2019 23:40:40 +0400 Subject: [PATCH 056/105] #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 057/105] #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 @@
-
- +
+
-
+
+
+
From b57142e28fc423b5779372e28107e536f03db963 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 8 May 2019 17:08:37 +0400 Subject: [PATCH 076/105] #70 added unique name control --- .../controller/ConferenceController.java | 1 + .../ulstu/conference/model/ConferenceDto.java | 3 ++- .../repository/ConferenceRepository.java | 7 +++++- .../conference/service/ConferenceService.java | 12 ++++++++-- .../java/ru/ulstu/name/NameContainer.java | 24 +++++++++++++++++++ .../java/ru/ulstu/name/NameRepository.java | 7 ++++++ src/main/java/ru/ulstu/name/NameService.java | 11 +++++++++ 7 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/ulstu/name/NameContainer.java create mode 100644 src/main/java/ru/ulstu/name/NameRepository.java create mode 100644 src/main/java/ru/ulstu/name/NameService.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 5aecb51..4e11d32 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -76,6 +76,7 @@ public class ConferenceController { public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { conferenceService.filterEmptyDeadlines(conferenceDto); conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors); + conferenceService.checkUniqueName(conferenceDto, errors); if (errors.hasErrors()) { return CONFERENCE_PAGE; } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 2e2f13b..9c9b37a 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.name.NameContainer; import ru.ulstu.paper.model.Paper; import javax.persistence.Temporal; @@ -16,7 +17,7 @@ import java.util.List; import static ru.ulstu.core.util.StreamApiUtils.convert; -public class ConferenceDto { +public class ConferenceDto extends NameContainer { private final static String BEGIN_DATE = "Начало: "; private final static String END_DATE = "Конец: "; diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 3a8bbe1..5dfe7dd 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -5,12 +5,13 @@ 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; +import ru.ulstu.name.NameRepository; import ru.ulstu.user.model.User; import java.util.Date; import java.util.List; -public interface ConferenceRepository extends JpaRepository { +public interface ConferenceRepository extends JpaRepository, NameRepository { @Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " + "AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC") List findByUserAndYear(@Param("user") User user, @Param("year") Integer year); @@ -24,4 +25,8 @@ public interface ConferenceRepository extends JpaRepository @Modifying @Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id") int updatePingConference(@Param("id") Integer id); + + @Override + @Query("SELECT title FROM Conference c WHERE c.title = :name") + String findByName(@Param("name") String name); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38de435..9a10efb 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -13,6 +13,7 @@ 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.name.NameService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.ping.service.PingService; @@ -31,7 +32,7 @@ import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @Service -public class ConferenceService { +public class ConferenceService extends NameService { private final static int MAX_DISPLAY_SIZE = 40; private final ConferenceRepository conferenceRepository; @@ -280,10 +281,17 @@ public class ConferenceService { } } - public void filterEmptyDeadlines(ConferenceDto conferenceDto) { conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription())) .collect(Collectors.toList())); } + + public void checkUniqueName(ConferenceDto conferenceDto, Errors errors) { + conferenceDto.setName(conferenceDto.getTitle()); + conferenceDto.setNameRepository(conferenceRepository); + if (checkUniqueName(conferenceDto)) { + errors.rejectValue("title", "errorCode", "Конференция с таким именем уже существует"); + } + } } diff --git a/src/main/java/ru/ulstu/name/NameContainer.java b/src/main/java/ru/ulstu/name/NameContainer.java new file mode 100644 index 0000000..bcccc80 --- /dev/null +++ b/src/main/java/ru/ulstu/name/NameContainer.java @@ -0,0 +1,24 @@ +package ru.ulstu.name; + +public abstract class NameContainer { + + private String name = ""; + + private NameRepository nameRepository; + + public NameRepository getNameRepository() { + return nameRepository; + } + + public void setNameRepository(NameRepository nameRepository) { + this.nameRepository = nameRepository; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/ru/ulstu/name/NameRepository.java b/src/main/java/ru/ulstu/name/NameRepository.java new file mode 100644 index 0000000..99bd3ac --- /dev/null +++ b/src/main/java/ru/ulstu/name/NameRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.name; + +import org.springframework.data.repository.query.Param; + +public interface NameRepository { + String findByName(@Param("name") String name); +} diff --git a/src/main/java/ru/ulstu/name/NameService.java b/src/main/java/ru/ulstu/name/NameService.java new file mode 100644 index 0000000..7d7bdc9 --- /dev/null +++ b/src/main/java/ru/ulstu/name/NameService.java @@ -0,0 +1,11 @@ +package ru.ulstu.name; + +import org.springframework.stereotype.Service; + +@Service +public abstract class NameService { + + public boolean checkUniqueName(NameContainer nameContainer) { + return nameContainer.getName().equals(nameContainer.getNameRepository().findByName(nameContainer.getName())); + } +} From 2d9fd0506079bb27016c07416c64977aadb2b616 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Wed, 8 May 2019 23:32:37 +0400 Subject: [PATCH 077/105] #119 create grantCreateNotification mail template --- .../grantCreateNotification.html | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/resources/mail_templates/grantCreateNotification.html diff --git a/src/main/resources/mail_templates/grantCreateNotification.html b/src/main/resources/mail_templates/grantCreateNotification.html new file mode 100644 index 0000000..69736cd --- /dev/null +++ b/src/main/resources/mail_templates/grantCreateNotification.html @@ -0,0 +1,28 @@ + + + + Уведомление о создании гранта + + + + +

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

+

+ Был добавлен новый грант: " + Title". +
+

+

+ Руководитель гранта: + + Leader. +

+

+ Regards, +
+ NG-tracker. +

+ + \ No newline at end of file From b640dea99a47521352214b6e00f1800adea2a7c2 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 9 May 2019 00:45:54 +0400 Subject: [PATCH 078/105] #119 create scheduler --- .../ulstu/grant/service/GrantScheduler.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/ru/ulstu/grant/service/GrantScheduler.java diff --git a/src/main/java/ru/ulstu/grant/service/GrantScheduler.java b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java new file mode 100644 index 0000000..1c38c4a --- /dev/null +++ b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java @@ -0,0 +1,30 @@ +package ru.ulstu.grant.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class GrantScheduler { + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; + + private final Logger log = LoggerFactory.getLogger(GrantScheduler.class); + + private final GrantNotificationService grantNotificationService; + private final GrantService grantService; + + public GrantScheduler(GrantNotificationService grantNotificationService, + GrantService grantService) { + this.grantNotificationService = grantNotificationService; + this.grantService = grantService; + } + + + @Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara") + public void checkDeadlineBeforeWeek() { + log.debug("GrantScheduler.checkDeadlineBeforeWeek started"); + grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("GrantScheduler.checkDeadlineBeforeWeek finished"); + } +} From 4262446aef8147b06e3b5b535076d7cfc519e24c Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 9 May 2019 01:21:56 +0400 Subject: [PATCH 079/105] #119 create all mail templates --- .../grantAuthorsChangeNotification.html | 24 ++++++++++++++++ .../grantDeadlineNotification.html | 28 +++++++++++++++++++ .../grantLeaderChangeNotification.html | 24 ++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/main/resources/mail_templates/grantAuthorsChangeNotification.html create mode 100644 src/main/resources/mail_templates/grantDeadlineNotification.html create mode 100644 src/main/resources/mail_templates/grantLeaderChangeNotification.html diff --git a/src/main/resources/mail_templates/grantAuthorsChangeNotification.html b/src/main/resources/mail_templates/grantAuthorsChangeNotification.html new file mode 100644 index 0000000..2bae4fe --- /dev/null +++ b/src/main/resources/mail_templates/grantAuthorsChangeNotification.html @@ -0,0 +1,24 @@ + + + + Уведомление об изменении состава рабочей группы + + + + +

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

+

+ Состав рабочей группы гранта "Title" сменился с + " oldAuthors" + на " newAuthors". +

+

+ Regards, +
+ NG-tracker. +

+ + diff --git a/src/main/resources/mail_templates/grantDeadlineNotification.html b/src/main/resources/mail_templates/grantDeadlineNotification.html new file mode 100644 index 0000000..190ef67 --- /dev/null +++ b/src/main/resources/mail_templates/grantDeadlineNotification.html @@ -0,0 +1,28 @@ + + + + Уведомление о дедлайне гранта + + + + +

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

+

+ Приближается дедлайн гранта "Title". +

+

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

+

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

+

+ Regards, +
+ NG-tracker. +

+ + diff --git a/src/main/resources/mail_templates/grantLeaderChangeNotification.html b/src/main/resources/mail_templates/grantLeaderChangeNotification.html new file mode 100644 index 0000000..c6a37e0 --- /dev/null +++ b/src/main/resources/mail_templates/grantLeaderChangeNotification.html @@ -0,0 +1,24 @@ + + + + Уведомление об изменении руководителя гранта + + + + +

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

+

+ Руководитель гранта "Title" сменился с + "oldLeader" + на "newLeader". +

+

+ Regards, +
+ NG-tracker. +

+ + From 74a8dcbd8ab22de90e4318da464254aa624cc0f6 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 9 May 2019 01:23:17 +0400 Subject: [PATCH 080/105] #119 add leader changed notification --- .../ulstu/grant/service/GrantNotificationService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java index c234290..40c045b 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java @@ -18,10 +18,12 @@ public class GrantNotificationService { private final static String TEMPLATE_DEADLINE = "grantDeadlineNotification"; private final static String TEMPLATE_CREATE = "grantCreateNotification"; private final static String TEMPLATE_AUTHORS_CHANGED = "grantAuthorsChangeNotification"; + private final static String TEMPLATE_LEADER_CHANGED = "grantLeaderChangeNotification"; private final static String TITLE_DEADLINE = "Приближается дедлайн гранта: %s"; private final static String TITLE_CREATE = "Создан грант: %s"; private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s"; + private final static String TITLE_LEADER_CHANGED = "Изменился руководитель гранта: %s"; private final MailService mailService; @@ -53,14 +55,18 @@ public class GrantNotificationService { sendForAllAuthors(variables, grant, TEMPLATE_CREATE, String.format(TITLE_CREATE, grant.getTitle())); } - public void authorsChangeNotification(Grant grant, List oldAuthors) { + public void sendAuthorsChangeNotification(Grant grant, Set oldAuthors) { Map variables = ImmutableMap.of("grant", grant, "oldAuthors", oldAuthors); sendForAllAuthors(variables, grant, TEMPLATE_AUTHORS_CHANGED, String.format(TITLE_AUTHORS_CHANGED, grant.getTitle())); } + public void sendLeaderChangeNotification(Grant grant, User oldLeader) { + Map variables = ImmutableMap.of("grant", grant, "oldLeader", oldLeader); + sendForAllAuthors(variables, grant, TEMPLATE_LEADER_CHANGED, String.format(TITLE_LEADER_CHANGED, grant.getTitle())); + } private void sendForAllAuthors(Map variables, Grant grant, String template, String title) { Set allAuthors = grant.getAuthors(); - allAuthors.add(grant.getLeader()); allAuthors.forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title)); + mailService.sendEmailFromTemplate(variables, grant.getLeader(), template, title); } } From 77e2ad06516d4da9d80b7c8d8c62a51d4397d5d3 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Thu, 9 May 2019 01:24:55 +0400 Subject: [PATCH 081/105] #119 add send notification functions --- .../ru/ulstu/grant/service/GrantService.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index ae11850..83ef49e 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -23,7 +23,9 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; @@ -41,6 +43,7 @@ public class GrantService { private final UserService userService; private final PaperService paperService; private final EventService eventService; + private final GrantNotificationService grantNotificationService; public GrantService(GrantRepository grantRepository, FileService fileService, @@ -48,7 +51,8 @@ public class GrantService { ProjectService projectService, UserService userService, PaperService paperService, - EventService eventService) { + EventService eventService, + GrantNotificationService grantNotificationService) { this.grantRepository = grantRepository; this.fileService = fileService; this.deadlineService = deadlineService; @@ -56,6 +60,7 @@ public class GrantService { this.userService = userService; this.paperService = paperService; this.eventService = eventService; + this.grantNotificationService = grantNotificationService; } public List findAll() { @@ -77,6 +82,7 @@ public class GrantService { Grant newGrant = copyFromDto(new Grant(), grantDto); newGrant = grantRepository.save(newGrant); eventService.createFromGrant(newGrant); + grantNotificationService.sendCreateNotification(newGrant); return newGrant.getId(); } @@ -113,6 +119,8 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { Grant grant = grantRepository.findOne(grantDto.getId()); + Set oldAuthors = new HashSet<>(grant.getAuthors()); + User oldLeader = grant.getLeader(); for (FileDataDto file : grantDto.getFiles().stream() .filter(f -> f.isDeleted() && f.getId() != null) .collect(toList())) { @@ -120,6 +128,20 @@ public class GrantService { } grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove); grantRepository.save(copyFromDto(grant, grantDto)); + + grant.getAuthors().forEach(author -> { + if (!oldAuthors.contains(author)) { + grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors); + } + }); + oldAuthors.forEach(oldAuthor -> { + if (!grant.getAuthors().contains(oldAuthor)) { + grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors); + } + }); + if (grant.getLeader() != oldLeader) { + grantNotificationService.sendLeaderChangeNotification(grant, oldLeader); + } eventService.updateGrantDeadlines(grant); return grant.getId(); } @@ -148,6 +170,7 @@ public class GrantService { grant = grantRepository.save(grant); eventService.createFromGrant(grant); + grantNotificationService.sendCreateNotification(grant); return grant; } @@ -222,7 +245,6 @@ public class GrantService { .filter(paper -> paper.getAuthors() != null) .flatMap(paper -> paper.getAuthors().stream()) .collect(toList()); - } private List getBAKAuthors() { From 961fdf939759265df386f113444593d9586b4b61 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 15:07:47 +0400 Subject: [PATCH 082/105] #70 added conference class, added create method test --- src/test/java/IndexConferenceTest.java | 59 +++++++++++++++++++ src/test/java/conference/ConferencePage.java | 19 ++++++ .../conference/ConferencesDashboardPage.java | 11 ++++ src/test/java/conference/ConferencesPage.java | 19 ++++++ 4 files changed, 108 insertions(+) create mode 100644 src/test/java/IndexConferenceTest.java create mode 100644 src/test/java/conference/ConferencePage.java create mode 100644 src/test/java/conference/ConferencesDashboardPage.java create mode 100644 src/test/java/conference/ConferencesPage.java diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java new file mode 100644 index 0000000..9adf2f5 --- /dev/null +++ b/src/test/java/IndexConferenceTest.java @@ -0,0 +1,59 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import conference.ConferencePage; +import conference.ConferencesDashboardPage; +import conference.ConferencesPage; +import core.PageObject; +import core.TestTemplate; +import org.assertj.core.api.Assertions; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import ru.ulstu.NgTrackerApplication; +import ru.ulstu.configuration.ApplicationProperties; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class IndexConferenceTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new ConferencesPage(), Arrays.asList("КОНФЕРЕНЦИИ", "/conferences/conferences"), + new ConferencePage(), Arrays.asList("РЕДАКТИРОВАНИЕ КОНФЕРЕНЦИИ", "/conferences/conference?id=0"), + new ConferencesDashboardPage(), Arrays.asList("АКТУАЛЬНЫЕ КОНФЕРЕНЦИИ", "/conferences/dashboard") + ); + + @Autowired + private ApplicationProperties applicationProperties; + + @Test + public void testStartApplication() { + getContext().goTo(applicationProperties.getBaseUrl()); + Assertions + .assertThat(getContext().getTitle()) + .isEqualTo("NG-Tracker"); + } + + @Test + public void testCreateNewConference() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(page.getKey()); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + + String newConferenceName = "test " + (new Date()).getTime(); + conferencePage.setName(newConferenceName); + conferencePage.clickSaveBut(); + + Assert.assertTrue(conferencesPage.getConferencesList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); + } +} diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java new file mode 100644 index 0000000..5f57008 --- /dev/null +++ b/src/test/java/conference/ConferencePage.java @@ -0,0 +1,19 @@ +package conference; + +import core.PageObject; +import org.openqa.selenium.By; + +public class ConferencePage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h3")).getText(); + } + + public void setName(String name) { + driver.findElement(By.id("title")).sendKeys(name); + } + + public void clickSaveBut() { + driver.findElement(By.id("send-message-button")).click(); + } +} diff --git a/src/test/java/conference/ConferencesDashboardPage.java b/src/test/java/conference/ConferencesDashboardPage.java new file mode 100644 index 0000000..d358c4a --- /dev/null +++ b/src/test/java/conference/ConferencesDashboardPage.java @@ -0,0 +1,11 @@ +package conference; + +import core.PageObject; +import org.openqa.selenium.By; + +public class ConferencesDashboardPage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h2")).getText(); + } +} diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java new file mode 100644 index 0000000..0dc899d --- /dev/null +++ b/src/test/java/conference/ConferencesPage.java @@ -0,0 +1,19 @@ +package conference; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class ConferencesPage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h3")).getText(); + } + + public List getConferencesList() { + return driver.findElements(By.cssSelector("span.h6.float-left.m-2")); + + } +} \ No newline at end of file From 1ad66d6fb17bcf14d12fc8ca7fa9218419ad1665 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 15:54:12 +0400 Subject: [PATCH 083/105] #103 change name method test --- src/test/java/IndexConferenceTest.java | 21 +++++++++++++++++++ src/test/java/conference/ConferencePage.java | 4 ++++ src/test/java/conference/ConferencesPage.java | 3 +++ 3 files changed, 28 insertions(+) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 9adf2f5..b3a4118 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -56,4 +56,25 @@ public class IndexConferenceTest extends TestTemplate { .stream() .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); } + + @Test + public void testChangeConferenceNameAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + String newConferenceName = "test " + (new Date()).getTime(); + conferencePage.clearName(); + conferencePage.setName(newConferenceName); + conferencePage.clickSaveBut(); + + Assert.assertTrue(conferencesPage.getConferencesList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); + } + + } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 5f57008..48362e0 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -13,6 +13,10 @@ public class ConferencePage extends PageObject { driver.findElement(By.id("title")).sendKeys(name); } + public void clearName() { + driver.findElement(By.id("title")).clear(); + } + public void clickSaveBut() { driver.findElement(By.id("send-message-button")).click(); } diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index 0dc899d..b258420 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -14,6 +14,9 @@ public class ConferencesPage extends PageObject { public List getConferencesList() { return driver.findElements(By.cssSelector("span.h6.float-left.m-2")); + } + public void getConferenceFirst() { + driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click(); } } \ No newline at end of file From 253f4b4aad96dad266fb62fb1180bea11055e5dd Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 17:03:47 +0400 Subject: [PATCH 084/105] #103 add check new deadline --- src/test/java/IndexConferenceTest.java | 29 +++++++++++++++++ src/test/java/conference/ConferencePage.java | 33 +++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index b3a4118..7f8ee57 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -9,6 +9,7 @@ import org.assertj.core.api.Assertions; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.openqa.selenium.By; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -76,5 +77,33 @@ public class IndexConferenceTest extends TestTemplate { .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); } + @Test + public void testAddDeadlineAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer deadlineCount = conferencePage.getDeadlineCount(); + + String description = "test"; + String date = "09.09.2019"; + String dateValue = "2019-09-09"; + conferencePage.clickAddDeadlineBut(); + conferencePage.setDeadlineDescription(description, deadlineCount); + conferencePage.setDeadlineDate(date, deadlineCount); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(conferencePage.getDeadlineList() + .stream() + .anyMatch(webElement -> { + return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description) + && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); + })); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 48362e0..00d9585 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -2,6 +2,9 @@ package conference; import core.PageObject; import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; public class ConferencePage extends PageObject { @@ -9,10 +12,18 @@ public class ConferencePage extends PageObject { return driver.findElement(By.tagName("h3")).getText(); } + public String getId() { + return driver.findElement(By.id("id")).getAttribute("value"); + } + public void setName(String name) { driver.findElement(By.id("title")).sendKeys(name); } + public String getName() { + return driver.findElement(By.id("title")).getAttribute("value"); + } + public void clearName() { driver.findElement(By.id("title")).clear(); } @@ -20,4 +31,24 @@ public class ConferencePage extends PageObject { public void clickSaveBut() { driver.findElement(By.id("send-message-button")).click(); } -} + + public void clickAddDeadlineBut() { + driver.findElement(By.id("addDeadline")).click(); + } + + public List getDeadlineList() { + return driver.findElements(By.className("deadline")); + } + + public Integer getDeadlineCount() { + return driver.findElements(By.className("deadline")).size(); + } + + public void setDeadlineDescription(String description, Integer i) { + driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); + } + + public void setDeadlineDate(String date, Integer i) { + driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); + } +} \ No newline at end of file From 0cb7b05c2556f64b277c1d6903229ea0f38e72be Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 17:21:36 +0400 Subject: [PATCH 085/105] #103 add check take part --- src/test/java/IndexConferenceTest.java | 21 ++++++++++++++++++++ src/test/java/conference/ConferencePage.java | 12 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 7f8ee57..4fb72d4 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -106,4 +106,25 @@ public class IndexConferenceTest extends TestTemplate { && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); })); } + + @Test + public void testTakePartAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer membersCount = conferencePage.getMemperCount(); + + conferencePage.clickTakePartBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(membersCount + 1 == conferencePage.getMemperCount() + && conferencePage.getTakePartButDisabledValue().equals("true")); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 00d9585..9a448eb 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -51,4 +51,16 @@ public class ConferencePage extends PageObject { public void setDeadlineDate(String date, Integer i) { driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); } + + public void clickTakePartBut() { + driver.findElement(By.id("take-part")).click(); + } + + public String getTakePartButDisabledValue() { + return driver.findElement(By.id("take-part")).getAttribute("disabled"); + } + + public Integer getMemperCount() { + return driver.findElements(By.className("member")).size(); + } } \ No newline at end of file From 7b4318a3b528c93b0be5cbdcbc19cb4019485221 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 17:40:24 +0400 Subject: [PATCH 086/105] #103 add delete deadline --- src/test/java/IndexConferenceTest.java | 20 ++++++++++++++++++++ src/test/java/conference/ConferencePage.java | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 4fb72d4..8408029 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -127,4 +127,24 @@ public class IndexConferenceTest extends TestTemplate { Assert.assertTrue(membersCount + 1 == conferencePage.getMemperCount() && conferencePage.getTakePartButDisabledValue().equals("true")); } + + @Test + public void testDeleteDeadlineAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer deadlineCount = conferencePage.getDeadlineCount(); + + conferencePage.clickDeleteDeadlineBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(deadlineCount - 1 == conferencePage.getDeadlineCount()); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 9a448eb..d51e7b9 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -63,4 +63,8 @@ public class ConferencePage extends PageObject { public Integer getMemperCount() { return driver.findElements(By.className("member")).size(); } + + public void clickDeleteDeadlineBut() { + driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).click(); + } } \ No newline at end of file From d9a4224317c2ef5c5dae969003c6342a530d4500 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 19:15:22 +0400 Subject: [PATCH 087/105] #103 add attach article --- src/test/java/IndexConferenceTest.java | 33 ++++++++++++++++++-- src/test/java/conference/ConferencePage.java | 20 +++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 8408029..4c40d7d 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -10,6 +10,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -117,14 +118,14 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer membersCount = conferencePage.getMemperCount(); + Integer membersCount = conferencePage.getMemberCount(); conferencePage.clickTakePartBut(); conferencePage.clickSaveBut(); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(membersCount + 1 == conferencePage.getMemperCount() + Assert.assertTrue(membersCount + 1 == conferencePage.getMemberCount() && conferencePage.getTakePartButDisabledValue().equals("true")); } @@ -147,4 +148,32 @@ public class IndexConferenceTest extends TestTemplate { Assert.assertTrue(deadlineCount - 1 == conferencePage.getDeadlineCount()); } + + @Test + public void testAttachArticle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getPaperCount(); + + conferencePage.showAllowToAttachArticles(); + WebElement paper = conferencePage.selectPaper(); + String paperName = paper.findElement(By.className("text")).getText(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount + 1 == conferencePage.getPaperCount() + && conferencePage.getPapers() + .stream() + .anyMatch(webElement -> webElement + .findElement(By.className("paper-name")) + .findElements(By.tagName("span")) + .get(1).getText().equals(paperName))); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index d51e7b9..02fa0fc 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -60,11 +60,29 @@ public class ConferencePage extends PageObject { return driver.findElement(By.id("take-part")).getAttribute("disabled"); } - public Integer getMemperCount() { + public Integer getMemberCount() { return driver.findElements(By.className("member")).size(); } public void clickDeleteDeadlineBut() { driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).click(); } + + public void showAllowToAttachArticles() { + driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click(); + } + + public List getPapers() { + return driver.findElements(By.className("paper")); + } + + public Integer getPaperCount() { + return driver.findElements(By.className("paper")).size(); + } + + public WebElement selectPaper() { + WebElement webElement = driver.findElement(By.xpath("//*[@id=\"conference-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a")); + webElement.click(); + return webElement; + } } \ No newline at end of file From cad8682088abff0a54035edbcd0baaa2c5fe26b1 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 20:07:55 +0400 Subject: [PATCH 088/105] #103 add adding article --- src/main/resources/public/css/conference.css | 6 +++++ src/test/java/IndexConferenceTest.java | 28 ++++++++++++++++++++ src/test/java/conference/ConferencePage.java | 4 +++ 3 files changed, 38 insertions(+) diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index 73a96ae..26ac40e 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -140,6 +140,7 @@ body { .paper-name { flex: 1; + overflow: hidden; } .paper-name:hover { @@ -156,6 +157,11 @@ body { float: left; } +.paper-name span:nth-child(2) { + max-width: 326px; + white-space: nowrap; +} + .icon { diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 4c40d7d..a2e0124 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -176,4 +176,32 @@ public class IndexConferenceTest extends TestTemplate { .findElements(By.tagName("span")) .get(1).getText().equals(paperName))); } + + @Test + public void testAddArticle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getPaperCount(); + + conferencePage.clickAddPaperBut(); + List webElements = conferencePage.getPapers(); + String paperName = webElements.get(webElements.size() - 1).findElement(By.tagName("a")).findElements(By.tagName("span")).get(1).getText(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount + 1 == conferencePage.getPaperCount() + && conferencePage.getPapers() + .stream() + .anyMatch(webElement -> webElement + .findElement(By.tagName("a")) + .findElements(By.tagName("span")) + .get(1).getText().equals(paperName))); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 02fa0fc..1a4a1df 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -85,4 +85,8 @@ public class ConferencePage extends PageObject { webElement.click(); return webElement; } + + public void clickAddPaperBut() { + driver.findElement(By.id("add-paper")).click(); + } } \ No newline at end of file From 4e4e7ae1948ac8ccfe1c4c612358c6399f887b30 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 20:54:43 +0400 Subject: [PATCH 089/105] #103 add paper transition --- src/main/resources/public/css/conference.css | 4 +++ src/test/java/IndexConferenceTest.java | 26 +++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index 26ac40e..dc83057 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -162,6 +162,10 @@ body { white-space: nowrap; } +.dropdown-menu { + max-width: 445px; +} + .icon { diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index a2e0124..b3314ff 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -191,7 +191,7 @@ public class IndexConferenceTest extends TestTemplate { conferencePage.clickAddPaperBut(); List webElements = conferencePage.getPapers(); - String paperName = webElements.get(webElements.size() - 1).findElement(By.tagName("a")).findElements(By.tagName("span")).get(1).getText(); + String paperName = webElements.get(webElements.size() - 1).findElements(By.tagName("input")).get(1).getAttribute("value"); conferencePage.clickSaveBut(); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); @@ -200,8 +200,26 @@ public class IndexConferenceTest extends TestTemplate { && conferencePage.getPapers() .stream() .anyMatch(webElement -> webElement - .findElement(By.tagName("a")) - .findElements(By.tagName("span")) - .get(1).getText().equals(paperName))); + .findElements(By.tagName("input")) + .get(1).getAttribute("value") + .equals(paperName))); + } + + @Test + public void testTransitionToTheArticle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + + WebElement paper = conferencePage.getPapers().get(0); + String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); + paper.findElement(By.tagName("a")).click(); + + Assertions.assertThat(conferencePage.getName()) + .isEqualTo(paperName); } } From 46864069543d5c6f69572b68ab91c8e209069b1c Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 21:15:49 +0400 Subject: [PATCH 090/105] #103 add undock article --- src/test/java/IndexConferenceTest.java | 38 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index b3314ff..84e51a2 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -159,17 +159,17 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.showAllowToAttachArticles(); - WebElement paper = conferencePage.selectPaper(); + WebElement paper = conferencePage.selectArticle(); String paperName = paper.findElement(By.className("text")).getText(); conferencePage.clickSaveBut(); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(paperCount + 1 == conferencePage.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement .findElement(By.className("paper-name")) @@ -187,17 +187,17 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.clickAddPaperBut(); - List webElements = conferencePage.getPapers(); + List webElements = conferencePage.getArticles(); String paperName = webElements.get(webElements.size() - 1).findElements(By.tagName("input")).get(1).getAttribute("value"); conferencePage.clickSaveBut(); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(paperCount + 1 == conferencePage.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement .findElements(By.tagName("input")) @@ -215,11 +215,31 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); - WebElement paper = conferencePage.getPapers().get(0); + WebElement paper = conferencePage.getArticles().get(0); String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); paper.findElement(By.tagName("a")).click(); Assertions.assertThat(conferencePage.getName()) .isEqualTo(paperName); } + + @Test + public void testUndockArticle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getArticlesCount(); + + conferencePage.clickUndockArticleBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount - 1 == conferencePage.getArticlesCount()); + } } From 6edcf8f5940fa3b3c0a0179d6910189412b8d230 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 21:15:49 +0400 Subject: [PATCH 091/105] #103 add sort and filter test, fixed delete conference, if it has fk with event --- .../conference/service/ConferenceService.java | 1 + .../ulstu/timeline/service/EventService.java | 5 ++ src/test/java/IndexConferenceTest.java | 57 +++++++++++++++---- src/test/java/conference/ConferencePage.java | 15 +++-- src/test/java/conference/ConferencesPage.java | 10 ++++ 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38de435..e0662a2 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -127,6 +127,7 @@ public class ConferenceService { @Transactional public void delete(Integer conferenceId) { if (conferenceRepository.exists(conferenceId)) { + eventService.removeConferencesEvent(conferenceRepository.findOne(conferenceId)); conferenceRepository.delete(conferenceId); } } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index b935f16..cd56a52 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -203,4 +203,9 @@ public class EventService { eventRepository.delete(eventRepository.findAllByGrant(grant)); createFromGrant(grant); } + + public void removeConferencesEvent(Conference conference) { + List eventList = eventRepository.findAllByConference(conference); + eventList.forEach(event -> eventRepository.delete(event.getId())); + } } diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index b3314ff..47af27f 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -159,22 +159,22 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.showAllowToAttachArticles(); - WebElement paper = conferencePage.selectPaper(); + WebElement paper = conferencePage.selectArticle(); String paperName = paper.findElement(By.className("text")).getText(); conferencePage.clickSaveBut(); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(paperCount + 1 == conferencePage.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement - .findElement(By.className("paper-name")) - .findElements(By.tagName("span")) - .get(1).getText().equals(paperName))); + .findElements(By.tagName("input")) + .get(1).getAttribute("value") + .equals(paperName))); } @Test @@ -187,17 +187,17 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.clickAddPaperBut(); - List webElements = conferencePage.getPapers(); + List webElements = conferencePage.getArticles(); String paperName = webElements.get(webElements.size() - 1).findElements(By.tagName("input")).get(1).getAttribute("value"); conferencePage.clickSaveBut(); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(paperCount + 1 == conferencePage.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement .findElements(By.tagName("input")) @@ -215,11 +215,44 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); - WebElement paper = conferencePage.getPapers().get(0); + WebElement paper = conferencePage.getArticles().get(0); String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); paper.findElement(By.tagName("a")).click(); Assertions.assertThat(conferencePage.getName()) .isEqualTo(paperName); } + + @Test + public void testUndockArticle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getArticlesCount(); + + conferencePage.clickUndockArticleBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount - 1 == conferencePage.getArticlesCount()); + } + + @Test + public void testSortAndFilterConferenceList() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + + conferencesPage.selectMember(); + conferencesPage.selectYear(); + + Assert.assertEquals(1, conferencesPage.getConferencesList().size()); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 1a4a1df..50e545e 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -72,21 +72,26 @@ public class ConferencePage extends PageObject { driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click(); } - public List getPapers() { + public void clickAddPaperBut() { + driver.findElement(By.id("add-paper")).click(); + } + + + public List getArticles() { return driver.findElements(By.className("paper")); } - public Integer getPaperCount() { + public Integer getArticlesCount() { return driver.findElements(By.className("paper")).size(); } - public WebElement selectPaper() { + public WebElement selectArticle() { WebElement webElement = driver.findElement(By.xpath("//*[@id=\"conference-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a")); webElement.click(); return webElement; } - public void clickAddPaperBut() { - driver.findElement(By.id("add-paper")).click(); + public void clickUndockArticleBut() { + driver.findElement(By.name("removePaper")).click(); } } \ No newline at end of file diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index b258420..795ccf3 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -19,4 +19,14 @@ public class ConferencesPage extends PageObject { public void getConferenceFirst() { driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click(); } + + public void selectMember() { + driver.findElements(By.className("bootstrap-select")).get(0).findElement(By.className("btn")).click(); + driver.findElements(By.className("bootstrap-select")).get(0).findElements(By.className("dropdown-item")).get(1).click(); + } + + public void selectYear() { + driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click(); + driver.findElements(By.className("bootstrap-select")).get(1).findElements(By.className("dropdown-item")).get(1).click(); + } } \ No newline at end of file From b2e8a43ceec6f280324bea07c33d838cfd9c32ef Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sat, 11 May 2019 00:51:57 +0400 Subject: [PATCH 092/105] #103 delete conf test --- src/test/java/IndexConferenceTest.java | 15 +++++++++++++++ src/test/java/conference/ConferencesPage.java | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 47af27f..64b144d 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -255,4 +255,19 @@ public class IndexConferenceTest extends TestTemplate { Assert.assertEquals(1, conferencesPage.getConferencesList().size()); } + + @Test + public void testDeleteConf() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + + Integer size = conferencesPage.getConferencesList().size(); + conferencesPage.deleteFirst(); + Thread.sleep(2000); + conferencesPage.clickConfirm(); + + Assert.assertEquals(size - 1, conferencesPage.getConferencesList().size()); + } } diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index 795ccf3..9cccf3f 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -29,4 +29,12 @@ public class ConferencesPage extends PageObject { driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click(); driver.findElements(By.className("bootstrap-select")).get(1).findElements(By.className("dropdown-item")).get(1).click(); } + + public void deleteFirst() { + driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/input[2]")).submit(); + } + + public void clickConfirm() { + driver.findElement(By.xpath("//*[@id=\"deleteConference\"]")).click(); + } } \ No newline at end of file From d846192046aae130e1882f0e889845a664c4180c Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 00:28:03 +0400 Subject: [PATCH 093/105] #111 fixes --- .../controller/ConferenceController.java | 7 ++++++- .../repository/ConferenceRepository.java | 8 ++++---- .../conference/service/ConferenceService.java | 13 +++---------- src/main/java/ru/ulstu/name/BaseRepository.java | 7 +++++++ src/main/java/ru/ulstu/name/BaseService.java | 16 ++++++++++++++++ src/main/java/ru/ulstu/name/NameContainer.java | 10 ---------- src/main/java/ru/ulstu/name/NameRepository.java | 7 ------- src/main/java/ru/ulstu/name/NameService.java | 11 ----------- 8 files changed, 36 insertions(+), 43 deletions(-) create mode 100644 src/main/java/ru/ulstu/name/BaseRepository.java create mode 100644 src/main/java/ru/ulstu/name/BaseService.java delete mode 100644 src/main/java/ru/ulstu/name/NameRepository.java delete mode 100644 src/main/java/ru/ulstu/name/NameService.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 4e11d32..48a2ef2 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -76,7 +76,12 @@ public class ConferenceController { public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { conferenceService.filterEmptyDeadlines(conferenceDto); conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors); - conferenceService.checkUniqueName(conferenceDto, errors); + conferenceDto.setName(conferenceDto.getTitle()); + conferenceService.checkUniqueName(conferenceDto, + errors, + conferenceDto.getId(), + "title", + "Конференция с таким именем уже существует"); if (errors.hasErrors()) { return CONFERENCE_PAGE; } diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 5dfe7dd..2b0a428 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -5,13 +5,13 @@ 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; -import ru.ulstu.name.NameRepository; +import ru.ulstu.name.BaseRepository; import ru.ulstu.user.model.User; import java.util.Date; import java.util.List; -public interface ConferenceRepository extends JpaRepository, NameRepository { +public interface ConferenceRepository extends JpaRepository, BaseRepository { @Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " + "AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC") List findByUserAndYear(@Param("user") User user, @Param("year") Integer year); @@ -27,6 +27,6 @@ public interface ConferenceRepository extends JpaRepository int updatePingConference(@Param("id") Integer id); @Override - @Query("SELECT title FROM Conference c WHERE c.title = :name") - String findByName(@Param("name") String name); + @Query("SELECT title FROM Conference c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ") + String findByNameAndNotId(@Param("name") String name, @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 9a10efb..8ffeb6f 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -13,7 +13,7 @@ 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.name.NameService; +import ru.ulstu.name.BaseService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.ping.service.PingService; @@ -32,7 +32,7 @@ import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @Service -public class ConferenceService extends NameService { +public class ConferenceService extends BaseService { private final static int MAX_DISPLAY_SIZE = 40; private final ConferenceRepository conferenceRepository; @@ -52,6 +52,7 @@ public class ConferenceService extends NameService { PingService pingService, ConferenceNotificationService conferenceNotificationService, EventService eventService) { + this.baseRepository = conferenceRepository; this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; @@ -286,12 +287,4 @@ public class ConferenceService extends NameService { .filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription())) .collect(Collectors.toList())); } - - public void checkUniqueName(ConferenceDto conferenceDto, Errors errors) { - conferenceDto.setName(conferenceDto.getTitle()); - conferenceDto.setNameRepository(conferenceRepository); - if (checkUniqueName(conferenceDto)) { - errors.rejectValue("title", "errorCode", "Конференция с таким именем уже существует"); - } - } } diff --git a/src/main/java/ru/ulstu/name/BaseRepository.java b/src/main/java/ru/ulstu/name/BaseRepository.java new file mode 100644 index 0000000..b691ea2 --- /dev/null +++ b/src/main/java/ru/ulstu/name/BaseRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.name; + +import org.springframework.data.repository.query.Param; + +public interface BaseRepository { + String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id); +} diff --git a/src/main/java/ru/ulstu/name/BaseService.java b/src/main/java/ru/ulstu/name/BaseService.java new file mode 100644 index 0000000..6619385 --- /dev/null +++ b/src/main/java/ru/ulstu/name/BaseService.java @@ -0,0 +1,16 @@ +package ru.ulstu.name; + +import org.springframework.stereotype.Service; +import org.springframework.validation.Errors; + +@Service +public abstract class BaseService { + + public BaseRepository baseRepository; + + public void checkUniqueName(NameContainer nameContainer, Errors errors, Integer id, String checkField, String errorMessage) { + if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) { + errors.rejectValue(checkField, "errorCode", errorMessage); + } + } +} diff --git a/src/main/java/ru/ulstu/name/NameContainer.java b/src/main/java/ru/ulstu/name/NameContainer.java index bcccc80..4339fb2 100644 --- a/src/main/java/ru/ulstu/name/NameContainer.java +++ b/src/main/java/ru/ulstu/name/NameContainer.java @@ -4,16 +4,6 @@ public abstract class NameContainer { private String name = ""; - private NameRepository nameRepository; - - public NameRepository getNameRepository() { - return nameRepository; - } - - public void setNameRepository(NameRepository nameRepository) { - this.nameRepository = nameRepository; - } - public String getName() { return name; } diff --git a/src/main/java/ru/ulstu/name/NameRepository.java b/src/main/java/ru/ulstu/name/NameRepository.java deleted file mode 100644 index 99bd3ac..0000000 --- a/src/main/java/ru/ulstu/name/NameRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.ulstu.name; - -import org.springframework.data.repository.query.Param; - -public interface NameRepository { - String findByName(@Param("name") String name); -} diff --git a/src/main/java/ru/ulstu/name/NameService.java b/src/main/java/ru/ulstu/name/NameService.java deleted file mode 100644 index 7d7bdc9..0000000 --- a/src/main/java/ru/ulstu/name/NameService.java +++ /dev/null @@ -1,11 +0,0 @@ -package ru.ulstu.name; - -import org.springframework.stereotype.Service; - -@Service -public abstract class NameService { - - public boolean checkUniqueName(NameContainer nameContainer) { - return nameContainer.getName().equals(nameContainer.getNameRepository().findByName(nameContainer.getName())); - } -} From a11e10dec45a37fcda54be3778f7d185f1ea62b9 Mon Sep 17 00:00:00 2001 From: ASH Date: Sun, 12 May 2019 01:00:26 +0400 Subject: [PATCH 094/105] #123 adding task timeline --- .../java/ru/ulstu/students/model/Task.java | 2 ++ .../ulstu/students/service/TaskService.java | 7 ++++- .../java/ru/ulstu/timeline/model/Event.java | 13 ++++++++ .../ru/ulstu/timeline/model/EventDto.java | 17 ++++++++++- .../timeline/repository/EventRepository.java | 3 ++ .../ulstu/timeline/service/EventService.java | 30 +++++++++++++++++++ .../db/changelog-20190511_000000-schema.xml | 13 ++++++++ src/main/resources/db/changelog-master.xml | 1 + 8 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/db/changelog-20190511_000000-schema.xml diff --git a/src/main/java/ru/ulstu/students/model/Task.java b/src/main/java/ru/ulstu/students/model/Task.java index 8ec9081..2a03e37 100644 --- a/src/main/java/ru/ulstu/students/model/Task.java +++ b/src/main/java/ru/ulstu/students/model/Task.java @@ -67,6 +67,7 @@ public class Task extends BaseEntity { private Date updateDate = new Date(); @ManyToMany(fetch = FetchType.EAGER) + @Fetch(FetchMode.SUBSELECT) @JoinTable(name = "task_tags", joinColumns = {@JoinColumn(name = "task_id")}, inverseJoinColumns = {@JoinColumn(name = "tag_id")}) @@ -127,4 +128,5 @@ public class Task extends BaseEntity { public void setTags(List tags) { this.tags = tags; } + } diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index a8747c7..8f335ac 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -11,6 +11,7 @@ import ru.ulstu.students.model.TaskFilterDto; import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.tags.model.Tag; import ru.ulstu.tags.service.TagService; +import ru.ulstu.timeline.service.EventService; import java.io.IOException; import java.util.Arrays; @@ -29,12 +30,14 @@ public class TaskService { private final TaskRepository taskRepository; private final DeadlineService deadlineService; private final TagService tagService; + private final EventService eventService; public TaskService(TaskRepository taskRepository, - DeadlineService deadlineService, TagService tagService) { + DeadlineService deadlineService, TagService tagService, EventService eventService) { this.taskRepository = taskRepository; this.deadlineService = deadlineService; this.tagService = tagService; + this.eventService = eventService; } public List findAll() { @@ -67,6 +70,7 @@ public class TaskService { public Integer create(TaskDto taskDto) throws IOException { Task newTask = copyFromDto(new Task(), taskDto); newTask = taskRepository.save(newTask); + eventService.createFromTask(newTask); return newTask.getId(); } @@ -86,6 +90,7 @@ public class TaskService { public Integer update(TaskDto taskDto) throws IOException { Task task = taskRepository.findOne(taskDto.getId()); taskRepository.save(copyFromDto(task, taskDto)); + eventService.updateTaskDeadlines(task); return task.getId(); } diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index 9252cec..e56c91c 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -5,6 +5,7 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.students.model.Task; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; @@ -87,6 +88,10 @@ public class Event extends BaseEntity { @JoinColumn(name = "grant_id") private Grant grant; + @ManyToOne + @JoinColumn(name = "task_id") + private Task task; + public String getTitle() { return title; } @@ -190,4 +195,12 @@ public class Event extends BaseEntity { public void setGrant(Grant grant) { this.grant = grant; } + + public Task getTask() { + return task; + } + + public void setTask(Task task) { + this.task = task; + } } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index 89df5d8..ccf0f0a 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.students.model.TaskDto; import ru.ulstu.user.model.UserDto; import javax.validation.constraints.NotNull; @@ -29,6 +30,7 @@ public class EventDto { private PaperDto paperDto; private ConferenceDto conferenceDto; private GrantDto grantDto; + private TaskDto taskDto; @JsonCreator public EventDto(@JsonProperty("id") Integer id, @@ -42,7 +44,8 @@ public class EventDto { @JsonProperty("paperDto") PaperDto paperDto, @JsonProperty("recipients") List recipients, @JsonProperty("conferenceDto") ConferenceDto conferenceDto, - @JsonProperty("grantDto") GrantDto grantDto) { + @JsonProperty("grantDto") GrantDto grantDto, + @JsonProperty("taskDto") TaskDto taskDto) { this.id = id; this.title = title; this.period = period; @@ -55,6 +58,7 @@ public class EventDto { this.paperDto = paperDto; this.conferenceDto = conferenceDto; this.grantDto = grantDto; + this.taskDto = taskDto; } public EventDto(Event event) { @@ -76,6 +80,9 @@ public class EventDto { if (grantDto != null) { this.grantDto = new GrantDto(event.getGrant()); } + if (taskDto != null) { + this.taskDto = new TaskDto(event.getTask()); + } } public Integer getId() { @@ -137,4 +144,12 @@ public class EventDto { public void setGrantDto(GrantDto grantDto) { this.grantDto = grantDto; } + + public TaskDto getTaskDto() { + return taskDto; + } + + public void setTaskDto(TaskDto taskDto) { + this.taskDto = taskDto; + } } diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java index e01037a..7ebd3c9 100644 --- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java +++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query; import ru.ulstu.conference.model.Conference; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.students.model.Task; import ru.ulstu.timeline.model.Event; import java.util.List; @@ -21,4 +22,6 @@ public interface EventRepository extends JpaRepository { List findAllByConference(Conference conference); List findAllByGrant(Grant grant); + + List findAllByTask(Task task); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index b935f16..9a2671c 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -8,6 +8,7 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.students.model.Task; import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.EventDto; import ru.ulstu.timeline.model.Timeline; @@ -203,4 +204,33 @@ public class EventService { eventRepository.delete(eventRepository.findAllByGrant(grant)); createFromGrant(grant); } + + public void createFromTask(Task newTask) { + List timelines = timelineService.findAll(); + Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); + + for (Deadline deadline : newTask.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() + "' задачи '" + newTask.getTitle() + "'"); + newEvent.getRecipients().add(userService.getCurrentUser()); + newEvent.setTask(newTask); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + } + + public void updateTaskDeadlines(Task task) { + eventRepository.delete(eventRepository.findAllByTask(task)); + createFromTask(task); + } } diff --git a/src/main/resources/db/changelog-20190511_000000-schema.xml b/src/main/resources/db/changelog-20190511_000000-schema.xml new file mode 100644 index 0000000..62e914f --- /dev/null +++ b/src/main/resources/db/changelog-20190511_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 0dc15e5..98e3c17 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -40,4 +40,5 @@ + \ No newline at end of file From 5b4180e68525337b2876a68ce8cf5b461316cb30 Mon Sep 17 00:00:00 2001 From: ASH Date: Sun, 12 May 2019 11:04:43 +0400 Subject: [PATCH 095/105] #123 fixing layout --- src/main/resources/public/css/tasks.css | 36 +++++++++++++++++++ src/main/resources/public/js/tasks.js | 22 ++++++------ .../students/fragments/taskLineFragment.html | 12 +++---- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/main/resources/public/css/tasks.css b/src/main/resources/public/css/tasks.css index 7e350ed..1c190b5 100644 --- a/src/main/resources/public/css/tasks.css +++ b/src/main/resources/public/css/tasks.css @@ -39,6 +39,42 @@ max-width: inherit; } +.task-row{ + + position: relative; +} + +.task-row .col:hover{ + + background-color: #f8f9fa; + +} + +.task-row .col > a{ + display: block; + text-decoration: none; +} + +.task-row .col:hover .remove-task{ + + visibility: visible; + +} + +.remove-task{ + visibility: hidden; + position: absolute; + right: -20px; + top: 50%; + transform: translate(-50%, -50%); + padding: 0 20px; +} + +.remove-task:hover{ + + background-color: #ebebeb; +} + .tag { display: inline-block; padding: .2em .6em .3em; diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index f756199..84b9567 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -70,17 +70,17 @@ $(document).ready(function () { }); $("span[data-role=remove]").click(removeTag); - $(".task-row").mouseenter(function (event) { - var taskRow = $(event.target).closest(".task-row"); - $(taskRow).css("background-color", "#f8f9fa"); - $(taskRow).find(".remove-task").removeClass("d-none"); - - }); - $(".task-row").mouseleave(function (event) { - var taskRow = $(event.target).closest(".task-row"); - $(taskRow).css("background-color", "white"); - $(taskRow).closest(".task-row").find(".remove-task").addClass("d-none"); - }); +// $(".task-row").mouseenter(function (event) { +// var taskRow = $(event.target).closest(".task-row"); +// $(taskRow).css("background-color", "#f8f9fa"); +// $(taskRow).find(".remove-task").removeClass("d-none"); +// +// }); +// $(".task-row").mouseleave(function (event) { +// var taskRow = $(event.target).closest(".task-row"); +// $(taskRow).css("background-color", "white"); +// $(taskRow).closest(".task-row").find(".remove-task").addClass("d-none"); +// }); $('a[data-confirm]').click(function(ev) { var href = $(this).attr('href'); diff --git a/src/main/resources/templates/students/fragments/taskLineFragment.html b/src/main/resources/templates/students/fragments/taskLineFragment.html index baad17e..210863d 100644 --- a/src/main/resources/templates/students/fragments/taskLineFragment.html +++ b/src/main/resources/templates/students/fragments/taskLineFragment.html @@ -6,15 +6,15 @@ From fe53c86136284413d153e6fc34700851ce98926e Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 13:42:50 +0400 Subject: [PATCH 096/105] #103 fixed delete conf test --- src/test/java/IndexConferenceTest.java | 71 +++++++++---------- src/test/java/conference/ConferencesPage.java | 4 +- src/test/java/core/PageObject.java | 3 + 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 64b144d..e893630 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -5,10 +5,11 @@ import conference.ConferencesDashboardPage; import conference.ConferencesPage; import core.PageObject; import core.TestTemplate; -import org.assertj.core.api.Assertions; import org.junit.Assert; +import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +24,7 @@ import java.util.List; import java.util.Map; @RunWith(SpringRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) @SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) public class IndexConferenceTest extends TestTemplate { private final Map> navigationHolder = ImmutableMap.of( @@ -35,15 +37,7 @@ public class IndexConferenceTest extends TestTemplate { private ApplicationProperties applicationProperties; @Test - public void testStartApplication() { - getContext().goTo(applicationProperties.getBaseUrl()); - Assertions - .assertThat(getContext().getTitle()) - .isEqualTo("NG-Tracker"); - } - - @Test - public void testCreateNewConference() { + public void testA_CreateNewConference() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -60,7 +54,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testChangeConferenceNameAndSave() { + public void testB_ChangeConferenceNameAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -79,7 +73,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testAddDeadlineAndSave() { + public void testC_AddDeadlineAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -109,7 +103,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testTakePartAndSave() { + public void testD_TakePartAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -130,7 +124,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testDeleteDeadlineAndSave() { + public void testE_DeleteDeadlineAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -146,11 +140,11 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(deadlineCount - 1 == conferencePage.getDeadlineCount()); + Assert.assertEquals(deadlineCount - 1, (int) conferencePage.getDeadlineCount()); } @Test - public void testAttachArticle() { + public void testF_AttachArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -178,7 +172,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testAddArticle() { + public void testG_AddArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -205,26 +199,27 @@ public class IndexConferenceTest extends TestTemplate { .equals(paperName))); } - @Test - public void testTransitionToTheArticle() { - Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); - - getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); - ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); - ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - - conferencesPage.getConferenceFirst(); - - WebElement paper = conferencePage.getArticles().get(0); - String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); - paper.findElement(By.tagName("a")).click(); - - Assertions.assertThat(conferencePage.getName()) - .isEqualTo(paperName); - } +// @Test +// @Order(8) +// public void testTransitionToTheArticle() { +// Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); +// +// getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); +// ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); +// ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); +// +// conferencesPage.getConferenceFirst(); +// +// WebElement paper = conferencePage.getArticles().get(0); +// String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); +// paper.findElement(By.tagName("a")).click(); +// +// Assertions.assertThat(conferencePage.getName()) +// .isEqualTo(paperName); +// } @Test - public void testUndockArticle() { + public void testH_UndockArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -244,7 +239,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testSortAndFilterConferenceList() { + public void testI_SortAndFilterConferenceList() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -257,7 +252,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testDeleteConf() throws InterruptedException { + public void testJ_DeleteConf() throws InterruptedException { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -265,7 +260,7 @@ public class IndexConferenceTest extends TestTemplate { Integer size = conferencesPage.getConferencesList().size(); conferencesPage.deleteFirst(); - Thread.sleep(2000); + Thread.sleep(3000); conferencesPage.clickConfirm(); Assert.assertEquals(size - 1, conferencesPage.getConferencesList().size()); diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index 9cccf3f..5129f89 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -31,10 +31,10 @@ public class ConferencesPage extends PageObject { } public void deleteFirst() { - driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/input[2]")).submit(); + js.executeScript("$('input[data-confirm]').click();"); } public void clickConfirm() { - driver.findElement(By.xpath("//*[@id=\"deleteConference\"]")).click(); + driver.findElement(By.id("deleteConference")).click(); } } \ No newline at end of file diff --git a/src/test/java/core/PageObject.java b/src/test/java/core/PageObject.java index d1fae83..f3e5cb8 100644 --- a/src/test/java/core/PageObject.java +++ b/src/test/java/core/PageObject.java @@ -1,14 +1,17 @@ package core; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; public abstract class PageObject { protected WebDriver driver; + protected JavascriptExecutor js; public abstract String getSubTitle(); public PageObject setDriver(WebDriver driver) { this.driver = driver; + js = (JavascriptExecutor) driver; return this; } } From 70062992ae44493b6ec871a8a53ccd3aac23d29e Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 13:45:17 +0400 Subject: [PATCH 097/105] #103 clear code --- src/test/java/IndexConferenceTest.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index e893630..7796502 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -199,25 +199,6 @@ public class IndexConferenceTest extends TestTemplate { .equals(paperName))); } -// @Test -// @Order(8) -// public void testTransitionToTheArticle() { -// Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); -// -// getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); -// ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); -// ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); -// -// conferencesPage.getConferenceFirst(); -// -// WebElement paper = conferencePage.getArticles().get(0); -// String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); -// paper.findElement(By.tagName("a")).click(); -// -// Assertions.assertThat(conferencePage.getName()) -// .isEqualTo(paperName); -// } - @Test public void testH_UndockArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); From 5cbbb6c3190e2a28d793f8865722abef100475d4 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 13:49:49 +0400 Subject: [PATCH 098/105] #103 fix code style --- src/test/java/IndexConferenceTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 7796502..c38414a 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -37,7 +37,7 @@ public class IndexConferenceTest extends TestTemplate { private ApplicationProperties applicationProperties; @Test - public void testA_CreateNewConference() { + public void testACreateNewConference() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -54,7 +54,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testB_ChangeConferenceNameAndSave() { + public void testBChangeConferenceNameAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -73,7 +73,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testC_AddDeadlineAndSave() { + public void testCAddDeadlineAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -103,7 +103,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testD_TakePartAndSave() { + public void testDTakePartAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -124,7 +124,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testE_DeleteDeadlineAndSave() { + public void testEDeleteDeadlineAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -144,7 +144,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testF_AttachArticle() { + public void testFAttachArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -172,7 +172,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testG_AddArticle() { + public void testGAddArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -200,7 +200,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testH_UndockArticle() { + public void testHUndockArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -216,7 +216,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(paperCount - 1 == conferencePage.getArticlesCount()); + Assert.assertEquals(paperCount - 1, (int) conferencePage.getArticlesCount()); } @Test From 451e7e5d04728e85a627852b3340b2b313b8e804 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 13:50:46 +0400 Subject: [PATCH 099/105] #103 fix code style --- src/test/java/IndexConferenceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index c38414a..7dbd39b 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -220,7 +220,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testI_SortAndFilterConferenceList() { + public void testISortAndFilterConferenceList() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -233,7 +233,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testJ_DeleteConf() throws InterruptedException { + public void testJDeleteConf() throws InterruptedException { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); From e1907d316920f1e00ec15a72a2cfdd55665f238c Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sun, 12 May 2019 15:28:47 +0400 Subject: [PATCH 100/105] #121 change Paper to PaperDto in attaching papers --- .../ru/ulstu/grant/controller/GrantController.java | 5 ++--- src/main/java/ru/ulstu/grant/model/Grant.java | 1 - src/main/java/ru/ulstu/grant/model/GrantDto.java | 14 +++++++------- .../java/ru/ulstu/paper/service/PaperService.java | 8 ++++---- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index b28f8c0..ad5e992 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -13,7 +13,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.service.GrantService; -import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.model.PaperDto; import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; @@ -104,7 +104,6 @@ public class GrantController { return GRANT_PAGE; } - @PostMapping(value = "/grant", params = "createProject") public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException { if (errors.hasErrors()) { @@ -131,7 +130,7 @@ public class GrantController { } @ModelAttribute("allPapers") - public List getAllPapers() { + public List getAllPapers() { return grantService.getAllUncompletedPapers(); } diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 760895e..e0cd9be 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -74,7 +74,6 @@ public class Grant extends BaseEntity implements UserContainer { @Fetch(FetchMode.SUBSELECT) private List files = new ArrayList<>(); - @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "project_id") private Project project; diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index e842b10..203d306 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -6,7 +6,7 @@ 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.paper.model.PaperDto; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.user.model.UserDto; @@ -37,7 +37,7 @@ public class GrantDto { private boolean hasBAKPapers; private boolean hasScopusPapers; private List paperIds = new ArrayList<>(); - private List papers = new ArrayList<>(); + private List papers = new ArrayList<>(); private List removedDeadlineIds = new ArrayList<>(); public GrantDto() { @@ -54,12 +54,12 @@ public class GrantDto { @JsonProperty("project") ProjectDto project, @JsonProperty("authorIds") Set authorIds, @JsonProperty("authors") Set authors, - @JsonProperty("leader") Integer leaderId, + @JsonProperty("leaderId") Integer leaderId, @JsonProperty("wasLeader") boolean wasLeader, @JsonProperty("hasAge") boolean hasAge, @JsonProperty("hasDegree") boolean hasDegree, @JsonProperty("paperIds") List paperIds, - @JsonProperty("papers") List papers) { + @JsonProperty("papers") List papers) { this.id = id; this.title = title; this.status = status; @@ -92,7 +92,7 @@ public class GrantDto { this.hasAge = false; this.hasDegree = false; this.paperIds = convert(grant.getPapers(), paper -> paper.getId()); - this.papers = grant.getPapers(); + this.papers = convert(grant.getPapers(), PaperDto::new); } public Integer getId() { @@ -214,11 +214,11 @@ public class GrantDto { this.paperIds = paperIds; } - public List getPapers() { + public List getPapers() { return papers; } - public void setPapers(List papers) { + public void setPapers(List papers) { this.papers = papers; } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 0083de7..db810f5 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -248,12 +248,12 @@ public class PaperService { } } - public List findAllNotCompleted() { - return paperRepository.findByStatusNot(COMPLETED); + public List findAllNotCompleted() { + return convert(paperRepository.findByStatusNot(COMPLETED), PaperDto::new); } - public List findAllSelect(List paperIds) { - return sortPapers(paperRepository.findAllByIdIn(paperIds)); + public List findAllSelect(List paperIds) { + return convert(paperRepository.findAllByIdIn(paperIds), PaperDto::new); } public List getPaperAuthors() { From 99ec7af3191409e2f08fb437576655adc00c8448 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sun, 12 May 2019 15:30:09 +0400 Subject: [PATCH 101/105] #121 reduce paper title --- .../ru/ulstu/grant/service/GrantService.java | 18 +++++++++--------- 1 file changed, 9 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 83ef49e..45f9b2f 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -11,6 +11,7 @@ import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.service.PaperService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -34,7 +35,7 @@ import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @Service public class GrantService { - private final static int MAX_DISPLAY_SIZE = 40; + private final static int MAX_DISPLAY_SIZE = 50; private final GrantRepository grantRepository; private final ProjectService projectService; @@ -210,17 +211,16 @@ public class GrantService { .collect(toList()); } - public List getGrantPapers(List paperIds) { + public List getGrantPapers(List paperIds) { return paperService.findAllSelect(paperIds); - } - public List getAllPapers() { - return paperService.findAll(); - } - - public List getAllUncompletedPapers() { - return paperService.findAllNotCompleted(); + public List getAllUncompletedPapers() { + List papers = paperService.findAllNotCompleted(); + papers.stream() + .forEach(paper -> + paper.setTitle(StringUtils.abbreviate(paper.getTitle(), MAX_DISPLAY_SIZE))); + return papers; } public void attachPaper(GrantDto grantDto) { From f6830d499b03f45b7bf42e31fdde496e9ae2f9ec Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sun, 12 May 2019 15:31:50 +0400 Subject: [PATCH 102/105] #121 update view --- src/main/resources/templates/grants/grant.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index e357876..38047bf 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -184,9 +184,9 @@ value="Отобразить прикрепленную статью"/>
From 6044d6f8e398e0aa6b5706066511a2133de304de Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Mon, 13 May 2019 19:08:21 +0400 Subject: [PATCH 103/105] #111 save method refactor --- .../controller/ConferenceController.java | 11 +---------- .../conference/service/ConferenceService.java | 16 +++++++++++++++- .../templates/conferences/conference.html | 7 ++++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 48a2ef2..f9a4bac 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -74,18 +74,9 @@ public class ConferenceController { @PostMapping(value = "/conference", params = "save") public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { - conferenceService.filterEmptyDeadlines(conferenceDto); - conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors); - conferenceDto.setName(conferenceDto.getTitle()); - conferenceService.checkUniqueName(conferenceDto, - errors, - conferenceDto.getId(), - "title", - "Конференция с таким именем уже существует"); - if (errors.hasErrors()) { + if (!conferenceService.save(conferenceDto, errors)) { return CONFERENCE_PAGE; } - conferenceService.save(conferenceDto); return String.format(REDIRECT_TO, CONFERENCES_PAGE); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 8ffeb6f..d3ef2da 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -91,12 +91,26 @@ public class ConferenceService extends BaseService { return new ConferenceDto(conferenceRepository.findOne(id)); } - public void save(ConferenceDto conferenceDto) throws IOException { + public boolean save(ConferenceDto conferenceDto, Errors errors) throws IOException { + conferenceDto.setName(conferenceDto.getTitle()); + filterEmptyDeadlines(conferenceDto); + checkEmptyFieldsOfDeadline(conferenceDto, errors); + checkUniqueName(conferenceDto, + errors, + conferenceDto.getId(), + "title", + "Конференция с таким именем уже существует"); + if (errors.hasErrors()) { + return false; + } + if (isEmpty(conferenceDto.getId())) { create(conferenceDto); } else { update(conferenceDto); } + + return true; } @Transactional diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index d5906b6..d629d4e 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -30,11 +30,12 @@ -

Incorrect title

-

+

Incorrect title

+

+
Date: Mon, 13 May 2019 20:13:53 +0400 Subject: [PATCH 104/105] #103 code refactoring --- src/test/java/IndexConferenceTest.java | 45 ++++++------------- src/test/java/conference/ConferencePage.java | 23 +++++++++- src/test/java/conference/ConferencesPage.java | 9 +++- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 7dbd39b..269561f 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -48,9 +48,7 @@ public class IndexConferenceTest extends TestTemplate { conferencePage.setName(newConferenceName); conferencePage.clickSaveBut(); - Assert.assertTrue(conferencesPage.getConferencesList() - .stream() - .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); + Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName)); } @Test @@ -61,15 +59,13 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String newConferenceName = "test " + (new Date()).getTime(); conferencePage.clearName(); conferencePage.setName(newConferenceName); conferencePage.clickSaveBut(); - Assert.assertTrue(conferencesPage.getConferencesList() - .stream() - .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); + Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName)); } @Test @@ -80,7 +76,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer deadlineCount = conferencePage.getDeadlineCount(); @@ -94,12 +90,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(conferencePage.getDeadlineList() - .stream() - .anyMatch(webElement -> { - return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description) - && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); - })); + Assert.assertTrue(conferencePage.checkDeadline(description, dateValue)); } @Test @@ -110,7 +101,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer membersCount = conferencePage.getMemberCount(); @@ -120,7 +111,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); Assert.assertTrue(membersCount + 1 == conferencePage.getMemberCount() - && conferencePage.getTakePartButDisabledValue().equals("true")); + && conferencePage.isTakePartButDisabledValueTrue()); } @Test @@ -131,7 +122,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer deadlineCount = conferencePage.getDeadlineCount(); @@ -151,7 +142,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer paperCount = conferencePage.getArticlesCount(); @@ -163,12 +154,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() - && conferencePage.getArticles() - .stream() - .anyMatch(webElement -> webElement - .findElements(By.tagName("input")) - .get(1).getAttribute("value") - .equals(paperName))); + && conferencePage.checkArticle(paperName)); } @Test @@ -179,7 +165,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer paperCount = conferencePage.getArticlesCount(); @@ -191,12 +177,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() - && conferencePage.getArticles() - .stream() - .anyMatch(webElement -> webElement - .findElements(By.tagName("input")) - .get(1).getAttribute("value") - .equals(paperName))); + && conferencePage.checkArticle(paperName)); } @Test @@ -207,7 +188,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer paperCount = conferencePage.getArticlesCount(); diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 50e545e..ef0d941 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -56,8 +56,8 @@ public class ConferencePage extends PageObject { driver.findElement(By.id("take-part")).click(); } - public String getTakePartButDisabledValue() { - return driver.findElement(By.id("take-part")).getAttribute("disabled"); + public Boolean isTakePartButDisabledValueTrue() { + return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true"); } public Integer getMemberCount() { @@ -94,4 +94,23 @@ public class ConferencePage extends PageObject { public void clickUndockArticleBut() { driver.findElement(By.name("removePaper")).click(); } + + public boolean checkDeadline(String description, String dateValue) { + return getDeadlineList() + .stream() + .anyMatch(webElement -> { + return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description) + && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); + }); + } + + public boolean checkArticle(String paperName) { + return getArticles() + .stream() + .anyMatch(webElement -> webElement + .findElements(By.tagName("input")) + .get(1).getAttribute("value") + .equals(paperName)); + } + } \ No newline at end of file diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index 5129f89..c11429f 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -16,7 +16,7 @@ public class ConferencesPage extends PageObject { return driver.findElements(By.cssSelector("span.h6.float-left.m-2")); } - public void getConferenceFirst() { + public void getFirstConference() { driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click(); } @@ -37,4 +37,11 @@ public class ConferencesPage extends PageObject { public void clickConfirm() { driver.findElement(By.id("deleteConference")).click(); } + + + public boolean checkNameInList(String newConferenceName) { + return getConferencesList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(newConferenceName)); + } } \ No newline at end of file From ab59cb524e4e3eecbbdd4bb56f475fe065445da5 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Mon, 13 May 2019 20:26:13 +0400 Subject: [PATCH 105/105] #103 fix code style --- src/main/resources/public/js/conference.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/public/js/conference.js b/src/main/resources/public/js/conference.js index 18a8c67..8273557 100644 --- a/src/main/resources/public/js/conference.js +++ b/src/main/resources/public/js/conference.js @@ -25,4 +25,5 @@ $(document).ready(function () { $('#dataConfirmModal').modal({show:true}); return false; }); + });