From b4c11a7f90cd8dd6733959a8e15dd7ea478f389c Mon Sep 17 00:00:00 2001 From: ASH Date: Sun, 28 Apr 2019 23:58:35 +0400 Subject: [PATCH 01/24] #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 02/24] #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 65dea9bce2c211126114386768ed6940fbbaee9f Mon Sep 17 00:00:00 2001 From: ASH Date: Mon, 6 May 2019 22:39:08 +0400 Subject: [PATCH 03/24] #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 0de34c89fea802355890f8d0fcecaaf0719c5d51 Mon Sep 17 00:00:00 2001 From: ASH Date: Sat, 11 May 2019 22:58:57 +0400 Subject: [PATCH 04/24] #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 05/24] #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 9da5fd8a7a8ae3d4f8fff8aea2d5349f1fc3ca2a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 14 May 2019 00:02:30 +0400 Subject: [PATCH 06/24] #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 07/24] #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 08/24] #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 09/24] #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 10/24] #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 11/24] #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 12/24] #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 00c5d5f755732ec8b22922df44ec8aa7b5e4bbd7 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 15 May 2019 00:54:30 +0400 Subject: [PATCH 13/24] #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 14/24] #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 bc9cca62d68751716b77a75a78c1b6ed6e9de6ad Mon Sep 17 00:00:00 2001 From: ASH Date: Wed, 15 May 2019 23:47:05 +0400 Subject: [PATCH 15/24] #79 refactoring --- .../java/ru/ulstu/core/util/DateUtils.java | 6 +++ .../students/service/SchedulerService.java | 2 +- .../ulstu/students/service/TaskService.java | 44 ++++++++----------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main/java/ru/ulstu/core/util/DateUtils.java b/src/main/java/ru/ulstu/core/util/DateUtils.java index 6122583..3a38452 100644 --- a/src/main/java/ru/ulstu/core/util/DateUtils.java +++ b/src/main/java/ru/ulstu/core/util/DateUtils.java @@ -54,4 +54,10 @@ public class DateUtils { cal.add(Calendar.DAY_OF_MONTH, count); return cal.getTime(); } + + public static Date addYears(Date date, int count) { + Calendar cal = getCalendar(date); + cal.add(Calendar.YEAR, count); + return cal.getTime(); + } } diff --git a/src/main/java/ru/ulstu/students/service/SchedulerService.java b/src/main/java/ru/ulstu/students/service/SchedulerService.java index 989255e..9d14926 100644 --- a/src/main/java/ru/ulstu/students/service/SchedulerService.java +++ b/src/main/java/ru/ulstu/students/service/SchedulerService.java @@ -53,7 +53,7 @@ public class SchedulerService { } private void checkNewPlan(List schedulerList) { - Set tags = taskService.checkRepeatingTags(false); + Set tags = taskService.checkRepeatingTags(true); Set newTags = null; if (!schedulerList.isEmpty()) { newTags = checkNewTags(tags, schedulerList); diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index 487818d..e79af68 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -24,7 +24,6 @@ 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; @@ -134,10 +133,8 @@ public class TaskService { public Task copyTaskWithNewDates(Task task) { Task newTask = new Task(); copyMainPart(newTask, task); - Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Samara")); - cal1.setTime(newTask.getCreateDate()); - Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("Europe/Samara")); - cal2.setTime(task.getCreateDate()); + Calendar cal1 = DateUtils.getCalendar(newTask.getCreateDate()); + Calendar cal2 = DateUtils.getCalendar(task.getCreateDate()); Integer interval = cal1.get(Calendar.DAY_OF_YEAR) - cal2.get(Calendar.DAY_OF_YEAR); newTask.setDeadlines(newDatesDeadlines(task.getDeadlines(), interval)); return newTask; @@ -167,29 +164,31 @@ public class TaskService { .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()); + newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1)); return deadlineService.create(newDeadline); }).collect(Collectors.toList()); } + private boolean equalsDate(Task task) { + Calendar taskDate = DateUtils.getCalendar(task.getCreateDate()); + Calendar nowDate = DateUtils.getCalendar(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)) { + return true; + } else { + return false; + } + } @Transactional public void generateYearTasks() { - Set tags = checkRepeatingTags(true); + Set tags = checkRepeatingTags(false); 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 (equalsDate(singleTask)) { if (!tasks.contains(singleTask)) { tasks.add(singleTask); } @@ -205,21 +204,16 @@ public class TaskService { @Transactional - public Set checkRepeatingTags(Boolean param) { //param: true = year task; false = period task + public Set checkRepeatingTags(Boolean createPeriodTask) { //param: false = year task; true = period task Map tagsCount = new TreeMap<>(); List tags = tagService.getTags(); - 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()); + List tasks = taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1))); tags.forEach(tag -> tagsCount.put(tag, tasks .stream() .filter(task -> task.getTags().contains(tag)) .count())); - if (param) { + if (!createPeriodTask) { return tagsCount .entrySet() .stream() From ce7b4c9c7a81d0752efc61a94a9216828aa5afd9 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 16 May 2019 13:33:26 +0400 Subject: [PATCH 16/24] #104 addDeadline, removeDeadline fixed --- .../ru/ulstu/deadline/model/Deadline.java | 5 ++++ .../service/ConferenceServiceTest.java | 25 +++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java index 148697c..6c564aa 100644 --- a/src/main/java/ru/ulstu/deadline/model/Deadline.java +++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java @@ -65,6 +65,11 @@ public class Deadline extends BaseEntity { return false; } Deadline deadline = (Deadline) o; + if (getId() == null && deadline.getId() == null && + description == null && deadline.description == null && + date == null && deadline.date == null) { + return true; + } return getId().equals(deadline.getId()) && description.equals(deadline.description) && date.equals(deadline.date); diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index af583f9..25c6d1b 100644 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -61,6 +61,9 @@ public class ConferenceServiceTest { @InjectMocks ConferenceService conferenceService; + private final Integer ID = 1; + private final Integer ROMOVE_INDEX = 0; + private List conferences; private List deadlines; private List papers; @@ -171,20 +174,26 @@ public class ConferenceServiceTest { @Test public void delete() { - when(conferenceRepository.exists(1)).thenReturn(true); - assertTrue(conferenceService.delete(1)); + when(conferenceRepository.exists(ID)).thenReturn(true); + when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); + assertTrue(conferenceService.delete(ID)); } @Test public void addDeadline() { - ConferenceDto newConferenceDto = conferenceService.addDeadline(conferenceDto); - assertEquals(conferenceDto, newConferenceDto); + ConferenceDto newConferenceDto = new ConferenceDto(); + newConferenceDto.getDeadlines().add(new Deadline()); + conferenceDto.getDeadlines().clear(); + assertEquals(newConferenceDto.getDeadlines(), conferenceService.addDeadline(conferenceDto).getDeadlines()); } @Test public void removeDeadline() throws IOException { - ConferenceDto newConferenceDto = conferenceService.removeDeadline(conferenceDto, 0); - assertEquals(conferenceDto, newConferenceDto); + ConferenceDto newConferenceDto = new ConferenceDto(); + newConferenceDto.getRemovedDeadlineIds().add(ID); + ConferenceDto result = conferenceService.removeDeadline(conferenceDto, ROMOVE_INDEX); + assertEquals(newConferenceDto.getDeadlines(), result.getDeadlines()); + assertEquals(newConferenceDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds()); } @Test @@ -196,7 +205,7 @@ public class ConferenceServiceTest { @Test public void removePaper() throws IOException { - ConferenceDto newConferenceDto = conferenceService.removePaper(conferenceDto, 0); + ConferenceDto newConferenceDto = conferenceService.removePaper(conferenceDto, ROMOVE_INDEX); assertEquals(conferenceDto, newConferenceDto); } @@ -234,7 +243,7 @@ public class ConferenceServiceTest { @Test public void ping() throws IOException { - when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); + when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); when(conferenceRepository.updatePingConference(1)).thenReturn(1); assertEquals(1, conferenceService.ping(conferenceDto)); } From c0937d721a2801efeb0b9a179ffaf9d08338f89b Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 16 May 2019 15:35:32 +0400 Subject: [PATCH 17/24] #104 removePaper, addPaper, takePart fixed --- src/main/java/ru/ulstu/paper/model/Paper.java | 27 +++++++++ .../service/ConferenceServiceTest.java | 57 +++++++++++-------- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 4536ce5..2624b66 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -29,6 +29,7 @@ import java.util.Comparator; import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -264,4 +265,30 @@ public class Paper extends BaseEntity implements UserContainer { .findAny() .isPresent(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + Paper paper = (Paper) o; + return Objects.equals(title, paper.title) && + status == paper.status && + type == paper.type && + Objects.equals(deadlines, paper.deadlines) && + Objects.equals(comment, paper.comment) && + Objects.equals(url, paper.url) && + Objects.equals(locked, paper.locked) && + Objects.equals(events, paper.events) && + Objects.equals(files, paper.files) && + Objects.equals(authors, paper.authors) && + Objects.equals(latexText, paper.latexText) && + Objects.equals(conferences, paper.conferences) && + Objects.equals(grants, paper.grants); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants); + } } diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index 25c6d1b..3a58cbb 100644 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -62,7 +62,9 @@ public class ConferenceServiceTest { ConferenceService conferenceService; private final Integer ID = 1; - private final Integer ROMOVE_INDEX = 0; + private final Integer INDEX = 0; + private final String NAME = "Name"; + private final boolean DISABLED = true; private List conferences; private List deadlines; @@ -76,6 +78,7 @@ public class ConferenceServiceTest { private ConferenceDto conferenceDto; private User user; + private Deadline deadline; @Before public void setUp() throws Exception { @@ -83,8 +86,8 @@ public class ConferenceServiceTest { conferenceWithId = new Conference(); Conference conferenceWithoutId = new Conference(); - conferenceWithId.setId(1); - conferenceWithId.setTitle("Название"); + conferenceWithId.setId(ID); + conferenceWithId.setTitle(NAME); conferenceWithId.setDescription("Описание"); conferenceWithoutId.setTitle("Название"); @@ -92,37 +95,31 @@ public class ConferenceServiceTest { paperWithId = new Paper(); paperWithId.setId(1); - paperWithId.setTitle("paperTitle"); + paperWithId.setTitle(NAME); paperWithoutId = new Paper(); - paperWithoutId.setTitle("paperTitleNoId"); + paperWithoutId.setTitle(NAME); papers = new ArrayList<>(); papers.add(paperWithId); papers.add(paperWithoutId); deadlines = new ArrayList<>(); - Deadline deadline = new Deadline(new Date(), "desc"); - deadline.setId(1); + deadline = new Deadline(new Date(), "desc"); + deadline.setId(ID); deadlines.add(deadline); ConferenceUser conferenceUser = new ConferenceUser(); conferenceUser.setDeposit(ConferenceUser.Deposit.ARTICLE); conferenceUser.setParticipation(ConferenceUser.Participation.INTRAMURAL); user = new User(); - user.setFirstName("Name"); + user.setFirstName(NAME); conferenceUser.setUser(user); conferenceUsers = new ArrayList<>(); conferenceUsers.add(conferenceUser); - conferenceWithId.setPapers(papers); - conferenceWithId.setDeadlines(deadlines); - conferenceWithId.setUsers(conferenceUsers); - conferenceWithoutId.setPapers(papers); - conferenceWithoutId.setDeadlines(deadlines); - conferenceWithoutId.setUsers(conferenceUsers); conferences.add(conferenceWithId); conferenceDto = new ConferenceDto(conferenceWithId); @@ -184,37 +181,52 @@ public class ConferenceServiceTest { ConferenceDto newConferenceDto = new ConferenceDto(); newConferenceDto.getDeadlines().add(new Deadline()); conferenceDto.getDeadlines().clear(); - assertEquals(newConferenceDto.getDeadlines(), conferenceService.addDeadline(conferenceDto).getDeadlines()); + assertEquals(newConferenceDto.getDeadlines().get(0), conferenceService.addDeadline(conferenceDto).getDeadlines().get(0)); } @Test public void removeDeadline() throws IOException { ConferenceDto newConferenceDto = new ConferenceDto(); newConferenceDto.getRemovedDeadlineIds().add(ID); - ConferenceDto result = conferenceService.removeDeadline(conferenceDto, ROMOVE_INDEX); + conferenceDto.getDeadlines().add(deadline); + ConferenceDto result = conferenceService.removeDeadline(conferenceDto, INDEX); assertEquals(newConferenceDto.getDeadlines(), result.getDeadlines()); assertEquals(newConferenceDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds()); } @Test public void addPaper() { + ConferenceDto newConferenceDto = new ConferenceDto(); + newConferenceDto.getPapers().add(paperWithoutId); + conferenceDto.getPapers().clear(); when(userService.getCurrentUser()).thenReturn(user); - ConferenceDto newConferenceDto = conferenceService.addPaper(conferenceDto); - assertEquals(conferenceDto, newConferenceDto); + ConferenceDto result = conferenceService.addPaper(conferenceDto); + result.getPapers().get(INDEX).setTitle(NAME); // приходится вручную назначать название, т.е. название зависит от даты + assertEquals(newConferenceDto.getPapers(), result.getPapers()); } @Test public void removePaper() throws IOException { - ConferenceDto newConferenceDto = conferenceService.removePaper(conferenceDto, ROMOVE_INDEX); - assertEquals(conferenceDto, newConferenceDto); + ConferenceDto newConferenceDto = new ConferenceDto(); + newConferenceDto.getNotSelectedPapers().add(paperWithId); + newConferenceDto.getPapers().add(paperWithoutId); + conferenceDto.getPapers().add(paperWithId); + conferenceDto.getPapers().add(paperWithoutId); + ConferenceDto result = conferenceService.removePaper(conferenceDto, INDEX); + assertEquals(newConferenceDto.getPapers(), result.getPapers()); + assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); } @Test public void takePart() throws IOException { when(userService.getCurrentUser()).thenReturn(user); ConferenceDto newConferenceDto = new ConferenceDto(); - conferenceService.takePart(newConferenceDto); - assertEquals(newConferenceDto.getUsers(), conferenceDto.getUsers()); + newConferenceDto.setUsers(conferenceUsers); + newConferenceDto.setDisabledTakePart(DISABLED); + conferenceDto.getPapers().clear(); + ConferenceDto result = conferenceService.takePart(conferenceDto); + assertEquals(newConferenceDto.getUsers(), result.getUsers()); + assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); } @Test @@ -224,7 +236,6 @@ public class ConferenceServiceTest { assertEquals(users, conferenceService.getAllUsers()); } - @Test public void filter() { ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto(); From bde9cb51fb20944b340792e8bb54b8d6cbec329a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 16 May 2019 15:55:29 +0400 Subject: [PATCH 18/24] #104 some methods fixed --- .../conference/service/ConferenceService.java | 8 ++-- src/main/java/ru/ulstu/paper/model/Paper.java | 12 ++++-- .../ru/ulstu/ping/service/PingService.java | 4 +- .../service/ConferenceServiceTest.java | 38 ++++++++++++------- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 7162d37..633fa2e 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -16,6 +16,7 @@ import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.name.BaseService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; @@ -240,9 +241,10 @@ public class ConferenceService extends BaseService { } @Transactional - public int ping(ConferenceDto conferenceDto) throws IOException { - pingService.addPing(findOne(conferenceDto.getId())); - return conferenceRepository.updatePingConference(conferenceDto.getId()); + public Ping ping(ConferenceDto conferenceDto) throws IOException { + Ping ping = pingService.addPing(findOne(conferenceDto.getId())); + conferenceRepository.updatePingConference(conferenceDto.getId()); + return ping; } private Conference findOne(Integer conferenceId) { diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 2624b66..15ee4b4 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -268,9 +268,15 @@ public class Paper extends BaseEntity implements UserContainer { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } Paper paper = (Paper) o; return Objects.equals(title, paper.title) && status == paper.status && diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index f7156f0..6666fdd 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -23,10 +23,10 @@ public class PingService { } @Transactional - public void addPing(Conference conference) throws IOException { + public Ping addPing(Conference conference) throws IOException { Ping newPing = new Ping(new Date(), userService.getCurrentUser()); newPing.setConference(conference); - pingRepository.save(newPing); + return pingRepository.save(newPing); } public Integer countPingYesterday(Conference conference, Calendar calendar) { diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index 3a58cbb..5925aed 100644 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -16,6 +16,7 @@ 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.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; @@ -65,6 +66,7 @@ public class ConferenceServiceTest { private final Integer INDEX = 0; private final String NAME = "Name"; private final boolean DISABLED = true; + private final Integer YEAR = 2019; private List conferences; private List deadlines; @@ -127,19 +129,27 @@ public class ConferenceServiceTest { @Test public void getExistConferenceById() { - when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); + when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); when(userService.getCurrentUser()).thenReturn(user); - conferenceDto.setDisabledTakePart(true); - assertEquals(conferenceDto, conferenceService.getExistConferenceById(1)); + ConferenceDto newConferenceDto = new ConferenceDto(conferenceWithId); + newConferenceDto.setNotSelectedPapers(papers); + newConferenceDto.setDisabledTakePart(!DISABLED); + ConferenceDto result = conferenceService.getExistConferenceById(ID); + assertEquals(newConferenceDto.getId(), result.getId()); + assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); + assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); } @Test public void getNewConference() { + when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); ConferenceDto newConferenceDto = new ConferenceDto(); newConferenceDto.setNotSelectedPapers(papers); - when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); - assertEquals(newConferenceDto, conferenceService.getNewConference()); + ConferenceDto result = conferenceService.getNewConference(); + assertEquals(newConferenceDto.getId(), result.getId()); + assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); + assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); } @Test @@ -239,23 +249,25 @@ 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); + conferenceFilterDto.setFilterUserId(ID); + conferenceFilterDto.setYear(YEAR); + when(userService.findById(ID)).thenReturn(user); + when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences); assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto)); } @Test public void isAttachedToConference() { - when(conferenceRepository.isPaperAttached(1)).thenReturn(true); - assertTrue(conferenceService.isAttachedToConference(1)); + when(conferenceRepository.isPaperAttached(ID)).thenReturn(true); + assertTrue(conferenceService.isAttachedToConference(ID)); } @Test public void ping() throws IOException { + Ping ping = new Ping(); when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); - when(conferenceRepository.updatePingConference(1)).thenReturn(1); - assertEquals(1, conferenceService.ping(conferenceDto)); + when(pingService.addPing(conferenceWithId)).thenReturn(ping); + when(conferenceRepository.updatePingConference(ID)).thenReturn(INDEX); + assertEquals(ping, conferenceService.ping(conferenceDto)); } } \ No newline at end of file From 80de18d3eeca5434490107b796b92fd7d7e10010 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 16 May 2019 16:31:10 +0400 Subject: [PATCH 19/24] #104 create fixed, remove update --- .../conference/service/ConferenceService.java | 8 +- .../service/ConferenceServiceTest.java | 88 +++++++++++-------- 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 633fa2e..38ce659 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -111,16 +111,16 @@ public class ConferenceService extends BaseService { } @Transactional - public Integer create(ConferenceDto conferenceDto) throws IOException { + public Conference create(ConferenceDto conferenceDto) throws IOException { Conference newConference = copyFromDto(new Conference(), conferenceDto); newConference = conferenceRepository.save(newConference); conferenceNotificationService.sendCreateNotification(newConference); eventService.createFromConference(newConference); - return newConference.getId(); + return newConference; } @Transactional - public Integer update(ConferenceDto conferenceDto) throws IOException { + public Conference update(ConferenceDto conferenceDto) throws IOException { Conference conference = conferenceRepository.findOne(conferenceDto.getId()); List oldDeadlines = conference.getDeadlines().stream() .map(this::copyDeadline) @@ -134,7 +134,7 @@ public class ConferenceService extends BaseService { conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate); } conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove); - return conference.getId(); + return conference; } @Transactional diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index 5925aed..95f4820 100644 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -62,11 +62,13 @@ public class ConferenceServiceTest { @InjectMocks ConferenceService conferenceService; - private final Integer ID = 1; - private final Integer INDEX = 0; - private final String NAME = "Name"; - private final boolean DISABLED = true; - private final Integer YEAR = 2019; + private final static Integer ID = 1; + private final static Integer INDEX = 0; + private final static String NAME = "Name"; + private final static String DESCRIPTION = "Desc"; + private final static boolean TRUE = true; + private final static Integer YEAR = 2019; + private final static Sort SORT = new Sort(Sort.Direction.DESC, "beginDate"); private List conferences; private List deadlines; @@ -86,14 +88,10 @@ public class ConferenceServiceTest { public void setUp() throws Exception { conferences = new ArrayList<>(); conferenceWithId = new Conference(); - Conference conferenceWithoutId = new Conference(); conferenceWithId.setId(ID); conferenceWithId.setTitle(NAME); - conferenceWithId.setDescription("Описание"); - - conferenceWithoutId.setTitle("Название"); - conferenceWithoutId.setDescription("Описание"); + conferenceWithId.setDescription(DESCRIPTION); paperWithId = new Paper(); paperWithId.setId(1); @@ -107,7 +105,7 @@ public class ConferenceServiceTest { papers.add(paperWithoutId); deadlines = new ArrayList<>(); - deadline = new Deadline(new Date(), "desc"); + deadline = new Deadline(new Date(), DESCRIPTION); deadline.setId(ID); deadlines.add(deadline); @@ -121,8 +119,6 @@ public class ConferenceServiceTest { conferenceUsers = new ArrayList<>(); conferenceUsers.add(conferenceUser); - - conferences.add(conferenceWithId); conferenceDto = new ConferenceDto(conferenceWithId); } @@ -132,10 +128,12 @@ public class ConferenceServiceTest { when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); when(userService.getCurrentUser()).thenReturn(user); + ConferenceDto newConferenceDto = new ConferenceDto(conferenceWithId); newConferenceDto.setNotSelectedPapers(papers); - newConferenceDto.setDisabledTakePart(!DISABLED); + newConferenceDto.setDisabledTakePart(!TRUE); ConferenceDto result = conferenceService.getExistConferenceById(ID); + assertEquals(newConferenceDto.getId(), result.getId()); assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); @@ -144,9 +142,11 @@ public class ConferenceServiceTest { @Test public void getNewConference() { when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); + ConferenceDto newConferenceDto = new ConferenceDto(); newConferenceDto.setNotSelectedPapers(papers); ConferenceDto result = conferenceService.getNewConference(); + assertEquals(newConferenceDto.getId(), result.getId()); assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); @@ -154,29 +154,34 @@ public class ConferenceServiceTest { @Test public void findAll() { - when(conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"))).thenReturn(conferences); - assertEquals(conferences, conferenceService.findAll()); + when(conferenceRepository.findAll(SORT)).thenReturn(conferences); + + assertEquals(Collections.singletonList(conferenceWithId), conferenceService.findAll()); } @Test 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); + when(paperService.findPaperById(ID)).thenReturn(paperWithId); + when(paperService.create(new Paper())).thenReturn(paperWithoutId); + when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); + when(conferenceUserService.saveOrCreate(new ArrayList<>())).thenReturn(conferenceUsers); when(conferenceRepository.save(new Conference())).thenReturn(conferenceWithId); - assertEquals(conferenceWithId.getId(), conferenceService.create(conferenceDto)); - } - @Test - 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.update(conferenceDto)); + conferenceDto.setPapers(papers); + conferenceDto.setDeadlines(deadlines); + conferenceDto.setUsers(conferenceUsers); + conferenceDto.getPaperIds().add(ID); + + Conference newConference = new Conference(); + newConference.setId(ID); + newConference.setTitle(NAME); + newConference.setDescription(DESCRIPTION); + newConference.setPapers(papers); + newConference.getPapers().add(paperWithId); + newConference.setDeadlines(deadlines); + newConference.setUsers(conferenceUsers); + + assertEquals(newConference, conferenceService.create(conferenceDto)); } @Test @@ -191,6 +196,7 @@ public class ConferenceServiceTest { ConferenceDto newConferenceDto = new ConferenceDto(); newConferenceDto.getDeadlines().add(new Deadline()); conferenceDto.getDeadlines().clear(); + assertEquals(newConferenceDto.getDeadlines().get(0), conferenceService.addDeadline(conferenceDto).getDeadlines().get(0)); } @@ -200,18 +206,21 @@ public class ConferenceServiceTest { newConferenceDto.getRemovedDeadlineIds().add(ID); conferenceDto.getDeadlines().add(deadline); ConferenceDto result = conferenceService.removeDeadline(conferenceDto, INDEX); + assertEquals(newConferenceDto.getDeadlines(), result.getDeadlines()); assertEquals(newConferenceDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds()); } @Test public void addPaper() { + when(userService.getCurrentUser()).thenReturn(user); + ConferenceDto newConferenceDto = new ConferenceDto(); newConferenceDto.getPapers().add(paperWithoutId); conferenceDto.getPapers().clear(); - when(userService.getCurrentUser()).thenReturn(user); ConferenceDto result = conferenceService.addPaper(conferenceDto); result.getPapers().get(INDEX).setTitle(NAME); // приходится вручную назначать название, т.е. название зависит от даты + assertEquals(newConferenceDto.getPapers(), result.getPapers()); } @@ -223,6 +232,7 @@ public class ConferenceServiceTest { conferenceDto.getPapers().add(paperWithId); conferenceDto.getPapers().add(paperWithoutId); ConferenceDto result = conferenceService.removePaper(conferenceDto, INDEX); + assertEquals(newConferenceDto.getPapers(), result.getPapers()); assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); } @@ -230,11 +240,13 @@ public class ConferenceServiceTest { @Test public void takePart() throws IOException { when(userService.getCurrentUser()).thenReturn(user); + ConferenceDto newConferenceDto = new ConferenceDto(); newConferenceDto.setUsers(conferenceUsers); - newConferenceDto.setDisabledTakePart(DISABLED); + newConferenceDto.setDisabledTakePart(TRUE); conferenceDto.getPapers().clear(); ConferenceDto result = conferenceService.takePart(conferenceDto); + assertEquals(newConferenceDto.getUsers(), result.getUsers()); assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); } @@ -248,17 +260,20 @@ public class ConferenceServiceTest { @Test public void filter() { + when(userService.findById(ID)).thenReturn(user); + when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences); + ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto(); conferenceFilterDto.setFilterUserId(ID); conferenceFilterDto.setYear(YEAR); - when(userService.findById(ID)).thenReturn(user); - when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences); + assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto)); } @Test public void isAttachedToConference() { - when(conferenceRepository.isPaperAttached(ID)).thenReturn(true); + when(conferenceRepository.isPaperAttached(ID)).thenReturn(TRUE); + assertTrue(conferenceService.isAttachedToConference(ID)); } @@ -268,6 +283,7 @@ public class ConferenceServiceTest { when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); when(pingService.addPing(conferenceWithId)).thenReturn(ping); when(conferenceRepository.updatePingConference(ID)).thenReturn(INDEX); + assertEquals(ping, conferenceService.ping(conferenceDto)); } } \ No newline at end of file From 526339337935f7913070fcfb9549ee667c31d8a1 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 16 May 2019 17:55:34 +0400 Subject: [PATCH 20/24] #104 remove chart example from dashboard --- .../templates/conferences/dashboard.html | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/resources/templates/conferences/dashboard.html b/src/main/resources/templates/conferences/dashboard.html index 86be4f2..e8cfa49 100644 --- a/src/main/resources/templates/conferences/dashboard.html +++ b/src/main/resources/templates/conferences/dashboard.html @@ -24,24 +24,24 @@

- - + + + + + + + + + + + + + + + + + +
From dc34c7bfb7944a04403cf0f3f2c67136471df979 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 16 May 2019 18:07:18 +0400 Subject: [PATCH 21/24] #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 64357c250877bd2f72a022de427ade3fbd27c8c2 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Fri, 17 May 2019 04:35:33 +0400 Subject: [PATCH 22/24] 88 fixed changePassword request data --- src/main/resources/public/js/users.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index fee4f70..acf04c7 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -17,9 +17,9 @@ function changePassword() { url:"/api/1.0/users/changePassword", contentType: "application/json; charset=utf-8", data: JSON.stringify({ - "oldPassword": document.getElementById("oldPassword").value, - "password": document.getElementById("password").value, - "confirmPassword": document.getElementById("confirmPassword").value, + "oldPassword": oldPassword, + "password": password, + "confirmPassword": confirmPassword, }), method: "POST", success: function() { From 740adc5318c639f76338e3a2d164f261e3c9893b Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Fri, 17 May 2019 12:23:45 +0400 Subject: [PATCH 23/24] 88 js using showFeedbackMessage --- src/main/resources/public/js/users.js | 35 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index acf04c7..3f4af95 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -17,17 +17,42 @@ function changePassword() { url:"/api/1.0/users/changePassword", contentType: "application/json; charset=utf-8", data: JSON.stringify({ - "oldPassword": oldPassword, - "password": password, - "confirmPassword": confirmPassword, + "oldPassword": document.getElementById("oldPassword").value, + "password": document.getElementById("password").value, + "confirmPassword": document.getElementById("confirmPassword").value, }), method: "POST", success: function() { document.getElementById("closeModalPassword").click(); - alert("Пароль был обновлен"); + showFeedbackMessage("Пароль был обновлен", MessageTypesEnum.SUCCESS) + }, error: function(errorData) { - alert(errorData.responseJSON.error.message) + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + } + }) +} + +function inviteUser() { + email = document.getElementById("email").value; + re = /\S+@\S+\.\S+/; + + + if (!re.test(email)) { + alert("Некорректный почтовый ящик") + return; + } + + $.ajax({ + url:"/api/1.0/users/invite?email=" + email, + contentType: "application/json; charset=utf-8", + method: "POST", + success: function() { + document.getElementById("closeModalInvite").click(); + showFeedbackMessage("Пользователь был успешно приглашен", MessageTypesEnum.SUCCESS) + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) } }) } \ No newline at end of file From 3da374326bd6b6109cf7c40b94f43f1a46230368 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Fri, 17 May 2019 14:16:41 +0400 Subject: [PATCH 24/24] 88 replacing all alerts in users.js --- src/main/resources/public/js/users.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index 3f4af95..76bd41d 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -4,12 +4,12 @@ function changePassword() { confirmPassword = document.getElementById("confirmPassword").value if ([oldPassword.length, password.length, confirmPassword.length].includes(0)) { - alert("Заполните все поля"); + showFeedbackMessage("Заполните все поля", MessageTypesEnum.WARNING); return; } if (password != confirmPassword) { - alert("Повторный пароль введен неверно"); + showFeedbackMessage("Повторный пароль введен неверно", MessageTypesEnum.WARNING); return; } @@ -17,9 +17,9 @@ function changePassword() { url:"/api/1.0/users/changePassword", contentType: "application/json; charset=utf-8", data: JSON.stringify({ - "oldPassword": document.getElementById("oldPassword").value, - "password": document.getElementById("password").value, - "confirmPassword": document.getElementById("confirmPassword").value, + "oldPassword": oldPassword, + "password": password, + "confirmPassword": confirmPassword, }), method: "POST", success: function() { @@ -39,7 +39,7 @@ function inviteUser() { if (!re.test(email)) { - alert("Некорректный почтовый ящик") + showFeedbackMessage("Некорректный почтовый ящик", MessageTypesEnum.WARNING); return; }