#112 changed mapping

This commit is contained in:
Artem.Arefev 2019-06-01 12:57:20 +04:00
parent 2d230afa35
commit 3898dcf1c1
13 changed files with 114 additions and 31 deletions

View File

@ -8,6 +8,7 @@ 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;
@ -71,6 +72,11 @@ 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;
} }
@ -156,4 +162,13 @@ 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;
}
} }

View File

@ -1,10 +1,14 @@
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();
} }

View File

@ -8,6 +8,7 @@ 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;
@ -98,6 +99,11 @@ 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;
} }
@ -191,4 +197,13 @@ 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;
}
} }

View File

@ -17,6 +17,7 @@ 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;
@ -347,6 +348,8 @@ public class GrantService extends BaseService {
@Transactional @Transactional
public void ping(int grantId) throws IOException { public void ping(int grantId) throws IOException {
pingService.addPing(findById(grantId)); Grant grant = findById(grantId);
grant.addPing(new Ping(new Date(), userService.getCurrentUser()));
grantRepository.save(grant);
} }
} }

View File

@ -9,6 +9,7 @@ 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;
@ -128,6 +129,11 @@ 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;
} }
@ -310,4 +316,13 @@ 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;
}
} }

View File

@ -15,6 +15,7 @@ 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;
@ -393,6 +394,8 @@ public class PaperService {
@Transactional @Transactional
public void ping(int paperId) throws IOException { public void ping(int paperId) throws IOException {
pingService.addPing(findPaperById(paperId)); Paper paper = findPaperById(paperId);
paper.addPing(new Ping(new Date(), userService.getCurrentUser()));
paperRepository.save(paper);
} }
} }

View File

@ -54,6 +54,5 @@ public class PingScheduler {
mailService.sendEmailFromTemplate(ImmutableMap.of("pings", pingInfo.getPings()), mailService.sendEmailFromTemplate(ImmutableMap.of("pings", pingInfo.getPings()),
pingInfo.getUser(), "pingsInfoWeekEmail", PING_MAIL_SUBJECT); pingInfo.getUser(), "pingsInfoWeekEmail", PING_MAIL_SUBJECT);
} }
} }
} }

View File

@ -1,11 +1,14 @@
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;
@ -76,6 +79,11 @@ 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)
@JoinColumn(name = "project_id")
@Fetch(FetchMode.SUBSELECT)
private List<Ping> pings = new ArrayList<>();
public String getTitle() { public String getTitle() {
return title; return title;
} }
@ -140,9 +148,16 @@ public class Project extends BaseEntity implements UserActivity {
this.executors = executors; this.executors = executors;
} }
@Override
public Set<User> getUsers() { public Set<User> getUsers() {
Set<User> users = new HashSet<User>(getExecutors()); return new HashSet<User>(getExecutors());
return users; }
public void addPing(Ping ping) {
this.pings.add(new Ping());
}
@Override
public List<Ping> getPings() {
return this.pings;
} }
} }

View File

@ -6,6 +6,7 @@ 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;
@ -15,6 +16,7 @@ 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;
@ -131,6 +133,8 @@ public class ProjectService {
@Transactional @Transactional
public void ping(int projectId) throws IOException { public void ping(int projectId) throws IOException {
pingService.addPing(findById(projectId)); Project project = findById(projectId);
project.addPing(new Ping(new Date(), userService.getCurrentUser()));
projectRepository.save(project);
} }
} }

View File

@ -14,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.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;
@ -21,8 +22,11 @@ import ru.ulstu.core.jpa.OffsetablePageRequest;
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.core.model.response.PageableItems; import ru.ulstu.core.model.response.PageableItems;
import ru.ulstu.grant.service.GrantService;
import ru.ulstu.paper.service.PaperService;
import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.model.Ping;
import ru.ulstu.ping.service.PingService; import ru.ulstu.ping.service.PingService;
import ru.ulstu.project.service.ProjectService;
import ru.ulstu.user.error.UserActivationError; import ru.ulstu.user.error.UserActivationError;
import ru.ulstu.user.error.UserEmailExistsException; import ru.ulstu.user.error.UserEmailExistsException;
import ru.ulstu.user.error.UserIdExistsException; import ru.ulstu.user.error.UserIdExistsException;
@ -78,6 +82,9 @@ 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,
@ -87,7 +94,10 @@ public class UserService implements UserDetailsService {
ApplicationProperties applicationProperties, ApplicationProperties applicationProperties,
@Lazy PingService pingService, @Lazy PingService pingService,
@Lazy ConferenceService conferenceRepository, @Lazy ConferenceService conferenceRepository,
@Lazy UserSessionService userSessionService) throws ParseException { @Lazy UserSessionService userSessionService,
@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;
@ -98,6 +108,9 @@ 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) {
@ -405,9 +418,24 @@ public class UserService implements UserDetailsService {
} }
Map<String, Integer> activitiesPings = new HashMap<>(); Map<String, Integer> activitiesPings = new HashMap<>();
for (Ping ping : pingService.getPings(activityName)) { List<? extends UserActivity> activities = new ArrayList<>();
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;
} }

View File

@ -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=postgres spring.datasource.password=password
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=true ng-tracker.dev-mode=false
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

View File

@ -1,18 +0,0 @@
<?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="arefyev" id="20190525_000000-1">
<addColumn tableName="ping">
<column name="paper_id" type="integer"/>
<column name="grant_id" type="integer"/>
<column name="project_id" type="integer"/>
</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>
</databaseChangeLog>

View File

@ -49,5 +49,5 @@
<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_000000-schema.xml"/>
<include file="db/changelog-20190528_000002-schema.xml"/> <include file="db/changelog-20190528_000002-schema.xml"/>
<include file="db/changelog-20190525_000000-schema.xml"/> <include file="db/changelog-20190531_000000-schema.xml"/>
</databaseChangeLog> </databaseChangeLog>