+
+
\ No newline at end of file
diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html
index 9c0736d..d33015c 100644
--- a/src/main/resources/templates/grants/grant.html
+++ b/src/main/resources/templates/grants/grant.html
@@ -61,7 +61,7 @@
-
-
+
+
-
+
+
+
From a69a257f09f4caf74e8ea10eef83578ad6cad961 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Tue, 30 Apr 2019 23:43:47 +0400
Subject: [PATCH 017/136] #38 add styles
---
src/main/resources/public/css/grant.css | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/main/resources/public/css/grant.css b/src/main/resources/public/css/grant.css
index 3c0cfc8..2e6349d 100644
--- a/src/main/resources/public/css/grant.css
+++ b/src/main/resources/public/css/grant.css
@@ -28,4 +28,16 @@
.btn-delete-deadline {
color: black;
+}
+
+.div-file-name{
+ padding-top: 6px;
+}
+
+.div-loader {
+ margin-bottom: 5px;
+}
+
+.div-row-file {
+ margin-bottom: 2px;
}
\ No newline at end of file
From 1f6d15b74b64aacb7837a1aed1575bf181f67cd0 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Tue, 30 Apr 2019 23:55:31 +0400
Subject: [PATCH 018/136] #38 create changelogs
---
.../resources/db/changelog-20190430_000000-schema.xml | 11 +++++++++++
src/main/resources/db/changelog-master.xml | 1 +
2 files changed, 12 insertions(+)
create mode 100644 src/main/resources/db/changelog-20190430_000000-schema.xml
diff --git a/src/main/resources/db/changelog-20190430_000000-schema.xml b/src/main/resources/db/changelog-20190430_000000-schema.xml
new file mode 100644
index 0000000..58a3bc5
--- /dev/null
+++ b/src/main/resources/db/changelog-20190430_000000-schema.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml
index 68b294a..42d33d7 100644
--- a/src/main/resources/db/changelog-master.xml
+++ b/src/main/resources/db/changelog-master.xml
@@ -34,4 +34,5 @@
+
\ No newline at end of file
From 60bdd9d233292b7f778b271d10cfa95b1fb70ddf Mon Sep 17 00:00:00 2001
From: Nightblade73
Date: Thu, 2 May 2019 14:35:40 +0400
Subject: [PATCH 019/136] #70 fixes
---
.../controller/ConferenceController.java | 21 ++------
.../ConferenceNotificationService.java | 30 ++++++-----
.../service/ConferenceScheduler.java | 9 +---
.../conference/service/ConferenceService.java | 54 +++++++++++--------
.../ru/ulstu/deadline/model/Deadline.java | 17 ++++++
.../ru/ulstu/ping/service/PingService.java | 9 ++--
.../java/ru/ulstu/timeline/model/Event.java | 3 +-
.../ulstu/timeline/service/EventService.java | 2 +-
8 files changed, 77 insertions(+), 68 deletions(-)
diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java
index d324eb4..5aecb51 100644
--- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java
+++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java
@@ -13,7 +13,6 @@ import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.conference.model.ConferenceFilterDto;
import ru.ulstu.conference.model.ConferenceUser;
import ru.ulstu.conference.service.ConferenceService;
-import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.user.model.User;
import springfox.documentation.annotations.ApiIgnore;
@@ -22,9 +21,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
-import java.util.stream.Collectors;
-import static org.springframework.util.StringUtils.isEmpty;
import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE;
import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE;
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
@@ -77,13 +74,8 @@ public class ConferenceController {
@PostMapping(value = "/conference", params = "save")
public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
- filterEmptyDeadlines(conferenceDto);
- for (Deadline deadline : conferenceDto.getDeadlines()) {
- if (deadline.getDate() == null || deadline.getDescription().isEmpty()) {
- errors.rejectValue("deadlines", "errorCode", "Все поля дедлайна должны быть заполнены");
- return CONFERENCE_PAGE;
- }
- }
+ conferenceService.filterEmptyDeadlines(conferenceDto);
+ conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors);
if (errors.hasErrors()) {
return CONFERENCE_PAGE;
}
@@ -93,11 +85,11 @@ public class ConferenceController {
@PostMapping(value = "/conference", params = "addDeadline")
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
- filterEmptyDeadlines(conferenceDto);
+ conferenceService.filterEmptyDeadlines(conferenceDto);
if (errors.hasErrors()) {
return CONFERENCE_PAGE;
}
- conferenceDto.getDeadlines().add(new Deadline());
+ conferenceService.addDeadline(conferenceDto);
return CONFERENCE_PAGE;
}
@@ -173,9 +165,4 @@ public class ConferenceController {
return years;
}
- private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
- conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
- .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
- .collect(Collectors.toList()));
- }
}
diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java
index 9449b12..ddb8130 100644
--- a/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java
+++ b/src/main/java/ru/ulstu/conference/service/ConferenceNotificationService.java
@@ -8,6 +8,7 @@ import ru.ulstu.ping.service.PingService;
import ru.ulstu.user.service.MailService;
import ru.ulstu.user.service.UserService;
+import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -15,7 +16,7 @@ import java.util.Map;
@Service
public class ConferenceNotificationService {
- private final static int YESTERDAY = 0;
+ private final static int YESTERDAY = -1;
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
private final static String TEMPLATE_PING = "conferencePingNotification";
private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification";
@@ -41,24 +42,23 @@ public class ConferenceNotificationService {
this.pingService = pingService;
}
- public void sendDeadlineNotifications(List conferences, boolean isDeadlineBeforeWeek) {
+ public void sendDeadlineNotifications(List conferences) {
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
conferences
.stream()
- .filter(conference -> needToSendDeadlineNotification(conference, now, isDeadlineBeforeWeek))
+ .filter(conference -> needToSendDeadlineNotification(conference, now))
.forEach(this::sendMessageDeadline);
}
- private boolean needToSendDeadlineNotification(Conference conference, Date compareDate, boolean isDeadlineBeforeWeek) {
+ private boolean needToSendDeadlineNotification(Conference conference, Date compareDate) {
return (conference.getNextDeadline().isPresent())
- && (compareDate.before(conference.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek
- || compareDate.after(conference.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek)
- && conference.getNextDeadline().get().getDate().after(new Date());
+ && conference.getNextDeadline().get().getDate().after(new Date())
+ && conference.getNextDeadline().get().getDate().before(compareDate);
}
private void sendMessageDeadline(Conference conference) {
Map variables = ImmutableMap.of("conference", conference);
- sendForAllParticipals(variables, conference, TEMPLATE_DEADLINE, TITLE_DEADLINE);
+ sendForAllParticipants(variables, conference, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, conference.getTitle()));
}
public void sendCreateNotification(Conference conference) {
@@ -68,29 +68,31 @@ public class ConferenceNotificationService {
public void updateDeadlineNotification(Conference conference) {
Map variables = ImmutableMap.of("conference", conference);
- sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DEADLINES, String.format(TITLE_UPDATE_DEADLINES, conference.getTitle()));
+ sendForAllParticipants(variables, conference, TEMPLATE_UPDATE_DEADLINES, String.format(TITLE_UPDATE_DEADLINES, conference.getTitle()));
}
public void updateConferencesDatesNotification(Conference conference, Date oldBeginDate, Date oldEndDate) {
Map variables = ImmutableMap.of("conference", conference, "oldBeginDate", oldBeginDate, "oldEndDate", oldEndDate);
- sendForAllParticipals(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle()));
+ sendForAllParticipants(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle()));
}
private void sendForAllUsers(Map variables, String template, String title) {
userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, template, title));
}
- private void sendForAllParticipals(Map variables, Conference conference, String template, String title) {
+ private void sendForAllParticipants(Map variables, Conference conference, String template, String title) {
conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title));
}
public void sendPingNotifications(List conferences) {
- Date yesterday = DateUtils.addDays(new Date(), YESTERDAY);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(new Date());
+ calendar.add(Calendar.DAY_OF_MONTH, YESTERDAY);
conferences
.stream()
.filter(conference -> {
- Integer pingCount = pingService.countPingYesterday(conference, yesterday);
+ Integer pingCount = pingService.countPingYesterday(conference, calendar);
return needToSendPingNotification(conference, pingCount);
})
.forEach(this::sendMessagePing);
@@ -106,6 +108,6 @@ public class ConferenceNotificationService {
private void sendMessagePing(Conference conference) {
Map variables = ImmutableMap.of("conference", conference);
- sendForAllParticipals(variables, conference, TEMPLATE_PING, String.format(TITLE_PING, conference.getTitle()));
+ sendForAllParticipants(variables, conference, TEMPLATE_PING, String.format(TITLE_PING, conference.getTitle()));
}
}
diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java
index f55f885..6f8fe90 100644
--- a/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java
+++ b/src/main/java/ru/ulstu/conference/service/ConferenceScheduler.java
@@ -24,17 +24,10 @@ public class ConferenceScheduler {
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
public void checkDeadlineBeforeWeek() {
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started");
- conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
+ conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll());
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished");
}
- @Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
- public void checkDeadlineAfterWeek() {
- log.debug("ConferenceScheduler.checkDeadlineAfterWeek started");
- conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
- log.debug("ConferenceScheduler.checkDeadlineAfterWeek finished");
- }
-
@Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara")
public void checkNewPing() {
log.debug("ConferenceScheduler.checkPing started");
diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java
index 0c1d37d..38de435 100644
--- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java
+++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java
@@ -5,6 +5,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
+import org.springframework.validation.Errors;
import ru.ulstu.conference.model.Conference;
import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.conference.model.ConferenceFilterDto;
@@ -115,7 +116,10 @@ public class ConferenceService {
Date oldEndDate = conference.getEndDate();
conferenceRepository.save(copyFromDto(conference, conferenceDto));
eventService.updateConferenceDeadlines(conference);
- sendNotificationAfterUpdate(conference, oldDeadlines, oldBeginDate, oldEndDate);
+ sendNotificationAfterUpdateDeadlines(conference, oldDeadlines);
+ if (!conference.getBeginDate().equals(oldBeginDate) || !conference.getEndDate().equals(oldEndDate)) {
+ conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate);
+ }
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
return conference.getId();
}
@@ -127,6 +131,11 @@ public class ConferenceService {
}
}
+ public void addDeadline(ConferenceDto conferenceDto) {
+ conferenceDto.getDeadlines().add(new Deadline());
+ }
+
+
public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
@@ -243,29 +252,17 @@ public class ConferenceService {
modelMap.addAttribute("offshoreSales", offshoreSales);
}
- public void sendNotificationAfterUpdate(Conference conference, List oldDeadlines, Date oldBeginDate, Date oldEndDate) {
- boolean isSendNotificationAboutDeadlines = false;
+ public void sendNotificationAfterUpdateDeadlines(Conference conference, List oldDeadlines) {
if (oldDeadlines.size() != conference.getDeadlines().size()) {
- isSendNotificationAboutDeadlines = true;
- }
- for (Deadline deadline : conference.getDeadlines()) {
- if (isSendNotificationAboutDeadlines) {
- break;
- }
- for (Deadline oldDeadline : oldDeadlines) {
- if (deadline.getId().equals(oldDeadline.getId())) {
- if (!deadline.getDescription().equals(oldDeadline.getDescription()) || !deadline.getDate().equals(oldDeadline.getDate())) {
- isSendNotificationAboutDeadlines = true;
- break;
- }
- }
- }
- }
- if (isSendNotificationAboutDeadlines) {
conferenceNotificationService.updateDeadlineNotification(conference);
+ return;
}
- if (!conference.getBeginDate().equals(oldBeginDate) || !conference.getEndDate().equals(oldEndDate)) {
- conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate);
+
+ if (conference.getDeadlines()
+ .stream()
+ .filter(deadline -> !oldDeadlines.contains(deadline))
+ .count() > 0) {
+ conferenceNotificationService.updateDeadlineNotification(conference);
}
}
@@ -274,4 +271,19 @@ public class ConferenceService {
newDeadline.setId(oldDeadline.getId());
return newDeadline;
}
+
+ public void checkEmptyFieldsOfDeadline(ConferenceDto conferenceDto, Errors errors) {
+ for (Deadline deadline : conferenceDto.getDeadlines()) {
+ if (deadline.getDate() == null || deadline.getDescription().isEmpty()) {
+ errors.rejectValue("deadlines", "errorCode", "Все поля дедлайна должны быть заполнены");
+ }
+ }
+ }
+
+
+ public void filterEmptyDeadlines(ConferenceDto conferenceDto) {
+ conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
+ .filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
+ .collect(Collectors.toList()));
+ }
}
diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java
index 404e5c8..199427c 100644
--- a/src/main/java/ru/ulstu/deadline/model/Deadline.java
+++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java
@@ -51,4 +51,21 @@ public class Deadline extends BaseEntity {
public void setDate(Date date) {
this.date = date;
}
+
+ @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;
+ }
+ Deadline deadline = (Deadline) o;
+ return getId().equals(deadline.getId()) &&
+ description.equals(deadline.description) &&
+ date.equals(deadline.date);
+ }
}
diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java
index f24ed9d..f7156f0 100644
--- a/src/main/java/ru/ulstu/ping/service/PingService.java
+++ b/src/main/java/ru/ulstu/ping/service/PingService.java
@@ -29,11 +29,8 @@ public class PingService {
pingRepository.save(newPing);
}
- public Integer countPingYesterday(Conference conference, Date yesterday) {
- Calendar cal = Calendar.getInstance();
- cal.setTime(yesterday);
-
- return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, cal.get(Calendar.DAY_OF_MONTH),
- cal.get(Calendar.MONTH) + 1, cal.get(Calendar.YEAR)));
+ public Integer countPingYesterday(Conference conference, Calendar calendar) {
+ return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, calendar.get(Calendar.DAY_OF_MONTH),
+ calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.YEAR)));
}
}
diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java
index f53a52d..9409f21 100644
--- a/src/main/java/ru/ulstu/timeline/model/Event.java
+++ b/src/main/java/ru/ulstu/timeline/model/Event.java
@@ -19,6 +19,7 @@ import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -63,7 +64,7 @@ public class Event extends BaseEntity {
private String description;
@ManyToMany(fetch = FetchType.EAGER)
- private List recipients;
+ private List recipients = new ArrayList();
@ManyToOne
@JoinColumn(name = "child_id")
diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java
index f4e2873..d2fa510 100644
--- a/src/main/java/ru/ulstu/timeline/service/EventService.java
+++ b/src/main/java/ru/ulstu/timeline/service/EventService.java
@@ -159,7 +159,7 @@ public class EventService {
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' конференции '" + newConference.getTitle() + "'");
newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser()));
newEvent.setConference(newConference);
- eventRepository.save(newEvent);
+ save(newEvent);
timeline.getEvents().add(newEvent);
timelineService.save(timeline);
From 6350e1c0d635ec76a6fe949ec01ab45c71c1b4b7 Mon Sep 17 00:00:00 2001
From: Nightblade73
Date: Thu, 2 May 2019 14:51:22 +0400
Subject: [PATCH 020/136] #70 add hashCode for deadline
---
src/main/java/ru/ulstu/deadline/model/Deadline.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java
index 199427c..148697c 100644
--- a/src/main/java/ru/ulstu/deadline/model/Deadline.java
+++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java
@@ -9,6 +9,7 @@ import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;
+import java.util.Objects;
@Entity
public class Deadline extends BaseEntity {
@@ -68,4 +69,9 @@ public class Deadline extends BaseEntity {
description.equals(deadline.description) &&
date.equals(deadline.date);
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), description, date);
+ }
}
From b334b5d70ecda284777035e1065476f652855a18 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Thu, 2 May 2019 21:42:06 +0400
Subject: [PATCH 021/136] #117 resolve discussions
---
.../ru/ulstu/grant/service/GrantService.java | 30 ++++++++++++-------
.../paper/repository/PaperRepository.java | 2 +-
.../ru/ulstu/paper/service/PaperService.java | 5 +++-
src/main/resources/application.properties | 4 +--
4 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java
index 5f3bdeb..2450440 100644
--- a/src/main/java/ru/ulstu/grant/service/GrantService.java
+++ b/src/main/java/ru/ulstu/grant/service/GrantService.java
@@ -19,11 +19,11 @@ import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
-import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
import static org.springframework.util.ObjectUtils.isEmpty;
@@ -84,7 +84,6 @@ public class GrantService {
grant.setProject(projectService.findById(grantDto.getProject().getId()));
}
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
-
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
.filter(f -> !f.isDeleted())
.collect(toList())));
@@ -110,7 +109,6 @@ public class GrantService {
@Transactional
public Integer update(GrantDto grantDto) throws IOException {
Grant grant = grantRepository.findOne(grantDto.getId());
-
for (FileDataDto file : grantDto.getFiles().stream()
.filter(f -> f.isDeleted() && f.getId() != null)
.collect(toList())) {
@@ -181,7 +179,7 @@ public class GrantService {
return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED)
.stream()
.map(Grant::getLeader)
- .collect(Collectors.toList());
+ .collect(toList());
}
public List getGrantPapers(List paperIds) {
@@ -211,10 +209,16 @@ public class GrantService {
private List getCompletedPapersAuthors(Paper.PaperType type) {
List papers = paperService.findAllCompletedByType(type);
- return papers.stream()
+ papers.stream()
.filter(paper -> paper.getAuthors() != null)
- .flatMap(paper-> paper.getAuthors().stream())
.collect(toList());
+ List users = new ArrayList<>();
+ for (Paper p : papers) {
+ p.getAuthors()
+ .stream()
+ .forEach(users::add);
+ }
+ return users;
}
private List getBAKAuthors() {
@@ -225,10 +229,14 @@ public class GrantService {
}
private List getScopusAuthors() {
- List authors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS);
- return authors
- .stream()
- .filter(author -> Collections.frequency(authors, author) > 3)
- .collect(toList());
+ List oldAuthors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS);
+ List newAuthors = new ArrayList<>();
+ oldAuthors.forEach(author -> {
+ int count = Collections.frequency(oldAuthors, author);
+ if (count > 3) {
+ newAuthors.add(author);
+ }
+ });
+ return newAuthors;
}
}
diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
index f935247..8bc59ce 100644
--- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
+++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
@@ -17,5 +17,5 @@ public interface PaperRepository extends JpaRepository {
List findAllByIdIn(List paperIds);
- List findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status);
+ List findByType(Paper.PaperType type);
}
diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java
index f98997d..97efafb 100644
--- a/src/main/java/ru/ulstu/paper/service/PaperService.java
+++ b/src/main/java/ru/ulstu/paper/service/PaperService.java
@@ -305,6 +305,9 @@ public class PaperService {
}
public List findAllCompletedByType(Paper.PaperType type) {
- return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED);
+ return paperRepository.findByType(type)
+ .stream()
+ .filter(findAllCompleted()::contains)
+ .collect(toList());
}
}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 8a3366e..038ddcf 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,7 +1,7 @@
# Server Settings
spring.main.banner-mode=off
server.port=8443
-server.http.port=8888
+server.http.port=8080
spring.http.multipart.maxFileSize=20MB
spring.http.multipart.maxRequestSize=20MB
# Thymeleaf Settings
@@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact
# JPA Settings
spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker
spring.datasource.username=postgres
-spring.datasource.password=superuser
+spring.datasource.password=postgres
spring.datasource.driverclassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=validate
# Liquibase Settings
From de625923e96ba4172ac4ae047560c85fc13e12c2 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Thu, 2 May 2019 21:56:54 +0400
Subject: [PATCH 022/136] #117 resolve discussions v.2
---
.../ru/ulstu/grant/service/GrantService.java | 26 ++++++-------------
.../paper/repository/PaperRepository.java | 2 +-
.../ru/ulstu/paper/service/PaperService.java | 5 +---
src/main/resources/application.properties | 2 +-
4 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java
index 2450440..daf50db 100644
--- a/src/main/java/ru/ulstu/grant/service/GrantService.java
+++ b/src/main/java/ru/ulstu/grant/service/GrantService.java
@@ -19,7 +19,6 @@ import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
@@ -209,16 +208,11 @@ public class GrantService {
private List getCompletedPapersAuthors(Paper.PaperType type) {
List papers = paperService.findAllCompletedByType(type);
- papers.stream()
+ return papers.stream()
.filter(paper -> paper.getAuthors() != null)
+ .flatMap(paper -> paper.getAuthors().stream())
.collect(toList());
- List users = new ArrayList<>();
- for (Paper p : papers) {
- p.getAuthors()
- .stream()
- .forEach(users::add);
- }
- return users;
+
}
private List getBAKAuthors() {
@@ -229,14 +223,10 @@ public class GrantService {
}
private List getScopusAuthors() {
- List oldAuthors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS);
- List newAuthors = new ArrayList<>();
- oldAuthors.forEach(author -> {
- int count = Collections.frequency(oldAuthors, author);
- if (count > 3) {
- newAuthors.add(author);
- }
- });
- return newAuthors;
+ List authors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS);
+ return authors
+ .stream()
+ .filter(author -> Collections.frequency(authors, author) > 3)
+ .collect(toList());
}
}
diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
index 8bc59ce..f935247 100644
--- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
+++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
@@ -17,5 +17,5 @@ public interface PaperRepository extends JpaRepository {
List findAllByIdIn(List paperIds);
- List findByType(Paper.PaperType type);
+ List findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status);
}
diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java
index 97efafb..f98997d 100644
--- a/src/main/java/ru/ulstu/paper/service/PaperService.java
+++ b/src/main/java/ru/ulstu/paper/service/PaperService.java
@@ -305,9 +305,6 @@ public class PaperService {
}
public List findAllCompletedByType(Paper.PaperType type) {
- return paperRepository.findByType(type)
- .stream()
- .filter(findAllCompleted()::contains)
- .collect(toList());
+ return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED);
}
}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 038ddcf..64194c9 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,7 +1,7 @@
# Server Settings
spring.main.banner-mode=off
server.port=8443
-server.http.port=8080
+server.http.port=8888
spring.http.multipart.maxFileSize=20MB
spring.http.multipart.maxRequestSize=20MB
# Thymeleaf Settings
From 0955388f277095bc08017cbc1466f58b572f7f8f Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Thu, 2 May 2019 22:00:53 +0400
Subject: [PATCH 023/136] #117 fix port
---
src/main/resources/application.properties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 64194c9..038ddcf 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,7 +1,7 @@
# Server Settings
spring.main.banner-mode=off
server.port=8443
-server.http.port=8888
+server.http.port=8080
spring.http.multipart.maxFileSize=20MB
spring.http.multipart.maxRequestSize=20MB
# Thymeleaf Settings
From 74d43dcd0d131213f0f6862524b1df89045b5f80 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Thu, 2 May 2019 22:49:58 +0400
Subject: [PATCH 024/136] #117 resolve last discussion
---
.../ru/ulstu/grant/service/GrantService.java | 21 ++++++++-----------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java
index daf50db..cb86b7a 100644
--- a/src/main/java/ru/ulstu/grant/service/GrantService.java
+++ b/src/main/java/ru/ulstu/grant/service/GrantService.java
@@ -154,26 +154,23 @@ public class GrantService {
public List getGrantAuthors(GrantDto grantDto) {
List filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree());
if (grantDto.isWasLeader()) {
- filteredUsers = filteredUsers
- .stream()
- .filter(getCompletedGrantLeaders()::contains)
- .collect(toList());
+ filteredUsers = checkContains(filteredUsers, getCompletedGrantLeaders());
}
if (grantDto.isHasBAKPapers()) {
- filteredUsers = filteredUsers
- .stream()
- .filter(getBAKAuthors()::contains)
- .collect(toList());
+ filteredUsers = checkContains(filteredUsers, getBAKAuthors());
}
if (grantDto.isHasScopusPapers()) {
- filteredUsers = filteredUsers
- .stream()
- .filter(getScopusAuthors()::contains)
- .collect(toList());
+ filteredUsers = checkContains(filteredUsers, getScopusAuthors());
}
return filteredUsers;
}
+ private List checkContains(List filteredUsers, List checkUsers) {
+ return filteredUsers.stream()
+ .filter(checkUsers::contains)
+ .collect(toList());
+ }
+
private List getCompletedGrantLeaders() {
return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED)
.stream()
From beb334f2fa2e21c508b86aac0f3ae54fb160fa12 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Sat, 4 May 2019 23:59:03 +0400
Subject: [PATCH 025/136] #32 add variable "events"
---
src/main/java/ru/ulstu/grant/model/Grant.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java
index d6f9f0c..ac8ac19 100644
--- a/src/main/java/ru/ulstu/grant/model/Grant.java
+++ b/src/main/java/ru/ulstu/grant/model/Grant.java
@@ -9,6 +9,7 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.project.model.Project;
+import ru.ulstu.timeline.model.Event;
import ru.ulstu.user.model.User;
import javax.persistence.CascadeType;
@@ -92,6 +93,10 @@ public class Grant extends BaseEntity implements UserContainer {
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
private List papers = new ArrayList<>();
+ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ @JoinColumn(name = "grant_id")
+ private List events = new ArrayList<>();
+
public GrantStatus getStatus() {
return status;
}
@@ -169,6 +174,14 @@ public class Grant extends BaseEntity implements UserContainer {
this.papers = papers;
}
+ public List getEvents() {
+ return events;
+ }
+
+ public void setEvents(List events) {
+ this.events = events;
+ }
+
public Optional getNextDeadline() {
return deadlines
.stream()
From 114f6769ac95a280381663ded00bdfe3fe3039d7 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Sun, 5 May 2019 23:54:02 +0400
Subject: [PATCH 026/136] #32 create changelog
---
.../db/changelog-20190505_000000-schema.xml | 14 ++++++++++++++
src/main/resources/db/changelog-master.xml | 1 +
2 files changed, 15 insertions(+)
create mode 100644 src/main/resources/db/changelog-20190505_000000-schema.xml
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..ac8707a
--- /dev/null
+++ b/src/main/resources/db/changelog-20190505_000000-schema.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml
index 3cc05ae..83ff280 100644
--- a/src/main/resources/db/changelog-master.xml
+++ b/src/main/resources/db/changelog-master.xml
@@ -37,4 +37,5 @@
+
\ No newline at end of file
From da382b659a003906aaf4a2ddd6b5b5b28d2fd959 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Mon, 6 May 2019 00:32:28 +0400
Subject: [PATCH 027/136] #32 add deadlines on timeline page
---
src/main/java/ru/ulstu/grant/model/Grant.java | 1 +
.../ru/ulstu/grant/service/GrantService.java | 11 ++++++-
.../java/ru/ulstu/timeline/model/Event.java | 13 ++++++++
.../ru/ulstu/timeline/model/EventDto.java | 17 +++++++++-
.../timeline/repository/EventRepository.java | 3 ++
.../ulstu/timeline/service/EventService.java | 33 +++++++++++++++++++
6 files changed, 76 insertions(+), 2 deletions(-)
diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java
index ac8ac19..760895e 100644
--- a/src/main/java/ru/ulstu/grant/model/Grant.java
+++ b/src/main/java/ru/ulstu/grant/model/Grant.java
@@ -91,6 +91,7 @@ public class Grant extends BaseEntity implements UserContainer {
@JoinTable(name = "grants_papers",
joinColumns = {@JoinColumn(name = "grant_id")},
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
+ @Fetch(FetchMode.SUBSELECT)
private List papers = new ArrayList<>();
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java
index cb86b7a..9cff4b6 100644
--- a/src/main/java/ru/ulstu/grant/service/GrantService.java
+++ b/src/main/java/ru/ulstu/grant/service/GrantService.java
@@ -15,6 +15,7 @@ import ru.ulstu.paper.service.PaperService;
import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.project.service.ProjectService;
+import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService;
@@ -39,19 +40,22 @@ public class GrantService {
private final FileService fileService;
private final UserService userService;
private final PaperService paperService;
+ private final EventService eventService;
public GrantService(GrantRepository grantRepository,
FileService fileService,
DeadlineService deadlineService,
ProjectService projectService,
UserService userService,
- PaperService paperService) {
+ PaperService paperService,
+ EventService eventService) {
this.grantRepository = grantRepository;
this.fileService = fileService;
this.deadlineService = deadlineService;
this.projectService = projectService;
this.userService = userService;
this.paperService = paperService;
+ this.eventService = eventService;
}
public List findAll() {
@@ -72,6 +76,7 @@ public class GrantService {
public Integer create(GrantDto grantDto) throws IOException {
Grant newGrant = copyFromDto(new Grant(), grantDto);
newGrant = grantRepository.save(newGrant);
+ eventService.createFromGrant(newGrant);
return newGrant.getId();
}
@@ -115,6 +120,7 @@ public class GrantService {
}
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
grantRepository.save(copyFromDto(grant, grantDto));
+ eventService.updateGrantDeadlines(grant);
return grant.getId();
}
@@ -140,6 +146,9 @@ public class GrantService {
grant.setLeader(user);
grant.getPapers().add(paper);
grant = grantRepository.save(grant);
+
+ eventService.createFromGrant(grant);
+
return grant;
}
diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java
index 9409f21..9252cec 100644
--- a/src/main/java/ru/ulstu/timeline/model/Event.java
+++ b/src/main/java/ru/ulstu/timeline/model/Event.java
@@ -3,6 +3,7 @@ package ru.ulstu.timeline.model;
import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.conference.model.Conference;
import ru.ulstu.core.model.BaseEntity;
+import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.user.model.User;
@@ -82,6 +83,10 @@ public class Event extends BaseEntity {
@JoinColumn(name = "conference_id")
private Conference conference;
+ @ManyToOne
+ @JoinColumn(name = "grant_id")
+ private Grant grant;
+
public String getTitle() {
return title;
}
@@ -177,4 +182,12 @@ public class Event extends BaseEntity {
public void setConference(Conference conference) {
this.conference = conference;
}
+
+ public Grant getGrant() {
+ return grant;
+ }
+
+ public void setGrant(Grant grant) {
+ this.grant = grant;
+ }
}
diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java
index ccce25a..89df5d8 100644
--- a/src/main/java/ru/ulstu/timeline/model/EventDto.java
+++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.conference.model.ConferenceDto;
+import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.user.model.UserDto;
@@ -27,6 +28,7 @@ public class EventDto {
private final List recipients;
private PaperDto paperDto;
private ConferenceDto conferenceDto;
+ private GrantDto grantDto;
@JsonCreator
public EventDto(@JsonProperty("id") Integer id,
@@ -39,7 +41,8 @@ public class EventDto {
@JsonProperty("description") String description,
@JsonProperty("paperDto") PaperDto paperDto,
@JsonProperty("recipients") List recipients,
- @JsonProperty("conferenceDto") ConferenceDto conferenceDto) {
+ @JsonProperty("conferenceDto") ConferenceDto conferenceDto,
+ @JsonProperty("grantDto") GrantDto grantDto) {
this.id = id;
this.title = title;
this.period = period;
@@ -51,6 +54,7 @@ public class EventDto {
this.recipients = recipients;
this.paperDto = paperDto;
this.conferenceDto = conferenceDto;
+ this.grantDto = grantDto;
}
public EventDto(Event event) {
@@ -69,6 +73,9 @@ public class EventDto {
if (conferenceDto != null) {
this.conferenceDto = new ConferenceDto(event.getConference());
}
+ if (grantDto != null) {
+ this.grantDto = new GrantDto(event.getGrant());
+ }
}
public Integer getId() {
@@ -122,4 +129,12 @@ public class EventDto {
public void setConferenceDto(ConferenceDto conferenceDto) {
this.conferenceDto = conferenceDto;
}
+
+ public GrantDto getGrantDto() {
+ return grantDto;
+ }
+
+ public void setGrantDto(GrantDto grantDto) {
+ this.grantDto = grantDto;
+ }
}
diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java
index a4b1e47..e01037a 100644
--- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java
+++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java
@@ -3,6 +3,7 @@ package ru.ulstu.timeline.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import ru.ulstu.conference.model.Conference;
+import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.timeline.model.Event;
@@ -18,4 +19,6 @@ public interface EventRepository extends JpaRepository {
List findAllByPaper(Paper paper);
List findAllByConference(Conference conference);
+
+ List findAllByGrant(Grant grant);
}
diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java
index d2fa510..b935f16 100644
--- a/src/main/java/ru/ulstu/timeline/service/EventService.java
+++ b/src/main/java/ru/ulstu/timeline/service/EventService.java
@@ -6,6 +6,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.ulstu.conference.model.Conference;
import ru.ulstu.deadline.model.Deadline;
+import ru.ulstu.grant.model.Grant;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.timeline.model.Event;
import ru.ulstu.timeline.model.EventDto;
@@ -170,4 +171,36 @@ public class EventService {
eventRepository.delete(eventRepository.findAllByConference(conference));
createFromConference(conference);
}
+
+ public void createFromGrant(Grant newGrant) {
+ List timelines = timelineService.findAll();
+ Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
+
+ for (Deadline deadline : newGrant.getDeadlines()
+ .stream()
+ .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
+ .collect(Collectors.toList())) {
+ Event newEvent = new Event();
+ newEvent.setTitle("Дедлайн гранта");
+ newEvent.setStatus(Event.EventStatus.NEW);
+ newEvent.setExecuteDate(deadline.getDate());
+ newEvent.setCreateDate(new Date());
+ newEvent.setUpdateDate(new Date());
+ newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' гранта '" + newGrant.getTitle() + "'");
+ if (newGrant.getAuthors() != null) {
+ newEvent.setRecipients(new ArrayList(newGrant.getAuthors()));
+ }
+ newEvent.getRecipients().add(newGrant.getLeader());
+ newEvent.setGrant(newGrant);
+ eventRepository.save(newEvent);
+
+ timeline.getEvents().add(newEvent);
+ timelineService.save(timeline);
+ }
+ }
+
+ public void updateGrantDeadlines(Grant grant) {
+ eventRepository.delete(eventRepository.findAllByGrant(grant));
+ createFromGrant(grant);
+ }
}
From 65dea9bce2c211126114386768ed6940fbbaee9f Mon Sep 17 00:00:00 2001
From: ASH
Date: Mon, 6 May 2019 22:39:08 +0400
Subject: [PATCH 028/136] #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 2dae39a100d12de0b3e40cfc8d080eaddc535ef7 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Mon, 6 May 2019 23:57:16 +0400
Subject: [PATCH 029/136] #119 create grants notification service
---
.../service/GrantNotificationService.java | 66 +++++++++++++++++++
1 file changed, 66 insertions(+)
create mode 100644 src/main/java/ru/ulstu/grant/service/GrantNotificationService.java
diff --git a/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java
new file mode 100644
index 0000000..c234290
--- /dev/null
+++ b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java
@@ -0,0 +1,66 @@
+package ru.ulstu.grant.service;
+
+import com.google.common.collect.ImmutableMap;
+import org.springframework.stereotype.Service;
+import ru.ulstu.core.util.DateUtils;
+import ru.ulstu.grant.model.Grant;
+import ru.ulstu.user.model.User;
+import ru.ulstu.user.service.MailService;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@Service
+public class GrantNotificationService {
+ private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
+ private final static String TEMPLATE_DEADLINE = "grantDeadlineNotification";
+ private final static String TEMPLATE_CREATE = "grantCreateNotification";
+ private final static String TEMPLATE_AUTHORS_CHANGED = "grantAuthorsChangeNotification";
+
+ private final static String TITLE_DEADLINE = "Приближается дедлайн гранта: %s";
+ private final static String TITLE_CREATE = "Создан грант: %s";
+ private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s";
+
+ private final MailService mailService;
+
+ public GrantNotificationService(MailService mailService) {
+ this.mailService = mailService;
+ }
+
+ public void sendDeadlineNotifications(List grants, boolean isDeadlineBeforeWeek) {
+ Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
+ grants.stream()
+ .filter(grant -> needToSendDeadlineNotification(grant, now, isDeadlineBeforeWeek))
+ .forEach(grant -> sendMessageDeadline(grant));
+ }
+
+ private boolean needToSendDeadlineNotification(Grant grant, Date compareDate, boolean isDeadlineBeforeWeek) {
+ return (grant.getNextDeadline().isPresent())
+ && (compareDate.before(grant.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek
+ || compareDate.after(grant.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek)
+ && grant.getNextDeadline().get().getDate().after(new Date());
+ }
+
+ private void sendMessageDeadline(Grant grant) {
+ Map variables = ImmutableMap.of("grant", grant);
+ sendForAllAuthors(variables, grant, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, grant.getTitle()));
+ }
+
+ public void sendCreateNotification(Grant grant) {
+ Map variables = ImmutableMap.of("grant", grant);
+ sendForAllAuthors(variables, grant, TEMPLATE_CREATE, String.format(TITLE_CREATE, grant.getTitle()));
+ }
+
+ public void authorsChangeNotification(Grant grant, List oldAuthors) {
+ Map variables = ImmutableMap.of("grant", grant, "oldAuthors", oldAuthors);
+ sendForAllAuthors(variables, grant, TEMPLATE_AUTHORS_CHANGED, String.format(TITLE_AUTHORS_CHANGED, grant.getTitle()));
+ }
+
+ private void sendForAllAuthors(Map variables, Grant grant, String template, String title) {
+ Set allAuthors = grant.getAuthors();
+ allAuthors.add(grant.getLeader());
+ allAuthors.forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title));
+ }
+}
From dffd839905ffda7d0d5cf86821b7c266abab9178 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?=
=?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?=
Date: Tue, 7 May 2019 20:26:49 +0400
Subject: [PATCH 030/136] #109 only uncompleted for grant
---
src/main/java/ru/ulstu/grant/controller/GrantController.java | 2 +-
src/main/java/ru/ulstu/grant/service/GrantService.java | 4 ++++
src/main/java/ru/ulstu/paper/repository/PaperRepository.java | 2 ++
src/main/java/ru/ulstu/paper/service/PaperService.java | 3 +++
4 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java
index 85a0cd9..b28f8c0 100644
--- a/src/main/java/ru/ulstu/grant/controller/GrantController.java
+++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java
@@ -132,7 +132,7 @@ public class GrantController {
@ModelAttribute("allPapers")
public List getAllPapers() {
- return grantService.getAllPapers();
+ return grantService.getAllUncompletedPapers();
}
private void filterEmptyDeadlines(GrantDto grantDto) {
diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java
index 9cff4b6..ae11850 100644
--- a/src/main/java/ru/ulstu/grant/service/GrantService.java
+++ b/src/main/java/ru/ulstu/grant/service/GrantService.java
@@ -196,6 +196,10 @@ public class GrantService {
return paperService.findAll();
}
+ public List getAllUncompletedPapers() {
+ return paperService.findAllNotCompleted();
+ }
+
public void attachPaper(GrantDto grantDto) {
if (!grantDto.getPaperIds().isEmpty()) {
grantDto.getPapers().clear();
diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
index f935247..7eff73d 100644
--- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
+++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
@@ -18,4 +18,6 @@ public interface PaperRepository extends JpaRepository {
List findAllByIdIn(List paperIds);
List findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status);
+
+ List findByStatusNot(Paper.PaperStatus status);
}
diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java
index f98997d..956b4b6 100644
--- a/src/main/java/ru/ulstu/paper/service/PaperService.java
+++ b/src/main/java/ru/ulstu/paper/service/PaperService.java
@@ -246,7 +246,10 @@ public class PaperService {
} else {
return sortPapers(paperRepository.findAll());
}
+ }
+ public List findAllNotCompleted() {
+ return paperRepository.findByStatusNot(COMPLETED);
}
public List findAllSelect(List paperIds) {
From 1e07c5424dd0dddeaf1e109d20dc53d488e2b027 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?=
=?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?=
Date: Tue, 7 May 2019 21:35:50 +0400
Subject: [PATCH 031/136] #109 only one conference for paper
---
src/main/java/ru/ulstu/paper/model/Paper.java | 12 ++++++++++++
.../ru/ulstu/paper/repository/PaperRepository.java | 4 ++++
.../java/ru/ulstu/paper/service/PaperService.java | 4 ++--
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java
index 65bd32c..eae8764 100644
--- a/src/main/java/ru/ulstu/paper/model/Paper.java
+++ b/src/main/java/ru/ulstu/paper/model/Paper.java
@@ -3,6 +3,7 @@ package ru.ulstu.paper.model;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.NotBlank;
+import ru.ulstu.conference.model.Conference;
import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.UserContainer;
import ru.ulstu.deadline.model.Deadline;
@@ -114,6 +115,9 @@ public class Paper extends BaseEntity implements UserContainer {
@Column(name = "latex_text")
private String latexText;
+ @ManyToMany(mappedBy = "papers")
+ private List conferences;
+
public PaperStatus getStatus() {
return status;
}
@@ -218,6 +222,14 @@ public class Paper extends BaseEntity implements UserContainer {
this.latexText = latexText;
}
+ public List getConferences() {
+ return conferences;
+ }
+
+ public void setConferences(List conferences) {
+ this.conferences = conferences;
+ }
+
@Override
public Set getUsers() {
return getAuthors();
diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
index 7eff73d..42d3703 100644
--- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
+++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java
@@ -20,4 +20,8 @@ public interface PaperRepository extends JpaRepository {
List findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status);
List findByStatusNot(Paper.PaperStatus status);
+
+ List findByConferencesIsNullAndStatusNot(Paper.PaperStatus status);
+
+ List findByIdNotInAndConferencesIsNullAndStatusNot(List paperIds, Paper.PaperStatus status);
}
diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java
index 956b4b6..0083de7 100644
--- a/src/main/java/ru/ulstu/paper/service/PaperService.java
+++ b/src/main/java/ru/ulstu/paper/service/PaperService.java
@@ -242,9 +242,9 @@ public class PaperService {
public List findAllNotSelect(List paperIds) {
if (!paperIds.isEmpty()) {
- return sortPapers(paperRepository.findByIdNotIn(paperIds));
+ return sortPapers(paperRepository.findByIdNotInAndConferencesIsNullAndStatusNot(paperIds, COMPLETED));
} else {
- return sortPapers(paperRepository.findAll());
+ return sortPapers(paperRepository.findByConferencesIsNullAndStatusNot(COMPLETED));
}
}
From 934d194df15434c3991d1afb091ea0b1edcd91b8 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Tue, 7 May 2019 22:15:49 +0400
Subject: [PATCH 032/136] #119 gelete unnecessary column
---
.../resources/db/changelog-20190507_000000-schema.xml | 8 ++++++++
src/main/resources/db/changelog-master.xml | 1 +
2 files changed, 9 insertions(+)
create mode 100644 src/main/resources/db/changelog-20190507_000000-schema.xml
diff --git a/src/main/resources/db/changelog-20190507_000000-schema.xml b/src/main/resources/db/changelog-20190507_000000-schema.xml
new file mode 100644
index 0000000..0cdb99b
--- /dev/null
+++ b/src/main/resources/db/changelog-20190507_000000-schema.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml
index 83ff280..65a07c2 100644
--- a/src/main/resources/db/changelog-master.xml
+++ b/src/main/resources/db/changelog-master.xml
@@ -38,4 +38,5 @@
+
\ No newline at end of file
From d2444378587e669fad6eb6e3204866e6f2c14b33 Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Tue, 7 May 2019 22:35:44 +0400
Subject: [PATCH 033/136] #122 fix bug
---
src/main/resources/db/changelog-master.xml | 1 +
.../db/common/changelog-20190507_000001-schema.xml | 14 ++++++++++++++
2 files changed, 15 insertions(+)
create mode 100644 src/main/resources/db/common/changelog-20190507_000001-schema.xml
diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml
index 83ff280..63d7ccf 100644
--- a/src/main/resources/db/changelog-master.xml
+++ b/src/main/resources/db/changelog-master.xml
@@ -38,4 +38,5 @@
+
\ No newline at end of file
diff --git a/src/main/resources/db/common/changelog-20190507_000001-schema.xml b/src/main/resources/db/common/changelog-20190507_000001-schema.xml
new file mode 100644
index 0000000..c320eba
--- /dev/null
+++ b/src/main/resources/db/common/changelog-20190507_000001-schema.xml
@@ -0,0 +1,14 @@
+
+
+
+
+ update grants
+ set leader_id =
+ (select u.id
+ from users u
+ where u.last_name = 'Романов' AND u.first_name = 'Антон');
+
+
+
From 7ffe04f1dbb9f630ed66aba5423800628c6f234e Mon Sep 17 00:00:00 2001
From: T-Midnight
Date: Tue, 7 May 2019 22:47:27 +0400
Subject: [PATCH 034/136] #122 move to right directory
---
.../db/{common => }/changelog-20190507_000001-schema.xml | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename src/main/resources/db/{common => }/changelog-20190507_000001-schema.xml (100%)
diff --git a/src/main/resources/db/common/changelog-20190507_000001-schema.xml b/src/main/resources/db/changelog-20190507_000001-schema.xml
similarity index 100%
rename from src/main/resources/db/common/changelog-20190507_000001-schema.xml
rename to src/main/resources/db/changelog-20190507_000001-schema.xml
From 2fba252df088b38068f76ddcc6ae2098e90074df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?=
=?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?=
Date: Tue, 7 May 2019 23:53:10 +0400
Subject: [PATCH 035/136] #109 show other paper attachs
---
src/main/java/ru/ulstu/paper/model/Paper.java | 12 ++++++++++
.../resources/templates/grants/grant.html | 24 +++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java
index eae8764..4536ce5 100644
--- a/src/main/java/ru/ulstu/paper/model/Paper.java
+++ b/src/main/java/ru/ulstu/paper/model/Paper.java
@@ -8,6 +8,7 @@ import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.UserContainer;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData;
+import ru.ulstu.grant.model.Grant;
import ru.ulstu.timeline.model.Event;
import ru.ulstu.user.model.User;
@@ -118,6 +119,9 @@ public class Paper extends BaseEntity implements UserContainer {
@ManyToMany(mappedBy = "papers")
private List conferences;
+ @ManyToMany(mappedBy = "papers")
+ private List grants;
+
public PaperStatus getStatus() {
return status;
}
@@ -230,6 +234,14 @@ public class Paper extends BaseEntity implements UserContainer {
this.conferences = conferences;
}
+ public List getGrants() {
+ return grants;
+ }
+
+ public void setGrants(List grants) {
+ this.grants = grants;
+ }
+
@Override
public Set getUsers() {
return getAuthors();
diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html
index 4d3cdde..e357876 100644
--- a/src/main/resources/templates/grants/grant.html
+++ b/src/main/resources/templates/grants/grant.html
@@ -201,6 +201,30 @@
Статус статьи
+
+
\ No newline at end of file
From d50673f5fa5eec40dea9e7dbb55c16c2d94b73a8 Mon Sep 17 00:00:00 2001
From: "Artem.Arefev"
Date: Thu, 16 May 2019 01:01:31 +0400
Subject: [PATCH 084/136] 87-inviting-user small fix in mail template, and
changed default user name
---
src/main/java/ru/ulstu/user/service/UserService.java | 4 ++--
src/main/resources/mail_templates/userInviteEmail.html | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java
index db20868..083b0f5 100644
--- a/src/main/java/ru/ulstu/user/service/UserService.java
+++ b/src/main/java/ru/ulstu/user/service/UserService.java
@@ -331,8 +331,8 @@ public class UserService implements UserDetailsService {
user.setPassword(passwordEncoder.encode(password));
user.setLogin(email);
user.setEmail(email);
- user.setFirstName("");
- user.setLastName("");
+ user.setFirstName("user");
+ user.setLastName("user");
user.setActivated(true);
userRepository.save(user);
diff --git a/src/main/resources/mail_templates/userInviteEmail.html b/src/main/resources/mail_templates/userInviteEmail.html
index 180f0c5..98fe85f 100644
--- a/src/main/resources/mail_templates/userInviteEmail.html
+++ b/src/main/resources/mail_templates/userInviteEmail.html
@@ -7,9 +7,9 @@
- Аккаунт в системе NG-Tracker был создан.
- Данные для входа:
- Логин -
+ Аккаунт в системе NG-Tracker был создан.
+ Данные для входа:
+ Логин -
Пароль -
From c47d4f8a05d4a3f573d87f269a9be31fd1a80398 Mon Sep 17 00:00:00 2001
From: "Artem.Arefev"
Date: Thu, 16 May 2019 01:17:04 +0400
Subject: [PATCH 085/136] #88 removed unused imports
---
src/main/java/ru/ulstu/user/controller/UserControllerV2.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/main/java/ru/ulstu/user/controller/UserControllerV2.java b/src/main/java/ru/ulstu/user/controller/UserControllerV2.java
index 84c0349..23bbba9 100644
--- a/src/main/java/ru/ulstu/user/controller/UserControllerV2.java
+++ b/src/main/java/ru/ulstu/user/controller/UserControllerV2.java
@@ -2,12 +2,10 @@ package ru.ulstu.user.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.configuration.Constants;
From ce7b4c9c7a81d0752efc61a94a9216828aa5afd9 Mon Sep 17 00:00:00 2001
From: Nightblade73
Date: Thu, 16 May 2019 13:33:26 +0400
Subject: [PATCH 086/136] #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 087/136] #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 088/136] #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 089/136] #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 090/136] #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 @@