diff --git a/core/src/main/java/org/sadtech/consultant/MessageSender.java b/core/src/main/java/org/sadtech/consultant/MessageSender.java new file mode 100644 index 0000000..75ba12e --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/MessageSender.java @@ -0,0 +1,7 @@ +package org.sadtech.consultant; + +public interface MessageSender { + + void send(Integer idNetSoc, String text); + +} diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Message.java b/core/src/main/java/org/sadtech/consultant/database/entity/Mail.java similarity index 68% rename from core/src/main/java/org/sadtech/consultant/database/entity/Message.java rename to core/src/main/java/org/sadtech/consultant/database/entity/Mail.java index 69afff2..5ba4490 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/Message.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Mail.java @@ -6,7 +6,7 @@ import javax.persistence.*; @Data @Entity -public class Message { +public class Mail { @Id @GeneratedValue @@ -14,11 +14,10 @@ public class Message { private String text; private Long date; private String sourceMessage; - private String sex; @ManyToOne - @JoinColumn(name = "idUser", nullable = false) - private Person user; + @JoinColumn(name = "idPerson", nullable = false) + private Person person; } diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Person.java b/core/src/main/java/org/sadtech/consultant/database/entity/Person.java index cf92adf..847e228 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/Person.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Person.java @@ -24,10 +24,13 @@ public class Person { private String city; private String token; + private String email; @ElementCollection @CollectionTable(name = "PersonSocialNetworks") @MapKeyColumn(name = "KeysSocialNetworks", length = 20) private Map socialNetworks = new HashMap<>(); + + } diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java b/core/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java index b5df08e..d198992 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java @@ -2,8 +2,7 @@ package org.sadtech.consultant.database.entity; import lombok.Data; -import javax.persistence.Entity; -import javax.persistence.Id; +import javax.persistence.*; @Entity @Data @@ -13,4 +12,8 @@ public class SaveUnit { private Long id; private Long idStage; + @OneToOne + @JoinColumn(name = "idPerson", nullable = false) + private Person user; + } diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java b/core/src/main/java/org/sadtech/consultant/database/repository/MailRepository.java similarity index 50% rename from core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java rename to core/src/main/java/org/sadtech/consultant/database/repository/MailRepository.java index 8dfc122..8e5541c 100644 --- a/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/MailRepository.java @@ -1,15 +1,15 @@ package org.sadtech.consultant.database.repository; -import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.entity.Mail; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.util.Collection; -public interface MessageRepository extends JpaRepository { +public interface MailRepository extends JpaRepository { - @Query("SELECT u FROM Message u WHERE u.date > :date") - Collection getMessagesByRange(@Param("date") Long date); + @Query("SELECT u FROM Mail u WHERE u.date > :date") + Collection getMessagesByRange(@Param("date") Long date); } diff --git a/core/src/main/java/org/sadtech/consultant/database/service/MailService.java b/core/src/main/java/org/sadtech/consultant/database/service/MailService.java new file mode 100644 index 0000000..1ca820b --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/MailService.java @@ -0,0 +1,12 @@ +package org.sadtech.consultant.database.service; + +import org.sadtech.consultant.database.entity.Mail; + +import java.util.List; + +public interface MailService { + + void addMessage(Mail message); + + List getMessageRange(Long date); +} 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 deleted file mode 100644 index 53e2d37..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/service/MessageService.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.sadtech.consultant.database.service; - -import org.sadtech.consultant.database.entity.Message; - -import java.util.List; - -public interface MessageService { - - void addMessage(Message message); - - List getMessageRange(Long date); -} diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java new file mode 100644 index 0000000..6432031 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java @@ -0,0 +1,25 @@ +package org.sadtech.consultant.database.service.impl; + +import org.sadtech.consultant.database.entity.Mail; +import org.sadtech.consultant.database.repository.MailRepository; +import org.sadtech.consultant.database.service.MailService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class MailServiceImpl implements MailService { + + @Autowired + private MailRepository repository; + + public void addMessage(Mail message) { + repository.saveAndFlush(message); + } + + @Override + public List getMessageRange(Long date) { + return (List) repository.getMessagesByRange(date); + } +} 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 deleted file mode 100644 index f5d967b..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -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; - -import java.util.List; - -@Service -public class MessageServiceImpl implements MessageService { - - @Autowired - private MessageRepository repository; - - public void addMessage(Message message) { - repository.saveAndFlush(message); - } - - @Override - public List getMessageRange(Long date) { - return (List) repository.getMessagesByRange(date); - } -} diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java index 7acd025..936d0d8 100644 --- a/core/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java @@ -1,7 +1,7 @@ package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.database.entity.Person; import org.sadtech.consultant.database.repository.PersonRepository; +import org.sadtech.consultant.database.entity.Person; import org.sadtech.consultant.database.service.PersonService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java index 1a67158..eeec2d8 100644 --- a/core/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java @@ -1,7 +1,7 @@ package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.database.entity.Unit; import org.sadtech.consultant.database.repository.UnitRepositoriy; +import org.sadtech.consultant.database.entity.Unit; 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/processing/MessageHandler.java b/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java index e486947..d513930 100644 --- a/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java +++ b/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java @@ -1,12 +1,17 @@ package org.sadtech.consultant.processing; import lombok.extern.log4j.Log4j; -import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.entity.Mail; +import org.sadtech.consultant.MessageSender; +import org.sadtech.consultant.database.entity.Person; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Log4j @Component @@ -14,6 +19,7 @@ public class MessageHandler { private MessageLogicService messageLogicService; private PersonLogicService userLogicService; + private Map senderHashMap = new HashMap<>(); private long data; public MessageHandler(MessageLogicService messageLogicService, PersonLogicService userLogicService) { @@ -22,13 +28,25 @@ public class MessageHandler { data = new Date().getTime() / 1000; } + public void addMessageSendler(String type, MessageSender messageSender) { + senderHashMap.put(type, messageSender); + } + @Async + @Transactional public void processing() { + log.info("process"); while (true) { - List messages = messageLogicService.getMessageRange(data); - for (Message message : messages) { - log.info(message); - data = message.getDate(); + List messages = messageLogicService.getMessageRange(data); + if (messages.size()>0) { + for (Mail message : messages) { + log.info(message); + Person person = message.getPerson(); + Integer idNetSoc = person.getSocialNetworks().get(message.getSourceMessage()); + senderHashMap.get(message.getSourceMessage()).send(idNetSoc, "Тестовое сообщение"); + + data = message.getDate(); + } } } } diff --git a/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java b/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java index 1ed910a..3eb2be4 100644 --- a/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java +++ b/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java @@ -1,7 +1,7 @@ package org.sadtech.consultant.processing; -import org.sadtech.consultant.database.entity.Message; -import org.sadtech.consultant.database.service.MessageService; +import org.sadtech.consultant.database.entity.Mail; +import org.sadtech.consultant.database.service.MailService; import org.springframework.stereotype.Component; import java.util.List; @@ -9,17 +9,17 @@ import java.util.List; @Component public class MessageLogicService { - private MessageService messageService; + private MailService messageService; - public MessageLogicService(MessageService messageService) { + public MessageLogicService(MailService messageService) { this.messageService = messageService; } - public void addMessage(Message message) { + public void addMessage(Mail message) { messageService.addMessage(message); } - public List getMessageRange(long data) { + public List getMessageRange(long data) { return messageService.getMessageRange(data); } } diff --git a/facebook-bot/pom.xml b/facebook-bot/pom.xml deleted file mode 100644 index dca92c0..0000000 --- a/facebook-bot/pom.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - consultant - org.sadtech - 0.1-SNAPSHOT - - 4.0.0 - - facebook-bot - - - \ No newline at end of file diff --git a/fit-elit-consultant/pom.xml b/fit-elit-consultant/pom.xml new file mode 100644 index 0000000..63bbdc8 --- /dev/null +++ b/fit-elit-consultant/pom.xml @@ -0,0 +1,181 @@ + + + + consultant + org.sadtech + 0.1-SNAPSHOT + + 4.0.0 + + ru.fit-elit + consultant + 0.1-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 7 + 7 + + + + + + + 0.5.13-SNAPSHOT + + 5.1.3.RELEASE + 5.1.3.RELEASE + 5.1.3.RELEASE + 5.1.3.RELEASE + 5.1.3.RELEASE + 5.1.3.RELEASE + 2.1.3.RELEASE + + 3.1.0 + 2.2 + + 5.4.0.Final + 5.2.10.Final + + 8.0.13 + + 1.18.4 + + 1.2.17 + + 20180813 + + 6.1.25 + + + + + + com.vk.api + sdk + ${vk.api.ver} + + + + org.sadtech + vk-bot + 0.2-SNAPSHOT + + + + org.projectlombok + lombok + ${lombok} + + + + log4j + log4j + ${log4j} + + + + + org.springframework + spring-core + ${spring.core} + + + org.springframework + spring-context + ${spring.context} + + + org.springframework + spring-context-support + ${spring.context} + + + org.springframework + spring-web + ${spring.web} + + + org.springframework + spring-webmvc + ${spring.webmvc} + + + org.springframework.data + spring-data-jpa + ${spring.data} + + + org.springframework + spring-orm + 5.1.3.RELEASE + + + + com.google.code.gson + gson + 2.8.5 + + + + org.mortbay.jetty + jetty-util + ${jetty.util} + + + + org.json + json + ${json} + + + + javax.persistence + javax.persistence-api + ${javax.persistance} + + + mysql + mysql-connector-java + ${mysql.connector} + + + + org.hibernate + hibernate-entitymanager + ${hibernate.entitymanager} + + + org.hibernate + hibernate-core + ${hibernate.core} + + + + org.slf4j + slf4j-nop + 1.7.13 + + + + org.sadtech + consultant-core + 1.0-SNAPSHOT + compile + + + org.jetbrains + annotations-java5 + 16.0.2 + compile + + + + + + \ No newline at end of file diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/Main.java similarity index 59% rename from vk-bot/src/main/java/org/sadtech/vkbot/Main.java rename to fit-elit-consultant/src/main/java/ru/fitelit/consultant/Main.java index cbddefb..0ce3138 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java +++ b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/Main.java @@ -1,11 +1,11 @@ -package org.sadtech.vkbot; +package ru.fitelit.consultant; import lombok.extern.log4j.Log4j; import org.sadtech.consultant.processing.MessageHandler; -import org.sadtech.vkbot.config.SpringConfigVk; -import org.sadtech.vkbot.listener.EventListenable; -import org.sadtech.vkbot.handlers.Handled; +import org.sadtech.vkbot.core.handlers.Handled; +import org.sadtech.vkbot.core.listener.EventListenable; import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import ru.fitelit.consultant.config.SpringConfigVk; @Log4j public class Main { @@ -19,9 +19,9 @@ public class Main { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class); EventListenable eventListener = context.getBean(EventListenable.class); eventListener.listen(); - Handled dispetcherHandler = context.getBean(Handled.class); - dispetcherHandler.sortAndSend(); -// MessageHandler messageHandler = context.getBean(MessageHandler.class); -// messageHandler.processing(); + Handled dispatcherHandler = context.getBean(Handled.class); + dispatcherHandler.sortAndSend(); + MessageHandler messageHandler = context.getBean(MessageHandler.class); + messageHandler.processing(); } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/DataConfig.java b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/DataConfig.java similarity index 98% rename from vk-bot/src/main/java/org/sadtech/vkbot/config/DataConfig.java rename to fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/DataConfig.java index 3069b6a..ccef4cb 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/DataConfig.java +++ b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/DataConfig.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.config; +package ru.fitelit.consultant.config; import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.beans.factory.annotation.Value; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/SpringConfigVk.java similarity index 94% rename from vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java rename to fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/SpringConfigVk.java index 231aa60..a700ffe 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java +++ b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/SpringConfigVk.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.config; +package ru.fitelit.consultant.config; import com.vk.api.sdk.client.TransportClient; import com.vk.api.sdk.client.VkApiClient; @@ -21,7 +21,7 @@ import java.util.concurrent.Executors; @EnableAsync @PropertySource("classpath:config.properties") @Import({DataConfig.class}) -@ComponentScan({"org.sadtech.vkbot", "org.sadtech.consultant.processing"}) +@ComponentScan({"ru.fitelit.consultant", "org.sadtech.consultant.processing", "org.sadtech.vkbot.core"}) public class SpringConfigVk { diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/WebConfig.java similarity index 88% rename from vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java rename to fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/WebConfig.java index d13c088..df46ba0 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java +++ b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/WebConfig.java @@ -2,9 +2,9 @@ // //import com.vk.api.sdk.exceptions.ApiException; //import com.vk.api.sdk.exceptions.ClientException; -//import org.sadtech.vkbot.listener.EventListenable; -//import org.sadtech.vkbot.listener.Observable; -//import org.sadtech.vkbot.listener.impl.EventListenerVk; +//import EventListenable; +//import Observable; +//import EventListenerVk; //import org.springframework.context.annotation.ComponentScan; //import org.springframework.context.annotation.Configuration; //import org.springframework.web.WebApplicationInitializer; diff --git a/pom.xml b/pom.xml index d7ad9d4..8d58c86 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ vk-bot core - facebook-bot + fit-elit-consultant diff --git a/vk-bot/WEB-INF/web.xml b/vk-bot/WEB-INF/web.xml deleted file mode 100644 index d80081d..0000000 --- a/vk-bot/WEB-INF/web.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - \ No newline at end of file diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml index e3617b7..dad10a1 100644 --- a/vk-bot/pom.xml +++ b/vk-bot/pom.xml @@ -2,16 +2,17 @@ - - time-table + consultant org.sadtech 1.0-SNAPSHOT 4.0.0 + org.sadtech vk-bot - 0.1-SNAPSHOT + 0.2-SNAPSHOT + jar @@ -170,6 +171,12 @@ 1.0-SNAPSHOT compile + + org.jetbrains + annotations-java5 + 16.0.2 + compile + diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/SourceMessage.java similarity index 87% rename from vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/SourceMessage.java index d76fef1..7385191 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/SourceMessage.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot; +package org.sadtech.vkbot.core; public enum SourceMessage { VK("VK"), diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java similarity index 97% rename from vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java index 2d436c5..6c2e68e 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot; +package org.sadtech.vkbot.core; import com.vk.api.sdk.client.VkApiClient; import com.vk.api.sdk.client.actors.GroupActor; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java similarity index 84% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java index 1c10736..47e0dc8 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.listener.data; +package org.sadtech.vkbot.core.data; import com.google.gson.JsonObject; 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/core/data/impl/ResponseDataVk.java similarity index 86% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/data/impl/ResponseDataVk.java index c7ec381..a5532b4 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/data/impl/ResponseDataVk.java @@ -1,7 +1,7 @@ -package org.sadtech.vkbot.listener.data.impl; +package org.sadtech.vkbot.core.data.impl; import com.google.gson.JsonObject; -import org.sadtech.vkbot.listener.data.ResponsibleData; +import org.sadtech.vkbot.core.data.ResponsibleData; import org.springframework.stereotype.Component; import java.util.Queue; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/Handled.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/Handled.java new file mode 100644 index 0000000..f5fe281 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/Handled.java @@ -0,0 +1,9 @@ +package org.sadtech.vkbot.core.handlers; + +import org.sadtech.vkbot.core.listener.Observer; + +public interface Handled { + + void sortAndSend() throws Exception; + void registerObserver(Observer o); +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/DispetcherHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/DispatcherHandlerVk.java similarity index 64% rename from vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/DispetcherHandlerVk.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/DispatcherHandlerVk.java index 03908b5..fb7c5e9 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/DispetcherHandlerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/DispatcherHandlerVk.java @@ -1,11 +1,11 @@ -package org.sadtech.vkbot.handlers.impl; +package org.sadtech.vkbot.core.handlers.impl; import com.google.gson.JsonObject; import lombok.extern.log4j.Log4j; -import org.sadtech.vkbot.handlers.Handled; -import org.sadtech.vkbot.listener.Observable; -import org.sadtech.vkbot.listener.Observer; -import org.sadtech.vkbot.listener.data.ResponsibleData; +import org.sadtech.vkbot.core.handlers.Handled; +import org.sadtech.vkbot.core.listener.Observable; +import org.sadtech.vkbot.core.data.ResponsibleData; +import org.sadtech.vkbot.core.listener.Observer; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -13,14 +13,14 @@ import java.util.ArrayList; import java.util.List; @Log4j -@Component -public class DispetcherHandlerVk implements Observable, Handled { +@Component("dispatcherHandler") +public class DispatcherHandlerVk implements Observable, Handled { private ResponsibleData date; - private List observers = new ArrayList(); + private List observers = new ArrayList<>(); private JsonObject event; - public DispetcherHandlerVk(ResponsibleData date) { + public DispatcherHandlerVk(ResponsibleData date) { this.date = date; } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java similarity index 65% rename from vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java index 936af0e..aa1513c 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java @@ -1,17 +1,19 @@ -package org.sadtech.vkbot.handlers.impl; +package org.sadtech.vkbot.core.handlers.impl; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.vk.api.sdk.objects.messages.Message; import com.vk.api.sdk.objects.users.UserXtrCounters; import lombok.extern.log4j.Log4j; -import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.entity.Mail; import org.sadtech.consultant.database.entity.Person; import org.sadtech.consultant.processing.MessageLogicService; import org.sadtech.consultant.processing.PersonLogicService; -import org.sadtech.vkbot.SourceMessage; -import org.sadtech.vkbot.VkApi; -import org.sadtech.vkbot.listener.Observable; -import org.sadtech.vkbot.listener.Observer; +import org.sadtech.vkbot.core.SourceMessage; +import org.sadtech.vkbot.core.VkApi; +import org.sadtech.vkbot.core.handlers.Handled; +import org.sadtech.vkbot.core.listener.Observer; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @Log4j @@ -20,41 +22,40 @@ public class MessageHandlerVk implements Observer { private MessageLogicService messageLogicService; private PersonLogicService personLogicService; + private Message userMessage; - public MessageHandlerVk(Observable dispetcherHandler, PersonLogicService personLogicService, MessageLogicService messageLogicService) { + public MessageHandlerVk(@Qualifier("dispatcherHandler") Handled dispatcherHandler, PersonLogicService personLogicService, MessageLogicService messageLogicService) { this.messageLogicService = messageLogicService; this.personLogicService = personLogicService; - dispetcherHandler.registerObserver(this); + dispatcherHandler.registerObserver(this); } @Override public void update(JsonObject object) { if (object.get("type").toString().equals("\"message_new\"")) { Gson gson = new Gson(); - log.info(object.getAsJsonObject("object")); - com.vk.api.sdk.objects.messages.Message message = gson.fromJson(object.getAsJsonObject("object"), com.vk.api.sdk.objects.messages.Message.class); - sendProcessing(message); + userMessage = gson.fromJson(object.getAsJsonObject("object"), com.vk.api.sdk.objects.messages.Message.class); + sortAndSend(); } } - private void sendProcessing(com.vk.api.sdk.objects.messages.Message userMessage) { + public void sortAndSend() { Person user; Integer userVkId = userMessage.getUserId(); - log.info(VkApi.getUserVk(userVkId)); if (personLogicService.checkPersonBySocialNetworksId(SourceMessage.VK.name(), userVkId)) { user = personLogicService.getUserBySocialId(SourceMessage.VK.name(), userMessage.getUserId()); } else { user = new Person(); UserXtrCounters userXtrCounters = VkApi.getUserVk(userVkId); - user.setCity("ыыыы"); + user.setCity("city"); user.setName(userXtrCounters.getFirstName()); user.setLastName(userXtrCounters.getLastName()); user.getSocialNetworks().put(String.valueOf(SourceMessage.VK), userMessage.getUserId()); personLogicService.addUser(user); } - Message message = new Message(); - message.setUser(user); + Mail message = new Mail(); + message.setPerson(user); message.setText(userMessage.getBody()); message.setDate(Long.valueOf(userMessage.getDate())); message.setSourceMessage(SourceMessage.VK.name()); diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java similarity index 64% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java index 5af0eb1..14308f4 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.listener; +package org.sadtech.vkbot.core.listener; public interface EventListenable { void listen() throws Exception; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observable.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java similarity index 58% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/Observable.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java index f8a11bd..bcab5b7 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observable.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java @@ -1,7 +1,6 @@ -package org.sadtech.vkbot.listener; +package org.sadtech.vkbot.core.listener; public interface Observable { - void registerObserver(Observer o); // void removeObserver(Observer o); void notifyObservers(); diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java similarity index 71% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java index cdc652e..2edd654 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.listener; +package org.sadtech.vkbot.core.listener; import com.google.gson.JsonObject; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java similarity index 74% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java rename to vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java index eb590f9..dca38d5 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.listener.impl; +package org.sadtech.vkbot.core.listener.impl; import com.vk.api.sdk.actions.LongPoll; import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; @@ -9,8 +9,8 @@ import com.vk.api.sdk.exceptions.ApiException; import com.vk.api.sdk.exceptions.ClientException; import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; import lombok.extern.log4j.Log4j; -import org.sadtech.vkbot.listener.EventListenable; -import org.sadtech.vkbot.listener.data.ResponsibleData; +import org.sadtech.vkbot.core.listener.EventListenable; +import org.sadtech.vkbot.core.data.ResponsibleData; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -51,7 +51,7 @@ public class EventListenerVk implements EventListenable { if (eventsResponse.getUpdates().toArray().length != 0) { responseData.add(eventsResponse.getUpdates().get(0)); log.info(eventsResponse.getUpdates()); - 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\"}]]}"; +// 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\"}]]}"; } longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20); } while (true); diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/sendler/MessageSendVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/sendler/MessageSendVk.java new file mode 100644 index 0000000..d250f01 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/core/sendler/MessageSendVk.java @@ -0,0 +1,20 @@ +package org.sadtech.vkbot.core.sendler; + +import org.sadtech.consultant.MessageSender; +import org.sadtech.consultant.processing.MessageHandler; +import org.sadtech.vkbot.core.SourceMessage; +import org.sadtech.vkbot.core.VkApi; +import org.springframework.stereotype.Component; + +@Component +public class MessageSendVk implements MessageSender { + + public MessageSendVk(MessageHandler messageHandler) { + messageHandler.addMessageSendler(SourceMessage.VK.name(), this); + } + + @Override + public void send(Integer idNetSoc, String text) { + VkApi.sendMessage(idNetSoc, text); + } +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/Handled.java b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/Handled.java deleted file mode 100644 index f82c1b6..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/Handled.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.vkbot.handlers; - -public interface Handled { - - void sortAndSend() throws Exception; - -}