merge dev
This commit is contained in:
commit
8187c9b614
@ -130,6 +130,6 @@ dependencies {
|
|||||||
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0'
|
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0'
|
||||||
|
|
||||||
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
|
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
|
||||||
testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1'
|
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1'
|
||||||
|
|
||||||
}
|
}
|
@ -18,6 +18,6 @@ fi
|
|||||||
|
|
||||||
ssh $USERSERVER "cd /tmp && rm -rf $ARTIFACT_NAME*.jar && echo `date` 'killed' >> log_$ARTIFACT_NAME"
|
ssh $USERSERVER "cd /tmp && rm -rf $ARTIFACT_NAME*.jar && echo `date` 'killed' >> log_$ARTIFACT_NAME"
|
||||||
scp build/libs/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar $USERSERVER:/tmp/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar
|
scp build/libs/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar $USERSERVER:/tmp/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar
|
||||||
ssh $USERSERVER -f "cd /tmp/ && /opt/jdk1.8.0_192/bin/java -jar $ARTIFACT_NAME-0.1.0-SNAPSHOT.jar -Xms 512m -Xmx 1024m --server.port=8443 --server.http.port=8080 --ng-tracker.base-url=http://193.110.3.124:8080 >> /home/user/logfile_$ARTIFACT_NAME" &
|
ssh $USERSERVER -f "cd /tmp/ && /opt/jdk1.8.0_192/bin/java -jar $ARTIFACT_NAME-0.1.0-SNAPSHOT.jar -Xms 512m -Xmx 1024m --server.port=8443 --server.http.port=8080 --ng-tracker.base-url=http://193.110.3.124:8080 --ng-tracker.dev-mode=false >> /home/user/logfile_$ARTIFACT_NAME" &
|
||||||
sleep 10
|
sleep 10
|
||||||
echo "is deployed"
|
echo "is deployed"
|
@ -13,7 +13,6 @@ import ru.ulstu.conference.model.ConferenceDto;
|
|||||||
import ru.ulstu.conference.model.ConferenceFilterDto;
|
import ru.ulstu.conference.model.ConferenceFilterDto;
|
||||||
import ru.ulstu.conference.model.ConferenceUser;
|
import ru.ulstu.conference.model.ConferenceUser;
|
||||||
import ru.ulstu.conference.service.ConferenceService;
|
import ru.ulstu.conference.service.ConferenceService;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
@ -22,9 +21,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
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.CONFERENCES_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE;
|
import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
||||||
@ -77,21 +74,19 @@ public class ConferenceController {
|
|||||||
|
|
||||||
@PostMapping(value = "/conference", params = "save")
|
@PostMapping(value = "/conference", params = "save")
|
||||||
public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
filterEmptyDeadlines(conferenceDto);
|
if (!conferenceService.save(conferenceDto, errors)) {
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return CONFERENCE_PAGE;
|
return CONFERENCE_PAGE;
|
||||||
}
|
}
|
||||||
conferenceService.save(conferenceDto);
|
|
||||||
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
|
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/conference", params = "addDeadline")
|
@PostMapping(value = "/conference", params = "addDeadline")
|
||||||
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
filterEmptyDeadlines(conferenceDto);
|
conferenceService.filterEmptyDeadlines(conferenceDto);
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
return CONFERENCE_PAGE;
|
return CONFERENCE_PAGE;
|
||||||
}
|
}
|
||||||
conferenceDto.getDeadlines().add(new Deadline());
|
conferenceService.addDeadline(conferenceDto);
|
||||||
return CONFERENCE_PAGE;
|
return CONFERENCE_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,9 +162,4 @@ public class ConferenceController {
|
|||||||
return years;
|
return years;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
|
||||||
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,10 @@ import javax.persistence.Table;
|
|||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "conference")
|
@Table(name = "conference")
|
||||||
@ -40,12 +42,12 @@ public class Conference extends BaseEntity {
|
|||||||
@Column(name = "begin_date")
|
@Column(name = "begin_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date beginDate;
|
private Date beginDate = new Date();
|
||||||
|
|
||||||
@Column(name = "end_date")
|
@Column(name = "end_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date endDate;
|
private Date endDate = new Date();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "conference_id", unique = true)
|
@JoinColumn(name = "conference_id", unique = true)
|
||||||
@ -57,6 +59,7 @@ public class Conference extends BaseEntity {
|
|||||||
@JoinTable(name = "paper_conference",
|
@JoinTable(name = "paper_conference",
|
||||||
joinColumns = {@JoinColumn(name = "conference_id")},
|
joinColumns = {@JoinColumn(name = "conference_id")},
|
||||||
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
|
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
private List<Paper> papers = new ArrayList<>();
|
private List<Paper> papers = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@ -135,4 +138,13 @@ public class Conference extends BaseEntity {
|
|||||||
public void setUsers(List<ConferenceUser> users) {
|
public void setUsers(List<ConferenceUser> users) {
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Deadline> getNextDeadline() {
|
||||||
|
return deadlines
|
||||||
|
.stream()
|
||||||
|
.filter(deadline -> deadline.getDate() != null)
|
||||||
|
.sorted(Comparator.comparing(Deadline::getDate))
|
||||||
|
.filter(d -> d.getDate().after(new Date()))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.name.NameContainer;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
@ -13,10 +14,11 @@ import javax.validation.constraints.Size;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class ConferenceDto {
|
public class ConferenceDto extends NameContainer {
|
||||||
|
|
||||||
private final static String BEGIN_DATE = "Начало: ";
|
private final static String BEGIN_DATE = "Начало: ";
|
||||||
private final static String END_DATE = "Конец: ";
|
private final static String END_DATE = "Конец: ";
|
||||||
@ -218,4 +220,33 @@ public class ConferenceDto {
|
|||||||
return BEGIN_DATE + beginDate.toString().split(" ")[0] + " " + END_DATE + endDate.toString().split(" ")[0];
|
return BEGIN_DATE + beginDate.toString().split(" ")[0] + " " + END_DATE + endDate.toString().split(" ")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ConferenceDto that = (ConferenceDto) o;
|
||||||
|
return ping == that.ping &&
|
||||||
|
disabledTakePart == that.disabledTakePart &&
|
||||||
|
Objects.equals(id, that.id) &&
|
||||||
|
Objects.equals(title, that.title) &&
|
||||||
|
Objects.equals(description, that.description) &&
|
||||||
|
Objects.equals(url, that.url) &&
|
||||||
|
Objects.equals(deadlines, that.deadlines) &&
|
||||||
|
Objects.equals(removedDeadlineIds, that.removedDeadlineIds) &&
|
||||||
|
Objects.equals(userIds, that.userIds) &&
|
||||||
|
Objects.equals(paperIds, that.paperIds) &&
|
||||||
|
Objects.equals(papers, that.papers) &&
|
||||||
|
Objects.equals(notSelectedPapers, that.notSelectedPapers) &&
|
||||||
|
Objects.equals(users, that.users);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds,
|
||||||
|
userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,13 @@ import org.springframework.data.jpa.repository.Modifying;
|
|||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.name.BaseRepository;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ConferenceRepository extends JpaRepository<Conference, Integer> {
|
public interface ConferenceRepository extends JpaRepository<Conference, Integer>, BaseRepository {
|
||||||
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " +
|
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " +
|
||||||
"AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC")
|
"AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC")
|
||||||
List<Conference> findByUserAndYear(@Param("user") User user, @Param("year") Integer year);
|
List<Conference> findByUserAndYear(@Param("user") User user, @Param("year") Integer year);
|
||||||
@ -24,4 +25,8 @@ public interface ConferenceRepository extends JpaRepository<Conference, Integer>
|
|||||||
@Modifying
|
@Modifying
|
||||||
@Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id")
|
@Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id")
|
||||||
int updatePingConference(@Param("id") Integer id);
|
int updatePingConference(@Param("id") Integer id);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Query("SELECT title FROM Conference c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ")
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,113 @@
|
|||||||
package ru.ulstu.conference.service;
|
package ru.ulstu.conference.service;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
import ru.ulstu.ping.service.PingService;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ConferenceNotificationService {
|
public class ConferenceNotificationService {
|
||||||
|
|
||||||
|
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";
|
||||||
|
private final static String TEMPLATE_CREATE = "conferenceCreateNotification";
|
||||||
|
private final static String TEMPLATE_UPDATE_DEADLINES = "conferenceUpdateDeadlinesNotification";
|
||||||
|
private final static String TEMPLATE_UPDATE_DATES = "conferenceUpdateDatesNotification";
|
||||||
|
|
||||||
|
private final static String TITLE_PING = "Обратите внимание на конференцию: %s";
|
||||||
|
private final static String TITLE_DEADLINE = "Приближается дедлайн конференции: %s";
|
||||||
|
private final static String TITLE_CREATE = "Создана новая конференция: %s";
|
||||||
|
private final static String TITLE_UPDATE_DEADLINES = "Изменения дедлайнов в конференции: %s";
|
||||||
|
private final static String TITLE_UPDATE_DATES = "Изменение дат проведения конференции: %s";
|
||||||
|
|
||||||
|
private final MailService mailService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final PingService pingService;
|
||||||
|
|
||||||
|
public ConferenceNotificationService(MailService mailService,
|
||||||
|
UserService userService,
|
||||||
|
PingService pingService) {
|
||||||
|
this.mailService = mailService;
|
||||||
|
this.userService = userService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendDeadlineNotifications(List<Conference> conferences) {
|
||||||
|
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
||||||
|
conferences
|
||||||
|
.stream()
|
||||||
|
.filter(conference -> needToSendDeadlineNotification(conference, now))
|
||||||
|
.forEach(this::sendMessageDeadline);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean needToSendDeadlineNotification(Conference conference, Date compareDate) {
|
||||||
|
return (conference.getNextDeadline().isPresent())
|
||||||
|
&& conference.getNextDeadline().get().getDate().after(new Date())
|
||||||
|
&& conference.getNextDeadline().get().getDate().before(compareDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageDeadline(Conference conference) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
||||||
|
sendForAllParticipants(variables, conference, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, conference.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Conference conference) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
||||||
|
sendForAllUsers(variables, TEMPLATE_CREATE, String.format(TITLE_CREATE, conference.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDeadlineNotification(Conference conference) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
||||||
|
sendForAllParticipants(variables, conference, TEMPLATE_UPDATE_DEADLINES, String.format(TITLE_UPDATE_DEADLINES, conference.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateConferencesDatesNotification(Conference conference, Date oldBeginDate, Date oldEndDate) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("conference", conference, "oldBeginDate", oldBeginDate, "oldEndDate", oldEndDate);
|
||||||
|
sendForAllParticipants(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendForAllUsers(Map<String, Object> variables, String template, String title) {
|
||||||
|
userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, template, title));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendForAllParticipants(Map<String, Object> variables, Conference conference, String template, String title) {
|
||||||
|
conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void sendPingNotifications(List<Conference> conferences) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(new Date());
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, YESTERDAY);
|
||||||
|
conferences
|
||||||
|
.stream()
|
||||||
|
.filter(conference -> {
|
||||||
|
Integer pingCount = pingService.countPingYesterday(conference, calendar);
|
||||||
|
return needToSendPingNotification(conference, pingCount);
|
||||||
|
})
|
||||||
|
.forEach(this::sendMessagePing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean needToSendPingNotification(Conference conference, Integer pingCount) {
|
||||||
|
if (pingCount > 0) {
|
||||||
|
conference.setPing((Integer) pingCount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessagePing(Conference conference) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("conference", conference);
|
||||||
|
sendForAllParticipants(variables, conference, TEMPLATE_PING, String.format(TITLE_PING, conference.getTitle()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package ru.ulstu.conference.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ConferenceScheduler {
|
||||||
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(ConferenceScheduler.class);
|
||||||
|
|
||||||
|
private final ConferenceNotificationService conferenceNotificationService;
|
||||||
|
private final ConferenceService conferenceService;
|
||||||
|
|
||||||
|
public ConferenceScheduler(ConferenceNotificationService conferenceNotificationService,
|
||||||
|
ConferenceService conferenceService) {
|
||||||
|
this.conferenceNotificationService = conferenceNotificationService;
|
||||||
|
this.conferenceService = conferenceService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
||||||
|
public void checkDeadlineBeforeWeek() {
|
||||||
|
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started");
|
||||||
|
conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll());
|
||||||
|
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara")
|
||||||
|
public void checkNewPing() {
|
||||||
|
log.debug("ConferenceScheduler.checkPing started");
|
||||||
|
conferenceNotificationService.sendPingNotifications(conferenceService.findAll());
|
||||||
|
log.debug("ConferenceScheduler.checkPing finished");
|
||||||
|
}
|
||||||
|
}
|
@ -5,15 +5,20 @@ import org.springframework.data.domain.Sort;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.conference.model.ConferenceDto;
|
import ru.ulstu.conference.model.ConferenceDto;
|
||||||
import ru.ulstu.conference.model.ConferenceFilterDto;
|
import ru.ulstu.conference.model.ConferenceFilterDto;
|
||||||
import ru.ulstu.conference.model.ConferenceUser;
|
import ru.ulstu.conference.model.ConferenceUser;
|
||||||
import ru.ulstu.conference.repository.ConferenceRepository;
|
import ru.ulstu.conference.repository.ConferenceRepository;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.name.BaseService;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
import ru.ulstu.ping.model.Ping;
|
||||||
import ru.ulstu.ping.service.PingService;
|
import ru.ulstu.ping.service.PingService;
|
||||||
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
@ -22,12 +27,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ConferenceService {
|
public class ConferenceService extends BaseService {
|
||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
private final static int MAX_DISPLAY_SIZE = 40;
|
||||||
|
|
||||||
private final ConferenceRepository conferenceRepository;
|
private final ConferenceRepository conferenceRepository;
|
||||||
@ -36,23 +42,30 @@ public class ConferenceService {
|
|||||||
private final PaperService paperService;
|
private final PaperService paperService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final PingService pingService;
|
private final PingService pingService;
|
||||||
|
private final ConferenceNotificationService conferenceNotificationService;
|
||||||
|
private final EventService eventService;
|
||||||
|
|
||||||
public ConferenceService(ConferenceRepository conferenceRepository,
|
public ConferenceService(ConferenceRepository conferenceRepository,
|
||||||
ConferenceUserService conferenceUserService,
|
ConferenceUserService conferenceUserService,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
PaperService paperService,
|
PaperService paperService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
PingService pingService) {
|
PingService pingService,
|
||||||
|
ConferenceNotificationService conferenceNotificationService,
|
||||||
|
EventService eventService) {
|
||||||
|
this.baseRepository = conferenceRepository;
|
||||||
this.conferenceRepository = conferenceRepository;
|
this.conferenceRepository = conferenceRepository;
|
||||||
this.conferenceUserService = conferenceUserService;
|
this.conferenceUserService = conferenceUserService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.paperService = paperService;
|
this.paperService = paperService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.pingService = pingService;
|
this.pingService = pingService;
|
||||||
|
this.conferenceNotificationService = conferenceNotificationService;
|
||||||
|
this.eventService = eventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto getExistConferenceById(Integer id) {
|
public ConferenceDto getExistConferenceById(Integer id) {
|
||||||
ConferenceDto conferenceDto = findOneDto(id);
|
ConferenceDto conferenceDto = new ConferenceDto(conferenceRepository.findOne(id));
|
||||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
||||||
conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers()));
|
conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers()));
|
||||||
return conferenceDto;
|
return conferenceDto;
|
||||||
@ -60,7 +73,7 @@ public class ConferenceService {
|
|||||||
|
|
||||||
public ConferenceDto getNewConference() {
|
public ConferenceDto getNewConference() {
|
||||||
ConferenceDto conferenceDto = new ConferenceDto();
|
ConferenceDto conferenceDto = new ConferenceDto();
|
||||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<Integer>()));
|
conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<>()));
|
||||||
return conferenceDto;
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,68 +88,103 @@ public class ConferenceService {
|
|||||||
return conferences;
|
return conferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto findOneDto(Integer id) {
|
public boolean save(ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
return new ConferenceDto(conferenceRepository.findOne(id));
|
conferenceDto.setName(conferenceDto.getTitle());
|
||||||
|
filterEmptyDeadlines(conferenceDto);
|
||||||
|
checkEmptyFieldsOfDeadline(conferenceDto, errors);
|
||||||
|
checkEmptyFieldsOfDates(conferenceDto, errors);
|
||||||
|
checkUniqueName(conferenceDto,
|
||||||
|
errors,
|
||||||
|
conferenceDto.getId(),
|
||||||
|
"title",
|
||||||
|
"Конференция с таким именем уже существует");
|
||||||
|
if (errors.hasErrors()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(ConferenceDto conferenceDto) throws IOException {
|
|
||||||
if (isEmpty(conferenceDto.getId())) {
|
if (isEmpty(conferenceDto.getId())) {
|
||||||
create(conferenceDto);
|
create(conferenceDto);
|
||||||
} else {
|
} else {
|
||||||
update(conferenceDto);
|
update(conferenceDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer create(ConferenceDto conferenceDto) throws IOException {
|
public Conference create(ConferenceDto conferenceDto) throws IOException {
|
||||||
Conference newConference = copyFromDto(new Conference(), conferenceDto);
|
Conference newConference = copyFromDto(new Conference(), conferenceDto);
|
||||||
newConference = conferenceRepository.save(newConference);
|
newConference = conferenceRepository.save(newConference);
|
||||||
return newConference.getId();
|
conferenceNotificationService.sendCreateNotification(newConference);
|
||||||
|
eventService.createFromConference(newConference);
|
||||||
|
return newConference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(ConferenceDto conferenceDto) throws IOException {
|
public Conference update(ConferenceDto conferenceDto) throws IOException {
|
||||||
Conference conference = conferenceRepository.findOne(conferenceDto.getId());
|
Conference conference = conferenceRepository.findOne(conferenceDto.getId());
|
||||||
|
List<Deadline> oldDeadlines = conference.getDeadlines().stream()
|
||||||
|
.map(this::copyDeadline)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Date oldBeginDate = conference.getBeginDate();
|
||||||
|
Date oldEndDate = conference.getEndDate();
|
||||||
conferenceRepository.save(copyFromDto(conference, conferenceDto));
|
conferenceRepository.save(copyFromDto(conference, conferenceDto));
|
||||||
|
eventService.updateConferenceDeadlines(conference);
|
||||||
|
sendNotificationAfterUpdateDeadlines(conference, oldDeadlines);
|
||||||
|
if (!conference.getBeginDate().equals(oldBeginDate) || !conference.getEndDate().equals(oldEndDate)) {
|
||||||
|
conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate);
|
||||||
|
}
|
||||||
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
||||||
return conference.getId();
|
return conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer conferenceId) {
|
public boolean delete(Integer conferenceId) {
|
||||||
if (conferenceRepository.exists(conferenceId)) {
|
if (conferenceRepository.exists(conferenceId)) {
|
||||||
|
eventService.removeConferencesEvent(conferenceRepository.findOne(conferenceId));
|
||||||
conferenceRepository.delete(conferenceId);
|
conferenceRepository.delete(conferenceId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
public ConferenceDto addDeadline(ConferenceDto conferenceDto) {
|
||||||
|
conferenceDto.getDeadlines().add(new Deadline());
|
||||||
|
return conferenceDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ConferenceDto removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
||||||
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
||||||
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
||||||
}
|
}
|
||||||
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPaper(ConferenceDto conferenceDto) {
|
public ConferenceDto addPaper(ConferenceDto conferenceDto) {
|
||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime());
|
paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime());
|
||||||
paper.setStatus(Paper.PaperStatus.DRAFT);
|
paper.setStatus(Paper.PaperStatus.DRAFT);
|
||||||
|
|
||||||
conferenceDto.getPapers().add(paper);
|
conferenceDto.getPapers().add(paper);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
public ConferenceDto removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
||||||
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
||||||
if (removedPaper.getId() != null) {
|
if (removedPaper.getId() != null) {
|
||||||
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
||||||
}
|
}
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takePart(ConferenceDto conferenceDto) throws IOException {
|
public ConferenceDto takePart(ConferenceDto conferenceDto) throws IOException {
|
||||||
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
||||||
conferenceDto.setDisabledTakePart(true);
|
conferenceDto.setDisabledTakePart(true);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
private List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
||||||
return paperService.findAllNotSelect(paperIds);
|
return paperService.findAllNotSelect(paperIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +218,7 @@ public class ConferenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
|
private boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
|
||||||
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
|
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +233,7 @@ public class ConferenceService {
|
|||||||
return convert(findAllActive(), ConferenceDto::new);
|
return convert(findAllActive(), ConferenceDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Conference> findAllActive() {
|
private List<Conference> findAllActive() {
|
||||||
return conferenceRepository.findAllActive(new Date());
|
return conferenceRepository.findAllActive(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,12 +242,13 @@ public class ConferenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void ping(ConferenceDto conferenceDto) throws IOException {
|
public Ping ping(ConferenceDto conferenceDto) throws IOException {
|
||||||
pingService.addPing(findOne(conferenceDto.getId()));
|
Ping ping = pingService.addPing(findOne(conferenceDto.getId()));
|
||||||
conferenceRepository.updatePingConference(conferenceDto.getId());
|
conferenceRepository.updatePingConference(conferenceDto.getId());
|
||||||
|
return ping;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Conference findOne(Integer conferenceId) {
|
private Conference findOne(Integer conferenceId) {
|
||||||
return conferenceRepository.findOne(conferenceId);
|
return conferenceRepository.findOne(conferenceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,4 +273,44 @@ public class ConferenceService {
|
|||||||
modelMap.addAttribute("nearshoreSales", nearshoreSales);
|
modelMap.addAttribute("nearshoreSales", nearshoreSales);
|
||||||
modelMap.addAttribute("offshoreSales", offshoreSales);
|
modelMap.addAttribute("offshoreSales", offshoreSales);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendNotificationAfterUpdateDeadlines(Conference conference, List<Deadline> oldDeadlines) {
|
||||||
|
if (oldDeadlines.size() != conference.getDeadlines().size()) {
|
||||||
|
conferenceNotificationService.updateDeadlineNotification(conference);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conference.getDeadlines()
|
||||||
|
.stream()
|
||||||
|
.filter(deadline -> !oldDeadlines.contains(deadline))
|
||||||
|
.count() > 0) {
|
||||||
|
conferenceNotificationService.updateDeadlineNotification(conference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Deadline copyDeadline(Deadline oldDeadline) {
|
||||||
|
Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription());
|
||||||
|
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", "Все поля дедлайна должны быть заполнены");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEmptyFieldsOfDates(ConferenceDto conferenceDto, Errors errors) {
|
||||||
|
if (conferenceDto.getBeginDate() == null || conferenceDto.getEndDate() == null) {
|
||||||
|
errors.rejectValue("beginDate", "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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ public class ApplicationProperties {
|
|||||||
|
|
||||||
private boolean checkRun;
|
private boolean checkRun;
|
||||||
|
|
||||||
|
private String debugEmail;
|
||||||
|
|
||||||
public boolean isUseHttps() {
|
public boolean isUseHttps() {
|
||||||
return useHttps;
|
return useHttps;
|
||||||
}
|
}
|
||||||
@ -60,4 +62,12 @@ public class ApplicationProperties {
|
|||||||
public void setCheckRun(boolean checkRun) {
|
public void setCheckRun(boolean checkRun) {
|
||||||
this.checkRun = checkRun;
|
this.checkRun = checkRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDebugEmail() {
|
||||||
|
return debugEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDebugEmail(String debugEmail) {
|
||||||
|
this.debugEmail = debugEmail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,11 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String MAIL_ACTIVATE = "Account activation";
|
public static final String MAIL_ACTIVATE = "Account activation";
|
||||||
public static final String MAIL_RESET = "Password reset";
|
public static final String MAIL_RESET = "Password reset";
|
||||||
|
public static final String MAIL_INVITE = "Account registration";
|
||||||
|
public static final String MAIL_CHANGE_PASSWORD = "Password has been changed";
|
||||||
|
|
||||||
public static final int MIN_PASSWORD_LENGTH = 6;
|
public static final int MIN_PASSWORD_LENGTH = 6;
|
||||||
|
public static final int MAX_PASSWORD_LENGTH = 32;
|
||||||
|
|
||||||
public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$";
|
public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$";
|
||||||
|
|
||||||
@ -17,4 +21,5 @@ public class Constants {
|
|||||||
public static final String PASSWORD_RESET_REQUEST_PAGE = "/resetRequest";
|
public static final String PASSWORD_RESET_REQUEST_PAGE = "/resetRequest";
|
||||||
public static final String PASSWORD_RESET_PAGE = "/reset";
|
public static final String PASSWORD_RESET_PAGE = "/reset";
|
||||||
|
|
||||||
|
public static final int RESET_KEY_LENGTH = 6;
|
||||||
}
|
}
|
@ -104,7 +104,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
.antMatchers("/css/**")
|
.antMatchers("/css/**")
|
||||||
.antMatchers("/js/**")
|
.antMatchers("/js/**")
|
||||||
.antMatchers("/templates/**")
|
.antMatchers("/templates/**")
|
||||||
.antMatchers("/webjars/**");
|
.antMatchers("/webjars/**")
|
||||||
|
.antMatchers("/img/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -20,6 +20,8 @@ import ru.ulstu.user.error.UserNotActivatedException;
|
|||||||
import ru.ulstu.user.error.UserNotFoundException;
|
import ru.ulstu.user.error.UserNotFoundException;
|
||||||
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
||||||
import ru.ulstu.user.error.UserResetKeyError;
|
import ru.ulstu.user.error.UserResetKeyError;
|
||||||
|
import ru.ulstu.user.error.UserSendingMailException;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -97,4 +99,9 @@ public class AdviceController {
|
|||||||
public ResponseExtended<String> handleUserIsUndeadException(Throwable e) {
|
public ResponseExtended<String> handleUserIsUndeadException(Throwable e) {
|
||||||
return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage());
|
return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(UserSendingMailException.class)
|
||||||
|
public ResponseExtended<String> handleUserSendingMailException(Throwable e) {
|
||||||
|
return handleException(ErrorConstants.USER_SENDING_MAIL_EXCEPTION, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,15 @@ public enum ErrorConstants {
|
|||||||
VALIDATION_ERROR(2, "Validation error"),
|
VALIDATION_ERROR(2, "Validation error"),
|
||||||
USER_ID_EXISTS(100, "New user can't have id"),
|
USER_ID_EXISTS(100, "New user can't have id"),
|
||||||
USER_ACTIVATION_ERROR(101, "Invalid activation key"),
|
USER_ACTIVATION_ERROR(101, "Invalid activation key"),
|
||||||
USER_EMAIL_EXISTS(102, "User with same email already exists"),
|
USER_EMAIL_EXISTS(102, "Пользователь с таким почтовым ящиком уже существует"),
|
||||||
USER_LOGIN_EXISTS(103, "User with same login already exists"),
|
USER_LOGIN_EXISTS(103, "Пользователь с таким логином уже существует"),
|
||||||
USER_PASSWORDS_NOT_VALID_OR_NOT_MATCH(104, "User passwords is not valid or not match"),
|
USER_PASSWORDS_NOT_VALID_OR_NOT_MATCH(104, "Пароли введены неверно"),
|
||||||
USER_NOT_FOUND(105, "User is not found"),
|
USER_NOT_FOUND(105, "Аккаунт не найден"),
|
||||||
USER_NOT_ACTIVATED(106, "User is not activated"),
|
USER_NOT_ACTIVATED(106, "User is not activated"),
|
||||||
USER_RESET_ERROR(107, "Invalid reset key"),
|
USER_RESET_ERROR(107, "Некорректный ключ подтверждения"),
|
||||||
USER_UNDEAD_ERROR(108, "Can't edit/delete that user"),
|
USER_UNDEAD_ERROR(108, "Can't edit/delete that user"),
|
||||||
FILE_UPLOAD_ERROR(110, "File upload error");
|
FILE_UPLOAD_ERROR(110, "File upload error"),
|
||||||
|
USER_SENDING_MAIL_EXCEPTION(111, "Во время отправки приглашения пользователю произошла ошибка");
|
||||||
|
|
||||||
private int code;
|
private int code;
|
||||||
private String message;
|
private String message;
|
||||||
|
@ -11,6 +11,6 @@ public class Response<D> extends ResponseEntity<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Response(ErrorConstants error) {
|
public Response(ErrorConstants error) {
|
||||||
super(new ControllerResponse<Void, Void>(new ControllerResponseError<>(error, null)), HttpStatus.OK);
|
super(new ControllerResponse<Void, Void>(new ControllerResponseError<>(error, null)), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ import ru.ulstu.core.model.ErrorConstants;
|
|||||||
public class ResponseExtended<E> extends ResponseEntity<Object> {
|
public class ResponseExtended<E> extends ResponseEntity<Object> {
|
||||||
|
|
||||||
public ResponseExtended(ErrorConstants error, E errorData) {
|
public ResponseExtended(ErrorConstants error, E errorData) {
|
||||||
super(new ControllerResponse<Void, E>(new ControllerResponseError<E>(error, errorData)), HttpStatus.OK);
|
super(new ControllerResponse<Void, E>(new ControllerResponseError<E>(error, errorData)), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,4 +54,10 @@ public class DateUtils {
|
|||||||
cal.add(Calendar.DAY_OF_MONTH, count);
|
cal.add(Calendar.DAY_OF_MONTH, count);
|
||||||
return cal.getTime();
|
return cal.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Date addYears(Date date, int count) {
|
||||||
|
Calendar cal = getCalendar(date);
|
||||||
|
cal.add(Calendar.YEAR, count);
|
||||||
|
return cal.getTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import javax.persistence.Entity;
|
|||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Deadline extends BaseEntity {
|
public class Deadline extends BaseEntity {
|
||||||
@ -51,4 +52,31 @@ public class Deadline extends BaseEntity {
|
|||||||
public void setDate(Date date) {
|
public void setDate(Date date) {
|
||||||
this.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;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), description, date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,15 @@ package ru.ulstu.deadline.repository;
|
|||||||
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
value = "SELECT date FROM Deadline d WHERE (d.grant_id = ?1) AND (d.date = ?2)",
|
||||||
|
nativeQuery = true)
|
||||||
|
Date findByGrantIdAndDate(Integer grantId, Date date);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.repository.DeadlineRepository;
|
import ru.ulstu.deadline.repository.DeadlineRepository;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -46,4 +47,8 @@ public class DeadlineService {
|
|||||||
public void remove(Integer deadlineId) {
|
public void remove(Integer deadlineId) {
|
||||||
deadlineRepository.delete(deadlineId);
|
deadlineRepository.delete(deadlineId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date findByGrantIdAndDate(Integer id, Date date) {
|
||||||
|
return deadlineRepository.findByGrantIdAndDate(id, date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,14 @@ import ru.ulstu.deadline.model.Deadline;
|
|||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
import ru.ulstu.grant.service.GrantService;
|
import ru.ulstu.grant.service.GrantService;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static org.springframework.util.StringUtils.isEmpty;
|
|
||||||
import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE;
|
import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.GRANT_PAGE;
|
import static ru.ulstu.core.controller.Navigation.GRANT_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
||||||
@ -45,7 +43,7 @@ public class GrantController {
|
|||||||
|
|
||||||
@GetMapping("/dashboard")
|
@GetMapping("/dashboard")
|
||||||
public void getDashboard(ModelMap modelMap) {
|
public void getDashboard(ModelMap modelMap) {
|
||||||
modelMap.put("grants", grantService.findAllDto());
|
modelMap.put("grants", grantService.findAllActiveDto());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/grant")
|
@GetMapping("/grant")
|
||||||
@ -62,17 +60,9 @@ public class GrantController {
|
|||||||
@PostMapping(value = "/grant", params = "save")
|
@PostMapping(value = "/grant", params = "save")
|
||||||
public String save(@Valid GrantDto grantDto, Errors errors)
|
public String save(@Valid GrantDto grantDto, Errors errors)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
filterEmptyDeadlines(grantDto);
|
if (!grantService.save(grantDto, errors)) {
|
||||||
if (grantDto.getDeadlines().isEmpty()) {
|
|
||||||
errors.rejectValue("deadlines", "errorCode", "Не может быть пусто");
|
|
||||||
}
|
|
||||||
if (grantDto.getLeaderId().equals(-1)) {
|
|
||||||
errors.rejectValue("leaderId", "errorCode", "Укажите руководителя");
|
|
||||||
}
|
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
grantService.save(grantDto);
|
|
||||||
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +79,7 @@ public class GrantController {
|
|||||||
|
|
||||||
@PostMapping(value = "/grant", params = "addDeadline")
|
@PostMapping(value = "/grant", params = "addDeadline")
|
||||||
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
||||||
filterEmptyDeadlines(grantDto);
|
grantService.filterEmptyDeadlines(grantDto);
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
@ -104,7 +94,6 @@ public class GrantController {
|
|||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping(value = "/grant", params = "createProject")
|
@PostMapping(value = "/grant", params = "createProject")
|
||||||
public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException {
|
public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException {
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
@ -131,13 +120,7 @@ public class GrantController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ModelAttribute("allPapers")
|
@ModelAttribute("allPapers")
|
||||||
public List<Paper> getAllPapers() {
|
public List<PaperDto> getAllPapers() {
|
||||||
return grantService.getAllPapers();
|
return grantService.getAllUncompletedPapers();
|
||||||
}
|
|
||||||
|
|
||||||
private void filterEmptyDeadlines(GrantDto grantDto) {
|
|
||||||
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package ru.ulstu.grant.model;
|
package ru.ulstu.grant.model;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.hibernate.validator.constraints.NotBlank;
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.core.model.UserContainer;
|
import ru.ulstu.core.model.UserContainer;
|
||||||
@ -7,6 +9,7 @@ import ru.ulstu.deadline.model.Deadline;
|
|||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.file.model.FileData;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
|
import ru.ulstu.timeline.model.Event;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
@ -40,7 +43,8 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
IN_WORK("В работе"),
|
IN_WORK("В работе"),
|
||||||
COMPLETED("Завершен"),
|
COMPLETED("Завершен"),
|
||||||
FAILED("Провалены сроки"),
|
FAILED("Провалены сроки"),
|
||||||
LOADED_FROM_KIAS("Загружен автоматически");
|
LOADED_FROM_KIAS("Загружен автоматически"),
|
||||||
|
SKIPPED("Не интересует");
|
||||||
|
|
||||||
private String statusName;
|
private String statusName;
|
||||||
|
|
||||||
@ -59,17 +63,17 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private GrantStatus status = GrantStatus.APPLICATION;
|
private GrantStatus status = GrantStatus.APPLICATION;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "grant_id")
|
@JoinColumn(name = "grant_id")
|
||||||
@OrderBy("date")
|
@OrderBy("date")
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
|
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
//Заявка на грант
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
@ManyToOne
|
@JoinColumn(name = "grant_id", unique = true)
|
||||||
@JoinColumn(name = "file_id")
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
private FileData application;
|
private List<FileData> files = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToOne(cascade = CascadeType.ALL)
|
@ManyToOne(cascade = CascadeType.ALL)
|
||||||
@JoinColumn(name = "project_id")
|
@JoinColumn(name = "project_id")
|
||||||
@ -87,8 +91,13 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
@JoinTable(name = "grants_papers",
|
@JoinTable(name = "grants_papers",
|
||||||
joinColumns = {@JoinColumn(name = "grant_id")},
|
joinColumns = {@JoinColumn(name = "grant_id")},
|
||||||
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
|
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
private List<Paper> papers = new ArrayList<>();
|
private List<Paper> papers = new ArrayList<>();
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "grant_id")
|
||||||
|
private List<Event> events = new ArrayList<>();
|
||||||
|
|
||||||
public GrantStatus getStatus() {
|
public GrantStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -113,12 +122,12 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileData getApplication() {
|
public List<FileData> getFiles() {
|
||||||
return application;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApplication(FileData application) {
|
public void setFiles(List<FileData> files) {
|
||||||
this.application = application;
|
this.files = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
@ -166,6 +175,14 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
this.papers = papers;
|
this.papers = papers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Event> getEvents() {
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEvents(List<Event> events) {
|
||||||
|
this.events = events;
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<Deadline> getNextDeadline() {
|
public Optional<Deadline> getNextDeadline() {
|
||||||
return deadlines
|
return deadlines
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -5,18 +5,21 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
|
import ru.ulstu.name.NameContainer;
|
||||||
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class GrantDto {
|
public class GrantDto extends NameContainer {
|
||||||
private final static int MAX_AUTHORS_LENGTH = 60;
|
private final static int MAX_AUTHORS_LENGTH = 60;
|
||||||
|
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@ -25,7 +28,7 @@ public class GrantDto {
|
|||||||
private Grant.GrantStatus status;
|
private Grant.GrantStatus status;
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
private String comment;
|
private String comment;
|
||||||
private String applicationFileName;
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
private ProjectDto project;
|
private ProjectDto project;
|
||||||
private Set<Integer> authorIds;
|
private Set<Integer> authorIds;
|
||||||
private Set<UserDto> authors;
|
private Set<UserDto> authors;
|
||||||
@ -33,8 +36,10 @@ public class GrantDto {
|
|||||||
private boolean wasLeader;
|
private boolean wasLeader;
|
||||||
private boolean hasAge;
|
private boolean hasAge;
|
||||||
private boolean hasDegree;
|
private boolean hasDegree;
|
||||||
|
private boolean hasBAKPapers;
|
||||||
|
private boolean hasScopusPapers;
|
||||||
private List<Integer> paperIds = new ArrayList<>();
|
private List<Integer> paperIds = new ArrayList<>();
|
||||||
private List<Paper> papers = new ArrayList<>();
|
private List<PaperDto> papers = new ArrayList<>();
|
||||||
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
||||||
|
|
||||||
public GrantDto() {
|
public GrantDto() {
|
||||||
@ -47,22 +52,24 @@ public class GrantDto {
|
|||||||
@JsonProperty("status") Grant.GrantStatus status,
|
@JsonProperty("status") Grant.GrantStatus status,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("project") ProjectDto project,
|
@JsonProperty("project") ProjectDto project,
|
||||||
@JsonProperty("authorIds") Set<Integer> authorIds,
|
@JsonProperty("authorIds") Set<Integer> authorIds,
|
||||||
@JsonProperty("authors") Set<UserDto> authors,
|
@JsonProperty("authors") Set<UserDto> authors,
|
||||||
@JsonProperty("leader") Integer leaderId,
|
@JsonProperty("leaderId") Integer leaderId,
|
||||||
@JsonProperty("wasLeader") boolean wasLeader,
|
@JsonProperty("wasLeader") boolean wasLeader,
|
||||||
@JsonProperty("hasAge") boolean hasAge,
|
@JsonProperty("hasAge") boolean hasAge,
|
||||||
@JsonProperty("hasDegree") boolean hasDegree,
|
@JsonProperty("hasDegree") boolean hasDegree,
|
||||||
@JsonProperty("paperIds") List<Integer> paperIds,
|
@JsonProperty("paperIds") List<Integer> paperIds,
|
||||||
@JsonProperty("papers") List<Paper> papers) {
|
@JsonProperty("papers") List<PaperDto> papers) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.applicationFileName = null;
|
this.files = files;
|
||||||
this.project = project;
|
this.project = project;
|
||||||
|
this.authorIds = authorIds;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
this.leaderId = leaderId;
|
this.leaderId = leaderId;
|
||||||
this.wasLeader = wasLeader;
|
this.wasLeader = wasLeader;
|
||||||
@ -78,8 +85,8 @@ public class GrantDto {
|
|||||||
this.status = grant.getStatus();
|
this.status = grant.getStatus();
|
||||||
this.deadlines = grant.getDeadlines();
|
this.deadlines = grant.getDeadlines();
|
||||||
this.comment = grant.getComment();
|
this.comment = grant.getComment();
|
||||||
|
this.files = convert(grant.getFiles(), FileDataDto::new);
|
||||||
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
||||||
this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName();
|
|
||||||
this.authorIds = convert(grant.getAuthors(), user -> user.getId());
|
this.authorIds = convert(grant.getAuthors(), user -> user.getId());
|
||||||
this.authors = convert(grant.getAuthors(), UserDto::new);
|
this.authors = convert(grant.getAuthors(), UserDto::new);
|
||||||
this.leaderId = grant.getLeader().getId();
|
this.leaderId = grant.getLeader().getId();
|
||||||
@ -87,7 +94,13 @@ public class GrantDto {
|
|||||||
this.hasAge = false;
|
this.hasAge = false;
|
||||||
this.hasDegree = false;
|
this.hasDegree = false;
|
||||||
this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
|
this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
|
||||||
this.papers = grant.getPapers();
|
this.papers = convert(grant.getPapers(), PaperDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto(String grantTitle, Date deadLineDate) {
|
||||||
|
this.title = grantTitle;
|
||||||
|
deadlines.add(new Deadline(deadLineDate, "Окончание приёма заявок"));
|
||||||
|
status = Grant.GrantStatus.LOADED_FROM_KIAS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -130,6 +143,14 @@ public class GrantDto {
|
|||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FileDataDto> getFiles() {
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFiles(List<FileDataDto> files) {
|
||||||
|
this.files = files;
|
||||||
|
}
|
||||||
|
|
||||||
public ProjectDto getProject() {
|
public ProjectDto getProject() {
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
@ -138,14 +159,6 @@ public class GrantDto {
|
|||||||
this.project = project;
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getApplicationFileName() {
|
|
||||||
return applicationFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplicationFileName(String applicationFileName) {
|
|
||||||
this.applicationFileName = applicationFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getAuthorIds() {
|
public Set<Integer> getAuthorIds() {
|
||||||
return authorIds;
|
return authorIds;
|
||||||
}
|
}
|
||||||
@ -209,11 +222,11 @@ public class GrantDto {
|
|||||||
this.paperIds = paperIds;
|
this.paperIds = paperIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getPapers() {
|
public List<PaperDto> getPapers() {
|
||||||
return papers;
|
return papers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPapers(List<Paper> papers) {
|
public void setPapers(List<PaperDto> papers) {
|
||||||
this.papers = papers;
|
this.papers = papers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,4 +237,20 @@ public class GrantDto {
|
|||||||
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
||||||
this.removedDeadlineIds = removedDeadlineIds;
|
this.removedDeadlineIds = removedDeadlineIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isHasBAKPapers() {
|
||||||
|
return hasBAKPapers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHasBAKPapers(boolean hasBAKPapers) {
|
||||||
|
this.hasBAKPapers = hasBAKPapers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasScopusPapers() {
|
||||||
|
return hasScopusPapers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHasScopusPapers(boolean hasScopusPapers) {
|
||||||
|
this.hasScopusPapers = hasScopusPapers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
50
src/main/java/ru/ulstu/grant/page/KiasPage.java
Normal file
50
src/main/java/ru/ulstu/grant/page/KiasPage.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package ru.ulstu.grant.page;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class KiasPage {
|
||||||
|
private final static String KIAS_GRANT_DATE_FORMAT = "dd.MM.yyyy HH:mm";
|
||||||
|
private WebDriver driver;
|
||||||
|
|
||||||
|
public KiasPage(WebDriver webDriver) {
|
||||||
|
this.driver = webDriver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean goToNextPage() {
|
||||||
|
try {
|
||||||
|
if (driver.findElements(By.id("js-ctrlNext")).size() > 0) {
|
||||||
|
driver.findElement(By.id("js-ctrlNext")).click();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getPageOfGrants() {
|
||||||
|
WebElement listContest = driver.findElement(By.tagName("tBody"));
|
||||||
|
List<WebElement> grants = listContest.findElements(By.cssSelector("tr.tr"));
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrantTitle(WebElement grant) {
|
||||||
|
return grant.findElement(By.cssSelector("td.tertiary")).findElement(By.tagName("a")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date parseDeadLineDate(WebElement grantElement) throws ParseException {
|
||||||
|
String deadlineDate = getFirstDeadline(grantElement); //10.06.2019 23:59
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat(KIAS_GRANT_DATE_FORMAT);
|
||||||
|
return formatter.parse(deadlineDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFirstDeadline(WebElement grantElement) {
|
||||||
|
return grantElement.findElement(By.xpath("./td[5]")).getText();
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,23 @@
|
|||||||
package ru.ulstu.grant.repository;
|
package ru.ulstu.grant.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
|
import ru.ulstu.name.BaseRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface GrantRepository extends JpaRepository<Grant, Integer> {
|
public interface GrantRepository extends JpaRepository<Grant, Integer>, BaseRepository {
|
||||||
|
|
||||||
List<Grant> findByStatus(Grant.GrantStatus status);
|
List<Grant> findByStatus(Grant.GrantStatus status);
|
||||||
|
|
||||||
|
Grant findByTitle(String title);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Query("SELECT title FROM Grant g WHERE (g.title = :name) AND (:id IS NULL OR g.id != :id) ")
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
|
||||||
|
@Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')")
|
||||||
|
List<Grant> findAllActive();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
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 TEMPLATE_LEADER_CHANGED = "grantLeaderChangeNotification";
|
||||||
|
|
||||||
|
private final static String TITLE_DEADLINE = "Приближается дедлайн гранта: %s";
|
||||||
|
private final static String TITLE_CREATE = "Создан грант: %s";
|
||||||
|
private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s";
|
||||||
|
private final static String TITLE_LEADER_CHANGED = "Изменился руководитель гранта: %s";
|
||||||
|
|
||||||
|
private final MailService mailService;
|
||||||
|
|
||||||
|
public GrantNotificationService(MailService mailService) {
|
||||||
|
this.mailService = mailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendDeadlineNotifications(List<Grant> 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<String, Object> variables = ImmutableMap.of("grant", grant);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Grant grant) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("grant", grant);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_CREATE, String.format(TITLE_CREATE, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAuthorsChangeNotification(Grant grant, Set<User> oldAuthors) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("grant", grant, "oldAuthors", oldAuthors);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_AUTHORS_CHANGED, String.format(TITLE_AUTHORS_CHANGED, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendLeaderChangeNotification(Grant grant, User oldLeader) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("grant", grant, "oldLeader", oldLeader);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_LEADER_CHANGED, String.format(TITLE_LEADER_CHANGED, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendForAllAuthors(Map<String, Object> variables, Grant grant, String template, String title) {
|
||||||
|
Set<User> allAuthors = grant.getAuthors();
|
||||||
|
allAuthors.forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title));
|
||||||
|
mailService.sendEmailFromTemplate(variables, grant.getLeader(), template, title);
|
||||||
|
}
|
||||||
|
}
|
44
src/main/java/ru/ulstu/grant/service/GrantScheduler.java
Normal file
44
src/main/java/ru/ulstu/grant/service/GrantScheduler.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GrantScheduler {
|
||||||
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(GrantScheduler.class);
|
||||||
|
|
||||||
|
private final GrantNotificationService grantNotificationService;
|
||||||
|
private final GrantService grantService;
|
||||||
|
|
||||||
|
public GrantScheduler(GrantNotificationService grantNotificationService,
|
||||||
|
GrantService grantService) {
|
||||||
|
this.grantNotificationService = grantNotificationService;
|
||||||
|
this.grantService = grantService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
||||||
|
public void checkDeadlineBeforeWeek() {
|
||||||
|
log.debug("GrantScheduler.checkDeadlineBeforeWeek started");
|
||||||
|
grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
|
log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
|
||||||
|
public void loadGrantsFromKias() {
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias started");
|
||||||
|
try {
|
||||||
|
grantService.createFromKias();
|
||||||
|
} catch (ParseException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias finished");
|
||||||
|
}
|
||||||
|
}
|
@ -1,35 +1,47 @@
|
|||||||
package ru.ulstu.grant.service;
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
import ru.ulstu.grant.repository.GrantRepository;
|
import ru.ulstu.grant.repository.GrantRepository;
|
||||||
|
import ru.ulstu.name.BaseService;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.project.service.ProjectService;
|
import ru.ulstu.project.service.ProjectService;
|
||||||
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GrantService {
|
public class GrantService extends BaseService {
|
||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
private final Logger log = LoggerFactory.getLogger(GrantService.class);
|
||||||
|
|
||||||
private final GrantRepository grantRepository;
|
private final GrantRepository grantRepository;
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
@ -37,19 +49,29 @@ public class GrantService {
|
|||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final PaperService paperService;
|
private final PaperService paperService;
|
||||||
|
private final EventService eventService;
|
||||||
|
private final GrantNotificationService grantNotificationService;
|
||||||
|
private final KiasService kiasService;
|
||||||
|
|
||||||
public GrantService(GrantRepository grantRepository,
|
public GrantService(GrantRepository grantRepository,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
ProjectService projectService,
|
ProjectService projectService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
PaperService paperService) {
|
PaperService paperService,
|
||||||
|
EventService eventService,
|
||||||
|
GrantNotificationService grantNotificationService,
|
||||||
|
KiasService kiasService) {
|
||||||
this.grantRepository = grantRepository;
|
this.grantRepository = grantRepository;
|
||||||
|
this.kiasService = kiasService;
|
||||||
|
this.baseRepository = grantRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.projectService = projectService;
|
this.projectService = projectService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.paperService = paperService;
|
this.paperService = paperService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
this.grantNotificationService = grantNotificationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Grant> findAll() {
|
public List<Grant> findAll() {
|
||||||
@ -57,9 +79,7 @@ public class GrantService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<GrantDto> findAllDto() {
|
public List<GrantDto> findAllDto() {
|
||||||
List<GrantDto> grants = convert(findAll(), GrantDto::new);
|
return convert(findAll(), GrantDto::new);
|
||||||
grants.forEach(grantDto -> grantDto.setTitle(StringUtils.abbreviate(grantDto.getTitle(), MAX_DISPLAY_SIZE)));
|
|
||||||
return grants;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrantDto findOneDto(Integer id) {
|
public GrantDto findOneDto(Integer id) {
|
||||||
@ -70,6 +90,8 @@ public class GrantService {
|
|||||||
public Integer create(GrantDto grantDto) throws IOException {
|
public Integer create(GrantDto grantDto) throws IOException {
|
||||||
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
||||||
newGrant = grantRepository.save(newGrant);
|
newGrant = grantRepository.save(newGrant);
|
||||||
|
eventService.createFromGrant(newGrant);
|
||||||
|
grantNotificationService.sendCreateNotification(newGrant);
|
||||||
return newGrant.getId();
|
return newGrant.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,9 +103,9 @@ public class GrantService {
|
|||||||
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
||||||
}
|
}
|
||||||
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
||||||
if (grantDto.getApplicationFileName() != null) {
|
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
|
||||||
grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName()));
|
.filter(f -> !f.isDeleted())
|
||||||
}
|
.collect(toList())));
|
||||||
grant.getAuthors().clear();
|
grant.getAuthors().clear();
|
||||||
if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) {
|
if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) {
|
||||||
grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds)));
|
grantDto.getAuthorIds().forEach(authorIds -> grant.getAuthors().add(userService.findById(authorIds)));
|
||||||
@ -106,20 +128,36 @@ public class GrantService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(GrantDto grantDto) throws IOException {
|
public Integer update(GrantDto grantDto) throws IOException {
|
||||||
Grant grant = grantRepository.findOne(grantDto.getId());
|
Grant grant = grantRepository.findOne(grantDto.getId());
|
||||||
if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) {
|
Set<User> oldAuthors = new HashSet<>(grant.getAuthors());
|
||||||
fileService.deleteFile(grant.getApplication());
|
User oldLeader = grant.getLeader();
|
||||||
|
for (FileDataDto file : grantDto.getFiles().stream()
|
||||||
|
.filter(f -> f.isDeleted() && f.getId() != null)
|
||||||
|
.collect(toList())) {
|
||||||
|
fileService.delete(file.getId());
|
||||||
}
|
}
|
||||||
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
||||||
grantRepository.save(copyFromDto(grant, grantDto));
|
grantRepository.save(copyFromDto(grant, grantDto));
|
||||||
|
|
||||||
|
grant.getAuthors().forEach(author -> {
|
||||||
|
if (!oldAuthors.contains(author)) {
|
||||||
|
grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
oldAuthors.forEach(oldAuthor -> {
|
||||||
|
if (!grant.getAuthors().contains(oldAuthor)) {
|
||||||
|
grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (grant.getLeader() != oldLeader) {
|
||||||
|
grantNotificationService.sendLeaderChangeNotification(grant, oldLeader);
|
||||||
|
}
|
||||||
|
eventService.updateGrantDeadlines(grant);
|
||||||
return grant.getId();
|
return grant.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer grantId) throws IOException {
|
public void delete(Integer grantId) throws IOException {
|
||||||
Grant grant = grantRepository.findOne(grantId);
|
Grant grant = grantRepository.findOne(grantId);
|
||||||
if (grant.getApplication() != null) {
|
|
||||||
fileService.deleteFile(grant.getApplication());
|
|
||||||
}
|
|
||||||
grantRepository.delete(grant);
|
grantRepository.delete(grant);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,42 +177,100 @@ public class GrantService {
|
|||||||
grant.setLeader(user);
|
grant.setLeader(user);
|
||||||
grant.getPapers().add(paper);
|
grant.getPapers().add(paper);
|
||||||
grant = grantRepository.save(grant);
|
grant = grantRepository.save(grant);
|
||||||
|
|
||||||
|
eventService.createFromGrant(grant);
|
||||||
|
grantNotificationService.sendCreateNotification(grant);
|
||||||
|
|
||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(GrantDto grantDto) throws IOException {
|
public boolean save(GrantDto grantDto, Errors errors) throws IOException {
|
||||||
|
grantDto.setName(grantDto.getTitle());
|
||||||
|
filterEmptyDeadlines(grantDto);
|
||||||
|
checkEmptyDeadlines(grantDto, errors);
|
||||||
|
checkEmptyLeader(grantDto, errors);
|
||||||
|
checkUniqueName(grantDto, errors, grantDto.getId(), "title", "Грант с таким именем уже существует");
|
||||||
|
if (errors.hasErrors()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (isEmpty(grantDto.getId())) {
|
if (isEmpty(grantDto.getId())) {
|
||||||
create(grantDto);
|
create(grantDto);
|
||||||
} else {
|
} else {
|
||||||
update(grantDto);
|
update(grantDto);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean saveFromKias(GrantDto grantDto) throws IOException {
|
||||||
|
grantDto.setName(grantDto.getTitle());
|
||||||
|
String title = checkUniqueName(grantDto, grantDto.getId()); //проверка уникальности имени
|
||||||
|
if (title != null) {
|
||||||
|
Grant grantFromDB = grantRepository.findByTitle(title); //грант с таким же названием из бд
|
||||||
|
if (checkSameDeadline(grantDto, grantFromDB.getId())) { //если дедайны тоже совпадают
|
||||||
|
return false;
|
||||||
|
} else { //иначе грант уже был в системе, но в другом году, поэтому надо создать
|
||||||
|
create(grantDto);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else { //иначе такого гранта ещё нет, поэтому надо создать
|
||||||
|
create(grantDto);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEmptyLeader(GrantDto grantDto, Errors errors) {
|
||||||
|
if (grantDto.getLeaderId().equals(-1)) {
|
||||||
|
errors.rejectValue("leaderId", "errorCode", "Укажите руководителя");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEmptyDeadlines(GrantDto grantDto, Errors errors) {
|
||||||
|
if (grantDto.getDeadlines().isEmpty()) {
|
||||||
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пусто");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkSameDeadline(GrantDto grantDto, Integer id) {
|
||||||
|
Date date = grantDto.getDeadlines().get(0).getDate(); //дата с сайта киас
|
||||||
|
if (deadlineService.findByGrantIdAndDate(id, date).compareTo(date) == 0) { //если есть такая строка с датой
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getGrantAuthors(GrantDto grantDto) {
|
public List<User> getGrantAuthors(GrantDto grantDto) {
|
||||||
List<User> filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree());
|
List<User> filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree());
|
||||||
if (grantDto.isWasLeader()) {
|
if (grantDto.isWasLeader()) {
|
||||||
filteredUsers = filteredUsers
|
filteredUsers = checkContains(filteredUsers, getCompletedGrantLeaders());
|
||||||
.stream()
|
}
|
||||||
.filter(getCompletedGrantLeaders()::contains)
|
if (grantDto.isHasBAKPapers()) {
|
||||||
.collect(Collectors.toList());
|
filteredUsers = checkContains(filteredUsers, getBAKAuthors());
|
||||||
|
}
|
||||||
|
if (grantDto.isHasScopusPapers()) {
|
||||||
|
filteredUsers = checkContains(filteredUsers, getScopusAuthors());
|
||||||
}
|
}
|
||||||
return filteredUsers;
|
return filteredUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<User> checkContains(List<User> filteredUsers, List<User> checkUsers) {
|
||||||
|
return filteredUsers.stream()
|
||||||
|
.filter(checkUsers::contains)
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
private List<User> getCompletedGrantLeaders() {
|
private List<User> getCompletedGrantLeaders() {
|
||||||
return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED)
|
return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED)
|
||||||
.stream()
|
.stream()
|
||||||
.map(Grant::getLeader)
|
.map(Grant::getLeader)
|
||||||
.collect(Collectors.toList());
|
.collect(toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getGrantPapers(List<Integer> paperIds) {
|
public List<PaperDto> getGrantPapers(List<Integer> paperIds) {
|
||||||
return paperService.findAllSelect(paperIds);
|
return paperService.findAllSelect(paperIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getAllPapers() {
|
public List<PaperDto> getAllUncompletedPapers() {
|
||||||
return paperService.findAll();
|
return paperService.findAllNotCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attachPaper(GrantDto grantDto) {
|
public void attachPaper(GrantDto grantDto) {
|
||||||
@ -193,4 +289,51 @@ public class GrantService {
|
|||||||
grantDto.getDeadlines().remove((int) deadlineId);
|
grantDto.getDeadlines().remove((int) deadlineId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<User> getCompletedPapersAuthors(Paper.PaperType type) {
|
||||||
|
List<Paper> papers = paperService.findAllCompletedByType(type);
|
||||||
|
return papers.stream()
|
||||||
|
.filter(paper -> paper.getAuthors() != null)
|
||||||
|
.flatMap(paper -> paper.getAuthors().stream())
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<User> getBAKAuthors() {
|
||||||
|
return getCompletedPapersAuthors(Paper.PaperType.VAK)
|
||||||
|
.stream()
|
||||||
|
.distinct()
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<User> getScopusAuthors() {
|
||||||
|
List<User> authors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS);
|
||||||
|
return authors
|
||||||
|
.stream()
|
||||||
|
.filter(author -> Collections.frequency(authors, author) > 3)
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void filterEmptyDeadlines(GrantDto grantDto) {
|
||||||
|
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
||||||
|
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void createFromKias() throws IOException, ParseException {
|
||||||
|
for (GrantDto grantDto : kiasService.getNewGrantsDto()) {
|
||||||
|
if (saveFromKias(grantDto)) {
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias new grant was loaded");
|
||||||
|
} else {
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias grant wasn't loaded, cause it's already exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> findAllActiveDto() {
|
||||||
|
return convert(findAllActive(), GrantDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Grant> findAllActive() {
|
||||||
|
return grantRepository.findAllActive();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
92
src/main/java/ru/ulstu/grant/service/KiasService.java
Normal file
92
src/main/java/ru/ulstu/grant/service/KiasService.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.grant.page.KiasPage;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class KiasService {
|
||||||
|
private final static String BASE_URL = "https://www.rfbr.ru/rffi/ru/contest_search?CONTEST_STATUS_ID=%s&CONTEST_TYPE=%s&CONTEST_YEAR=%s";
|
||||||
|
private final static String CONTEST_STATUS_ID = "1";
|
||||||
|
private final static String CONTEST_TYPE = "-1";
|
||||||
|
|
||||||
|
private final static String DRIVER_LOCATION = "drivers/%s";
|
||||||
|
private final static String WINDOWS_DRIVER = "chromedriver.exe";
|
||||||
|
private final static String LINUX_DRIVER = "chromedriver";
|
||||||
|
private final static String DRIVER_TYPE = "webdriver.chrome.driver";
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
public KiasService(UserService userService) {
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> getNewGrantsDto() throws ParseException {
|
||||||
|
WebDriver webDriver = getDriver();
|
||||||
|
Integer leaderId = userService.findOneByLoginIgnoreCase("admin").getId();
|
||||||
|
List<GrantDto> grants = new ArrayList<>();
|
||||||
|
for (Integer year : generateGrantYears()) {
|
||||||
|
webDriver.get(String.format(BASE_URL, CONTEST_STATUS_ID, CONTEST_TYPE, year));
|
||||||
|
grants.addAll(getKiasGrants(webDriver));
|
||||||
|
}
|
||||||
|
grants.forEach(grantDto -> grantDto.setLeaderId(leaderId));
|
||||||
|
webDriver.quit();
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> getKiasGrants(WebDriver webDriver) throws ParseException {
|
||||||
|
List<GrantDto> newGrants = new ArrayList<>();
|
||||||
|
KiasPage kiasPage = new KiasPage(webDriver);
|
||||||
|
do {
|
||||||
|
newGrants.addAll(getGrantsFromPage(kiasPage));
|
||||||
|
} while (kiasPage.goToNextPage()); //проверка существования следующей страницы с грантами
|
||||||
|
return newGrants;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<GrantDto> getGrantsFromPage(KiasPage kiasPage) throws ParseException {
|
||||||
|
List<GrantDto> grants = new ArrayList<>();
|
||||||
|
for (WebElement grantElement : kiasPage.getPageOfGrants()) {
|
||||||
|
GrantDto grantDto = new GrantDto(
|
||||||
|
kiasPage.getGrantTitle(grantElement),
|
||||||
|
kiasPage.parseDeadLineDate(grantElement));
|
||||||
|
grants.add(grantDto);
|
||||||
|
}
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> generateGrantYears() {
|
||||||
|
return Arrays.asList(Calendar.getInstance().get(Calendar.YEAR),
|
||||||
|
Calendar.getInstance().get(Calendar.YEAR) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private WebDriver getDriver() {
|
||||||
|
System.setProperty(DRIVER_TYPE, getDriverExecutablePath());
|
||||||
|
final ChromeOptions chromeOptions = new ChromeOptions();
|
||||||
|
chromeOptions.addArguments("--headless");
|
||||||
|
return new ChromeDriver(chromeOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDriverExecutablePath() {
|
||||||
|
return KiasService.class.getClassLoader().getResource(
|
||||||
|
String.format(DRIVER_LOCATION, getDriverExecutable(isWindows()))).getFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDriverExecutable(boolean isWindows) {
|
||||||
|
return isWindows ? WINDOWS_DRIVER : LINUX_DRIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isWindows() {
|
||||||
|
return System.getProperty("os.name").toLowerCase().contains("windows");
|
||||||
|
}
|
||||||
|
}
|
7
src/main/java/ru/ulstu/name/BaseRepository.java
Normal file
7
src/main/java/ru/ulstu/name/BaseRepository.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package ru.ulstu.name;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
public interface BaseRepository {
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
}
|
23
src/main/java/ru/ulstu/name/BaseService.java
Normal file
23
src/main/java/ru/ulstu/name/BaseService.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package ru.ulstu.name;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public abstract class BaseService {
|
||||||
|
|
||||||
|
public BaseRepository baseRepository;
|
||||||
|
|
||||||
|
public void checkUniqueName(NameContainer nameContainer, Errors errors, Integer id, String checkField, String errorMessage) {
|
||||||
|
if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) {
|
||||||
|
errors.rejectValue(checkField, "errorCode", errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String checkUniqueName(NameContainer nameContainer, Integer id) {
|
||||||
|
if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) {
|
||||||
|
return baseRepository.findByNameAndNotId(nameContainer.getName(), id);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
14
src/main/java/ru/ulstu/name/NameContainer.java
Normal file
14
src/main/java/ru/ulstu/name/NameContainer.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package ru.ulstu.name;
|
||||||
|
|
||||||
|
public abstract class NameContainer {
|
||||||
|
|
||||||
|
private String name = "";
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
@ -13,9 +13,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import ru.ulstu.conference.service.ConferenceService;
|
import ru.ulstu.conference.service.ConferenceService;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.paper.model.AutoCompleteData;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.model.PaperListDto;
|
import ru.ulstu.paper.model.PaperListDto;
|
||||||
|
import ru.ulstu.paper.model.ReferenceDto;
|
||||||
import ru.ulstu.paper.service.LatexService;
|
import ru.ulstu.paper.service.LatexService;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
@ -103,6 +105,15 @@ public class PaperController {
|
|||||||
return "/papers/paper";
|
return "/papers/paper";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/paper", params = "addReference")
|
||||||
|
public String addReference(@Valid PaperDto paperDto, Errors errors) {
|
||||||
|
if (errors.hasErrors()) {
|
||||||
|
return "/papers/paper";
|
||||||
|
}
|
||||||
|
paperDto.getReferences().add(new ReferenceDto());
|
||||||
|
return "/papers/paper";
|
||||||
|
}
|
||||||
|
|
||||||
@ModelAttribute("allStatuses")
|
@ModelAttribute("allStatuses")
|
||||||
public List<Paper.PaperStatus> getPaperStatuses() {
|
public List<Paper.PaperStatus> getPaperStatuses() {
|
||||||
return paperService.getPaperStatuses();
|
return paperService.getPaperStatuses();
|
||||||
@ -127,6 +138,16 @@ public class PaperController {
|
|||||||
return years;
|
return years;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("allFormatStandards")
|
||||||
|
public List<ReferenceDto.FormatStandard> getFormatStandards() {
|
||||||
|
return paperService.getFormatStandards();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("allReferenceTypes")
|
||||||
|
public List<ReferenceDto.ReferenceType> getReferenceTypes() {
|
||||||
|
return paperService.getReferenceTypes();
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/generatePdf")
|
@PostMapping("/generatePdf")
|
||||||
public ResponseEntity<byte[]> getPdfFile(PaperDto paper) throws IOException, InterruptedException {
|
public ResponseEntity<byte[]> getPdfFile(PaperDto paper) throws IOException, InterruptedException {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
@ -135,6 +156,16 @@ public class PaperController {
|
|||||||
return new ResponseEntity<>(latexService.generatePdfFromLatexFile(paper), headers, HttpStatus.OK);
|
return new ResponseEntity<>(latexService.generatePdfFromLatexFile(paper), headers, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getFormattedReferences")
|
||||||
|
public ResponseEntity<String> getFormattedReferences(PaperDto paperDto) {
|
||||||
|
return new ResponseEntity<>(paperService.getFormattedReferences(paperDto), new HttpHeaders(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("autocompleteData")
|
||||||
|
public AutoCompleteData getAutocompleteData() {
|
||||||
|
return paperService.getAutoCompleteData();
|
||||||
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(PaperDto paperDto) {
|
private void filterEmptyDeadlines(PaperDto paperDto) {
|
||||||
paperDto.setDeadlines(paperDto.getDeadlines().stream()
|
paperDto.setDeadlines(paperDto.getDeadlines().stream()
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||||
|
43
src/main/java/ru/ulstu/paper/model/AutoCompleteData.java
Normal file
43
src/main/java/ru/ulstu/paper/model/AutoCompleteData.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AutoCompleteData {
|
||||||
|
private List<String> authors = new ArrayList<>();
|
||||||
|
private List<String> publicationTitles = new ArrayList<>();
|
||||||
|
private List<String> publishers = new ArrayList<>();
|
||||||
|
private List<String> journalOrCollectionTitles = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<String> getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(List<String> authors) {
|
||||||
|
this.authors = authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPublicationTitles() {
|
||||||
|
return publicationTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationTitles(List<String> publicationTitles) {
|
||||||
|
this.publicationTitles = publicationTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPublishers() {
|
||||||
|
return publishers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublishers(List<String> publishers) {
|
||||||
|
this.publishers = publishers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getJournalOrCollectionTitles() {
|
||||||
|
return journalOrCollectionTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJournalOrCollectionTitles(List<String> journalOrCollectionTitles) {
|
||||||
|
this.journalOrCollectionTitles = journalOrCollectionTitles;
|
||||||
|
}
|
||||||
|
}
|
@ -3,10 +3,12 @@ package ru.ulstu.paper.model;
|
|||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.hibernate.validator.constraints.NotBlank;
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.core.model.UserContainer;
|
import ru.ulstu.core.model.UserContainer;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.file.model.FileData;
|
||||||
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.timeline.model.Event;
|
import ru.ulstu.timeline.model.Event;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
@ -27,6 +29,7 @@ import java.util.Comparator;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -114,6 +117,17 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
@Column(name = "latex_text")
|
@Column(name = "latex_text")
|
||||||
private String latexText;
|
private String latexText;
|
||||||
|
|
||||||
|
@ManyToMany(mappedBy = "papers")
|
||||||
|
private List<Conference> conferences;
|
||||||
|
|
||||||
|
@ManyToMany(mappedBy = "papers")
|
||||||
|
private List<Grant> grants;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "paper_id", unique = true)
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
|
private List<Reference> references = new ArrayList<>();
|
||||||
|
|
||||||
public PaperStatus getStatus() {
|
public PaperStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -218,11 +232,35 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
this.latexText = latexText;
|
this.latexText = latexText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Conference> getConferences() {
|
||||||
|
return conferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConferences(List<Conference> conferences) {
|
||||||
|
this.conferences = conferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Grant> getGrants() {
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrants(List<Grant> grants) {
|
||||||
|
this.grants = grants;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<User> getUsers() {
|
public Set<User> getUsers() {
|
||||||
return getAuthors();
|
return getAuthors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Reference> getReferences() {
|
||||||
|
return references;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferences(List<Reference> references) {
|
||||||
|
this.references = references;
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<Deadline> getNextDeadline() {
|
public Optional<Deadline> getNextDeadline() {
|
||||||
return deadlines
|
return deadlines
|
||||||
.stream()
|
.stream()
|
||||||
@ -240,4 +278,36 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
.findAny()
|
.findAny()
|
||||||
.isPresent();
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ public class PaperDto {
|
|||||||
private Set<UserDto> authors;
|
private Set<UserDto> authors;
|
||||||
private Integer filterAuthorId;
|
private Integer filterAuthorId;
|
||||||
private String latexText;
|
private String latexText;
|
||||||
|
private List<ReferenceDto> references = new ArrayList<>();
|
||||||
|
private ReferenceDto.FormatStandard formatStandard = ReferenceDto.FormatStandard.GOST;
|
||||||
|
|
||||||
public PaperDto() {
|
public PaperDto() {
|
||||||
deadlines.add(new Deadline());
|
deadlines.add(new Deadline());
|
||||||
@ -57,7 +59,9 @@ public class PaperDto {
|
|||||||
@JsonProperty("locked") Boolean locked,
|
@JsonProperty("locked") Boolean locked,
|
||||||
@JsonProperty("files") List<FileDataDto> files,
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("authorIds") Set<Integer> authorIds,
|
@JsonProperty("authorIds") Set<Integer> authorIds,
|
||||||
@JsonProperty("authors") Set<UserDto> authors) {
|
@JsonProperty("authors") Set<UserDto> authors,
|
||||||
|
@JsonProperty("references") List<ReferenceDto> references,
|
||||||
|
@JsonProperty("formatStandard") ReferenceDto.FormatStandard formatStandard) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -71,6 +75,8 @@ public class PaperDto {
|
|||||||
this.locked = locked;
|
this.locked = locked;
|
||||||
this.files = files;
|
this.files = files;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
|
this.references = references;
|
||||||
|
this.formatStandard = formatStandard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaperDto(Paper paper) {
|
public PaperDto(Paper paper) {
|
||||||
@ -88,6 +94,7 @@ public class PaperDto {
|
|||||||
this.files = convert(paper.getFiles(), FileDataDto::new);
|
this.files = convert(paper.getFiles(), FileDataDto::new);
|
||||||
this.authorIds = convert(paper.getAuthors(), user -> user.getId());
|
this.authorIds = convert(paper.getAuthors(), user -> user.getId());
|
||||||
this.authors = convert(paper.getAuthors(), UserDto::new);
|
this.authors = convert(paper.getAuthors(), UserDto::new);
|
||||||
|
this.references = convert(paper.getReferences(), ReferenceDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -216,4 +223,20 @@ public class PaperDto {
|
|||||||
public void setFilterAuthorId(Integer filterAuthorId) {
|
public void setFilterAuthorId(Integer filterAuthorId) {
|
||||||
this.filterAuthorId = filterAuthorId;
|
this.filterAuthorId = filterAuthorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ReferenceDto> getReferences() {
|
||||||
|
return references;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferences(List<ReferenceDto> references) {
|
||||||
|
this.references = references;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto.FormatStandard getFormatStandard() {
|
||||||
|
return formatStandard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormatStandard(ReferenceDto.FormatStandard formatStandard) {
|
||||||
|
this.formatStandard = formatStandard;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
88
src/main/java/ru/ulstu/paper/model/Reference.java
Normal file
88
src/main/java/ru/ulstu/paper/model/Reference.java
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Reference extends BaseEntity {
|
||||||
|
|
||||||
|
private String authors;
|
||||||
|
|
||||||
|
@Column(name = "publication_title")
|
||||||
|
private String publicationTitle;
|
||||||
|
|
||||||
|
@Column(name = "publication_year")
|
||||||
|
private Integer publicationYear;
|
||||||
|
|
||||||
|
private String publisher;
|
||||||
|
|
||||||
|
private String pages;
|
||||||
|
|
||||||
|
@Column(name = "journal_or_collection_title")
|
||||||
|
private String journalOrCollectionTitle;
|
||||||
|
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
@Column(name = "reference_type")
|
||||||
|
private ReferenceDto.ReferenceType referenceType = ReferenceDto.ReferenceType.ARTICLE;
|
||||||
|
|
||||||
|
public String getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(String authors) {
|
||||||
|
this.authors = authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublicationTitle() {
|
||||||
|
return publicationTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationTitle(String publicationTitle) {
|
||||||
|
this.publicationTitle = publicationTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPublicationYear() {
|
||||||
|
return publicationYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationYear(Integer publicationYear) {
|
||||||
|
this.publicationYear = publicationYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublisher() {
|
||||||
|
return publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublisher(String publisher) {
|
||||||
|
this.publisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPages() {
|
||||||
|
return pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPages(String pages) {
|
||||||
|
this.pages = pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJournalOrCollectionTitle() {
|
||||||
|
return journalOrCollectionTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJournalOrCollectionTitle(String journalOrCollectionTitle) {
|
||||||
|
this.journalOrCollectionTitle = journalOrCollectionTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto.ReferenceType getReferenceType() {
|
||||||
|
return referenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferenceType(ReferenceDto.ReferenceType referenceType) {
|
||||||
|
this.referenceType = referenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -34,6 +34,7 @@ public class ReferenceDto {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
private String authors;
|
private String authors;
|
||||||
private String publicationTitle;
|
private String publicationTitle;
|
||||||
private Integer publicationYear;
|
private Integer publicationYear;
|
||||||
@ -42,9 +43,11 @@ public class ReferenceDto {
|
|||||||
private String journalOrCollectionTitle;
|
private String journalOrCollectionTitle;
|
||||||
private ReferenceType referenceType;
|
private ReferenceType referenceType;
|
||||||
private FormatStandard formatStandard;
|
private FormatStandard formatStandard;
|
||||||
|
private boolean deleted;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public ReferenceDto(
|
public ReferenceDto(
|
||||||
|
@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("authors") String authors,
|
@JsonProperty("authors") String authors,
|
||||||
@JsonProperty("publicationTitle") String publicationTitle,
|
@JsonProperty("publicationTitle") String publicationTitle,
|
||||||
@JsonProperty("publicationYear") Integer publicationYear,
|
@JsonProperty("publicationYear") Integer publicationYear,
|
||||||
@ -52,7 +55,9 @@ public class ReferenceDto {
|
|||||||
@JsonProperty("pages") String pages,
|
@JsonProperty("pages") String pages,
|
||||||
@JsonProperty("journalOrCollectionTitle") String journalOrCollectionTitle,
|
@JsonProperty("journalOrCollectionTitle") String journalOrCollectionTitle,
|
||||||
@JsonProperty("referenceType") ReferenceType referenceType,
|
@JsonProperty("referenceType") ReferenceType referenceType,
|
||||||
@JsonProperty("formatStandard") FormatStandard formatStandard) {
|
@JsonProperty("formatStandard") FormatStandard formatStandard,
|
||||||
|
@JsonProperty("isDeleted") boolean deleted) {
|
||||||
|
this.id = id;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
this.publicationTitle = publicationTitle;
|
this.publicationTitle = publicationTitle;
|
||||||
this.publicationYear = publicationYear;
|
this.publicationYear = publicationYear;
|
||||||
@ -61,6 +66,22 @@ public class ReferenceDto {
|
|||||||
this.journalOrCollectionTitle = journalOrCollectionTitle;
|
this.journalOrCollectionTitle = journalOrCollectionTitle;
|
||||||
this.referenceType = referenceType;
|
this.referenceType = referenceType;
|
||||||
this.formatStandard = formatStandard;
|
this.formatStandard = formatStandard;
|
||||||
|
this.deleted = deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto(Reference reference) {
|
||||||
|
this.id = reference.getId();
|
||||||
|
this.authors = reference.getAuthors();
|
||||||
|
this.publicationTitle = reference.getPublicationTitle();
|
||||||
|
this.publicationYear = reference.getPublicationYear();
|
||||||
|
this.publisher = reference.getPublisher();
|
||||||
|
this.pages = reference.getPages();
|
||||||
|
this.journalOrCollectionTitle = reference.getJournalOrCollectionTitle();
|
||||||
|
this.referenceType = reference.getReferenceType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto() {
|
||||||
|
referenceType = ReferenceType.ARTICLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthors() {
|
public String getAuthors() {
|
||||||
@ -126,4 +147,20 @@ public class ReferenceDto {
|
|||||||
public void setFormatStandard(FormatStandard formatStandard) {
|
public void setFormatStandard(FormatStandard formatStandard) {
|
||||||
this.formatStandard = formatStandard;
|
this.formatStandard = formatStandard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDeleted() {
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeleted(boolean deleted) {
|
||||||
|
this.deleted = deleted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,12 @@ public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
|||||||
List<Paper> findByIdNotIn(List<Integer> paperIds);
|
List<Paper> findByIdNotIn(List<Integer> paperIds);
|
||||||
|
|
||||||
List<Paper> findAllByIdIn(List<Integer> paperIds);
|
List<Paper> findAllByIdIn(List<Integer> paperIds);
|
||||||
|
|
||||||
|
List<Paper> findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status);
|
||||||
|
|
||||||
|
List<Paper> findByStatusNot(Paper.PaperStatus status);
|
||||||
|
|
||||||
|
List<Paper> findByConferencesIsNullAndStatusNot(Paper.PaperStatus status);
|
||||||
|
|
||||||
|
List<Paper> findByIdNotInAndConferencesIsNullAndStatusNot(List<Integer> paperIds, Paper.PaperStatus status);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package ru.ulstu.paper.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import ru.ulstu.paper.model.Reference;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ReferenceRepository extends JpaRepository<Reference, Integer> {
|
||||||
|
void deleteById(Integer id);
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.authors FROM Reference r")
|
||||||
|
List<String> findDistinctAuthors();
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.publicationTitle FROM Reference r")
|
||||||
|
List<String> findDistinctPublicationTitles();
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.publisher FROM Reference r")
|
||||||
|
List<String> findDistinctPublishers();
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.journalOrCollectionTitle FROM Reference r where r.journalOrCollectionTitle <> ''")
|
||||||
|
List<String> findDistinctJournalOrCollectionTitles();
|
||||||
|
}
|
@ -7,11 +7,14 @@ import ru.ulstu.deadline.model.Deadline;
|
|||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
|
import ru.ulstu.paper.model.AutoCompleteData;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.model.PaperListDto;
|
import ru.ulstu.paper.model.PaperListDto;
|
||||||
|
import ru.ulstu.paper.model.Reference;
|
||||||
import ru.ulstu.paper.model.ReferenceDto;
|
import ru.ulstu.paper.model.ReferenceDto;
|
||||||
import ru.ulstu.paper.repository.PaperRepository;
|
import ru.ulstu.paper.repository.PaperRepository;
|
||||||
|
import ru.ulstu.paper.repository.ReferenceRepository;
|
||||||
import ru.ulstu.timeline.service.EventService;
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
@ -39,6 +42,7 @@ import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.ARTICLE;
|
|||||||
import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.BOOK;
|
import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.BOOK;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class PaperService {
|
public class PaperService {
|
||||||
private final static int MAX_DISPLAY_SIZE = 75;
|
private final static int MAX_DISPLAY_SIZE = 75;
|
||||||
private final static String PAPER_FORMATTED_TEMPLATE = "%s %s";
|
private final static String PAPER_FORMATTED_TEMPLATE = "%s %s";
|
||||||
@ -49,14 +53,17 @@ public class PaperService {
|
|||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
|
private final ReferenceRepository referenceRepository;
|
||||||
|
|
||||||
public PaperService(PaperRepository paperRepository,
|
public PaperService(PaperRepository paperRepository,
|
||||||
|
ReferenceRepository referenceRepository,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
PaperNotificationService paperNotificationService,
|
PaperNotificationService paperNotificationService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
EventService eventService) {
|
EventService eventService) {
|
||||||
this.paperRepository = paperRepository;
|
this.paperRepository = paperRepository;
|
||||||
|
this.referenceRepository = referenceRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.paperNotificationService = paperNotificationService;
|
this.paperNotificationService = paperNotificationService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
@ -117,6 +124,7 @@ public class PaperService {
|
|||||||
paper.setTitle(paperDto.getTitle());
|
paper.setTitle(paperDto.getTitle());
|
||||||
paper.setUpdateDate(new Date());
|
paper.setUpdateDate(new Date());
|
||||||
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
||||||
|
paper.setReferences(saveOrCreateReferences(paperDto.getReferences()));
|
||||||
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
||||||
.filter(f -> !f.isDeleted())
|
.filter(f -> !f.isDeleted())
|
||||||
.collect(toList())));
|
.collect(toList())));
|
||||||
@ -127,6 +135,41 @@ public class PaperService {
|
|||||||
return paper;
|
return paper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Reference> saveOrCreateReferences(List<ReferenceDto> references) {
|
||||||
|
return references
|
||||||
|
.stream()
|
||||||
|
.filter(reference -> !reference.getDeleted())
|
||||||
|
.map(reference -> reference.getId() != null ? updateReference(reference) : createReference(reference))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Reference updateReference(ReferenceDto referenceDto) {
|
||||||
|
Reference updateReference = referenceRepository.findOne(referenceDto.getId());
|
||||||
|
copyFromDto(updateReference, referenceDto);
|
||||||
|
referenceRepository.save(updateReference);
|
||||||
|
return updateReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Reference createReference(ReferenceDto referenceDto) {
|
||||||
|
Reference newReference = new Reference();
|
||||||
|
copyFromDto(newReference, referenceDto);
|
||||||
|
newReference = referenceRepository.save(newReference);
|
||||||
|
return newReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Reference copyFromDto(Reference reference, ReferenceDto referenceDto) {
|
||||||
|
reference.setAuthors(referenceDto.getAuthors());
|
||||||
|
reference.setJournalOrCollectionTitle(referenceDto.getJournalOrCollectionTitle());
|
||||||
|
reference.setPages(referenceDto.getPages());
|
||||||
|
reference.setPublicationTitle(referenceDto.getPublicationTitle());
|
||||||
|
reference.setPublicationYear(referenceDto.getPublicationYear());
|
||||||
|
reference.setPublisher(referenceDto.getPublisher());
|
||||||
|
reference.setReferenceType(referenceDto.getReferenceType());
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(PaperDto paperDto) throws IOException {
|
public Integer update(PaperDto paperDto) throws IOException {
|
||||||
Paper paper = paperRepository.findOne(paperDto.getId());
|
Paper paper = paperRepository.findOne(paperDto.getId());
|
||||||
@ -139,6 +182,11 @@ public class PaperService {
|
|||||||
fileService.delete(file.getId());
|
fileService.delete(file.getId());
|
||||||
}
|
}
|
||||||
paperRepository.save(copyFromDto(paper, paperDto));
|
paperRepository.save(copyFromDto(paper, paperDto));
|
||||||
|
for (ReferenceDto referenceDto : paperDto.getReferences().stream()
|
||||||
|
.filter(f -> f.getDeleted() && f.getId() != null)
|
||||||
|
.collect(toList())) {
|
||||||
|
referenceRepository.deleteById(referenceDto.getId());
|
||||||
|
}
|
||||||
eventService.updatePaperDeadlines(paper);
|
eventService.updatePaperDeadlines(paper);
|
||||||
|
|
||||||
paper.getAuthors().forEach(author -> {
|
paper.getAuthors().forEach(author -> {
|
||||||
@ -168,6 +216,14 @@ public class PaperService {
|
|||||||
return Arrays.asList(Paper.PaperType.values());
|
return Arrays.asList(Paper.PaperType.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ReferenceDto.FormatStandard> getFormatStandards() {
|
||||||
|
return Arrays.asList(ReferenceDto.FormatStandard.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReferenceDto.ReferenceType> getReferenceTypes() {
|
||||||
|
return Arrays.asList(ReferenceDto.ReferenceType.values());
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Paper create(String title, User user, Date deadlineDate) {
|
public Paper create(String title, User user, Date deadlineDate) {
|
||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
@ -242,15 +298,18 @@ public class PaperService {
|
|||||||
|
|
||||||
public List<Paper> findAllNotSelect(List<Integer> paperIds) {
|
public List<Paper> findAllNotSelect(List<Integer> paperIds) {
|
||||||
if (!paperIds.isEmpty()) {
|
if (!paperIds.isEmpty()) {
|
||||||
return sortPapers(paperRepository.findByIdNotIn(paperIds));
|
return sortPapers(paperRepository.findByIdNotInAndConferencesIsNullAndStatusNot(paperIds, COMPLETED));
|
||||||
} else {
|
} else {
|
||||||
return sortPapers(paperRepository.findAll());
|
return sortPapers(paperRepository.findByConferencesIsNullAndStatusNot(COMPLETED));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<PaperDto> findAllNotCompleted() {
|
||||||
|
return convert(paperRepository.findByStatusNot(COMPLETED), PaperDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> findAllSelect(List<Integer> paperIds) {
|
public List<PaperDto> findAllSelect(List<Integer> paperIds) {
|
||||||
return sortPapers(paperRepository.findAllByIdIn(paperIds));
|
return convert(paperRepository.findAllByIdIn(paperIds), PaperDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getPaperAuthors() {
|
public List<User> getPaperAuthors() {
|
||||||
@ -284,12 +343,23 @@ public class PaperService {
|
|||||||
: getSpringerReference(referenceDto);
|
: getSpringerReference(referenceDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFormattedReferences(PaperDto paperDto) {
|
||||||
|
return String.join("\r\n", paperDto.getReferences()
|
||||||
|
.stream()
|
||||||
|
.filter(r -> !r.getDeleted())
|
||||||
|
.map(r -> {
|
||||||
|
r.setFormatStandard(paperDto.getFormatStandard());
|
||||||
|
return getFormattedReference(r);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
public String getGostReference(ReferenceDto referenceDto) {
|
public String getGostReference(ReferenceDto referenceDto) {
|
||||||
return MessageFormat.format(referenceDto.getReferenceType() == BOOK ? "{0} {1} - {2}{3}. - {4}с." : "{0} {1}{5} {2}{3}. С. {4}.",
|
return MessageFormat.format(referenceDto.getReferenceType() == BOOK ? "{0} {1} - {2}{3}. - {4}с." : "{0} {1}{5} {2}{3}. С. {4}.",
|
||||||
referenceDto.getAuthors(),
|
referenceDto.getAuthors(),
|
||||||
referenceDto.getPublicationTitle(),
|
referenceDto.getPublicationTitle(),
|
||||||
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
||||||
referenceDto.getPublicationYear().toString(),
|
referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "",
|
||||||
referenceDto.getPages(),
|
referenceDto.getPages(),
|
||||||
StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + ".");
|
StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + ".");
|
||||||
}
|
}
|
||||||
@ -297,10 +367,23 @@ public class PaperService {
|
|||||||
public String getSpringerReference(ReferenceDto referenceDto) {
|
public String getSpringerReference(ReferenceDto referenceDto) {
|
||||||
return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}",
|
return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}",
|
||||||
referenceDto.getAuthors(),
|
referenceDto.getAuthors(),
|
||||||
referenceDto.getPublicationYear().toString(),
|
referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "",
|
||||||
referenceDto.getPublicationTitle(),
|
referenceDto.getPublicationTitle(),
|
||||||
referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "",
|
referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "",
|
||||||
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
||||||
referenceDto.getPages());
|
referenceDto.getPages());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Paper> findAllCompletedByType(Paper.PaperType type) {
|
||||||
|
return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoCompleteData getAutoCompleteData() {
|
||||||
|
AutoCompleteData autoCompleteData = new AutoCompleteData();
|
||||||
|
autoCompleteData.setAuthors(referenceRepository.findDistinctAuthors());
|
||||||
|
autoCompleteData.setJournalOrCollectionTitles(referenceRepository.findDistinctJournalOrCollectionTitles());
|
||||||
|
autoCompleteData.setPublicationTitles(referenceRepository.findDistinctPublicationTitles());
|
||||||
|
autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers());
|
||||||
|
return autoCompleteData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
package ru.ulstu.ping.repository;
|
package ru.ulstu.ping.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.ping.model.Ping;
|
import ru.ulstu.ping.model.Ping;
|
||||||
|
|
||||||
public interface PingRepository extends JpaRepository<Ping, Integer> {
|
public interface PingRepository extends JpaRepository<Ping, Integer> {
|
||||||
|
|
||||||
|
@Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (YEAR(p.date) = :year) AND (p.conference = :conference)")
|
||||||
|
long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import ru.ulstu.ping.repository.PingRepository;
|
|||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -22,9 +23,14 @@ public class PingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addPing(Conference conference) throws IOException {
|
public Ping addPing(Conference conference) throws IOException {
|
||||||
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
||||||
newPing.setConference(conference);
|
newPing.setConference(conference);
|
||||||
pingRepository.save(newPing);
|
return pingRepository.save(newPing);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
src/main/java/ru/ulstu/students/model/Scheduler.java
Normal file
49
src/main/java/ru/ulstu/students/model/Scheduler.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -67,6 +67,7 @@ public class Task extends BaseEntity {
|
|||||||
private Date updateDate = new Date();
|
private Date updateDate = new Date();
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany(fetch = FetchType.EAGER)
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
@JoinTable(name = "task_tags",
|
@JoinTable(name = "task_tags",
|
||||||
joinColumns = {@JoinColumn(name = "task_id")},
|
joinColumns = {@JoinColumn(name = "task_id")},
|
||||||
inverseJoinColumns = {@JoinColumn(name = "tag_id")})
|
inverseJoinColumns = {@JoinColumn(name = "tag_id")})
|
||||||
@ -127,4 +128,5 @@ public class Task extends BaseEntity {
|
|||||||
public void setTags(List<Tag> tags) {
|
public void setTags(List<Tag> tags) {
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import ru.ulstu.tags.model.Tag;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -135,6 +136,29 @@ public class TaskDto {
|
|||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TaskDto taskDto = (TaskDto) o;
|
||||||
|
return Objects.equals(id, taskDto.id) &&
|
||||||
|
Objects.equals(title, taskDto.title) &&
|
||||||
|
Objects.equals(description, taskDto.description) &&
|
||||||
|
status == taskDto.status &&
|
||||||
|
Objects.equals(deadlines, taskDto.deadlines) &&
|
||||||
|
Objects.equals(tagIds, taskDto.tagIds) &&
|
||||||
|
Objects.equals(tags, taskDto.tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, title, description, status, deadlines, createDate, updateDate, tagIds, tags);
|
||||||
|
}
|
||||||
|
|
||||||
public String getTagsString() {
|
public String getTagsString() {
|
||||||
return StringUtils.abbreviate(tags
|
return StringUtils.abbreviate(tags
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package ru.ulstu.students.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.students.model.Scheduler;
|
||||||
|
import ru.ulstu.students.model.Task;
|
||||||
|
|
||||||
|
public interface SchedulerRepository extends JpaRepository<Scheduler, Integer> {
|
||||||
|
|
||||||
|
Scheduler findOneByTask(Task task);
|
||||||
|
|
||||||
|
}
|
@ -6,6 +6,7 @@ import org.springframework.data.repository.query.Param;
|
|||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.tags.model.Tag;
|
import ru.ulstu.tags.model.Tag;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface TaskRepository extends JpaRepository<Task, Integer> {
|
public interface TaskRepository extends JpaRepository<Task, Integer> {
|
||||||
@ -15,4 +16,12 @@ public interface TaskRepository extends JpaRepository<Task, Integer> {
|
|||||||
|
|
||||||
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC")
|
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC")
|
||||||
List<Task> filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
List<Task> filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
||||||
|
|
||||||
|
@Query("SELECT t FROM Task t WHERE(:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC")
|
||||||
|
List<Task> findByTag(@Param("tag") Tag tag);
|
||||||
|
|
||||||
|
@Query("SELECT t FROM Task t WHERE (t.createDate >= :date) ORDER BY create_date DESC")
|
||||||
|
List<Task> findAllYear(@Param("date") Date date);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
116
src/main/java/ru/ulstu/students/service/SchedulerService.java
Normal file
116
src/main/java/ru/ulstu/students/service/SchedulerService.java
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
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<Task> 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<Scheduler> schedulerList = schedulerRepository.findAll();
|
||||||
|
if (!schedulerList.isEmpty()) {
|
||||||
|
doTodayPlanIfNeed(schedulerList);
|
||||||
|
schedulerList = schedulerRepository.findAll();
|
||||||
|
}
|
||||||
|
checkNewPlan(schedulerList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkNewPlan(List<Scheduler> schedulerList) {
|
||||||
|
Set<Tag> tags = taskService.checkRepeatingTags(true);
|
||||||
|
Set<Tag> newTags = null;
|
||||||
|
if (!schedulerList.isEmpty()) {
|
||||||
|
newTags = checkNewTags(tags, schedulerList);
|
||||||
|
} else {
|
||||||
|
if (!tags.isEmpty()) {
|
||||||
|
newTags = tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newTags != null) {
|
||||||
|
newTags.forEach(tag -> {
|
||||||
|
if (!hasNewTag(tag, schedulerList)) {
|
||||||
|
save(tag);
|
||||||
|
Task task = taskService.findTasksByTag(tag).get(0);
|
||||||
|
schedulerList.add(new Scheduler(task, task.getDeadlines().get(task.getDeadlines().size() - 1).getDate()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasNewTag(Tag tag, List<Scheduler> schedulerList) {
|
||||||
|
|
||||||
|
return schedulerList
|
||||||
|
.stream()
|
||||||
|
.anyMatch(scheduler -> scheduler.getTask().getTags().contains(tag));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Set<Tag> checkNewTags(Set<Tag> tags, List<Scheduler> schedulerList) {
|
||||||
|
Set<Tag> newTags = tags
|
||||||
|
.stream()
|
||||||
|
.filter(tag -> schedulerList
|
||||||
|
.stream()
|
||||||
|
.anyMatch(scheduler ->
|
||||||
|
!scheduler.getTask().getTags().contains(tag)))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
if (!newTags.isEmpty()) {
|
||||||
|
return newTags;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTodayPlanIfNeed(List<Scheduler> schedulerList) {
|
||||||
|
List<Scheduler> plan = schedulerList
|
||||||
|
.stream()
|
||||||
|
.filter(scheduler -> scheduler.getDate().before(new Date()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
doToday(plan);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doToday(List<Scheduler> plan) {
|
||||||
|
plan.forEach(scheduler -> {
|
||||||
|
taskService.createPeriodTask(scheduler);
|
||||||
|
delete(scheduler.getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package ru.ulstu.students.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TaskGenerationService {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(TaskGenerationService.class);
|
||||||
|
private final TaskService taskService;
|
||||||
|
private final SchedulerService schedulerService;
|
||||||
|
|
||||||
|
public TaskGenerationService(TaskService taskService, SchedulerService schedulerService) {
|
||||||
|
|
||||||
|
this.taskService = taskService;
|
||||||
|
this.schedulerService = schedulerService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 0 * * ?", zone = "Europe/Samara")
|
||||||
|
public void generateTasks() {
|
||||||
|
log.debug("SchedulerService.checkPlanToday started");
|
||||||
|
schedulerService.checkPlanToday();
|
||||||
|
log.debug("SchedulerService.checkPlanToday finished");
|
||||||
|
|
||||||
|
log.debug("TaskService.generateYearTasks started");
|
||||||
|
taskService.generateYearTasks();
|
||||||
|
log.debug("TaskService.generateYearTasks finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,18 +4,29 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
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.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.students.model.Scheduler;
|
||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.students.model.TaskDto;
|
import ru.ulstu.students.model.TaskDto;
|
||||||
import ru.ulstu.students.model.TaskFilterDto;
|
import ru.ulstu.students.model.TaskFilterDto;
|
||||||
|
import ru.ulstu.students.repository.SchedulerRepository;
|
||||||
import ru.ulstu.students.repository.TaskRepository;
|
import ru.ulstu.students.repository.TaskRepository;
|
||||||
import ru.ulstu.tags.model.Tag;
|
import ru.ulstu.tags.model.Tag;
|
||||||
import ru.ulstu.tags.service.TagService;
|
import ru.ulstu.tags.service.TagService;
|
||||||
|
import ru.ulstu.timeline.service.EventService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
@ -27,14 +38,19 @@ public class TaskService {
|
|||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
private final static int MAX_DISPLAY_SIZE = 40;
|
||||||
|
|
||||||
private final TaskRepository taskRepository;
|
private final TaskRepository taskRepository;
|
||||||
|
private final SchedulerRepository schedulerRepository;
|
||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final TagService tagService;
|
private final TagService tagService;
|
||||||
|
private final EventService eventService;
|
||||||
|
|
||||||
|
|
||||||
public TaskService(TaskRepository taskRepository,
|
public TaskService(TaskRepository taskRepository,
|
||||||
DeadlineService deadlineService, TagService tagService) {
|
DeadlineService deadlineService, TagService tagService, SchedulerRepository schedulerRepository, EventService eventService) {
|
||||||
this.taskRepository = taskRepository;
|
this.taskRepository = taskRepository;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.tagService = tagService;
|
this.tagService = tagService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
this.schedulerRepository = schedulerRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Task> findAll() {
|
public List<Task> findAll() {
|
||||||
@ -67,6 +83,7 @@ public class TaskService {
|
|||||||
public Integer create(TaskDto taskDto) throws IOException {
|
public Integer create(TaskDto taskDto) throws IOException {
|
||||||
Task newTask = copyFromDto(new Task(), taskDto);
|
Task newTask = copyFromDto(new Task(), taskDto);
|
||||||
newTask = taskRepository.save(newTask);
|
newTask = taskRepository.save(newTask);
|
||||||
|
eventService.createFromTask(newTask);
|
||||||
return newTask.getId();
|
return newTask.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,14 +103,22 @@ public class TaskService {
|
|||||||
public Integer update(TaskDto taskDto) throws IOException {
|
public Integer update(TaskDto taskDto) throws IOException {
|
||||||
Task task = taskRepository.findOne(taskDto.getId());
|
Task task = taskRepository.findOne(taskDto.getId());
|
||||||
taskRepository.save(copyFromDto(task, taskDto));
|
taskRepository.save(copyFromDto(task, taskDto));
|
||||||
|
eventService.updateTaskDeadlines(task);
|
||||||
return task.getId();
|
return task.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer taskId) throws IOException {
|
public boolean delete(Integer taskId) throws IOException {
|
||||||
if (taskRepository.exists(taskId)) {
|
if (taskRepository.exists(taskId)) {
|
||||||
taskRepository.delete(taskId);
|
Task scheduleTask = taskRepository.findOne(taskId);
|
||||||
|
Scheduler sch = schedulerRepository.findOneByTask(scheduleTask);
|
||||||
|
if (sch != null) {
|
||||||
|
schedulerRepository.delete(sch.getId());
|
||||||
}
|
}
|
||||||
|
taskRepository.delete(taskId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +130,112 @@ public class TaskService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task copyTaskWithNewDates(Task task) {
|
||||||
|
Task newTask = new Task();
|
||||||
|
copyMainPart(newTask, task);
|
||||||
|
Calendar cal1 = DateUtils.getCalendar(newTask.getCreateDate());
|
||||||
|
Calendar cal2 = DateUtils.getCalendar(task.getCreateDate());
|
||||||
|
Integer interval = cal1.get(Calendar.DAY_OF_YEAR) - cal2.get(Calendar.DAY_OF_YEAR);
|
||||||
|
newTask.setDeadlines(newDatesDeadlines(task.getDeadlines(), interval));
|
||||||
|
return newTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Deadline> newDatesDeadlines(List<Deadline> 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task copyTaskWithNewYear(Task task) {
|
||||||
|
Task newTask = new Task();
|
||||||
|
copyMainPart(newTask, task);
|
||||||
|
newTask.setDeadlines(newYearDeadlines(task.getDeadlines()));
|
||||||
|
return newTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Deadline> newYearDeadlines(List<Deadline> deadlines) {
|
||||||
|
return deadlines
|
||||||
|
.stream()
|
||||||
|
.map(deadline -> {
|
||||||
|
Deadline newDeadline = new Deadline();
|
||||||
|
newDeadline.setDescription(deadline.getDescription());
|
||||||
|
newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1));
|
||||||
|
return deadlineService.create(newDeadline);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equalsDate(Task task) {
|
||||||
|
Calendar taskDate = DateUtils.getCalendar(task.getCreateDate());
|
||||||
|
Calendar nowDate = DateUtils.getCalendar(new Date());
|
||||||
|
return (taskDate.get(Calendar.DAY_OF_MONTH) == nowDate.get(Calendar.DAY_OF_MONTH) &&
|
||||||
|
taskDate.get(Calendar.MONTH) + 1 == nowDate.get(Calendar.MONTH) + 1 &&
|
||||||
|
taskDate.get(Calendar.YEAR) + 1 == nowDate.get(Calendar.YEAR));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<Task> generateYearTasks() {
|
||||||
|
Set<Tag> tags = checkRepeatingTags(false);
|
||||||
|
List<Task> tasks = new ArrayList<>();
|
||||||
|
tags.forEach(tag -> {
|
||||||
|
Task singleTask = findTasksByTag(tag).get(0);
|
||||||
|
if (equalsDate(singleTask)) {
|
||||||
|
if (!tasks.contains(singleTask)) {
|
||||||
|
tasks.add(singleTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (tasks != null) {
|
||||||
|
tasks.forEach(task -> {
|
||||||
|
Task newTask = copyTaskWithNewYear(task);
|
||||||
|
taskRepository.save(newTask);
|
||||||
|
});
|
||||||
|
return tasks;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Set<Tag> checkRepeatingTags(Boolean createPeriodTask) { //param: false = year task; true = period task
|
||||||
|
Map<Tag, Long> tagsCount = new TreeMap<>();
|
||||||
|
List<Tag> tags = tagService.getTags();
|
||||||
|
List<Task> tasks = taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)));
|
||||||
|
tags.forEach(tag ->
|
||||||
|
tagsCount.put(tag, tasks
|
||||||
|
.stream()
|
||||||
|
.filter(task -> task.getTags().contains(tag))
|
||||||
|
.count()));
|
||||||
|
if (!createPeriodTask) {
|
||||||
|
return tagsCount
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(tagLongEntry -> tagLongEntry.getValue() == 1)
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
|
||||||
|
.keySet();
|
||||||
|
} else {
|
||||||
|
return tagsCount
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.filter(tagLongEntry -> tagLongEntry.getValue() >= 2)
|
||||||
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
|
||||||
|
.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public List<Task.TaskStatus> getTaskStatuses() {
|
public List<Task.TaskStatus> getTaskStatuses() {
|
||||||
return Arrays.asList(Task.TaskStatus.values());
|
return Arrays.asList(Task.TaskStatus.values());
|
||||||
}
|
}
|
||||||
@ -113,4 +244,14 @@ public class TaskService {
|
|||||||
return tagService.getTags();
|
return tagService.getTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Task> findTasksByTag(Tag tag) {
|
||||||
|
return taskRepository.findByTag(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Task createPeriodTask(Scheduler scheduler) {
|
||||||
|
Task newTask = copyTaskWithNewDates(scheduler.getTask());
|
||||||
|
taskRepository.save(newTask);
|
||||||
|
return newTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import javax.persistence.Column;
|
|||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "tag")
|
@Table(name = "tag")
|
||||||
@ -41,4 +42,21 @@ public class Tag extends BaseEntity {
|
|||||||
public void setTagName(String tagName) {
|
public void setTagName(String tagName) {
|
||||||
this.tagName = 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package ru.ulstu.timeline.model;
|
package ru.ulstu.timeline.model;
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.NotBlank;
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
@ -18,6 +21,7 @@ import javax.persistence.OneToMany;
|
|||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -61,8 +65,8 @@ public class Event extends BaseEntity {
|
|||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany(fetch = FetchType.LAZY)
|
||||||
private List<User> recipients;
|
private List<User> recipients = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "child_id")
|
@JoinColumn(name = "child_id")
|
||||||
@ -76,6 +80,18 @@ public class Event extends BaseEntity {
|
|||||||
@JoinColumn(name = "paper_id")
|
@JoinColumn(name = "paper_id")
|
||||||
private Paper paper;
|
private Paper paper;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "conference_id")
|
||||||
|
private Conference conference;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "grant_id")
|
||||||
|
private Grant grant;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "task_id")
|
||||||
|
private Task task;
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
@ -163,4 +179,28 @@ public class Event extends BaseEntity {
|
|||||||
public void setPaper(Paper paper) {
|
public void setPaper(Paper paper) {
|
||||||
this.paper = paper;
|
this.paper = paper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Conference getConference() {
|
||||||
|
return conference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConference(Conference conference) {
|
||||||
|
this.conference = conference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Grant getGrant() {
|
||||||
|
return grant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrant(Grant grant) {
|
||||||
|
this.grant = grant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task getTask() {
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTask(Task task) {
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,10 @@ package ru.ulstu.timeline.model;
|
|||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.hibernate.validator.constraints.NotBlank;
|
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.paper.model.PaperDto;
|
||||||
|
import ru.ulstu.students.model.TaskDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
@ -25,6 +28,9 @@ public class EventDto {
|
|||||||
private final String description;
|
private final String description;
|
||||||
private final List<UserDto> recipients;
|
private final List<UserDto> recipients;
|
||||||
private PaperDto paperDto;
|
private PaperDto paperDto;
|
||||||
|
private ConferenceDto conferenceDto;
|
||||||
|
private GrantDto grantDto;
|
||||||
|
private TaskDto taskDto;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public EventDto(@JsonProperty("id") Integer id,
|
public EventDto(@JsonProperty("id") Integer id,
|
||||||
@ -36,7 +42,10 @@ public class EventDto {
|
|||||||
@JsonProperty("updateDate") Date updateDate,
|
@JsonProperty("updateDate") Date updateDate,
|
||||||
@JsonProperty("description") String description,
|
@JsonProperty("description") String description,
|
||||||
@JsonProperty("paperDto") PaperDto paperDto,
|
@JsonProperty("paperDto") PaperDto paperDto,
|
||||||
@JsonProperty("recipients") List<UserDto> recipients) {
|
@JsonProperty("recipients") List<UserDto> recipients,
|
||||||
|
@JsonProperty("conferenceDto") ConferenceDto conferenceDto,
|
||||||
|
@JsonProperty("grantDto") GrantDto grantDto,
|
||||||
|
@JsonProperty("taskDto") TaskDto taskDto) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.period = period;
|
this.period = period;
|
||||||
@ -47,6 +56,9 @@ public class EventDto {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
this.recipients = recipients;
|
this.recipients = recipients;
|
||||||
this.paperDto = paperDto;
|
this.paperDto = paperDto;
|
||||||
|
this.conferenceDto = conferenceDto;
|
||||||
|
this.grantDto = grantDto;
|
||||||
|
this.taskDto = taskDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventDto(Event event) {
|
public EventDto(Event event) {
|
||||||
@ -58,8 +70,19 @@ public class EventDto {
|
|||||||
this.createDate = event.getCreateDate();
|
this.createDate = event.getCreateDate();
|
||||||
this.updateDate = event.getUpdateDate();
|
this.updateDate = event.getUpdateDate();
|
||||||
this.description = event.getDescription();
|
this.description = event.getDescription();
|
||||||
this.paperDto = new PaperDto(event.getPaper());
|
|
||||||
this.recipients = convert(event.getRecipients(), UserDto::new);
|
this.recipients = convert(event.getRecipients(), UserDto::new);
|
||||||
|
if (paperDto != null) {
|
||||||
|
this.paperDto = new PaperDto(event.getPaper());
|
||||||
|
}
|
||||||
|
if (conferenceDto != null) {
|
||||||
|
this.conferenceDto = new ConferenceDto(event.getConference());
|
||||||
|
}
|
||||||
|
if (grantDto != null) {
|
||||||
|
this.grantDto = new GrantDto(event.getGrant());
|
||||||
|
}
|
||||||
|
if (taskDto != null) {
|
||||||
|
this.taskDto = new TaskDto(event.getTask());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -105,4 +128,28 @@ public class EventDto {
|
|||||||
public void setPaperDto(PaperDto paperDto) {
|
public void setPaperDto(PaperDto paperDto) {
|
||||||
this.paperDto = paperDto;
|
this.paperDto = paperDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConferenceDto getConferenceDto() {
|
||||||
|
return conferenceDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConferenceDto(ConferenceDto conferenceDto) {
|
||||||
|
this.conferenceDto = conferenceDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto getGrantDto() {
|
||||||
|
return grantDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrantDto(GrantDto grantDto) {
|
||||||
|
this.grantDto = grantDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskDto getTaskDto() {
|
||||||
|
return taskDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskDto(TaskDto taskDto) {
|
||||||
|
this.taskDto = taskDto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@ package ru.ulstu.timeline.repository;
|
|||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
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.paper.model.Paper;
|
||||||
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.timeline.model.Event;
|
import ru.ulstu.timeline.model.Event;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -15,4 +18,10 @@ public interface EventRepository extends JpaRepository<Event, Integer> {
|
|||||||
List<Event> findAllFuture();
|
List<Event> findAllFuture();
|
||||||
|
|
||||||
List<Event> findAllByPaper(Paper paper);
|
List<Event> findAllByPaper(Paper paper);
|
||||||
|
|
||||||
|
List<Event> findAllByConference(Conference conference);
|
||||||
|
|
||||||
|
List<Event> findAllByGrant(Grant grant);
|
||||||
|
|
||||||
|
List<Event> findAllByTask(Task task);
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,11 @@ import org.apache.commons.lang3.time.DateUtils;
|
|||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.timeline.model.Event;
|
import ru.ulstu.timeline.model.Event;
|
||||||
import ru.ulstu.timeline.model.EventDto;
|
import ru.ulstu.timeline.model.EventDto;
|
||||||
import ru.ulstu.timeline.model.Timeline;
|
import ru.ulstu.timeline.model.Timeline;
|
||||||
@ -140,4 +143,99 @@ public class EventService {
|
|||||||
public List<EventDto> findAllFutureDto() {
|
public List<EventDto> findAllFutureDto() {
|
||||||
return convert(findAllFuture(), EventDto::new);
|
return convert(findAllFuture(), EventDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void createFromConference(Conference newConference) {
|
||||||
|
List<Timeline> timelines = timelineService.findAll();
|
||||||
|
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
||||||
|
|
||||||
|
for (Deadline deadline : newConference.getDeadlines()
|
||||||
|
.stream()
|
||||||
|
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
|
||||||
|
.collect(Collectors.toList())) {
|
||||||
|
Event newEvent = new Event();
|
||||||
|
newEvent.setTitle("Дедлайн конференции");
|
||||||
|
newEvent.setStatus(Event.EventStatus.NEW);
|
||||||
|
newEvent.setExecuteDate(deadline.getDate());
|
||||||
|
newEvent.setCreateDate(new Date());
|
||||||
|
newEvent.setUpdateDate(new Date());
|
||||||
|
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' конференции '" + newConference.getTitle() + "'");
|
||||||
|
newConference.getUsers().forEach(conferenceUser -> newEvent.getRecipients().add(conferenceUser.getUser()));
|
||||||
|
newEvent.setConference(newConference);
|
||||||
|
save(newEvent);
|
||||||
|
|
||||||
|
timeline.getEvents().add(newEvent);
|
||||||
|
timelineService.save(timeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateConferenceDeadlines(Conference conference) {
|
||||||
|
eventRepository.delete(eventRepository.findAllByConference(conference));
|
||||||
|
createFromConference(conference);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createFromGrant(Grant newGrant) {
|
||||||
|
List<Timeline> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeConferencesEvent(Conference conference) {
|
||||||
|
List<Event> eventList = eventRepository.findAllByConference(conference);
|
||||||
|
eventList.forEach(event -> eventRepository.delete(event.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createFromTask(Task newTask) {
|
||||||
|
List<Timeline> timelines = timelineService.findAll();
|
||||||
|
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
||||||
|
|
||||||
|
for (Deadline deadline : newTask.getDeadlines()
|
||||||
|
.stream()
|
||||||
|
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
|
||||||
|
.collect(Collectors.toList())) {
|
||||||
|
Event newEvent = new Event();
|
||||||
|
newEvent.setTitle("Дедлайн задачи");
|
||||||
|
newEvent.setStatus(Event.EventStatus.NEW);
|
||||||
|
newEvent.setExecuteDate(deadline.getDate());
|
||||||
|
newEvent.setCreateDate(new Date());
|
||||||
|
newEvent.setUpdateDate(new Date());
|
||||||
|
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' задачи '" + newTask.getTitle() + "'");
|
||||||
|
newEvent.getRecipients().add(userService.getCurrentUser());
|
||||||
|
newEvent.setTask(newTask);
|
||||||
|
eventRepository.save(newEvent);
|
||||||
|
|
||||||
|
timeline.getEvents().add(newEvent);
|
||||||
|
timelineService.save(timeline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTaskDeadlines(Task task) {
|
||||||
|
eventRepository.delete(eventRepository.findAllByTask(task));
|
||||||
|
createFromTask(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package ru.ulstu.user.controller;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.security.access.annotation.Secured;
|
import org.springframework.security.access.annotation.Secured;
|
||||||
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
@ -19,6 +20,7 @@ import ru.ulstu.odin.controller.OdinController;
|
|||||||
import ru.ulstu.odin.model.OdinMetadata;
|
import ru.ulstu.odin.model.OdinMetadata;
|
||||||
import ru.ulstu.odin.model.OdinVoid;
|
import ru.ulstu.odin.model.OdinVoid;
|
||||||
import ru.ulstu.odin.service.OdinService;
|
import ru.ulstu.odin.service.OdinService;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
import ru.ulstu.user.model.UserListDto;
|
import ru.ulstu.user.model.UserListDto;
|
||||||
import ru.ulstu.user.model.UserResetPasswordDto;
|
import ru.ulstu.user.model.UserResetPasswordDto;
|
||||||
@ -28,8 +30,12 @@ import ru.ulstu.user.model.UserSessionListDto;
|
|||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
import ru.ulstu.user.service.UserSessionService;
|
import ru.ulstu.user.service.UserSessionService;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static ru.ulstu.user.controller.UserController.URL;
|
import static ru.ulstu.user.controller.UserController.URL;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -141,30 +147,28 @@ public class UserController extends OdinController<UserListDto, UserDto> {
|
|||||||
return new Response<>(userService.activateUser(activationKey));
|
return new Response<>(userService.activateUser(activationKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add page for user edit (user-profile)
|
|
||||||
@PostMapping("/change-information")
|
|
||||||
public Response<UserDto> changeInformation(@Valid @RequestBody UserDto userDto) {
|
|
||||||
log.debug("REST: UserController.changeInformation( {} )", userDto.getLogin());
|
|
||||||
return new Response<>(userService.updateUserInformation(userDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add page for user password change (user-profile)
|
|
||||||
@PostMapping("/change-password")
|
|
||||||
public Response<UserDto> changePassword(@Valid @RequestBody UserDto userDto) {
|
|
||||||
log.debug("REST: UserController.changePassword( {} )", userDto.getLogin());
|
|
||||||
return new Response<>(userService.changeUserPassword(userDto));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping(PASSWORD_RESET_REQUEST_URL)
|
@PostMapping(PASSWORD_RESET_REQUEST_URL)
|
||||||
public Response<Boolean> requestPasswordReset(@RequestParam("email") String email) {
|
public void requestPasswordReset(@RequestParam("email") String email) {
|
||||||
log.debug("REST: UserController.requestPasswordReset( {} )", email);
|
log.debug("REST: UserController.requestPasswordReset( {} )", email);
|
||||||
return new Response<>(userService.requestUserPasswordReset(email));
|
userService.requestUserPasswordReset(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(PASSWORD_RESET_URL)
|
@PostMapping(PASSWORD_RESET_URL)
|
||||||
public Response<Boolean> finishPasswordReset(@RequestParam("key") String key,
|
public Response<Boolean> finishPasswordReset(@RequestBody UserResetPasswordDto userResetPasswordDto) {
|
||||||
@RequestBody UserResetPasswordDto userResetPasswordDto) {
|
log.debug("REST: UserController.requestPasswordReset( {} )", userResetPasswordDto.getResetKey());
|
||||||
log.debug("REST: UserController.requestPasswordReset( {} )", key);
|
return new Response<>(userService.completeUserPasswordReset(userResetPasswordDto));
|
||||||
return new Response<>(userService.completeUserPasswordReset(key, userResetPasswordDto));
|
}
|
||||||
|
|
||||||
|
@PostMapping("/changePassword")
|
||||||
|
public void changePassword(@RequestBody Map<String, String> payload, HttpServletRequest request) {
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||||
|
User user = userSessionService.getUserBySessionId(sessionId);
|
||||||
|
userService.changeUserPassword(user, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/invite")
|
||||||
|
public void inviteUser(@RequestParam("email") String email) {
|
||||||
|
userService.inviteUser(email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package ru.ulstu.user.controller;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
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.RequestMapping;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
import ru.ulstu.odin.controller.OdinController;
|
||||||
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.model.UserListDto;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
import ru.ulstu.user.service.UserSessionService;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping(value = "/users")
|
||||||
|
public class UserMvcController extends OdinController<UserListDto, UserDto> {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(UserMvcController.class);
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
private final UserSessionService userSessionService;
|
||||||
|
|
||||||
|
public UserMvcController(UserService userService,
|
||||||
|
UserSessionService userSessionService) {
|
||||||
|
super(UserListDto.class, UserDto.class);
|
||||||
|
this.userService = userService;
|
||||||
|
this.userSessionService = userSessionService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/profile")
|
||||||
|
public void getUserProfile(ModelMap modelMap, HttpServletRequest request) {
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||||
|
modelMap.addAttribute("userDto", new UserDto(userSessionService.getUserBySessionId(sessionId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/profile")
|
||||||
|
public void updateUserProfile(ModelMap modelMap, HttpServletRequest request, UserDto userDto) {
|
||||||
|
HttpSession session = request.getSession(false);
|
||||||
|
final String sessionId = session.getAttribute(Constants.SESSION_ID_ATTR).toString();
|
||||||
|
User user = userSessionService.getUserBySessionId(sessionId);
|
||||||
|
modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto));
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package ru.ulstu.user.error;
|
package ru.ulstu.user.error;
|
||||||
|
|
||||||
public class UserPasswordsNotValidOrNotMatchException extends RuntimeException {
|
public class UserPasswordsNotValidOrNotMatchException extends RuntimeException {
|
||||||
public UserPasswordsNotValidOrNotMatchException() {
|
public UserPasswordsNotValidOrNotMatchException(String message) {
|
||||||
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package ru.ulstu.user.error;
|
||||||
|
|
||||||
|
public class UserSendingMailException extends RuntimeException {
|
||||||
|
public UserSendingMailException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -232,7 +232,7 @@ public class User extends BaseEntity {
|
|||||||
public String getUserAbbreviate() {
|
public String getUserAbbreviate() {
|
||||||
return String.format(USER_ABBREVIATE_TEMPLATE,
|
return String.format(USER_ABBREVIATE_TEMPLATE,
|
||||||
lastName == null ? "" : lastName,
|
lastName == null ? "" : lastName,
|
||||||
firstName == null ? "" : firstName.substring(0, 1) + ".",
|
firstName == null ? "" : firstName.substring(0, 1),
|
||||||
patronymic == null ? "" : patronymic.substring(0, 1) + ".");
|
patronymic == null ? "" : patronymic.substring(0, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@ public class UserResetPasswordDto {
|
|||||||
@Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50)
|
@Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50)
|
||||||
private String passwordConfirm;
|
private String passwordConfirm;
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
@Size(min = Constants.RESET_KEY_LENGTH)
|
||||||
|
private String resetKey;
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
@ -25,4 +29,8 @@ public class UserResetPasswordDto {
|
|||||||
public boolean isPasswordsValid() {
|
public boolean isPasswordsValid() {
|
||||||
return Objects.equals(password, passwordConfirm);
|
return Objects.equals(password, passwordConfirm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getResetKey() {
|
||||||
|
return resetKey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package ru.ulstu.user.service;
|
package ru.ulstu.user.service;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.autoconfigure.mail.MailProperties;
|
import org.springframework.boot.autoconfigure.mail.MailProperties;
|
||||||
|
import org.springframework.mail.MailException;
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
@ -13,17 +15,16 @@ import ru.ulstu.configuration.ApplicationProperties;
|
|||||||
import ru.ulstu.configuration.Constants;
|
import ru.ulstu.configuration.Constants;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MailService {
|
public class MailService {
|
||||||
private final Logger log = LoggerFactory.getLogger(MailService.class);
|
|
||||||
|
|
||||||
private static final String USER = "user";
|
private static final String USER = "user";
|
||||||
private static final String BASE_URL = "baseUrl";
|
private static final String BASE_URL = "baseUrl";
|
||||||
|
private final Logger log = LoggerFactory.getLogger(MailService.class);
|
||||||
private final JavaMailSender javaMailSender;
|
private final JavaMailSender javaMailSender;
|
||||||
private final SpringTemplateEngine templateEngine;
|
private final SpringTemplateEngine templateEngine;
|
||||||
private final MailProperties mailProperties;
|
private final MailProperties mailProperties;
|
||||||
@ -38,23 +39,23 @@ public class MailService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
public void sendEmail(String to, String subject, String content) {
|
public void sendEmail(String to, String subject, String content) throws MessagingException, MailException {
|
||||||
log.debug("Send email to '{}' with subject '{}'", to, subject);
|
log.debug("Send email to '{}' with subject '{}'", to, subject);
|
||||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||||
try {
|
|
||||||
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, StandardCharsets.UTF_8.name());
|
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, StandardCharsets.UTF_8.name());
|
||||||
message.setTo(to);
|
message.setTo(to);
|
||||||
message.setFrom(mailProperties.getUsername());
|
message.setFrom(mailProperties.getUsername());
|
||||||
message.setSubject(subject);
|
message.setSubject(subject);
|
||||||
message.setText(content, true);
|
message.setText(content, true);
|
||||||
|
modifyForDebug(message, subject);
|
||||||
javaMailSender.send(mimeMessage);
|
javaMailSender.send(mimeMessage);
|
||||||
log.debug("Sent email to User '{}'", to);
|
log.debug("Sent email to User '{}'", to);
|
||||||
} catch (Exception e) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.warn("Email could not be sent to user '{}'", to, e);
|
|
||||||
} else {
|
|
||||||
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void modifyForDebug(MimeMessageHelper message, String originalSubject) throws MessagingException {
|
||||||
|
if (!StringUtils.isEmpty(applicationProperties.getDebugEmail())) {
|
||||||
|
message.setTo(applicationProperties.getDebugEmail());
|
||||||
|
message.setSubject("To " + applicationProperties.getDebugEmail() + "; " + originalSubject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +65,17 @@ public class MailService {
|
|||||||
context.setVariable(USER, user);
|
context.setVariable(USER, user);
|
||||||
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
||||||
String content = templateEngine.process(templateName, context);
|
String content = templateEngine.process(templateName, context);
|
||||||
|
try {
|
||||||
sendEmail(user.getEmail(), subject, content);
|
sendEmail(user.getEmail(), subject, content);
|
||||||
|
} catch (
|
||||||
|
Exception e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.warn("Email could not be sent to user '{}'", user.getEmail(), e);
|
||||||
|
} else {
|
||||||
|
log.warn("Email could not be sent to user '{}': {}", user.getEmail(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Todo: выделить сервис нотификаций
|
//Todo: выделить сервис нотификаций
|
||||||
@ -75,7 +86,26 @@ public class MailService {
|
|||||||
context.setVariable(USER, user);
|
context.setVariable(USER, user);
|
||||||
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
||||||
String content = templateEngine.process(templateName, context);
|
String content = templateEngine.process(templateName, context);
|
||||||
|
try {
|
||||||
sendEmail(user.getEmail(), subject, content);
|
sendEmail(user.getEmail(), subject, content);
|
||||||
|
} catch (
|
||||||
|
Exception e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.warn("Email could not be sent to user '{}'", user.getEmail(), e);
|
||||||
|
} else {
|
||||||
|
log.warn("Email could not be sent to user '{}': {}", user.getEmail(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void sendEmailFromTemplate(Map<String, Object> variables, String templateName, String subject, String email)
|
||||||
|
throws MessagingException {
|
||||||
|
Context context = new Context();
|
||||||
|
variables.entrySet().forEach(entry -> context.setVariable(entry.getKey(), entry.getValue()));
|
||||||
|
context.setVariable(BASE_URL, applicationProperties.getBaseUrl());
|
||||||
|
String content = templateEngine.process(templateName, context);
|
||||||
|
sendEmail(email, subject, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
@ -83,8 +113,16 @@ public class MailService {
|
|||||||
sendEmailFromTemplate(user, "activationEmail", Constants.MAIL_ACTIVATE);
|
sendEmailFromTemplate(user, "activationEmail", Constants.MAIL_ACTIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
public void sendPasswordResetMail(User user) throws MessagingException, MailException {
|
||||||
public void sendPasswordResetMail(User user) {
|
|
||||||
sendEmailFromTemplate(user, "passwordResetEmail", Constants.MAIL_RESET);
|
sendEmailFromTemplate(user, "passwordResetEmail", Constants.MAIL_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendInviteMail(Map<String, Object> variables, String email) throws MessagingException, MailException {
|
||||||
|
sendEmailFromTemplate(variables, "userInviteEmail", Constants.MAIL_INVITE, email);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void sendChangePasswordMail(User user) {
|
||||||
|
sendEmailFromTemplate(user, "passwordChangeEmail", Constants.MAIL_CHANGE_PASSWORD);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package ru.ulstu.user.service;
|
package ru.ulstu.user.service;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.mail.MailException;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
@ -25,6 +27,7 @@ import ru.ulstu.user.error.UserNotActivatedException;
|
|||||||
import ru.ulstu.user.error.UserNotFoundException;
|
import ru.ulstu.user.error.UserNotFoundException;
|
||||||
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
||||||
import ru.ulstu.user.error.UserResetKeyError;
|
import ru.ulstu.user.error.UserResetKeyError;
|
||||||
|
import ru.ulstu.user.error.UserSendingMailException;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
import ru.ulstu.user.model.UserListDto;
|
import ru.ulstu.user.model.UserListDto;
|
||||||
@ -36,10 +39,12 @@ import ru.ulstu.user.repository.UserRepository;
|
|||||||
import ru.ulstu.user.repository.UserRoleRepository;
|
import ru.ulstu.user.repository.UserRoleRepository;
|
||||||
import ru.ulstu.user.util.UserUtils;
|
import ru.ulstu.user.util.UserUtils;
|
||||||
|
|
||||||
|
import javax.mail.MessagingException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -48,6 +53,8 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class UserService implements UserDetailsService {
|
public class UserService implements UserDetailsService {
|
||||||
|
private static final String INVITE_USER_EXCEPTION = "Во время отправки приглашения произошла ошибка";
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(UserService.class);
|
private final Logger log = LoggerFactory.getLogger(UserService.class);
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
@ -122,7 +129,7 @@ public class UserService implements UserDetailsService {
|
|||||||
throw new UserEmailExistsException(userDto.getEmail());
|
throw new UserEmailExistsException(userDto.getEmail());
|
||||||
}
|
}
|
||||||
if (!userDto.isPasswordsValid()) {
|
if (!userDto.isPasswordsValid()) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
||||||
}
|
}
|
||||||
User user = userMapper.userDtoToUserEntity(userDto);
|
User user = userMapper.userDtoToUserEntity(userDto);
|
||||||
user.setActivated(false);
|
user.setActivated(false);
|
||||||
@ -192,10 +199,10 @@ public class UserService implements UserDetailsService {
|
|||||||
: roles);
|
: roles);
|
||||||
if (!StringUtils.isEmpty(userDto.getOldPassword())) {
|
if (!StringUtils.isEmpty(userDto.getOldPassword())) {
|
||||||
if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) {
|
if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
||||||
}
|
}
|
||||||
if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) {
|
if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
||||||
}
|
}
|
||||||
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
|
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
|
||||||
log.debug("Changed password for User: {}", user.getLogin());
|
log.debug("Changed password for User: {}", user.getLogin());
|
||||||
@ -205,46 +212,28 @@ public class UserService implements UserDetailsService {
|
|||||||
return userMapper.userEntityToUserDto(user);
|
return userMapper.userEntityToUserDto(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDto updateUserInformation(UserDto userDto) {
|
public UserDto updateUserInformation(User user, UserDto updateUser) {
|
||||||
if (userDto.getId() == null) {
|
user.setFirstName(updateUser.getFirstName());
|
||||||
throw new EntityIdIsNullException();
|
user.setLastName(updateUser.getLastName());
|
||||||
}
|
user.setEmail(updateUser.getEmail());
|
||||||
if (!Objects.equals(
|
user.setLogin(updateUser.getLogin());
|
||||||
Optional.ofNullable(getUserByEmail(userDto.getEmail()))
|
|
||||||
.map(BaseEntity::getId).orElse(userDto.getId()),
|
|
||||||
userDto.getId())) {
|
|
||||||
throw new UserEmailExistsException(userDto.getEmail());
|
|
||||||
}
|
|
||||||
User user = userRepository.findOne(userDto.getId());
|
|
||||||
if (user == null) {
|
|
||||||
throw new UserNotFoundException(userDto.getId().toString());
|
|
||||||
}
|
|
||||||
user.setFirstName(userDto.getFirstName());
|
|
||||||
user.setLastName(userDto.getLastName());
|
|
||||||
user.setEmail(userDto.getEmail());
|
|
||||||
user = userRepository.save(user);
|
user = userRepository.save(user);
|
||||||
log.debug("Updated Information for User: {}", user.getLogin());
|
log.debug("Updated Information for User: {}", user.getLogin());
|
||||||
return userMapper.userEntityToUserDto(user);
|
return userMapper.userEntityToUserDto(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDto changeUserPassword(UserDto userDto) {
|
public void changeUserPassword(User user, Map<String, String> payload) {
|
||||||
if (userDto.getId() == null) {
|
if (!payload.get("password").equals(payload.get("confirmPassword"))) {
|
||||||
throw new EntityIdIsNullException();
|
throw new UserPasswordsNotValidOrNotMatchException("");
|
||||||
}
|
}
|
||||||
if (!userDto.isPasswordsValid() || !userDto.isOldPasswordValid()) {
|
if (!passwordEncoder.matches(payload.get("oldPassword"), user.getPassword())) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("Старый пароль введен неправильно");
|
||||||
}
|
}
|
||||||
final String login = UserUtils.getCurrentUserLogin();
|
user.setPassword(passwordEncoder.encode(payload.get("password")));
|
||||||
final User user = userRepository.findOneByLoginIgnoreCase(login);
|
|
||||||
if (user == null) {
|
|
||||||
throw new UserNotFoundException(login);
|
|
||||||
}
|
|
||||||
if (!passwordEncoder.matches(userDto.getOldPassword(), user.getPassword())) {
|
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
|
||||||
}
|
|
||||||
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
|
|
||||||
log.debug("Changed password for User: {}", user.getLogin());
|
log.debug("Changed password for User: {}", user.getLogin());
|
||||||
return userMapper.userEntityToUserDto(userRepository.save(user));
|
userRepository.save(user);
|
||||||
|
|
||||||
|
mailService.sendChangePasswordMail(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requestUserPasswordReset(String email) {
|
public boolean requestUserPasswordReset(String email) {
|
||||||
@ -258,23 +247,30 @@ public class UserService implements UserDetailsService {
|
|||||||
user.setResetKey(UserUtils.generateResetKey());
|
user.setResetKey(UserUtils.generateResetKey());
|
||||||
user.setResetDate(new Date());
|
user.setResetDate(new Date());
|
||||||
user = userRepository.save(user);
|
user = userRepository.save(user);
|
||||||
|
try {
|
||||||
mailService.sendPasswordResetMail(user);
|
mailService.sendPasswordResetMail(user);
|
||||||
|
} catch (MessagingException | MailException e) {
|
||||||
|
throw new UserSendingMailException(email);
|
||||||
|
}
|
||||||
log.debug("Created Reset Password Request for User: {}", user.getLogin());
|
log.debug("Created Reset Password Request for User: {}", user.getLogin());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean completeUserPasswordReset(String key, UserResetPasswordDto userResetPasswordDto) {
|
public boolean completeUserPasswordReset(UserResetPasswordDto userResetPasswordDto) {
|
||||||
if (!userResetPasswordDto.isPasswordsValid()) {
|
if (!userResetPasswordDto.isPasswordsValid()) {
|
||||||
throw new UserPasswordsNotValidOrNotMatchException();
|
throw new UserPasswordsNotValidOrNotMatchException("Пароли не совпадают");
|
||||||
}
|
}
|
||||||
User user = userRepository.findOneByResetKey(key);
|
User user = userRepository.findOneByResetKey(userResetPasswordDto.getResetKey());
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new UserResetKeyError(key);
|
throw new UserResetKeyError(userResetPasswordDto.getResetKey());
|
||||||
}
|
}
|
||||||
user.setPassword(passwordEncoder.encode(userResetPasswordDto.getPassword()));
|
user.setPassword(passwordEncoder.encode(userResetPasswordDto.getPassword()));
|
||||||
user.setResetKey(null);
|
user.setResetKey(null);
|
||||||
user.setResetDate(null);
|
user.setResetDate(null);
|
||||||
user = userRepository.save(user);
|
user = userRepository.save(user);
|
||||||
|
|
||||||
|
mailService.sendChangePasswordMail(user);
|
||||||
|
|
||||||
log.debug("Reset Password for User: {}", user.getLogin());
|
log.debug("Reset Password for User: {}", user.getLogin());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -328,4 +324,32 @@ public class UserService implements UserDetailsService {
|
|||||||
public List<User> filterByAgeAndDegree(boolean hasDegree, boolean hasAge) {
|
public List<User> filterByAgeAndDegree(boolean hasDegree, boolean hasAge) {
|
||||||
return userRepository.filterByAgeAndDegree(hasDegree, hasAge);
|
return userRepository.filterByAgeAndDegree(hasDegree, hasAge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void inviteUser(String email) throws UserSendingMailException {
|
||||||
|
if (userRepository.findOneByEmailIgnoreCase(email) != null) {
|
||||||
|
throw new UserEmailExistsException(email);
|
||||||
|
}
|
||||||
|
|
||||||
|
String password = UserUtils.generatePassword();
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
|
user.setPassword(passwordEncoder.encode(password));
|
||||||
|
user.setLogin(email);
|
||||||
|
user.setEmail(email);
|
||||||
|
user.setFirstName("user");
|
||||||
|
user.setLastName("user");
|
||||||
|
user.setActivated(true);
|
||||||
|
userRepository.save(user);
|
||||||
|
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("password", password, "email", email);
|
||||||
|
try {
|
||||||
|
mailService.sendInviteMail(variables, email);
|
||||||
|
} catch (MessagingException | MailException e) {
|
||||||
|
throw new UserSendingMailException(email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public User findOneByLoginIgnoreCase(String login) {
|
||||||
|
return userRepository.findOneByLoginIgnoreCase(login);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,4 +54,8 @@ public class UserSessionService {
|
|||||||
userSessionRepository.save(userSession);
|
userSessionRepository.save(userSession);
|
||||||
log.debug("User session {} closed", sessionId);
|
log.debug("User session {} closed", sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User getUserBySessionId(String sessionId) {
|
||||||
|
return userSessionRepository.findOneBySessionId(sessionId).getUser();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.springframework.security.core.Authentication;
|
|||||||
import org.springframework.security.core.context.SecurityContext;
|
import org.springframework.security.core.context.SecurityContext;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
|
||||||
public class UserUtils {
|
public class UserUtils {
|
||||||
private static final int DEF_COUNT = 20;
|
private static final int DEF_COUNT = 20;
|
||||||
@ -32,4 +33,8 @@ public class UserUtils {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String generatePassword() {
|
||||||
|
return RandomStringUtils.randomAscii(Constants.MIN_PASSWORD_LENGTH, Constants.MAX_PASSWORD_LENGTH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,5 +35,6 @@ liquibase.change-log=classpath:db/changelog-master.xml
|
|||||||
ng-tracker.base-url=http://127.0.0.1:8080
|
ng-tracker.base-url=http://127.0.0.1:8080
|
||||||
ng-tracker.undead-user-login=admin
|
ng-tracker.undead-user-login=admin
|
||||||
ng-tracker.dev-mode=true
|
ng-tracker.dev-mode=true
|
||||||
|
ng-tracker.debug_email=
|
||||||
ng-tracker.use-https=false
|
ng-tracker.use-https=false
|
||||||
ng-tracker.check-run=false
|
ng-tracker.check-run=false
|
13
src/main/resources/db/changelog-20190426_000000-schema.xml
Normal file
13
src/main/resources/db/changelog-20190426_000000-schema.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="vova" id="20190426_000000-1">
|
||||||
|
<addColumn tableName="event">
|
||||||
|
<column name="conference_id" type="integer"></column>
|
||||||
|
</addColumn>
|
||||||
|
<addForeignKeyConstraint baseTableName="event" baseColumnNames="conference_id"
|
||||||
|
constraintName="fk_event_conference_id" referencedTableName="conference"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
10
src/main/resources/db/changelog-20190428_000000-schema.xml
Normal file
10
src/main/resources/db/changelog-20190428_000000-schema.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="anton" id="20190428_000000-1">
|
||||||
|
<update tableName="project">
|
||||||
|
<column name="status" value="APPLICATION"/>
|
||||||
|
</update>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
11
src/main/resources/db/changelog-20190430_000000-schema.xml
Normal file
11
src/main/resources/db/changelog-20190430_000000-schema.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="tanya" id="20190430_000000-1">
|
||||||
|
<dropColumn columnName="file_id" tableName="grants"/>
|
||||||
|
<addColumn tableName="file">
|
||||||
|
<column name="grant_id" type="integer"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
15
src/main/resources/db/changelog-20190505_000000-schema.xml
Normal file
15
src/main/resources/db/changelog-20190505_000000-schema.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
|
||||||
|
<changeSet author="tanya" id="20190505_000000-1">
|
||||||
|
<addColumn tableName="event">
|
||||||
|
<column name="grant_id" type="integer"/>
|
||||||
|
</addColumn>
|
||||||
|
<addForeignKeyConstraint baseTableName="event" baseColumnNames="grant_id"
|
||||||
|
constraintName="fk_event_grant_id" referencedTableName="grants"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
25
src/main/resources/db/changelog-20190505_000001-schema.xml
Normal file
25
src/main/resources/db/changelog-20190505_000001-schema.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
|
||||||
|
<changeSet author="nastya" id="20190505_000001-1">
|
||||||
|
<createTable tableName="scheduler">
|
||||||
|
<column name="id" type="integer">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="task_id" type="integer">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="date" type="timestamp">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey columnNames="id" constraintName="pk_scheduler" tableName="scheduler"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="scheduler" baseColumnNames="task_id"
|
||||||
|
constraintName="fk_scheduler_task_id" referencedTableName="task"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="tanya" id="20190507_000000-1">
|
||||||
|
<dropColumn columnName="deadline_date" tableName="grants"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
14
src/main/resources/db/changelog-20190507_000001-schema.xml
Normal file
14
src/main/resources/db/changelog-20190507_000001-schema.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="tanya" id="20190507_000001-1">
|
||||||
|
<sql>
|
||||||
|
update grants
|
||||||
|
set leader_id =
|
||||||
|
(select u.id
|
||||||
|
from users u
|
||||||
|
where u.last_name = 'Романов' AND u.first_name = 'Антон');
|
||||||
|
</sql>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
13
src/main/resources/db/changelog-20190511_000000-schema.xml
Normal file
13
src/main/resources/db/changelog-20190511_000000-schema.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="nastya" id="20190511_000000-1">
|
||||||
|
<addColumn tableName="event">
|
||||||
|
<column name="task_id" type="integer"></column>
|
||||||
|
</addColumn>
|
||||||
|
<addForeignKeyConstraint baseTableName="event" baseColumnNames="task_id"
|
||||||
|
constraintName="fk_event_task_id" referencedTableName="task"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="tanya" id="20190520_000000-1">
|
||||||
|
<dropColumn columnName="applicationFileName" tableName="grants"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
27
src/main/resources/db/changelog-20190523_000000-schema.xml
Normal file
27
src/main/resources/db/changelog-20190523_000000-schema.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="masha" id="20190523_000000-1">
|
||||||
|
<createTable tableName="reference">
|
||||||
|
<column name="id" type="integer">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="authors" type="varchar(255)"/>
|
||||||
|
<column name="publication_title" type="varchar(255)"/>
|
||||||
|
<column name="publication_year" type="integer"/>
|
||||||
|
<column name="paper_id" type="integer"/>
|
||||||
|
<column name="publisher" type="varchar(255)"/>
|
||||||
|
<column name="pages" type="varchar(255)"/>
|
||||||
|
<column name="journal_or_collection_title" type="varchar(255)"/>
|
||||||
|
<column name="reference_type" type="varchar(255)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey columnNames="id" constraintName="pk_reference" tableName="reference"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="reference" baseColumnNames="paper_id"
|
||||||
|
constraintName="fk_reference_paper_id" referencedTableName="paper"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -34,4 +34,14 @@
|
|||||||
<include file="db/changelog-20190421_000000-schema.xml"/>
|
<include file="db/changelog-20190421_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20190422_000000-schema.xml"/>
|
<include file="db/changelog-20190422_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20190424_000000-schema.xml"/>
|
<include file="db/changelog-20190424_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190426_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190428_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190430_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190505_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190505_000001-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190507_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190507_000001-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190511_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190520_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190523_000000-schema.xml"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
0
src/main/resources/drivers/chromedriver
Normal file → Executable file
0
src/main/resources/drivers/chromedriver
Normal file → Executable file
0
src/main/resources/drivers/geckodriver
Normal file → Executable file
0
src/main/resources/drivers/geckodriver
Normal file → Executable file
@ -0,0 +1,30 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Уведомление о создании конференции</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Была создана новая конференция: "<a th:href="@{|${baseUrl}/conferences/conference?id=${conference.id}|}">
|
||||||
|
<span th:text="${conference.title}">Title</span></a>".
|
||||||
|
<br/>
|
||||||
|
Спешите принять участие!
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Даты проведения:
|
||||||
|
<span th:text="${#dates.format(conference.beginDate, 'dd.MM.yyyy')}"></span>
|
||||||
|
-
|
||||||
|
<span th:text="${#dates.format(conference.endDate, 'dd.MM.yyyy')}"></span>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>NG-tracker.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,29 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Уведомление о дедлайне конференции</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Приближается дедлайн конференции "<a th:href="@{|${baseUrl}/conferences/conference?id=${conference.id}|}">
|
||||||
|
<span th:text="${conference.title}">Title</span></a>".
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Срок исполнения: <b><span th:text="${#dates.format(conference.nextDeadline.get().date, 'dd.MM.yyyy')}"></span></b>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Примечание: <b><span th:text="${conference.nextDeadline.get().description}"></span></b>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>NG-tracker.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Обратите внимание на конференциию</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Конференция "<a th:href="@{|${baseUrl}/conferences/conference?id=${conference.id}|}">
|
||||||
|
<span th:text="${conference.title}">Title</span></a>" была пропингована
|
||||||
|
<b><span th:text="${conference.ping}"></span></b> раз.
|
||||||
|
<br/>
|
||||||
|
Обратите внимание.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>NG-tracker.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,31 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Уведомление об изменении дат проведения конференции</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Даты проведения конференции "<a th:href="@{|${baseUrl}/conferences/conference?id=${conference.id}|}">
|
||||||
|
<span th:text="${conference.title}">Title</span></a>" изменились с <br/>
|
||||||
|
"<span th:text="${#dates.format(oldBeginDate, 'dd.MM.yyyy')}">oldBeginDate</span>"
|
||||||
|
-
|
||||||
|
"<span th:text="${#dates.format(oldEndDate, 'dd.MM.yyyy')}">oldEndDate</span>"
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
на <br/>
|
||||||
|
"<span th:text="${#dates.format(conference.beginDate, 'dd.MM.yyyy')}"></span>"
|
||||||
|
-
|
||||||
|
"<span th:text="${#dates.format(conference.endDate, 'dd.MM.yyyy')}"></span>".
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>NG-tracker.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Уведомление об изменении дедлайнов конференции</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Дедлайны конференции "<a th:href="@{|${baseUrl}/conferences/conference?id=${conference.id}|}">
|
||||||
|
<span th:text="${conference.title}">Title</span></a>" притерпели изменения.
|
||||||
|
<br/>
|
||||||
|
Ознакомтесь с изменениями.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>NG-tracker.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Уведомление об изменении состава рабочей группы</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Состав рабочей группы гранта "<a th:href="@{|${baseUrl}/grants/grant?id=${grant.id}|}"><span
|
||||||
|
th:text="${grant.title}">Title</span></a>" сменился с
|
||||||
|
" <span th:each="author : ${oldAuthors}" th:text="${author.lastName + ' '}">oldAuthors</span>"
|
||||||
|
на " <span th:each="author : ${grant.authors}" th:text="${author.lastName + ' '}">newAuthors</span>".
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>NG-tracker.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,28 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Уведомление о создании гранта</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Был добавлен новый грант: "<a th:href="@{|${baseUrl}/grants/grant?id=${grant.id}|}">
|
||||||
|
<span th:text="${grant.title}">Title</span></a>".
|
||||||
|
<br/>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Руководитель гранта:
|
||||||
|
<span th:text="${grant.leader.firstName}"></span>
|
||||||
|
<span th:text="${grant.leader.lastName}">Leader</span>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>NG-tracker.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,28 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Уведомление о дедлайне гранта</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Приближается дедлайн гранта "<a th:href="@{|${baseUrl}/grants/grant?id=${grant.id}|}"><span
|
||||||
|
th:text="${grant.title}">Title</span></a>".
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Срок исполнения: <b><span th:text="${#dates.format(grant.nextDeadline.get().date, 'dd.MM.yyyy')}">Date</span></b>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Примечание: <b><span th:text="${grant.nextDeadline.get().description}">Description</span></b>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>NG-tracker.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Уведомление об изменении руководителя гранта</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Руководитель гранта "<a th:href="@{|${baseUrl}/grants/grant?id=${grant.id}|}"><span
|
||||||
|
th:text="${grant.title}">Title</span></a>" сменился с
|
||||||
|
"<span th:text="${oldLeader.lastName} ">oldLeader</span>"
|
||||||
|
на "<span th:text="${grant.leader.lastName}">newLeader</span>".
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>NG-tracker.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
21
src/main/resources/mail_templates/passwordChangeEmail.html
Normal file
21
src/main/resources/mail_templates/passwordChangeEmail.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Password reset</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Dear <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Your password has been changed.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>Balance Team.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,23 +1,19 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<head>
|
<head>
|
||||||
<title>Password reset</title>
|
<title>Восстановление пароля</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>
|
<p>
|
||||||
Dear <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
Дорогой <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
For your account a password reset was requested, please click on the URL below to
|
Ваш ключ для восстановления пароля <span th:text="${user.resetKey}"></span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<a th:href="@{|${baseUrl}/reset?key=${user.resetKey}|}"
|
С уважением,
|
||||||
th:text="@{|${baseUrl}/reset?key=${user.resetKey}|}">Reset Link</a>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Regards,
|
|
||||||
<br/>
|
<br/>
|
||||||
<em>Balance Team.</em>
|
<em>Balance Team.</em>
|
||||||
</p>
|
</p>
|
||||||
|
21
src/main/resources/mail_templates/userInviteEmail.html
Normal file
21
src/main/resources/mail_templates/userInviteEmail.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Account activation</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
|
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Аккаунт в системе NG-Tracker был создан. <br />
|
||||||
|
Данные для входа: <br />
|
||||||
|
Логин - <span th:text="${email}"></span> <br />
|
||||||
|
Пароль - <span th:text="${password}"></span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Regards,
|
||||||
|
<br/>
|
||||||
|
<em>Balance Team.</em>
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
3
src/main/resources/public/css/base.css
Normal file
3
src/main/resources/public/css/base.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.loader {
|
||||||
|
padding-left:50%
|
||||||
|
}
|
@ -7,6 +7,10 @@ body {
|
|||||||
border-radius: .25rem;
|
border-radius: .25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.conference-row .d-flex:hover .icon-delete {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
.filter-option-inner-inner {
|
.filter-option-inner-inner {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
@ -17,10 +21,26 @@ body {
|
|||||||
|
|
||||||
.conference-row .d-flex .text-decoration {
|
.conference-row .d-flex .text-decoration {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.conference-row .d-flex .text-decoration:nth-child(1) {
|
||||||
|
margin-left: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.conference-row .d-flex .text-decoration:nth-child(1) {
|
.conference-row .d-flex .text-decoration span.h6.float-left.m-2 {
|
||||||
margin-left: 10px;
|
max-width: 470px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.conference-row .d-flex .icon-delete {
|
||||||
|
width: 29px;
|
||||||
|
height: 29px;
|
||||||
|
margin: auto;
|
||||||
|
border: none;
|
||||||
|
visibility: hidden;
|
||||||
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -126,6 +146,7 @@ body {
|
|||||||
|
|
||||||
.paper-name {
|
.paper-name {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.paper-name:hover {
|
.paper-name:hover {
|
||||||
@ -142,6 +163,15 @@ body {
|
|||||||
float: left;
|
float: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.paper-name span:nth-child(2) {
|
||||||
|
max-width: 326px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu {
|
||||||
|
max-width: 445px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
@ -159,7 +189,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.icon-delete:hover {
|
.icon-delete:hover {
|
||||||
background-color: #ff0000;
|
background-color: #ff0000 !important;
|
||||||
transition: background-color .15s ease-in-out;
|
transition: background-color .15s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,3 +29,15 @@
|
|||||||
.btn-delete-deadline {
|
.btn-delete-deadline {
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.div-file-name{
|
||||||
|
padding-top: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.div-loader {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.div-row-file {
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
@ -7,3 +7,34 @@
|
|||||||
.nav-tabs {
|
.nav-tabs {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#nav-references label, #nav-references select, #nav-references input {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-references .collapse-heading {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 5px 15px;
|
||||||
|
background-color: #efefef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-references .collapse-heading a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-references a:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav-references #formattedReferencesArea {
|
||||||
|
height: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-autocomplete {
|
||||||
|
max-height: 200px;
|
||||||
|
max-width: 400px;
|
||||||
|
overflow-y: scroll;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
@ -38,6 +38,65 @@
|
|||||||
width: auto;
|
width: auto;
|
||||||
max-width: inherit;
|
max-width: inherit;
|
||||||
}
|
}
|
||||||
|
.tag-info{
|
||||||
|
font-size: 10px;
|
||||||
|
color: white;
|
||||||
|
padding: 5px 15px;
|
||||||
|
background-color: black;
|
||||||
|
display: none;
|
||||||
|
margin-left: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
opacity: 0.8;
|
||||||
|
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-question-circle{
|
||||||
|
|
||||||
|
font-size: 15px;
|
||||||
|
color: #212529;
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fa-question-circle:hover .tag-info{
|
||||||
|
display:inline-block;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-row{
|
||||||
|
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-row .col:hover{
|
||||||
|
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-row .col > a{
|
||||||
|
display: block;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-row .col:hover .remove-task{
|
||||||
|
|
||||||
|
visibility: visible;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove-task{
|
||||||
|
visibility: hidden;
|
||||||
|
position: absolute;
|
||||||
|
right: -20px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
padding: 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove-task:hover{
|
||||||
|
|
||||||
|
background-color: #ebebeb;
|
||||||
|
}
|
||||||
|
|
||||||
.tag {
|
.tag {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
BIN
src/main/resources/public/img/main/ajax-loader.gif
Normal file
BIN
src/main/resources/public/img/main/ajax-loader.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 673 B |
@ -25,4 +25,5 @@ $(document).ready(function () {
|
|||||||
$('#dataConfirmModal').modal({show:true});
|
$('#dataConfirmModal').modal({show:true});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
var urlFileUpload = "/api/1.0/files/uploadTmpFile";
|
var urlFileUpload = "/api/1.0/files/uploadTmpFile";
|
||||||
var urlFileDownload = "/api/1.0/files/download/";
|
var urlFileDownload = "/api/1.0/files/download/";
|
||||||
var urlPdfGenerating = "/papers/generatePdf";
|
var urlPdfGenerating = "/papers/generatePdf";
|
||||||
|
var urlReferencesFormatting = "/papers/getFormattedReferences";
|
||||||
var urlFileDownloadTmp = "/api/1.0/files/download-tmp/";
|
var urlFileDownloadTmp = "/api/1.0/files/download-tmp/";
|
||||||
|
|
||||||
/* exported MessageTypesEnum */
|
/* exported MessageTypesEnum */
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user