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

Проекты

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

Проекты

+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+ + From b4c11a7f90cd8dd6733959a8e15dd7ea478f389c Mon Sep 17 00:00:00 2001 From: ASH Date: Sun, 28 Apr 2019 23:58:35 +0400 Subject: [PATCH 002/128] #79 year generation --- .../students/repository/TaskRepository.java | 5 +++ .../service/TaskGenerationService.java | 25 ++++++++++++++ .../ulstu/students/service/TaskService.java | 33 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/main/java/ru/ulstu/students/service/TaskGenerationService.java diff --git a/src/main/java/ru/ulstu/students/repository/TaskRepository.java b/src/main/java/ru/ulstu/students/repository/TaskRepository.java index ee49ab8..0b17691 100644 --- a/src/main/java/ru/ulstu/students/repository/TaskRepository.java +++ b/src/main/java/ru/ulstu/students/repository/TaskRepository.java @@ -15,4 +15,9 @@ public interface TaskRepository extends JpaRepository { @Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC") List filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag); + + @Query("SELECT t FROM Task t WHERE (EXTRACT(DAY FROM t.createDate) = :day) AND (EXTRACT(MONTH FROM t.createDate) = :month) AND (EXTRACT" + + "(YEAR FROM t.createDate) = :year)") + List findToGenerate(@Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year); + } diff --git a/src/main/java/ru/ulstu/students/service/TaskGenerationService.java b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java new file mode 100644 index 0000000..d347140 --- /dev/null +++ b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java @@ -0,0 +1,25 @@ +package ru.ulstu.students.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class TaskGenerationService { + + private final Logger log = LoggerFactory.getLogger(TaskGenerationService.class); + private final TaskService taskService; + + public TaskGenerationService(TaskService taskService) { + + this.taskService = taskService; + } + + @Scheduled(cron = "0 * * ? * *", zone = "Europe/Samara") + public void generateYearTasks() { + log.debug("TaskService.generateYearTasks started"); + taskService.generateYearTasks(); + log.debug("TaskService.generateYearTasks finished"); + } +} diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index a8747c7..d35720d 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; @@ -14,8 +15,10 @@ import ru.ulstu.tags.service.TagService; import java.io.IOException; import java.util.Arrays; +import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -105,6 +108,36 @@ public class TaskService { } } + public Task copyYearTask(Task task) { + + Task newTask = new Task(); + newTask.setTitle(task.getTitle()); + newTask.setTags(tagService.saveOrCreate(task.getTags())); + newTask.setCreateDate(new Date()); + newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS); + newTask.setDeadlines(task.getDeadlines() + .stream() + .map(deadline -> { + Deadline newDeadline = new Deadline(); + Calendar cal = Calendar.getInstance(); + cal.setTime(deadline.getDate()); + cal.add(Calendar.YEAR, 1); + newDeadline.setDescription(deadline.getDescription()); + newDeadline.setDate(cal.getTime()); + return deadlineService.create(newDeadline); + }).collect(Collectors.toList())); + + return newTask; + } + + public void generateYearTasks() { + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + List tasks = taskRepository.findToGenerate(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); + System.out.println(cal.get(Calendar.DAY_OF_MONTH) + " " + cal.get(Calendar.MONTH)); + tasks.forEach(task -> taskRepository.save(copyYearTask(task))); + } + public List getTaskStatuses() { return Arrays.asList(Task.TaskStatus.values()); } From 7ce8b20841e8a16740aa1ec319737ee1283637a6 Mon Sep 17 00:00:00 2001 From: ASH Date: Tue, 30 Apr 2019 22:05:57 +0400 Subject: [PATCH 003/128] #79 fixing bug --- src/main/java/ru/ulstu/students/service/TaskService.java | 9 ++++++--- src/main/resources/public/js/tasks.js | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index d35720d..0fab0be 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -130,12 +130,15 @@ public class TaskService { return newTask; } + @Transactional public void generateYearTasks() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); - List tasks = taskRepository.findToGenerate(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)); - System.out.println(cal.get(Calendar.DAY_OF_MONTH) + " " + cal.get(Calendar.MONTH)); - tasks.forEach(task -> taskRepository.save(copyYearTask(task))); + List tasks = taskRepository.findToGenerate(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR) - 1); + tasks.forEach(task -> { + Task newTask = copyYearTask(task); + taskRepository.save(newTask); + }); } public List getTaskStatuses() { diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index f756199..0eb2da6 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -21,6 +21,14 @@ $(document).ready(function () { $("#input-tag").keyup(function (event) { if(event.keyCode == 13 || event.keyCode == 188) { var tagNumber = $("#tags .tag").length; + if(length != 0) { + tagNumber = $("#tags .tag").last() + .children('input') + .attr("name") + .split(']')[0] + .split('[')[1]; + tagNumber++; + } var tagName = $.trim($(this).val()); var addTag = true; // проверка, добавлен ли этот тег From ee55e08feee4ea20dfa52403996f0659cd42f1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 6 May 2019 17:43:20 +0300 Subject: [PATCH 004/128] #98 project tasks deadline edited --- .../conference/service/ConferenceService.java | 3 +- .../ru/ulstu/deadline/model/Deadline.java | 35 ++++++++++++++++--- .../ru/ulstu/grant/service/GrantService.java | 2 +- .../ru/ulstu/paper/service/PaperService.java | 2 +- .../project/controller/ProjectController.java | 7 ++++ .../ru/ulstu/project/model/ProjectDto.java | 9 +++++ .../ulstu/project/service/ProjectService.java | 7 ++++ .../db/changelog-20190506_000000-schema.xml | 13 +++++++ src/main/resources/db/changelog-master.xml | 1 + .../resources/templates/projects/project.html | 8 +++-- 10 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 src/main/resources/db/changelog-20190506_000000-schema.xml diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38de435..b42f981 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -267,7 +267,8 @@ public class ConferenceService { } public Deadline copyDeadline(Deadline oldDeadline) { - Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription()); + Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription(), + oldDeadline.getExecutor(), oldDeadline.getDone()); newDeadline.setId(oldDeadline.getId()); return newDeadline; } diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java index 148697c..9ab9acd 100644 --- a/src/main/java/ru/ulstu/deadline/model/Deadline.java +++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java @@ -20,21 +20,30 @@ public class Deadline extends BaseEntity { @DateTimeFormat(pattern = "yyyy-MM-dd") private Date date; + private String executor; + private Boolean done; + public Deadline() { } - public Deadline(Date deadlineDate, String description) { + public Deadline(Date deadlineDate, String description, String executor, Boolean done) { this.date = deadlineDate; this.description = description; + this.executor = executor; + this.done = done; } @JsonCreator public Deadline(@JsonProperty("id") Integer id, @JsonProperty("description") String description, - @JsonProperty("date") Date date) { + @JsonProperty("date") Date date, + @JsonProperty("executor") String executor, + @JsonProperty("done") Boolean done) { this.setId(id); this.description = description; this.date = date; + this.executor = executor; + this.done = done; } public String getDescription() { @@ -53,6 +62,22 @@ public class Deadline extends BaseEntity { this.date = date; } + public String getExecutor() { + return executor; + } + + public void setExecutor(String executor) { + this.executor = executor; + } + + public Boolean getDone() { + return done; + } + + public void setDone(Boolean done) { + this.done = done; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -67,11 +92,13 @@ public class Deadline extends BaseEntity { Deadline deadline = (Deadline) o; return getId().equals(deadline.getId()) && description.equals(deadline.description) && - date.equals(deadline.date); + date.equals(deadline.date) && + executor.equals(deadline.executor) && + done.equals(deadline.done); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), description, date); + return Objects.hash(super.hashCode(), description, date, executor, done); } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 9cff4b6..0837b49 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -141,7 +141,7 @@ public class GrantService { grant.setComment("Комментарий к гранту 1"); grant.setProject(projectId); grant.setStatus(APPLICATION); - grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); + grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн", "", false)); grant.getAuthors().add(user); grant.setLeader(user); grant.getPapers().add(paper); diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index f98997d..1188c28 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -173,7 +173,7 @@ public class PaperService { Paper paper = new Paper(); paper.setTitle(title); paper.getAuthors().add(user); - paper.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн")); + paper.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн", "", false)); paper.setCreateDate(new Date()); paper.setUpdateDate(new Date()); paper.setStatus(DRAFT); diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index ae09658..14b8736 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -79,6 +79,13 @@ public class ProjectController { return "/projects/project"; } + @PostMapping(value = "/project", params = "removeDeadline") + public String removeDeadline(ProjectDto projectDto, + @RequestParam(value = "removeDeadline") Integer deadlineId) { + projectService.removeDeadline(projectDto, deadlineId); + return "/projects/project"; + } + @GetMapping("/delete/{project-id}") public String delete(@PathVariable("project-id") Integer projectId) throws IOException { projectService.delete(projectId); diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index 4e03365..319609c 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -20,6 +20,7 @@ public class ProjectDto { private GrantDto grant; private String repository; private String applicationFileName; + private List removedDeadlineIds = new ArrayList<>(); public ProjectDto() { } @@ -121,4 +122,12 @@ public class ProjectDto { public void setApplicationFileName(String applicationFileName) { this.applicationFileName = applicationFileName; } + + public List getRemovedDeadlineIds() { + return removedDeadlineIds; + } + + public void setRemovedDeadlineIds(List removedDeadlineIds) { + this.removedDeadlineIds = removedDeadlineIds; + } } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 247624d..4a79e6c 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -104,6 +104,13 @@ public class ProjectService { } } + public void removeDeadline(ProjectDto projectDto, Integer deadlineId) { + if (projectDto.getDeadlines().get(deadlineId).getId() != null) { + projectDto.getRemovedDeadlineIds().add(projectDto.getDeadlines().get(deadlineId).getId()); + } + projectDto.getDeadlines().remove((int) deadlineId); + } + public Project findById(Integer id) { return projectRepository.findOne(id); } diff --git a/src/main/resources/db/changelog-20190506_000000-schema.xml b/src/main/resources/db/changelog-20190506_000000-schema.xml new file mode 100644 index 0000000..cd5a59b --- /dev/null +++ b/src/main/resources/db/changelog-20190506_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 83ff280..3b455a8 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -38,4 +38,5 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index dc3fa6d..cd49319 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -73,14 +73,18 @@
-
+
-
+
+
+ +
-
+
-
+
-
+
-
- -
+
+
+
+ +
+
+
From 65dea9bce2c211126114386768ed6940fbbaee9f Mon Sep 17 00:00:00 2001 From: ASH Date: Mon, 6 May 2019 22:39:08 +0400 Subject: [PATCH 006/128] #79 adding task planer generation --- .../ru/ulstu/students/model/Scheduler.java | 49 +++++++++ .../repository/SchedulerRepository.java | 8 ++ .../students/repository/TaskRepository.java | 2 + .../students/service/SchedulerService.java | 99 +++++++++++++++++++ .../service/TaskGenerationService.java | 19 +++- .../ulstu/students/service/TaskService.java | 81 +++++++++++++-- src/main/java/ru/ulstu/tags/model/Tag.java | 14 +++ .../db/changelog-20190505_000000-schema.xml | 24 +++++ src/main/resources/db/changelog-master.xml | 1 + src/main/resources/public/js/tasks.js | 2 +- 10 files changed, 285 insertions(+), 14 deletions(-) create mode 100644 src/main/java/ru/ulstu/students/model/Scheduler.java create mode 100644 src/main/java/ru/ulstu/students/repository/SchedulerRepository.java create mode 100644 src/main/java/ru/ulstu/students/service/SchedulerService.java create mode 100644 src/main/resources/db/changelog-20190505_000000-schema.xml diff --git a/src/main/java/ru/ulstu/students/model/Scheduler.java b/src/main/java/ru/ulstu/students/model/Scheduler.java new file mode 100644 index 0000000..67005b1 --- /dev/null +++ b/src/main/java/ru/ulstu/students/model/Scheduler.java @@ -0,0 +1,49 @@ +package ru.ulstu.students.model; + +import org.springframework.format.annotation.DateTimeFormat; +import ru.ulstu.core.model.BaseEntity; + +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.Date; + +@Entity +@Table(name = "scheduler") +public class Scheduler extends BaseEntity { + + @OneToOne(optional = false) + @JoinColumn(name = "task_id") + private Task task; + + @Temporal(value = TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date date; + + public Scheduler() { + } + + public Scheduler(Task task, Date date) { + this.task = task; + this.date = date; + } + + public Task getTask() { + return task; + } + + public void setTask(Task task) { + this.task = task; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } +} diff --git a/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java b/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java new file mode 100644 index 0000000..ff25e98 --- /dev/null +++ b/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java @@ -0,0 +1,8 @@ +package ru.ulstu.students.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.students.model.Scheduler; + +public interface SchedulerRepository extends JpaRepository { + +} diff --git a/src/main/java/ru/ulstu/students/repository/TaskRepository.java b/src/main/java/ru/ulstu/students/repository/TaskRepository.java index 0b17691..adcc43a 100644 --- a/src/main/java/ru/ulstu/students/repository/TaskRepository.java +++ b/src/main/java/ru/ulstu/students/repository/TaskRepository.java @@ -20,4 +20,6 @@ public interface TaskRepository extends JpaRepository { "(YEAR FROM t.createDate) = :year)") List findToGenerate(@Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year); + @Query("SELECT t FROM Task t WHERE(:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC") + List findByTag(@Param("tag") Tag tag); } diff --git a/src/main/java/ru/ulstu/students/service/SchedulerService.java b/src/main/java/ru/ulstu/students/service/SchedulerService.java new file mode 100644 index 0000000..09fbce7 --- /dev/null +++ b/src/main/java/ru/ulstu/students/service/SchedulerService.java @@ -0,0 +1,99 @@ +package ru.ulstu.students.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.students.model.Scheduler; +import ru.ulstu.students.model.Task; +import ru.ulstu.students.repository.SchedulerRepository; +import ru.ulstu.tags.model.Tag; + +import java.util.Date; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +@Service +public class SchedulerService { + + private final TaskService taskService; + private final SchedulerRepository schedulerRepository; + + public SchedulerService(TaskService taskService, SchedulerRepository schedulerRepository) { + this.taskService = taskService; + this.schedulerRepository = schedulerRepository; + } + + private void save(Tag tag) { + List taskList = taskService.findTasksByTag(tag); + create(taskList.get(0)); + } + + + @Transactional + private Scheduler create(Task task) { + Scheduler scheduler = new Scheduler(task, task.getDeadlines().get(task.getDeadlines().size() - 1).getDate()); + return schedulerRepository.save(scheduler); + } + + @Transactional + private void delete(Integer schedulerId) { + if (schedulerRepository.exists(schedulerId)) { + schedulerRepository.delete(schedulerId); + } + } + + public void checkPlanToday() { + List schedulerList = schedulerRepository.findAll(); + if (!schedulerList.isEmpty()) { + doTodayPlanIfNeed(schedulerList); + schedulerList = schedulerRepository.findAll(); + } + checkNewPlan(schedulerList); + } + + private void checkNewPlan(List schedulerList) { + Set tags = taskService.checkRepeatingTags(); + Tag newTag = null; + if (!schedulerList.isEmpty()) { + newTag = checkNewTag(tags, schedulerList); + } else { + if (!tags.isEmpty()) { + newTag = tags.iterator().next(); + } + } + if (newTag != null) { + save(newTag); + } + } + + private Tag checkNewTag(Set tags, List schedulerList) { + Set newTags = tags + .stream() + .filter(tag -> schedulerList + .stream() + .anyMatch(scheduler -> + !scheduler.getTask().getTags().contains(tag))) + .collect(Collectors.toSet()); + if (!newTags.isEmpty()) { + return newTags.iterator().next(); + } + return null; + } + + private void doTodayPlanIfNeed(List schedulerList) { + List plan = schedulerList + .stream() + .filter(scheduler -> scheduler.getDate().before(new Date())) + .collect(Collectors.toList()); + doToday(plan); + } + + private void doToday(List plan) { + plan.forEach(scheduler -> { + taskService.createPeriodTask(scheduler); + delete(scheduler.getId()); + }); + } + + +} diff --git a/src/main/java/ru/ulstu/students/service/TaskGenerationService.java b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java index d347140..57060d5 100644 --- a/src/main/java/ru/ulstu/students/service/TaskGenerationService.java +++ b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java @@ -10,16 +10,25 @@ public class TaskGenerationService { private final Logger log = LoggerFactory.getLogger(TaskGenerationService.class); private final TaskService taskService; + private final SchedulerService schedulerService; - public TaskGenerationService(TaskService taskService) { + public TaskGenerationService(TaskService taskService, SchedulerService schedulerService) { this.taskService = taskService; + this.schedulerService = schedulerService; } +// @Scheduled(cron = "0 * * ? * *", zone = "Europe/Samara") +// public void generateYearTasks() { +// log.debug("TaskService.generateYearTasks started"); +// taskService.generateYearTasks(); +// log.debug("TaskService.generateYearTasks finished"); +// } + @Scheduled(cron = "0 * * ? * *", zone = "Europe/Samara") - public void generateYearTasks() { - log.debug("TaskService.generateYearTasks started"); - taskService.generateYearTasks(); - log.debug("TaskService.generateYearTasks finished"); + public void checkPlanToday() { + log.debug("SchedulerService.checkPlanToday started"); + schedulerService.checkPlanToday(); + log.debug("SchedulerService.checkPlanToday finished"); } } diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index 0fab0be..c7f750c 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -4,8 +4,10 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.core.util.DateUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.students.model.Scheduler; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; import ru.ulstu.students.model.TaskFilterDto; @@ -18,6 +20,10 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TimeZone; +import java.util.TreeMap; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; @@ -108,14 +114,46 @@ public class TaskService { } } - public Task copyYearTask(Task task) { - - Task newTask = new Task(); + public void copyMainPart(Task newTask, Task task) { newTask.setTitle(task.getTitle()); newTask.setTags(tagService.saveOrCreate(task.getTags())); newTask.setCreateDate(new Date()); newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS); - newTask.setDeadlines(task.getDeadlines() + } + + public Task copyTaskWithNewDates(Task task) { + Task newTask = new Task(); + copyMainPart(newTask, task); + Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris")); + cal1.setTime(newTask.getCreateDate()); + Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris")); + cal2.setTime(task.getCreateDate()); + Integer interval = cal1.get(Calendar.DAY_OF_YEAR) - cal2.get(Calendar.DAY_OF_YEAR); + newTask.setDeadlines(newDatesDeadlines(task.getDeadlines(), interval)); + return newTask; + } + + private List newDatesDeadlines(List deadlines, Integer interval) { + return deadlines + .stream() + .map(deadline -> { + Deadline newDeadline = new Deadline(); + Date newDate = DateUtils.addDays(deadline.getDate(), interval); + newDeadline.setDescription(deadline.getDescription()); + newDeadline.setDate(newDate); + return deadlineService.create(newDeadline); + }).collect(Collectors.toList()); + } + + public Task copyTaskWithNewYear(Task task) { + Task newTask = new Task(); + copyMainPart(newTask, task); + newTask.setDeadlines(newYearDeadlines(task.getDeadlines())); + return newTask; + } + + private List newYearDeadlines(List deadlines) { + return deadlines .stream() .map(deadline -> { Deadline newDeadline = new Deadline(); @@ -125,22 +163,40 @@ public class TaskService { newDeadline.setDescription(deadline.getDescription()); newDeadline.setDate(cal.getTime()); return deadlineService.create(newDeadline); - }).collect(Collectors.toList())); - - return newTask; + }).collect(Collectors.toList()); } + @Transactional public void generateYearTasks() { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); List tasks = taskRepository.findToGenerate(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR) - 1); tasks.forEach(task -> { - Task newTask = copyYearTask(task); + Task newTask = copyTaskWithNewYear(task); taskRepository.save(newTask); }); } + @Transactional + public Set checkRepeatingTags() { + Map tagsCount = new TreeMap<>(); + List tags = tagService.getTags(); + List tasks = taskRepository.findAll(); + tags.forEach(tag -> + tagsCount.put(tag, tasks + .stream() + .filter(task -> task.getTags().contains(tag)) + .count())); + + return tagsCount + .entrySet() + .stream() + .filter(tagLongEntry -> tagLongEntry.getValue() >= 2) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) + .keySet(); + } + public List getTaskStatuses() { return Arrays.asList(Task.TaskStatus.values()); } @@ -149,4 +205,13 @@ public class TaskService { return tagService.getTags(); } + public List findTasksByTag(Tag tag) { + return taskRepository.findByTag(tag); + } + + @Transactional + public void createPeriodTask(Scheduler scheduler) { + Task newTask = copyTaskWithNewDates(scheduler.getTask()); + taskRepository.save(newTask); + } } diff --git a/src/main/java/ru/ulstu/tags/model/Tag.java b/src/main/java/ru/ulstu/tags/model/Tag.java index aed000f..933b3ef 100644 --- a/src/main/java/ru/ulstu/tags/model/Tag.java +++ b/src/main/java/ru/ulstu/tags/model/Tag.java @@ -9,6 +9,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import javax.validation.constraints.Size; +import java.util.Objects; @Entity @Table(name = "tag") @@ -41,4 +42,17 @@ public class Tag extends BaseEntity { public void setTagName(String tagName) { this.tagName = tagName; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Tag tag = (Tag) o; + return tagName.equals(tag.tagName); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), tagName); + } } diff --git a/src/main/resources/db/changelog-20190505_000000-schema.xml b/src/main/resources/db/changelog-20190505_000000-schema.xml new file mode 100644 index 0000000..a47476e --- /dev/null +++ b/src/main/resources/db/changelog-20190505_000000-schema.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 68b294a..a28952a 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 diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index 0eb2da6..be24d5b 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -21,7 +21,7 @@ $(document).ready(function () { $("#input-tag").keyup(function (event) { if(event.keyCode == 13 || event.keyCode == 188) { var tagNumber = $("#tags .tag").length; - if(length != 0) { + if(tagNumber > 0) { tagNumber = $("#tags .tag").last() .children('input') .attr("name") From 4025aa67ca1720d75cdda18dcf4221868470f162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Mon, 6 May 2019 21:51:58 +0300 Subject: [PATCH 007/128] #98 project completion added --- .../java/ru/ulstu/project/model/Project.java | 16 ++++++++ .../ru/ulstu/project/model/ProjectDto.java | 41 ++++++++++++++++++- .../db/changelog-20190506_000001-schema.xml | 17 ++++++++ src/main/resources/db/changelog-master.xml | 1 + src/main/resources/public/css/project.css | 5 +++ .../resources/templates/projects/project.html | 15 +++---- 6 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/db/changelog-20190506_000001-schema.xml create mode 100644 src/main/resources/public/css/project.css diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index c971c4b..acf0d0f 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -5,17 +5,22 @@ import ru.ulstu.core.model.BaseEntity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; +import ru.ulstu.user.model.User; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.validation.constraints.NotNull; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; @Entity public class Project extends BaseEntity { @@ -62,6 +67,9 @@ public class Project extends BaseEntity { @JoinColumn(name = "file_id") private FileData application; + @ManyToMany(fetch = FetchType.EAGER) + private Set executors = new HashSet<>(); + public String getTitle() { return title; } @@ -117,4 +125,12 @@ public class Project extends BaseEntity { public void setApplication(FileData application) { this.application = application; } + + public Set getExecutors() { + return executors; + } + + public void setExecutors(Set executors) { + this.executors = executors; + } } diff --git a/src/main/java/ru/ulstu/project/model/ProjectDto.java b/src/main/java/ru/ulstu/project/model/ProjectDto.java index 319609c..0f86e1a 100644 --- a/src/main/java/ru/ulstu/project/model/ProjectDto.java +++ b/src/main/java/ru/ulstu/project/model/ProjectDto.java @@ -3,11 +3,17 @@ package ru.ulstu.project.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; +import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.GrantDto; +import ru.ulstu.user.model.UserDto; import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static ru.ulstu.core.util.StreamApiUtils.convert; public class ProjectDto { private Integer id; @@ -21,6 +27,10 @@ public class ProjectDto { private String repository; private String applicationFileName; private List removedDeadlineIds = new ArrayList<>(); + private Set executorIds; + private Set executors; + + private final static int MAX_EXECUTORS_LENGTH = 40; public ProjectDto() { } @@ -36,7 +46,9 @@ public class ProjectDto { @JsonProperty("description") String description, @JsonProperty("grant") GrantDto grant, @JsonProperty("repository") String repository, - @JsonProperty("deadlines") List deadlines) { + @JsonProperty("deadlines") List deadlines, + @JsonProperty("executorIds") Set executorIds, + @JsonProperty("executors") Set executors) { this.id = id; this.title = title; this.status = status; @@ -45,6 +57,8 @@ public class ProjectDto { this.repository = repository; this.deadlines = deadlines; this.applicationFileName = null; + this.executorIds = executorIds; + this.executors = executors; } @@ -57,6 +71,8 @@ public class ProjectDto { this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); this.repository = project.getRepository(); this.deadlines = project.getDeadlines(); + this.executorIds = convert(project.getExecutors(), user -> user.getId()); + this.executors = convert(project.getExecutors(), UserDto::new); } public Integer getId() { @@ -130,4 +146,27 @@ public class ProjectDto { public void setRemovedDeadlineIds(List removedDeadlineIds) { this.removedDeadlineIds = removedDeadlineIds; } + + public Set getExecutorIds() { + return executorIds; + } + + public void setExecutorIds(Set executorIds) { + this.executorIds = executorIds; + } + + public Set getExecutors() { + return executors; + } + + public void setExecutors(Set executors) { + this.executors = executors; + } + + public String getExecutorsString() { + return StringUtils.abbreviate(executors + .stream() + .map(executor -> executor.getLastName()) + .collect(Collectors.joining(", ")), MAX_EXECUTORS_LENGTH); + } } diff --git a/src/main/resources/db/changelog-20190506_000001-schema.xml b/src/main/resources/db/changelog-20190506_000001-schema.xml new file mode 100644 index 0000000..e28d009 --- /dev/null +++ b/src/main/resources/db/changelog-20190506_000001-schema.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 3b455a8..051c953 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -39,4 +39,5 @@ + \ No newline at end of file diff --git a/src/main/resources/public/css/project.css b/src/main/resources/public/css/project.css new file mode 100644 index 0000000..24e12ea --- /dev/null +++ b/src/main/resources/public/css/project.css @@ -0,0 +1,5 @@ +.div-deadline-done { + width: 60%; + height: 100%; + float: right; +} \ No newline at end of file diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index 2a0b7cf..8385694 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -3,7 +3,7 @@ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> - + @@ -90,17 +90,18 @@ aria-hidden="true">
-
-

Incorrect title

-
-
-
+
+
+ +
+

Incorrect title

Date: Mon, 6 May 2019 22:10:40 +0300 Subject: [PATCH 008/128] #98 deadline edited --- src/main/java/ru/ulstu/deadline/model/Deadline.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java index 5a05ea1..9ab9acd 100644 --- a/src/main/java/ru/ulstu/deadline/model/Deadline.java +++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java @@ -66,7 +66,9 @@ public class Deadline extends BaseEntity { return executor; } - public void setExecutor(String executor) { this.executor = executor; } + public void setExecutor(String executor) { + this.executor = executor; + } public Boolean getDone() { return done; From 2dae39a100d12de0b3e40cfc8d080eaddc535ef7 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Mon, 6 May 2019 23:57:16 +0400 Subject: [PATCH 009/128] #119 create grants notification service --- .../service/GrantNotificationService.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/java/ru/ulstu/grant/service/GrantNotificationService.java diff --git a/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java new file mode 100644 index 0000000..c234290 --- /dev/null +++ b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java @@ -0,0 +1,66 @@ +package ru.ulstu.grant.service; + +import com.google.common.collect.ImmutableMap; +import org.springframework.stereotype.Service; +import ru.ulstu.core.util.DateUtils; +import ru.ulstu.grant.model.Grant; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.MailService; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@Service +public class GrantNotificationService { + private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7; + 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 TITLE_DEADLINE = "Приближается дедлайн гранта: %s"; + private final static String TITLE_CREATE = "Создан грант: %s"; + private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s"; + + private final MailService mailService; + + public GrantNotificationService(MailService mailService) { + this.mailService = mailService; + } + + public void sendDeadlineNotifications(List grants, boolean isDeadlineBeforeWeek) { + Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION); + grants.stream() + .filter(grant -> needToSendDeadlineNotification(grant, now, isDeadlineBeforeWeek)) + .forEach(grant -> sendMessageDeadline(grant)); + } + + private boolean needToSendDeadlineNotification(Grant grant, Date compareDate, boolean isDeadlineBeforeWeek) { + return (grant.getNextDeadline().isPresent()) + && (compareDate.before(grant.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek + || compareDate.after(grant.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek) + && grant.getNextDeadline().get().getDate().after(new Date()); + } + + private void sendMessageDeadline(Grant grant) { + Map variables = ImmutableMap.of("grant", grant); + sendForAllAuthors(variables, grant, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, grant.getTitle())); + } + + public void sendCreateNotification(Grant grant) { + Map variables = ImmutableMap.of("grant", grant); + sendForAllAuthors(variables, grant, TEMPLATE_CREATE, String.format(TITLE_CREATE, grant.getTitle())); + } + + public void authorsChangeNotification(Grant grant, List oldAuthors) { + Map variables = ImmutableMap.of("grant", grant, "oldAuthors", oldAuthors); + sendForAllAuthors(variables, grant, TEMPLATE_AUTHORS_CHANGED, String.format(TITLE_AUTHORS_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)); + } +} From dffd839905ffda7d0d5cf86821b7c266abab9178 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: Tue, 7 May 2019 20:26:49 +0400 Subject: [PATCH 010/128] #109 only uncompleted for grant --- src/main/java/ru/ulstu/grant/controller/GrantController.java | 2 +- src/main/java/ru/ulstu/grant/service/GrantService.java | 4 ++++ src/main/java/ru/ulstu/paper/repository/PaperRepository.java | 2 ++ src/main/java/ru/ulstu/paper/service/PaperService.java | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 85a0cd9..b28f8c0 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -132,7 +132,7 @@ public class GrantController { @ModelAttribute("allPapers") public List getAllPapers() { - return grantService.getAllPapers(); + return grantService.getAllUncompletedPapers(); } private void filterEmptyDeadlines(GrantDto grantDto) { diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 9cff4b6..ae11850 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -196,6 +196,10 @@ public class GrantService { return paperService.findAll(); } + public List getAllUncompletedPapers() { + return paperService.findAllNotCompleted(); + } + public void attachPaper(GrantDto grantDto) { if (!grantDto.getPaperIds().isEmpty()) { grantDto.getPapers().clear(); diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index f935247..7eff73d 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -18,4 +18,6 @@ public interface PaperRepository extends JpaRepository { List findAllByIdIn(List paperIds); List findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status); + + List findByStatusNot(Paper.PaperStatus status); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index f98997d..956b4b6 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -246,7 +246,10 @@ public class PaperService { } else { return sortPapers(paperRepository.findAll()); } + } + public List findAllNotCompleted() { + return paperRepository.findByStatusNot(COMPLETED); } public List findAllSelect(List paperIds) { From 1e07c5424dd0dddeaf1e109d20dc53d488e2b027 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: Tue, 7 May 2019 21:35:50 +0400 Subject: [PATCH 011/128] #109 only one conference for paper --- src/main/java/ru/ulstu/paper/model/Paper.java | 12 ++++++++++++ .../ru/ulstu/paper/repository/PaperRepository.java | 4 ++++ .../java/ru/ulstu/paper/service/PaperService.java | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 65bd32c..eae8764 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -3,6 +3,7 @@ package ru.ulstu.paper.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; @@ -114,6 +115,9 @@ public class Paper extends BaseEntity implements UserContainer { @Column(name = "latex_text") private String latexText; + @ManyToMany(mappedBy = "papers") + private List conferences; + public PaperStatus getStatus() { return status; } @@ -218,6 +222,14 @@ public class Paper extends BaseEntity implements UserContainer { this.latexText = latexText; } + public List getConferences() { + return conferences; + } + + public void setConferences(List conferences) { + this.conferences = conferences; + } + @Override public Set getUsers() { return getAuthors(); diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index 7eff73d..42d3703 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -20,4 +20,8 @@ public interface PaperRepository extends JpaRepository { List findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status); List findByStatusNot(Paper.PaperStatus status); + + List findByConferencesIsNullAndStatusNot(Paper.PaperStatus status); + + List findByIdNotInAndConferencesIsNullAndStatusNot(List paperIds, Paper.PaperStatus status); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 956b4b6..0083de7 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -242,9 +242,9 @@ public class PaperService { public List findAllNotSelect(List paperIds) { if (!paperIds.isEmpty()) { - return sortPapers(paperRepository.findByIdNotIn(paperIds)); + return sortPapers(paperRepository.findByIdNotInAndConferencesIsNullAndStatusNot(paperIds, COMPLETED)); } else { - return sortPapers(paperRepository.findAll()); + return sortPapers(paperRepository.findByConferencesIsNullAndStatusNot(COMPLETED)); } } From 934d194df15434c3991d1afb091ea0b1edcd91b8 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 7 May 2019 22:15:49 +0400 Subject: [PATCH 012/128] #119 gelete unnecessary column --- .../resources/db/changelog-20190507_000000-schema.xml | 8 ++++++++ src/main/resources/db/changelog-master.xml | 1 + 2 files changed, 9 insertions(+) create mode 100644 src/main/resources/db/changelog-20190507_000000-schema.xml diff --git a/src/main/resources/db/changelog-20190507_000000-schema.xml b/src/main/resources/db/changelog-20190507_000000-schema.xml new file mode 100644 index 0000000..0cdb99b --- /dev/null +++ b/src/main/resources/db/changelog-20190507_000000-schema.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 83ff280..65a07c2 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -38,4 +38,5 @@ + \ No newline at end of file From d2444378587e669fad6eb6e3204866e6f2c14b33 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 7 May 2019 22:35:44 +0400 Subject: [PATCH 013/128] #122 fix bug --- src/main/resources/db/changelog-master.xml | 1 + .../db/common/changelog-20190507_000001-schema.xml | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/main/resources/db/common/changelog-20190507_000001-schema.xml diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 83ff280..63d7ccf 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -38,4 +38,5 @@ + \ No newline at end of file diff --git a/src/main/resources/db/common/changelog-20190507_000001-schema.xml b/src/main/resources/db/common/changelog-20190507_000001-schema.xml new file mode 100644 index 0000000..c320eba --- /dev/null +++ b/src/main/resources/db/common/changelog-20190507_000001-schema.xml @@ -0,0 +1,14 @@ + + + + + update grants + set leader_id = + (select u.id + from users u + where u.last_name = 'Романов' AND u.first_name = 'Антон'); + + + From 7ffe04f1dbb9f630ed66aba5423800628c6f234e Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Tue, 7 May 2019 22:47:27 +0400 Subject: [PATCH 014/128] #122 move to right directory --- .../db/{common => }/changelog-20190507_000001-schema.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/resources/db/{common => }/changelog-20190507_000001-schema.xml (100%) diff --git a/src/main/resources/db/common/changelog-20190507_000001-schema.xml b/src/main/resources/db/changelog-20190507_000001-schema.xml similarity index 100% rename from src/main/resources/db/common/changelog-20190507_000001-schema.xml rename to src/main/resources/db/changelog-20190507_000001-schema.xml From 2fba252df088b38068f76ddcc6ae2098e90074df 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: Tue, 7 May 2019 23:53:10 +0400 Subject: [PATCH 015/128] #109 show other paper attachs --- src/main/java/ru/ulstu/paper/model/Paper.java | 12 ++++++++++ .../resources/templates/grants/grant.html | 24 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index eae8764..4536ce5 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -8,6 +8,7 @@ import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; +import ru.ulstu.grant.model.Grant; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; @@ -118,6 +119,9 @@ public class Paper extends BaseEntity implements UserContainer { @ManyToMany(mappedBy = "papers") private List conferences; + @ManyToMany(mappedBy = "papers") + private List grants; + public PaperStatus getStatus() { return status; } @@ -230,6 +234,14 @@ public class Paper extends BaseEntity implements UserContainer { this.conferences = conferences; } + public List getGrants() { + return grants; + } + + public void setGrants(List grants) { + this.grants = grants; + } + @Override public Set getUsers() { return getAuthors(); diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 4d3cdde..e357876 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -201,6 +201,30 @@ Статус статьи
+
+ +
+
+
  • + + + +
  • +
    +
    +
    +
    + +
    +
  • + + + +
  • +
    +
    From b57142e28fc423b5779372e28107e536f03db963 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 8 May 2019 17:08:37 +0400 Subject: [PATCH 016/128] #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 017/128] #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 018/128] #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 019/128] #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 020/128] #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 021/128] #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 022/128] #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 023/128] #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 024/128] #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 025/128] #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 026/128] #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 027/128] #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 028/128] #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 029/128] #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 030/128] #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 031/128] #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 032/128] #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 0de34c89fea802355890f8d0fcecaaf0719c5d51 Mon Sep 17 00:00:00 2001 From: ASH Date: Sat, 11 May 2019 22:58:57 +0400 Subject: [PATCH 033/128] #79 fixing planner and year generation --- .../repository/SchedulerRepository.java | 3 + .../students/repository/TaskRepository.java | 10 ++- .../students/service/SchedulerService.java | 33 ++++++-- .../service/TaskGenerationService.java | 16 ++-- .../ulstu/students/service/TaskService.java | 76 ++++++++++++++----- src/main/java/ru/ulstu/tags/model/Tag.java | 8 +- src/main/resources/public/css/tasks.css | 23 ++++++ src/main/resources/public/js/tasks.js | 2 +- .../resources/templates/students/task.html | 2 +- 9 files changed, 131 insertions(+), 42 deletions(-) diff --git a/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java b/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java index ff25e98..7481692 100644 --- a/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java +++ b/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java @@ -2,7 +2,10 @@ package ru.ulstu.students.repository; import org.springframework.data.jpa.repository.JpaRepository; import ru.ulstu.students.model.Scheduler; +import ru.ulstu.students.model.Task; public interface SchedulerRepository extends JpaRepository { + Scheduler findOneByTask(Task task); + } diff --git a/src/main/java/ru/ulstu/students/repository/TaskRepository.java b/src/main/java/ru/ulstu/students/repository/TaskRepository.java index adcc43a..af277d1 100644 --- a/src/main/java/ru/ulstu/students/repository/TaskRepository.java +++ b/src/main/java/ru/ulstu/students/repository/TaskRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.repository.query.Param; import ru.ulstu.students.model.Task; import ru.ulstu.tags.model.Tag; +import java.util.Date; import java.util.List; public interface TaskRepository extends JpaRepository { @@ -16,10 +17,11 @@ public interface TaskRepository extends JpaRepository { @Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC") List filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag); - @Query("SELECT t FROM Task t WHERE (EXTRACT(DAY FROM t.createDate) = :day) AND (EXTRACT(MONTH FROM t.createDate) = :month) AND (EXTRACT" + - "(YEAR FROM t.createDate) = :year)") - List findToGenerate(@Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year); - @Query("SELECT t FROM Task t WHERE(:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC") List findByTag(@Param("tag") Tag tag); + + @Query("SELECT t FROM Task t WHERE (t.createDate >= :date) ORDER BY create_date DESC") + List findAllYear(@Param("date") Date date); + + } diff --git a/src/main/java/ru/ulstu/students/service/SchedulerService.java b/src/main/java/ru/ulstu/students/service/SchedulerService.java index 09fbce7..989255e 100644 --- a/src/main/java/ru/ulstu/students/service/SchedulerService.java +++ b/src/main/java/ru/ulstu/students/service/SchedulerService.java @@ -23,6 +23,7 @@ public class SchedulerService { this.schedulerRepository = schedulerRepository; } + private void save(Tag tag) { List taskList = taskService.findTasksByTag(tag); create(taskList.get(0)); @@ -52,21 +53,37 @@ public class SchedulerService { } private void checkNewPlan(List schedulerList) { - Set tags = taskService.checkRepeatingTags(); - Tag newTag = null; + Set tags = taskService.checkRepeatingTags(false); + Set newTags = null; if (!schedulerList.isEmpty()) { - newTag = checkNewTag(tags, schedulerList); + newTags = checkNewTags(tags, schedulerList); } else { if (!tags.isEmpty()) { - newTag = tags.iterator().next(); + newTags = tags; } } - if (newTag != null) { - save(newTag); + + if (newTags != null) { + newTags.forEach(tag -> { + if (!hasNewTag(tag, schedulerList)) { + save(tag); + Task task = taskService.findTasksByTag(tag).get(0); + schedulerList.add(new Scheduler(task, task.getDeadlines().get(task.getDeadlines().size() - 1).getDate())); + } + }); } } - private Tag checkNewTag(Set tags, List schedulerList) { + private boolean hasNewTag(Tag tag, List schedulerList) { + + return schedulerList + .stream() + .anyMatch(scheduler -> scheduler.getTask().getTags().contains(tag)); + + } + + + private Set checkNewTags(Set tags, List schedulerList) { Set newTags = tags .stream() .filter(tag -> schedulerList @@ -75,7 +92,7 @@ public class SchedulerService { !scheduler.getTask().getTags().contains(tag))) .collect(Collectors.toSet()); if (!newTags.isEmpty()) { - return newTags.iterator().next(); + return newTags; } return null; } diff --git a/src/main/java/ru/ulstu/students/service/TaskGenerationService.java b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java index 57060d5..1c04c20 100644 --- a/src/main/java/ru/ulstu/students/service/TaskGenerationService.java +++ b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java @@ -18,17 +18,15 @@ public class TaskGenerationService { this.schedulerService = schedulerService; } -// @Scheduled(cron = "0 * * ? * *", zone = "Europe/Samara") -// public void generateYearTasks() { -// log.debug("TaskService.generateYearTasks started"); -// taskService.generateYearTasks(); -// log.debug("TaskService.generateYearTasks finished"); -// } - - @Scheduled(cron = "0 * * ? * *", zone = "Europe/Samara") - public void checkPlanToday() { + @Scheduled(cron = "0 0 0 * * ?", zone = "Europe/Samara") + public void generateTasks() { log.debug("SchedulerService.checkPlanToday started"); schedulerService.checkPlanToday(); log.debug("SchedulerService.checkPlanToday finished"); + + log.debug("TaskService.generateYearTasks started"); + taskService.generateYearTasks(); + log.debug("TaskService.generateYearTasks finished"); } + } diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index c7f750c..f57c084 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -11,11 +11,13 @@ import ru.ulstu.students.model.Scheduler; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; import ru.ulstu.students.model.TaskFilterDto; +import ru.ulstu.students.repository.SchedulerRepository; import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.tags.model.Tag; import ru.ulstu.tags.service.TagService; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Date; @@ -36,14 +38,17 @@ public class TaskService { private final static int MAX_DISPLAY_SIZE = 40; private final TaskRepository taskRepository; + private final SchedulerRepository schedulerRepository; private final DeadlineService deadlineService; private final TagService tagService; + public TaskService(TaskRepository taskRepository, - DeadlineService deadlineService, TagService tagService) { + DeadlineService deadlineService, TagService tagService, SchedulerRepository schedulerRepository) { this.taskRepository = taskRepository; this.deadlineService = deadlineService; this.tagService = tagService; + this.schedulerRepository = schedulerRepository; } public List findAll() { @@ -101,6 +106,11 @@ public class TaskService { @Transactional public void delete(Integer taskId) throws IOException { if (taskRepository.exists(taskId)) { + Task scheduleTask = taskRepository.findOne(taskId); + Scheduler sch = schedulerRepository.findOneByTask(scheduleTask); + if (sch != null) { + schedulerRepository.delete(sch.getId()); + } taskRepository.delete(taskId); } @@ -124,9 +134,9 @@ public class TaskService { public Task copyTaskWithNewDates(Task task) { Task newTask = new Task(); copyMainPart(newTask, task); - Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris")); + Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Samara")); cal1.setTime(newTask.getCreateDate()); - Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris")); + Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Samara")); cal2.setTime(task.getCreateDate()); Integer interval = cal1.get(Calendar.DAY_OF_YEAR) - cal2.get(Calendar.DAY_OF_YEAR); newTask.setDeadlines(newDatesDeadlines(task.getDeadlines(), interval)); @@ -169,32 +179,64 @@ public class TaskService { @Transactional public void generateYearTasks() { - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - List tasks = taskRepository.findToGenerate(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR) - 1); - tasks.forEach(task -> { - Task newTask = copyTaskWithNewYear(task); - taskRepository.save(newTask); + Set tags = checkRepeatingTags(true); + List tasks = new ArrayList<>(); + tags.forEach(tag -> + { + Task singleTask = findTasksByTag(tag).get(0); + Calendar taskDate = Calendar.getInstance(); + Calendar nowDate = Calendar.getInstance(); + taskDate.setTime(singleTask.getCreateDate()); + nowDate.setTime(new Date()); + if (taskDate.get(Calendar.DAY_OF_MONTH) == nowDate.get(Calendar.DAY_OF_MONTH) && + taskDate.get(Calendar.MONTH) + 1 == nowDate.get(Calendar.MONTH) + 1 && + taskDate.get(Calendar.YEAR) + 1 == nowDate.get(Calendar.YEAR)) { + if (!tasks.contains(singleTask)) { + tasks.add(singleTask); + } + } }); + if (tasks != null) { + tasks.forEach(task -> { + Task newTask = copyTaskWithNewYear(task); + taskRepository.save(newTask); + }); + } } + @Transactional - public Set checkRepeatingTags() { + public Set checkRepeatingTags(Boolean param) { //param: true = year task; false = period task Map tagsCount = new TreeMap<>(); List tags = tagService.getTags(); - List tasks = taskRepository.findAll(); + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + cal.add(Calendar.YEAR, -1); + cal.set(Calendar.HOUR_OF_DAY, 0); + System.out.println(cal.getTime()); + List tasks = taskRepository.findAllYear(cal.getTime()); + ; tags.forEach(tag -> tagsCount.put(tag, tasks .stream() .filter(task -> task.getTags().contains(tag)) .count())); + if (param) { + return tagsCount + .entrySet() + .stream() + .filter(tagLongEntry -> tagLongEntry.getValue() == 1) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) + .keySet(); + } else { + return tagsCount + .entrySet() + .stream() + .filter(tagLongEntry -> tagLongEntry.getValue() >= 2) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) + .keySet(); + } - return tagsCount - .entrySet() - .stream() - .filter(tagLongEntry -> tagLongEntry.getValue() >= 2) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) - .keySet(); } public List getTaskStatuses() { diff --git a/src/main/java/ru/ulstu/tags/model/Tag.java b/src/main/java/ru/ulstu/tags/model/Tag.java index 933b3ef..e1c63d2 100644 --- a/src/main/java/ru/ulstu/tags/model/Tag.java +++ b/src/main/java/ru/ulstu/tags/model/Tag.java @@ -45,8 +45,12 @@ public class Tag extends BaseEntity { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Tag tag = (Tag) o; return tagName.equals(tag.tagName); } diff --git a/src/main/resources/public/css/tasks.css b/src/main/resources/public/css/tasks.css index 7e350ed..eadf073 100644 --- a/src/main/resources/public/css/tasks.css +++ b/src/main/resources/public/css/tasks.css @@ -38,6 +38,29 @@ width: auto; max-width: inherit; } +.tag-info{ + font-size: 10px; + color: white; + padding: 5px 15px; + background-color: black; + display: none; + margin-left: 5px; + border-radius: 5px; + opacity: 0.8; + font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; +} + +.fa-question-circle{ + + font-size: 15px; + color: #212529; + cursor:pointer; +} + +.fa-question-circle:hover .tag-info{ + display:inline-block; + +} .tag { display: inline-block; diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index be24d5b..74b5a88 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -19,7 +19,7 @@ $(document).ready(function () { $("#input-tag").keyup(function (event) { - if(event.keyCode == 13 || event.keyCode == 188) { + if(event.keyCode == 13) { var tagNumber = $("#tags .tag").length; if(tagNumber > 0) { tagNumber = $("#tags .tag").last() diff --git a/src/main/resources/templates/students/task.html b/src/main/resources/templates/students/task.html index 968c7a0..3642221 100644 --- a/src/main/resources/templates/students/task.html +++ b/src/main/resources/templates/students/task.html @@ -52,7 +52,7 @@
    - +
    From c59bb45c70bdab32f1ce88a63006e0cc81c77ece Mon Sep 17 00:00:00 2001 From: ASH Date: Sat, 11 May 2019 23:06:30 +0400 Subject: [PATCH 034/128] #79 fixing codestyle --- src/main/java/ru/ulstu/students/service/TaskService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index f57c084..487818d 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -181,8 +181,7 @@ public class TaskService { public void generateYearTasks() { Set tags = checkRepeatingTags(true); List tasks = new ArrayList<>(); - tags.forEach(tag -> - { + tags.forEach(tag -> { Task singleTask = findTasksByTag(tag).get(0); Calendar taskDate = Calendar.getInstance(); Calendar nowDate = Calendar.getInstance(); @@ -215,7 +214,6 @@ public class TaskService { cal.set(Calendar.HOUR_OF_DAY, 0); System.out.println(cal.getTime()); List tasks = taskRepository.findAllYear(cal.getTime()); - ; tags.forEach(tag -> tagsCount.put(tag, tasks .stream() From d846192046aae130e1882f0e889845a664c4180c Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 00:28:03 +0400 Subject: [PATCH 035/128] #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 036/128] #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 037/128] #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 038/128] #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 039/128] #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 040/128] #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 041/128] #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 042/128] #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 043/128] #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 044/128] #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 045/128] #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 046/128] #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 047/128] #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; }); + }); From 9da5fd8a7a8ae3d4f8fff8aea2d5349f1fc3ca2a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 14 May 2019 00:02:30 +0400 Subject: [PATCH 048/128] #104 shock, the first unit test works --- .../conference/service/ConferenceService.java | 2 + .../module_test/ConferenceServiceTest.java | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/test/java/conference/module_test/ConferenceServiceTest.java diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38de435..8ffbf70 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -1,6 +1,7 @@ package ru.ulstu.conference.service; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -43,6 +44,7 @@ public class ConferenceService { private final ConferenceNotificationService conferenceNotificationService; private final EventService eventService; + @Autowired public ConferenceService(ConferenceRepository conferenceRepository, ConferenceUserService conferenceUserService, DeadlineService deadlineService, diff --git a/src/test/java/conference/module_test/ConferenceServiceTest.java b/src/test/java/conference/module_test/ConferenceServiceTest.java new file mode 100644 index 0000000..44c92ea --- /dev/null +++ b/src/test/java/conference/module_test/ConferenceServiceTest.java @@ -0,0 +1,37 @@ +package conference.module_test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.data.domain.Sort; +import ru.ulstu.conference.model.Conference; +import ru.ulstu.conference.repository.ConferenceRepository; +import ru.ulstu.conference.service.ConferenceService; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(MockitoJUnitRunner.class) +public class ConferenceServiceTest { + + @Mock + ConferenceRepository conferenceRepository; + + @InjectMocks + ConferenceService conferenceService; + + @Test + public void testFindAllConferences() { + List conferences = new ArrayList<>(); + Conference conference = new Conference(); + conference.setId(1); + conferences.add(conference); + Mockito.when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences); + assertEquals(conferences, conferenceService.findAll()); + } +} From 3a9fde3404bd3422dabde9a2a5459508bd043765 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 14 May 2019 16:20:19 +0400 Subject: [PATCH 049/128] #104 setUp fields --- .../module_test/ConferenceServiceTest.java | 60 +++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/src/test/java/conference/module_test/ConferenceServiceTest.java b/src/test/java/conference/module_test/ConferenceServiceTest.java index 44c92ea..de83ae7 100644 --- a/src/test/java/conference/module_test/ConferenceServiceTest.java +++ b/src/test/java/conference/module_test/ConferenceServiceTest.java @@ -1,5 +1,6 @@ package conference.module_test; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -8,10 +9,17 @@ import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.data.domain.Sort; import ru.ulstu.conference.model.Conference; +import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.conference.service.ConferenceService; +import ru.ulstu.conference.service.ConferenceUserService; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.service.PaperService; import java.util.ArrayList; +import java.util.Date; import java.util.List; import static org.junit.Assert.assertEquals; @@ -22,16 +30,60 @@ public class ConferenceServiceTest { @Mock ConferenceRepository conferenceRepository; + @Mock + DeadlineService deadlineService; + + @Mock + ConferenceUserService conferenceUserService; + + @Mock + PaperService paperService; + @InjectMocks ConferenceService conferenceService; + private List conferences; + private List deadlines; + private Conference conference; + + private Paper paperWithId; + private Paper paperWithoutId; + private Deadline deadline; + + private ConferenceDto conferenceDto; + + @Before + public void setUp() throws Exception { + conferences = new ArrayList<>(); + conference = new Conference(); + conference.setId(1); + conference.setTitle("Название"); + conference.setDescription("Описание"); + conferences.add(conference); + conferenceDto = new ConferenceDto(conference); + + paperWithId = new Paper(); + paperWithId.setId(1); + paperWithId.setTitle("paperTitle"); + + paperWithoutId = new Paper(); + paperWithoutId.setTitle("paperTitleNoId"); + + deadlines = new ArrayList<>(); + deadline = new Deadline(new Date(),"desc"); + deadline.setId(1); + deadlines.add(deadline); + } + @Test public void testFindAllConferences() { - List conferences = new ArrayList<>(); - Conference conference = new Conference(); - conference.setId(1); - conferences.add(conference); Mockito.when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences); assertEquals(conferences, conferenceService.findAll()); } + + @Test + public void testCopyFromDto() { + + + } } From a8d987b01f5e62f3a48652c248c7f55904518e00 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 14 May 2019 17:49:22 +0400 Subject: [PATCH 050/128] #104 test copy from dto method --- .../conference/service/ConferenceService.java | 2 +- .../module_test/ConferenceServiceTest.java | 47 +++++++++++++++---- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 8ffbf70..0e4dd54 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -181,7 +181,7 @@ public class ConferenceService { return Arrays.asList(ConferenceUser.Deposit.values()); } - private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { + public Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); diff --git a/src/test/java/conference/module_test/ConferenceServiceTest.java b/src/test/java/conference/module_test/ConferenceServiceTest.java index de83ae7..87a77a8 100644 --- a/src/test/java/conference/module_test/ConferenceServiceTest.java +++ b/src/test/java/conference/module_test/ConferenceServiceTest.java @@ -5,11 +5,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.data.domain.Sort; import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; +import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.conference.service.ConferenceUserService; @@ -17,12 +17,15 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.user.model.User; +import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class ConferenceServiceTest { @@ -44,7 +47,10 @@ public class ConferenceServiceTest { private List conferences; private List deadlines; + private List papers; + private List conferenceUsers; private Conference conference; + private ConferenceUser conferenceUser; private Paper paperWithId; private Paper paperWithoutId; @@ -56,11 +62,9 @@ public class ConferenceServiceTest { public void setUp() throws Exception { conferences = new ArrayList<>(); conference = new Conference(); - conference.setId(1); + conference.setTitle("Название"); conference.setDescription("Описание"); - conferences.add(conference); - conferenceDto = new ConferenceDto(conference); paperWithId = new Paper(); paperWithId.setId(1); @@ -69,21 +73,46 @@ public class ConferenceServiceTest { paperWithoutId = new Paper(); paperWithoutId.setTitle("paperTitleNoId"); + papers = new ArrayList<>(); + papers.add(paperWithId); + papers.add(paperWithoutId); + deadlines = new ArrayList<>(); - deadline = new Deadline(new Date(),"desc"); + deadline = new Deadline(new Date(), "desc"); deadline.setId(1); deadlines.add(deadline); + + conferenceUser = new ConferenceUser(); + conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE); + conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL); + User user = new User(); + user.setFirstName("Name"); + conferenceUser.setUser(user); + + conferenceUsers = new ArrayList<>(); + conferenceUsers.add(conferenceUser); + + conference.setPapers(papers); + conference.setDeadlines(deadlines); + conference.setUsers(conferenceUsers); + + conferences.add(conference); + conferenceDto = new ConferenceDto(conference); } @Test public void testFindAllConferences() { - Mockito.when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences); + when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences); assertEquals(conferences, conferenceService.findAll()); } @Test - public void testCopyFromDto() { - - + public void testCopyFromDto() throws IOException { + when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId); + when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId); + when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines); + when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers); + assertEquals(conference, conferenceService.copyFromDto(new Conference(), conferenceDto)); } + } From e6cb991463b4a6d0eb549d6dc9418b63b5fc97e0 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 14 May 2019 17:54:18 +0400 Subject: [PATCH 051/128] #104 test is member --- .../module_test/ConferenceServiceTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/test/java/conference/module_test/ConferenceServiceTest.java b/src/test/java/conference/module_test/ConferenceServiceTest.java index 87a77a8..1e8f306 100644 --- a/src/test/java/conference/module_test/ConferenceServiceTest.java +++ b/src/test/java/conference/module_test/ConferenceServiceTest.java @@ -18,6 +18,7 @@ import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.ArrayList; @@ -42,6 +43,9 @@ public class ConferenceServiceTest { @Mock PaperService paperService; + @Mock + UserService userService; + @InjectMocks ConferenceService conferenceService; @@ -57,6 +61,7 @@ public class ConferenceServiceTest { private Deadline deadline; private ConferenceDto conferenceDto; + private User user; @Before public void setUp() throws Exception { @@ -85,7 +90,7 @@ public class ConferenceServiceTest { conferenceUser = new ConferenceUser(); conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE); conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL); - User user = new User(); + user = new User(); user.setFirstName("Name"); conferenceUser.setUser(user); @@ -115,4 +120,9 @@ public class ConferenceServiceTest { assertEquals(conference, conferenceService.copyFromDto(new Conference(), conferenceDto)); } + @Test + public void testIsCurrentUserParticipant() throws IOException { + when(userService.getCurrentUser()).thenReturn(user); + assertEquals(true, conferenceService.isCurrentUserParticipant(conferenceUsers)); + } } From 1c5c05b5e466ff364d9e335615018b03151e39a1 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 14 May 2019 18:01:50 +0400 Subject: [PATCH 052/128] #104 test take part --- .../conference/module_test/ConferenceServiceTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/conference/module_test/ConferenceServiceTest.java b/src/test/java/conference/module_test/ConferenceServiceTest.java index 1e8f306..1ccbc85 100644 --- a/src/test/java/conference/module_test/ConferenceServiceTest.java +++ b/src/test/java/conference/module_test/ConferenceServiceTest.java @@ -125,4 +125,12 @@ public class ConferenceServiceTest { when(userService.getCurrentUser()).thenReturn(user); assertEquals(true, conferenceService.isCurrentUserParticipant(conferenceUsers)); } + + @Test + public void testTakePart() throws IOException { + when(userService.getCurrentUser()).thenReturn(user); + ConferenceDto newConferenceDto = new ConferenceDto(); + conferenceService.takePart(newConferenceDto); + assertEquals(newConferenceDto.getUsers(), conferenceDto.getUsers()); + } } From c88c77cd7db6800f8d0df39351a0f54916ad02f2 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 14 May 2019 18:20:01 +0400 Subject: [PATCH 053/128] #104 test find one dto --- .../ulstu/conference/model/ConferenceDto.java | 27 +++++++++++++++++++ .../conference/service/ConferenceService.java | 1 - .../module_test/ConferenceServiceTest.java | 6 +++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 2e2f13b..944cd9d 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -13,6 +13,7 @@ import javax.validation.constraints.Size; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -218,4 +219,30 @@ public class ConferenceDto { return BEGIN_DATE + beginDate.toString().split(" ")[0] + " " + END_DATE + endDate.toString().split(" ")[0]; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ConferenceDto that = (ConferenceDto) o; + return ping == that.ping && + disabledTakePart == that.disabledTakePart && + Objects.equals(id, that.id) && + Objects.equals(title, that.title) && + Objects.equals(description, that.description) && + Objects.equals(url, that.url) && + Objects.equals(beginDate, that.beginDate) && + Objects.equals(endDate, that.endDate) && + Objects.equals(deadlines, that.deadlines) && + Objects.equals(removedDeadlineIds, that.removedDeadlineIds) && + Objects.equals(userIds, that.userIds) && + Objects.equals(paperIds, that.paperIds) && + Objects.equals(papers, that.papers) && + Objects.equals(notSelectedPapers, that.notSelectedPapers) && + Objects.equals(users, that.users); + } + + @Override + public int hashCode() { + return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds, userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart); + } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 0e4dd54..cdb33ef 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -149,7 +149,6 @@ public class ConferenceService { Paper paper = new Paper(); paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime()); paper.setStatus(Paper.PaperStatus.DRAFT); - conferenceDto.getPapers().add(paper); } diff --git a/src/test/java/conference/module_test/ConferenceServiceTest.java b/src/test/java/conference/module_test/ConferenceServiceTest.java index 1ccbc85..6f2146b 100644 --- a/src/test/java/conference/module_test/ConferenceServiceTest.java +++ b/src/test/java/conference/module_test/ConferenceServiceTest.java @@ -133,4 +133,10 @@ public class ConferenceServiceTest { conferenceService.takePart(newConferenceDto); assertEquals(newConferenceDto.getUsers(), conferenceDto.getUsers()); } + + @Test + public void testFindOneDto() throws IOException { + when(conferenceRepository.findOne(1)).thenReturn(conference); + assertEquals(conferenceDto, conferenceService.findOneDto(1)); + } } From 11cab955b4d51bbc3b11413a0e0d844b05edfb5a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 14 May 2019 18:51:03 +0400 Subject: [PATCH 054/128] #104 test create --- .../ulstu/conference/model/ConferenceDto.java | 11 ++-- .../module_test/ConferenceServiceTest.java | 52 +++++++++++++++---- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 944cd9d..76dbb90 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -221,8 +221,12 @@ public class ConferenceDto { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } ConferenceDto that = (ConferenceDto) o; return ping == that.ping && disabledTakePart == that.disabledTakePart && @@ -243,6 +247,7 @@ public class ConferenceDto { @Override public int hashCode() { - return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds, userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart); + return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds, + userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart); } } diff --git a/src/test/java/conference/module_test/ConferenceServiceTest.java b/src/test/java/conference/module_test/ConferenceServiceTest.java index 6f2146b..200b6f1 100644 --- a/src/test/java/conference/module_test/ConferenceServiceTest.java +++ b/src/test/java/conference/module_test/ConferenceServiceTest.java @@ -11,12 +11,14 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; +import ru.ulstu.conference.service.ConferenceNotificationService; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.conference.service.ConferenceUserService; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -26,6 +28,7 @@ import java.util.Date; import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -46,6 +49,12 @@ public class ConferenceServiceTest { @Mock UserService userService; + @Mock + ConferenceNotificationService conferenceNotificationService; + + @Mock + EventService eventService; + @InjectMocks ConferenceService conferenceService; @@ -53,7 +62,9 @@ public class ConferenceServiceTest { private List deadlines; private List papers; private List conferenceUsers; - private Conference conference; + + private Conference conferenceWithId; + private Conference conferenceWithoutId; private ConferenceUser conferenceUser; private Paper paperWithId; @@ -66,10 +77,15 @@ public class ConferenceServiceTest { @Before public void setUp() throws Exception { conferences = new ArrayList<>(); - conference = new Conference(); + conferenceWithId = new Conference(); + conferenceWithoutId = new Conference(); - conference.setTitle("Название"); - conference.setDescription("Описание"); + conferenceWithId.setId(1); + conferenceWithId.setTitle("Название"); + conferenceWithId.setDescription("Описание"); + + conferenceWithoutId.setTitle("Название"); + conferenceWithoutId.setDescription("Описание"); paperWithId = new Paper(); paperWithId.setId(1); @@ -97,12 +113,16 @@ public class ConferenceServiceTest { conferenceUsers = new ArrayList<>(); conferenceUsers.add(conferenceUser); - conference.setPapers(papers); - conference.setDeadlines(deadlines); - conference.setUsers(conferenceUsers); + conferenceWithId.setPapers(papers); + conferenceWithId.setDeadlines(deadlines); + conferenceWithId.setUsers(conferenceUsers); - conferences.add(conference); - conferenceDto = new ConferenceDto(conference); + conferenceWithoutId.setPapers(papers); + conferenceWithoutId.setDeadlines(deadlines); + conferenceWithoutId.setUsers(conferenceUsers); + + conferences.add(conferenceWithId); + conferenceDto = new ConferenceDto(conferenceWithId); } @Test @@ -117,7 +137,7 @@ public class ConferenceServiceTest { when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId); when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines); when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers); - assertEquals(conference, conferenceService.copyFromDto(new Conference(), conferenceDto)); + assertEquals(conferenceWithoutId, conferenceService.copyFromDto(new Conference(), conferenceDto)); } @Test @@ -136,7 +156,17 @@ public class ConferenceServiceTest { @Test public void testFindOneDto() throws IOException { - when(conferenceRepository.findOne(1)).thenReturn(conference); + when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); assertEquals(conferenceDto, conferenceService.findOneDto(1)); } + + @Test + public void testCreate() throws IOException { + when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId); + when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId); + when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines); + when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers); + when(conferenceRepository.save(conferenceWithoutId)).thenReturn(conferenceWithoutId); + assertNull(conferenceService.create(conferenceDto)); + } } From 95fc9da47decf785efc8aed710c02936b0994a38 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Wed, 15 May 2019 00:49:54 +0400 Subject: [PATCH 055/128] lk base, created from dev --- .../ulstu/user/controller/UserController.java | 7 - .../user/controller/UserControllerV2.java | 178 ++++++++++++++++++ .../ru/ulstu/user/service/UserService.java | 21 +-- .../user/service/UserSessionService.java | 4 + src/main/resources/templates/default.html | 10 +- .../resources/templates/users/profile.html | 75 ++++++++ 6 files changed, 269 insertions(+), 26 deletions(-) create mode 100644 src/main/java/ru/ulstu/user/controller/UserControllerV2.java create mode 100644 src/main/resources/templates/users/profile.html diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index d7db909..6806d19 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -141,13 +141,6 @@ public class UserController extends OdinController { return new Response<>(userService.activateUser(activationKey)); } - // TODO: add page for user edit (user-profile) - @PostMapping("/change-information") - public Response changeInformation(@Valid @RequestBody UserDto userDto) { - log.debug("REST: UserController.changeInformation( {} )", userDto.getLogin()); - return new Response<>(userService.updateUserInformation(userDto)); - } - // TODO: add page for user password change (user-profile) @PostMapping("/change-password") public Response changePassword(@Valid @RequestBody UserDto userDto) { diff --git a/src/main/java/ru/ulstu/user/controller/UserControllerV2.java b/src/main/java/ru/ulstu/user/controller/UserControllerV2.java new file mode 100644 index 0000000..f15872e --- /dev/null +++ b/src/main/java/ru/ulstu/user/controller/UserControllerV2.java @@ -0,0 +1,178 @@ +package ru.ulstu.user.controller; + +import com.sun.org.apache.xpath.internal.operations.Mod; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.access.annotation.Secured; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import ru.ulstu.configuration.Constants; +import ru.ulstu.core.model.response.PageableItems; +import ru.ulstu.core.model.response.Response; +import ru.ulstu.odin.controller.OdinController; +import ru.ulstu.odin.model.OdinMetadata; +import ru.ulstu.odin.model.OdinVoid; +import ru.ulstu.odin.service.OdinService; +import ru.ulstu.user.model.*; +import ru.ulstu.user.service.UserService; +import ru.ulstu.user.service.UserSessionService; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import javax.validation.Valid; + +import static ru.ulstu.user.controller.UserController.URL; + +@Controller +@RequestMapping(value = "/users") +public class UserControllerV2 extends OdinController { + public static final String URL = Constants.API_1_0 + "users"; + public static final String ROLES_URL = "/roles"; + public static final String ROLES_META_URL = ROLES_URL + OdinController.META_LIST_URL; + public static final String SESSIONS_URL = "/sessions"; + public static final String SESSIONS_META_URL = SESSIONS_URL + OdinController.META_LIST_URL; + public static final String REGISTER_URL = "/register"; + public static final String ACTIVATE_URL = "/activate"; + public static final String PASSWORD_RESET_REQUEST_URL = "/password-reset-request"; + public static final String PASSWORD_RESET_URL = "/password-reset"; + + private final Logger log = LoggerFactory.getLogger(UserController.class); + + private final UserService userService; + private final UserSessionService userSessionService; + private final OdinService odinRolesService; + private final OdinService odinSessionsService; + + public UserControllerV2(UserService userService, + UserSessionService userSessionService, + OdinService odinRolesService, + OdinService odinSessionsService) { + super(UserListDto.class, UserDto.class); + this.userService = userService; + this.userSessionService = userSessionService; + this.odinRolesService = odinRolesService; + this.odinSessionsService = odinSessionsService; + } + + @GetMapping("/profile") + public void getUserProfile(ModelMap modelMap, HttpServletRequest request) { + HttpSession session = request.getSession(false); + final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString(); + modelMap.addAttribute("userDto", new UserDto(userSessionService.getUserDtoBySessionId(sessionId))); + } + + @PostMapping("/profile") + public void updateUserProfile(ModelMap modelMap, HttpServletRequest request, UserDto userDto) { + HttpSession session = request.getSession(false); + final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString(); + User user = userSessionService.getUserDtoBySessionId(sessionId); + modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto)); + } + + @GetMapping(ROLES_URL) + @Secured(UserRoleConstants.ADMIN) + public Response> getUserRoles() { + log.debug("REST: UserController.getUserRoles()"); + return new Response<>(userService.getUserRoles()); + } + + @GetMapping(ROLES_META_URL) + @Secured(UserRoleConstants.ADMIN) + public Response getUserRolesMetaData() { + log.debug("REST: UserController.getUserRolesMetaData()"); + return new Response<>(odinRolesService.getListModel(UserRoleDto.class)); + } + + @GetMapping(SESSIONS_URL) + @Secured(UserRoleConstants.ADMIN) + public Response> getUserSessions(@RequestParam(value = "offset", defaultValue = "0") int offset, + @RequestParam(value = "count", defaultValue = "10") int count) { + log.debug("REST: UserController.getUserSessions()"); + return new Response<>(userSessionService.getSessions(offset, count)); + } + + @GetMapping(SESSIONS_META_URL) + @Secured(UserRoleConstants.ADMIN) + public Response getUserSessionsMetaData() { + log.debug("REST: UserController.getUserSessionsMetaData()"); + return new Response<>(odinSessionsService.getListModel(UserSessionListDto.class)); + } + + @GetMapping("") + @Secured(UserRoleConstants.ADMIN) + public Response> getAllUsers(@RequestParam(value = "offset", defaultValue = "0") int offset, + @RequestParam(value = "count", defaultValue = "10") int count) { + log.debug("REST: UserController.getAllUsers( {}, {} )", offset, count); + return new Response<>(userService.getAllUsers(offset, count)); + } + + @GetMapping("/{userId}") + @Secured(UserRoleConstants.ADMIN) + public Response getUser(@PathVariable Integer userId) { + log.debug("REST: UserController.getUser( {} )", userId); + return new Response<>(userService.getUserWithRolesById(userId)); + } + + + @PostMapping("") + @Secured(UserRoleConstants.ADMIN) + public Response createUser(@Valid @RequestBody UserDto userDto) { + log.debug("REST: UserController.createUser( {} )", userDto.getLogin()); + return new Response<>(userService.createUser(userDto)); + } + + @PutMapping("") + @Secured(UserRoleConstants.ADMIN) + public Response updateUser(@Valid @RequestBody UserDto userDto) { + log.debug("REST: UserController.updateUser( {} )", userDto.getLogin()); + return new Response<>(userService.updateUser(userDto)); + } + + @DeleteMapping("/{userId}") + @Secured(UserRoleConstants.ADMIN) + public Response deleteUser(@PathVariable Integer userId) { + log.debug("REST: UserController.deleteUser( {} )", userId); + return new Response<>(userService.deleteUser(userId)); + } + + @PostMapping(REGISTER_URL) + public Response registerUser(@Valid @RequestBody UserDto userDto) { + log.debug("REST: UserController.registerUser( {} )", userDto.getLogin()); + return new Response<>(userService.createUser(userDto)); + } + + @PostMapping(ACTIVATE_URL) + public Response activateUser(@RequestParam("key") String activationKey) { + log.debug("REST: UserController.activateUser( {} )", activationKey); + return new Response<>(userService.activateUser(activationKey)); + } + + // TODO: add page for user password change (user-profile) + @PostMapping("/change-password") + public Response changePassword(@Valid @RequestBody UserDto userDto) { + log.debug("REST: UserController.changePassword( {} )", userDto.getLogin()); + return new Response<>(userService.changeUserPassword(userDto)); + } + + @PostMapping(PASSWORD_RESET_REQUEST_URL) + public Response requestPasswordReset(@RequestParam("email") String email) { + log.debug("REST: UserController.requestPasswordReset( {} )", email); + return new Response<>(userService.requestUserPasswordReset(email)); + } + + @PostMapping(PASSWORD_RESET_URL) + public Response finishPasswordReset(@RequestParam("key") String key, + @RequestBody UserResetPasswordDto userResetPasswordDto) { + log.debug("REST: UserController.requestPasswordReset( {} )", key); + return new Response<>(userService.completeUserPasswordReset(key, userResetPasswordDto)); + } +} diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index c98e4b7..202cf10 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -205,23 +205,10 @@ public class UserService implements UserDetailsService { return userMapper.userEntityToUserDto(user); } - public UserDto updateUserInformation(UserDto userDto) { - if (userDto.getId() == null) { - throw new EntityIdIsNullException(); - } - if (!Objects.equals( - Optional.ofNullable(getUserByEmail(userDto.getEmail())) - .map(BaseEntity::getId).orElse(userDto.getId()), - userDto.getId())) { - throw new UserEmailExistsException(userDto.getEmail()); - } - User user = userRepository.findOne(userDto.getId()); - if (user == null) { - throw new UserNotFoundException(userDto.getId().toString()); - } - user.setFirstName(userDto.getFirstName()); - user.setLastName(userDto.getLastName()); - user.setEmail(userDto.getEmail()); + public UserDto updateUserInformation(User user, UserDto updateUser) { + user.setFirstName(updateUser.getFirstName()); + user.setLastName(updateUser.getLastName()); + user.setEmail(updateUser.getEmail()); user = userRepository.save(user); log.debug("Updated Information for User: {}", user.getLogin()); return userMapper.userEntityToUserDto(user); diff --git a/src/main/java/ru/ulstu/user/service/UserSessionService.java b/src/main/java/ru/ulstu/user/service/UserSessionService.java index 0d985cd..03415de 100644 --- a/src/main/java/ru/ulstu/user/service/UserSessionService.java +++ b/src/main/java/ru/ulstu/user/service/UserSessionService.java @@ -54,4 +54,8 @@ public class UserSessionService { userSessionRepository.save(userSession); log.debug("User session {} closed", sessionId); } + + public User getUserDtoBySessionId(String sessionId) { + return userSessionRepository.findOneBySessionId(sessionId).getUser(); + } } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 65e0be6..4f9ec12 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -61,8 +61,14 @@ -
    diff --git a/src/main/resources/templates/users/profile.html b/src/main/resources/templates/users/profile.html new file mode 100644 index 0000000..5468d1b --- /dev/null +++ b/src/main/resources/templates/users/profile.html @@ -0,0 +1,75 @@ + + + + + + + + +
    +
    +
    +
    +
    +

    Личный кабинет

    +
    +
    +
    +
    +
    +
    + +
    + + +

    Incorrect firstName

    +

    +
    +
    + + +

    Incorrect lastName

    +

    +
    +
    + + +

    Incorrect email

    +

    +
    +
    + + +

    Incorrect login

    +

    +
    +
    + +
    +
    +
    +
    +
    +
    +
    + + From 00c5d5f755732ec8b22922df44ec8aa7b5e4bbd7 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 15 May 2019 00:54:30 +0400 Subject: [PATCH 056/128] #104 test refactoring --- .../ulstu/conference/model/ConferenceDto.java | 2 - .../conference/service/ConferenceService.java | 41 ++++--- .../service}/ConferenceServiceTest.java | 109 ++++++++++++++---- 3 files changed, 109 insertions(+), 43 deletions(-) rename src/test/java/{conference/module_test => ru/ulstu/conference/service}/ConferenceServiceTest.java (64%) diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 76dbb90..606ddae 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -234,8 +234,6 @@ public class ConferenceDto { Objects.equals(title, that.title) && Objects.equals(description, that.description) && Objects.equals(url, that.url) && - Objects.equals(beginDate, that.beginDate) && - Objects.equals(endDate, that.endDate) && Objects.equals(deadlines, that.deadlines) && Objects.equals(removedDeadlineIds, that.removedDeadlineIds) && Objects.equals(userIds, that.userIds) && diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index cdb33ef..c69d273 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -64,7 +64,7 @@ public class ConferenceService { } public ConferenceDto getExistConferenceById(Integer id) { - ConferenceDto conferenceDto = findOneDto(id); + ConferenceDto conferenceDto = new ConferenceDto(conferenceRepository.findOne(id)); conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds())); conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers())); return conferenceDto; @@ -72,7 +72,7 @@ public class ConferenceService { public ConferenceDto getNewConference() { ConferenceDto conferenceDto = new ConferenceDto(); - conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList())); + conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<>())); return conferenceDto; } @@ -87,10 +87,6 @@ public class ConferenceService { return conferences; } - public ConferenceDto findOneDto(Integer id) { - return new ConferenceDto(conferenceRepository.findOne(id)); - } - public void save(ConferenceDto conferenceDto) throws IOException { if (isEmpty(conferenceDto.getId())) { create(conferenceDto); @@ -127,44 +123,51 @@ public class ConferenceService { } @Transactional - public void delete(Integer conferenceId) { + public boolean delete(Integer conferenceId) { if (conferenceRepository.exists(conferenceId)) { conferenceRepository.delete(conferenceId); + return true; } + return false; } - public void addDeadline(ConferenceDto conferenceDto) { + public ConferenceDto addDeadline(ConferenceDto conferenceDto) { conferenceDto.getDeadlines().add(new Deadline()); + return conferenceDto; } - public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException { + public ConferenceDto removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException { if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) { conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId()); } conferenceDto.getDeadlines().remove((int) deadlineIndex); + return conferenceDto; } - public void addPaper(ConferenceDto conferenceDto) { + public ConferenceDto addPaper(ConferenceDto conferenceDto) { Paper paper = new Paper(); paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime()); paper.setStatus(Paper.PaperStatus.DRAFT); conferenceDto.getPapers().add(paper); + return conferenceDto; } - public void removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException { + public ConferenceDto removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException { Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex); if (removedPaper.getId() != null) { conferenceDto.getNotSelectedPapers().add(removedPaper); } + return conferenceDto; } - public void takePart(ConferenceDto conferenceDto) throws IOException { + public ConferenceDto takePart(ConferenceDto conferenceDto) throws IOException { conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser())); conferenceDto.setDisabledTakePart(true); + return conferenceDto; } - public List getNotSelectPapers(List paperIds) { + private List getNotSelectPapers(List paperIds) { return paperService.findAllNotSelect(paperIds); } @@ -180,7 +183,7 @@ public class ConferenceService { return Arrays.asList(ConferenceUser.Deposit.values()); } - public Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { + private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); @@ -198,7 +201,7 @@ public class ConferenceService { } - public boolean isCurrentUserParticipant(List conferenceUsers) { + private boolean isCurrentUserParticipant(List conferenceUsers) { return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser())); } @@ -213,7 +216,7 @@ public class ConferenceService { return convert(findAllActive(), ConferenceDto::new); } - public List findAllActive() { + private List findAllActive() { return conferenceRepository.findAllActive(new Date()); } @@ -227,7 +230,7 @@ public class ConferenceService { conferenceRepository.updatePingConference(conferenceDto.getId()); } - public Conference findOne(Integer conferenceId) { + private Conference findOne(Integer conferenceId) { return conferenceRepository.findOne(conferenceId); } @@ -253,7 +256,7 @@ public class ConferenceService { modelMap.addAttribute("offshoreSales", offshoreSales); } - public void sendNotificationAfterUpdateDeadlines(Conference conference, List oldDeadlines) { + private void sendNotificationAfterUpdateDeadlines(Conference conference, List oldDeadlines) { if (oldDeadlines.size() != conference.getDeadlines().size()) { conferenceNotificationService.updateDeadlineNotification(conference); return; @@ -267,7 +270,7 @@ public class ConferenceService { } } - public Deadline copyDeadline(Deadline oldDeadline) { + private Deadline copyDeadline(Deadline oldDeadline) { Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription()); newDeadline.setId(oldDeadline.getId()); return newDeadline; diff --git a/src/test/java/conference/module_test/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java similarity index 64% rename from src/test/java/conference/module_test/ConferenceServiceTest.java rename to src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index 200b6f1..9fe8301 100644 --- a/src/test/java/conference/module_test/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -1,4 +1,4 @@ -package conference.module_test; +package ru.ulstu.conference.service; import org.junit.Before; import org.junit.Test; @@ -11,9 +11,6 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; -import ru.ulstu.conference.service.ConferenceNotificationService; -import ru.ulstu.conference.service.ConferenceService; -import ru.ulstu.conference.service.ConferenceUserService; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; @@ -24,11 +21,12 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -126,28 +124,82 @@ public class ConferenceServiceTest { } @Test - public void testFindAllConferences() { + public void getExistConferenceById() { + when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); + when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); + when(userService.getCurrentUser()).thenReturn(user); + conferenceDto.setDisabledTakePart(true); + assertEquals(conferenceDto, conferenceService.getExistConferenceById(1)); + } + + @Test + public void getNewConference() { + ConferenceDto newConferenceDto = new ConferenceDto(); + newConferenceDto.setNotSelectedPapers(papers); + when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); + assertEquals(newConferenceDto, conferenceService.getNewConference()); + } + + @Test + public void findAll() { when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences); assertEquals(conferences, conferenceService.findAll()); } @Test - public void testCopyFromDto() throws IOException { + public void create() throws IOException { when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId); when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId); when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines); when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers); - assertEquals(conferenceWithoutId, conferenceService.copyFromDto(new Conference(), conferenceDto)); + when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId); + assertEquals(conferenceWithId.getId(), conferenceService.create(conferenceDto)); } @Test - public void testIsCurrentUserParticipant() throws IOException { + public void update() throws IOException { + when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); + when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId); + when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId); + when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines); + when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers); + when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId); + assertEquals(conferenceWithId.getId(), conferenceService.create(conferenceDto)); + } + + @Test + public void delete() { + when(conferenceRepository.exists(1)).thenReturn(true); + assertTrue(conferenceService.delete(1)); + } + + @Test + public void addDeadline() { + ConferenceDto newConferenceDto = conferenceService.addDeadline(conferenceDto); + assertEquals(conferenceDto, newConferenceDto); + } + + @Test + public void removeDeadline() throws IOException { + ConferenceDto newConferenceDto = conferenceService.removeDeadline(conferenceDto, 0); + assertEquals(conferenceDto, newConferenceDto); + } + + @Test + public void addPaper() { when(userService.getCurrentUser()).thenReturn(user); - assertEquals(true, conferenceService.isCurrentUserParticipant(conferenceUsers)); + ConferenceDto newConferenceDto = conferenceService.addPaper(conferenceDto); + assertEquals(conferenceDto, newConferenceDto); } @Test - public void testTakePart() throws IOException { + public void removePaper() throws IOException { + ConferenceDto newConferenceDto = conferenceService.removePaper(conferenceDto, 0); + assertEquals(conferenceDto, newConferenceDto); + } + + @Test + public void takePart() throws IOException { when(userService.getCurrentUser()).thenReturn(user); ConferenceDto newConferenceDto = new ConferenceDto(); conferenceService.takePart(newConferenceDto); @@ -155,18 +207,31 @@ public class ConferenceServiceTest { } @Test - public void testFindOneDto() throws IOException { - when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); - assertEquals(conferenceDto, conferenceService.findOneDto(1)); + public void getAllUsers() { + List users = Collections.singletonList(user); + when(userService.findAll()).thenReturn(users); + assertEquals(users, conferenceService.getAllUsers()); + } + + + @Test + public void filter() { } @Test - public void testCreate() throws IOException { - when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId); - when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId); - when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines); - when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers); - when(conferenceRepository.save(conferenceWithoutId)).thenReturn(conferenceWithoutId); - assertNull(conferenceService.create(conferenceDto)); + public void isAttachedToConference() { } -} + + @Test + public void ping() { + } + + + @Test + public void checkEmptyFieldsOfDeadline() { + } + + @Test + public void filterEmptyDeadlines() { + } +} \ No newline at end of file From 7952787229fa31ec706ce6491ab5db8e5f72307f Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 15 May 2019 01:14:02 +0400 Subject: [PATCH 057/128] #104 add new tests, fixes --- .../ru/ulstu/conference/model/Conference.java | 4 +- .../conference/service/ConferenceService.java | 4 +- .../service/ConferenceServiceTest.java | 40 ++++++++++--------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 7e18ac0..4df1a1f 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -42,12 +42,12 @@ public class Conference extends BaseEntity { @Column(name = "begin_date") @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date beginDate; + private Date beginDate = new Date(); @Column(name = "end_date") @Temporal(TemporalType.TIMESTAMP) @DateTimeFormat(pattern = "yyyy-MM-dd") - private Date endDate; + private Date endDate = new Date(); @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "conference_id", unique = true) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index c69d273..550c884 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -225,9 +225,9 @@ public class ConferenceService { } @Transactional - public void ping(ConferenceDto conferenceDto) throws IOException { + public int ping(ConferenceDto conferenceDto) throws IOException { pingService.addPing(findOne(conferenceDto.getId())); - conferenceRepository.updatePingConference(conferenceDto.getId()); + return conferenceRepository.updatePingConference(conferenceDto.getId()); } private Conference findOne(Integer conferenceId) { diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index 9fe8301..af583f9 100644 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -9,12 +9,14 @@ import org.mockito.runners.MockitoJUnitRunner; import org.springframework.data.domain.Sort; import ru.ulstu.conference.model.Conference; 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; +import ru.ulstu.ping.service.PingService; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -47,11 +49,14 @@ public class ConferenceServiceTest { @Mock UserService userService; + @Mock + EventService eventService; + @Mock ConferenceNotificationService conferenceNotificationService; @Mock - EventService eventService; + PingService pingService; @InjectMocks ConferenceService conferenceService; @@ -62,12 +67,9 @@ public class ConferenceServiceTest { private List conferenceUsers; private Conference conferenceWithId; - private Conference conferenceWithoutId; - private ConferenceUser conferenceUser; private Paper paperWithId; private Paper paperWithoutId; - private Deadline deadline; private ConferenceDto conferenceDto; private User user; @@ -76,7 +78,7 @@ public class ConferenceServiceTest { public void setUp() throws Exception { conferences = new ArrayList<>(); conferenceWithId = new Conference(); - conferenceWithoutId = new Conference(); + Conference conferenceWithoutId = new Conference(); conferenceWithId.setId(1); conferenceWithId.setTitle("Название"); @@ -97,11 +99,11 @@ public class ConferenceServiceTest { papers.add(paperWithoutId); deadlines = new ArrayList<>(); - deadline = new Deadline(new Date(), "desc"); + Deadline deadline = new Deadline(new Date(), "desc"); deadline.setId(1); deadlines.add(deadline); - conferenceUser = new ConferenceUser(); + ConferenceUser conferenceUser = new ConferenceUser(); conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE); conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL); user = new User(); @@ -164,7 +166,7 @@ public class ConferenceServiceTest { when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines); when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers); when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId); - assertEquals(conferenceWithId.getId(), conferenceService.create(conferenceDto)); + assertEquals(conferenceWithId.getId(), conferenceService.update(conferenceDto)); } @Test @@ -216,22 +218,24 @@ public class ConferenceServiceTest { @Test public void filter() { + ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto(); + conferenceFilterDto.setFilterUserId(1); + conferenceFilterDto.setYear(2019); + when(userService.findById(1)).thenReturn(user); + when(conferenceRepository.findByUserAndYear(user, 2019)).thenReturn(conferences); + assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto)); } @Test public void isAttachedToConference() { + when(conferenceRepository.isPaperAttached(1)).thenReturn(true); + assertTrue(conferenceService.isAttachedToConference(1)); } @Test - public void ping() { - } - - - @Test - public void checkEmptyFieldsOfDeadline() { - } - - @Test - public void filterEmptyDeadlines() { + public void ping() throws IOException { + when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); + when(conferenceRepository.updatePingConference(1)).thenReturn(1); + assertEquals(1, conferenceService.ping(conferenceDto)); } } \ No newline at end of file From 11ef644e5e8e5c2b157ee937341f4a4aa8c4ef04 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Wed, 15 May 2019 02:48:44 +0400 Subject: [PATCH 058/128] 88 inviting user base --- .../ru/ulstu/configuration/Constants.java | 3 + .../user/controller/UserControllerV2.java | 127 +----------------- .../ru/ulstu/user/service/MailService.java | 14 ++ .../ru/ulstu/user/service/UserService.java | 32 ++++- .../user/service/UserSessionService.java | 2 +- .../java/ru/ulstu/user/util/UserUtils.java | 5 + .../mail_templates/userInviteEmail.html | 21 +++ src/main/resources/templates/default.html | 7 +- .../templates/users/inviteModal.html | 32 +++++ .../resources/templates/users/profile.html | 9 -- 10 files changed, 114 insertions(+), 138 deletions(-) create mode 100644 src/main/resources/mail_templates/userInviteEmail.html create mode 100644 src/main/resources/templates/users/inviteModal.html diff --git a/src/main/java/ru/ulstu/configuration/Constants.java b/src/main/java/ru/ulstu/configuration/Constants.java index 0a2268a..51806b6 100644 --- a/src/main/java/ru/ulstu/configuration/Constants.java +++ b/src/main/java/ru/ulstu/configuration/Constants.java @@ -5,7 +5,10 @@ public class Constants { public static final String MAIL_ACTIVATE = "Account activation"; public static final String MAIL_RESET = "Password reset"; + public static final String MAIL_INVITE = "Account registration"; + public static final int MIN_PASSWORD_LENGTH = 6; + public static final int MAX_PASSWORD_LENGTH = 32; public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$"; diff --git a/src/main/java/ru/ulstu/user/controller/UserControllerV2.java b/src/main/java/ru/ulstu/user/controller/UserControllerV2.java index f15872e..3447a49 100644 --- a/src/main/java/ru/ulstu/user/controller/UserControllerV2.java +++ b/src/main/java/ru/ulstu/user/controller/UserControllerV2.java @@ -1,36 +1,21 @@ package ru.ulstu.user.controller; -import com.sun.org.apache.xpath.internal.operations.Mod; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.security.access.annotation.Secured; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; import ru.ulstu.configuration.Constants; -import ru.ulstu.core.model.response.PageableItems; -import ru.ulstu.core.model.response.Response; import ru.ulstu.odin.controller.OdinController; -import ru.ulstu.odin.model.OdinMetadata; -import ru.ulstu.odin.model.OdinVoid; -import ru.ulstu.odin.service.OdinService; import ru.ulstu.user.model.*; import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserSessionService; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import javax.validation.Valid; - -import static ru.ulstu.user.controller.UserController.URL; @Controller @RequestMapping(value = "/users") @@ -49,130 +34,32 @@ public class UserControllerV2 extends OdinController { private final UserService userService; private final UserSessionService userSessionService; - private final OdinService odinRolesService; - private final OdinService odinSessionsService; public UserControllerV2(UserService userService, - UserSessionService userSessionService, - OdinService odinRolesService, - OdinService odinSessionsService) { + UserSessionService userSessionService) { super(UserListDto.class, UserDto.class); this.userService = userService; this.userSessionService = userSessionService; - this.odinRolesService = odinRolesService; - this.odinSessionsService = odinSessionsService; } @GetMapping("/profile") public void getUserProfile(ModelMap modelMap, HttpServletRequest request) { HttpSession session = request.getSession(false); final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString(); - modelMap.addAttribute("userDto", new UserDto(userSessionService.getUserDtoBySessionId(sessionId))); + modelMap.addAttribute("userDto", new UserDto(userSessionService.getUserBySessionId(sessionId))); } @PostMapping("/profile") public void updateUserProfile(ModelMap modelMap, HttpServletRequest request, UserDto userDto) { HttpSession session = request.getSession(false); final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString(); - User user = userSessionService.getUserDtoBySessionId(sessionId); + User user = userSessionService.getUserBySessionId(sessionId); modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto)); } - @GetMapping(ROLES_URL) - @Secured(UserRoleConstants.ADMIN) - public Response> getUserRoles() { - log.debug("REST: UserController.getUserRoles()"); - return new Response<>(userService.getUserRoles()); - } - - @GetMapping(ROLES_META_URL) - @Secured(UserRoleConstants.ADMIN) - public Response getUserRolesMetaData() { - log.debug("REST: UserController.getUserRolesMetaData()"); - return new Response<>(odinRolesService.getListModel(UserRoleDto.class)); - } - - @GetMapping(SESSIONS_URL) - @Secured(UserRoleConstants.ADMIN) - public Response> getUserSessions(@RequestParam(value = "offset", defaultValue = "0") int offset, - @RequestParam(value = "count", defaultValue = "10") int count) { - log.debug("REST: UserController.getUserSessions()"); - return new Response<>(userSessionService.getSessions(offset, count)); - } - - @GetMapping(SESSIONS_META_URL) - @Secured(UserRoleConstants.ADMIN) - public Response getUserSessionsMetaData() { - log.debug("REST: UserController.getUserSessionsMetaData()"); - return new Response<>(odinSessionsService.getListModel(UserSessionListDto.class)); - } - - @GetMapping("") - @Secured(UserRoleConstants.ADMIN) - public Response> getAllUsers(@RequestParam(value = "offset", defaultValue = "0") int offset, - @RequestParam(value = "count", defaultValue = "10") int count) { - log.debug("REST: UserController.getAllUsers( {}, {} )", offset, count); - return new Response<>(userService.getAllUsers(offset, count)); - } - - @GetMapping("/{userId}") - @Secured(UserRoleConstants.ADMIN) - public Response getUser(@PathVariable Integer userId) { - log.debug("REST: UserController.getUser( {} )", userId); - return new Response<>(userService.getUserWithRolesById(userId)); - } - - - @PostMapping("") - @Secured(UserRoleConstants.ADMIN) - public Response createUser(@Valid @RequestBody UserDto userDto) { - log.debug("REST: UserController.createUser( {} )", userDto.getLogin()); - return new Response<>(userService.createUser(userDto)); - } - - @PutMapping("") - @Secured(UserRoleConstants.ADMIN) - public Response updateUser(@Valid @RequestBody UserDto userDto) { - log.debug("REST: UserController.updateUser( {} )", userDto.getLogin()); - return new Response<>(userService.updateUser(userDto)); - } - - @DeleteMapping("/{userId}") - @Secured(UserRoleConstants.ADMIN) - public Response deleteUser(@PathVariable Integer userId) { - log.debug("REST: UserController.deleteUser( {} )", userId); - return new Response<>(userService.deleteUser(userId)); - } - - @PostMapping(REGISTER_URL) - public Response registerUser(@Valid @RequestBody UserDto userDto) { - log.debug("REST: UserController.registerUser( {} )", userDto.getLogin()); - return new Response<>(userService.createUser(userDto)); - } - - @PostMapping(ACTIVATE_URL) - public Response activateUser(@RequestParam("key") String activationKey) { - log.debug("REST: UserController.activateUser( {} )", activationKey); - return new Response<>(userService.activateUser(activationKey)); - } - - // TODO: add page for user password change (user-profile) - @PostMapping("/change-password") - public Response changePassword(@Valid @RequestBody UserDto userDto) { - log.debug("REST: UserController.changePassword( {} )", userDto.getLogin()); - return new Response<>(userService.changeUserPassword(userDto)); - } - - @PostMapping(PASSWORD_RESET_REQUEST_URL) - public Response requestPasswordReset(@RequestParam("email") String email) { - log.debug("REST: UserController.requestPasswordReset( {} )", email); - return new Response<>(userService.requestUserPasswordReset(email)); - } - - @PostMapping(PASSWORD_RESET_URL) - public Response finishPasswordReset(@RequestParam("key") String key, - @RequestBody UserResetPasswordDto userResetPasswordDto) { - log.debug("REST: UserController.requestPasswordReset( {} )", key); - return new Response<>(userService.completeUserPasswordReset(key, userResetPasswordDto)); + @PostMapping("/invite" ) + public String inviteUser(@RequestParam(value = "email") String email){ + userService.inviteUser(email); + return "redirect:/"; } } diff --git a/src/main/java/ru/ulstu/user/service/MailService.java b/src/main/java/ru/ulstu/user/service/MailService.java index da1da6d..da8e098 100644 --- a/src/main/java/ru/ulstu/user/service/MailService.java +++ b/src/main/java/ru/ulstu/user/service/MailService.java @@ -78,6 +78,15 @@ public class MailService { sendEmail(user.getEmail(), subject, content); } + @Async + public void sendEmailFromTemplate(Map variables, String templateName, String subject, String email) { + Context context = new Context(); + variables.entrySet().forEach(entry -> context.setVariable(entry.getKey(), entry.getValue())); + context.setVariable(BASE_URL, applicationProperties.getBaseUrl()); + String content = templateEngine.process(templateName, context); + sendEmail(email, subject, content); + } + @Async public void sendActivationEmail(User user) { sendEmailFromTemplate(user, "activationEmail", Constants.MAIL_ACTIVATE); @@ -87,4 +96,9 @@ public class MailService { public void sendPasswordResetMail(User user) { sendEmailFromTemplate(user, "passwordResetEmail", Constants.MAIL_RESET); } + + @Async + public void sendInviteMail(Map variables, String email) { + sendEmailFromTemplate(variables, "userInviteEmail", Constants.MAIL_INVITE, email); + } } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 202cf10..ef11796 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -1,5 +1,6 @@ package ru.ulstu.user.service; +import com.google.common.collect.ImmutableMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; @@ -12,6 +13,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import ru.ulstu.configuration.ApplicationProperties; +import ru.ulstu.configuration.Constants; import ru.ulstu.core.error.EntityIdIsNullException; import ru.ulstu.core.jpa.OffsetablePageRequest; import ru.ulstu.core.model.BaseEntity; @@ -36,13 +38,7 @@ import ru.ulstu.user.repository.UserRepository; import ru.ulstu.user.repository.UserRoleRepository; import ru.ulstu.user.util.UserUtils; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; @Service @@ -55,6 +51,7 @@ public class UserService implements UserDetailsService { private final UserMapper userMapper; private final MailService mailService; private final ApplicationProperties applicationProperties; + private final Random random; public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder, @@ -68,6 +65,7 @@ public class UserService implements UserDetailsService { this.userMapper = userMapper; this.mailService = mailService; this.applicationProperties = applicationProperties; + this.random = new Random(); } private User getUserByEmail(String email) { @@ -315,4 +313,24 @@ public class UserService implements UserDetailsService { public List filterByAgeAndDegree(boolean hasDegree, boolean hasAge) { return userRepository.filterByAgeAndDegree(hasDegree, hasAge); } + + public void inviteUser(String email) { + if (userRepository.findOneByEmailIgnoreCase(email) != null) { + throw new UserEmailExistsException(email); + } + + String password = UserUtils.generatePassword(); + + User user = new User(); + user.setPassword(passwordEncoder.encode(password)); + user.setLogin(email); + user.setEmail(email); + user.setFirstName(""); + user.setLastName(""); + user.setActivated(true); + userRepository.save(user); + + Map variables = ImmutableMap.of("password", password, "email", email); + mailService.sendInviteMail(variables, email); + } } diff --git a/src/main/java/ru/ulstu/user/service/UserSessionService.java b/src/main/java/ru/ulstu/user/service/UserSessionService.java index 03415de..ae289d0 100644 --- a/src/main/java/ru/ulstu/user/service/UserSessionService.java +++ b/src/main/java/ru/ulstu/user/service/UserSessionService.java @@ -55,7 +55,7 @@ public class UserSessionService { log.debug("User session {} closed", sessionId); } - public User getUserDtoBySessionId(String sessionId) { + public User getUserBySessionId(String sessionId) { return userSessionRepository.findOneBySessionId(sessionId).getUser(); } } diff --git a/src/main/java/ru/ulstu/user/util/UserUtils.java b/src/main/java/ru/ulstu/user/util/UserUtils.java index de585a5..ec58dd9 100644 --- a/src/main/java/ru/ulstu/user/util/UserUtils.java +++ b/src/main/java/ru/ulstu/user/util/UserUtils.java @@ -5,6 +5,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; +import ru.ulstu.configuration.Constants; public class UserUtils { private static final int DEF_COUNT = 20; @@ -32,4 +33,8 @@ public class UserUtils { } return null; } + + public static String generatePassword() { + return RandomStringUtils.randomAscii(Constants.MIN_PASSWORD_LENGTH, Constants.MAX_PASSWORD_LENGTH); + } } diff --git a/src/main/resources/mail_templates/userInviteEmail.html b/src/main/resources/mail_templates/userInviteEmail.html new file mode 100644 index 0000000..180f0c5 --- /dev/null +++ b/src/main/resources/mail_templates/userInviteEmail.html @@ -0,0 +1,21 @@ + + + + Account activation + + + + +

    + Аккаунт в системе NG-Tracker был создан. + Данные для входа: + Логин - + Пароль - +

    +

    + Regards, +
    + Balance Team. +

    + + diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 4f9ec12..0c92865 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -62,18 +62,21 @@ КИАС РФФИ
    +
    -
    - - -

    Incorrect login

    -

    -
    @@ -77,6 +78,7 @@
    +

    - - + + + + + + + + + + + + + + + + + +
    From dc34c7bfb7944a04403cf0f3f2c67136471df979 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 16 May 2019 18:07:18 +0400 Subject: [PATCH 071/128] #104 fixed conference-row style --- src/main/resources/public/css/conference.css | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index dc83057..60a866d 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -23,11 +23,17 @@ body { text-decoration: none; margin: 0; } - .conference-row .d-flex .text-decoration:nth-child(1) { margin-left: 5px; } +.conference-row .d-flex .text-decoration span.h6.float-left.m-2 { + max-width: 470px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + .conference-row .d-flex .icon-delete { width: 29px; height: 29px; From 728fa4297278be50a17d55e2036d828cc940b27a Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Fri, 17 May 2019 02:01:26 +0400 Subject: [PATCH 072/128] 87 error handling --- ...ntrollerV2.java => UserMvcController.java} | 19 +++++++++++------ .../ru/ulstu/user/service/UserService.java | 5 ++++- src/main/resources/templates/error/error.html | 21 +++++++++++++++++++ .../resources/templates/users/profile.html | 9 ++++++++ 4 files changed, 47 insertions(+), 7 deletions(-) rename src/main/java/ru/ulstu/user/controller/{UserControllerV2.java => UserMvcController.java} (77%) create mode 100644 src/main/resources/templates/error/error.html diff --git a/src/main/java/ru/ulstu/user/controller/UserControllerV2.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java similarity index 77% rename from src/main/java/ru/ulstu/user/controller/UserControllerV2.java rename to src/main/java/ru/ulstu/user/controller/UserMvcController.java index eee98a1..c35dd79 100644 --- a/src/main/java/ru/ulstu/user/controller/UserControllerV2.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -3,14 +3,15 @@ package ru.ulstu.user.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.configuration.Constants; import ru.ulstu.odin.controller.OdinController; -import ru.ulstu.user.error.UserSendingMailException; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserListDto; @@ -22,20 +23,26 @@ import javax.servlet.http.HttpSession; @Controller @RequestMapping(value = "/users") -public class UserControllerV2 extends OdinController { +public class UserMvcController extends OdinController { - private final Logger log = LoggerFactory.getLogger(UserControllerV2.class); + private final Logger log = LoggerFactory.getLogger(UserMvcController.class); private final UserService userService; private final UserSessionService userSessionService; - public UserControllerV2(UserService userService, - UserSessionService userSessionService) { + public UserMvcController(UserService userService, + UserSessionService userSessionService) { super(UserListDto.class, UserDto.class); this.userService = userService; this.userSessionService = userSessionService; } + @ExceptionHandler(Exception.class) + public String errorHandler(Model model, Exception exception) { + model.addAttribute("error", exception.getMessage()); + return "/error/error"; + } + @GetMapping("/profile") public void getUserProfile(ModelMap modelMap, HttpServletRequest request) { HttpSession session = request.getSession(false); @@ -52,7 +59,7 @@ public class UserControllerV2 extends OdinController { } @PostMapping("/invite") - public String inviteUser(@RequestParam(value = "email") String email) throws UserSendingMailException { + public String inviteUser(@RequestParam(value = "email") String email, ModelMap modelMap) { userService.inviteUser(email); return "redirect:/"; } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 083b0f5..78f9d66 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -52,6 +52,8 @@ import java.util.stream.Collectors; @Service @Transactional public class UserService implements UserDetailsService { + private static final String INVITE_USER_EXCEPTION = "Во время отправки приглашения произошла ошибка"; + private final Logger log = LoggerFactory.getLogger(UserService.class); private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; @@ -213,6 +215,7 @@ public class UserService implements UserDetailsService { user.setFirstName(updateUser.getFirstName()); user.setLastName(updateUser.getLastName()); user.setEmail(updateUser.getEmail()); + user.setLogin(updateUser.getLogin()); user = userRepository.save(user); log.debug("Updated Information for User: {}", user.getLogin()); return userMapper.userEntityToUserDto(user); @@ -340,7 +343,7 @@ public class UserService implements UserDetailsService { try { mailService.sendInviteMail(variables, email); } catch (MessagingException e) { - throw new UserSendingMailException(email); + throw new UserSendingMailException(INVITE_USER_EXCEPTION); } } } diff --git a/src/main/resources/templates/error/error.html b/src/main/resources/templates/error/error.html new file mode 100644 index 0000000..53c9054 --- /dev/null +++ b/src/main/resources/templates/error/error.html @@ -0,0 +1,21 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/users/profile.html b/src/main/resources/templates/users/profile.html index c97e539..93adfc7 100644 --- a/src/main/resources/templates/users/profile.html +++ b/src/main/resources/templates/users/profile.html @@ -49,6 +49,15 @@ class="alert alert-danger">Incorrect email

    +
    + + +

    Incorrect email

    +

    +