From 482e2b35954906d5c25157d8f1e22b1fba050dca Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Mon, 27 May 2019 00:42:43 +0400 Subject: [PATCH 1/8] #112 base ping activities --- .../grant/controller/GrantController.java | 7 ++ .../ru/ulstu/grant/service/GrantService.java | 15 +++- .../paper/controller/PaperRestController.java | 6 ++ .../ru/ulstu/paper/service/PaperService.java | 12 ++- src/main/java/ru/ulstu/ping/model/Ping.java | 53 +++++++++++- .../ulstu/ping/repository/PingRepository.java | 8 ++ .../ru/ulstu/ping/service/PingService.java | 9 +- .../project/controller/ProjectController.java | 7 ++ .../ulstu/project/service/ProjectService.java | 10 ++- .../ulstu/user/controller/UserController.java | 8 ++ .../user/controller/UserMvcController.java | 18 ++++ .../ru/ulstu/user/model/DiagramElement.java | 86 +++++++++++++++++++ .../ru/ulstu/user/service/UserService.java | 28 +++++- .../db/changelog-20190525_000000-schema.xml | 18 ++++ src/main/resources/db/changelog-master.xml | 1 + src/main/resources/public/js/users.js | 38 ++++++++ .../resources/templates/grants/grant.html | 24 +++++- .../resources/templates/papers/paper.html | 18 +++- .../resources/templates/projects/project.html | 24 +++++- .../resources/templates/users/activities.html | 51 +++++++++++ .../resources/templates/users/profile.html | 7 ++ 21 files changed, 436 insertions(+), 12 deletions(-) create mode 100644 src/main/java/ru/ulstu/user/model/DiagramElement.java create mode 100644 src/main/resources/db/changelog-20190525_000000-schema.xml create mode 100644 src/main/resources/templates/users/activities.html diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index ad5e992..8f7d760 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; @@ -139,4 +140,10 @@ public class GrantController { .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) .collect(Collectors.toList())); } + + @ResponseBody + @PostMapping(value = "/ping") + public void ping(@RequestParam("grantId") int grantId) throws IOException { + grantService.ping(grantId); + } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 45f9b2f..031467d 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -13,6 +13,7 @@ import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.ping.service.PingService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; @@ -45,6 +46,7 @@ public class GrantService { private final PaperService paperService; private final EventService eventService; private final GrantNotificationService grantNotificationService; + private final PingService pingService; public GrantService(GrantRepository grantRepository, FileService fileService, @@ -53,7 +55,8 @@ public class GrantService { UserService userService, PaperService paperService, EventService eventService, - GrantNotificationService grantNotificationService) { + GrantNotificationService grantNotificationService, + PingService pingService) { this.grantRepository = grantRepository; this.fileService = fileService; this.deadlineService = deadlineService; @@ -62,6 +65,7 @@ public class GrantService { this.paperService = paperService; this.eventService = eventService; this.grantNotificationService = grantNotificationService; + this.pingService = pingService; } public List findAll() { @@ -261,4 +265,13 @@ public class GrantService { .filter(author -> Collections.frequency(authors, author) > 3) .collect(toList()); } + + public Grant findById(Integer id) { + return grantRepository.findOne(id); + } + + @Transactional + public void ping(int grantId) throws IOException { + pingService.addPing(findById(grantId)); + } } diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java index 6da009f..7c0d9c5 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.Response; @@ -72,4 +73,9 @@ public class PaperRestController { public Response getFormattedReference(@RequestBody @Valid ReferenceDto referenceDto) { return new Response<>(paperService.getFormattedReference(referenceDto)); } + + @PostMapping(value = "/ping") + public void ping(@RequestParam("paperId") int paperId) throws IOException { + paperService.ping(paperId); + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 2393af4..912b85e 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -1,5 +1,6 @@ package ru.ulstu.paper.service; +import com.sun.deploy.pings.Pings; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +16,7 @@ import ru.ulstu.paper.model.Reference; import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.paper.repository.ReferenceRepository; +import ru.ulstu.ping.service.PingService; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -54,6 +56,7 @@ public class PaperService { private final FileService fileService; private final EventService eventService; private final ReferenceRepository referenceRepository; + private final PingService pingService; public PaperService(PaperRepository paperRepository, ReferenceRepository referenceRepository, @@ -61,7 +64,8 @@ public class PaperService { PaperNotificationService paperNotificationService, UserService userService, DeadlineService deadlineService, - EventService eventService) { + EventService eventService, + PingService pingService) { this.paperRepository = paperRepository; this.referenceRepository = referenceRepository; this.fileService = fileService; @@ -69,6 +73,7 @@ public class PaperService { this.userService = userService; this.deadlineService = deadlineService; this.eventService = eventService; + this.pingService = pingService; } public List findAll() { @@ -386,4 +391,9 @@ public class PaperService { autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers()); return autoCompleteData; } + + @Transactional + public void ping(int paperId) throws IOException { + pingService.addPing(findPaperById(paperId)); + } } diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java index c7e4c5e..d52bb07 100644 --- a/src/main/java/ru/ulstu/ping/model/Ping.java +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -4,6 +4,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.grant.model.Grant; +import ru.ulstu.paper.model.Paper; +import ru.ulstu.project.model.Project; import ru.ulstu.user.model.User; import javax.persistence.Entity; @@ -25,10 +28,22 @@ public class Ping extends BaseEntity { @JoinColumn(name = "users_id") private User user; - @ManyToOne(optional = false) + @ManyToOne() @JoinColumn(name = "conference_id") private Conference conference; + @ManyToOne() + @JoinColumn(name = "paper_id") + private Paper paper; + + @ManyToOne() + @JoinColumn(name = "grant_id") + private Grant grant; + + @ManyToOne() + @JoinColumn(name = "project_id") + private Project project; + public Ping() { } @@ -70,4 +85,40 @@ public class Ping extends BaseEntity { 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 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; + } + } } diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java index de79dd7..0a97c31 100644 --- a/src/main/java/ru/ulstu/ping/repository/PingRepository.java +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -6,8 +6,16 @@ import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; import ru.ulstu.ping.model.Ping; +import java.util.List; + public interface PingRepository extends JpaRepository { @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)") 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 (:user IS NULL OR p.user.id = :user) " + + "AND (:activity != 'conferences' OR p.conference IS NOT NULL) 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 getPings(@Param("user") Integer user, + @Param("activity") String activity); } diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index 6666fdd..de61422 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -10,6 +10,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Calendar; import java.util.Date; +import java.util.List; @Service public class PingService { @@ -23,9 +24,9 @@ public class PingService { } @Transactional - public Ping addPing(Conference conference) throws IOException { + public Ping addPing(T activity) throws IOException { Ping newPing = new Ping(new Date(), userService.getCurrentUser()); - newPing.setConference(conference); + newPing.setActivity(activity); return pingRepository.save(newPing); } @@ -33,4 +34,8 @@ public class PingService { return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.YEAR))); } + + public List getPings(Integer userId, String activity) { + return pingRepository.getPings(userId, activity); + } } diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index ae09658..efaa00b 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -90,4 +91,10 @@ public class ProjectController { .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) .collect(Collectors.toList())); } + + @ResponseBody + @PostMapping(value = "/ping") + public void ping(@RequestParam("projectId") int projectId) throws IOException { + projectService.ping(projectId); + } } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 247624d..ecc36b6 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -6,6 +6,7 @@ import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.repository.GrantRepository; +import ru.ulstu.ping.service.PingService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.repository.ProjectRepository; @@ -26,15 +27,18 @@ public class ProjectService { private final DeadlineService deadlineService; private final GrantRepository grantRepository; private final FileService fileService; + private final PingService pingService; public ProjectService(ProjectRepository projectRepository, DeadlineService deadlineService, GrantRepository grantRepository, - FileService fileService) { + FileService fileService, + PingService pingService) { this.projectRepository = projectRepository; this.deadlineService = deadlineService; this.grantRepository = grantRepository; this.fileService = fileService; + this.pingService = pingService; } public List findAll() { @@ -108,4 +112,8 @@ public class ProjectService { return projectRepository.findOne(id); } + @Transactional + public void ping(int projectId) throws IOException { + pingService.addPing(findById(projectId)); + } } diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index c40ed8f..3487370 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -20,6 +20,7 @@ import ru.ulstu.odin.controller.OdinController; import ru.ulstu.odin.model.OdinMetadata; import ru.ulstu.odin.model.OdinVoid; import ru.ulstu.odin.service.OdinService; +import ru.ulstu.user.model.DiagramElement; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserListDto; @@ -34,6 +35,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.validation.Valid; +import java.util.List; import java.util.Map; import static ru.ulstu.user.controller.UserController.URL; @@ -171,4 +173,10 @@ public class UserController extends OdinController { public void inviteUser(@RequestParam("email") String email) { userService.inviteUser(email); } + + @GetMapping("/activities/pings") + public Response> getActivitesStats(@RequestParam(value = "userId", required = false) Integer userId, + @RequestParam(value = "activity", required = false) String activity) { + return new Response<>(userService.getActivitiesPings(userId, activity)); + } } diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index 5bcbd13..ac8d955 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.configuration.Constants; @@ -17,6 +18,8 @@ import ru.ulstu.user.service.UserSessionService; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; +import java.util.ArrayList; +import java.util.List; @Controller @RequestMapping(value = "/users") @@ -48,4 +51,19 @@ public class UserMvcController extends OdinController { User user = userSessionService.getUserBySessionId(sessionId); modelMap.addAttribute("userDto", userService.updateUserInformation(user, userDto)); } + + @ModelAttribute("allUsers") + public List getAllUsers() { + return userService.findAll(); + } + + @ModelAttribute("allActivities") + public List getAllActivites() { + return new ArrayList() {{ + add("papers"); + add("projects"); + add("grants"); + add("conferences"); + }}; + } } diff --git a/src/main/java/ru/ulstu/user/model/DiagramElement.java b/src/main/java/ru/ulstu/user/model/DiagramElement.java new file mode 100644 index 0000000..3509110 --- /dev/null +++ b/src/main/java/ru/ulstu/user/model/DiagramElement.java @@ -0,0 +1,86 @@ +package ru.ulstu.user.model; + +import ru.ulstu.ping.model.Ping; + +public class DiagramElement { + private User user; + private int conferences = 0; + private int projects = 0; + private int grants = 0; + private int papers = 0; + + public DiagramElement() { + } + + public DiagramElement(User user) { + this.user = user; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public int getConferences() { + return conferences; + } + + public void setConferences(int conferences) { + this.conferences = conferences; + } + + public int getProjects() { + return projects; + } + + public void setProjects(int projects) { + this.projects = projects; + } + + public int getGrants() { + return grants; + } + + public void setGrants(int grants) { + this.grants = grants; + } + + public int getPapers() { + return papers; + } + + public void setPapers(int papers) { + this.papers = papers; + } + + public void incrementPapers(int value) { + this.papers ++; + } + + public void incrementProjects(int value) { + this.projects ++; + } + + public void incrementConferences(int value) { + this.conferences ++; + } + + public void incrementGrants(int value) { + this.grants ++; + } + + public void incrementActivity(Ping ping) { + if (ping.getConference() != null) { + this.conferences ++; + } else if(ping.getPaper() != null) { + this.papers ++; + } else if(ping.getProject() != null) { + this.projects ++; + } else if(ping.getGrant() != null) { + this.grants ++; + } + } +} diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 8089a8e..90a79c0 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -3,6 +3,7 @@ package ru.ulstu.user.service; import com.google.common.collect.ImmutableMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.Page; import org.springframework.data.domain.Sort; import org.springframework.mail.MailException; @@ -18,6 +19,8 @@ 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.ping.model.Ping; +import ru.ulstu.ping.service.PingService; import ru.ulstu.user.error.UserActivationError; import ru.ulstu.user.error.UserEmailExistsException; import ru.ulstu.user.error.UserIdExistsException; @@ -28,6 +31,7 @@ import ru.ulstu.user.error.UserNotFoundException; import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException; import ru.ulstu.user.error.UserResetKeyError; import ru.ulstu.user.error.UserSendingMailException; +import ru.ulstu.user.model.DiagramElement; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserListDto; @@ -40,6 +44,7 @@ import ru.ulstu.user.repository.UserRoleRepository; import ru.ulstu.user.util.UserUtils; import javax.mail.MessagingException; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -62,19 +67,22 @@ public class UserService implements UserDetailsService { private final UserMapper userMapper; private final MailService mailService; private final ApplicationProperties applicationProperties; + private final PingService pingService; public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder, UserRoleRepository userRoleRepository, UserMapper userMapper, MailService mailService, - ApplicationProperties applicationProperties) { + ApplicationProperties applicationProperties, + @Lazy PingService pingService) { this.userRepository = userRepository; this.passwordEncoder = passwordEncoder; this.userRoleRepository = userRoleRepository; this.userMapper = userMapper; this.mailService = mailService; this.applicationProperties = applicationProperties; + this.pingService = pingService; } private User getUserByEmail(String email) { @@ -236,7 +244,7 @@ public class UserService implements UserDetailsService { mailService.sendChangePasswordMail(user); } - public boolean requestUserPasswordReset(String email) { + public boolean requestUserPasswordReset(String email) { User user = userRepository.findOneByEmailIgnoreCase(email); if (user == null) { throw new UserNotFoundException(email); @@ -348,4 +356,20 @@ public class UserService implements UserDetailsService { throw new UserSendingMailException(email); } } + + public List getActivitiesPings(Integer userId, + String activity) { + List pings = pingService.getPings(userId, activity); + List diagramElements = new ArrayList<>(); + + for (Ping ping:pings) { + DiagramElement diagramElement = diagramElements.stream().filter(element -> element.getUser() == ping.getUser()).findFirst().orElse(null); + if(diagramElement == null) { + diagramElement = new DiagramElement(ping.getUser()); + diagramElements.add(diagramElement); + } + diagramElement.incrementActivity(ping); + } + return diagramElements; + } } diff --git a/src/main/resources/db/changelog-20190525_000000-schema.xml b/src/main/resources/db/changelog-20190525_000000-schema.xml new file mode 100644 index 0000000..51fffe6 --- /dev/null +++ b/src/main/resources/db/changelog-20190525_000000-schema.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 5011cc5..d4488f7 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -43,4 +43,5 @@ + \ No newline at end of file diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index e31d3ad..d0c7c38 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -124,4 +124,42 @@ function resetPassword() { function isEmailValid(email) { re = /\S+@\S+\.\S+/; return re.test(email) +} + +function drawChart() { + userId = $('#author :selected').val() + activity = $('#activity :selected').val() + $.ajax({ + url:`/api/1.0/users/activities?userId=${userId}&activity=${activity}`, + contentType: "application/json; charset=utf-8", + method: "GET", + success: function(response) { + if (response.data.length == 0) { + return; + } + if(userId) { + array = [['Активность', 'Количество'], + ['Конференции', response.data[0].conferences], + ['Статьи', response.data[0].papers], + ['Проекты', response.data[0].projects], + ['Гранты', response.data[0].grants]] + } else { + array = [['Пользователи', 'Количество']] + response.data.forEach(function(element) { + array.push([element.user.firstName, element[`${activity}`]]) + }) + } + var data = google.visualization.arrayToDataTable(array); + var options = { + title: 'Активность', + is3D: true, + pieResidueSliceLabel: 'Остальное' + }; + var chart = new google.visualization.PieChart(document.getElementById('air')); + chart.draw(data, options); + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + } + }) } \ No newline at end of file diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 38047bf..4f70a7a 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -23,7 +23,7 @@ th:object="${grantDto}">
- +
+
+ +
@@ -367,6 +373,22 @@ var lid = $("#leaderId option:selected").val(); $("#authors [value='" + lid + "']").attr("disabled", "disabled"); } + + function sendPing() { + id = document.getElementById("grantId").value + + $.ajax({ + url:"/grants/ping?grantId=" + id, + contentType: "application/json; charset=utf-8", + method: "POST", + success: function() { + showFeedbackMessage("Пароль был обновлен", MessageTypesEnum.SUCCESS) + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + } + }) + }
diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 2755aba..ea748ef 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -43,7 +43,7 @@
@@ -562,21 +562,6 @@ $(this).autocomplete("search"); }); - function sendPing() { - id = document.getElementById("paperId").value - - $.ajax({ - url:"/api/1.0/papers/ping?paperId=" + id, - contentType: "application/json; charset=utf-8", - method: "POST", - success: function() { - showFeedbackMessage("Пароль был обновлен", MessageTypesEnum.SUCCESS) - }, - error: function(errorData) { - showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) - } - }) - } /*]]>*/
diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index c291ff8..92c6410 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -106,7 +106,7 @@
@@ -157,7 +157,7 @@ contentType: "application/json; charset=utf-8", method: "POST", success: function() { - showFeedbackMessage("Пароль был обновлен", MessageTypesEnum.SUCCESS) + showFeedbackMessage("Ping был отправлен", MessageTypesEnum.SUCCESS) }, error: function(errorData) { showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) diff --git a/src/main/resources/templates/users/activities.html b/src/main/resources/templates/users/activities.html deleted file mode 100644 index 1b93828..0000000 --- a/src/main/resources/templates/users/activities.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - -
-
-
-
-
-

Личный кабинет

-
-
-
-
-
-
Фильтр:
- -
- -
-
-
-
-
- - diff --git a/src/main/resources/templates/users/pings.html b/src/main/resources/templates/users/pings.html new file mode 100644 index 0000000..c0ed722 --- /dev/null +++ b/src/main/resources/templates/users/pings.html @@ -0,0 +1,53 @@ + + + + + + + + + + + + +
+
+
+
+
+

Ping активности

+
+
+
+
+
Фильтр:
+ +
+ +
+
+
+
+ +
+
+ + diff --git a/src/main/resources/templates/users/profile.html b/src/main/resources/templates/users/profile.html index 86fed78..93adfc7 100644 --- a/src/main/resources/templates/users/profile.html +++ b/src/main/resources/templates/users/profile.html @@ -4,13 +4,6 @@ layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> - - - - From 2d230afa35edf97cacc2900b7eb53888efd3c199 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Sat, 1 Jun 2019 12:56:37 +0400 Subject: [PATCH 3/8] #112changed mapping --- .../db/changelog-20190531_000000-schema.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/resources/db/changelog-20190531_000000-schema.xml diff --git a/src/main/resources/db/changelog-20190531_000000-schema.xml b/src/main/resources/db/changelog-20190531_000000-schema.xml new file mode 100644 index 0000000..51fffe6 --- /dev/null +++ b/src/main/resources/db/changelog-20190531_000000-schema.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + From 3898dcf1c1acc4fade3527047c7b88c99b14d129 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Sat, 1 Jun 2019 12:57:20 +0400 Subject: [PATCH 4/8] #112 changed mapping --- .../ru/ulstu/conference/model/Conference.java | 15 ++++++++ .../ru/ulstu/core/model/UserActivity.java | 4 +++ src/main/java/ru/ulstu/grant/model/Grant.java | 15 ++++++++ .../ru/ulstu/grant/service/GrantService.java | 5 ++- src/main/java/ru/ulstu/paper/model/Paper.java | 15 ++++++++ .../ru/ulstu/paper/service/PaperService.java | 5 ++- .../ru/ulstu/ping/service/PingScheduler.java | 1 - .../java/ru/ulstu/project/model/Project.java | 21 ++++++++++-- .../ulstu/project/service/ProjectService.java | 6 +++- .../ru/ulstu/user/service/UserService.java | 34 +++++++++++++++++-- src/main/resources/application.properties | 4 +-- .../db/changelog-20190525_000000-schema.xml | 18 ---------- src/main/resources/db/changelog-master.xml | 2 +- 13 files changed, 114 insertions(+), 31 deletions(-) delete mode 100644 src/main/resources/db/changelog-20190525_000000-schema.xml diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 0c3972d..09220c0 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -8,6 +8,7 @@ import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserActivity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; +import ru.ulstu.ping.model.Ping; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; @@ -71,6 +72,11 @@ public class Conference extends BaseEntity implements UserActivity { @Fetch(FetchMode.SUBSELECT) private List users = new ArrayList<>(); + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "conference_id") + @Fetch(FetchMode.SUBSELECT) + private List pings; + public String getTitle() { return title; } @@ -156,4 +162,13 @@ public class Conference extends BaseEntity implements UserActivity { public Set getActivityUsers() { return getUsers().stream().map(ConferenceUser::getUser).collect(Collectors.toSet()); } + + public void addPing(Ping ping) { + this.pings.add(ping); + } + + @Override + public List getPings() { + return this.pings; + } } diff --git a/src/main/java/ru/ulstu/core/model/UserActivity.java b/src/main/java/ru/ulstu/core/model/UserActivity.java index 8e4e270..051a5c9 100644 --- a/src/main/java/ru/ulstu/core/model/UserActivity.java +++ b/src/main/java/ru/ulstu/core/model/UserActivity.java @@ -1,10 +1,14 @@ package ru.ulstu.core.model; +import ru.ulstu.ping.model.Ping; import ru.ulstu.user.model.User; +import java.util.List; import java.util.Set; public interface UserActivity { String getTitle(); Set getActivityUsers(); + void addPing(Ping ping); + List getPings(); } diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index a653772..c10ad11 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -8,6 +8,7 @@ import ru.ulstu.core.model.UserActivity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.paper.model.Paper; +import ru.ulstu.ping.model.Ping; import ru.ulstu.project.model.Project; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; @@ -98,6 +99,11 @@ public class Grant extends BaseEntity implements UserActivity { @JoinColumn(name = "grant_id") private List events = new ArrayList<>(); + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "grant_id") + @Fetch(FetchMode.SUBSELECT) + private List pings; + public GrantStatus getStatus() { return status; } @@ -191,4 +197,13 @@ public class Grant extends BaseEntity implements UserActivity { .filter(d -> d.getDate().after(new Date())) .findFirst(); } + + public void addPing(Ping ping) { + this.pings.add(ping); + } + + @Override + public List getPings() { + return this.pings; + } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 1770334..84e363f 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -17,6 +17,7 @@ import ru.ulstu.name.BaseService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -347,6 +348,8 @@ public class GrantService extends BaseService { @Transactional 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); } } diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 5d951a5..e183877 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -9,6 +9,7 @@ import ru.ulstu.core.model.UserActivity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; +import ru.ulstu.ping.model.Ping; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; @@ -128,6 +129,11 @@ public class Paper extends BaseEntity implements UserActivity { @Fetch(FetchMode.SUBSELECT) private List references = new ArrayList<>(); + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "paper_id") + @Fetch(FetchMode.SUBSELECT) + private List pings; + public PaperStatus getStatus() { return status; } @@ -310,4 +316,13 @@ public class Paper extends BaseEntity implements UserActivity { public int hashCode() { 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 getPings() { + return this.pings; + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 3be9aee..0e159d5 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -15,6 +15,7 @@ import ru.ulstu.paper.model.Reference; import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.paper.repository.ReferenceRepository; +import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; @@ -393,6 +394,8 @@ public class PaperService { @Transactional 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); } } diff --git a/src/main/java/ru/ulstu/ping/service/PingScheduler.java b/src/main/java/ru/ulstu/ping/service/PingScheduler.java index a60e061..239abbf 100644 --- a/src/main/java/ru/ulstu/ping/service/PingScheduler.java +++ b/src/main/java/ru/ulstu/ping/service/PingScheduler.java @@ -54,6 +54,5 @@ public class PingScheduler { mailService.sendEmailFromTemplate(ImmutableMap.of("pings", pingInfo.getPings()), pingInfo.getUser(), "pingsInfoWeekEmail", PING_MAIL_SUBJECT); } - } } diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 227856e..84324dd 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -1,11 +1,14 @@ package ru.ulstu.project.model; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserActivity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; +import ru.ulstu.ping.model.Ping; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; @@ -76,6 +79,11 @@ public class Project extends BaseEntity implements UserActivity { @ManyToMany(fetch = FetchType.LAZY) private List executors = new ArrayList<>(); + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "project_id") + @Fetch(FetchMode.SUBSELECT) + private List pings = new ArrayList<>(); + public String getTitle() { return title; } @@ -140,9 +148,16 @@ public class Project extends BaseEntity implements UserActivity { this.executors = executors; } - @Override public Set getUsers() { - Set users = new HashSet(getExecutors()); - return users; + return new HashSet(getExecutors()); + } + + public void addPing(Ping ping) { + this.pings.add(new Ping()); + } + + @Override + public List getPings() { + return this.pings; } } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 6c00193..9e1e285 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -6,6 +6,7 @@ import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.repository.GrantRepository; +import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -15,6 +16,7 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Arrays; +import java.util.Date; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; @@ -131,6 +133,8 @@ public class ProjectService { @Transactional 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); } } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 62e7ce2..e8cdd4e 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -14,6 +14,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; +import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.configuration.ApplicationProperties; 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.UserActivity; 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.service.PingService; +import ru.ulstu.project.service.ProjectService; import ru.ulstu.user.error.UserActivationError; import ru.ulstu.user.error.UserEmailExistsException; import ru.ulstu.user.error.UserIdExistsException; @@ -78,6 +82,9 @@ public class UserService implements UserDetailsService { private final ConferenceService conferenceService; private final UserSessionService userSessionService; private final PingService pingService; + private final PaperService paperService; + private final ProjectService projectService; + private final GrantService grantService; public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder, @@ -87,7 +94,10 @@ public class UserService implements UserDetailsService { ApplicationProperties applicationProperties, @Lazy PingService pingService, @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.passwordEncoder = passwordEncoder; this.userRoleRepository = userRoleRepository; @@ -98,6 +108,9 @@ public class UserService implements UserDetailsService { this.timetableService = new TimetableService(); this.userSessionService = userSessionService; this.pingService = pingService; + this.paperService = paperService; + this.projectService = projectService; + this.grantService = grantService; } private User getUserByEmail(String email) { @@ -405,9 +418,24 @@ public class UserService implements UserDetailsService { } Map activitiesPings = new HashMap<>(); - for (Ping ping : pingService.getPings(activityName)) { - UserActivity activity = ping.getActivity(); + List activities = new ArrayList<>(); + 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)) { continue; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f4be778..7e793c0 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact # JPA Settings spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.username=postgres -spring.datasource.password=postgres +spring.datasource.password=password spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate # Liquibase Settings @@ -34,7 +34,7 @@ liquibase.change-log=classpath:db/changelog-master.xml # Application Settings ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.undead-user-login=admin -ng-tracker.dev-mode=true +ng-tracker.dev-mode=false ng-tracker.debug_email= ng-tracker.use-https=false ng-tracker.check-run=false \ No newline at end of file diff --git a/src/main/resources/db/changelog-20190525_000000-schema.xml b/src/main/resources/db/changelog-20190525_000000-schema.xml deleted file mode 100644 index 51fffe6..0000000 --- a/src/main/resources/db/changelog-20190525_000000-schema.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 14cb9d7..6285b47 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -49,5 +49,5 @@ - + \ No newline at end of file From abea3c7dad3a44e94fb09821c223f45bde7a23ae Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Sun, 2 Jun 2019 21:53:51 +0400 Subject: [PATCH 5/8] #112 ping model changed --- .../ru/ulstu/conference/model/Conference.java | 17 +-- .../conference/service/ConferenceService.java | 5 +- .../ru/ulstu/core/model/UserActivity.java | 4 - src/main/java/ru/ulstu/grant/model/Grant.java | 17 +-- .../ru/ulstu/grant/service/GrantService.java | 5 +- src/main/java/ru/ulstu/paper/model/Paper.java | 17 +-- .../ru/ulstu/paper/service/PaperService.java | 5 +- src/main/java/ru/ulstu/ping/model/Ping.java | 105 +++++------------- .../ulstu/ping/repository/PingRepository.java | 6 +- .../ru/ulstu/ping/service/PingService.java | 4 +- .../java/ru/ulstu/project/model/Project.java | 27 ++--- .../ulstu/project/service/ProjectService.java | 6 +- .../user/controller/UserMvcController.java | 8 +- .../ru/ulstu/user/service/UserService.java | 31 +----- src/main/resources/application.properties | 4 +- .../db/changelog-20190531_000000-schema.xml | 11 +- .../resources/templates/papers/paper.html | 1 + .../service/ConferenceServiceTest.java | 10 -- 18 files changed, 63 insertions(+), 220 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 09220c0..81a8de7 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -8,11 +8,11 @@ import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserActivity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; -import ru.ulstu.ping.model.Ping; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; @@ -33,6 +33,7 @@ import java.util.stream.Collectors; @Entity @Table(name = "conference") +@DiscriminatorValue("CONFERENCE") public class Conference extends BaseEntity implements UserActivity { @NotBlank @@ -72,11 +73,6 @@ public class Conference extends BaseEntity implements UserActivity { @Fetch(FetchMode.SUBSELECT) private List users = new ArrayList<>(); - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) - @JoinColumn(name = "conference_id") - @Fetch(FetchMode.SUBSELECT) - private List pings; - public String getTitle() { return title; } @@ -162,13 +158,4 @@ public class Conference extends BaseEntity implements UserActivity { public Set getActivityUsers() { return getUsers().stream().map(ConferenceUser::getUser).collect(Collectors.toSet()); } - - public void addPing(Ping ping) { - this.pings.add(ping); - } - - @Override - public List getPings() { - return this.pings; - } } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 1b8e67b..ad5192f 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -242,10 +242,9 @@ public class ConferenceService extends BaseService { } @Transactional - public Ping ping(ConferenceDto conferenceDto) throws IOException { - Ping ping = pingService.addPing(findOne(conferenceDto.getId())); + public void ping(ConferenceDto conferenceDto) throws IOException { + pingService.addPing(findOne(conferenceDto.getId())); conferenceRepository.updatePingConference(conferenceDto.getId()); - return ping; } private Conference findOne(Integer conferenceId) { diff --git a/src/main/java/ru/ulstu/core/model/UserActivity.java b/src/main/java/ru/ulstu/core/model/UserActivity.java index 051a5c9..8e4e270 100644 --- a/src/main/java/ru/ulstu/core/model/UserActivity.java +++ b/src/main/java/ru/ulstu/core/model/UserActivity.java @@ -1,14 +1,10 @@ package ru.ulstu.core.model; -import ru.ulstu.ping.model.Ping; import ru.ulstu.user.model.User; -import java.util.List; import java.util.Set; public interface UserActivity { String getTitle(); Set getActivityUsers(); - void addPing(Ping ping); - List getPings(); } diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index c10ad11..ad74c1b 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -8,12 +8,12 @@ import ru.ulstu.core.model.UserActivity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.paper.model.Paper; -import ru.ulstu.ping.model.Ping; import ru.ulstu.project.model.Project; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -36,6 +36,7 @@ import java.util.Set; @Entity @Table(name = "grants") +@DiscriminatorValue("GRANT") public class Grant extends BaseEntity implements UserActivity { public enum GrantStatus { APPLICATION("Заявка"), @@ -99,11 +100,6 @@ public class Grant extends BaseEntity implements UserActivity { @JoinColumn(name = "grant_id") private List events = new ArrayList<>(); - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) - @JoinColumn(name = "grant_id") - @Fetch(FetchMode.SUBSELECT) - private List pings; - public GrantStatus getStatus() { return status; } @@ -197,13 +193,4 @@ public class Grant extends BaseEntity implements UserActivity { .filter(d -> d.getDate().after(new Date())) .findFirst(); } - - public void addPing(Ping ping) { - this.pings.add(ping); - } - - @Override - public List getPings() { - return this.pings; - } } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 84e363f..1770334 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -17,7 +17,6 @@ import ru.ulstu.name.BaseService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.service.PaperService; -import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -348,8 +347,6 @@ public class GrantService extends BaseService { @Transactional public void ping(int grantId) throws IOException { - Grant grant = findById(grantId); - grant.addPing(new Ping(new Date(), userService.getCurrentUser())); - grantRepository.save(grant); + pingService.addPing(findById(grantId)); } } diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index e183877..bfc2b5b 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -9,12 +9,12 @@ import ru.ulstu.core.model.UserActivity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; -import ru.ulstu.ping.model.Ping; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; import javax.persistence.Column; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -35,6 +35,7 @@ import java.util.Optional; import java.util.Set; @Entity +@DiscriminatorValue("PAPER") public class Paper extends BaseEntity implements UserActivity { public enum PaperStatus { ATTENTION("Обратить внимание"), @@ -129,11 +130,6 @@ public class Paper extends BaseEntity implements UserActivity { @Fetch(FetchMode.SUBSELECT) private List references = new ArrayList<>(); - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) - @JoinColumn(name = "paper_id") - @Fetch(FetchMode.SUBSELECT) - private List pings; - public PaperStatus getStatus() { return status; } @@ -316,13 +312,4 @@ public class Paper extends BaseEntity implements UserActivity { public int hashCode() { 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 getPings() { - return this.pings; - } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 0e159d5..3be9aee 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -15,7 +15,6 @@ import ru.ulstu.paper.model.Reference; import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.paper.repository.ReferenceRepository; -import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; @@ -394,8 +393,6 @@ public class PaperService { @Transactional public void ping(int paperId) throws IOException { - Paper paper = findPaperById(paperId); - paper.addPing(new Ping(new Date(), userService.getCurrentUser())); - paperRepository.save(paper); + pingService.addPing(findPaperById(paperId)); } } diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java index 82c9fe2..7118c22 100644 --- a/src/main/java/ru/ulstu/ping/model/Ping.java +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -1,6 +1,8 @@ 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 ru.ulstu.conference.model.Conference; 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.user.model.User; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; @@ -29,21 +33,24 @@ public class Ping extends BaseEntity { @JoinColumn(name = "users_id") private User user; - @ManyToOne() - @JoinColumn(name = "conference_id") - private Conference conference; + @Column(name = "activity_type", insertable = false, updatable = false) + private String activityType; - @ManyToOne() - @JoinColumn(name = "paper_id") - private Paper paper; - - @ManyToOne() - @JoinColumn(name = "grant_id") - private Grant grant; - - @ManyToOne() - @JoinColumn(name = "project_id") - private Project project; + @Any( + metaColumn = @Column(name = "activity_type"), + fetch = FetchType.LAZY + ) + @AnyMetaDef( + idType = "integer", metaType = "string", + metaValues = { + @MetaValue(targetEntity = Conference.class, value = "CONFERENCE"), + @MetaValue(targetEntity = Paper.class, value = "PAPER"), + @MetaValue(targetEntity = Project.class, value = "PROJECT"), + @MetaValue(targetEntity = Grant.class, value = "GRANT") + } + ) + @JoinColumn(name = "activity_id") + private UserActivity activity; public Ping() { } @@ -53,16 +60,6 @@ public class Ping extends BaseEntity { 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() { return date; } @@ -79,59 +76,11 @@ public class Ping extends BaseEntity { 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 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() { - if (conference != null) { - return conference; - } else if (project != null) { - return project; - } else if (paper != null) { - return paper; - } else { - return grant; - } + return this.activity; + } + + public void setActivity(UserActivity activity) { + this.activity = activity; } } diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java index 116c4fc..cec24e7 100644 --- a/src/main/java/ru/ulstu/ping/repository/PingRepository.java +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -11,12 +11,10 @@ import java.util.List; public interface PingRepository extends JpaRepository { - @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); - @Query("SELECT p FROM Ping p WHERE (:activity != 'conferences' OR p.conference IS NOT NULL) " + - "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)") + @Query("SELECT p FROM Ping p WHERE (:activity = '' OR p.activityType = :activity)") List getPings(@Param("activity") String activity); @Query("SELECT p FROM Ping p WHERE (:dateFrom < date)") diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index 97cc353..e1c0035 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -3,6 +3,7 @@ package ru.ulstu.ping.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.conference.model.Conference; +import ru.ulstu.core.model.UserActivity; import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.repository.PingRepository; import ru.ulstu.user.service.UserService; @@ -27,8 +28,7 @@ public class PingService { } @Transactional - public Ping addPing(T activity) throws IOException { - pingScheduler.sendPingsInfo(); + public Ping addPing(UserActivity activity) throws IOException { Ping newPing = new Ping(new Date(), userService.getCurrentUser()); newPing.setActivity(activity); return pingRepository.save(newPing); diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 84324dd..54e8545 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -1,17 +1,15 @@ package ru.ulstu.project.model; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.UserActivity; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileData; import ru.ulstu.grant.model.Grant; -import ru.ulstu.ping.model.Ping; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -27,11 +25,8 @@ import java.util.List; import java.util.Set; @Entity +@DiscriminatorValue("PROJECT") public class Project extends BaseEntity implements UserActivity { - @Override - public Set getActivityUsers() { - return new HashSet<>(); - } public enum ProjectStatus { TECHNICAL_TASK("Техническое задание"), @@ -79,10 +74,10 @@ public class Project extends BaseEntity implements UserActivity { @ManyToMany(fetch = FetchType.LAZY) private List executors = new ArrayList<>(); - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) - @JoinColumn(name = "project_id") - @Fetch(FetchMode.SUBSELECT) - private List pings = new ArrayList<>(); +// @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) +// @JoinColumn(name = "project_id") +// @Fetch(FetchMode.SUBSELECT) +// private List pings = new ArrayList<>(); public String getTitle() { return title; @@ -149,15 +144,11 @@ public class Project extends BaseEntity implements UserActivity { } public Set getUsers() { - return new HashSet(getExecutors()); - } - - public void addPing(Ping ping) { - this.pings.add(new Ping()); + return new HashSet<>(getExecutors()); } @Override - public List getPings() { - return this.pings; + public Set getActivityUsers() { + return new HashSet<>(); } } diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index 9e1e285..6c00193 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -6,7 +6,6 @@ import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; import ru.ulstu.grant.repository.GrantRepository; -import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -16,7 +15,6 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.Arrays; -import java.util.Date; import java.util.List; import static org.springframework.util.ObjectUtils.isEmpty; @@ -133,8 +131,6 @@ public class ProjectService { @Transactional public void ping(int projectId) throws IOException { - Project project = findById(projectId); - project.addPing(new Ping(new Date(), userService.getCurrentUser())); - projectRepository.save(project); + pingService.addPing(findById(projectId)); } } diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index 7069c10..df2ed71 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -65,10 +65,10 @@ public class UserMvcController extends OdinController { @ModelAttribute("allActivities") public Map getAllActivites() { - return ImmutableMap.of("papers", "Статьи", - "grants", "Гранты", - "projects", "Проекты", - "conferences", "Конференции"); + return ImmutableMap.of("PAPER", "Статьи", + "GRANT", "Гранты", + "PROJECT", "Проекты", + "CONFERENCE", "Конференции"); } @GetMapping("/pings") diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index e8cdd4e..b4f8f28 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -14,7 +14,6 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; -import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.configuration.ApplicationProperties; import ru.ulstu.core.error.EntityIdIsNullException; @@ -82,9 +81,6 @@ public class UserService implements UserDetailsService { private final ConferenceService conferenceService; private final UserSessionService userSessionService; private final PingService pingService; - private final PaperService paperService; - private final ProjectService projectService; - private final GrantService grantService; public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder, @@ -94,10 +90,7 @@ public class UserService implements UserDetailsService { ApplicationProperties applicationProperties, @Lazy PingService pingService, @Lazy ConferenceService conferenceRepository, - @Lazy UserSessionService userSessionService, - @Lazy PaperService paperService, - @Lazy ProjectService projectService, - @Lazy GrantService grantService) throws ParseException { + @Lazy UserSessionService userSessionService) throws ParseException { this.userRepository = userRepository; this.passwordEncoder = passwordEncoder; this.userRoleRepository = userRoleRepository; @@ -108,9 +101,6 @@ public class UserService implements UserDetailsService { this.timetableService = new TimetableService(); this.userSessionService = userSessionService; this.pingService = pingService; - this.paperService = paperService; - this.projectService = projectService; - this.grantService = grantService; } private User getUserByEmail(String email) { @@ -418,24 +408,9 @@ public class UserService implements UserDetailsService { } Map activitiesPings = new HashMap<>(); - List 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)) { continue; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7e793c0..f4be778 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -24,7 +24,7 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact # JPA Settings spring.datasource.url=jdbc:postgresql://localhost:5432/ng-tracker spring.datasource.username=postgres -spring.datasource.password=password +spring.datasource.password=postgres spring.datasource.driverclassName=org.postgresql.Driver spring.jpa.hibernate.ddl-auto=validate # Liquibase Settings @@ -34,7 +34,7 @@ liquibase.change-log=classpath:db/changelog-master.xml # Application Settings ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.undead-user-login=admin -ng-tracker.dev-mode=false +ng-tracker.dev-mode=true ng-tracker.debug_email= ng-tracker.use-https=false ng-tracker.check-run=false \ No newline at end of file diff --git a/src/main/resources/db/changelog-20190531_000000-schema.xml b/src/main/resources/db/changelog-20190531_000000-schema.xml index 51fffe6..c035b35 100644 --- a/src/main/resources/db/changelog-20190531_000000-schema.xml +++ b/src/main/resources/db/changelog-20190531_000000-schema.xml @@ -4,15 +4,8 @@ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> - - - + + - - - diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 5c26d0f..e92e4c6 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -562,6 +562,7 @@ $(this).autocomplete("search"); }); + /*]]>*/ diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index 95f4820..686211e 100644 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -276,14 +276,4 @@ public class ConferenceServiceTest { 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)); - } } \ No newline at end of file From 019ac6e0adb4e0414b0207a53ba0ec33fb5f4cd9 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Thu, 6 Jun 2019 00:21:19 +0400 Subject: [PATCH 6/8] #112 fix ping authors in grant --- src/main/resources/templates/grants/grant.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 5781a3d..ede1486 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -199,13 +199,13 @@ + -->
- -->
From 59e52aaf4a08a5e2878cf409901175fdc37e79b2 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 6 Jun 2019 17:07:25 +0400 Subject: [PATCH 7/8] different drivers --- deploy/gdccloud/deploy.sh | 2 +- .../configuration/ApplicationProperties.java | 10 ++++++++++ .../java/ru/ulstu/grant/service/KiasService.java | 15 ++++++++++++--- src/main/resources/application.properties | 3 ++- src/test/java/context/Context.java | 2 -- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/deploy/gdccloud/deploy.sh b/deploy/gdccloud/deploy.sh index de785fd..50d3d5c 100644 --- a/deploy/gdccloud/deploy.sh +++ b/deploy/gdccloud/deploy.sh @@ -18,6 +18,6 @@ fi ssh $USERSERVER "cd /tmp && rm -rf $ARTIFACT_NAME*.jar && echo `date` 'killed' >> log_$ARTIFACT_NAME" scp build/libs/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar $USERSERVER:/tmp/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar -ssh $USERSERVER -f "cd /tmp/ && /opt/jdk1.8.0_192/bin/java -jar $ARTIFACT_NAME-0.1.0-SNAPSHOT.jar -Xms 512m -Xmx 1024m --server.port=8443 --server.http.port=8080 --ng-tracker.base-url=http://193.110.3.124:8080 --ng-tracker.dev-mode=false >> /home/user/logfile_$ARTIFACT_NAME" & +ssh $USERSERVER -f "cd /tmp/ && /opt/jdk1.8.0_192/bin/java -jar $ARTIFACT_NAME-0.1.0-SNAPSHOT.jar -Xms 512m -Xmx 1024m --server.port=8443 --server.http.port=8080 --ng-tracker.base-url=http://193.110.3.124:8080 --ng-tracker.dev-mode=false --ng-tracker.driver-path=/home/user >> /home/user/logfile_$ARTIFACT_NAME" & sleep 10 echo "is deployed" \ No newline at end of file diff --git a/src/main/java/ru/ulstu/configuration/ApplicationProperties.java b/src/main/java/ru/ulstu/configuration/ApplicationProperties.java index 49efac4..a1c0ba2 100644 --- a/src/main/java/ru/ulstu/configuration/ApplicationProperties.java +++ b/src/main/java/ru/ulstu/configuration/ApplicationProperties.java @@ -23,6 +23,8 @@ public class ApplicationProperties { private String debugEmail; + private String driverPath; + public boolean isUseHttps() { return useHttps; } @@ -70,4 +72,12 @@ public class ApplicationProperties { public void setDebugEmail(String debugEmail) { this.debugEmail = debugEmail; } + + public String getDriverPath() { + return driverPath; + } + + public void setDriverPath(String driverPath) { + this.driverPath = driverPath; + } } diff --git a/src/main/java/ru/ulstu/grant/service/KiasService.java b/src/main/java/ru/ulstu/grant/service/KiasService.java index 618e83c..dbeacf5 100644 --- a/src/main/java/ru/ulstu/grant/service/KiasService.java +++ b/src/main/java/ru/ulstu/grant/service/KiasService.java @@ -5,16 +5,20 @@ 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.configuration.ApplicationProperties; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.page.KiasPage; import ru.ulstu.user.service.UserService; +import java.nio.file.Paths; import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.List; +import static org.apache.commons.lang3.StringUtils.isEmpty; + @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"; @@ -27,9 +31,12 @@ public class KiasService { private final static String DRIVER_TYPE = "webdriver.chrome.driver"; private final UserService userService; + private final ApplicationProperties applicationProperties; - public KiasService(UserService userService) { + public KiasService(UserService userService, + ApplicationProperties applicationProperties) { this.userService = userService; + this.applicationProperties = applicationProperties; } public List getNewGrantsDto() throws ParseException { @@ -78,8 +85,10 @@ public class KiasService { } private String getDriverExecutablePath() { - return KiasService.class.getClassLoader().getResource( - String.format(DRIVER_LOCATION, getDriverExecutable(isWindows()))).getFile(); + return isEmpty(applicationProperties.getDriverPath()) + ? KiasService.class.getClassLoader() + .getResource(String.format(DRIVER_LOCATION, getDriverExecutable(isWindows()))).getFile() + : Paths.get(applicationProperties.getDriverPath(), getDriverExecutable(isWindows())).toString(); } private String getDriverExecutable(boolean isWindows) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f4be778..f4d9c36 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -37,4 +37,5 @@ ng-tracker.undead-user-login=admin ng-tracker.dev-mode=true ng-tracker.debug_email= ng-tracker.use-https=false -ng-tracker.check-run=false \ No newline at end of file +ng-tracker.check-run=false +ng-tracker.driver-path= diff --git a/src/test/java/context/Context.java b/src/test/java/context/Context.java index b32c08e..474b1cb 100644 --- a/src/test/java/context/Context.java +++ b/src/test/java/context/Context.java @@ -6,8 +6,6 @@ import org.openqa.selenium.WebDriver; import java.util.concurrent.TimeUnit; -//import org.openqa.selenium.support.PageFactory; - public abstract class Context { private final static String DRIVER_LOCATION = "drivers/%s"; From f8c1e52ca449691ef886539320751decccce683a Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 7 Jun 2019 09:48:07 +0400 Subject: [PATCH 8/8] add kias loader to rest --- .../grant/controller/GrantRestController.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/ru/ulstu/grant/controller/GrantRestController.java diff --git a/src/main/java/ru/ulstu/grant/controller/GrantRestController.java b/src/main/java/ru/ulstu/grant/controller/GrantRestController.java new file mode 100644 index 0000000..9b90a4d --- /dev/null +++ b/src/main/java/ru/ulstu/grant/controller/GrantRestController.java @@ -0,0 +1,29 @@ +package ru.ulstu.grant.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import ru.ulstu.configuration.Constants; +import ru.ulstu.grant.service.GrantService; + +import java.io.IOException; +import java.text.ParseException; + +import static ru.ulstu.paper.controller.PaperRestController.URL; + +@RestController +@RequestMapping(URL) +public class GrantRestController { + public static final String URL = Constants.API_1_0 + "grants"; + + private final GrantService grantService; + + public GrantRestController(GrantService grantService) { + this.grantService = grantService; + } + + @GetMapping("/grab") + public void grab() throws IOException, ParseException { + grantService.createFromKias(); + } +}