#112 ping model changed
This commit is contained in:
parent
3898dcf1c1
commit
abea3c7dad
@ -8,11 +8,11 @@ import ru.ulstu.core.model.BaseEntity;
|
|||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.core.model.UserActivity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.ping.model.Ping;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.DiscriminatorValue;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import javax.persistence.FetchType;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
@ -33,6 +33,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "conference")
|
@Table(name = "conference")
|
||||||
|
@DiscriminatorValue("CONFERENCE")
|
||||||
public class Conference extends BaseEntity implements UserActivity {
|
public class Conference extends BaseEntity implements UserActivity {
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@ -72,11 +73,6 @@ public class Conference extends BaseEntity implements UserActivity {
|
|||||||
@Fetch(FetchMode.SUBSELECT)
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
private List<ConferenceUser> users = new ArrayList<>();
|
private List<ConferenceUser> users = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
|
||||||
@JoinColumn(name = "conference_id")
|
|
||||||
@Fetch(FetchMode.SUBSELECT)
|
|
||||||
private List<Ping> pings;
|
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
@ -162,13 +158,4 @@ public class Conference extends BaseEntity implements UserActivity {
|
|||||||
public Set<User> getActivityUsers() {
|
public Set<User> getActivityUsers() {
|
||||||
return getUsers().stream().map(ConferenceUser::getUser).collect(Collectors.toSet());
|
return getUsers().stream().map(ConferenceUser::getUser).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPing(Ping ping) {
|
|
||||||
this.pings.add(ping);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Ping> getPings() {
|
|
||||||
return this.pings;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -242,10 +242,9 @@ public class ConferenceService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Ping ping(ConferenceDto conferenceDto) throws IOException {
|
public void ping(ConferenceDto conferenceDto) throws IOException {
|
||||||
Ping ping = pingService.addPing(findOne(conferenceDto.getId()));
|
pingService.addPing(findOne(conferenceDto.getId()));
|
||||||
conferenceRepository.updatePingConference(conferenceDto.getId());
|
conferenceRepository.updatePingConference(conferenceDto.getId());
|
||||||
return ping;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Conference findOne(Integer conferenceId) {
|
private Conference findOne(Integer conferenceId) {
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
package ru.ulstu.core.model;
|
package ru.ulstu.core.model;
|
||||||
|
|
||||||
import ru.ulstu.ping.model.Ping;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface UserActivity {
|
public interface UserActivity {
|
||||||
String getTitle();
|
String getTitle();
|
||||||
Set<User> getActivityUsers();
|
Set<User> getActivityUsers();
|
||||||
void addPing(Ping ping);
|
|
||||||
List<Ping> getPings();
|
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,12 @@ import ru.ulstu.core.model.UserActivity;
|
|||||||
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.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.ping.model.Ping;
|
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.timeline.model.Event;
|
import ru.ulstu.timeline.model.Event;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.DiscriminatorValue;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
@ -36,6 +36,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "grants")
|
@Table(name = "grants")
|
||||||
|
@DiscriminatorValue("GRANT")
|
||||||
public class Grant extends BaseEntity implements UserActivity {
|
public class Grant extends BaseEntity implements UserActivity {
|
||||||
public enum GrantStatus {
|
public enum GrantStatus {
|
||||||
APPLICATION("Заявка"),
|
APPLICATION("Заявка"),
|
||||||
@ -99,11 +100,6 @@ public class Grant extends BaseEntity implements UserActivity {
|
|||||||
@JoinColumn(name = "grant_id")
|
@JoinColumn(name = "grant_id")
|
||||||
private List<Event> events = new ArrayList<>();
|
private List<Event> events = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
|
||||||
@JoinColumn(name = "grant_id")
|
|
||||||
@Fetch(FetchMode.SUBSELECT)
|
|
||||||
private List<Ping> pings;
|
|
||||||
|
|
||||||
public GrantStatus getStatus() {
|
public GrantStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -197,13 +193,4 @@ public class Grant extends BaseEntity implements UserActivity {
|
|||||||
.filter(d -> d.getDate().after(new Date()))
|
.filter(d -> d.getDate().after(new Date()))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPing(Ping ping) {
|
|
||||||
this.pings.add(ping);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Ping> getPings() {
|
|
||||||
return this.pings;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ 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;
|
||||||
import ru.ulstu.ping.model.Ping;
|
|
||||||
import ru.ulstu.ping.service.PingService;
|
import ru.ulstu.ping.service.PingService;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
@ -348,8 +347,6 @@ public class GrantService extends BaseService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void ping(int grantId) throws IOException {
|
public void ping(int grantId) throws IOException {
|
||||||
Grant grant = findById(grantId);
|
pingService.addPing(findById(grantId));
|
||||||
grant.addPing(new Ping(new Date(), userService.getCurrentUser()));
|
|
||||||
grantRepository.save(grant);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ import ru.ulstu.core.model.UserActivity;
|
|||||||
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.ping.model.Ping;
|
|
||||||
import ru.ulstu.timeline.model.Event;
|
import ru.ulstu.timeline.model.Event;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.DiscriminatorValue;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
@ -35,6 +35,7 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@DiscriminatorValue("PAPER")
|
||||||
public class Paper extends BaseEntity implements UserActivity {
|
public class Paper extends BaseEntity implements UserActivity {
|
||||||
public enum PaperStatus {
|
public enum PaperStatus {
|
||||||
ATTENTION("Обратить внимание"),
|
ATTENTION("Обратить внимание"),
|
||||||
@ -129,11 +130,6 @@ public class Paper extends BaseEntity implements UserActivity {
|
|||||||
@Fetch(FetchMode.SUBSELECT)
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
private List<Reference> references = new ArrayList<>();
|
private List<Reference> references = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
|
||||||
@JoinColumn(name = "paper_id")
|
|
||||||
@Fetch(FetchMode.SUBSELECT)
|
|
||||||
private List<Ping> pings;
|
|
||||||
|
|
||||||
public PaperStatus getStatus() {
|
public PaperStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -316,13 +312,4 @@ public class Paper extends BaseEntity implements UserActivity {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants);
|
return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPing(Ping ping) {
|
|
||||||
this.pings.add(ping);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Ping> getPings() {
|
|
||||||
return this.pings;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import ru.ulstu.paper.model.Reference;
|
|||||||
import ru.ulstu.paper.model.ReferenceDto;
|
import ru.ulstu.paper.model.ReferenceDto;
|
||||||
import ru.ulstu.paper.repository.PaperRepository;
|
import ru.ulstu.paper.repository.PaperRepository;
|
||||||
import ru.ulstu.paper.repository.ReferenceRepository;
|
import ru.ulstu.paper.repository.ReferenceRepository;
|
||||||
import ru.ulstu.ping.model.Ping;
|
|
||||||
import ru.ulstu.ping.service.PingService;
|
import ru.ulstu.ping.service.PingService;
|
||||||
import ru.ulstu.timeline.service.EventService;
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
@ -394,8 +393,6 @@ public class PaperService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void ping(int paperId) throws IOException {
|
public void ping(int paperId) throws IOException {
|
||||||
Paper paper = findPaperById(paperId);
|
pingService.addPing(findPaperById(paperId));
|
||||||
paper.addPing(new Ping(new Date(), userService.getCurrentUser()));
|
|
||||||
paperRepository.save(paper);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package ru.ulstu.ping.model;
|
package ru.ulstu.ping.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import org.hibernate.annotations.Any;
|
||||||
|
import org.hibernate.annotations.AnyMetaDef;
|
||||||
|
import org.hibernate.annotations.MetaValue;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
@ -10,7 +12,9 @@ import ru.ulstu.paper.model.Paper;
|
|||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.FetchType;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
@ -29,21 +33,24 @@ public class Ping extends BaseEntity {
|
|||||||
@JoinColumn(name = "users_id")
|
@JoinColumn(name = "users_id")
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@ManyToOne()
|
@Column(name = "activity_type", insertable = false, updatable = false)
|
||||||
@JoinColumn(name = "conference_id")
|
private String activityType;
|
||||||
private Conference conference;
|
|
||||||
|
|
||||||
@ManyToOne()
|
@Any(
|
||||||
@JoinColumn(name = "paper_id")
|
metaColumn = @Column(name = "activity_type"),
|
||||||
private Paper paper;
|
fetch = FetchType.LAZY
|
||||||
|
)
|
||||||
@ManyToOne()
|
@AnyMetaDef(
|
||||||
@JoinColumn(name = "grant_id")
|
idType = "integer", metaType = "string",
|
||||||
private Grant grant;
|
metaValues = {
|
||||||
|
@MetaValue(targetEntity = Conference.class, value = "CONFERENCE"),
|
||||||
@ManyToOne()
|
@MetaValue(targetEntity = Paper.class, value = "PAPER"),
|
||||||
@JoinColumn(name = "project_id")
|
@MetaValue(targetEntity = Project.class, value = "PROJECT"),
|
||||||
private Project project;
|
@MetaValue(targetEntity = Grant.class, value = "GRANT")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@JoinColumn(name = "activity_id")
|
||||||
|
private UserActivity activity;
|
||||||
|
|
||||||
public Ping() {
|
public Ping() {
|
||||||
}
|
}
|
||||||
@ -53,16 +60,6 @@ public class Ping extends BaseEntity {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ping(@JsonProperty("id") Integer id,
|
|
||||||
@JsonProperty("date") Date date,
|
|
||||||
@JsonProperty("user") User user,
|
|
||||||
@JsonProperty("conference") Conference conference) {
|
|
||||||
setId(id);
|
|
||||||
this.date = date;
|
|
||||||
this.user = user;
|
|
||||||
this.conference = conference;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getDate() {
|
public Date getDate() {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
@ -79,59 +76,11 @@ public class Ping extends BaseEntity {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Conference getConference() {
|
|
||||||
return conference;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConference(Conference conference) {
|
|
||||||
this.conference = conference;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Paper getPaper() {
|
|
||||||
return paper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPaper(Paper paper) {
|
|
||||||
this.paper = paper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Grant getGrant() {
|
|
||||||
return grant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrant(Grant grant) {
|
|
||||||
this.grant = grant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Project getProject() {
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProject(Project project) {
|
|
||||||
this.project = project;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void setActivity(T object) {
|
|
||||||
if (object.getClass() == Conference.class) {
|
|
||||||
this.conference = (Conference) object;
|
|
||||||
} else if (object.getClass() == Project.class) {
|
|
||||||
this.project = (Project) object;
|
|
||||||
} else if (object.getClass() == Grant.class) {
|
|
||||||
this.grant = (Grant) object;
|
|
||||||
} else if (object.getClass() == Paper.class) {
|
|
||||||
this.paper = (Paper) object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserActivity getActivity() {
|
public UserActivity getActivity() {
|
||||||
if (conference != null) {
|
return this.activity;
|
||||||
return conference;
|
}
|
||||||
} else if (project != null) {
|
|
||||||
return project;
|
public void setActivity(UserActivity activity) {
|
||||||
} else if (paper != null) {
|
this.activity = activity;
|
||||||
return paper;
|
|
||||||
} else {
|
|
||||||
return grant;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,10 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface PingRepository extends JpaRepository<Ping, Integer> {
|
public interface PingRepository extends JpaRepository<Ping, Integer> {
|
||||||
|
|
||||||
@Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (YEAR(p.date) = :year) AND (p.conference = :conference)")
|
@Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (YEAR(p.date) = :year) AND (p.activityType = 'conference') AND (p.activity = :conference)")
|
||||||
long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year);
|
long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year);
|
||||||
|
|
||||||
@Query("SELECT p FROM Ping p WHERE (:activity != 'conferences' OR p.conference IS NOT NULL) " +
|
@Query("SELECT p FROM Ping p WHERE (:activity = '' OR p.activityType = :activity)")
|
||||||
"AND (:activity != 'papers' OR p.paper IS NOT NULL) AND (:activity != 'projects' OR p.project IS NOT NULL) " +
|
|
||||||
"AND (:activity != 'grants' OR p.grant IS NOT NULL)")
|
|
||||||
List<Ping> getPings(@Param("activity") String activity);
|
List<Ping> getPings(@Param("activity") String activity);
|
||||||
|
|
||||||
@Query("SELECT p FROM Ping p WHERE (:dateFrom < date)")
|
@Query("SELECT p FROM Ping p WHERE (:dateFrom < date)")
|
||||||
|
@ -3,6 +3,7 @@ package ru.ulstu.ping.service;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.core.model.UserActivity;
|
||||||
import ru.ulstu.ping.model.Ping;
|
import ru.ulstu.ping.model.Ping;
|
||||||
import ru.ulstu.ping.repository.PingRepository;
|
import ru.ulstu.ping.repository.PingRepository;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
@ -27,8 +28,7 @@ public class PingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public <T> Ping addPing(T activity) throws IOException {
|
public Ping addPing(UserActivity activity) throws IOException {
|
||||||
pingScheduler.sendPingsInfo();
|
|
||||||
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
||||||
newPing.setActivity(activity);
|
newPing.setActivity(activity);
|
||||||
return pingRepository.save(newPing);
|
return pingRepository.save(newPing);
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
package ru.ulstu.project.model;
|
package ru.ulstu.project.model;
|
||||||
|
|
||||||
import org.hibernate.annotations.Fetch;
|
|
||||||
import org.hibernate.annotations.FetchMode;
|
|
||||||
import org.hibernate.validator.constraints.NotBlank;
|
import org.hibernate.validator.constraints.NotBlank;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.core.model.UserActivity;
|
||||||
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.ping.model.Ping;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.DiscriminatorValue;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
@ -27,11 +25,8 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@DiscriminatorValue("PROJECT")
|
||||||
public class Project extends BaseEntity implements UserActivity {
|
public class Project extends BaseEntity implements UserActivity {
|
||||||
@Override
|
|
||||||
public Set<User> getActivityUsers() {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ProjectStatus {
|
public enum ProjectStatus {
|
||||||
TECHNICAL_TASK("Техническое задание"),
|
TECHNICAL_TASK("Техническое задание"),
|
||||||
@ -79,10 +74,10 @@ public class Project extends BaseEntity implements UserActivity {
|
|||||||
@ManyToMany(fetch = FetchType.LAZY)
|
@ManyToMany(fetch = FetchType.LAZY)
|
||||||
private List<User> executors = new ArrayList<>();
|
private List<User> executors = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
// @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "project_id")
|
// @JoinColumn(name = "project_id")
|
||||||
@Fetch(FetchMode.SUBSELECT)
|
// @Fetch(FetchMode.SUBSELECT)
|
||||||
private List<Ping> pings = new ArrayList<>();
|
// private List<Ping> pings = new ArrayList<>();
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
@ -149,15 +144,11 @@ public class Project extends BaseEntity implements UserActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<User> getUsers() {
|
public Set<User> getUsers() {
|
||||||
return new HashSet<User>(getExecutors());
|
return new HashSet<>(getExecutors());
|
||||||
}
|
|
||||||
|
|
||||||
public void addPing(Ping ping) {
|
|
||||||
this.pings.add(new Ping());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Ping> getPings() {
|
public Set<User> getActivityUsers() {
|
||||||
return this.pings;
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import org.thymeleaf.util.StringUtils;
|
|||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
import ru.ulstu.grant.repository.GrantRepository;
|
import ru.ulstu.grant.repository.GrantRepository;
|
||||||
import ru.ulstu.ping.model.Ping;
|
|
||||||
import ru.ulstu.ping.service.PingService;
|
import ru.ulstu.ping.service.PingService;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
@ -16,7 +15,6 @@ import ru.ulstu.user.service.UserService;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
@ -133,8 +131,6 @@ public class ProjectService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void ping(int projectId) throws IOException {
|
public void ping(int projectId) throws IOException {
|
||||||
Project project = findById(projectId);
|
pingService.addPing(findById(projectId));
|
||||||
project.addPing(new Ping(new Date(), userService.getCurrentUser()));
|
|
||||||
projectRepository.save(project);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,10 +65,10 @@ public class UserMvcController extends OdinController<UserListDto, UserDto> {
|
|||||||
|
|
||||||
@ModelAttribute("allActivities")
|
@ModelAttribute("allActivities")
|
||||||
public Map<String, String> getAllActivites() {
|
public Map<String, String> getAllActivites() {
|
||||||
return ImmutableMap.of("papers", "Статьи",
|
return ImmutableMap.of("PAPER", "Статьи",
|
||||||
"grants", "Гранты",
|
"GRANT", "Гранты",
|
||||||
"projects", "Проекты",
|
"PROJECT", "Проекты",
|
||||||
"conferences", "Конференции");
|
"CONFERENCE", "Конференции");
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/pings")
|
@GetMapping("/pings")
|
||||||
|
@ -14,7 +14,6 @@ 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.model.Conference;
|
|
||||||
import ru.ulstu.conference.service.ConferenceService;
|
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;
|
||||||
@ -82,9 +81,6 @@ public class UserService implements UserDetailsService {
|
|||||||
private final ConferenceService conferenceService;
|
private final ConferenceService conferenceService;
|
||||||
private final UserSessionService userSessionService;
|
private final UserSessionService userSessionService;
|
||||||
private final PingService pingService;
|
private final PingService pingService;
|
||||||
private final PaperService paperService;
|
|
||||||
private final ProjectService projectService;
|
|
||||||
private final GrantService grantService;
|
|
||||||
|
|
||||||
public UserService(UserRepository userRepository,
|
public UserService(UserRepository userRepository,
|
||||||
PasswordEncoder passwordEncoder,
|
PasswordEncoder passwordEncoder,
|
||||||
@ -94,10 +90,7 @@ public class UserService implements UserDetailsService {
|
|||||||
ApplicationProperties applicationProperties,
|
ApplicationProperties applicationProperties,
|
||||||
@Lazy PingService pingService,
|
@Lazy PingService pingService,
|
||||||
@Lazy ConferenceService conferenceRepository,
|
@Lazy ConferenceService conferenceRepository,
|
||||||
@Lazy UserSessionService userSessionService,
|
@Lazy UserSessionService userSessionService) throws ParseException {
|
||||||
@Lazy PaperService paperService,
|
|
||||||
@Lazy ProjectService projectService,
|
|
||||||
@Lazy GrantService grantService) throws ParseException {
|
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
this.passwordEncoder = passwordEncoder;
|
this.passwordEncoder = passwordEncoder;
|
||||||
this.userRoleRepository = userRoleRepository;
|
this.userRoleRepository = userRoleRepository;
|
||||||
@ -108,9 +101,6 @@ public class UserService implements UserDetailsService {
|
|||||||
this.timetableService = new TimetableService();
|
this.timetableService = new TimetableService();
|
||||||
this.userSessionService = userSessionService;
|
this.userSessionService = userSessionService;
|
||||||
this.pingService = pingService;
|
this.pingService = pingService;
|
||||||
this.paperService = paperService;
|
|
||||||
this.projectService = projectService;
|
|
||||||
this.grantService = grantService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private User getUserByEmail(String email) {
|
private User getUserByEmail(String email) {
|
||||||
@ -418,24 +408,9 @@ public class UserService implements UserDetailsService {
|
|||||||
}
|
}
|
||||||
Map<String, Integer> activitiesPings = new HashMap<>();
|
Map<String, Integer> activitiesPings = new HashMap<>();
|
||||||
|
|
||||||
List<? extends UserActivity> activities = new ArrayList<>();
|
for (Ping ping : pingService.getPings(activityName)) {
|
||||||
|
UserActivity activity = ping.getActivity();
|
||||||
|
|
||||||
switch (activityName) {
|
|
||||||
case "conferences":
|
|
||||||
activities = conferenceService.findAll();
|
|
||||||
break;
|
|
||||||
case "papers":
|
|
||||||
activities = paperService.findAll();
|
|
||||||
break;
|
|
||||||
case "projects":
|
|
||||||
activities = projectService.findAll();
|
|
||||||
break;
|
|
||||||
case "grants":
|
|
||||||
activities = grantService.findAll();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (UserActivity activity : activities) {
|
|
||||||
if (user != null && !activity.getActivityUsers().contains(user)) {
|
if (user != null && !activity.getActivityUsers().contains(user)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact
|
|||||||
# JPA Settings
|
# JPA Settings
|
||||||
spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker
|
spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker
|
||||||
spring.datasource.username=postgres
|
spring.datasource.username=postgres
|
||||||
spring.datasource.password=password
|
spring.datasource.password=postgres
|
||||||
spring.datasource.driverclassName=org.postgresql.Driver
|
spring.datasource.driverclassName=org.postgresql.Driver
|
||||||
spring.jpa.hibernate.ddl-auto=validate
|
spring.jpa.hibernate.ddl-auto=validate
|
||||||
# Liquibase Settings
|
# Liquibase Settings
|
||||||
@ -34,7 +34,7 @@ liquibase.change-log=classpath:db/changelog-master.xml
|
|||||||
# Application Settings
|
# Application Settings
|
||||||
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=false
|
ng-tracker.dev-mode=true
|
||||||
ng-tracker.debug_email=
|
ng-tracker.debug_email=
|
||||||
ng-tracker.use-https=false
|
ng-tracker.use-https=false
|
||||||
ng-tracker.check-run=false
|
ng-tracker.check-run=false
|
@ -4,15 +4,8 @@
|
|||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
<changeSet author="arefyev" id="20190525_000000-1">
|
<changeSet author="arefyev" id="20190525_000000-1">
|
||||||
<addColumn tableName="ping">
|
<addColumn tableName="ping">
|
||||||
<column name="paper_id" type="integer"/>
|
<column name="activity_type" type="varchar(20)"/>
|
||||||
<column name="grant_id" type="integer"/>
|
<column name="activity_id" type="integer"/>
|
||||||
<column name="project_id" type="integer"/>
|
|
||||||
</addColumn>
|
</addColumn>
|
||||||
<addForeignKeyConstraint baseTableName="ping" baseColumnNames="paper_id" constraintName="paper_fk" referencedTableName="paper"
|
|
||||||
referencedColumnNames="id"/>
|
|
||||||
<addForeignKeyConstraint baseTableName="ping" baseColumnNames="grant_id" constraintName="grant_fk" referencedTableName="grants"
|
|
||||||
referencedColumnNames="id"/>
|
|
||||||
<addForeignKeyConstraint baseTableName="ping" baseColumnNames="project_id" constraintName="project_fk" referencedTableName="project"
|
|
||||||
referencedColumnNames="id"/>
|
|
||||||
</changeSet>
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
@ -562,6 +562,7 @@
|
|||||||
$(this).autocomplete("search");
|
$(this).autocomplete("search");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*]]>*/
|
/*]]>*/
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
@ -276,14 +276,4 @@ public class ConferenceServiceTest {
|
|||||||
|
|
||||||
assertTrue(conferenceService.isAttachedToConference(ID));
|
assertTrue(conferenceService.isAttachedToConference(ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void ping() throws IOException {
|
|
||||||
Ping ping = new Ping();
|
|
||||||
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId);
|
|
||||||
when(pingService.addPing(conferenceWithId)).thenReturn(ping);
|
|
||||||
when(conferenceRepository.updatePingConference(ID)).thenReturn(INDEX);
|
|
||||||
|
|
||||||
assertEquals(ping, conferenceService.ping(conferenceDto));
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user