From a28b3ea57b6d4870bcdbde1d0d66400fbd548e93 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Fri, 7 Jun 2019 12:46:27 +0400 Subject: [PATCH] #93 resolve stashed conflicts --- .../java/ru/ulstu/conference/model/Conference.java | 8 ++++++++ src/main/java/ru/ulstu/grant/model/Grant.java | 11 +++++++++++ .../ru/ulstu/grant/repository/GrantRepository.java | 9 +++++++++ .../java/ru/ulstu/grant/service/GrantService.java | 4 ++++ .../ru/ulstu/paper/repository/PaperRepository.java | 8 ++++++++ .../java/ru/ulstu/paper/service/PaperService.java | 5 +++++ src/main/java/ru/ulstu/project/model/Project.java | 12 ++++++++++++ .../ulstu/project/repository/ProjectRepository.java | 13 +++++++++++++ .../ru/ulstu/project/service/ProjectService.java | 6 ++++++ .../java/ru/ulstu/user/service/UserService.java | 6 ++++++ 10 files changed, 82 insertions(+) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 4df1a1f..8915fcf 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -67,6 +67,14 @@ public class Conference extends BaseEntity { @Fetch(FetchMode.SUBSELECT) private List users = new ArrayList<>(); + @Column(name = "create_date") + @Temporal(TemporalType.TIMESTAMP) + private Date createDate = new Date(); + + @Column(name = "update_date") + @Temporal(TemporalType.TIMESTAMP) + private Date updateDate = new Date(); + public String getTitle() { return title; } diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 369568f..88949e7 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -13,6 +13,7 @@ import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -24,6 +25,8 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Comparator; @@ -98,6 +101,14 @@ public class Grant extends BaseEntity implements UserContainer { @JoinColumn(name = "grant_id") private List events = new ArrayList<>(); + @Column(name = "create_date") + @Temporal(TemporalType.TIMESTAMP) + private Date createDate = new Date(); + + @Column(name = "update_date") + @Temporal(TemporalType.TIMESTAMP) + private Date updateDate = new Date(); + public GrantStatus getStatus() { return status; } diff --git a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java index 876a8c1..9e66ac9 100644 --- a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java +++ b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java @@ -4,8 +4,10 @@ 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.user.model.User; import ru.ulstu.name.BaseRepository; +import java.util.Date; import java.util.List; public interface GrantRepository extends JpaRepository, BaseRepository { @@ -20,4 +22,11 @@ public interface GrantRepository extends JpaRepository, BaseRepo @Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')") List findAllActive(); + + @Query("SELECT g FROM Grant g WHERE (:user IS NULL OR user MEMBER OF g.authors) AND (:status IS NULL OR :status = p.status) " + + " AND (:dateFrom IS NULL OR :dateFrom < p.updateDate) AND (:dateTo IS NULL OR :dateTo > p.updateDate)") + List findByAuthorHasAndStatus(@Param("user") User user, + @Param("status") Grant.GrantStatus status, + @Param("dateFrom") Date dateFrom, + @Param("dateTo") Date dateTo); } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 3243ace..385d939 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -334,4 +334,8 @@ public class GrantService extends BaseService { private List findAllActive() { return grantRepository.findAllActive(); } + + public List getByUserAndStatusAndInterval(User user, Grant.GrantStatus status, Date dateFrom, Date dateTo) { + return grantRepository.findByAuthorHasAndStatus(user, status, dateFrom, dateTo); + } } diff --git a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java index 42d3703..f4cd800 100644 --- a/src/main/java/ru/ulstu/paper/repository/PaperRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/PaperRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.repository.query.Param; import ru.ulstu.paper.model.Paper; import ru.ulstu.user.model.User; +import java.util.Date; import java.util.List; public interface PaperRepository extends JpaRepository { @@ -24,4 +25,11 @@ public interface PaperRepository extends JpaRepository { List findByConferencesIsNullAndStatusNot(Paper.PaperStatus status); List findByIdNotInAndConferencesIsNullAndStatusNot(List paperIds, Paper.PaperStatus status); + + @Query("SELECT p FROM Paper g WHERE (:user IS NULL OR user MEMBER OF p.authors) AND (:status IS NULL OR :status = p.status) " + + "AND (:dateFrom IS NULL OR :dateFrom < p.updateDate) AND (:dateTo IS NULL OR :dateTo > p.updateDate)") + List findByAuthorHasAndStatus(@Param("user") User user, + @Param("status") Paper.PaperStatus status, + @Param("dateFrom") Date dateFrom, + @Param("dateTo") Date dateTo); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 013ce72..aa00e54 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -7,6 +7,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; +import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.AutoCompleteData; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; @@ -391,4 +392,8 @@ public class PaperService { autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers()); return autoCompleteData; } + + public List getByUserAndStatusAndInterval(User user, Paper.PaperStatus status, Date dateFrom, Date dateTo) { + return paperRepository.findByAuthorHasAndStatus(user, status, dateFrom, dateTo); + } } diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 3d11583..a404eb4 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -9,6 +9,7 @@ import ru.ulstu.grant.model.Grant; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -17,9 +18,12 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.HashSet; +import java.util.Date; import java.util.List; import java.util.Set; @@ -72,6 +76,14 @@ public class Project extends BaseEntity implements UserContainer { @ManyToMany(fetch = FetchType.LAZY) private List executors = new ArrayList<>(); + @Column(name = "create_date") + @Temporal(TemporalType.TIMESTAMP) + private Date createDate = new Date(); + + @Column(name = "update_date") + @Temporal(TemporalType.TIMESTAMP) + private Date updateDate = new Date(); + public String getTitle() { return title; } diff --git a/src/main/java/ru/ulstu/project/repository/ProjectRepository.java b/src/main/java/ru/ulstu/project/repository/ProjectRepository.java index 6a78075..63ab6c7 100644 --- a/src/main/java/ru/ulstu/project/repository/ProjectRepository.java +++ b/src/main/java/ru/ulstu/project/repository/ProjectRepository.java @@ -1,8 +1,21 @@ package ru.ulstu.project.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import ru.ulstu.paper.model.Paper; import ru.ulstu.project.model.Project; +import ru.ulstu.user.model.User; + +import java.util.Date; +import java.util.List; public interface ProjectRepository extends JpaRepository { + @Query("SELECT p FROM Project p WHERE (:user IS NULL OR user MEMBER OF p.authors) AND (:status IS NULL OR :status = p.status) " + + "AND (:dateFrom IS NULL OR :dateFrom < p.updateDate) AND (:dateTo IS NULL OR :dateTo > p.updateDate)") + List findByAuthorHasAndStatus(@Param("user") User user, + @Param("status") Project.ProjectStatus status, + @Param("dateFrom") Date dateFrom, + @Param("dateTo") Date dateTo); } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index a8444a6..78e9f99 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -11,9 +11,11 @@ import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.repository.ProjectRepository; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; +import ru.ulstu.user.model.User; import java.io.IOException; import java.util.Arrays; +import java.util.Date; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; @@ -126,6 +128,10 @@ public class ProjectService { return projectRepository.findOne(id); } + public List getByUserAndStatusAndInterval(User user, Project.ProjectStatus status, Date dateFrom, Date dateTo) { + return projectRepository.findByAuthorHasAndStatus(user, status, dateFrom, dateTo); + } + public List getProjectExecutors(ProjectDto projectDto) { List users = userService.findAll(); return users; diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 0004268..db75aec 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -20,6 +20,12 @@ import ru.ulstu.core.error.EntityIdIsNullException; import ru.ulstu.core.jpa.OffsetablePageRequest; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.response.PageableItems; +import ru.ulstu.grant.model.Grant; +import ru.ulstu.grant.service.GrantService; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.service.PaperService; +import ru.ulstu.project.model.Project; +import ru.ulstu.project.service.ProjectService; import ru.ulstu.user.error.UserActivationError; import ru.ulstu.user.error.UserEmailExistsException; import ru.ulstu.user.error.UserIdExistsException;