From 5bff419dbda018dec4eaaf262fc83cbf63bac891 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 16:44:17 +0400 Subject: [PATCH 1/7] #68 added ping table --- .../db/changelog-20190424_000000-schema.xml | 28 +++++++++++++++++++ src/main/resources/db/changelog-master.xml | 1 + 2 files changed, 29 insertions(+) create mode 100644 src/main/resources/db/changelog-20190424_000000-schema.xml diff --git a/src/main/resources/db/changelog-20190424_000000-schema.xml b/src/main/resources/db/changelog-20190424_000000-schema.xml new file mode 100644 index 0000000..50c53f8 --- /dev/null +++ b/src/main/resources/db/changelog-20190424_000000-schema.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index d0f1837..7f40dc7 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -31,4 +31,5 @@ + \ No newline at end of file From b16b3ed2e3ab3f20dc4096179bea5ca0c76f0cf4 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 17:41:19 +0400 Subject: [PATCH 2/7] #68 added class structure --- src/main/java/ru/ulstu/ping/model/Ping.java | 58 +++++++++++++++++++ .../ulstu/ping/repository/PingRepository.java | 7 +++ .../ru/ulstu/ping/service/PingService.java | 13 +++++ .../db/changelog-20190424_000000-schema.xml | 6 +- 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ru/ulstu/ping/model/Ping.java create mode 100644 src/main/java/ru/ulstu/ping/repository/PingRepository.java create mode 100644 src/main/java/ru/ulstu/ping/service/PingService.java diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java new file mode 100644 index 0000000..d3fea2b --- /dev/null +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -0,0 +1,58 @@ +package ru.ulstu.ping.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.format.annotation.DateTimeFormat; +import ru.ulstu.core.model.BaseEntity; +import ru.ulstu.user.model.User; + +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.Date; + +@Entity +@Table(name = "ping") +public class Ping extends BaseEntity { + @Temporal(value = TemporalType.TIMESTAMP) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date date; + + @ManyToOne(optional = false) + @JoinColumn(name = "users_id") + private User user; + + public Ping() { + } + + public Ping(Date date, User user) { + this.date = date; + this.user = user; + } + + public Ping(@JsonProperty("id") Integer id, + @JsonProperty("date") Date date, + @JsonProperty("user") User user) { + setId(id); + this.date = date; + this.user = user; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/src/main/java/ru/ulstu/ping/repository/PingRepository.java b/src/main/java/ru/ulstu/ping/repository/PingRepository.java new file mode 100644 index 0000000..ebafc0c --- /dev/null +++ b/src/main/java/ru/ulstu/ping/repository/PingRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.ping.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.ping.model.Ping; + +public interface PingRepository extends JpaRepository { +} diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java new file mode 100644 index 0000000..07f108a --- /dev/null +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -0,0 +1,13 @@ +package ru.ulstu.ping.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.ping.repository.PingRepository; + +@Service +public class PingService { + private final PingRepository pingRepository; + + public PingService(PingRepository pingRepository) { + this.pingRepository = pingRepository; + } +} diff --git a/src/main/resources/db/changelog-20190424_000000-schema.xml b/src/main/resources/db/changelog-20190424_000000-schema.xml index 50c53f8..d61b38a 100644 --- a/src/main/resources/db/changelog-20190424_000000-schema.xml +++ b/src/main/resources/db/changelog-20190424_000000-schema.xml @@ -10,15 +10,15 @@ - + - Date: Wed, 24 Apr 2019 18:55:52 +0400 Subject: [PATCH 3/7] #68 added demo version of charts, using highcharts lib --- .../controller/ConferenceController.java | 21 +++ .../templates/conferences/dashboard.html | 129 ++++++++++++++++++ .../fragments/confNavigationFragment.html | 2 +- 3 files changed, 151 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index a416345..6afa73e 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -21,6 +21,7 @@ import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; @@ -57,6 +58,26 @@ public class ConferenceController { @GetMapping("/dashboard") public void getDashboard(ModelMap modelMap) { modelMap.put("conferences", conferenceService.findAllActiveDto()); + //first, add the regional sales + Integer northeastSales = 17089; + Integer westSales = 10603; + Integer midwestSales = 5223; + Integer southSales = 10111; + + modelMap.addAttribute("northeastSales", northeastSales); + modelMap.addAttribute("southSales", southSales); + modelMap.addAttribute("midwestSales", midwestSales); + modelMap.addAttribute("westSales", westSales); + + //now add sales by lure type + List inshoreSales = Arrays.asList(4074, 3455, 4112); + List nearshoreSales = Arrays.asList(3222, 3011, 3788); + List offshoreSales = Arrays.asList(7811, 7098, 6455); + + modelMap.addAttribute("inshoreSales", inshoreSales); + modelMap.addAttribute("nearshoreSales", nearshoreSales); + modelMap.addAttribute("offshoreSales", offshoreSales); + } @GetMapping("/conference") diff --git a/src/main/resources/templates/conferences/dashboard.html b/src/main/resources/templates/conferences/dashboard.html index cb4f2c0..3480cc8 100644 --- a/src/main/resources/templates/conferences/dashboard.html +++ b/src/main/resources/templates/conferences/dashboard.html @@ -4,6 +4,7 @@ layout:decorator="default" xmlns:th=""> +
@@ -21,8 +22,136 @@
+
+ +
+ \ No newline at end of file diff --git a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html index 7e67365..7bf9d27 100644 --- a/src/main/resources/templates/conferences/fragments/confNavigationFragment.html +++ b/src/main/resources/templates/conferences/fragments/confNavigationFragment.html @@ -21,7 +21,7 @@
- Новая конференцию + Новая конференция
From d921def09dfe5df401c47e4acc893ba41a3eb151 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 21:05:25 +0400 Subject: [PATCH 4/7] #68 added ping method --- .../controller/ConferenceController.java | 30 +++++--------- .../ru/ulstu/conference/model/Conference.java | 2 +- .../conference/service/ConferenceService.java | 41 ++++++++++++++++++- src/main/java/ru/ulstu/ping/model/Ping.java | 19 ++++++++- .../ru/ulstu/ping/service/PingService.java | 19 ++++++++- .../templates/conferences/conference.html | 5 ++- .../templates/conferences/dashboard.html | 21 +++------- 7 files changed, 96 insertions(+), 41 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 6afa73e..01eac3b 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -21,7 +21,6 @@ import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; @@ -58,26 +57,8 @@ public class ConferenceController { @GetMapping("/dashboard") public void getDashboard(ModelMap modelMap) { modelMap.put("conferences", conferenceService.findAllActiveDto()); - //first, add the regional sales - Integer northeastSales = 17089; - Integer westSales = 10603; - Integer midwestSales = 5223; - Integer southSales = 10111; - - modelMap.addAttribute("northeastSales", northeastSales); - modelMap.addAttribute("southSales", southSales); - modelMap.addAttribute("midwestSales", midwestSales); - modelMap.addAttribute("westSales", westSales); - - //now add sales by lure type - List inshoreSales = Arrays.asList(4074, 3455, 4112); - List nearshoreSales = Arrays.asList(3222, 3011, 3788); - List offshoreSales = Arrays.asList(7811, 7098, 6455); - - modelMap.addAttribute("inshoreSales", inshoreSales); - modelMap.addAttribute("nearshoreSales", nearshoreSales); - modelMap.addAttribute("offshoreSales", offshoreSales); + conferenceService.setChartData(modelMap); // example } @GetMapping("/conference") @@ -145,6 +126,15 @@ public class ConferenceController { return CONFERENCE_PAGE; } + @PostMapping(value = "/conference", params = "ping") + public String ping(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { + if (errors.hasErrors()) { + return CONFERENCE_PAGE; + } + conferenceService.ping(conferenceDto); + return CONFERENCE_PAGE; + } + @ModelAttribute("allParticipation") public List getAllParticipation() { return conferenceService.getAllParticipations(); diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index e252e4d..6221b64 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -35,7 +35,7 @@ public class Conference extends BaseEntity { private String url; - private int ping; + private int ping = 0; @Column(name = "begin_date") @Temporal(TemporalType.TIMESTAMP) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index e5ce29f..0287e31 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.ui.ModelMap; import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; @@ -12,6 +13,7 @@ import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.ping.service.PingService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -33,17 +35,20 @@ public class ConferenceService { private final DeadlineService deadlineService; private final PaperService paperService; private final UserService userService; + private final PingService pingService; public ConferenceService(ConferenceRepository conferenceRepository, ConferenceUserService conferenceUserService, DeadlineService deadlineService, PaperService paperService, - UserService userService) { + UserService userService, + PingService pingService) { this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; this.paperService = paperService; this.userService = userService; + this.pingService = pingService; } public ConferenceDto getExistConferenceById(Integer id) { @@ -141,7 +146,8 @@ public class ConferenceService { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); - conference.setPing(0); + Integer pingCount = conferenceDto.getPing() - conference.getPing(); // for notification + conference.setPing(conference.getPing()); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); conference.setPapers(conferenceDto.getPapers()); @@ -173,4 +179,35 @@ public class ConferenceService { public List findAllActive() { return conferenceRepository.findAllActive(new Date()); } + + public void ping(ConferenceDto conferenceDto) throws IOException { + pingService.addPing(findOne(conferenceDto.getId())); +// conferenceDto.setPing(conferenceDto.getPing() + 1); + } + + public Conference findOne(Integer conferenceId) { + return conferenceRepository.findOne(conferenceId); + } + + public void setChartData(ModelMap modelMap) { + //first, add the regional sales + Integer northeastSales = 17089; + Integer westSales = 10603; + Integer midwestSales = 5223; + Integer southSales = 10111; + + modelMap.addAttribute("northeastSales", northeastSales); + modelMap.addAttribute("southSales", southSales); + modelMap.addAttribute("midwestSales", midwestSales); + modelMap.addAttribute("westSales", westSales); + + //now add sales by lure type + List inshoreSales = Arrays.asList(4074, 3455, 4112); + List nearshoreSales = Arrays.asList(3222, 3011, 3788); + List offshoreSales = Arrays.asList(7811, 7098, 6455); + + modelMap.addAttribute("inshoreSales", inshoreSales); + modelMap.addAttribute("nearshoreSales", nearshoreSales); + modelMap.addAttribute("offshoreSales", offshoreSales); + } } diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java index d3fea2b..5ab0860 100644 --- a/src/main/java/ru/ulstu/ping/model/Ping.java +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -1,7 +1,9 @@ package ru.ulstu.ping.model; import com.fasterxml.jackson.annotation.JsonProperty; +import com.sun.istack.internal.Nullable; import org.springframework.format.annotation.DateTimeFormat; +import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.user.model.User; @@ -24,6 +26,11 @@ public class Ping extends BaseEntity { @JoinColumn(name = "users_id") private User user; + @Nullable + @ManyToOne(optional = false) + @JoinColumn(name = "conference_id") + private Conference conference; + public Ping() { } @@ -34,10 +41,12 @@ public class Ping extends BaseEntity { public Ping(@JsonProperty("id") Integer id, @JsonProperty("date") Date date, - @JsonProperty("user") User user) { + @JsonProperty("user") User user, + @JsonProperty("conference") Conference conference) { setId(id); this.date = date; this.user = user; + this.conference = conference; } public Date getDate() { @@ -55,4 +64,12 @@ public class Ping extends BaseEntity { public void setUser(User user) { this.user = user; } + + public Conference getConference() { + return conference; + } + + public void setConference(Conference conference) { + this.conference = conference; + } } diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index 07f108a..ff0d249 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -1,13 +1,30 @@ 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.ping.model.Ping; import ru.ulstu.ping.repository.PingRepository; +import ru.ulstu.user.service.UserService; + +import java.io.IOException; +import java.util.Date; @Service public class PingService { private final PingRepository pingRepository; + private final UserService userService; - public PingService(PingRepository pingRepository) { + public PingService(PingRepository pingRepository, + UserService userService) { this.pingRepository = pingRepository; + this.userService = userService; + } + + @Transactional + public void addPing(Conference conference) throws IOException { + Ping newPing = new Ping(new Date(), userService.getCurrentUser()); + newPing.setConference(conference); + pingRepository.save(newPing); } } diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 184f5b5..26fa695 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -121,7 +121,10 @@ -
+
+ +

+
+ From d4b514a9b0631d287314d990ea21f685497f5c27 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 21:24:32 +0400 Subject: [PATCH 5/7] #68 added ping in db --- .../ru/ulstu/conference/repository/ConferenceRepository.java | 5 +++++ .../java/ru/ulstu/conference/service/ConferenceService.java | 4 ++-- src/main/java/ru/ulstu/ping/model/Ping.java | 2 -- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index cb8a488..25a481c 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -1,6 +1,7 @@ package ru.ulstu.conference.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; @@ -16,4 +17,8 @@ public interface ConferenceRepository extends JpaRepository @Query("SELECT c FROM Conference c WHERE c.beginDate > :date") List findAllActive(@Param("date") Date date); + + @Modifying + @Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id") + int updatePingConference(@Param("id") Integer id); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 0287e31..370d7d6 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -146,7 +146,6 @@ public class ConferenceService { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); conference.setUrl(conferenceDto.getUrl()); - Integer pingCount = conferenceDto.getPing() - conference.getPing(); // for notification conference.setPing(conference.getPing()); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); @@ -180,9 +179,10 @@ public class ConferenceService { return conferenceRepository.findAllActive(new Date()); } + @Transactional public void ping(ConferenceDto conferenceDto) throws IOException { pingService.addPing(findOne(conferenceDto.getId())); -// conferenceDto.setPing(conferenceDto.getPing() + 1); + conferenceRepository.updatePingConference(conferenceDto.getId()); } public Conference findOne(Integer conferenceId) { diff --git a/src/main/java/ru/ulstu/ping/model/Ping.java b/src/main/java/ru/ulstu/ping/model/Ping.java index 5ab0860..c7e4c5e 100644 --- a/src/main/java/ru/ulstu/ping/model/Ping.java +++ b/src/main/java/ru/ulstu/ping/model/Ping.java @@ -1,7 +1,6 @@ package ru.ulstu.ping.model; import com.fasterxml.jackson.annotation.JsonProperty; -import com.sun.istack.internal.Nullable; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; @@ -26,7 +25,6 @@ public class Ping extends BaseEntity { @JoinColumn(name = "users_id") private User user; - @Nullable @ManyToOne(optional = false) @JoinColumn(name = "conference_id") private Conference conference; From 70d260c34b7196f3921c0ad092d17f90def836a4 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 24 Apr 2019 21:52:13 +0400 Subject: [PATCH 6/7] #68 ping but style --- .../conference/controller/ConferenceController.java | 2 +- src/main/resources/public/css/conference.css | 10 ++++++++++ .../resources/templates/conferences/conference.html | 7 ++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 01eac3b..8da0cce 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -126,7 +126,7 @@ public class ConferenceController { return CONFERENCE_PAGE; } - @PostMapping(value = "/conference", params = "ping") + @PostMapping(value = "/conference", params = "pingConference") public String ping(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { if (errors.hasErrors()) { return CONFERENCE_PAGE; diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index ad06b3c..8572b08 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -77,6 +77,16 @@ body { border-right: 1px solid #ced4da; } +#ping-button[disabled=disabled] { + background-color: #ced4da; + border-color: #c2c5c7; +} + +#ping-button[disabled=disabled]:hover { + background-color: #737475 !important; + border-color: #5d5e5f !important; +} + #take-part[disabled=disabled] { background-color: #ced4da; border-color: #c2c5c7; diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 26fa695..9cd9c38 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -122,9 +122,10 @@