diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 5aecb51..f9a4bac 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -74,12 +74,9 @@ public class ConferenceController { @PostMapping(value = "/conference", params = "save") public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { - conferenceService.filterEmptyDeadlines(conferenceDto); - conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors); - if (errors.hasErrors()) { + if (!conferenceService.save(conferenceDto, errors)) { return CONFERENCE_PAGE; } - conferenceService.save(conferenceDto); return String.format(REDIRECT_TO, CONFERENCES_PAGE); } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 2e2f13b..9c9b37a 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.name.NameContainer; import ru.ulstu.paper.model.Paper; import javax.persistence.Temporal; @@ -16,7 +17,7 @@ import java.util.List; import static ru.ulstu.core.util.StreamApiUtils.convert; -public class ConferenceDto { +public class ConferenceDto extends NameContainer { private final static String BEGIN_DATE = "Начало: "; private final static String END_DATE = "Конец: "; diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 3a8bbe1..2b0a428 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -5,12 +5,13 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; +import ru.ulstu.name.BaseRepository; import ru.ulstu.user.model.User; import java.util.Date; import java.util.List; -public interface ConferenceRepository extends JpaRepository { +public interface ConferenceRepository extends JpaRepository, BaseRepository { @Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " + "AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC") List findByUserAndYear(@Param("user") User user, @Param("year") Integer year); @@ -24,4 +25,8 @@ public interface ConferenceRepository extends JpaRepository @Modifying @Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id") int updatePingConference(@Param("id") Integer id); + + @Override + @Query("SELECT title FROM Conference c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ") + String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38de435..1754987 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -13,6 +13,7 @@ import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.name.BaseService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.ping.service.PingService; @@ -31,7 +32,7 @@ import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @Service -public class ConferenceService { +public class ConferenceService extends BaseService { private final static int MAX_DISPLAY_SIZE = 40; private final ConferenceRepository conferenceRepository; @@ -51,6 +52,7 @@ public class ConferenceService { PingService pingService, ConferenceNotificationService conferenceNotificationService, EventService eventService) { + this.baseRepository = conferenceRepository; this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; @@ -89,12 +91,26 @@ public class ConferenceService { return new ConferenceDto(conferenceRepository.findOne(id)); } - public void save(ConferenceDto conferenceDto) throws IOException { + public boolean save(ConferenceDto conferenceDto, Errors errors) throws IOException { + conferenceDto.setName(conferenceDto.getTitle()); + filterEmptyDeadlines(conferenceDto); + checkEmptyFieldsOfDeadline(conferenceDto, errors); + checkUniqueName(conferenceDto, + errors, + conferenceDto.getId(), + "title", + "Конференция с таким именем уже существует"); + if (errors.hasErrors()) { + return false; + } + if (isEmpty(conferenceDto.getId())) { create(conferenceDto); } else { update(conferenceDto); } + + return true; } @Transactional @@ -127,6 +143,7 @@ public class ConferenceService { @Transactional public void delete(Integer conferenceId) { if (conferenceRepository.exists(conferenceId)) { + eventService.removeConferencesEvent(conferenceRepository.findOne(conferenceId)); conferenceRepository.delete(conferenceId); } } @@ -280,7 +297,6 @@ public class ConferenceService { } } - public void filterEmptyDeadlines(ConferenceDto conferenceDto) { conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/core/util/DateUtils.java b/src/main/java/ru/ulstu/core/util/DateUtils.java index 6122583..3a38452 100644 --- a/src/main/java/ru/ulstu/core/util/DateUtils.java +++ b/src/main/java/ru/ulstu/core/util/DateUtils.java @@ -54,4 +54,10 @@ public class DateUtils { cal.add(Calendar.DAY_OF_MONTH, count); return cal.getTime(); } + + public static Date addYears(Date date, int count) { + Calendar cal = getCalendar(date); + cal.add(Calendar.YEAR, count); + return cal.getTime(); + } } diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 85a0cd9..ad5e992 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -13,7 +13,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.service.GrantService; -import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.model.PaperDto; import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; @@ -104,7 +104,6 @@ public class GrantController { return GRANT_PAGE; } - @PostMapping(value = "/grant", params = "createProject") public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException { if (errors.hasErrors()) { @@ -131,8 +130,8 @@ public class GrantController { } @ModelAttribute("allPapers") - public List getAllPapers() { - return grantService.getAllPapers(); + public List getAllPapers() { + return grantService.getAllUncompletedPapers(); } private void filterEmptyDeadlines(GrantDto grantDto) { diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 760895e..e0cd9be 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -74,7 +74,6 @@ public class Grant extends BaseEntity implements UserContainer { @Fetch(FetchMode.SUBSELECT) private List files = new ArrayList<>(); - @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "project_id") private Project project; diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index e842b10..203d306 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileDataDto; -import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.model.PaperDto; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.user.model.UserDto; @@ -37,7 +37,7 @@ public class GrantDto { private boolean hasBAKPapers; private boolean hasScopusPapers; private List paperIds = new ArrayList<>(); - private List papers = new ArrayList<>(); + private List papers = new ArrayList<>(); private List removedDeadlineIds = new ArrayList<>(); public GrantDto() { @@ -54,12 +54,12 @@ public class GrantDto { @JsonProperty("project") ProjectDto project, @JsonProperty("authorIds") Set authorIds, @JsonProperty("authors") Set authors, - @JsonProperty("leader") Integer leaderId, + @JsonProperty("leaderId") Integer leaderId, @JsonProperty("wasLeader") boolean wasLeader, @JsonProperty("hasAge") boolean hasAge, @JsonProperty("hasDegree") boolean hasDegree, @JsonProperty("paperIds") List paperIds, - @JsonProperty("papers") List papers) { + @JsonProperty("papers") List papers) { this.id = id; this.title = title; this.status = status; @@ -92,7 +92,7 @@ public class GrantDto { this.hasAge = false; this.hasDegree = false; this.paperIds = convert(grant.getPapers(), paper -> paper.getId()); - this.papers = grant.getPapers(); + this.papers = convert(grant.getPapers(), PaperDto::new); } public Integer getId() { @@ -214,11 +214,11 @@ public class GrantDto { this.paperIds = paperIds; } - public List getPapers() { + public List getPapers() { return papers; } - public void setPapers(List papers) { + public void setPapers(List papers) { this.papers = papers; } diff --git a/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java new file mode 100644 index 0000000..677b38f --- /dev/null +++ b/src/main/java/ru/ulstu/grant/service/GrantNotificationService.java @@ -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 grants, boolean isDeadlineBeforeWeek) { + Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION); + grants.stream() + .filter(grant -> needToSendDeadlineNotification(grant, now, isDeadlineBeforeWeek)) + .forEach(grant -> sendMessageDeadline(grant)); + } + + private boolean needToSendDeadlineNotification(Grant grant, Date compareDate, boolean isDeadlineBeforeWeek) { + return (grant.getNextDeadline().isPresent()) + && (compareDate.before(grant.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek + || compareDate.after(grant.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek) + && grant.getNextDeadline().get().getDate().after(new Date()); + } + + private void sendMessageDeadline(Grant grant) { + Map variables = ImmutableMap.of("grant", grant); + sendForAllAuthors(variables, grant, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, grant.getTitle())); + } + + public void sendCreateNotification(Grant grant) { + Map variables = ImmutableMap.of("grant", grant); + sendForAllAuthors(variables, grant, TEMPLATE_CREATE, String.format(TITLE_CREATE, grant.getTitle())); + } + + public void sendAuthorsChangeNotification(Grant grant, Set oldAuthors) { + Map variables = ImmutableMap.of("grant", grant, "oldAuthors", oldAuthors); + sendForAllAuthors(variables, grant, TEMPLATE_AUTHORS_CHANGED, String.format(TITLE_AUTHORS_CHANGED, grant.getTitle())); + } + + public void sendLeaderChangeNotification(Grant grant, User oldLeader) { + Map variables = ImmutableMap.of("grant", grant, "oldLeader", oldLeader); + sendForAllAuthors(variables, grant, TEMPLATE_LEADER_CHANGED, String.format(TITLE_LEADER_CHANGED, grant.getTitle())); + } + + private void sendForAllAuthors(Map variables, Grant grant, String template, String title) { + Set allAuthors = grant.getAuthors(); + allAuthors.forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title)); + mailService.sendEmailFromTemplate(variables, grant.getLeader(), template, title); + } +} diff --git a/src/main/java/ru/ulstu/grant/service/GrantScheduler.java b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java new file mode 100644 index 0000000..1c38c4a --- /dev/null +++ b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java @@ -0,0 +1,30 @@ +package ru.ulstu.grant.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +public class GrantScheduler { + private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; + + private final Logger log = LoggerFactory.getLogger(GrantScheduler.class); + + private final GrantNotificationService grantNotificationService; + private final GrantService grantService; + + public GrantScheduler(GrantNotificationService grantNotificationService, + GrantService grantService) { + this.grantNotificationService = grantNotificationService; + this.grantService = grantService; + } + + + @Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara") + public void checkDeadlineBeforeWeek() { + log.debug("GrantScheduler.checkDeadlineBeforeWeek started"); + grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); + log.debug("GrantScheduler.checkDeadlineBeforeWeek finished"); + } +} diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 9cff4b6..45f9b2f 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -11,6 +11,7 @@ import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.service.PaperService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -23,7 +24,9 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static java.util.stream.Collectors.toList; import static org.springframework.util.ObjectUtils.isEmpty; @@ -32,7 +35,7 @@ import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @Service public class GrantService { - private final static int MAX_DISPLAY_SIZE = 40; + private final static int MAX_DISPLAY_SIZE = 50; private final GrantRepository grantRepository; private final ProjectService projectService; @@ -41,6 +44,7 @@ public class GrantService { private final UserService userService; private final PaperService paperService; private final EventService eventService; + private final GrantNotificationService grantNotificationService; public GrantService(GrantRepository grantRepository, FileService fileService, @@ -48,7 +52,8 @@ public class GrantService { ProjectService projectService, UserService userService, PaperService paperService, - EventService eventService) { + EventService eventService, + GrantNotificationService grantNotificationService) { this.grantRepository = grantRepository; this.fileService = fileService; this.deadlineService = deadlineService; @@ -56,6 +61,7 @@ public class GrantService { this.userService = userService; this.paperService = paperService; this.eventService = eventService; + this.grantNotificationService = grantNotificationService; } public List findAll() { @@ -77,6 +83,7 @@ public class GrantService { Grant newGrant = copyFromDto(new Grant(), grantDto); newGrant = grantRepository.save(newGrant); eventService.createFromGrant(newGrant); + grantNotificationService.sendCreateNotification(newGrant); return newGrant.getId(); } @@ -113,6 +120,8 @@ public class GrantService { @Transactional public Integer update(GrantDto grantDto) throws IOException { Grant grant = grantRepository.findOne(grantDto.getId()); + Set oldAuthors = new HashSet<>(grant.getAuthors()); + User oldLeader = grant.getLeader(); for (FileDataDto file : grantDto.getFiles().stream() .filter(f -> f.isDeleted() && f.getId() != null) .collect(toList())) { @@ -120,6 +129,20 @@ public class GrantService { } grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove); grantRepository.save(copyFromDto(grant, grantDto)); + + grant.getAuthors().forEach(author -> { + if (!oldAuthors.contains(author)) { + grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors); + } + }); + oldAuthors.forEach(oldAuthor -> { + if (!grant.getAuthors().contains(oldAuthor)) { + grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors); + } + }); + if (grant.getLeader() != oldLeader) { + grantNotificationService.sendLeaderChangeNotification(grant, oldLeader); + } eventService.updateGrantDeadlines(grant); return grant.getId(); } @@ -148,6 +171,7 @@ public class GrantService { grant = grantRepository.save(grant); eventService.createFromGrant(grant); + grantNotificationService.sendCreateNotification(grant); return grant; } @@ -187,13 +211,16 @@ public class GrantService { .collect(toList()); } - public List getGrantPapers(List paperIds) { + public List getGrantPapers(List paperIds) { return paperService.findAllSelect(paperIds); - } - public List getAllPapers() { - return paperService.findAll(); + public List getAllUncompletedPapers() { + List papers = paperService.findAllNotCompleted(); + papers.stream() + .forEach(paper -> + paper.setTitle(StringUtils.abbreviate(paper.getTitle(), MAX_DISPLAY_SIZE))); + return papers; } public void attachPaper(GrantDto grantDto) { @@ -218,7 +245,6 @@ public class GrantService { .filter(paper -> paper.getAuthors() != null) .flatMap(paper -> paper.getAuthors().stream()) .collect(toList()); - } private List getBAKAuthors() { diff --git a/src/main/java/ru/ulstu/name/BaseRepository.java b/src/main/java/ru/ulstu/name/BaseRepository.java new file mode 100644 index 0000000..b691ea2 --- /dev/null +++ b/src/main/java/ru/ulstu/name/BaseRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.name; + +import org.springframework.data.repository.query.Param; + +public interface BaseRepository { + String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id); +} diff --git a/src/main/java/ru/ulstu/name/BaseService.java b/src/main/java/ru/ulstu/name/BaseService.java new file mode 100644 index 0000000..6619385 --- /dev/null +++ b/src/main/java/ru/ulstu/name/BaseService.java @@ -0,0 +1,16 @@ +package ru.ulstu.name; + +import org.springframework.stereotype.Service; +import org.springframework.validation.Errors; + +@Service +public abstract class BaseService { + + public BaseRepository baseRepository; + + public void checkUniqueName(NameContainer nameContainer, Errors errors, Integer id, String checkField, String errorMessage) { + if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) { + errors.rejectValue(checkField, "errorCode", errorMessage); + } + } +} diff --git a/src/main/java/ru/ulstu/name/NameContainer.java b/src/main/java/ru/ulstu/name/NameContainer.java new file mode 100644 index 0000000..4339fb2 --- /dev/null +++ b/src/main/java/ru/ulstu/name/NameContainer.java @@ -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; + } +} diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 65bd32c..4536ce5 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -3,10 +3,12 @@ package ru.ulstu.paper.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserContainer; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; +import ru.ulstu.grant.model.Grant; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; @@ -114,6 +116,12 @@ public class Paper extends BaseEntity implements UserContainer { @Column(name = "latex_text") private String latexText; + @ManyToMany(mappedBy = "papers") + private List conferences; + + @ManyToMany(mappedBy = "papers") + private List grants; + public PaperStatus getStatus() { return status; } @@ -218,6 +226,22 @@ public class Paper extends BaseEntity implements UserContainer { this.latexText = latexText; } + public List getConferences() { + return conferences; + } + + public void setConferences(List conferences) { + this.conferences = conferences; + } + + public List getGrants() { + return grants; + } + + public void setGrants(List grants) { + this.grants = grants; + } + @Override public Set getUsers() { return getAuthors(); diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index f935247..42d3703 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -18,4 +18,10 @@ public interface PaperRepository extends JpaRepository { List findAllByIdIn(List paperIds); List findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status); + + List findByStatusNot(Paper.PaperStatus status); + + List findByConferencesIsNullAndStatusNot(Paper.PaperStatus status); + + List findByIdNotInAndConferencesIsNullAndStatusNot(List paperIds, Paper.PaperStatus status); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index f98997d..db810f5 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -242,15 +242,18 @@ public class PaperService { public List findAllNotSelect(List paperIds) { if (!paperIds.isEmpty()) { - return sortPapers(paperRepository.findByIdNotIn(paperIds)); + return sortPapers(paperRepository.findByIdNotInAndConferencesIsNullAndStatusNot(paperIds, COMPLETED)); } else { - return sortPapers(paperRepository.findAll()); + return sortPapers(paperRepository.findByConferencesIsNullAndStatusNot(COMPLETED)); } + } + public List findAllNotCompleted() { + return convert(paperRepository.findByStatusNot(COMPLETED), PaperDto::new); } - public List findAllSelect(List paperIds) { - return sortPapers(paperRepository.findAllByIdIn(paperIds)); + public List findAllSelect(List paperIds) { + return convert(paperRepository.findAllByIdIn(paperIds), PaperDto::new); } public List getPaperAuthors() { diff --git a/src/main/java/ru/ulstu/students/model/Scheduler.java b/src/main/java/ru/ulstu/students/model/Scheduler.java new file mode 100644 index 0000000..67005b1 --- /dev/null +++ b/src/main/java/ru/ulstu/students/model/Scheduler.java @@ -0,0 +1,49 @@ +package ru.ulstu.students.model; + +import org.springframework.format.annotation.DateTimeFormat; +import ru.ulstu.core.model.BaseEntity; + +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.Date; + +@Entity +@Table(name = "scheduler") +public class Scheduler extends BaseEntity { + + @OneToOne(optional = false) + @JoinColumn(name = "task_id") + private Task task; + + @Temporal(value = TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date date; + + public Scheduler() { + } + + public Scheduler(Task task, Date date) { + this.task = task; + this.date = date; + } + + public Task getTask() { + return task; + } + + public void setTask(Task task) { + this.task = task; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } +} diff --git a/src/main/java/ru/ulstu/students/model/Task.java b/src/main/java/ru/ulstu/students/model/Task.java index 8ec9081..2a03e37 100644 --- a/src/main/java/ru/ulstu/students/model/Task.java +++ b/src/main/java/ru/ulstu/students/model/Task.java @@ -67,6 +67,7 @@ public class Task extends BaseEntity { private Date updateDate = new Date(); @ManyToMany(fetch = FetchType.EAGER) + @Fetch(FetchMode.SUBSELECT) @JoinTable(name = "task_tags", joinColumns = {@JoinColumn(name = "task_id")}, inverseJoinColumns = {@JoinColumn(name = "tag_id")}) @@ -127,4 +128,5 @@ public class Task extends BaseEntity { public void setTags(List tags) { this.tags = tags; } + } diff --git a/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java b/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java new file mode 100644 index 0000000..7481692 --- /dev/null +++ b/src/main/java/ru/ulstu/students/repository/SchedulerRepository.java @@ -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 findOneByTask(Task task); + +} diff --git a/src/main/java/ru/ulstu/students/repository/TaskRepository.java b/src/main/java/ru/ulstu/students/repository/TaskRepository.java index ee49ab8..af277d1 100644 --- a/src/main/java/ru/ulstu/students/repository/TaskRepository.java +++ b/src/main/java/ru/ulstu/students/repository/TaskRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.repository.query.Param; import ru.ulstu.students.model.Task; import ru.ulstu.tags.model.Tag; +import java.util.Date; import java.util.List; public interface TaskRepository extends JpaRepository { @@ -15,4 +16,12 @@ public interface TaskRepository extends JpaRepository { @Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date ASC") List filterOld(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag); + + @Query("SELECT t FROM Task t WHERE(:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC") + List findByTag(@Param("tag") Tag tag); + + @Query("SELECT t FROM Task t WHERE (t.createDate >= :date) ORDER BY create_date DESC") + List findAllYear(@Param("date") Date date); + + } diff --git a/src/main/java/ru/ulstu/students/service/SchedulerService.java b/src/main/java/ru/ulstu/students/service/SchedulerService.java new file mode 100644 index 0000000..9d14926 --- /dev/null +++ b/src/main/java/ru/ulstu/students/service/SchedulerService.java @@ -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 taskList = taskService.findTasksByTag(tag); + create(taskList.get(0)); + } + + + @Transactional + private Scheduler create(Task task) { + Scheduler scheduler = new Scheduler(task, task.getDeadlines().get(task.getDeadlines().size() - 1).getDate()); + return schedulerRepository.save(scheduler); + } + + @Transactional + private void delete(Integer schedulerId) { + if (schedulerRepository.exists(schedulerId)) { + schedulerRepository.delete(schedulerId); + } + } + + public void checkPlanToday() { + List schedulerList = schedulerRepository.findAll(); + if (!schedulerList.isEmpty()) { + doTodayPlanIfNeed(schedulerList); + schedulerList = schedulerRepository.findAll(); + } + checkNewPlan(schedulerList); + } + + private void checkNewPlan(List schedulerList) { + Set tags = taskService.checkRepeatingTags(true); + Set 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 schedulerList) { + + return schedulerList + .stream() + .anyMatch(scheduler -> scheduler.getTask().getTags().contains(tag)); + + } + + + private Set checkNewTags(Set tags, List schedulerList) { + Set newTags = tags + .stream() + .filter(tag -> schedulerList + .stream() + .anyMatch(scheduler -> + !scheduler.getTask().getTags().contains(tag))) + .collect(Collectors.toSet()); + if (!newTags.isEmpty()) { + return newTags; + } + return null; + } + + private void doTodayPlanIfNeed(List schedulerList) { + List plan = schedulerList + .stream() + .filter(scheduler -> scheduler.getDate().before(new Date())) + .collect(Collectors.toList()); + doToday(plan); + } + + private void doToday(List plan) { + plan.forEach(scheduler -> { + taskService.createPeriodTask(scheduler); + delete(scheduler.getId()); + }); + } + + +} diff --git a/src/main/java/ru/ulstu/students/service/TaskGenerationService.java b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java new file mode 100644 index 0000000..1c04c20 --- /dev/null +++ b/src/main/java/ru/ulstu/students/service/TaskGenerationService.java @@ -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"); + } + +} diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index a8747c7..2be44cb 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -4,18 +4,29 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.core.util.DateUtils; +import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.students.model.Scheduler; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; import ru.ulstu.students.model.TaskFilterDto; +import ru.ulstu.students.repository.SchedulerRepository; import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.tags.model.Tag; import ru.ulstu.tags.service.TagService; +import ru.ulstu.timeline.service.EventService; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; 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 TaskRepository taskRepository; + private final SchedulerRepository schedulerRepository; private final DeadlineService deadlineService; private final TagService tagService; + private final EventService eventService; + public TaskService(TaskRepository taskRepository, - DeadlineService deadlineService, TagService tagService) { + DeadlineService deadlineService, TagService tagService, SchedulerRepository schedulerRepository, EventService eventService) { this.taskRepository = taskRepository; this.deadlineService = deadlineService; this.tagService = tagService; + this.eventService = eventService; + this.schedulerRepository = schedulerRepository; } public List findAll() { @@ -67,6 +83,7 @@ public class TaskService { public Integer create(TaskDto taskDto) throws IOException { Task newTask = copyFromDto(new Task(), taskDto); newTask = taskRepository.save(newTask); + eventService.createFromTask(newTask); return newTask.getId(); } @@ -86,12 +103,18 @@ public class TaskService { public Integer update(TaskDto taskDto) throws IOException { Task task = taskRepository.findOne(taskDto.getId()); taskRepository.save(copyFromDto(task, taskDto)); + eventService.updateTaskDeadlines(task); return task.getId(); } @Transactional public void delete(Integer taskId) throws IOException { if (taskRepository.exists(taskId)) { + Task scheduleTask = taskRepository.findOne(taskId); + Scheduler sch = schedulerRepository.findOneByTask(scheduleTask); + if (sch != null) { + schedulerRepository.delete(sch.getId()); + } taskRepository.delete(taskId); } @@ -105,6 +128,110 @@ public class TaskService { } } + public void copyMainPart(Task newTask, Task task) { + newTask.setTitle(task.getTitle()); + newTask.setTags(tagService.saveOrCreate(task.getTags())); + newTask.setCreateDate(new Date()); + newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS); + } + + public 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 newDatesDeadlines(List deadlines, Integer interval) { + return deadlines + .stream() + .map(deadline -> { + Deadline newDeadline = new Deadline(); + Date newDate = DateUtils.addDays(deadline.getDate(), interval); + newDeadline.setDescription(deadline.getDescription()); + newDeadline.setDate(newDate); + return deadlineService.create(newDeadline); + }).collect(Collectors.toList()); + } + + public Task copyTaskWithNewYear(Task task) { + Task newTask = new Task(); + copyMainPart(newTask, task); + newTask.setDeadlines(newYearDeadlines(task.getDeadlines())); + return newTask; + } + + private List newYearDeadlines(List deadlines) { + return deadlines + .stream() + .map(deadline -> { + Deadline newDeadline = new Deadline(); + 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 void generateYearTasks() { + Set tags = checkRepeatingTags(false); + List 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); + }); + } + } + + + @Transactional + public Set checkRepeatingTags(Boolean createPeriodTask) { //param: false = year task; true = period task + Map tagsCount = new TreeMap<>(); + List tags = tagService.getTags(); + List tasks = taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1))); + tags.forEach(tag -> + tagsCount.put(tag, tasks + .stream() + .filter(task -> task.getTags().contains(tag)) + .count())); + if (!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 getTaskStatuses() { return Arrays.asList(Task.TaskStatus.values()); } @@ -113,4 +240,13 @@ public class TaskService { return tagService.getTags(); } + public List findTasksByTag(Tag tag) { + return taskRepository.findByTag(tag); + } + + @Transactional + public void createPeriodTask(Scheduler scheduler) { + Task newTask = copyTaskWithNewDates(scheduler.getTask()); + taskRepository.save(newTask); + } } diff --git a/src/main/java/ru/ulstu/tags/model/Tag.java b/src/main/java/ru/ulstu/tags/model/Tag.java index aed000f..e1c63d2 100644 --- a/src/main/java/ru/ulstu/tags/model/Tag.java +++ b/src/main/java/ru/ulstu/tags/model/Tag.java @@ -9,6 +9,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; import javax.validation.constraints.Size; +import java.util.Objects; @Entity @Table(name = "tag") @@ -41,4 +42,21 @@ public class Tag extends BaseEntity { public void setTagName(String tagName) { this.tagName = tagName; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Tag tag = (Tag) o; + return tagName.equals(tag.tagName); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), tagName); + } } diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index 9252cec..e56c91c 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -5,6 +5,7 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.students.model.Task; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; @@ -87,6 +88,10 @@ public class Event extends BaseEntity { @JoinColumn(name = "grant_id") private Grant grant; + @ManyToOne + @JoinColumn(name = "task_id") + private Task task; + public String getTitle() { return title; } @@ -190,4 +195,12 @@ public class Event extends BaseEntity { public void setGrant(Grant grant) { this.grant = grant; } + + public Task getTask() { + return task; + } + + public void setTask(Task task) { + this.task = task; + } } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index 89df5d8..ccf0f0a 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.students.model.TaskDto; import ru.ulstu.user.model.UserDto; import javax.validation.constraints.NotNull; @@ -29,6 +30,7 @@ public class EventDto { private PaperDto paperDto; private ConferenceDto conferenceDto; private GrantDto grantDto; + private TaskDto taskDto; @JsonCreator public EventDto(@JsonProperty("id") Integer id, @@ -42,7 +44,8 @@ public class EventDto { @JsonProperty("paperDto") PaperDto paperDto, @JsonProperty("recipients") List recipients, @JsonProperty("conferenceDto") ConferenceDto conferenceDto, - @JsonProperty("grantDto") GrantDto grantDto) { + @JsonProperty("grantDto") GrantDto grantDto, + @JsonProperty("taskDto") TaskDto taskDto) { this.id = id; this.title = title; this.period = period; @@ -55,6 +58,7 @@ public class EventDto { this.paperDto = paperDto; this.conferenceDto = conferenceDto; this.grantDto = grantDto; + this.taskDto = taskDto; } public EventDto(Event event) { @@ -76,6 +80,9 @@ public class EventDto { if (grantDto != null) { this.grantDto = new GrantDto(event.getGrant()); } + if (taskDto != null) { + this.taskDto = new TaskDto(event.getTask()); + } } public Integer getId() { @@ -137,4 +144,12 @@ public class EventDto { public void setGrantDto(GrantDto grantDto) { this.grantDto = grantDto; } + + public TaskDto getTaskDto() { + return taskDto; + } + + public void setTaskDto(TaskDto taskDto) { + this.taskDto = taskDto; + } } diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java index e01037a..7ebd3c9 100644 --- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java +++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query; import ru.ulstu.conference.model.Conference; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.students.model.Task; import ru.ulstu.timeline.model.Event; import java.util.List; @@ -21,4 +22,6 @@ public interface EventRepository extends JpaRepository { List findAllByConference(Conference conference); List findAllByGrant(Grant grant); + + List findAllByTask(Task task); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index b935f16..8c68291 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -8,6 +8,7 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.students.model.Task; import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.EventDto; import ru.ulstu.timeline.model.Timeline; @@ -203,4 +204,38 @@ public class EventService { eventRepository.delete(eventRepository.findAllByGrant(grant)); createFromGrant(grant); } + + public void removeConferencesEvent(Conference conference) { + List eventList = eventRepository.findAllByConference(conference); + eventList.forEach(event -> eventRepository.delete(event.getId())); + } + + public void createFromTask(Task newTask) { + List timelines = timelineService.findAll(); + Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); + + for (Deadline deadline : newTask.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн задачи"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' задачи '" + newTask.getTitle() + "'"); + newEvent.getRecipients().add(userService.getCurrentUser()); + newEvent.setTask(newTask); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + } + + public void updateTaskDeadlines(Task task) { + eventRepository.delete(eventRepository.findAllByTask(task)); + createFromTask(task); + } } diff --git a/src/main/resources/db/changelog-20190505_000000-schema.xml b/src/main/resources/db/changelog-20190505_000000-schema.xml index ac8707a..ad56dac 100644 --- a/src/main/resources/db/changelog-20190505_000000-schema.xml +++ b/src/main/resources/db/changelog-20190505_000000-schema.xml @@ -2,6 +2,7 @@ + diff --git a/src/main/resources/db/changelog-20190505_000001-schema.xml b/src/main/resources/db/changelog-20190505_000001-schema.xml new file mode 100644 index 0000000..1148d3a --- /dev/null +++ b/src/main/resources/db/changelog-20190505_000001-schema.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-20190507_000000-schema.xml b/src/main/resources/db/changelog-20190507_000000-schema.xml new file mode 100644 index 0000000..0cdb99b --- /dev/null +++ b/src/main/resources/db/changelog-20190507_000000-schema.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/src/main/resources/db/changelog-20190507_000001-schema.xml b/src/main/resources/db/changelog-20190507_000001-schema.xml new file mode 100644 index 0000000..c320eba --- /dev/null +++ b/src/main/resources/db/changelog-20190507_000001-schema.xml @@ -0,0 +1,14 @@ + + + + + update grants + set leader_id = + (select u.id + from users u + where u.last_name = 'Романов' AND u.first_name = 'Антон'); + + + diff --git a/src/main/resources/db/changelog-20190511_000000-schema.xml b/src/main/resources/db/changelog-20190511_000000-schema.xml new file mode 100644 index 0000000..62e914f --- /dev/null +++ b/src/main/resources/db/changelog-20190511_000000-schema.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 83ff280..18bd645 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -38,4 +38,8 @@ + + + + \ No newline at end of file diff --git a/src/main/resources/mail_templates/grantAuthorsChangeNotification.html b/src/main/resources/mail_templates/grantAuthorsChangeNotification.html new file mode 100644 index 0000000..2bae4fe --- /dev/null +++ b/src/main/resources/mail_templates/grantAuthorsChangeNotification.html @@ -0,0 +1,24 @@ + + + + Уведомление об изменении состава рабочей группы + + + + +

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

+

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

+

+ Regards, +
+ NG-tracker. +

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

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

+

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

+

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

+

+ Regards, +
+ NG-tracker. +

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

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

+

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

+

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

+

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

+

+ Regards, +
+ NG-tracker. +

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

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

+

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

+

+ Regards, +
+ NG-tracker. +

+ + diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index 73a96ae..dc83057 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -140,6 +140,7 @@ body { .paper-name { flex: 1; + overflow: hidden; } .paper-name:hover { @@ -156,6 +157,15 @@ body { float: left; } +.paper-name span:nth-child(2) { + max-width: 326px; + white-space: nowrap; +} + +.dropdown-menu { + max-width: 445px; +} + .icon { diff --git a/src/main/resources/public/css/tasks.css b/src/main/resources/public/css/tasks.css index 7e350ed..936dd84 100644 --- a/src/main/resources/public/css/tasks.css +++ b/src/main/resources/public/css/tasks.css @@ -38,6 +38,65 @@ width: auto; max-width: inherit; } +.tag-info{ + font-size: 10px; + color: white; + padding: 5px 15px; + background-color: black; + display: none; + margin-left: 5px; + border-radius: 5px; + opacity: 0.8; + font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; +} + +.fa-question-circle{ + + font-size: 15px; + color: #212529; + cursor:pointer; +} + +.fa-question-circle:hover .tag-info{ + display:inline-block; + +} + +.task-row{ + + position: relative; +} + +.task-row .col:hover{ + + background-color: #f8f9fa; + +} + +.task-row .col > a{ + display: block; + text-decoration: none; +} + +.task-row .col:hover .remove-task{ + + visibility: visible; + +} + +.remove-task{ + visibility: hidden; + position: absolute; + right: -20px; + top: 50%; + transform: translate(-50%, -50%); + padding: 0 20px; +} + +.remove-task:hover{ + + background-color: #ebebeb; +} .tag { display: inline-block; diff --git a/src/main/resources/public/js/conference.js b/src/main/resources/public/js/conference.js index 18a8c67..8273557 100644 --- a/src/main/resources/public/js/conference.js +++ b/src/main/resources/public/js/conference.js @@ -25,4 +25,5 @@ $(document).ready(function () { $('#dataConfirmModal').modal({show:true}); return false; }); + }); diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index f756199..f1cf868 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -19,8 +19,16 @@ $(document).ready(function () { $("#input-tag").keyup(function (event) { - if(event.keyCode == 13 || event.keyCode == 188) { + if(event.keyCode == 13) { var tagNumber = $("#tags .tag").length; + if(tagNumber > 0) { + tagNumber = $("#tags .tag").last() + .children('input') + .attr("name") + .split(']')[0] + .split('[')[1]; + tagNumber++; + } var tagName = $.trim($(this).val()); var addTag = true; // проверка, добавлен ли этот тег @@ -70,17 +78,17 @@ $(document).ready(function () { }); $("span[data-role=remove]").click(removeTag); - $(".task-row").mouseenter(function (event) { - var taskRow = $(event.target).closest(".task-row"); - $(taskRow).css("background-color", "#f8f9fa"); - $(taskRow).find(".remove-task").removeClass("d-none"); - - }); - $(".task-row").mouseleave(function (event) { - var taskRow = $(event.target).closest(".task-row"); - $(taskRow).css("background-color", "white"); - $(taskRow).closest(".task-row").find(".remove-task").addClass("d-none"); - }); +// $(".task-row").mouseenter(function (event) { +// var taskRow = $(event.target).closest(".task-row"); +// $(taskRow).css("background-color", "#f8f9fa"); +// $(taskRow).find(".remove-task").removeClass("d-none"); +// +// }); +// $(".task-row").mouseleave(function (event) { +// var taskRow = $(event.target).closest(".task-row"); +// $(taskRow).css("background-color", "white"); +// $(taskRow).closest(".task-row").find(".remove-task").addClass("d-none"); +// }); $('a[data-confirm]').click(function(ev) { var href = $(this).attr('href'); diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index d5906b6..d629d4e 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -30,11 +30,12 @@ -

Incorrect title

-

+

Incorrect title

+

+
diff --git a/src/main/resources/templates/students/fragments/taskLineFragment.html b/src/main/resources/templates/students/fragments/taskLineFragment.html index baad17e..210863d 100644 --- a/src/main/resources/templates/students/fragments/taskLineFragment.html +++ b/src/main/resources/templates/students/fragments/taskLineFragment.html @@ -6,15 +6,15 @@ diff --git a/src/main/resources/templates/students/task.html b/src/main/resources/templates/students/task.html index 968c7a0..3642221 100644 --- a/src/main/resources/templates/students/task.html +++ b/src/main/resources/templates/students/task.html @@ -52,7 +52,7 @@
- +
diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java new file mode 100644 index 0000000..269561f --- /dev/null +++ b/src/test/java/IndexConferenceTest.java @@ -0,0 +1,230 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import conference.ConferencePage; +import conference.ConferencesDashboardPage; +import conference.ConferencesPage; +import core.PageObject; +import core.TestTemplate; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import ru.ulstu.NgTrackerApplication; +import ru.ulstu.configuration.ApplicationProperties; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@RunWith(SpringRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class IndexConferenceTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new ConferencesPage(), Arrays.asList("КОНФЕРЕНЦИИ", "/conferences/conferences"), + new ConferencePage(), Arrays.asList("РЕДАКТИРОВАНИЕ КОНФЕРЕНЦИИ", "/conferences/conference?id=0"), + new ConferencesDashboardPage(), Arrays.asList("АКТУАЛЬНЫЕ КОНФЕРЕНЦИИ", "/conferences/dashboard") + ); + + @Autowired + private ApplicationProperties applicationProperties; + + @Test + public void testACreateNewConference() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(page.getKey()); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + + String newConferenceName = "test " + (new Date()).getTime(); + conferencePage.setName(newConferenceName); + conferencePage.clickSaveBut(); + + Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName)); + } + + @Test + public void testBChangeConferenceNameAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getFirstConference(); + String newConferenceName = "test " + (new Date()).getTime(); + conferencePage.clearName(); + conferencePage.setName(newConferenceName); + conferencePage.clickSaveBut(); + + Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName)); + } + + @Test + public void testCAddDeadlineAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getFirstConference(); + String conferenceId = conferencePage.getId(); + Integer deadlineCount = conferencePage.getDeadlineCount(); + + String description = "test"; + String date = "09.09.2019"; + String dateValue = "2019-09-09"; + conferencePage.clickAddDeadlineBut(); + conferencePage.setDeadlineDescription(description, deadlineCount); + conferencePage.setDeadlineDate(date, deadlineCount); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(conferencePage.checkDeadline(description, dateValue)); + } + + @Test + public void testDTakePartAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getFirstConference(); + String conferenceId = conferencePage.getId(); + Integer membersCount = conferencePage.getMemberCount(); + + conferencePage.clickTakePartBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(membersCount + 1 == conferencePage.getMemberCount() + && conferencePage.isTakePartButDisabledValueTrue()); + } + + @Test + public void testEDeleteDeadlineAndSave() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getFirstConference(); + String conferenceId = conferencePage.getId(); + Integer deadlineCount = conferencePage.getDeadlineCount(); + + conferencePage.clickDeleteDeadlineBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertEquals(deadlineCount - 1, (int) conferencePage.getDeadlineCount()); + } + + @Test + public void testFAttachArticle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getFirstConference(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getArticlesCount(); + + conferencePage.showAllowToAttachArticles(); + WebElement paper = conferencePage.selectArticle(); + String paperName = paper.findElement(By.className("text")).getText(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.checkArticle(paperName)); + } + + @Test + public void testGAddArticle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getFirstConference(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getArticlesCount(); + + conferencePage.clickAddPaperBut(); + List webElements = conferencePage.getArticles(); + String paperName = webElements.get(webElements.size() - 1).findElements(By.tagName("input")).get(1).getAttribute("value"); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.checkArticle(paperName)); + } + + @Test + public void testHUndockArticle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + conferencesPage.getFirstConference(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getArticlesCount(); + + conferencePage.clickUndockArticleBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertEquals(paperCount - 1, (int) conferencePage.getArticlesCount()); + } + + @Test + public void testISortAndFilterConferenceList() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + + conferencesPage.selectMember(); + conferencesPage.selectYear(); + + Assert.assertEquals(1, conferencesPage.getConferencesList().size()); + } + + @Test + public void testJDeleteConf() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); + + Integer size = conferencesPage.getConferencesList().size(); + conferencesPage.deleteFirst(); + Thread.sleep(3000); + conferencesPage.clickConfirm(); + + Assert.assertEquals(size - 1, conferencesPage.getConferencesList().size()); + } +} diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java new file mode 100644 index 0000000..ef0d941 --- /dev/null +++ b/src/test/java/conference/ConferencePage.java @@ -0,0 +1,116 @@ +package conference; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class ConferencePage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h3")).getText(); + } + + public String getId() { + return driver.findElement(By.id("id")).getAttribute("value"); + } + + public void setName(String name) { + driver.findElement(By.id("title")).sendKeys(name); + } + + public String getName() { + return driver.findElement(By.id("title")).getAttribute("value"); + } + + public void clearName() { + driver.findElement(By.id("title")).clear(); + } + + public void clickSaveBut() { + driver.findElement(By.id("send-message-button")).click(); + } + + public void clickAddDeadlineBut() { + driver.findElement(By.id("addDeadline")).click(); + } + + public List getDeadlineList() { + return driver.findElements(By.className("deadline")); + } + + public Integer getDeadlineCount() { + return driver.findElements(By.className("deadline")).size(); + } + + public void setDeadlineDescription(String description, Integer i) { + driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); + } + + public void setDeadlineDate(String date, Integer i) { + driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); + } + + public void clickTakePartBut() { + driver.findElement(By.id("take-part")).click(); + } + + public Boolean isTakePartButDisabledValueTrue() { + return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true"); + } + + public Integer getMemberCount() { + return driver.findElements(By.className("member")).size(); + } + + public void clickDeleteDeadlineBut() { + driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).click(); + } + + public void showAllowToAttachArticles() { + driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click(); + } + + public void clickAddPaperBut() { + driver.findElement(By.id("add-paper")).click(); + } + + + public List getArticles() { + return driver.findElements(By.className("paper")); + } + + public Integer getArticlesCount() { + return driver.findElements(By.className("paper")).size(); + } + + public WebElement selectArticle() { + WebElement webElement = driver.findElement(By.xpath("//*[@id=\"conference-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a")); + webElement.click(); + return webElement; + } + + public void clickUndockArticleBut() { + driver.findElement(By.name("removePaper")).click(); + } + + public boolean checkDeadline(String description, String dateValue) { + return getDeadlineList() + .stream() + .anyMatch(webElement -> { + return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description) + && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); + }); + } + + public boolean checkArticle(String paperName) { + return getArticles() + .stream() + .anyMatch(webElement -> webElement + .findElements(By.tagName("input")) + .get(1).getAttribute("value") + .equals(paperName)); + } + +} \ No newline at end of file diff --git a/src/test/java/conference/ConferencesDashboardPage.java b/src/test/java/conference/ConferencesDashboardPage.java new file mode 100644 index 0000000..d358c4a --- /dev/null +++ b/src/test/java/conference/ConferencesDashboardPage.java @@ -0,0 +1,11 @@ +package conference; + +import core.PageObject; +import org.openqa.selenium.By; + +public class ConferencesDashboardPage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h2")).getText(); + } +} diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java new file mode 100644 index 0000000..c11429f --- /dev/null +++ b/src/test/java/conference/ConferencesPage.java @@ -0,0 +1,47 @@ +package conference; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class ConferencesPage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h3")).getText(); + } + + public List getConferencesList() { + return driver.findElements(By.cssSelector("span.h6.float-left.m-2")); + } + + public void getFirstConference() { + driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click(); + } + + public void selectMember() { + driver.findElements(By.className("bootstrap-select")).get(0).findElement(By.className("btn")).click(); + driver.findElements(By.className("bootstrap-select")).get(0).findElements(By.className("dropdown-item")).get(1).click(); + } + + public void selectYear() { + driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click(); + driver.findElements(By.className("bootstrap-select")).get(1).findElements(By.className("dropdown-item")).get(1).click(); + } + + public void deleteFirst() { + js.executeScript("$('input[data-confirm]').click();"); + } + + public void clickConfirm() { + driver.findElement(By.id("deleteConference")).click(); + } + + + public boolean checkNameInList(String newConferenceName) { + return getConferencesList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(newConferenceName)); + } +} \ No newline at end of file diff --git a/src/test/java/core/PageObject.java b/src/test/java/core/PageObject.java index d1fae83..f3e5cb8 100644 --- a/src/test/java/core/PageObject.java +++ b/src/test/java/core/PageObject.java @@ -1,14 +1,17 @@ package core; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; public abstract class PageObject { protected WebDriver driver; + protected JavascriptExecutor js; public abstract String getSubTitle(); public PageObject setDriver(WebDriver driver) { this.driver = driver; + js = (JavascriptExecutor) driver; return this; } }