From da8b5cba1198e0e155df8490d3f305bbb4e04cd1 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 31 Dec 2018 12:35:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B9=20=D0=B8=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => database}/entity/Message.java | 5 ++- .../{ => database}/entity/NextUnit.java | 4 +- .../{ => database}/entity/SaveUnit.java | 2 +- .../{ => database}/entity/SocialNetworks.java | 2 +- .../{ => database}/entity/Unit.java | 2 +- .../{ => database}/entity/User.java | 5 +-- .../repository/MessageRepository.java | 4 +- .../repository/NextUnitRepositoriy.java | 4 +- .../repository/SaveUnitRepositoriy.java | 4 +- .../repository/SocialNetworksRepositoriy.java | 4 +- .../repository/UnitRepositoriy.java | 4 +- .../repository/UserRepositoriy.java | 4 +- .../database/service/MessageService.java | 8 ++++ .../database/service/NextUnitService.java | 4 ++ .../database/service/SaveUnitService.java | 4 ++ .../service/SocialNetworksService.java | 4 ++ .../database/service/UnitService.java | 10 +++++ .../database/service/UserService.java | 10 +++++ .../service/impl/MessageServiceImpl.java | 18 +++++++++ .../service/impl/NextUnitServiceImpl.java | 6 +-- .../service/impl/SaveUnitServiceImpl.java | 6 +-- .../impl/SocialNetworksServiceImpl.java | 6 +-- .../service/impl/UnitServiceImpl.java | 8 ++-- .../service/impl/UserServiceImpl.java | 8 ++-- .../consultant/service/MessageService.java | 8 ---- .../consultant/service/NextUnitService.java | 4 -- .../consultant/service/SaveUnitService.java | 4 -- .../service/SocialNetworksService.java | 4 -- .../consultant/service/UnitService.java | 10 ----- .../consultant/service/UserService.java | 10 ----- .../service/impl/MessageServiceImpl.java | 16 -------- vk-bot/pom.xml | 31 +++++++++++++-- .../vkbot/{config/TestMain.java => Main.java} | 20 ++++++---- .../org/sadtech/vkbot/config/DataConfig.java | 7 +--- .../sadtech/vkbot/config/SpringConfigVk.java | 7 +--- .../java/org/sadtech/vkbot/entity/User.java | 16 -------- .../sadtech/vkbot/listener/Observable.java | 1 - .../org/sadtech/vkbot/listener/Observer.java | 2 +- .../listener/data/impl/ResponseDataVk.java | 2 +- .../vkbot/listener/handlers/Handled.java | 7 ++++ .../listener/handlers/MessageHandlerVk.java | 21 ---------- .../DispetcherHandlerVk.java} | 16 ++++---- .../handlers/impl/MessageHandlerVk.java | 39 +++++++++++++++++++ .../vkbot/listener/impl/EventListenerVk.java | 2 - .../sadtech/vkbot/repo/UserRepository.java | 9 ----- .../sadtech/vkbot/service/UserService.java | 11 ------ .../vkbot/service/impl/UserServiceImpl.java | 26 ------------- 47 files changed, 200 insertions(+), 209 deletions(-) rename core/src/main/java/org/sadtech/consultant/{ => database}/entity/Message.java (61%) rename core/src/main/java/org/sadtech/consultant/{ => database}/entity/NextUnit.java (62%) rename core/src/main/java/org/sadtech/consultant/{ => database}/entity/SaveUnit.java (79%) rename core/src/main/java/org/sadtech/consultant/{ => database}/entity/SocialNetworks.java (81%) rename core/src/main/java/org/sadtech/consultant/{ => database}/entity/Unit.java (81%) rename core/src/main/java/org/sadtech/consultant/{ => database}/entity/User.java (68%) rename core/src/main/java/org/sadtech/consultant/{ => database}/repository/MessageRepository.java (56%) rename core/src/main/java/org/sadtech/consultant/{ => database}/repository/NextUnitRepositoriy.java (57%) rename core/src/main/java/org/sadtech/consultant/{ => database}/repository/SaveUnitRepositoriy.java (56%) rename core/src/main/java/org/sadtech/consultant/{ => database}/repository/SocialNetworksRepositoriy.java (57%) rename core/src/main/java/org/sadtech/consultant/{ => database}/repository/UnitRepositoriy.java (56%) rename core/src/main/java/org/sadtech/consultant/{ => database}/repository/UserRepositoriy.java (56%) create mode 100644 core/src/main/java/org/sadtech/consultant/database/service/MessageService.java create mode 100644 core/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java create mode 100644 core/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java create mode 100644 core/src/main/java/org/sadtech/consultant/database/service/SocialNetworksService.java create mode 100644 core/src/main/java/org/sadtech/consultant/database/service/UnitService.java create mode 100644 core/src/main/java/org/sadtech/consultant/database/service/UserService.java create mode 100644 core/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java rename core/src/main/java/org/sadtech/consultant/{ => database}/service/impl/NextUnitServiceImpl.java (56%) rename core/src/main/java/org/sadtech/consultant/{ => database}/service/impl/SaveUnitServiceImpl.java (56%) rename core/src/main/java/org/sadtech/consultant/{ => database}/service/impl/SocialNetworksServiceImpl.java (56%) rename core/src/main/java/org/sadtech/consultant/{ => database}/service/impl/UnitServiceImpl.java (60%) rename core/src/main/java/org/sadtech/consultant/{ => database}/service/impl/UserServiceImpl.java (67%) delete mode 100644 core/src/main/java/org/sadtech/consultant/service/MessageService.java delete mode 100644 core/src/main/java/org/sadtech/consultant/service/NextUnitService.java delete mode 100644 core/src/main/java/org/sadtech/consultant/service/SaveUnitService.java delete mode 100644 core/src/main/java/org/sadtech/consultant/service/SocialNetworksService.java delete mode 100644 core/src/main/java/org/sadtech/consultant/service/UnitService.java delete mode 100644 core/src/main/java/org/sadtech/consultant/service/UserService.java delete mode 100644 core/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java rename vk-bot/src/main/java/org/sadtech/vkbot/{config/TestMain.java => Main.java} (54%) delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/entity/User.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/Handled.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/MessageHandlerVk.java rename vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/{DispetcherHandler.java => impl/DispetcherHandlerVk.java} (67%) create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/MessageHandlerVk.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/repo/UserRepository.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/service/UserService.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/service/impl/UserServiceImpl.java diff --git a/core/src/main/java/org/sadtech/consultant/entity/Message.java b/core/src/main/java/org/sadtech/consultant/database/entity/Message.java similarity index 61% rename from core/src/main/java/org/sadtech/consultant/entity/Message.java rename to core/src/main/java/org/sadtech/consultant/database/entity/Message.java index 454188f..e729d25 100644 --- a/core/src/main/java/org/sadtech/consultant/entity/Message.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Message.java @@ -1,8 +1,9 @@ -package org.sadtech.consultant.entity; +package org.sadtech.consultant.database.entity; import lombok.Data; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; import javax.persistence.Id; @Data @@ -10,9 +11,11 @@ import javax.persistence.Id; public class Message { @Id + @GeneratedValue private Long idMess; private Long idUser; private String text; + private String date; } diff --git a/core/src/main/java/org/sadtech/consultant/entity/NextUnit.java b/core/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java similarity index 62% rename from core/src/main/java/org/sadtech/consultant/entity/NextUnit.java rename to core/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java index 922cd20..64281d3 100644 --- a/core/src/main/java/org/sadtech/consultant/entity/NextUnit.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java @@ -1,13 +1,15 @@ -package org.sadtech.consultant.entity; +package org.sadtech.consultant.database.entity; import lombok.Data; import javax.persistence.Entity; +import javax.persistence.Id; @Entity @Data public class NextUnit { + @Id private Long id; private Long idNext; diff --git a/core/src/main/java/org/sadtech/consultant/entity/SaveUnit.java b/core/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java similarity index 79% rename from core/src/main/java/org/sadtech/consultant/entity/SaveUnit.java rename to core/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java index 8e7a447..b5df08e 100644 --- a/core/src/main/java/org/sadtech/consultant/entity/SaveUnit.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.entity; +package org.sadtech.consultant.database.entity; import lombok.Data; diff --git a/core/src/main/java/org/sadtech/consultant/entity/SocialNetworks.java b/core/src/main/java/org/sadtech/consultant/database/entity/SocialNetworks.java similarity index 81% rename from core/src/main/java/org/sadtech/consultant/entity/SocialNetworks.java rename to core/src/main/java/org/sadtech/consultant/database/entity/SocialNetworks.java index d167608..d3c78a4 100644 --- a/core/src/main/java/org/sadtech/consultant/entity/SocialNetworks.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/SocialNetworks.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.entity; +package org.sadtech.consultant.database.entity; import lombok.Data; diff --git a/core/src/main/java/org/sadtech/consultant/entity/Unit.java b/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java similarity index 81% rename from core/src/main/java/org/sadtech/consultant/entity/Unit.java rename to core/src/main/java/org/sadtech/consultant/database/entity/Unit.java index 0f13505..a267686 100644 --- a/core/src/main/java/org/sadtech/consultant/entity/Unit.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.entity; +package org.sadtech.consultant.database.entity; import lombok.Data; diff --git a/core/src/main/java/org/sadtech/consultant/entity/User.java b/core/src/main/java/org/sadtech/consultant/database/entity/User.java similarity index 68% rename from core/src/main/java/org/sadtech/consultant/entity/User.java rename to core/src/main/java/org/sadtech/consultant/database/entity/User.java index c58617b..10271c7 100644 --- a/core/src/main/java/org/sadtech/consultant/entity/User.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/User.java @@ -1,9 +1,8 @@ -package org.sadtech.consultant.entity; +package org.sadtech.consultant.database.entity; import lombok.Data; import javax.persistence.Entity; -import javax.persistence.GeneratedValue; import javax.persistence.Id; import java.util.List; @@ -17,7 +16,7 @@ public class User { private String token; private String lastName; private String city; - private List socialNetworks; +// private List socialNetworks; } diff --git a/core/src/main/java/org/sadtech/consultant/repository/MessageRepository.java b/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java similarity index 56% rename from core/src/main/java/org/sadtech/consultant/repository/MessageRepository.java rename to core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java index aa0ec3b..51d73ed 100644 --- a/core/src/main/java/org/sadtech/consultant/repository/MessageRepository.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.repository; +package org.sadtech.consultant.database.repository; -import org.sadtech.consultant.entity.Message; +import org.sadtech.consultant.database.entity.Message; import org.springframework.data.jpa.repository.JpaRepository; public interface MessageRepository extends JpaRepository { diff --git a/core/src/main/java/org/sadtech/consultant/repository/NextUnitRepositoriy.java b/core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepositoriy.java similarity index 57% rename from core/src/main/java/org/sadtech/consultant/repository/NextUnitRepositoriy.java rename to core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepositoriy.java index 6cc97d5..eff732b 100644 --- a/core/src/main/java/org/sadtech/consultant/repository/NextUnitRepositoriy.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepositoriy.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.repository; +package org.sadtech.consultant.database.repository; -import org.sadtech.consultant.entity.NextUnit; +import org.sadtech.consultant.database.entity.NextUnit; import org.springframework.data.jpa.repository.JpaRepository; public interface NextUnitRepositoriy extends JpaRepository { diff --git a/core/src/main/java/org/sadtech/consultant/repository/SaveUnitRepositoriy.java b/core/src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java similarity index 56% rename from core/src/main/java/org/sadtech/consultant/repository/SaveUnitRepositoriy.java rename to core/src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java index d1cd49a..7ff8077 100644 --- a/core/src/main/java/org/sadtech/consultant/repository/SaveUnitRepositoriy.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.repository; +package org.sadtech.consultant.database.repository; -import org.sadtech.consultant.entity.SaveUnit; +import org.sadtech.consultant.database.entity.SaveUnit; import org.springframework.data.jpa.repository.JpaRepository; public interface SaveUnitRepositoriy extends JpaRepository { diff --git a/core/src/main/java/org/sadtech/consultant/repository/SocialNetworksRepositoriy.java b/core/src/main/java/org/sadtech/consultant/database/repository/SocialNetworksRepositoriy.java similarity index 57% rename from core/src/main/java/org/sadtech/consultant/repository/SocialNetworksRepositoriy.java rename to core/src/main/java/org/sadtech/consultant/database/repository/SocialNetworksRepositoriy.java index 1e9e84a..7c606ae 100644 --- a/core/src/main/java/org/sadtech/consultant/repository/SocialNetworksRepositoriy.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/SocialNetworksRepositoriy.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.repository; +package org.sadtech.consultant.database.repository; -import org.sadtech.consultant.entity.SocialNetworks; +import org.sadtech.consultant.database.entity.SocialNetworks; import org.springframework.data.jpa.repository.JpaRepository; public interface SocialNetworksRepositoriy extends JpaRepository { diff --git a/core/src/main/java/org/sadtech/consultant/repository/UnitRepositoriy.java b/core/src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java similarity index 56% rename from core/src/main/java/org/sadtech/consultant/repository/UnitRepositoriy.java rename to core/src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java index f804f65..51e7cca 100644 --- a/core/src/main/java/org/sadtech/consultant/repository/UnitRepositoriy.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.repository; +package org.sadtech.consultant.database.repository; -import org.sadtech.consultant.entity.Unit; +import org.sadtech.consultant.database.entity.Unit; import org.springframework.data.jpa.repository.JpaRepository; public interface UnitRepositoriy extends JpaRepository { diff --git a/core/src/main/java/org/sadtech/consultant/repository/UserRepositoriy.java b/core/src/main/java/org/sadtech/consultant/database/repository/UserRepositoriy.java similarity index 56% rename from core/src/main/java/org/sadtech/consultant/repository/UserRepositoriy.java rename to core/src/main/java/org/sadtech/consultant/database/repository/UserRepositoriy.java index 25e5e05..f92f0d1 100644 --- a/core/src/main/java/org/sadtech/consultant/repository/UserRepositoriy.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/UserRepositoriy.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.repository; +package org.sadtech.consultant.database.repository; -import org.sadtech.consultant.entity.User; +import org.sadtech.consultant.database.entity.User; import org.springframework.data.jpa.repository.JpaRepository; public interface UserRepositoriy extends JpaRepository { diff --git a/core/src/main/java/org/sadtech/consultant/database/service/MessageService.java b/core/src/main/java/org/sadtech/consultant/database/service/MessageService.java new file mode 100644 index 0000000..c4edb28 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/MessageService.java @@ -0,0 +1,8 @@ +package org.sadtech.consultant.database.service; + +import org.sadtech.consultant.database.entity.Message; + +public interface MessageService { + + void addMessage(Message message); +} diff --git a/core/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java b/core/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java new file mode 100644 index 0000000..0106520 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java @@ -0,0 +1,4 @@ +package org.sadtech.consultant.database.service; + +public interface NextUnitService { +} diff --git a/core/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java b/core/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java new file mode 100644 index 0000000..74250ae --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java @@ -0,0 +1,4 @@ +package org.sadtech.consultant.database.service; + +public interface SaveUnitService { +} diff --git a/core/src/main/java/org/sadtech/consultant/database/service/SocialNetworksService.java b/core/src/main/java/org/sadtech/consultant/database/service/SocialNetworksService.java new file mode 100644 index 0000000..83d12da --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/SocialNetworksService.java @@ -0,0 +1,4 @@ +package org.sadtech.consultant.database.service; + +public interface SocialNetworksService { +} diff --git a/core/src/main/java/org/sadtech/consultant/database/service/UnitService.java b/core/src/main/java/org/sadtech/consultant/database/service/UnitService.java new file mode 100644 index 0000000..9de39e8 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/UnitService.java @@ -0,0 +1,10 @@ +package org.sadtech.consultant.database.service; + +import org.sadtech.consultant.database.entity.Unit; + +public interface UnitService { + + void addUnit(Unit unit); + void removeUnit(Long id); + +} diff --git a/core/src/main/java/org/sadtech/consultant/database/service/UserService.java b/core/src/main/java/org/sadtech/consultant/database/service/UserService.java new file mode 100644 index 0000000..3e81573 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/UserService.java @@ -0,0 +1,10 @@ +package org.sadtech.consultant.database.service; + +import org.sadtech.consultant.database.entity.User; + +public interface UserService { + + void addUser(User user); + void removeUser(Long id); + +} diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java new file mode 100644 index 0000000..2171cda --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java @@ -0,0 +1,18 @@ +package org.sadtech.consultant.database.service.impl; + +import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.repository.MessageRepository; +import org.sadtech.consultant.database.service.MessageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class MessageServiceImpl implements MessageService { + + @Autowired + private MessageRepository repository; + + public void addMessage(Message message) { + repository.saveAndFlush(message); + } +} diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/NextUnitServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java similarity index 56% rename from core/src/main/java/org/sadtech/consultant/service/impl/NextUnitServiceImpl.java rename to core/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java index d06b195..282c162 100644 --- a/core/src/main/java/org/sadtech/consultant/service/impl/NextUnitServiceImpl.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java @@ -1,7 +1,7 @@ -package org.sadtech.consultant.service.impl; +package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.repository.NextUnitRepositoriy; -import org.sadtech.consultant.service.NextUnitService; +import org.sadtech.consultant.database.repository.NextUnitRepositoriy; +import org.sadtech.consultant.database.service.NextUnitService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/SaveUnitServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java similarity index 56% rename from core/src/main/java/org/sadtech/consultant/service/impl/SaveUnitServiceImpl.java rename to core/src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java index 51ef4b6..2524815 100644 --- a/core/src/main/java/org/sadtech/consultant/service/impl/SaveUnitServiceImpl.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java @@ -1,7 +1,7 @@ -package org.sadtech.consultant.service.impl; +package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.repository.SaveUnitRepositoriy; -import org.sadtech.consultant.service.SaveUnitService; +import org.sadtech.consultant.database.repository.SaveUnitRepositoriy; +import org.sadtech.consultant.database.service.SaveUnitService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/SocialNetworksServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/SocialNetworksServiceImpl.java similarity index 56% rename from core/src/main/java/org/sadtech/consultant/service/impl/SocialNetworksServiceImpl.java rename to core/src/main/java/org/sadtech/consultant/database/service/impl/SocialNetworksServiceImpl.java index 06d5f78..b1b8c05 100644 --- a/core/src/main/java/org/sadtech/consultant/service/impl/SocialNetworksServiceImpl.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/SocialNetworksServiceImpl.java @@ -1,7 +1,7 @@ -package org.sadtech.consultant.service.impl; +package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.repository.SocialNetworksRepositoriy; -import org.sadtech.consultant.service.SocialNetworksService; +import org.sadtech.consultant.database.repository.SocialNetworksRepositoriy; +import org.sadtech.consultant.database.service.SocialNetworksService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/UnitServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java similarity index 60% rename from core/src/main/java/org/sadtech/consultant/service/impl/UnitServiceImpl.java rename to core/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java index 14706d9..1a67158 100644 --- a/core/src/main/java/org/sadtech/consultant/service/impl/UnitServiceImpl.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java @@ -1,8 +1,8 @@ -package org.sadtech.consultant.service.impl; +package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.entity.Unit; -import org.sadtech.consultant.repository.UnitRepositoriy; -import org.sadtech.consultant.service.UnitService; +import org.sadtech.consultant.database.entity.Unit; +import org.sadtech.consultant.database.repository.UnitRepositoriy; +import org.sadtech.consultant.database.service.UnitService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/UserServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/UserServiceImpl.java similarity index 67% rename from core/src/main/java/org/sadtech/consultant/service/impl/UserServiceImpl.java rename to core/src/main/java/org/sadtech/consultant/database/service/impl/UserServiceImpl.java index 3535b00..fe6c606 100644 --- a/core/src/main/java/org/sadtech/consultant/service/impl/UserServiceImpl.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/UserServiceImpl.java @@ -1,8 +1,8 @@ -package org.sadtech.consultant.service.impl; +package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.entity.User; -import org.sadtech.consultant.repository.UserRepositoriy; -import org.sadtech.consultant.service.UserService; +import org.sadtech.consultant.database.entity.User; +import org.sadtech.consultant.database.repository.UserRepositoriy; +import org.sadtech.consultant.database.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/core/src/main/java/org/sadtech/consultant/service/MessageService.java b/core/src/main/java/org/sadtech/consultant/service/MessageService.java deleted file mode 100644 index b40658e..0000000 --- a/core/src/main/java/org/sadtech/consultant/service/MessageService.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.sadtech.consultant.service; - -import org.sadtech.consultant.entity.Message; - -public interface MessageService { - - void addMessage(Message message); -} diff --git a/core/src/main/java/org/sadtech/consultant/service/NextUnitService.java b/core/src/main/java/org/sadtech/consultant/service/NextUnitService.java deleted file mode 100644 index 9ff5ac8..0000000 --- a/core/src/main/java/org/sadtech/consultant/service/NextUnitService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.consultant.service; - -public interface NextUnitService { -} diff --git a/core/src/main/java/org/sadtech/consultant/service/SaveUnitService.java b/core/src/main/java/org/sadtech/consultant/service/SaveUnitService.java deleted file mode 100644 index 39e76cc..0000000 --- a/core/src/main/java/org/sadtech/consultant/service/SaveUnitService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.consultant.service; - -public interface SaveUnitService { -} diff --git a/core/src/main/java/org/sadtech/consultant/service/SocialNetworksService.java b/core/src/main/java/org/sadtech/consultant/service/SocialNetworksService.java deleted file mode 100644 index 54dab6d..0000000 --- a/core/src/main/java/org/sadtech/consultant/service/SocialNetworksService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.consultant.service; - -public interface SocialNetworksService { -} diff --git a/core/src/main/java/org/sadtech/consultant/service/UnitService.java b/core/src/main/java/org/sadtech/consultant/service/UnitService.java deleted file mode 100644 index c8e77e9..0000000 --- a/core/src/main/java/org/sadtech/consultant/service/UnitService.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.sadtech.consultant.service; - -import org.sadtech.consultant.entity.Unit; - -public interface UnitService { - - void addUnit(Unit unit); - void removeUnit(Long id); - -} diff --git a/core/src/main/java/org/sadtech/consultant/service/UserService.java b/core/src/main/java/org/sadtech/consultant/service/UserService.java deleted file mode 100644 index 5018e68..0000000 --- a/core/src/main/java/org/sadtech/consultant/service/UserService.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.sadtech.consultant.service; - -import org.sadtech.consultant.entity.User; - -public interface UserService { - - void addUser(User user); - void removeUser(Long id); - -} diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java b/core/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java deleted file mode 100644 index e752d1e..0000000 --- a/core/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.consultant.service.impl; - -import org.sadtech.consultant.entity.Message; -import org.sadtech.consultant.repository.MessageRepository; -import org.sadtech.consultant.service.MessageService; -import org.springframework.beans.factory.annotation.Autowired; - -public class MessageServiceImpl implements MessageService { - - @Autowired - private MessageRepository repository; - - public void addMessage(Message message) { - repository.saveAndFlush(message); - } -} diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml index cf57bdb..939a596 100644 --- a/vk-bot/pom.xml +++ b/vk-bot/pom.xml @@ -18,8 +18,8 @@ org.apache.maven.plugins maven-compiler-plugin - 6 - 6 + 7 + 7 @@ -45,7 +45,7 @@ 2.1.3.RELEASE 3.1.0 - 1.0.2 + 2.2 5.4.0.Final 5.2.10.Final @@ -81,6 +81,10 @@ ${log4j} + + + + org.springframework spring-core @@ -111,6 +115,11 @@ spring-data-jpa ${spring.data} + + org.springframework + spring-orm + 5.1.3.RELEASE + javax.servlet @@ -138,19 +147,21 @@ javax.persistence - persistence-api + javax.persistence-api ${javax.persistance} mysql mysql-connector-java ${mysql.connector} + runtime org.hibernate hibernate-entitymanager ${hibernate.entitymanager} + runtime org.hibernate @@ -158,6 +169,18 @@ ${hibernate.core} + + org.slf4j + slf4j-nop + 1.7.13 + + + org.sadtech + consultant-core + 1.0-SNAPSHOT + compile + + \ No newline at end of file diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java similarity index 54% rename from vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java rename to vk-bot/src/main/java/org/sadtech/vkbot/Main.java index a741b01..012ceb4 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java @@ -1,21 +1,27 @@ -package org.sadtech.vkbot.config; +package org.sadtech.vkbot; import lombok.extern.log4j.Log4j; +import org.sadtech.vkbot.config.DataConfig; +import org.sadtech.vkbot.config.SpringConfigVk; import org.sadtech.vkbot.listener.EventListenable; -import org.sadtech.vkbot.listener.Observable; +import org.sadtech.vkbot.listener.handlers.Handled; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @Log4j -public class TestMain { +public class Main { public static void main(String[] args) throws Exception { + Main main = new Main(); + main.run(); + } + + public void run() throws Exception { log.info("\n\n\n\n=== Запуск прогарммы ===\n\n"); - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class); - context.register(DataConfig.class); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class, DataConfig.class); EventListenable eventListener = context.getBean(EventListenable.class); eventListener.listen(); - Observable dispetcherHandler = context.getBean(Observable.class); - dispetcherHandler.packaging(); + Handled dispetcherHandler = context.getBean(Handled.class); + dispetcherHandler.sortAndSend(); log.info("\n\n=== Конец программы ===\n\n"); } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/DataConfig.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/DataConfig.java index 5360255..4a93c53 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/DataConfig.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/DataConfig.java @@ -4,8 +4,6 @@ import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @@ -16,8 +14,7 @@ import java.util.Properties; @Configuration @EnableTransactionManagement -@EnableJpaRepositories("org.sadtech.vkbot.repo") -@PropertySource("classpath:config.properties") + public class DataConfig { @Value("${db.driver}") @@ -38,7 +35,7 @@ public class DataConfig { @Value("${db.hibernate.hbm2ddl.auto}") private String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO; - @Bean(name = "entityManagerFactory") + @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java index 35ee625..f1f06b4 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java @@ -9,10 +9,7 @@ import com.vk.api.sdk.exceptions.ClientException; import com.vk.api.sdk.httpclient.HttpTransportClient; import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; +import org.springframework.context.annotation.*; import org.springframework.core.task.TaskExecutor; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @@ -23,9 +20,9 @@ import java.util.concurrent.Executors; @Configuration @EnableAsync +@Import({DataConfig.class}) @PropertySource("classpath:config.properties") @ComponentScan("org.sadtech.vkbot.listener") -@EnableScheduling public class SpringConfigVk { @Value("${vk.groupID}") diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/entity/User.java b/vk-bot/src/main/java/org/sadtech/vkbot/entity/User.java deleted file mode 100644 index 1601df8..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/entity/User.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.vkbot.entity; - -import lombok.Data; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -@Data -public class User { - - @Id - private long id; - private String name; - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observable.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observable.java index fc0d341..f8a11bd 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observable.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observable.java @@ -6,5 +6,4 @@ public interface Observable { // void removeObserver(Observer o); void notifyObservers(); - void packaging() throws Exception; } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java index 7c27ddf..57a9b15 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java @@ -5,5 +5,5 @@ import com.google.gson.JsonObject; import java.util.List; public interface Observer { - void update(List jsonObjects); + void update(JsonObject object); } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java index 1630991..c7ec381 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java @@ -10,7 +10,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; @Component public class ResponseDataVk implements ResponsibleData { - private Queue jsonObjects = new ConcurrentLinkedQueue(); + private Queue jsonObjects = new ConcurrentLinkedQueue<>(); @Override public void add(JsonObject jsonObject) { diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/Handled.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/Handled.java new file mode 100644 index 0000000..7a5513f --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/Handled.java @@ -0,0 +1,7 @@ +package org.sadtech.vkbot.listener.handlers; + +public interface Handled { + + void sortAndSend() throws Exception; + +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/MessageHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/MessageHandlerVk.java deleted file mode 100644 index 8efc101..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/MessageHandlerVk.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.sadtech.vkbot.listener.handlers; - -import com.google.gson.JsonObject; -import org.sadtech.vkbot.listener.Observer; - -import java.util.List; - -public class MessageHandlerVk implements Observer { - - private DispetcherHandler dispetcherHandler; - - public MessageHandlerVk(DispetcherHandler dispetcherHandler) { - this.dispetcherHandler = dispetcherHandler; - dispetcherHandler.registerObserver(this); - } - - @Override - public void update(List jsonObjects) { - - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/DispetcherHandlerVk.java similarity index 67% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java rename to vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/DispetcherHandlerVk.java index a4f4a58..ba1c642 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/DispetcherHandlerVk.java @@ -1,12 +1,12 @@ -package org.sadtech.vkbot.listener.handlers; +package org.sadtech.vkbot.listener.handlers.impl; import com.google.gson.JsonObject; import lombok.extern.log4j.Log4j; import org.sadtech.vkbot.listener.Observable; import org.sadtech.vkbot.listener.Observer; import org.sadtech.vkbot.listener.data.ResponsibleData; +import org.sadtech.vkbot.listener.handlers.Handled; import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -14,20 +14,22 @@ import java.util.List; @Log4j @Component -public class DispetcherHandler implements Observable { +public class DispetcherHandlerVk implements Observable, Handled { private ResponsibleData date; private List observers = new ArrayList(); + private JsonObject event; - public DispetcherHandler(ResponsibleData date) { + public DispetcherHandlerVk(ResponsibleData date) { this.date = date; } @Async - public void packaging() { + public void sortAndSend() { while (true) { if (date.getJsonObjects().peek() != null) { - log.info(date.getJsonObjects().poll()); + event = date.getJsonObjects().poll(); + notifyObservers(); } } } @@ -40,7 +42,7 @@ public class DispetcherHandler implements Observable { @Override public void notifyObservers() { for (Observer observer : observers) { - //observer.update(); + observer.update(event); } } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/MessageHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/MessageHandlerVk.java new file mode 100644 index 0000000..79d0881 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/MessageHandlerVk.java @@ -0,0 +1,39 @@ +package org.sadtech.vkbot.listener.handlers.impl; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.vk.api.sdk.objects.messages.Message; +import lombok.extern.log4j.Log4j; +import org.sadtech.consultant.database.service.MessageService; +import org.sadtech.consultant.database.service.impl.MessageServiceImpl; +import org.sadtech.vkbot.listener.Observable; +import org.sadtech.vkbot.listener.Observer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Log4j +@Component +public class MessageHandlerVk implements Observer { + + private Observable dispetcherHandler; +// @Autowired +// private MessageService service; + + public MessageHandlerVk(Observable dispetcherHandler) { + this.dispetcherHandler = dispetcherHandler; + dispetcherHandler.registerObserver(this); + } + + @Override + public void update(JsonObject object) { + if (object.get("type").toString().equals("\"message_new\"")) { + Gson gson = new Gson(); + Message message = gson.fromJson(object.getAsJsonObject("object"), Message.class); + send(message); + } + } + + private void send(Message message) { + log.info(message.getBody()); + } +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java index 5010b4b..2261bf1 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java @@ -59,8 +59,6 @@ public class EventListenerVk implements EventListenable { String test = "{\"one_time\":false,\"buttons\":[[{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"1\\\"}\",\"label\":\"Red2\"},\"color\":\"negative\"},{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"2\\\"}\",\"label\":\"Green\"},\"color\":\"positive\"}],[{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"3\\\"}\",\"label\":\"White\"},\"color\":\"default\"},{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"4\\\"}\",\"label\":\"Blue\"},\"color\":\"primary\"}]]}"; vk.messages().send(actor).peerId(244319573).keyboard(test).message("Сообщение получено").execute(); - - } longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20); } while (true); diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/repo/UserRepository.java b/vk-bot/src/main/java/org/sadtech/vkbot/repo/UserRepository.java deleted file mode 100644 index f3cfd50..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/repo/UserRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.sadtech.vkbot.repo; - -import org.sadtech.vkbot.entity.User; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface UserRepository extends JpaRepository { - - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/service/UserService.java b/vk-bot/src/main/java/org/sadtech/vkbot/service/UserService.java deleted file mode 100644 index 88cba65..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/service/UserService.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sadtech.vkbot.service; - -import org.sadtech.vkbot.entity.User; - -public interface UserService { - - User addUser(User user); - - void removeUser(long id); - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/service/impl/UserServiceImpl.java b/vk-bot/src/main/java/org/sadtech/vkbot/service/impl/UserServiceImpl.java deleted file mode 100644 index e7e1d2a..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/service/impl/UserServiceImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.sadtech.vkbot.service.impl; - -import org.sadtech.vkbot.entity.User; -import org.sadtech.vkbot.repo.UserRepository; -import org.sadtech.vkbot.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - - -@Service -public class UserServiceImpl implements UserService { - - @Autowired - private UserRepository userRepository; - - @Override - public User addUser(User user) { - User savedUser = userRepository.saveAndFlush(user); - return savedUser; - } - - @Override - public void removeUser(long id) { - userRepository.deleteById(id); - } -}