Merge remote-tracking branch 'origin/dev' into 93-activites-analytics
This commit is contained in:
commit
ea0b8fbaad
@ -126,6 +126,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'
|
||||||
|
|
||||||
}
|
}
|
@ -29,4 +29,8 @@ public interface ConferenceRepository extends JpaRepository<Conference, Integer>
|
|||||||
@Override
|
@Override
|
||||||
@Query("SELECT title FROM Conference c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ")
|
@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);
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
|
||||||
|
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " +
|
||||||
|
"AND (u.participation = 'INTRAMURAL') AND (c.beginDate <= CURRENT_DATE) AND (c.endDate >= CURRENT_DATE)")
|
||||||
|
Conference findActiveByUser(@Param("user") User user);
|
||||||
}
|
}
|
||||||
|
@ -313,4 +313,8 @@ public class ConferenceService extends BaseService {
|
|||||||
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Conference getActiveConferenceByUser(User user) {
|
||||||
|
return conferenceRepository.findActiveByUser(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,4 @@ public class ConferenceUserService {
|
|||||||
newUser = conferenceUserRepository.save(newUser);
|
newUser = conferenceUserRepository.save(newUser);
|
||||||
return newUser;
|
return newUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,15 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
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.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -20,6 +24,11 @@ public class Deadline extends BaseEntity {
|
|||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date date;
|
private Date date;
|
||||||
|
|
||||||
|
@OneToMany(targetEntity = User.class, fetch = FetchType.EAGER)
|
||||||
|
private List<User> executors;
|
||||||
|
|
||||||
|
private Boolean done;
|
||||||
|
|
||||||
public Deadline() {
|
public Deadline() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,13 +37,24 @@ public class Deadline extends BaseEntity {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Deadline(Date deadlineDate, String description, List<User> executors, Boolean done) {
|
||||||
|
this.date = deadlineDate;
|
||||||
|
this.description = description;
|
||||||
|
this.executors = executors;
|
||||||
|
this.done = done;
|
||||||
|
}
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public Deadline(@JsonProperty("id") Integer id,
|
public Deadline(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("description") String description,
|
@JsonProperty("description") String description,
|
||||||
@JsonProperty("date") Date date) {
|
@JsonProperty("date") Date date,
|
||||||
|
@JsonProperty("executors") List<User> executors,
|
||||||
|
@JsonProperty("done") Boolean done) {
|
||||||
this.setId(id);
|
this.setId(id);
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
|
this.executors = executors;
|
||||||
|
this.done = done;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
@ -53,6 +73,22 @@ public class Deadline extends BaseEntity {
|
|||||||
this.date = date;
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<User> getExecutors() {
|
||||||
|
return executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutors(List<User> executors) {
|
||||||
|
this.executors = executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getDone() {
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDone(Boolean done) {
|
||||||
|
this.done = done;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
@ -72,11 +108,13 @@ public class Deadline extends BaseEntity {
|
|||||||
}
|
}
|
||||||
return getId().equals(deadline.getId()) &&
|
return getId().equals(deadline.getId()) &&
|
||||||
description.equals(deadline.description) &&
|
description.equals(deadline.description) &&
|
||||||
date.equals(deadline.date);
|
date.equals(deadline.date) &&
|
||||||
|
executors.equals(deadline.executors) &&
|
||||||
|
done.equals(deadline.done);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(super.hashCode(), description, date);
|
return Objects.hash(super.hashCode(), description, date, executors, done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
@ -29,6 +30,8 @@ public class DeadlineService {
|
|||||||
Deadline updateDeadline = deadlineRepository.findOne(deadline.getId());
|
Deadline updateDeadline = deadlineRepository.findOne(deadline.getId());
|
||||||
updateDeadline.setDate(deadline.getDate());
|
updateDeadline.setDate(deadline.getDate());
|
||||||
updateDeadline.setDescription(deadline.getDescription());
|
updateDeadline.setDescription(deadline.getDescription());
|
||||||
|
updateDeadline.setExecutors(deadline.getExecutors());
|
||||||
|
updateDeadline.setDone(deadline.getDone());
|
||||||
deadlineRepository.save(updateDeadline);
|
deadlineRepository.save(updateDeadline);
|
||||||
return updateDeadline;
|
return updateDeadline;
|
||||||
}
|
}
|
||||||
@ -38,6 +41,8 @@ public class DeadlineService {
|
|||||||
Deadline newDeadline = new Deadline();
|
Deadline newDeadline = new Deadline();
|
||||||
newDeadline.setDate(deadline.getDate());
|
newDeadline.setDate(deadline.getDate());
|
||||||
newDeadline.setDescription(deadline.getDescription());
|
newDeadline.setDescription(deadline.getDescription());
|
||||||
|
newDeadline.setExecutors(deadline.getExecutors());
|
||||||
|
newDeadline.setDone(deadline.getDone());
|
||||||
newDeadline = deadlineRepository.save(newDeadline);
|
newDeadline = deadlineRepository.save(newDeadline);
|
||||||
return newDeadline;
|
return newDeadline;
|
||||||
}
|
}
|
||||||
@ -46,4 +51,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,7 @@ 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;
|
||||||
}
|
}
|
||||||
@ -133,10 +123,4 @@ public class GrantController {
|
|||||||
public List<PaperDto> getAllPapers() {
|
public List<PaperDto> getAllPapers() {
|
||||||
return grantService.getAllUncompletedPapers();
|
return grantService.getAllUncompletedPapers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(GrantDto grantDto) {
|
|
||||||
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -43,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;
|
||||||
|
|
||||||
@ -62,14 +63,14 @@ 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.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "grant_id", unique = true)
|
@JoinColumn(name = "grant_id", unique = true)
|
||||||
@Fetch(FetchMode.SUBSELECT)
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
private List<FileData> files = new ArrayList<>();
|
private List<FileData> files = new ArrayList<>();
|
||||||
|
@ -6,18 +6,20 @@ 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.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
|
import ru.ulstu.name.NameContainer;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
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;
|
||||||
@ -95,6 +97,12 @@ public class GrantDto {
|
|||||||
this.papers = convert(grant.getPapers(), PaperDto::new);
|
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() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GrantScheduler {
|
public class GrantScheduler {
|
||||||
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
@ -27,4 +30,15 @@ public class GrantScheduler {
|
|||||||
grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
|
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,8 +1,11 @@
|
|||||||
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.model.FileDataDto;
|
||||||
@ -10,6 +13,7 @@ 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.model.PaperDto;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
@ -21,12 +25,14 @@ 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.Collections;
|
||||||
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.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
@ -34,8 +40,8 @@ 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 = 50;
|
private final Logger log = LoggerFactory.getLogger(GrantService.class);
|
||||||
|
|
||||||
private final GrantRepository grantRepository;
|
private final GrantRepository grantRepository;
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
@ -45,6 +51,7 @@ public class GrantService {
|
|||||||
private final PaperService paperService;
|
private final PaperService paperService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
private final GrantNotificationService grantNotificationService;
|
private final GrantNotificationService grantNotificationService;
|
||||||
|
private final KiasService kiasService;
|
||||||
|
|
||||||
public GrantService(GrantRepository grantRepository,
|
public GrantService(GrantRepository grantRepository,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
@ -53,8 +60,11 @@ public class GrantService {
|
|||||||
UserService userService,
|
UserService userService,
|
||||||
PaperService paperService,
|
PaperService paperService,
|
||||||
EventService eventService,
|
EventService eventService,
|
||||||
GrantNotificationService grantNotificationService) {
|
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;
|
||||||
@ -69,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) {
|
||||||
@ -176,12 +184,56 @@ public class GrantService {
|
|||||||
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(); //дата с сайта киас
|
||||||
|
Date foundGrantDate = deadlineService.findByGrantIdAndDate(id, date);
|
||||||
|
return foundGrantDate != null && foundGrantDate.compareTo(date) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getGrantAuthors(GrantDto grantDto) {
|
public List<User> getGrantAuthors(GrantDto grantDto) {
|
||||||
@ -216,11 +268,7 @@ public class GrantService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperDto> getAllUncompletedPapers() {
|
public List<PaperDto> getAllUncompletedPapers() {
|
||||||
List<PaperDto> papers = paperService.findAllNotCompleted();
|
return paperService.findAllNotCompleted();
|
||||||
papers.stream()
|
|
||||||
.forEach(paper ->
|
|
||||||
paper.setTitle(StringUtils.abbreviate(paper.getTitle(), MAX_DISPLAY_SIZE)));
|
|
||||||
return papers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attachPaper(GrantDto grantDto) {
|
public void attachPaper(GrantDto grantDto) {
|
||||||
@ -261,4 +309,29 @@ public class GrantService {
|
|||||||
.filter(author -> Collections.frequency(authors, author) > 3)
|
.filter(author -> Collections.frequency(authors, author) > 3)
|
||||||
.collect(toList());
|
.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");
|
||||||
|
}
|
||||||
|
}
|
@ -13,4 +13,11 @@ public abstract class BaseService {
|
|||||||
errors.rejectValue(checkField, "errorCode", errorMessage);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import ru.ulstu.deadline.model.Deadline;
|
|||||||
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.user.model.User;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
@ -79,12 +80,24 @@ public class ProjectController {
|
|||||||
return "/projects/project";
|
return "/projects/project";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/project", params = "removeDeadline")
|
||||||
|
public String removeDeadline(ProjectDto projectDto,
|
||||||
|
@RequestParam(value = "removeDeadline") Integer deadlineId) {
|
||||||
|
projectService.removeDeadline(projectDto, deadlineId);
|
||||||
|
return "/projects/project";
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/delete/{project-id}")
|
@GetMapping("/delete/{project-id}")
|
||||||
public String delete(@PathVariable("project-id") Integer projectId) throws IOException {
|
public String delete(@PathVariable("project-id") Integer projectId) throws IOException {
|
||||||
projectService.delete(projectId);
|
projectService.delete(projectId);
|
||||||
return String.format("redirect:%s", "/projects/projects");
|
return String.format("redirect:%s", "/projects/projects");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("allExecutors")
|
||||||
|
public List<User> getAllExecutors(ProjectDto projectDto) {
|
||||||
|
return projectService.getProjectExecutors(projectDto);
|
||||||
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(ProjectDto projectDto) {
|
private void filterEmptyDeadlines(ProjectDto projectDto) {
|
||||||
projectDto.setDeadlines(projectDto.getDeadlines().stream()
|
projectDto.setDeadlines(projectDto.getDeadlines().stream()
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||||
|
@ -2,29 +2,36 @@ package ru.ulstu.project.model;
|
|||||||
|
|
||||||
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.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.grant.model.Grant;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Project extends BaseEntity {
|
public class Project extends BaseEntity implements UserContainer {
|
||||||
|
|
||||||
public enum ProjectStatus {
|
public enum ProjectStatus {
|
||||||
APPLICATION("Заявка"),
|
TECHNICAL_TASK("Техническое задание"),
|
||||||
ON_COMPETITION("Отправлен на конкурс"),
|
OPEN("Открыт"),
|
||||||
SUCCESSFUL_PASSAGE("Успешное прохождение"),
|
|
||||||
IN_WORK("В работе"),
|
IN_WORK("В работе"),
|
||||||
COMPLETED("Завершен"),
|
CERTIFICATE_ISSUED("Оформление свидетельства"),
|
||||||
|
CLOSED("Закрыт"),
|
||||||
FAILED("Провалены сроки");
|
FAILED("Провалены сроки");
|
||||||
|
|
||||||
private String statusName;
|
private String statusName;
|
||||||
@ -42,7 +49,7 @@ public class Project extends BaseEntity {
|
|||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private ProjectStatus status = ProjectStatus.APPLICATION;
|
private ProjectStatus status = ProjectStatus.TECHNICAL_TASK;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String description;
|
private String description;
|
||||||
@ -62,6 +69,9 @@ public class Project extends BaseEntity {
|
|||||||
@JoinColumn(name = "file_id")
|
@JoinColumn(name = "file_id")
|
||||||
private FileData application;
|
private FileData application;
|
||||||
|
|
||||||
|
@ManyToMany(fetch = FetchType.LAZY)
|
||||||
|
private List<User> executors = new ArrayList<>();
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
@ -117,4 +127,18 @@ public class Project extends BaseEntity {
|
|||||||
public void setApplication(FileData application) {
|
public void setApplication(FileData application) {
|
||||||
this.application = application;
|
this.application = application;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<User> getExecutors() {
|
||||||
|
return executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutors(List<User> executors) {
|
||||||
|
this.executors = executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<User> getUsers() {
|
||||||
|
Set<User> users = new HashSet<User>(getExecutors());
|
||||||
|
return users;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,19 @@ package ru.ulstu.project.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.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
import org.thymeleaf.util.StringUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class ProjectDto {
|
public class ProjectDto {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@ -20,6 +28,11 @@ public class ProjectDto {
|
|||||||
private GrantDto grant;
|
private GrantDto grant;
|
||||||
private String repository;
|
private String repository;
|
||||||
private String applicationFileName;
|
private String applicationFileName;
|
||||||
|
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
||||||
|
private Set<Integer> executorIds;
|
||||||
|
private List<UserDto> executors;
|
||||||
|
|
||||||
|
private final static int MAX_EXECUTORS_LENGTH = 40;
|
||||||
|
|
||||||
public ProjectDto() {
|
public ProjectDto() {
|
||||||
}
|
}
|
||||||
@ -35,7 +48,9 @@ public class ProjectDto {
|
|||||||
@JsonProperty("description") String description,
|
@JsonProperty("description") String description,
|
||||||
@JsonProperty("grant") GrantDto grant,
|
@JsonProperty("grant") GrantDto grant,
|
||||||
@JsonProperty("repository") String repository,
|
@JsonProperty("repository") String repository,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines) {
|
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||||
|
@JsonProperty("executorIds") Set<Integer> executorIds,
|
||||||
|
@JsonProperty("executors") List<UserDto> executors) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -44,10 +59,13 @@ public class ProjectDto {
|
|||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.applicationFileName = null;
|
this.applicationFileName = null;
|
||||||
|
this.executorIds = executorIds;
|
||||||
|
this.executors = executors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ProjectDto(Project project) {
|
public ProjectDto(Project project) {
|
||||||
|
Set<User> users = new HashSet<User>(project.getExecutors());
|
||||||
this.id = project.getId();
|
this.id = project.getId();
|
||||||
this.title = project.getTitle();
|
this.title = project.getTitle();
|
||||||
this.status = project.getStatus();
|
this.status = project.getStatus();
|
||||||
@ -56,6 +74,8 @@ public class ProjectDto {
|
|||||||
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
|
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
|
||||||
this.repository = project.getRepository();
|
this.repository = project.getRepository();
|
||||||
this.deadlines = project.getDeadlines();
|
this.deadlines = project.getDeadlines();
|
||||||
|
this.executorIds = convert(users, user -> user.getId());
|
||||||
|
this.executors = convert(project.getExecutors(), UserDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -121,4 +141,35 @@ public class ProjectDto {
|
|||||||
public void setApplicationFileName(String applicationFileName) {
|
public void setApplicationFileName(String applicationFileName) {
|
||||||
this.applicationFileName = applicationFileName;
|
this.applicationFileName = applicationFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Integer> getRemovedDeadlineIds() {
|
||||||
|
return removedDeadlineIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
||||||
|
this.removedDeadlineIds = removedDeadlineIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Integer> getExecutorIds() {
|
||||||
|
return executorIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutorIds(Set<Integer> executorIds) {
|
||||||
|
this.executorIds = executorIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UserDto> getExecutors() {
|
||||||
|
return executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutors(List<UserDto> executors) {
|
||||||
|
this.executors = executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExecutorsString() {
|
||||||
|
return StringUtils.abbreviate(executors
|
||||||
|
.stream()
|
||||||
|
.map(executor -> executor.getLastName())
|
||||||
|
.collect(Collectors.joining(", ")), MAX_EXECUTORS_LENGTH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ import ru.ulstu.grant.repository.GrantRepository;
|
|||||||
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.repository.ProjectRepository;
|
import ru.ulstu.project.repository.ProjectRepository;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -16,7 +18,7 @@ import java.util.List;
|
|||||||
|
|
||||||
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.project.model.Project.ProjectStatus.APPLICATION;
|
import static ru.ulstu.project.model.Project.ProjectStatus.TECHNICAL_TASK;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ProjectService {
|
public class ProjectService {
|
||||||
@ -26,15 +28,18 @@ public class ProjectService {
|
|||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final GrantRepository grantRepository;
|
private final GrantRepository grantRepository;
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
public ProjectService(ProjectRepository projectRepository,
|
public ProjectService(ProjectRepository projectRepository,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
GrantRepository grantRepository,
|
GrantRepository grantRepository,
|
||||||
FileService fileService) {
|
FileService fileService,
|
||||||
|
UserService userService) {
|
||||||
this.projectRepository = projectRepository;
|
this.projectRepository = projectRepository;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.grantRepository = grantRepository;
|
this.grantRepository = grantRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Project> findAll() {
|
public List<Project> findAll() {
|
||||||
@ -83,7 +88,7 @@ public class ProjectService {
|
|||||||
|
|
||||||
private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
|
private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
|
||||||
project.setDescription(projectDto.getDescription());
|
project.setDescription(projectDto.getDescription());
|
||||||
project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus());
|
project.setStatus(projectDto.getStatus() == null ? TECHNICAL_TASK : projectDto.getStatus());
|
||||||
project.setTitle(projectDto.getTitle());
|
project.setTitle(projectDto.getTitle());
|
||||||
if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) {
|
if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) {
|
||||||
project.setGrant(grantRepository.findOne(projectDto.getGrant().getId()));
|
project.setGrant(grantRepository.findOne(projectDto.getGrant().getId()));
|
||||||
@ -104,8 +109,20 @@ public class ProjectService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeDeadline(ProjectDto projectDto, Integer deadlineId) {
|
||||||
|
if (deadlineId != null) {
|
||||||
|
projectDto.getRemovedDeadlineIds().add(deadlineId);
|
||||||
|
}
|
||||||
|
projectDto.getDeadlines().remove((int) deadlineId);
|
||||||
|
}
|
||||||
|
|
||||||
public Project findById(Integer id) {
|
public Project findById(Integer id) {
|
||||||
return projectRepository.findOne(id);
|
return projectRepository.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<User> getProjectExecutors(ProjectDto projectDto) {
|
||||||
|
List<User> users = userService.findAll();
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -65,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 = new ArrayList<User>();
|
private List<User> recipients = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "child_id")
|
@JoinColumn(name = "child_id")
|
||||||
|
@ -17,6 +17,8 @@ import ru.ulstu.user.model.UserDto;
|
|||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -103,9 +105,13 @@ public class EventService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createFromPaper(Paper newPaper) {
|
public void createFromPaper(Paper newPaper) {
|
||||||
|
createFromPaper(newPaper, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createFromPaper(Paper newPaper, List<Event> events) {
|
||||||
List<Timeline> timelines = timelineService.findAll();
|
List<Timeline> timelines = timelineService.findAll();
|
||||||
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
||||||
|
timeline.getEvents().removeAll(events);
|
||||||
for (Deadline deadline : newPaper.getDeadlines()
|
for (Deadline deadline : newPaper.getDeadlines()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
|
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
|
||||||
@ -119,17 +125,15 @@ public class EventService {
|
|||||||
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'");
|
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' cтатьи '" + newPaper.getTitle() + "'");
|
||||||
newEvent.setRecipients(new ArrayList(newPaper.getAuthors()));
|
newEvent.setRecipients(new ArrayList(newPaper.getAuthors()));
|
||||||
newEvent.setPaper(newPaper);
|
newEvent.setPaper(newPaper);
|
||||||
eventRepository.save(newEvent);
|
timeline.getEvents().add(eventRepository.save(newEvent));
|
||||||
|
|
||||||
timeline.getEvents().add(newEvent);
|
|
||||||
timelineService.save(timeline);
|
|
||||||
}
|
}
|
||||||
|
timelineService.save(timeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePaperDeadlines(Paper paper) {
|
public void updatePaperDeadlines(Paper paper) {
|
||||||
eventRepository.delete(eventRepository.findAllByPaper(paper));
|
List<Event> foundEvents = eventRepository.findAllByPaper(paper);
|
||||||
|
eventRepository.delete(foundEvents);
|
||||||
createFromPaper(paper);
|
createFromPaper(paper, foundEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Event> findByCurrentDate() {
|
public List<Event> findByCurrentDate() {
|
||||||
|
@ -48,4 +48,9 @@ public class UserMvcController extends OdinController<UserListDto, UserDto> {
|
|||||||
User user = userSessionService.getUserBySessionId(sessionId);
|
User user = userSessionService.getUserBySessionId(sessionId);
|
||||||
modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto));
|
modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/dashboard")
|
||||||
|
public void getUsersDashboard(ModelMap modelMap) {
|
||||||
|
modelMap.addAllAttributes(userService.getUsersInfo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
50
src/main/java/ru/ulstu/user/model/UserInfoNow.java
Normal file
50
src/main/java/ru/ulstu/user/model/UserInfoNow.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package ru.ulstu.user.model;
|
||||||
|
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.utils.timetable.model.Lesson;
|
||||||
|
|
||||||
|
public class UserInfoNow {
|
||||||
|
private Lesson lesson;
|
||||||
|
private Conference conference;
|
||||||
|
private User user;
|
||||||
|
private boolean isOnline;
|
||||||
|
|
||||||
|
public UserInfoNow(Lesson lesson, Conference conference, User user, boolean isOnline) {
|
||||||
|
this.lesson = lesson;
|
||||||
|
this.conference = conference;
|
||||||
|
this.user = user;
|
||||||
|
this.isOnline = isOnline;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Lesson getLesson() {
|
||||||
|
return lesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLesson(Lesson lesson) {
|
||||||
|
this.lesson = lesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conference getConference() {
|
||||||
|
return conference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConference(Conference conference) {
|
||||||
|
this.conference = conference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOnline() {
|
||||||
|
return isOnline;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnline(boolean online) {
|
||||||
|
isOnline = online;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package ru.ulstu.user.repository;
|
package ru.ulstu.user.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserSession;
|
import ru.ulstu.user.model.UserSession;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -10,4 +11,6 @@ public interface UserSessionRepository extends JpaRepository<UserSession, Intege
|
|||||||
UserSession findOneBySessionId(String sessionId);
|
UserSession findOneBySessionId(String sessionId);
|
||||||
|
|
||||||
List<UserSession> findAllByLogoutTimeIsNullAndLoginTimeBefore(Date date);
|
List<UserSession> findAllByLogoutTimeIsNullAndLoginTimeBefore(Date date);
|
||||||
|
|
||||||
|
List<UserSession> findAllByUserAndLogoutTimeIsNullAndLoginTimeBefore(User user, Date date);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
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;
|
||||||
@ -21,11 +22,9 @@ 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;
|
||||||
@ -48,10 +47,18 @@ public class MailService {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void modifyForDebug(MimeMessageHelper message, String originalSubject) throws MessagingException {
|
||||||
|
if (!StringUtils.isEmpty(applicationProperties.getDebugEmail())) {
|
||||||
|
message.setTo(applicationProperties.getDebugEmail());
|
||||||
|
message.setSubject("To " + applicationProperties.getDebugEmail() + "; " + originalSubject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
public void sendEmailFromTemplate(User user, String templateName, String subject) {
|
public void sendEmailFromTemplate(User user, String templateName, String subject) {
|
||||||
Context context = new Context();
|
Context context = new Context();
|
||||||
|
@ -3,6 +3,7 @@ package ru.ulstu.user.service;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
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.context.annotation.Lazy;
|
||||||
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.mail.MailException;
|
||||||
@ -13,6 +14,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
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.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import ru.ulstu.conference.service.ConferenceService;
|
||||||
import ru.ulstu.configuration.ApplicationProperties;
|
import ru.ulstu.configuration.ApplicationProperties;
|
||||||
import ru.ulstu.core.error.EntityIdIsNullException;
|
import ru.ulstu.core.error.EntityIdIsNullException;
|
||||||
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
||||||
@ -30,6 +32,7 @@ import ru.ulstu.user.error.UserResetKeyError;
|
|||||||
import ru.ulstu.user.error.UserSendingMailException;
|
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.UserInfoNow;
|
||||||
import ru.ulstu.user.model.UserListDto;
|
import ru.ulstu.user.model.UserListDto;
|
||||||
import ru.ulstu.user.model.UserResetPasswordDto;
|
import ru.ulstu.user.model.UserResetPasswordDto;
|
||||||
import ru.ulstu.user.model.UserRole;
|
import ru.ulstu.user.model.UserRole;
|
||||||
@ -38,8 +41,13 @@ import ru.ulstu.user.model.UserRoleDto;
|
|||||||
import ru.ulstu.user.repository.UserRepository;
|
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 ru.ulstu.utils.timetable.TimetableService;
|
||||||
|
import ru.ulstu.utils.timetable.errors.TimetableClientException;
|
||||||
|
import ru.ulstu.utils.timetable.model.Lesson;
|
||||||
|
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -62,19 +70,27 @@ public class UserService implements UserDetailsService {
|
|||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
private final MailService mailService;
|
private final MailService mailService;
|
||||||
private final ApplicationProperties applicationProperties;
|
private final ApplicationProperties applicationProperties;
|
||||||
|
private final TimetableService timetableService;
|
||||||
|
private final ConferenceService conferenceService;
|
||||||
|
private final UserSessionService userSessionService;
|
||||||
|
|
||||||
public UserService(UserRepository userRepository,
|
public UserService(UserRepository userRepository,
|
||||||
PasswordEncoder passwordEncoder,
|
PasswordEncoder passwordEncoder,
|
||||||
UserRoleRepository userRoleRepository,
|
UserRoleRepository userRoleRepository,
|
||||||
UserMapper userMapper,
|
UserMapper userMapper,
|
||||||
MailService mailService,
|
MailService mailService,
|
||||||
ApplicationProperties applicationProperties) {
|
ApplicationProperties applicationProperties,
|
||||||
|
@Lazy ConferenceService conferenceRepository,
|
||||||
|
@Lazy UserSessionService userSessionService) throws ParseException {
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
this.passwordEncoder = passwordEncoder;
|
this.passwordEncoder = passwordEncoder;
|
||||||
this.userRoleRepository = userRoleRepository;
|
this.userRoleRepository = userRoleRepository;
|
||||||
this.userMapper = userMapper;
|
this.userMapper = userMapper;
|
||||||
this.mailService = mailService;
|
this.mailService = mailService;
|
||||||
this.applicationProperties = applicationProperties;
|
this.applicationProperties = applicationProperties;
|
||||||
|
this.conferenceService = conferenceRepository;
|
||||||
|
this.timetableService = new TimetableService();
|
||||||
|
this.userSessionService = userSessionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private User getUserByEmail(String email) {
|
private User getUserByEmail(String email) {
|
||||||
@ -348,4 +364,29 @@ public class UserService implements UserDetailsService {
|
|||||||
throw new UserSendingMailException(email);
|
throw new UserSendingMailException(email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User findOneByLoginIgnoreCase(String login) {
|
||||||
|
return userRepository.findOneByLoginIgnoreCase(login);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getUsersInfo() {
|
||||||
|
List<UserInfoNow> usersInfoNow = new ArrayList<>();
|
||||||
|
String err = "";
|
||||||
|
|
||||||
|
for (User user : userRepository.findAll()) {
|
||||||
|
Lesson lesson = null;
|
||||||
|
try {
|
||||||
|
lesson = timetableService.getCurrentLesson(user.getUserAbbreviate());
|
||||||
|
} catch (TimetableClientException e) {
|
||||||
|
err = "Не удалось загрузить расписание";
|
||||||
|
}
|
||||||
|
usersInfoNow.add(new UserInfoNow(
|
||||||
|
lesson,
|
||||||
|
conferenceService.getActiveConferenceByUser(user),
|
||||||
|
user,
|
||||||
|
userSessionService.isOnline(user))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return ImmutableMap.of("users", usersInfoNow, "error", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ import ru.ulstu.user.model.UserSession;
|
|||||||
import ru.ulstu.user.model.UserSessionListDto;
|
import ru.ulstu.user.model.UserSessionListDto;
|
||||||
import ru.ulstu.user.repository.UserSessionRepository;
|
import ru.ulstu.user.repository.UserSessionRepository;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -58,4 +60,8 @@ public class UserSessionService {
|
|||||||
public User getUserBySessionId(String sessionId) {
|
public User getUserBySessionId(String sessionId) {
|
||||||
return userSessionRepository.findOneBySessionId(sessionId).getUser();
|
return userSessionRepository.findOneBySessionId(sessionId).getUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOnline(User user) {
|
||||||
|
return !userSessionRepository.findAllByUserAndLogoutTimeIsNullAndLoginTimeBefore(user, new Date()).isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
98
src/main/java/ru/ulstu/utils/timetable/TimetableService.java
Normal file
98
src/main/java/ru/ulstu/utils/timetable/TimetableService.java
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package ru.ulstu.utils.timetable;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
import ru.ulstu.utils.timetable.errors.TimetableClientException;
|
||||||
|
import ru.ulstu.utils.timetable.model.Lesson;
|
||||||
|
import ru.ulstu.utils.timetable.model.TimetableResponse;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TimetableService {
|
||||||
|
private static final String TIMETABLE_URL = "http://timetable.athene.tech/api/1.0/timetable?filter=%s";
|
||||||
|
private SimpleDateFormat lessonTimeFormat = new SimpleDateFormat("hh:mm");
|
||||||
|
|
||||||
|
private long[] lessonsStarts = new long[] {
|
||||||
|
lessonTimeFormat.parse("8:00:00").getTime(),
|
||||||
|
lessonTimeFormat.parse("9:40:00").getTime(),
|
||||||
|
lessonTimeFormat.parse("11:30:00").getTime(),
|
||||||
|
lessonTimeFormat.parse("13:10:00").getTime(),
|
||||||
|
lessonTimeFormat.parse("14:50:00").getTime(),
|
||||||
|
lessonTimeFormat.parse("16:30:00").getTime(),
|
||||||
|
lessonTimeFormat.parse("18:10:00").getTime(),
|
||||||
|
};
|
||||||
|
|
||||||
|
public TimetableService() throws ParseException {
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCurrentDay() {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
int day = calendar.get(Calendar.DAY_OF_WEEK);
|
||||||
|
return (day + 5) % 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCurrentLessonNumber() {
|
||||||
|
long lessonDuration = 90 * 60000;
|
||||||
|
Date now = new Date();
|
||||||
|
long timeNow = now.getTime() % (24 * 60 * 60 * 1000L);
|
||||||
|
|
||||||
|
for (int i = 0; i < lessonsStarts.length; i++) {
|
||||||
|
if (timeNow > lessonsStarts[i] && timeNow < lessonsStarts[i] + lessonDuration) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCurrentWeek() {
|
||||||
|
Date currentDate = Calendar.getInstance().getTime();
|
||||||
|
currentDate = DateUtils.clearTime(currentDate);
|
||||||
|
|
||||||
|
Calendar firstJan = Calendar.getInstance();
|
||||||
|
firstJan.set(Calendar.MONTH, 0);
|
||||||
|
firstJan.set(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
|
||||||
|
return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000)
|
||||||
|
+ DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TimetableResponse getTimetableForUser(String userFIO) throws RestClientException {
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
return restTemplate.getForObject(String.format(TIMETABLE_URL, userFIO), TimetableResponse.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Lesson getCurrentLesson(String userFio) {
|
||||||
|
TimetableResponse response;
|
||||||
|
try {
|
||||||
|
response = getTimetableForUser(userFio);
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new TimetableClientException(userFio);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lessonNumber = getCurrentLessonNumber();
|
||||||
|
if (lessonNumber < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Lesson> lessons = response
|
||||||
|
.getResponse()
|
||||||
|
.getWeeks()
|
||||||
|
.get(getCurrentWeek())
|
||||||
|
.getDays()
|
||||||
|
.get(getCurrentDay())
|
||||||
|
.getLessons()
|
||||||
|
.get(lessonNumber);
|
||||||
|
|
||||||
|
if (lessons.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectMapper().convertValue(lessons.get(0), Lesson.class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package ru.ulstu.utils.timetable.errors;
|
||||||
|
|
||||||
|
public class TimetableClientException extends RuntimeException {
|
||||||
|
public TimetableClientException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
28
src/main/java/ru/ulstu/utils/timetable/model/Day.java
Normal file
28
src/main/java/ru/ulstu/utils/timetable/model/Day.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package ru.ulstu.utils.timetable.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class Day {
|
||||||
|
|
||||||
|
private Integer day;
|
||||||
|
private List<List<Lesson>> lessons = new ArrayList<>();
|
||||||
|
|
||||||
|
public Integer getDay() {
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDay(Integer day) {
|
||||||
|
this.day = day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<List<Lesson>> getLessons() {
|
||||||
|
return lessons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessons(List<List<Lesson>> lessons) {
|
||||||
|
this.lessons = lessons;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
24
src/main/java/ru/ulstu/utils/timetable/model/Lesson.java
Normal file
24
src/main/java/ru/ulstu/utils/timetable/model/Lesson.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package ru.ulstu.utils.timetable.model;
|
||||||
|
|
||||||
|
public class Lesson {
|
||||||
|
private String group;
|
||||||
|
private String nameOfLesson;
|
||||||
|
private String teacher;
|
||||||
|
private String room;
|
||||||
|
|
||||||
|
public String getGroup() {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameOfLesson() {
|
||||||
|
return nameOfLesson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTeacher() {
|
||||||
|
return teacher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoom() {
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
}
|
17
src/main/java/ru/ulstu/utils/timetable/model/Response.java
Normal file
17
src/main/java/ru/ulstu/utils/timetable/model/Response.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package ru.ulstu.utils.timetable.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Response {
|
||||||
|
|
||||||
|
private List<Week> weeks = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<Week> getWeeks() {
|
||||||
|
return weeks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWeeks(List<Week> weeks) {
|
||||||
|
this.weeks = weeks;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package ru.ulstu.utils.timetable.model;
|
||||||
|
|
||||||
|
public class TimetableResponse {
|
||||||
|
private Response response;
|
||||||
|
private String error;
|
||||||
|
|
||||||
|
public Response getResponse() {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponse(Response response) {
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getError() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError(String error) {
|
||||||
|
this.error = error;
|
||||||
|
}
|
||||||
|
}
|
18
src/main/java/ru/ulstu/utils/timetable/model/Week.java
Normal file
18
src/main/java/ru/ulstu/utils/timetable/model/Week.java
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package ru.ulstu.utils.timetable.model;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Week implements Serializable {
|
||||||
|
|
||||||
|
private List<Day> days = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<Day> getDays() {
|
||||||
|
return days;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDays(List<Day> days) {
|
||||||
|
this.days = days;
|
||||||
|
}
|
||||||
|
}
|
@ -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-20190506_000000-schema.xml
Normal file
13
src/main/resources/db/changelog-20190506_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="anton" id="20190506_000000-1">
|
||||||
|
<addColumn tableName="deadline">
|
||||||
|
<column name="executor" type="varchar(255)"/>
|
||||||
|
</addColumn>
|
||||||
|
<addColumn tableName="deadline">
|
||||||
|
<column name="done" type="boolean"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
17
src/main/resources/db/changelog-20190506_000001-schema.xml
Normal file
17
src/main/resources/db/changelog-20190506_000001-schema.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?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="20190506_000000-2">
|
||||||
|
<createTable tableName="project_executors">
|
||||||
|
<column name="project_id" type="integer"/>
|
||||||
|
<column name="executors_id" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addForeignKeyConstraint baseTableName="project_executors" baseColumnNames="project_id"
|
||||||
|
constraintName="fk_project_project_executors" referencedTableName="project"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="project_executors" baseColumnNames="executors_id"
|
||||||
|
constraintName="fk_user_project_executors" referencedTableName="users"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
14
src/main/resources/db/changelog-20190517_000001-schema.xml
Normal file
14
src/main/resources/db/changelog-20190517_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="anton" id="20190517_000001-1">
|
||||||
|
<modifyDataType tableName="deadline"
|
||||||
|
columnName="executor"
|
||||||
|
newDataType="integer"
|
||||||
|
schemaName="public"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="executor"
|
||||||
|
constraintName="fk_deadline_executor" referencedTableName="users"
|
||||||
|
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>
|
11
src/main/resources/db/changelog-20190528_000000-schema.xml
Normal file
11
src/main/resources/db/changelog-20190528_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="anton" id="20190528_000000-1">
|
||||||
|
<renameColumn tableName="deadline"
|
||||||
|
columnDataType="integer"
|
||||||
|
newColumnName="executors"
|
||||||
|
oldColumnName="executor"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
17
src/main/resources/db/changelog-20190528_000002-schema.xml
Normal file
17
src/main/resources/db/changelog-20190528_000002-schema.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?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="20190528_000000-3">
|
||||||
|
<createTable tableName="deadline_executors">
|
||||||
|
<column name="deadline_id" type="integer"/>
|
||||||
|
<column name="executors_id" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addForeignKeyConstraint baseTableName="deadline_executors" baseColumnNames="deadline_id"
|
||||||
|
constraintName="fk_deadline_deadline_executors" referencedTableName="deadline"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="deadline_executors" baseColumnNames="executors_id"
|
||||||
|
constraintName="fk_user_deadline_executors" referencedTableName="users"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -39,8 +39,14 @@
|
|||||||
<include file="db/changelog-20190430_000000-schema.xml"/>
|
<include file="db/changelog-20190430_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20190505_000000-schema.xml"/>
|
<include file="db/changelog-20190505_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20190505_000001-schema.xml"/>
|
<include file="db/changelog-20190505_000001-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190506_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190506_000001-schema.xml"/>
|
||||||
<include file="db/changelog-20190507_000000-schema.xml"/>
|
<include file="db/changelog-20190507_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20190507_000001-schema.xml"/>
|
<include file="db/changelog-20190507_000001-schema.xml"/>
|
||||||
<include file="db/changelog-20190511_000000-schema.xml"/>
|
<include file="db/changelog-20190511_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190517_000001-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190520_000000-schema.xml"/>
|
||||||
<include file="db/changelog-20190523_000000-schema.xml"/>
|
<include file="db/changelog-20190523_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190528_000000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20190528_000002-schema.xml"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
5
src/main/resources/public/css/project.css
Normal file
5
src/main/resources/public/css/project.css
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.div-deadline-done {
|
||||||
|
width: 60%;
|
||||||
|
height: 100%;
|
||||||
|
float: right;
|
||||||
|
}
|
@ -8,7 +8,8 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<span th:replace="grants/fragments/grantStatusFragment :: grantStatus(grantStatus=${grant.status})"/>
|
<span th:replace="grants/fragments/grantStatusFragment :: grantStatus(grantStatus=${grant.status})"/>
|
||||||
<a th:href="@{'grant?id='+${grant.id}}">
|
<a th:href="@{'grant?id='+${grant.id}}">
|
||||||
<span class="h6" th:text="${grant.title}"/>
|
<span class="h6" th:if="${#strings.length(grant.title) > 50}" th:text="${#strings.substring(grant.title, 0, 50)} + '...'" th:title="${grant.title}"/>
|
||||||
|
<span class="h6" th:if="${#strings.length(grant.title) le 50}" th:text="${grant.title}" th:title="${grant.title}"/>
|
||||||
<span class="text-muted" th:text="${grant.authorsString}"/>
|
<span class="text-muted" th:text="${grant.authorsString}"/>
|
||||||
</a>
|
</a>
|
||||||
<input class="id-class" type="hidden" th:value="${grant.id}"/>
|
<input class="id-class" type="hidden" th:value="${grant.id}"/>
|
||||||
|
@ -186,47 +186,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-control list-group div-selected-papers" id="selected-papers">
|
<div class="form-control list-group div-selected-papers" id="selected-papers">
|
||||||
<div th:each="paper, rowStat : *{papers}">
|
<div th:each="paper, rowStat : *{papers}">
|
||||||
<input type="hidden" th:field="*{papers[__${rowStat.index}__].id}"/>
|
<div th:replace="papers/fragments/paperLineFragment :: paperLine(paper=${paper})"/>
|
||||||
<div class="col">
|
|
||||||
<a th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}">
|
|
||||||
<img class="icon-paper" src="/img/conference/paper.png"/>
|
|
||||||
<span th:text="*{papers[__${rowStat.index}__].title}">
|
|
||||||
Название статьи
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="col">
|
|
||||||
<label>Статус: </label>
|
|
||||||
<span th:text="*{papers[__${rowStat.index}__].status.statusName}">
|
|
||||||
Статус статьи
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<!--
|
|
||||||
<div class="col" th:unless="${#lists.isEmpty(paper.grants)}">
|
|
||||||
<label>Гранты: </label>
|
|
||||||
<div th:each="grant, grantRowStat : *{papers[__${rowStat.index}__].grants}"
|
|
||||||
th:remove="tag">
|
|
||||||
<div th:unless="${grant.id}==*{id}" th:remove="tag">
|
|
||||||
<li>
|
|
||||||
<a th:href="@{'/grants/grant?id=' + ${grant.id} + ''}">
|
|
||||||
<span th:text="${grant.title} "></span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col" th:unless="${#lists.isEmpty(paper.conferences)}">
|
|
||||||
<label>Конференции: </label>
|
|
||||||
<div th:each="conference, conferenceRowStat : *{papers[__${rowStat.index}__].conferences}"
|
|
||||||
th:remove="tag">
|
|
||||||
<li>
|
|
||||||
<a th:href="@{'/conferences/conference?id=' + ${conference.id} + ''}">
|
|
||||||
<span th:text="${conference.title}"></span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=${paper.status})"/>
|
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=${paper.status})"/>
|
||||||
<a th:href="@{'paper?id='+${paper.id}}">
|
<a th:href="@{'paper?id='+${paper.id}}">
|
||||||
<span class="h6" th:text="${paper.title}"/>
|
<span class="h6" th:if="${#strings.length(paper.title)} > 50" th:text="${#strings.substring(paper.title, 0, 50) + '...'}" th:title="${paper.title}"/>
|
||||||
|
<span class="h6" th:if="${#strings.length(paper.title) le 50}" th:text="${paper.title}" th:title="${paper.title}"/>
|
||||||
<span class="text-muted" th:text="${paper.authorsString}"/>
|
<span class="text-muted" th:text="${paper.authorsString}"/>
|
||||||
</a>
|
</a>
|
||||||
<input class="id-class" type="hidden" th:value="${paper.id}"/>
|
<input class="id-class" type="hidden" th:value="${paper.id}"/>
|
||||||
|
@ -6,19 +6,19 @@
|
|||||||
<body>
|
<body>
|
||||||
<span th:fragment="projectStatus (projectStatus)" class="fa-stack fa-1x">
|
<span th:fragment="projectStatus (projectStatus)" class="fa-stack fa-1x">
|
||||||
<th:block th:switch="${projectStatus.name()}">
|
<th:block th:switch="${projectStatus.name()}">
|
||||||
<div th:case="'APPLICATION'">
|
<div th:case="'TECHNICAL_TASK'">
|
||||||
<i class="fa fa-circle fa-stack-2x text-draft"></i>
|
<i class="fa fa-circle fa-stack-2x text-draft"></i>
|
||||||
</div>
|
</div>
|
||||||
<div th:case="'ON_COMPETITION'">
|
<div th:case="'OPEN'">
|
||||||
<i class="fa fa-circle fa-stack-2x text-review"></i>
|
<i class="fa fa-circle fa-stack-2x text-review"></i>
|
||||||
</div>
|
</div>
|
||||||
<div th:case="'SUCCESSFUL_PASSAGE'">
|
<div th:case="'IN_WORK'">
|
||||||
<i class="fa fa-circle fa-stack-2x text-accepted"></i>
|
<i class="fa fa-circle fa-stack-2x text-accepted"></i>
|
||||||
</div>
|
</div>
|
||||||
<div th:case="'IN_WORK'">
|
<div th:case="'CERTIFICATE_ISSUED'">
|
||||||
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
</div>
|
</div>
|
||||||
<div th:case="'COMPLETED'">
|
<div th:case="'CLOSED'">
|
||||||
<i class="fa fa-circle fa-stack-2x text-success"></i>
|
<i class="fa fa-circle fa-stack-2x text-success"></i>
|
||||||
</div>
|
</div>
|
||||||
<div th:case="'FAILED'">
|
<div th:case="'FAILED'">
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||||
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
|
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
|
||||||
<head>
|
<head>
|
||||||
|
<link rel="stylesheet" href="../css/project.css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
@ -71,7 +71,8 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Дедлайны показателей:</label>
|
<label>Дедлайны показателей:</label>
|
||||||
<div class="row" th:each="deadline, rowStat : *{deadlines}">
|
<div class="row" th:each="deadline, rowStat : *{deadlines}"
|
||||||
|
style="margin-bottom: 15px;">
|
||||||
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
|
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
|
||||||
<div class="col-6 div-deadline-date">
|
<div class="col-6 div-deadline-date">
|
||||||
<input type="date" class="form-control form-deadline-date" name="deadline"
|
<input type="date" class="form-control form-deadline-date" name="deadline"
|
||||||
@ -89,6 +90,20 @@
|
|||||||
aria-hidden="true"><i class="fa fa-times"/></span>
|
aria-hidden="true"><i class="fa fa-times"/></span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-12" style="margin-bottom: 15px;"></div>
|
||||||
|
<div class="col-10 div-deadline-executor">
|
||||||
|
<select class="selectpicker form-control" multiple="true" data-live-search="true"
|
||||||
|
title="-- Выберите исполнителя --" id="executors"
|
||||||
|
th:field="*{deadlines[__${rowStat.index}__].executors}" data-size="5">
|
||||||
|
<option th:each="executors : ${allExecutors}" th:value="${executors.id}"
|
||||||
|
th:text="${executors.lastName}"> Участник
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-2">
|
||||||
|
<input class="form-control div-deadline-done" type="checkbox"
|
||||||
|
th:field="*{deadlines[__${rowStat.index}__].done}"/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
|
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
|
||||||
class="alert alert-danger">Incorrect title</p>
|
class="alert alert-danger">Incorrect title</p>
|
||||||
|
35
src/main/resources/templates/users/dashboard.html
Normal file
35
src/main/resources/templates/users/dashboard.html
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en"
|
||||||
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||||
|
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<script src="/js/core.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container" layout:fragment="content">
|
||||||
|
<section id="services">
|
||||||
|
<div class="container">
|
||||||
|
<div class="col-lg-12 text-center">
|
||||||
|
<h2 class="section-heading text-uppercase">Пользователи</h2>
|
||||||
|
</div>
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 th:text="${error}">teste</h2>
|
||||||
|
</div>
|
||||||
|
<div class="row justify-content-center" id="dashboard">
|
||||||
|
<th:block th:each="user : ${users}">
|
||||||
|
<div th:replace="users/fragments/userDashboardFragment :: userDashboard(user=${user})"/>
|
||||||
|
</th:block>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<script th:inline="javascript">
|
||||||
|
/*<![CDATA[*/
|
||||||
|
$(document).ready(function () {
|
||||||
|
var error = /*[[${error}]]*/
|
||||||
|
showFeedbackMessage(error, MessageTypesEnum.WARNING)
|
||||||
|
});
|
||||||
|
/*]]>*/
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head th:fragment="headerfiles">
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div th:fragment="userDashboard (user)" class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col col-10">
|
||||||
|
<b><p th:text="${user.user.lastName} + ' ' + ${user.user.firstName} + ' ' + ${user.user.patronymic}"></p></b>
|
||||||
|
<i><p th:if="${user.conference != null}" th:text="'Сейчас на конференции ' + ${user.conference.title}"></p></i>
|
||||||
|
<i><p th:if="${user.lesson != null}" th:text="'Сейчас на паре ' + ${user.lesson.nameOfLesson} + ' в аудитории ' + ${user.lesson.room}"></p></i>
|
||||||
|
<p th:if="${user.isOnline()}">Онлайн</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -26,7 +26,7 @@ import java.util.Map;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
public class IndexConferenceTest extends TestTemplate {
|
public class ConferenceTest extends TestTemplate {
|
||||||
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||||
new ConferencesPage(), Arrays.asList("КОНФЕРЕНЦИИ", "/conferences/conferences"),
|
new ConferencesPage(), Arrays.asList("КОНФЕРЕНЦИИ", "/conferences/conferences"),
|
||||||
new ConferencePage(), Arrays.asList("РЕДАКТИРОВАНИЕ КОНФЕРЕНЦИИ", "/conferences/conference?id=0"),
|
new ConferencePage(), Arrays.asList("РЕДАКТИРОВАНИЕ КОНФЕРЕНЦИИ", "/conferences/conference?id=0"),
|
@ -24,14 +24,14 @@ import java.util.Map;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
public class IndexTaskTest extends TestTemplate {
|
public class StudentTaskTest extends TestTemplate {
|
||||||
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||||
new TasksPage(), Arrays.asList("Список задач", "/students/tasks"),
|
new TasksPage(), Arrays.asList("Список задач", "/students/tasks"),
|
||||||
new TasksDashboardPage(), Arrays.asList("Панель управления", "/students/dashboard"),
|
new TasksDashboardPage(), Arrays.asList("Панель управления", "/students/dashboard"),
|
||||||
new TaskPage(), Arrays.asList("Создать задачу", "/students/task?id=0")
|
new TaskPage(), Arrays.asList("Создать задачу", "/students/task?id=0")
|
||||||
);
|
);
|
||||||
|
|
||||||
private final String TAG = "ATag";
|
private final String tag = "ATag";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationProperties applicationProperties;
|
private ApplicationProperties applicationProperties;
|
||||||
@ -168,13 +168,13 @@ public class IndexTaskTest extends TestTemplate {
|
|||||||
String taskName = "Task " + (new Date()).getTime();
|
String taskName = "Task " + (new Date()).getTime();
|
||||||
|
|
||||||
taskPage.setName(taskName);
|
taskPage.setName(taskName);
|
||||||
taskPage.setTag(TAG);
|
taskPage.setTag(tag);
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
taskPage.addDeadlineDate("01.01.2020", 0);
|
taskPage.addDeadlineDate("01.01.2020", 0);
|
||||||
taskPage.addDeadlineDescription("Description", 0);
|
taskPage.addDeadlineDescription("Description", 0);
|
||||||
taskPage.save();
|
taskPage.save();
|
||||||
|
|
||||||
Assert.assertTrue(tasksPage.findTaskByTag(taskName, TAG));
|
Assert.assertTrue(tasksPage.findTaskByTag(taskName, tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -185,7 +185,7 @@ public class IndexTaskTest extends TestTemplate {
|
|||||||
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
|
||||||
Assert.assertTrue(tasksPage.findTag(TAG));
|
Assert.assertTrue(tasksPage.findTag(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -194,9 +194,9 @@ public class IndexTaskTest extends TestTemplate {
|
|||||||
|
|
||||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
TasksPage tasksPage = (TasksPage) getContext().initPage(page.getKey());
|
||||||
tasksPage.selectTag(TAG);
|
tasksPage.selectTag(tag);
|
||||||
|
|
||||||
Assert.assertTrue(tasksPage.findTasksByTag(TAG));
|
Assert.assertTrue(tasksPage.findTasksByTag(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
11
src/test/java/grant/KiasPage.java
Normal file
11
src/test/java/grant/KiasPage.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package grant;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
|
||||||
|
public class KiasPage extends PageObject {
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h1")).getText();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user