From 6793efcc555631f6dceb1d08203dd5656b7be3d5 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 20 Dec 2018 00:45:34 +0300 Subject: [PATCH 01/29] =?UTF-8?q?=D0=9D=D0=B0=D1=83=D1=87=D0=B8=D0=BB?= =?UTF-8?q?=D1=81=D1=8F=20=D0=BF=D1=80=D0=B8=D0=BD=D0=B8=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B8=D0=B7=20=D0=B2=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Все данные для настройки соединения и взаимодествия с вк в отдельном файле * Научился отлавливать новые сообщения в сообществе и отправлять ответ * Добавил паттерн Наблюдатель --- .gitignore | 4 +- core/pom.xml | 15 +++ pom.xml | 5 + vk-bot/pom.xml | 91 +++++++++++++++++++ .../java/org/sadtech/vkbot/Observable.java | 7 ++ .../main/java/org/sadtech/vkbot/Observer.java | 9 ++ .../java/org/sadtech/vkbot/ResponseData.java | 29 ++++++ .../java/org/sadtech/vkbot/TestLogic.java | 20 ++++ .../sadtech/vkbot/config/SpringConfig.java | 87 ++++++++++++++++++ .../org/sadtech/vkbot/config/WebConfig.java | 27 ++++++ .../org/sadtech/vkbot/controller/Test.java | 66 ++++++++++++++ 11 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 core/pom.xml create mode 100644 vk-bot/pom.xml create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/Observable.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/Observer.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/ResponseData.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java diff --git a/.gitignore b/.gitignore index 8f8104e..1c7043d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.iml .idea/ -**/target/** \ No newline at end of file +**/target/** +.DS_Store +/vk-bot/src/main/resources/config.properties diff --git a/core/pom.xml b/core/pom.xml new file mode 100644 index 0000000..6f96fe4 --- /dev/null +++ b/core/pom.xml @@ -0,0 +1,15 @@ + + + + consultant + org.sadtech + 1.0-SNAPSHOT + + 4.0.0 + + consultant-core + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 62c59bf..494110a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,12 @@ org.sadtech consultant + pom 0.1-SNAPSHOT + + vk-bot + core + \ No newline at end of file diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml new file mode 100644 index 0000000..7c82c9f --- /dev/null +++ b/vk-bot/pom.xml @@ -0,0 +1,91 @@ + + + + time-table + org.sadtech + 1.0-SNAPSHOT + + 4.0.0 + + vk-bot + 0.1-SNAPSHOT + war + + + + org.apache.maven.plugins + maven-compiler-plugin + + 6 + 6 + + + + + + + 0.5.12 + 5.1.3.RELEASE + + + + + com.vk.api + sdk + ${vk.api.ver} + + + + org.springframework + spring-core + ${spring.ver} + + + + org.springframework + spring-context + ${spring.ver} + + + + org.springframework + spring-context-support + ${spring.ver} + + + org.springframework + spring-web + ${spring.ver} + + + javax.servlet + javax.servlet-api + 3.1.0 + + + org.springframework + spring-webmvc + 5.1.3.RELEASE + + + org.springframework + spring-core + 5.1.3.RELEASE + + + org.mortbay.jetty + jetty-util + 6.1.25 + + + + org.json + json + 20180813 + + + + + \ No newline at end of file diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/Observable.java b/vk-bot/src/main/java/org/sadtech/vkbot/Observable.java new file mode 100644 index 0000000..b9a0acc --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/Observable.java @@ -0,0 +1,7 @@ +package org.sadtech.vkbot; + +public interface Observable { + void registerObserver(org.sadtech.vkbot.Observer o); +// void removeObserver(Observer o); + void notifyObservers(); +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/Observer.java b/vk-bot/src/main/java/org/sadtech/vkbot/Observer.java new file mode 100644 index 0000000..8cca6ce --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/Observer.java @@ -0,0 +1,9 @@ +package org.sadtech.vkbot; + +import com.google.gson.JsonObject; + +import java.util.List; + +public interface Observer { + void update(List jsonObjects); +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/ResponseData.java b/vk-bot/src/main/java/org/sadtech/vkbot/ResponseData.java new file mode 100644 index 0000000..e6008b2 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/ResponseData.java @@ -0,0 +1,29 @@ +package org.sadtech.vkbot; + +import com.google.gson.JsonObject; + +import java.util.ArrayList; +import java.util.List; + +public class ResponseData implements Observable { + + private List observers = new ArrayList(); + private List jsonObjects = new ArrayList(); + + @Override + public void registerObserver(Observer o) { + observers.add(o); + } + + @Override + public void notifyObservers() { + for (Observer observer:observers) { + observer.update(jsonObjects); + } + } + + public void setJsonObjects(List jsonObjects) { + this.jsonObjects = jsonObjects; + notifyObservers(); + } +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java b/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java new file mode 100644 index 0000000..8e8ed9e --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java @@ -0,0 +1,20 @@ +package org.sadtech.vkbot; + +import com.google.gson.JsonObject; + +import java.util.List; + +public class TestLogic implements Observer{ + + private ResponseData responseData; + + public TestLogic(ResponseData responseData) { + this.responseData = responseData; + responseData.registerObserver(this); + } + + @Override + public void update(List jsonObjects) { + System.out.println(jsonObjects); + } +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java new file mode 100644 index 0000000..fe02b9e --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java @@ -0,0 +1,87 @@ +package org.sadtech.vkbot.config; + +import com.vk.api.sdk.client.TransportClient; +import com.vk.api.sdk.client.VkApiClient; +import com.vk.api.sdk.client.actors.GroupActor; +import com.vk.api.sdk.exceptions.ApiException; +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.sadtech.vkbot.ResponseData; +import org.sadtech.consultant.controller.Test; +import org.sadtech.vkbot.TestLogic; +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; + +@Configuration +@PropertySource("classpath:config.properties") +public class SpringConfig { + + @Value("${vk.groupID}") + private String groupId; + + @Value("${vk.appID}") + private String appID; + + @Value("${vk.secretKey}") + private String secretKey; + + @Value("${vk.redirectURL}") + private String redirectURL; + + @Value("${vk.code}") + private String code; + + @Value("${vk.token}") + private String token; + + @Bean + public TransportClient transportClient() { + return HttpTransportClient.getInstance(); + } + + @Bean + public VkApiClient vkApiClient() { + VkApiClient vk = new VkApiClient(transportClient()); +// System.out.println("vk: " + vk); + return vk; + } + + @Bean + public GroupActor groupActor() { + GroupActor actor = new GroupActor(new Integer(groupId), token); +// System.out.println("actor: " + actor); + return actor; + } + + @Bean + public GetLongPollServerResponse GroupsGetLongPollServerQuery() { + GetLongPollServerResponse getLongPollServerResponse = null; + try { + getLongPollServerResponse = vkApiClient().groups().getLongPollServer(groupActor()).execute(); + } catch (ApiException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } +// System.out.println("server: "+getLongPollServerResponse); + return getLongPollServerResponse; + } + + @Bean(initMethod = "start") + public Test test() { + return new Test(); + } + + @Bean + public ResponseData responseData() { + return new ResponseData(); + } + + @Bean + public TestLogic testLogic() { + return new TestLogic(responseData()); + } +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java new file mode 100644 index 0000000..f7b4685 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java @@ -0,0 +1,27 @@ +package org.sadtech.vkbot.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +@Configuration +@ComponentScan("org.sadtech.vkbot.controller") +public class WebConfig implements WebApplicationInitializer { + + @Override + public void onStartup(ServletContext servletContext) throws ServletException { + AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); + context.register(SpringConfig.class, WebConfig.class); + context.setServletContext(servletContext); + + ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); + dispatcher.setLoadOnStartup(1); + dispatcher.addMapping("/"); + } +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java b/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java new file mode 100644 index 0000000..849c466 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java @@ -0,0 +1,66 @@ +package org.sadtech.consultant.controller; + +import com.vk.api.sdk.actions.LongPoll; +import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; +import com.vk.api.sdk.callback.longpoll.responses.GetLongPollEventsResponse; +import com.vk.api.sdk.client.VkApiClient; +import com.vk.api.sdk.client.actors.GroupActor; +import com.vk.api.sdk.exceptions.ApiException; +import com.vk.api.sdk.exceptions.ClientException; +import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; +import org.json.JSONObject; +import org.sadtech.vkbot.ResponseData; +import org.springframework.beans.factory.annotation.Autowired; + +public class Test extends Thread { + + @Autowired + private VkApiClient vk; + + @Autowired + private GroupActor actor; + + @Autowired + private ResponseData responseData; + + private GetLongPollEventsResponse getLongPollEventsResponse = null; + + public void run() { + GetLongPollServerResponse getResponse = null; + try { + getResponse = vk.groups().getLongPollServer(actor).execute(); + } catch (ApiException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } + + JSONObject jObject = new JSONObject(getResponse); // json +// System.out.println(getResponse); + String key = jObject.getString("key"); // get the name from data. + String server = jObject.getString("server"); + Integer ts = jObject.getInt("ts"); + LongPoll longPoll = new LongPoll(vk); + GetLongPollEventsQuery getLongPollEventsQuery = longPoll.getEvents(server, key, ts).waitTime(5); +// Gson gson = new Gson(); + + while (true) { + try { + getLongPollEventsResponse = getLongPollEventsQuery.execute(); + } catch (ApiException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } +// System.out.println(getLongPollEventsResponse); + if (getLongPollEventsResponse.getUpdates().toArray().length != 0) { + responseData.setJsonObjects(getLongPollEventsResponse.getUpdates()); +// JsonObject updates = getLongPollEventsResponse.getUpdates().get(0); +// JsonObject object = updates.getAsJsonObject("object"); +// Message messages = gson.fromJson(object, Message.class); + } + getLongPollEventsQuery = longPoll.getEvents(server, key, getLongPollEventsResponse.getTs()).waitTime(5); + } + } + +} From 6fa2baac7ed2d167ac5cc401e626e449fd2de58f Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 21 Dec 2018 23:14:50 +0300 Subject: [PATCH 02/29] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D1=81=D0=B2=D1=8F?= =?UTF-8?q?=D0=B7=D1=8C=20=D1=81=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Добавли логироание Log4j * Настроил тестовую взаимосвязь с БД MySQL --- .gitignore | 2 + core/pom.xml | 18 +++++ .../org/sadtech/consultant/dao/NextStage.java | 14 ++++ .../org/sadtech/consultant/dao/SaveStage.java | 16 ++++ .../consultant/dao/SocialNetworks.java | 18 +++++ .../org/sadtech/consultant/dao/Stage.java | 17 ++++ .../java/org/sadtech/consultant/dao/User.java | 24 ++++++ vk-bot/WEB-INF/web.xml | 6 ++ vk-bot/pom.xml | 69 +++++++++++++++-- .../org/sadtech/vkbot/config/DataConfig.java | 77 +++++++++++++++++++ .../sadtech/vkbot/config/SpringConfig.java | 12 ++- .../org/sadtech/vkbot/config/WebConfig.java | 3 +- .../org/sadtech/vkbot/controller/Test.java | 24 +++++- .../main/java/org/sadtech/vkbot/dao/User.java | 19 +++++ .../sadtech/vkbot/repo/UserRepository.java | 9 +++ .../sadtech/vkbot/service/UserService.java | 11 +++ .../vkbot/service/impl/UserServiceImpl.java | 24 ++++++ 17 files changed, 351 insertions(+), 12 deletions(-) create mode 100644 core/src/main/java/org/sadtech/consultant/dao/NextStage.java create mode 100644 core/src/main/java/org/sadtech/consultant/dao/SaveStage.java create mode 100644 core/src/main/java/org/sadtech/consultant/dao/SocialNetworks.java create mode 100644 core/src/main/java/org/sadtech/consultant/dao/Stage.java create mode 100644 core/src/main/java/org/sadtech/consultant/dao/User.java create mode 100644 vk-bot/WEB-INF/web.xml create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/config/DataConfig.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/dao/User.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/repo/UserRepository.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/service/UserService.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/service/impl/UserServiceImpl.java diff --git a/.gitignore b/.gitignore index 1c7043d..c2292b6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ **/target/** .DS_Store /vk-bot/src/main/resources/config.properties +*.log +*.properties diff --git a/core/pom.xml b/core/pom.xml index 6f96fe4..b500633 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -11,5 +11,23 @@ consultant-core + + 1.0.2 + 1.18.4 + + + + + javax.persistence + persistence-api + ${persistence.ver} + + + + org.projectlombok + lombok + ${lombok.ver} + + \ No newline at end of file diff --git a/core/src/main/java/org/sadtech/consultant/dao/NextStage.java b/core/src/main/java/org/sadtech/consultant/dao/NextStage.java new file mode 100644 index 0000000..9a7947d --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/dao/NextStage.java @@ -0,0 +1,14 @@ +package org.sadtech.consultant.dao; + +import lombok.Data; + +import javax.persistence.Entity; + +@Entity +@Data +public class NextStage { + + private long id; + private long idNext; + +} diff --git a/core/src/main/java/org/sadtech/consultant/dao/SaveStage.java b/core/src/main/java/org/sadtech/consultant/dao/SaveStage.java new file mode 100644 index 0000000..c80e35e --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/dao/SaveStage.java @@ -0,0 +1,16 @@ +package org.sadtech.consultant.dao; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +@Data +public class SaveStage { + + @Id + private long id; + private long idStage; + +} diff --git a/core/src/main/java/org/sadtech/consultant/dao/SocialNetworks.java b/core/src/main/java/org/sadtech/consultant/dao/SocialNetworks.java new file mode 100644 index 0000000..7dd831a --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/dao/SocialNetworks.java @@ -0,0 +1,18 @@ +package org.sadtech.consultant.dao; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Data +@Entity +public class SocialNetworks { + + @Id + private long id; + private long idVk; + private long idFacebook; + private long phone; + +} diff --git a/core/src/main/java/org/sadtech/consultant/dao/Stage.java b/core/src/main/java/org/sadtech/consultant/dao/Stage.java new file mode 100644 index 0000000..59aa1d7 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/dao/Stage.java @@ -0,0 +1,17 @@ +package org.sadtech.consultant.dao; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +@Data +public class Stage { + + @Id + private long id; + private String text; + private String wordKeys; + +} diff --git a/core/src/main/java/org/sadtech/consultant/dao/User.java b/core/src/main/java/org/sadtech/consultant/dao/User.java new file mode 100644 index 0000000..cf14046 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/dao/User.java @@ -0,0 +1,24 @@ +package org.sadtech.consultant.dao; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import java.util.List; + +@Entity +@Data +public class User { + + @Id + @GeneratedValue + private long id; + private String name; + private String token; + private String lastName; + private String city; + private List socialNetworks; + + +} diff --git a/vk-bot/WEB-INF/web.xml b/vk-bot/WEB-INF/web.xml new file mode 100644 index 0000000..d80081d --- /dev/null +++ b/vk-bot/WEB-INF/web.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml index 7c82c9f..09af7bc 100644 --- a/vk-bot/pom.xml +++ b/vk-bot/pom.xml @@ -22,6 +22,14 @@ 6 + + + org.apache.maven.plugins + maven-war-plugin + + false + + @@ -42,13 +50,11 @@ spring-core ${spring.ver} - org.springframework spring-context ${spring.ver} - org.springframework spring-context-support @@ -59,11 +65,6 @@ spring-web ${spring.ver} - - javax.servlet - javax.servlet-api - 3.1.0 - org.springframework spring-webmvc @@ -74,6 +75,19 @@ spring-core 5.1.3.RELEASE + + org.springframework.data + spring-data-jpa + 2.1.3.RELEASE + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + org.mortbay.jetty jetty-util @@ -85,7 +99,48 @@ json 20180813 + + + javax.persistence + persistence-api + 1.0.2 + + + mysql + mysql-connector-java + 8.0.13 + + + + org.hibernate + hibernate-entitymanager + 5.4.0.Final + + + + org.projectlombok + lombok + 1.18.4 + + + + log4j + log4j + 1.2.17 + + + org.hibernate + hibernate-core + 5.2.10.Final + + + org.hibernate + hibernate-core + 5.2.10.Final + + + \ No newline at end of file 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 new file mode 100644 index 0000000..1acd9af --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/DataConfig.java @@ -0,0 +1,77 @@ +package org.sadtech.vkbot.config; + +import org.hibernate.jpa.HibernatePersistenceProvider; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +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; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; +import java.util.Properties; + +@Configuration +@EnableTransactionManagement +@ComponentScan("org.sadtech.vkbot") +@EnableJpaRepositories("org.sadtech.vkbot.repo") +public class DataConfig { + + private static final String PROPERTY_NAME_DATABASE_DRIVER = "com.mysql.jdbc.Driver"; + private static final String PROPERTY_NAME_DATABASE_URL = "jdbc:mysql://localhost:3306/testbd"+ + "?verifyServerCertificate=false"+ + "&useSSL=false"+ + "&requireSSL=false"+ + "&useLegacyDatetimeCode=false"+ + "&"+ + "&serverTimezone=UTC"; + private static final String PROPERTY_NAME_DATABASE_USERNAME = "root"; + private static final String PROPERTY_NAME_DATABASE_PASSWORD = "121314185398MAmaPApa"; + + private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "org.hibernate.dialect.MySQL5Dialect"; + private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "true"; + private static final String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN = "org.sadtech.vkbot"; + private static final String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO = "create-drop"; + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); + entityManagerFactoryBean.setDataSource(dataSource()); + entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); + entityManagerFactoryBean.setPackagesToScan(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN); + entityManagerFactoryBean.setJpaProperties(hibernateProp()); + + return entityManagerFactoryBean; + } + + @Bean + public JpaTransactionManager transactionManager() { + JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); + + return transactionManager; + } + + @Bean + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + + dataSource.setDriverClassName(PROPERTY_NAME_DATABASE_DRIVER); + dataSource.setUrl(PROPERTY_NAME_DATABASE_URL); + dataSource.setUsername(PROPERTY_NAME_DATABASE_USERNAME); + dataSource.setPassword(PROPERTY_NAME_DATABASE_PASSWORD); + + return dataSource; + } + + private Properties hibernateProp() { + Properties properties = new Properties(); + properties.put("hibernate.dialect", PROPERTY_NAME_HIBERNATE_DIALECT); + properties.put("hibernate.show_sql", PROPERTY_NAME_HIBERNATE_SHOW_SQL); + properties.put("hibernate.hbm2ddl.auto", PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO); + return properties; + } + +} \ No newline at end of file diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java index fe02b9e..20c0c81 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java @@ -8,15 +8,20 @@ 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.sadtech.vkbot.ResponseData; -import org.sadtech.consultant.controller.Test; import org.sadtech.vkbot.TestLogic; +import org.sadtech.vkbot.controller.Test; +import org.sadtech.vkbot.service.UserService; +import org.sadtech.vkbot.service.impl.UserServiceImpl; 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.data.jpa.repository.config.EnableJpaRepositories; @Configuration @PropertySource("classpath:config.properties") +@ComponentScan("org.sadtech.vkbot") public class SpringConfig { @Value("${vk.groupID}") @@ -75,6 +80,11 @@ public class SpringConfig { return new Test(); } + @Bean + public UserService userService() { + return new UserServiceImpl(); + } + @Bean public ResponseData responseData() { return new ResponseData(); diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java index f7b4685..b808784 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java @@ -9,6 +9,7 @@ import org.springframework.web.servlet.DispatcherServlet; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; +import javax.sql.DataSource; @Configuration @ComponentScan("org.sadtech.vkbot.controller") @@ -17,7 +18,7 @@ public class WebConfig implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - context.register(SpringConfig.class, WebConfig.class); + context.register(SpringConfig.class, WebConfig.class, DataConfig.class); context.setServletContext(servletContext); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java b/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java index 849c466..23b8b78 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.controller; +package org.sadtech.vkbot.controller; import com.vk.api.sdk.actions.LongPoll; import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; @@ -8,10 +8,20 @@ import com.vk.api.sdk.client.actors.GroupActor; 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.json.JSONObject; import org.sadtech.vkbot.ResponseData; +import org.sadtech.vkbot.dao.User; +import org.sadtech.vkbot.service.UserService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Repository; +import javax.annotation.Resource; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +@Log4j public class Test extends Thread { @Autowired @@ -23,6 +33,9 @@ public class Test extends Thread { @Autowired private ResponseData responseData; + @Resource + private UserService userService; + private GetLongPollEventsResponse getLongPollEventsResponse = null; public void run() { @@ -34,7 +47,7 @@ public class Test extends Thread { } catch (ClientException e) { e.printStackTrace(); } - + log.info("Test"); JSONObject jObject = new JSONObject(getResponse); // json // System.out.println(getResponse); String key = jObject.getString("key"); // get the name from data. @@ -44,6 +57,11 @@ public class Test extends Thread { GetLongPollEventsQuery getLongPollEventsQuery = longPoll.getEvents(server, key, ts).waitTime(5); // Gson gson = new Gson(); + User user = new User(); + user.setId(1); + user.setName("Test"); + userService.addUser(user); + while (true) { try { getLongPollEventsResponse = getLongPollEventsQuery.execute(); @@ -52,7 +70,7 @@ public class Test extends Thread { } catch (ClientException e) { e.printStackTrace(); } -// System.out.println(getLongPollEventsResponse); + System.out.println(getLongPollEventsResponse); if (getLongPollEventsResponse.getUpdates().toArray().length != 0) { responseData.setJsonObjects(getLongPollEventsResponse.getUpdates()); // JsonObject updates = getLongPollEventsResponse.getUpdates().get(0); diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/dao/User.java b/vk-bot/src/main/java/org/sadtech/vkbot/dao/User.java new file mode 100644 index 0000000..3009957 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/dao/User.java @@ -0,0 +1,19 @@ +package org.sadtech.vkbot.dao; + +import lombok.Data; +import org.hibernate.annotations.GenericGenerator; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +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/repo/UserRepository.java b/vk-bot/src/main/java/org/sadtech/vkbot/repo/UserRepository.java new file mode 100644 index 0000000..f1629f3 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/repo/UserRepository.java @@ -0,0 +1,9 @@ +package org.sadtech.vkbot.repo; + +import org.sadtech.vkbot.dao.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 new file mode 100644 index 0000000..9657604 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/service/UserService.java @@ -0,0 +1,11 @@ +package org.sadtech.vkbot.service; + +import org.sadtech.vkbot.dao.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 new file mode 100644 index 0000000..e3f8e70 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/service/impl/UserServiceImpl.java @@ -0,0 +1,24 @@ +package org.sadtech.vkbot.service.impl; + +import org.sadtech.vkbot.dao.User; +import org.sadtech.vkbot.repo.UserRepository; +import org.sadtech.vkbot.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; + + +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); + } +} From 8be8c6f1fade778ad99ad106b4909486dbb51189 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 22 Dec 2018 01:38:29 +0300 Subject: [PATCH 03/29] MinnorUpdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Перенес настройки базы и hibernate в properties --- .../org/sadtech/vkbot/config/DataConfig.java | 33 +++++++++++-------- .../vkbot/service/impl/UserServiceImpl.java | 2 ++ 2 files changed, 21 insertions(+), 14 deletions(-) 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 1acd9af..e529826 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 @@ -1,9 +1,11 @@ package org.sadtech.vkbot.config; import org.hibernate.jpa.HibernatePersistenceProvider; +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.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; @@ -17,23 +19,26 @@ import java.util.Properties; @EnableTransactionManagement @ComponentScan("org.sadtech.vkbot") @EnableJpaRepositories("org.sadtech.vkbot.repo") +@PropertySource("classpath:app.properties") public class DataConfig { - private static final String PROPERTY_NAME_DATABASE_DRIVER = "com.mysql.jdbc.Driver"; - private static final String PROPERTY_NAME_DATABASE_URL = "jdbc:mysql://localhost:3306/testbd"+ - "?verifyServerCertificate=false"+ - "&useSSL=false"+ - "&requireSSL=false"+ - "&useLegacyDatetimeCode=false"+ - "&"+ - "&serverTimezone=UTC"; - private static final String PROPERTY_NAME_DATABASE_USERNAME = "root"; - private static final String PROPERTY_NAME_DATABASE_PASSWORD = "121314185398MAmaPApa"; + @Value("${db.driver}") + private String PROPERTY_NAME_DATABASE_DRIVER; + @Value("${db.url}") + private String PROPERTY_NAME_DATABASE_URL; + @Value("${db.username}") + private String PROPERTY_NAME_DATABASE_USERNAME; + @Value("${db.password}") + private String PROPERTY_NAME_DATABASE_PASSWORD; - private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "org.hibernate.dialect.MySQL5Dialect"; - private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "true"; - private static final String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN = "org.sadtech.vkbot"; - private static final String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO = "create-drop"; + @Value("${db.hibernate.dialect}") + private String PROPERTY_NAME_HIBERNATE_DIALECT; + @Value("${db.hibernate.show_sql}") + private String PROPERTY_NAME_HIBERNATE_SHOW_SQL; + @Value("${db.entitymanager.packages.to.scan}") + private String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN; + @Value("${db.hibernate.hbm2ddl.auto}") + private String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO; @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { 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 index e3f8e70..1484ff6 100644 --- 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 @@ -4,8 +4,10 @@ import org.sadtech.vkbot.dao.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 From 6c6a4338c60b0236845f0cacd6ffc05713959c5f Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sun, 23 Dec 2018 03:34:18 +0300 Subject: [PATCH 04/29] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=20OR?= =?UTF-8?q?M=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D1=83=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 15 +++ .../org/sadtech/consultant/dao/NextStage.java | 14 --- .../sadtech/consultant/entity/NextUnit.java | 14 +++ .../sadtech/consultant/entity/SaveUnit.java | 16 ++++ .../{dao => entity}/SocialNetworks.java | 9 +- .../{dao/Stage.java => entity/Unit.java} | 6 +- .../consultant/{dao => entity}/User.java | 5 +- .../repository/NextUnitRepositoriy.java | 10 ++ .../repository/SaveUnitRepositoriy.java | 7 ++ .../repository/SocialNetworksRepositoriy.java | 7 ++ .../repository/UnitRepositoriy.java | 7 ++ .../repository/UserRepositoriy.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/NextUnitServiceImpl.java | 14 +++ .../service/impl/SaveUnitServiceImpl.java | 14 +++ .../impl/SocialNetworksServiceImpl.java | 14 +++ .../service/impl/UnitServiceImpl.java | 22 +++++ .../service/impl/UserServiceImpl.java | 22 +++++ facebook-bot/pom.xml | 15 +++ pom.xml | 1 + vk-bot/pom.xml | 93 +++++++++++-------- .../org/sadtech/vkbot/config/DataConfig.java | 2 +- .../org/sadtech/vkbot/controller/Test.java | 14 +-- .../main/java/org/sadtech/vkbot/dao/User.java | 19 ---- .../java/org/sadtech/vkbot/entity/User.java | 6 +- .../sadtech/vkbot/repo/UserRepository.java | 2 +- .../sadtech/vkbot/service/UserService.java | 2 +- .../vkbot/service/impl/UserServiceImpl.java | 2 +- 32 files changed, 291 insertions(+), 101 deletions(-) delete mode 100644 core/src/main/java/org/sadtech/consultant/dao/NextStage.java create mode 100644 core/src/main/java/org/sadtech/consultant/entity/NextUnit.java create mode 100644 core/src/main/java/org/sadtech/consultant/entity/SaveUnit.java rename core/src/main/java/org/sadtech/consultant/{dao => entity}/SocialNetworks.java (51%) rename core/src/main/java/org/sadtech/consultant/{dao/Stage.java => entity/Unit.java} (67%) rename core/src/main/java/org/sadtech/consultant/{dao => entity}/User.java (81%) create mode 100644 core/src/main/java/org/sadtech/consultant/repository/NextUnitRepositoriy.java create mode 100644 core/src/main/java/org/sadtech/consultant/repository/SaveUnitRepositoriy.java create mode 100644 core/src/main/java/org/sadtech/consultant/repository/SocialNetworksRepositoriy.java create mode 100644 core/src/main/java/org/sadtech/consultant/repository/UnitRepositoriy.java create mode 100644 core/src/main/java/org/sadtech/consultant/repository/UserRepositoriy.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/NextUnitService.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/SaveUnitService.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/SocialNetworksService.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/UnitService.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/UserService.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/impl/NextUnitServiceImpl.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/impl/SaveUnitServiceImpl.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/impl/SocialNetworksServiceImpl.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/impl/UnitServiceImpl.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/impl/UserServiceImpl.java create mode 100644 facebook-bot/pom.xml delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/dao/User.java rename core/src/main/java/org/sadtech/consultant/dao/SaveStage.java => vk-bot/src/main/java/org/sadtech/vkbot/entity/User.java (60%) diff --git a/core/pom.xml b/core/pom.xml index b500633..5e55758 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -14,6 +14,9 @@ 1.0.2 1.18.4 + 1.2.17 + + 2.1.3.RELEASE @@ -28,6 +31,18 @@ lombok ${lombok.ver} + + + log4j + log4j + ${log4j} + + + + org.springframework.data + spring-data-jpa + ${spring.data} + \ No newline at end of file diff --git a/core/src/main/java/org/sadtech/consultant/dao/NextStage.java b/core/src/main/java/org/sadtech/consultant/dao/NextStage.java deleted file mode 100644 index 9a7947d..0000000 --- a/core/src/main/java/org/sadtech/consultant/dao/NextStage.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sadtech.consultant.dao; - -import lombok.Data; - -import javax.persistence.Entity; - -@Entity -@Data -public class NextStage { - - private long id; - private long idNext; - -} diff --git a/core/src/main/java/org/sadtech/consultant/entity/NextUnit.java b/core/src/main/java/org/sadtech/consultant/entity/NextUnit.java new file mode 100644 index 0000000..922cd20 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/entity/NextUnit.java @@ -0,0 +1,14 @@ +package org.sadtech.consultant.entity; + +import lombok.Data; + +import javax.persistence.Entity; + +@Entity +@Data +public class NextUnit { + + 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/entity/SaveUnit.java new file mode 100644 index 0000000..8e7a447 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/entity/SaveUnit.java @@ -0,0 +1,16 @@ +package org.sadtech.consultant.entity; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +@Data +public class SaveUnit { + + @Id + private Long id; + private Long idStage; + +} diff --git a/core/src/main/java/org/sadtech/consultant/dao/SocialNetworks.java b/core/src/main/java/org/sadtech/consultant/entity/SocialNetworks.java similarity index 51% rename from core/src/main/java/org/sadtech/consultant/dao/SocialNetworks.java rename to core/src/main/java/org/sadtech/consultant/entity/SocialNetworks.java index 7dd831a..d167608 100644 --- a/core/src/main/java/org/sadtech/consultant/dao/SocialNetworks.java +++ b/core/src/main/java/org/sadtech/consultant/entity/SocialNetworks.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.dao; +package org.sadtech.consultant.entity; import lombok.Data; @@ -10,9 +10,8 @@ import javax.persistence.Id; public class SocialNetworks { @Id - private long id; - private long idVk; - private long idFacebook; - private long phone; + private Long id; + private Long idVk; + private Long idFacebook; } diff --git a/core/src/main/java/org/sadtech/consultant/dao/Stage.java b/core/src/main/java/org/sadtech/consultant/entity/Unit.java similarity index 67% rename from core/src/main/java/org/sadtech/consultant/dao/Stage.java rename to core/src/main/java/org/sadtech/consultant/entity/Unit.java index 59aa1d7..0f13505 100644 --- a/core/src/main/java/org/sadtech/consultant/dao/Stage.java +++ b/core/src/main/java/org/sadtech/consultant/entity/Unit.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.dao; +package org.sadtech.consultant.entity; import lombok.Data; @@ -7,10 +7,10 @@ import javax.persistence.Id; @Entity @Data -public class Stage { +public class Unit { @Id - private long id; + private Long id; private String text; private String wordKeys; diff --git a/core/src/main/java/org/sadtech/consultant/dao/User.java b/core/src/main/java/org/sadtech/consultant/entity/User.java similarity index 81% rename from core/src/main/java/org/sadtech/consultant/dao/User.java rename to core/src/main/java/org/sadtech/consultant/entity/User.java index cf14046..c58617b 100644 --- a/core/src/main/java/org/sadtech/consultant/dao/User.java +++ b/core/src/main/java/org/sadtech/consultant/entity/User.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.dao; +package org.sadtech.consultant.entity; import lombok.Data; @@ -12,8 +12,7 @@ import java.util.List; public class User { @Id - @GeneratedValue - private long id; + private Long id; private String name; private String token; private String lastName; diff --git a/core/src/main/java/org/sadtech/consultant/repository/NextUnitRepositoriy.java b/core/src/main/java/org/sadtech/consultant/repository/NextUnitRepositoriy.java new file mode 100644 index 0000000..6cc97d5 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/repository/NextUnitRepositoriy.java @@ -0,0 +1,10 @@ +package org.sadtech.consultant.repository; + +import org.sadtech.consultant.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/repository/SaveUnitRepositoriy.java new file mode 100644 index 0000000..d1cd49a --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/repository/SaveUnitRepositoriy.java @@ -0,0 +1,7 @@ +package org.sadtech.consultant.repository; + +import org.sadtech.consultant.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/repository/SocialNetworksRepositoriy.java new file mode 100644 index 0000000..1e9e84a --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/repository/SocialNetworksRepositoriy.java @@ -0,0 +1,7 @@ +package org.sadtech.consultant.repository; + +import org.sadtech.consultant.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/repository/UnitRepositoriy.java new file mode 100644 index 0000000..f804f65 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/repository/UnitRepositoriy.java @@ -0,0 +1,7 @@ +package org.sadtech.consultant.repository; + +import org.sadtech.consultant.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/repository/UserRepositoriy.java new file mode 100644 index 0000000..25e5e05 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/repository/UserRepositoriy.java @@ -0,0 +1,8 @@ +package org.sadtech.consultant.repository; + +import org.sadtech.consultant.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepositoriy extends JpaRepository { + +} diff --git a/core/src/main/java/org/sadtech/consultant/service/NextUnitService.java b/core/src/main/java/org/sadtech/consultant/service/NextUnitService.java new file mode 100644 index 0000000..9ff5ac8 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/NextUnitService.java @@ -0,0 +1,4 @@ +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 new file mode 100644 index 0000000..39e76cc --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/SaveUnitService.java @@ -0,0 +1,4 @@ +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 new file mode 100644 index 0000000..54dab6d --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/SocialNetworksService.java @@ -0,0 +1,4 @@ +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 new file mode 100644 index 0000000..c8e77e9 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/UnitService.java @@ -0,0 +1,10 @@ +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 new file mode 100644 index 0000000..5018e68 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/UserService.java @@ -0,0 +1,10 @@ +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/NextUnitServiceImpl.java b/core/src/main/java/org/sadtech/consultant/service/impl/NextUnitServiceImpl.java new file mode 100644 index 0000000..d06b195 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/impl/NextUnitServiceImpl.java @@ -0,0 +1,14 @@ +package org.sadtech.consultant.service.impl; + +import org.sadtech.consultant.repository.NextUnitRepositoriy; +import org.sadtech.consultant.service.NextUnitService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class NextUnitServiceImpl implements NextUnitService { + + @Autowired + private NextUnitRepositoriy repositoriy; + +} diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/SaveUnitServiceImpl.java b/core/src/main/java/org/sadtech/consultant/service/impl/SaveUnitServiceImpl.java new file mode 100644 index 0000000..51ef4b6 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/impl/SaveUnitServiceImpl.java @@ -0,0 +1,14 @@ +package org.sadtech.consultant.service.impl; + +import org.sadtech.consultant.repository.SaveUnitRepositoriy; +import org.sadtech.consultant.service.SaveUnitService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class SaveUnitServiceImpl implements SaveUnitService { + + @Autowired + private SaveUnitRepositoriy repositoriy; + +} diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/SocialNetworksServiceImpl.java b/core/src/main/java/org/sadtech/consultant/service/impl/SocialNetworksServiceImpl.java new file mode 100644 index 0000000..06d5f78 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/impl/SocialNetworksServiceImpl.java @@ -0,0 +1,14 @@ +package org.sadtech.consultant.service.impl; + +import org.sadtech.consultant.repository.SocialNetworksRepositoriy; +import org.sadtech.consultant.service.SocialNetworksService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class SocialNetworksServiceImpl implements SocialNetworksService { + + @Autowired + private SocialNetworksRepositoriy repositoriy; + +} diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/UnitServiceImpl.java b/core/src/main/java/org/sadtech/consultant/service/impl/UnitServiceImpl.java new file mode 100644 index 0000000..14706d9 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/impl/UnitServiceImpl.java @@ -0,0 +1,22 @@ +package org.sadtech.consultant.service.impl; + +import org.sadtech.consultant.entity.Unit; +import org.sadtech.consultant.repository.UnitRepositoriy; +import org.sadtech.consultant.service.UnitService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class UnitServiceImpl implements UnitService { + + @Autowired + private UnitRepositoriy repositoriy; + + public void addUnit(Unit unit) { + repositoriy.saveAndFlush(unit); + } + + public void removeUnit(Long id) { + + } +} diff --git a/core/src/main/java/org/sadtech/consultant/service/impl/UserServiceImpl.java b/core/src/main/java/org/sadtech/consultant/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..3535b00 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/impl/UserServiceImpl.java @@ -0,0 +1,22 @@ +package org.sadtech.consultant.service.impl; + +import org.sadtech.consultant.entity.User; +import org.sadtech.consultant.repository.UserRepositoriy; +import org.sadtech.consultant.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class UserServiceImpl implements UserService { + + @Autowired + private UserRepositoriy repositoriy; + + public void addUser(User user) { + //@TODO: Написть добавление профиля в бд + } + + public void removeUser(Long id) { + //@TODO: Написать удаление профиля из бд + } +} diff --git a/facebook-bot/pom.xml b/facebook-bot/pom.xml new file mode 100644 index 0000000..dca92c0 --- /dev/null +++ b/facebook-bot/pom.xml @@ -0,0 +1,15 @@ + + + + consultant + org.sadtech + 0.1-SNAPSHOT + + 4.0.0 + + facebook-bot + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 494110a..d7ad9d4 100644 --- a/pom.xml +++ b/pom.xml @@ -11,6 +11,7 @@ vk-bot core + facebook-bot diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml index 09af7bc..8139c8a 100644 --- a/vk-bot/pom.xml +++ b/vk-bot/pom.xml @@ -2,6 +2,7 @@ + time-table org.sadtech @@ -35,10 +36,46 @@ 0.5.12 - 5.1.3.RELEASE + + 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 + 1.0.2 + + 5.4.0.Final + 5.2.10.Final + + 8.0.13 + + 1.18.4 + + 1.2.17 + + 20180813 + + 6.1.25 + + + org.projectlombok + lombok + ${lombok} + + + + log4j + log4j + ${log4j} + + com.vk.api sdk @@ -48,99 +85,73 @@ org.springframework spring-core - ${spring.ver} + ${spring.core} org.springframework spring-context - ${spring.ver} + ${spring.context} org.springframework spring-context-support - ${spring.ver} + ${spring.context} org.springframework spring-web - ${spring.ver} + ${spring.web} org.springframework spring-webmvc - 5.1.3.RELEASE - - - org.springframework - spring-core - 5.1.3.RELEASE + ${spring.webmvc} org.springframework.data spring-data-jpa - 2.1.3.RELEASE + ${spring.data} javax.servlet javax.servlet-api - 3.1.0 + ${javax.servlet} - org.mortbay.jetty jetty-util - 6.1.25 + ${jetty.util} org.json json - 20180813 + ${json} javax.persistence persistence-api - 1.0.2 + ${javax.persistance} mysql mysql-connector-java - 8.0.13 + ${mysql.connector} org.hibernate hibernate-entitymanager - 5.4.0.Final - - - - org.projectlombok - lombok - 1.18.4 - - - - log4j - log4j - 1.2.17 + ${hibernate.entitymanager} org.hibernate hibernate-core - 5.2.10.Final - - - org.hibernate - hibernate-core - 5.2.10.Final + ${hibernate.core} + - - - - \ No newline at end of file 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 e529826..ebca4c1 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 @@ -19,7 +19,7 @@ import java.util.Properties; @EnableTransactionManagement @ComponentScan("org.sadtech.vkbot") @EnableJpaRepositories("org.sadtech.vkbot.repo") -@PropertySource("classpath:app.properties") +@PropertySource("classpath:config.properties") public class DataConfig { @Value("${db.driver}") diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java b/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java index 23b8b78..2ccf655 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java @@ -11,17 +11,14 @@ import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; import lombok.extern.log4j.Log4j; import org.json.JSONObject; import org.sadtech.vkbot.ResponseData; -import org.sadtech.vkbot.dao.User; +import org.sadtech.vkbot.entity.User; import org.sadtech.vkbot.service.UserService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.stereotype.Repository; import javax.annotation.Resource; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; @Log4j + public class Test extends Thread { @Autowired @@ -47,14 +44,13 @@ public class Test extends Thread { } catch (ClientException e) { e.printStackTrace(); } - log.info("Test"); JSONObject jObject = new JSONObject(getResponse); // json // System.out.println(getResponse); String key = jObject.getString("key"); // get the name from data. String server = jObject.getString("server"); Integer ts = jObject.getInt("ts"); LongPoll longPoll = new LongPoll(vk); - GetLongPollEventsQuery getLongPollEventsQuery = longPoll.getEvents(server, key, ts).waitTime(5); + GetLongPollEventsQuery getLongPollEventsQuery = longPoll.getEvents(server, key, ts).waitTime(20); // Gson gson = new Gson(); User user = new User(); @@ -70,14 +66,14 @@ public class Test extends Thread { } catch (ClientException e) { e.printStackTrace(); } - System.out.println(getLongPollEventsResponse); + log.info(getLongPollEventsResponse); if (getLongPollEventsResponse.getUpdates().toArray().length != 0) { responseData.setJsonObjects(getLongPollEventsResponse.getUpdates()); // JsonObject updates = getLongPollEventsResponse.getUpdates().get(0); // JsonObject object = updates.getAsJsonObject("object"); // Message messages = gson.fromJson(object, Message.class); } - getLongPollEventsQuery = longPoll.getEvents(server, key, getLongPollEventsResponse.getTs()).waitTime(5); + getLongPollEventsQuery = longPoll.getEvents(server, key, getLongPollEventsResponse.getTs()).waitTime(20); } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/dao/User.java b/vk-bot/src/main/java/org/sadtech/vkbot/dao/User.java deleted file mode 100644 index 3009957..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/dao/User.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sadtech.vkbot.dao; - -import lombok.Data; -import org.hibernate.annotations.GenericGenerator; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -@Data -public class User { - - @Id - private long id; - private String name; - -} diff --git a/core/src/main/java/org/sadtech/consultant/dao/SaveStage.java b/vk-bot/src/main/java/org/sadtech/vkbot/entity/User.java similarity index 60% rename from core/src/main/java/org/sadtech/consultant/dao/SaveStage.java rename to vk-bot/src/main/java/org/sadtech/vkbot/entity/User.java index c80e35e..1601df8 100644 --- a/core/src/main/java/org/sadtech/consultant/dao/SaveStage.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/entity/User.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.dao; +package org.sadtech.vkbot.entity; import lombok.Data; @@ -7,10 +7,10 @@ import javax.persistence.Id; @Entity @Data -public class SaveStage { +public class User { @Id private long id; - private long idStage; + private String name; } 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 index f1629f3..f3cfd50 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/repo/UserRepository.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/repo/UserRepository.java @@ -1,6 +1,6 @@ package org.sadtech.vkbot.repo; -import org.sadtech.vkbot.dao.User; +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 index 9657604..88cba65 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/service/UserService.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/service/UserService.java @@ -1,6 +1,6 @@ package org.sadtech.vkbot.service; -import org.sadtech.vkbot.dao.User; +import org.sadtech.vkbot.entity.User; public interface UserService { 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 index 1484ff6..e7e1d2a 100644 --- 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 @@ -1,6 +1,6 @@ package org.sadtech.vkbot.service.impl; -import org.sadtech.vkbot.dao.User; +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; From 92e8a893a7415de2a6bb150fb1249abb9817b9bc Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sun, 23 Dec 2018 13:54:40 +0300 Subject: [PATCH 05/29] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B8=20=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D0=B9=20=D0=9A=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=BB=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Рефракторинг класса слушателя сообщений вк Новый контроллер для запросов к вк без токена --- .../java/org/sadtech/vkbot/VkOpenMethod.java | 22 +++++ .../sadtech/vkbot/config/SpringConfig.java | 25 ++++-- .../vkbot/controller/MessagesListener.java | 62 ++++++++++++++ .../org/sadtech/vkbot/controller/Test.java | 80 ------------------- 4 files changed, 103 insertions(+), 86 deletions(-) create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/controller/MessagesListener.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java new file mode 100644 index 0000000..87ee357 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java @@ -0,0 +1,22 @@ +package org.sadtech.vkbot; + +import com.vk.api.sdk.client.VkApiClient; +import com.vk.api.sdk.client.actors.GroupActor; +import lombok.extern.log4j.Log4j; +import org.springframework.stereotype.Component; + +@Component +@Log4j +public class VkOpenMethod { + + private VkApiClient vk; + + private GroupActor actor; + + public VkOpenMethod(VkApiClient vk, GroupActor actor) { + this.vk = vk; + this.actor = actor; + } + + +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java index 20c0c81..1162f1d 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java @@ -3,13 +3,15 @@ package org.sadtech.vkbot.config; import com.vk.api.sdk.client.TransportClient; import com.vk.api.sdk.client.VkApiClient; import com.vk.api.sdk.client.actors.GroupActor; +import com.vk.api.sdk.client.actors.ServiceActor; import com.vk.api.sdk.exceptions.ApiException; 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.sadtech.vkbot.ResponseData; import org.sadtech.vkbot.TestLogic; -import org.sadtech.vkbot.controller.Test; +import org.sadtech.vkbot.VkOpenMethod; +import org.sadtech.vkbot.controller.MessagesListener; import org.sadtech.vkbot.service.UserService; import org.sadtech.vkbot.service.impl.UserServiceImpl; import org.springframework.beans.factory.annotation.Value; @@ -17,7 +19,6 @@ 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.data.jpa.repository.config.EnableJpaRepositories; @Configuration @PropertySource("classpath:config.properties") @@ -42,6 +43,9 @@ public class SpringConfig { @Value("${vk.token}") private String token; + @Value("${vk.service.token}") + private String serviceToken; + @Bean public TransportClient transportClient() { return HttpTransportClient.getInstance(); @@ -50,14 +54,18 @@ public class SpringConfig { @Bean public VkApiClient vkApiClient() { VkApiClient vk = new VkApiClient(transportClient()); -// System.out.println("vk: " + vk); return vk; } @Bean public GroupActor groupActor() { GroupActor actor = new GroupActor(new Integer(groupId), token); -// System.out.println("actor: " + actor); + return actor; + } + + @Bean + public ServiceActor serviceActor() { + ServiceActor actor = new ServiceActor(new Integer(appID), serviceToken); return actor; } @@ -76,8 +84,8 @@ public class SpringConfig { } @Bean(initMethod = "start") - public Test test() { - return new Test(); + public MessagesListener messagesListener() { + return new MessagesListener(); } @Bean @@ -94,4 +102,9 @@ public class SpringConfig { public TestLogic testLogic() { return new TestLogic(responseData()); } + + @Bean + public VkOpenMethod vkOpenMethod() { + return new VkOpenMethod(vkApiClient(), groupActor()); + } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/controller/MessagesListener.java b/vk-bot/src/main/java/org/sadtech/vkbot/controller/MessagesListener.java new file mode 100644 index 0000000..76ee76b --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/controller/MessagesListener.java @@ -0,0 +1,62 @@ +package org.sadtech.vkbot.controller; + +import com.vk.api.sdk.actions.LongPoll; +import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; +import com.vk.api.sdk.callback.longpoll.responses.GetLongPollEventsResponse; +import com.vk.api.sdk.client.VkApiClient; +import com.vk.api.sdk.client.actors.GroupActor; +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.ResponseData; +import org.springframework.beans.factory.annotation.Autowired; + +@Log4j +public class MessagesListener extends Thread{ + + @Autowired + private VkApiClient vk; + + @Autowired + private GroupActor actor; + + @Autowired + private ResponseData responseData; + + public void run() { + GetLongPollServerResponse serverResponse = null; + try { + serverResponse = vk.groups().getLongPollServer(actor).execute(); + } catch (ApiException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } + + String key = serverResponse.getServer(); + String server = serverResponse.getKey(); + Integer ts = serverResponse.getTs(); + + LongPoll longPoll = new LongPoll(vk); + GetLongPollEventsQuery longPollEventsQuery = longPoll.getEvents(server, key, ts).waitTime(20); + + GetLongPollEventsResponse eventsResponse = null; + do { + try { + eventsResponse = longPollEventsQuery.execute(); + } catch (ApiException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } + if (eventsResponse.getUpdates().toArray().length != 0) { + + responseData.setJsonObjects(eventsResponse.getUpdates()); + + } + longPollEventsQuery = longPoll.getEvents(server, key, eventsResponse.getTs()).waitTime(20); + } while (true); + } + +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java b/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java deleted file mode 100644 index 2ccf655..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/controller/Test.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.sadtech.vkbot.controller; - -import com.vk.api.sdk.actions.LongPoll; -import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; -import com.vk.api.sdk.callback.longpoll.responses.GetLongPollEventsResponse; -import com.vk.api.sdk.client.VkApiClient; -import com.vk.api.sdk.client.actors.GroupActor; -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.json.JSONObject; -import org.sadtech.vkbot.ResponseData; -import org.sadtech.vkbot.entity.User; -import org.sadtech.vkbot.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; - -import javax.annotation.Resource; - -@Log4j - -public class Test extends Thread { - - @Autowired - private VkApiClient vk; - - @Autowired - private GroupActor actor; - - @Autowired - private ResponseData responseData; - - @Resource - private UserService userService; - - private GetLongPollEventsResponse getLongPollEventsResponse = null; - - public void run() { - GetLongPollServerResponse getResponse = null; - try { - getResponse = vk.groups().getLongPollServer(actor).execute(); - } catch (ApiException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } - JSONObject jObject = new JSONObject(getResponse); // json -// System.out.println(getResponse); - String key = jObject.getString("key"); // get the name from data. - String server = jObject.getString("server"); - Integer ts = jObject.getInt("ts"); - LongPoll longPoll = new LongPoll(vk); - GetLongPollEventsQuery getLongPollEventsQuery = longPoll.getEvents(server, key, ts).waitTime(20); -// Gson gson = new Gson(); - - User user = new User(); - user.setId(1); - user.setName("Test"); - userService.addUser(user); - - while (true) { - try { - getLongPollEventsResponse = getLongPollEventsQuery.execute(); - } catch (ApiException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } - log.info(getLongPollEventsResponse); - if (getLongPollEventsResponse.getUpdates().toArray().length != 0) { - responseData.setJsonObjects(getLongPollEventsResponse.getUpdates()); -// JsonObject updates = getLongPollEventsResponse.getUpdates().get(0); -// JsonObject object = updates.getAsJsonObject("object"); -// Message messages = gson.fromJson(object, Message.class); - } - getLongPollEventsQuery = longPoll.getEvents(server, key, getLongPollEventsResponse.getTs()).waitTime(20); - } - } - -} From 1ead58f1698dfc8ab8698c61a8d0aa3c8865ad2a Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 24 Dec 2018 00:51:28 +0300 Subject: [PATCH 06/29] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B8=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D1=80=D1=84=D0=B5=D1=81=D0=BE=D0=B2=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BB=D1=83=D1=88=D0=B0=D1=82=D0=B5=D0=BB=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...{ResponseData.java => ResponseDataVk.java} | 12 ++- .../org/sadtech/vkbot/ResponsibleData.java | 10 +++ .../java/org/sadtech/vkbot/TestLogic.java | 4 +- .../java/org/sadtech/vkbot/VkOpenMethod.java | 4 +- .../org/sadtech/vkbot/config/DataConfig.java | 1 - ...{SpringConfig.java => SpringConfigVk.java} | 24 ++---- .../org/sadtech/vkbot/config/WebConfig.java | 5 +- .../vkbot/controller/MessagesListener.java | 62 ---------------- .../vkbot/listener/EventListenable.java | 6 ++ .../vkbot/listener/EventListenerVk.java | 74 +++++++++++++++++++ 10 files changed, 115 insertions(+), 87 deletions(-) rename vk-bot/src/main/java/org/sadtech/vkbot/{ResponseData.java => ResponseDataVk.java} (75%) create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/ResponsibleData.java rename vk-bot/src/main/java/org/sadtech/vkbot/config/{SpringConfig.java => SpringConfigVk.java} (84%) delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/controller/MessagesListener.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenerVk.java diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/ResponseData.java b/vk-bot/src/main/java/org/sadtech/vkbot/ResponseDataVk.java similarity index 75% rename from vk-bot/src/main/java/org/sadtech/vkbot/ResponseData.java rename to vk-bot/src/main/java/org/sadtech/vkbot/ResponseDataVk.java index e6008b2..c778882 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/ResponseData.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/ResponseDataVk.java @@ -5,7 +5,7 @@ import com.google.gson.JsonObject; import java.util.ArrayList; import java.util.List; -public class ResponseData implements Observable { +public class ResponseDataVk implements Observable, ResponsibleData { private List observers = new ArrayList(); private List jsonObjects = new ArrayList(); @@ -26,4 +26,14 @@ public class ResponseData implements Observable { this.jsonObjects = jsonObjects; notifyObservers(); } + + @Override + public void add(JsonObject jsonObject) { + + } + + @Override + public void remove(JsonObject jsonObject) { + + } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/ResponsibleData.java b/vk-bot/src/main/java/org/sadtech/vkbot/ResponsibleData.java new file mode 100644 index 0000000..0c2e8fa --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/ResponsibleData.java @@ -0,0 +1,10 @@ +package org.sadtech.vkbot; + +import com.google.gson.JsonObject; + +public interface ResponsibleData { + + void add(JsonObject jsonObject); + void remove(JsonObject jsonObject); + +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java b/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java index 8e8ed9e..561eaeb 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java @@ -6,9 +6,9 @@ import java.util.List; public class TestLogic implements Observer{ - private ResponseData responseData; + private ResponseDataVk responseData; - public TestLogic(ResponseData responseData) { + public TestLogic(ResponseDataVk responseData) { this.responseData = responseData; responseData.registerObserver(this); } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java index 87ee357..ab62ad9 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java @@ -4,13 +4,13 @@ import com.vk.api.sdk.client.VkApiClient; import com.vk.api.sdk.client.actors.GroupActor; import lombok.extern.log4j.Log4j; import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; -@Component @Log4j +@Component public class VkOpenMethod { private VkApiClient vk; - private GroupActor actor; public VkOpenMethod(VkApiClient vk, GroupActor actor) { 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 ebca4c1..bd5202d 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 @@ -17,7 +17,6 @@ import java.util.Properties; @Configuration @EnableTransactionManagement -@ComponentScan("org.sadtech.vkbot") @EnableJpaRepositories("org.sadtech.vkbot.repo") @PropertySource("classpath:config.properties") public class DataConfig { diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java similarity index 84% rename from vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java rename to vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java index 1162f1d..3877aea 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfig.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java @@ -8,10 +8,9 @@ import com.vk.api.sdk.exceptions.ApiException; 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.sadtech.vkbot.ResponseData; +import org.sadtech.vkbot.ResponseDataVk; import org.sadtech.vkbot.TestLogic; import org.sadtech.vkbot.VkOpenMethod; -import org.sadtech.vkbot.controller.MessagesListener; import org.sadtech.vkbot.service.UserService; import org.sadtech.vkbot.service.impl.UserServiceImpl; import org.springframework.beans.factory.annotation.Value; @@ -19,11 +18,13 @@ 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.scheduling.annotation.EnableAsync; @Configuration @PropertySource("classpath:config.properties") @ComponentScan("org.sadtech.vkbot") -public class SpringConfig { +@EnableAsync +public class SpringConfigVk { @Value("${vk.groupID}") private String groupId; @@ -83,28 +84,19 @@ public class SpringConfig { return getLongPollServerResponse; } - @Bean(initMethod = "start") - public MessagesListener messagesListener() { - return new MessagesListener(); - } - @Bean public UserService userService() { return new UserServiceImpl(); } @Bean - public ResponseData responseData() { - return new ResponseData(); + public ResponseDataVk responseDataVk() { + return new ResponseDataVk(); } @Bean public TestLogic testLogic() { - return new TestLogic(responseData()); - } - - @Bean - public VkOpenMethod vkOpenMethod() { - return new VkOpenMethod(vkApiClient(), groupActor()); + return new TestLogic(responseDataVk()); } + } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java index b808784..4670ac2 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java @@ -9,16 +9,15 @@ import org.springframework.web.servlet.DispatcherServlet; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; -import javax.sql.DataSource; @Configuration -@ComponentScan("org.sadtech.vkbot.controller") +@ComponentScan("org.sadtech.vkbot.listener") public class WebConfig implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - context.register(SpringConfig.class, WebConfig.class, DataConfig.class); + context.register(SpringConfigVk.class, WebConfig.class, DataConfig.class); context.setServletContext(servletContext); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/controller/MessagesListener.java b/vk-bot/src/main/java/org/sadtech/vkbot/controller/MessagesListener.java deleted file mode 100644 index 76ee76b..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/controller/MessagesListener.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.sadtech.vkbot.controller; - -import com.vk.api.sdk.actions.LongPoll; -import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; -import com.vk.api.sdk.callback.longpoll.responses.GetLongPollEventsResponse; -import com.vk.api.sdk.client.VkApiClient; -import com.vk.api.sdk.client.actors.GroupActor; -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.ResponseData; -import org.springframework.beans.factory.annotation.Autowired; - -@Log4j -public class MessagesListener extends Thread{ - - @Autowired - private VkApiClient vk; - - @Autowired - private GroupActor actor; - - @Autowired - private ResponseData responseData; - - public void run() { - GetLongPollServerResponse serverResponse = null; - try { - serverResponse = vk.groups().getLongPollServer(actor).execute(); - } catch (ApiException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } - - String key = serverResponse.getServer(); - String server = serverResponse.getKey(); - Integer ts = serverResponse.getTs(); - - LongPoll longPoll = new LongPoll(vk); - GetLongPollEventsQuery longPollEventsQuery = longPoll.getEvents(server, key, ts).waitTime(20); - - GetLongPollEventsResponse eventsResponse = null; - do { - try { - eventsResponse = longPollEventsQuery.execute(); - } catch (ApiException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } - if (eventsResponse.getUpdates().toArray().length != 0) { - - responseData.setJsonObjects(eventsResponse.getUpdates()); - - } - longPollEventsQuery = longPoll.getEvents(server, key, eventsResponse.getTs()).waitTime(20); - } while (true); - } - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java new file mode 100644 index 0000000..0faccd8 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java @@ -0,0 +1,6 @@ +package org.sadtech.vkbot.listener; + +public interface EventListenable +{ + void listen() throws Exception; +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenerVk.java new file mode 100644 index 0000000..00aadb0 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenerVk.java @@ -0,0 +1,74 @@ +package org.sadtech.vkbot.listener; + +import com.vk.api.sdk.actions.LongPoll; +import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; +import com.vk.api.sdk.callback.longpoll.responses.GetLongPollEventsResponse; +import com.vk.api.sdk.client.VkApiClient; +import com.vk.api.sdk.client.actors.GroupActor; +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.ResponsibleData; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; + +@Log4j +@Service +public class EventListenerVk implements EventListenable, Runnable { + + private VkApiClient vk; + private GroupActor actor; + private ResponsibleData responseData; + + private GetLongPollEventsQuery longPollEventsQuery; + private LongPoll longPoll; + private GetLongPollServerResponse server; + + public EventListenerVk(VkApiClient vk, GroupActor actor, ResponsibleData responseData) { + this.vk = vk; + this.actor = actor; + this.responseData = responseData; + longPoll = new LongPoll(vk); + } + + public void run() { + try { + listen(); + } catch (ClientException e) { + e.printStackTrace(); + } catch (ApiException e) { + e.printStackTrace(); + } + } + + private void initServer() throws ClientException, ApiException { + server = vk.groups().getLongPollServer(actor).execute(); + String key = server.getKey(); + String serverUrl = server.getServer(); + Integer ts = server.getTs(); + + longPoll = new LongPoll(vk); + longPollEventsQuery = longPoll.getEvents(serverUrl, key, ts).waitTime(20); + } + + @Async + @PostConstruct + public void listen() throws ClientException, ApiException { + initServer(); + do { + GetLongPollEventsResponse eventsResponse; + eventsResponse = longPollEventsQuery.execute(); + if (eventsResponse.getUpdates().toArray().length != 0) { + + //responseData.setJsonObjects(eventsResponse.getUpdates()); + log.info(eventsResponse.getUpdates()); + } + longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20); + } while (true); + } + + +} From 9a719d70b85d24a070e767924d22fee3b46f5409 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Tue, 25 Dec 2018 03:13:04 +0300 Subject: [PATCH 07/29] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B0=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D1=81=D0=BB=D1=83=D1=88=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8F=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Научил программу работать в двух потоках. Первый поток слушает все сообещния от сервера и записывает их в отдельный класс. Другой поток раз в какое-то время обращается к этому классу и что-то делает --- .../sadtech/consultant/entity/Message.java | 18 ++++++ .../repository/MessageRepository.java | 8 +++ .../consultant/service/MessageService.java | 8 +++ .../service/impl/MessageServiceImpl.java | 16 +++++ .../java/org/sadtech/vkbot/Observable.java | 7 --- .../org/sadtech/vkbot/ResponseDataVk.java | 39 ------------ .../org/sadtech/vkbot/ResponsibleData.java | 10 ---- .../java/org/sadtech/vkbot/TestLogic.java | 20 ------- .../java/org/sadtech/vkbot/VkOpenMethod.java | 1 - .../org/sadtech/vkbot/config/DataConfig.java | 9 +-- .../sadtech/vkbot/config/SpringConfigVk.java | 31 +++++----- .../org/sadtech/vkbot/config/TestMain.java | 17 ++++++ .../org/sadtech/vkbot/config/WebConfig.java | 59 ++++++++++--------- .../vkbot/listener/EventListenable.java | 3 +- .../sadtech/vkbot/listener/Observable.java | 10 ++++ .../vkbot/{ => listener}/Observer.java | 2 +- .../vkbot/listener/data/ResponsibleData.java | 17 ++++++ .../listener/data/impl/ResponseDataVk.java | 33 +++++++++++ .../listener/handlers/DispetcherHandler.java | 48 +++++++++++++++ .../listener/handlers/MessageHandlerVk.java | 21 +++++++ .../listener/{ => impl}/EventListenerVk.java | 32 +++------- 21 files changed, 255 insertions(+), 154 deletions(-) create mode 100644 core/src/main/java/org/sadtech/consultant/entity/Message.java create mode 100644 core/src/main/java/org/sadtech/consultant/repository/MessageRepository.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/MessageService.java create mode 100644 core/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/Observable.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/ResponseDataVk.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/ResponsibleData.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/Observable.java rename vk-bot/src/main/java/org/sadtech/vkbot/{ => listener}/Observer.java (79%) create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/MessageHandlerVk.java rename vk-bot/src/main/java/org/sadtech/vkbot/listener/{ => impl}/EventListenerVk.java (75%) diff --git a/core/src/main/java/org/sadtech/consultant/entity/Message.java b/core/src/main/java/org/sadtech/consultant/entity/Message.java new file mode 100644 index 0000000..454188f --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/entity/Message.java @@ -0,0 +1,18 @@ +package org.sadtech.consultant.entity; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Data +@Entity +public class Message { + + @Id + private Long idMess; + private Long idUser; + private String text; + + +} diff --git a/core/src/main/java/org/sadtech/consultant/repository/MessageRepository.java b/core/src/main/java/org/sadtech/consultant/repository/MessageRepository.java new file mode 100644 index 0000000..aa0ec3b --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/repository/MessageRepository.java @@ -0,0 +1,8 @@ +package org.sadtech.consultant.repository; + +import org.sadtech.consultant.entity.Message; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MessageRepository extends JpaRepository { + +} diff --git a/core/src/main/java/org/sadtech/consultant/service/MessageService.java b/core/src/main/java/org/sadtech/consultant/service/MessageService.java new file mode 100644 index 0000000..b40658e --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/MessageService.java @@ -0,0 +1,8 @@ +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/impl/MessageServiceImpl.java b/core/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java new file mode 100644 index 0000000..e752d1e --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java @@ -0,0 +1,16 @@ +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/src/main/java/org/sadtech/vkbot/Observable.java b/vk-bot/src/main/java/org/sadtech/vkbot/Observable.java deleted file mode 100644 index b9a0acc..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/Observable.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.vkbot; - -public interface Observable { - void registerObserver(org.sadtech.vkbot.Observer o); -// void removeObserver(Observer o); - void notifyObservers(); -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/ResponseDataVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/ResponseDataVk.java deleted file mode 100644 index c778882..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/ResponseDataVk.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.sadtech.vkbot; - -import com.google.gson.JsonObject; - -import java.util.ArrayList; -import java.util.List; - -public class ResponseDataVk implements Observable, ResponsibleData { - - private List observers = new ArrayList(); - private List jsonObjects = new ArrayList(); - - @Override - public void registerObserver(Observer o) { - observers.add(o); - } - - @Override - public void notifyObservers() { - for (Observer observer:observers) { - observer.update(jsonObjects); - } - } - - public void setJsonObjects(List jsonObjects) { - this.jsonObjects = jsonObjects; - notifyObservers(); - } - - @Override - public void add(JsonObject jsonObject) { - - } - - @Override - public void remove(JsonObject jsonObject) { - - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/ResponsibleData.java b/vk-bot/src/main/java/org/sadtech/vkbot/ResponsibleData.java deleted file mode 100644 index 0c2e8fa..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/ResponsibleData.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.sadtech.vkbot; - -import com.google.gson.JsonObject; - -public interface ResponsibleData { - - void add(JsonObject jsonObject); - void remove(JsonObject jsonObject); - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java b/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java deleted file mode 100644 index 561eaeb..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/TestLogic.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.sadtech.vkbot; - -import com.google.gson.JsonObject; - -import java.util.List; - -public class TestLogic implements Observer{ - - private ResponseDataVk responseData; - - public TestLogic(ResponseDataVk responseData) { - this.responseData = responseData; - responseData.registerObserver(this); - } - - @Override - public void update(List jsonObjects) { - System.out.println(jsonObjects); - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java index ab62ad9..d26c51b 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java @@ -4,7 +4,6 @@ import com.vk.api.sdk.client.VkApiClient; import com.vk.api.sdk.client.actors.GroupActor; import lombok.extern.log4j.Log4j; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; @Log4j @Component 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 bd5202d..5360255 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 @@ -3,7 +3,6 @@ package org.sadtech.vkbot.config; import org.hibernate.jpa.HibernatePersistenceProvider; 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.data.jpa.repository.config.EnableJpaRepositories; @@ -39,14 +38,13 @@ public class DataConfig { @Value("${db.hibernate.hbm2ddl.auto}") private String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO; - @Bean + @Bean(name = "entityManagerFactory") public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); entityManagerFactoryBean.setPackagesToScan(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN); entityManagerFactoryBean.setJpaProperties(hibernateProp()); - return entityManagerFactoryBean; } @@ -54,25 +52,22 @@ public class DataConfig { public JpaTransactionManager transactionManager() { JpaTransactionManager transactionManager = new JpaTransactionManager(); transactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); - return transactionManager; } @Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(PROPERTY_NAME_DATABASE_DRIVER); dataSource.setUrl(PROPERTY_NAME_DATABASE_URL); dataSource.setUsername(PROPERTY_NAME_DATABASE_USERNAME); dataSource.setPassword(PROPERTY_NAME_DATABASE_PASSWORD); - return dataSource; } private Properties hibernateProp() { Properties properties = new Properties(); - properties.put("hibernate.dialect", PROPERTY_NAME_HIBERNATE_DIALECT); + properties.put("hibernate.dialect", PROPERTY_NAME_HIBERNATE_DIALECT); properties.put("hibernate.show_sql", PROPERTY_NAME_HIBERNATE_SHOW_SQL); properties.put("hibernate.hbm2ddl.auto", PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO); return properties; 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 3877aea..8519254 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 @@ -8,9 +8,8 @@ import com.vk.api.sdk.exceptions.ApiException; 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.sadtech.vkbot.ResponseDataVk; -import org.sadtech.vkbot.TestLogic; -import org.sadtech.vkbot.VkOpenMethod; +import org.sadtech.vkbot.listener.data.impl.ResponseDataVk; +import org.sadtech.vkbot.listener.impl.EventListenerVk; import org.sadtech.vkbot.service.UserService; import org.sadtech.vkbot.service.impl.UserServiceImpl; import org.springframework.beans.factory.annotation.Value; @@ -18,12 +17,19 @@ 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.core.task.TaskExecutor; import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; + +import java.util.concurrent.Executors; + @Configuration -@PropertySource("classpath:config.properties") -@ComponentScan("org.sadtech.vkbot") @EnableAsync +@PropertySource("classpath:config.properties") +@ComponentScan("org.sadtech.vkbot.listener") +@EnableScheduling public class SpringConfigVk { @Value("${vk.groupID}") @@ -80,23 +86,14 @@ public class SpringConfigVk { } catch (ClientException e) { e.printStackTrace(); } -// System.out.println("server: "+getLongPollServerResponse); return getLongPollServerResponse; } - @Bean - public UserService userService() { - return new UserServiceImpl(); - } @Bean - public ResponseDataVk responseDataVk() { - return new ResponseDataVk(); + public TaskExecutor taskExecutor() { + return new ConcurrentTaskExecutor(Executors.newFixedThreadPool(5)); } - @Bean - public TestLogic testLogic() { - return new TestLogic(responseDataVk()); - } - + } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java new file mode 100644 index 0000000..de506c8 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java @@ -0,0 +1,17 @@ +package org.sadtech.vkbot.config; + +import org.sadtech.vkbot.listener.EventListenable; +import org.sadtech.vkbot.listener.Observable; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + + +public class TestMain { + public static void main(String[] args) throws Exception { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class); + context.register(DataConfig.class); + EventListenable eventListener = context.getBean(EventListenable.class); + eventListener.listen(); + Observable dispetcherHandler = context.getBean(Observable.class); + dispetcherHandler.packaging(); + } +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java index 4670ac2..d13c088 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/WebConfig.java @@ -1,27 +1,32 @@ -package org.sadtech.vkbot.config; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.WebApplicationInitializer; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.servlet.DispatcherServlet; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; - -@Configuration -@ComponentScan("org.sadtech.vkbot.listener") -public class WebConfig implements WebApplicationInitializer { - - @Override - public void onStartup(ServletContext servletContext) throws ServletException { - AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - context.register(SpringConfigVk.class, WebConfig.class, DataConfig.class); - context.setServletContext(servletContext); - - ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); - dispatcher.setLoadOnStartup(1); - dispatcher.addMapping("/"); - } -} +//package org.sadtech.vkbot.config; +// +//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 org.springframework.context.annotation.ComponentScan; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.web.WebApplicationInitializer; +//import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +//import org.springframework.web.servlet.DispatcherServlet; +// +//import javax.servlet.ServletContext; +//import javax.servlet.ServletException; +// +//@Configuration +//public class WebConfig implements WebApplicationInitializer { +// +// @Override +// public void onStartup(ServletContext servletContext) throws ServletException { +// AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); +// context.register(SpringConfigVk.class, DataConfig.class, WebConfig.class); +// +//// context.setServletContext(servletContext); +//// +//// +//// ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); +//// dispatcher.setLoadOnStartup(1); +//// dispatcher.addMapping("/"); +// } +//} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java index 0faccd8..5af0eb1 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenable.java @@ -1,6 +1,5 @@ package org.sadtech.vkbot.listener; -public interface EventListenable -{ +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/listener/Observable.java new file mode 100644 index 0000000..fc0d341 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observable.java @@ -0,0 +1,10 @@ +package org.sadtech.vkbot.listener; + +public interface Observable { + void registerObserver(Observer o); + + // void removeObserver(Observer o); + void notifyObservers(); + + void packaging() throws Exception; +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/Observer.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java similarity index 79% rename from vk-bot/src/main/java/org/sadtech/vkbot/Observer.java rename to vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java index 8cca6ce..7c27ddf 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/Observer.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/Observer.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot; +package org.sadtech.vkbot.listener; import com.google.gson.JsonObject; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java new file mode 100644 index 0000000..4ef3475 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java @@ -0,0 +1,17 @@ +package org.sadtech.vkbot.listener.data; + +import com.google.gson.JsonObject; + +import java.util.List; + +public interface ResponsibleData { + + void add(JsonObject jsonObject); + + void remove(int id); + + void cleanAll(); + + List getJsonObjects(); + +} 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 new file mode 100644 index 0000000..6fca8a2 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/impl/ResponseDataVk.java @@ -0,0 +1,33 @@ +package org.sadtech.vkbot.listener.data.impl; + +import com.google.gson.JsonObject; +import org.sadtech.vkbot.listener.data.ResponsibleData; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class ResponseDataVk implements ResponsibleData { + + private List jsonObjects = new ArrayList(); + + @Override + public void add(JsonObject jsonObject) { + jsonObjects.add(jsonObject); + } + + @Override + public void remove(int id) { + jsonObjects.remove(id); + } + + @Override + public void cleanAll() { + jsonObjects.clear(); + } + + public List getJsonObjects() { + return 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/DispetcherHandler.java new file mode 100644 index 0000000..f47bfbf --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java @@ -0,0 +1,48 @@ +package org.sadtech.vkbot.listener.handlers; + +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.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Log4j +@Component +public class DispetcherHandler implements Observable { + + private ResponsibleData date; + private List observers = new ArrayList(); + private List objects; + + public DispetcherHandler(ResponsibleData date) { + this.date = date; + } + + @Scheduled(fixedRate = 5000) + public void packaging() { + + objects = new ArrayList(date.getJsonObjects()); + date.cleanAll(); + for (JsonObject object : objects) { + System.out.println(object); + } + + } + + @Override + public void registerObserver(Observer o) { + observers.add(o); + } + + @Override + public void notifyObservers() { + for (Observer observer : observers) { + //observer.update(); + } + } +} 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 new file mode 100644 index 0000000..8efc101 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/MessageHandlerVk.java @@ -0,0 +1,21 @@ +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/EventListenerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java similarity index 75% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenerVk.java rename to vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java index 00aadb0..6f6c413 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/EventListenerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.listener; +package org.sadtech.vkbot.listener.impl; import com.vk.api.sdk.actions.LongPoll; import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; @@ -9,15 +9,14 @@ 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.ResponsibleData; +import org.sadtech.vkbot.listener.EventListenable; +import org.sadtech.vkbot.listener.data.ResponsibleData; import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Service; - -import javax.annotation.PostConstruct; +import org.springframework.stereotype.Component; @Log4j -@Service -public class EventListenerVk implements EventListenable, Runnable { +@Component +public class EventListenerVk implements EventListenable { private VkApiClient vk; private GroupActor actor; @@ -34,41 +33,28 @@ public class EventListenerVk implements EventListenable, Runnable { longPoll = new LongPoll(vk); } - public void run() { - try { - listen(); - } catch (ClientException e) { - e.printStackTrace(); - } catch (ApiException e) { - e.printStackTrace(); - } - } - private void initServer() throws ClientException, ApiException { server = vk.groups().getLongPollServer(actor).execute(); String key = server.getKey(); String serverUrl = server.getServer(); Integer ts = server.getTs(); - longPoll = new LongPoll(vk); longPollEventsQuery = longPoll.getEvents(serverUrl, key, ts).waitTime(20); } @Async - @PostConstruct public void listen() throws ClientException, ApiException { initServer(); do { GetLongPollEventsResponse eventsResponse; eventsResponse = longPollEventsQuery.execute(); + log.info(eventsResponse); if (eventsResponse.getUpdates().toArray().length != 0) { - - //responseData.setJsonObjects(eventsResponse.getUpdates()); - log.info(eventsResponse.getUpdates()); + responseData.add(eventsResponse.getUpdates().get(0)); +// log.info(eventsResponse.getUpdates()); } longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20); } while (true); } - } From edebc5c4faada8b5dfedef9ff4450c3d27c86007 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sun, 30 Dec 2018 23:17:08 +0300 Subject: [PATCH 08/29] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8E=20vk-api=20snapsh?= =?UTF-8?q?ot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vk-bot/pom.xml | 22 ++++++++++++------- .../java/org/sadtech/vkbot/VkOpenMethod.java | 3 +++ .../sadtech/vkbot/config/SpringConfigVk.java | 4 ---- .../org/sadtech/vkbot/config/TestMain.java | 7 +++++- .../listener/handlers/DispetcherHandler.java | 2 +- .../vkbot/listener/impl/EventListenerVk.java | 17 +++++++++++--- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml index 8139c8a..cf57bdb 100644 --- a/vk-bot/pom.xml +++ b/vk-bot/pom.xml @@ -12,7 +12,6 @@ vk-bot 0.1-SNAPSHOT - war @@ -35,7 +34,7 @@ - 0.5.12 + 0.5.13-SNAPSHOT 5.1.3.RELEASE 5.1.3.RELEASE @@ -64,6 +63,12 @@ + + com.vk.api + sdk + ${vk.api.ver} + + org.projectlombok lombok @@ -76,12 +81,6 @@ ${log4j} - - com.vk.api - sdk - ${vk.api.ver} - - org.springframework spring-core @@ -119,6 +118,12 @@ ${javax.servlet} + + com.google.code.gson + gson + 2.8.5 + + org.mortbay.jetty jetty-util @@ -153,5 +158,6 @@ ${hibernate.core} + \ No newline at end of file diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java index d26c51b..6308980 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java @@ -17,5 +17,8 @@ public class VkOpenMethod { this.actor = actor; } + public void sendMessage(Integer id, String text) { + vk.messages().send(actor).userId(id).peerId(id).message(text); + } } 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 8519254..35ee625 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 @@ -8,10 +8,6 @@ import com.vk.api.sdk.exceptions.ApiException; 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.sadtech.vkbot.listener.data.impl.ResponseDataVk; -import org.sadtech.vkbot.listener.impl.EventListenerVk; -import org.sadtech.vkbot.service.UserService; -import org.sadtech.vkbot.service.impl.UserServiceImpl; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java index de506c8..a741b01 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java @@ -1,17 +1,22 @@ package org.sadtech.vkbot.config; +import lombok.extern.log4j.Log4j; import org.sadtech.vkbot.listener.EventListenable; import org.sadtech.vkbot.listener.Observable; import org.springframework.context.annotation.AnnotationConfigApplicationContext; - +@Log4j public class TestMain { public static void main(String[] args) throws Exception { + log.info("\n\n\n\n=== Запуск прогарммы ===\n\n"); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class); context.register(DataConfig.class); EventListenable eventListener = context.getBean(EventListenable.class); eventListener.listen(); Observable dispetcherHandler = context.getBean(Observable.class); dispetcherHandler.packaging(); + + log.info("\n\n=== Конец программы ===\n\n"); } } 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/DispetcherHandler.java index f47bfbf..c120a03 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/DispetcherHandler.java @@ -29,7 +29,7 @@ public class DispetcherHandler implements Observable { objects = new ArrayList(date.getJsonObjects()); date.cleanAll(); for (JsonObject object : objects) { - System.out.println(object); + log.info(object); } } 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 6f6c413..5010b4b 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 @@ -1,5 +1,7 @@ package org.sadtech.vkbot.listener.impl; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.vk.api.sdk.actions.LongPoll; import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; import com.vk.api.sdk.callback.longpoll.responses.GetLongPollEventsResponse; @@ -8,9 +10,12 @@ import com.vk.api.sdk.client.actors.GroupActor; import com.vk.api.sdk.exceptions.ApiException; import com.vk.api.sdk.exceptions.ClientException; import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; +import jdk.nashorn.internal.parser.JSONParser; import lombok.extern.log4j.Log4j; +import org.json.JSONObject; import org.sadtech.vkbot.listener.EventListenable; import org.sadtech.vkbot.listener.data.ResponsibleData; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -43,18 +48,24 @@ public class EventListenerVk implements EventListenable { } @Async - public void listen() throws ClientException, ApiException { + public void listen() throws Exception { initServer(); do { GetLongPollEventsResponse eventsResponse; eventsResponse = longPollEventsQuery.execute(); - log.info(eventsResponse); if (eventsResponse.getUpdates().toArray().length != 0) { responseData.add(eventsResponse.getUpdates().get(0)); -// log.info(eventsResponse.getUpdates()); + 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\"}]]}"; + vk.messages().send(actor).peerId(244319573).keyboard(test).message("Сообщение получено").execute(); + + + } longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20); } while (true); } + + } From 58d2e7d3bc95027a75ad5c33d884ad1c50848dd4 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 31 Dec 2018 01:12:25 +0300 Subject: [PATCH 09/29] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20ArrayList=20=D0=BD=D0=B0=20=D0=BF=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=BA=D0=BE=D0=B1=D0=B5=D0=B7=D0=BE=D0=BF=D0=B0=D1=81=D0=BD?= =?UTF-8?q?=D1=83=D1=8E=20Queue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Заменил ArrayList собираемых данных с poll сервера на потокобезопасную Queue, что позволило запустить паралельно с слушателем событий обработчик событий, при этом не теряя сообщения --- .../vkbot/listener/data/ResponsibleData.java | 4 ++-- .../vkbot/listener/data/impl/ResponseDataVk.java | 10 +++++----- .../vkbot/listener/handlers/DispetcherHandler.java | 14 ++++++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java index 4ef3475..1c10736 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/data/ResponsibleData.java @@ -2,7 +2,7 @@ package org.sadtech.vkbot.listener.data; import com.google.gson.JsonObject; -import java.util.List; +import java.util.Queue; public interface ResponsibleData { @@ -12,6 +12,6 @@ public interface ResponsibleData { void cleanAll(); - List getJsonObjects(); + Queue getJsonObjects(); } 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 6fca8a2..1630991 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 @@ -4,17 +4,17 @@ import com.google.gson.JsonObject; import org.sadtech.vkbot.listener.data.ResponsibleData; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.List; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; @Component public class ResponseDataVk implements ResponsibleData { - private List jsonObjects = new ArrayList(); + private Queue jsonObjects = new ConcurrentLinkedQueue(); @Override public void add(JsonObject jsonObject) { - jsonObjects.add(jsonObject); + jsonObjects.offer(jsonObject); } @Override @@ -27,7 +27,7 @@ public class ResponseDataVk implements ResponsibleData { jsonObjects.clear(); } - public List getJsonObjects() { + public Queue getJsonObjects() { return 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/DispetcherHandler.java index c120a03..a4f4a58 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/DispetcherHandler.java @@ -5,6 +5,7 @@ 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.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -17,21 +18,18 @@ public class DispetcherHandler implements Observable { private ResponsibleData date; private List observers = new ArrayList(); - private List objects; public DispetcherHandler(ResponsibleData date) { this.date = date; } - @Scheduled(fixedRate = 5000) + @Async public void packaging() { - - objects = new ArrayList(date.getJsonObjects()); - date.cleanAll(); - for (JsonObject object : objects) { - log.info(object); + while (true) { + if (date.getJsonObjects().peek() != null) { + log.info(date.getJsonObjects().poll()); + } } - } @Override From da8b5cba1198e0e155df8490d3f305bbb4e04cd1 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 31 Dec 2018 12:35:16 +0300 Subject: [PATCH 10/29] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D1=81=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B9=20=D0=B8=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84?= =?UTF-8?q?=D0=B0=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); - } -} From 30f4c09bbd39062eb68b9b4c4dda7169644f447f Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 5 Jan 2019 00:45:57 +0300 Subject: [PATCH 11/29] =?UTF-8?q?*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20ENUM=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=B8=D0=BA=D0=B0=20=D1=81=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B=D1=82=D0=B8=D1=8F=20*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BA=D0=B0=D1=81=D1=82=D0=BE=D0=BC=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20SQL=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D1=8E=D1=89=D0=B8?= =?UTF-8?q?=D0=B9=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B8=D0=B7=20=D0=91=D0=94=20=D0=BD=D0=BE=D0=B2=D0=B5=D0=B5?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=88=D0=B5=D0=BD=D0=BE=D0=B9?= =?UTF-8?q?=20=D0=B4=D0=B0=D1=82=D1=8B=20*=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B3=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B8=D0=BA=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20*=20=D0=98=D1=81=D1=80=D0=BF=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3?= =?UTF-8?q?=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20spring,=20=D0=BA=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D1=8B=D0=B5=20=D0=BF=D1=80=D0=B8=D0=B2=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D0=BB=D0=B8=20=D0=BA=20=D0=BE=D1=88=D0=B8=D0=B1?= =?UTF-8?q?=D0=BA=D0=B0=D0=BC=20=D0=B2=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8=20=D0=B1=D0=B8=D0=BD=D0=BE=D0=B2=20*=20?= =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=20=D1=81=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=D0=BC=D0=B8=20=D0=B2=D0=BA=20=D0=B0=D0=BF=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 17 +++++++ .../entity/{Message.java => Messages.java} | 10 ++-- .../database/entity/SocialNetworks.java | 17 ------- .../database/entity/SourceMessage.java | 5 ++ .../consultant/database/entity/User.java | 8 ++-- .../repository/MessageRepository.java | 12 ++++- ...positoriy.java => NextUnitRepository.java} | 3 +- .../repository/SocialNetworksRepositoriy.java | 7 --- .../database/service/MessageService.java | 8 +++- .../service/SocialNetworksService.java | 4 -- .../service/impl/MessageServiceImpl.java | 11 ++++- .../service/impl/NextUnitServiceImpl.java | 4 +- .../impl/SocialNetworksServiceImpl.java | 14 ------ .../consultant/processing/MessageHandler.java | 40 ++++++++++++++++ vk-bot/pom.xml | 12 +---- .../src/main/java/org/sadtech/vkbot/Main.java | 9 ++-- .../main/java/org/sadtech/vkbot/VkApi.java | 47 +++++++++++++++++++ .../java/org/sadtech/vkbot/VkOpenMethod.java | 24 ---------- .../org/sadtech/vkbot/config/DataConfig.java | 5 +- .../sadtech/vkbot/config/SpringConfigVk.java | 10 ++-- .../{listener => }/handlers/Handled.java | 2 +- .../handlers/impl/DispetcherHandlerVk.java | 4 +- .../vkbot/handlers/impl/MessageHandlerVk.java | 46 ++++++++++++++++++ .../handlers/impl/MessageHandlerVk.java | 39 --------------- .../vkbot/listener/impl/EventListenerVk.java | 10 ++-- 25 files changed, 214 insertions(+), 154 deletions(-) rename core/src/main/java/org/sadtech/consultant/database/entity/{Message.java => Messages.java} (56%) delete mode 100644 core/src/main/java/org/sadtech/consultant/database/entity/SocialNetworks.java create mode 100644 core/src/main/java/org/sadtech/consultant/database/entity/SourceMessage.java rename core/src/main/java/org/sadtech/consultant/database/repository/{NextUnitRepositoriy.java => NextUnitRepository.java} (69%) delete mode 100644 core/src/main/java/org/sadtech/consultant/database/repository/SocialNetworksRepositoriy.java delete mode 100644 core/src/main/java/org/sadtech/consultant/database/service/SocialNetworksService.java delete mode 100644 core/src/main/java/org/sadtech/consultant/database/service/impl/SocialNetworksServiceImpl.java create mode 100644 core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java rename vk-bot/src/main/java/org/sadtech/vkbot/{listener => }/handlers/Handled.java (61%) rename vk-bot/src/main/java/org/sadtech/vkbot/{listener => }/handlers/impl/DispetcherHandlerVk.java (91%) create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/MessageHandlerVk.java diff --git a/core/pom.xml b/core/pom.xml index 5e55758..4a34740 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -10,6 +10,18 @@ 4.0.0 consultant-core + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + 1.0.2 @@ -43,6 +55,11 @@ spring-data-jpa ${spring.data} + + javax.persistence + javax.persistence-api + 2.2 + \ No newline at end of file diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Message.java b/core/src/main/java/org/sadtech/consultant/database/entity/Messages.java similarity index 56% rename from core/src/main/java/org/sadtech/consultant/database/entity/Message.java rename to core/src/main/java/org/sadtech/consultant/database/entity/Messages.java index e729d25..f752173 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/Message.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Messages.java @@ -2,20 +2,20 @@ package org.sadtech.consultant.database.entity; import lombok.Data; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; +import javax.persistence.*; @Data @Entity -public class Message { +public class Messages { @Id @GeneratedValue private Long idMess; private Long idUser; private String text; - private String date; + private Long date; + @Enumerated(EnumType.STRING) + private SourceMessage source; } diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/SocialNetworks.java b/core/src/main/java/org/sadtech/consultant/database/entity/SocialNetworks.java deleted file mode 100644 index d3c78a4..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/entity/SocialNetworks.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.sadtech.consultant.database.entity; - -import lombok.Data; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Data -@Entity -public class SocialNetworks { - - @Id - private Long id; - private Long idVk; - private Long idFacebook; - -} diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/SourceMessage.java b/core/src/main/java/org/sadtech/consultant/database/entity/SourceMessage.java new file mode 100644 index 0000000..df6497a --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/entity/SourceMessage.java @@ -0,0 +1,5 @@ +package org.sadtech.consultant.database.entity; + +public enum SourceMessage { + VK, FACEBOOK; +} diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/User.java b/core/src/main/java/org/sadtech/consultant/database/entity/User.java index 10271c7..17267fa 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/User.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/User.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.*; import java.util.List; @Entity @@ -16,7 +15,10 @@ public class User { private String token; private String lastName; private String city; -// private List socialNetworks; + + @ElementCollection + @CollectionTable(name="SocialNetworks", joinColumns=@JoinColumn(name="id")) + private List socialNetworks; } diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java b/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java index 51d73ed..cedfccb 100644 --- a/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java @@ -1,8 +1,16 @@ package org.sadtech.consultant.database.repository; -import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.entity.Messages; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; -public interface MessageRepository extends JpaRepository { +import java.util.Collection; +import java.util.List; + +public interface MessageRepository extends JpaRepository { + + @Query("SELECT u FROM Messages u WHERE u.date > :date") + Collection getMessagesByRange(@Param("date") Long date); } diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepositoriy.java b/core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java similarity index 69% rename from core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepositoriy.java rename to core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java index eff732b..3f3f71f 100644 --- a/core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepositoriy.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java @@ -3,8 +3,7 @@ package org.sadtech.consultant.database.repository; import org.sadtech.consultant.database.entity.NextUnit; import org.springframework.data.jpa.repository.JpaRepository; -public interface NextUnitRepositoriy extends JpaRepository { - +public interface NextUnitRepository extends JpaRepository { } diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/SocialNetworksRepositoriy.java b/core/src/main/java/org/sadtech/consultant/database/repository/SocialNetworksRepositoriy.java deleted file mode 100644 index 7c606ae..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/repository/SocialNetworksRepositoriy.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.consultant.database.repository; - -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/database/service/MessageService.java b/core/src/main/java/org/sadtech/consultant/database/service/MessageService.java index c4edb28..9aa136e 100644 --- a/core/src/main/java/org/sadtech/consultant/database/service/MessageService.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/MessageService.java @@ -1,8 +1,12 @@ package org.sadtech.consultant.database.service; -import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.entity.Messages; + +import java.util.List; public interface MessageService { - void addMessage(Message message); + void addMessage(Messages message); + + List getMessageRange(Long date); } 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 deleted file mode 100644 index 83d12da..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/service/SocialNetworksService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.consultant.database.service; - -public interface SocialNetworksService { -} 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 index 2171cda..23f6d65 100644 --- 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 @@ -1,18 +1,25 @@ package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.entity.Messages; 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) { + public void addMessage(Messages 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/NextUnitServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java index 282c162..1e93a0f 100644 --- a/core/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java @@ -1,6 +1,6 @@ package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.database.repository.NextUnitRepositoriy; +import org.sadtech.consultant.database.repository.NextUnitRepository; import org.sadtech.consultant.database.service.NextUnitService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -9,6 +9,6 @@ import org.springframework.stereotype.Service; public class NextUnitServiceImpl implements NextUnitService { @Autowired - private NextUnitRepositoriy repositoriy; + private NextUnitRepository repository; } diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/SocialNetworksServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/SocialNetworksServiceImpl.java deleted file mode 100644 index b1b8c05..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/service/impl/SocialNetworksServiceImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sadtech.consultant.database.service.impl; - -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; - -@Service -public class SocialNetworksServiceImpl implements SocialNetworksService { - - @Autowired - private SocialNetworksRepositoriy repositoriy; - -} diff --git a/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java b/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java new file mode 100644 index 0000000..fdd84a8 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java @@ -0,0 +1,40 @@ +package org.sadtech.consultant.processing; + +import lombok.extern.log4j.Log4j; +import org.sadtech.consultant.database.entity.Messages; +import org.sadtech.consultant.database.service.MessageService; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.List; + +@Log4j +@Component +public class MessageHandler { + + private MessageService service; + private long data; + + public MessageHandler(MessageService service) { + this.service = service; + data = new Date().getTime() / 1000; + } + + @Async + public void processing() { + while (true) { + List messages = service.getMessageRange(data); + for (Messages message : messages) { + System.out.println(message); + data = message.getDate(); + } + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml index 939a596..e3617b7 100644 --- a/vk-bot/pom.xml +++ b/vk-bot/pom.xml @@ -82,9 +82,6 @@ - - - org.springframework spring-core @@ -121,12 +118,6 @@ 5.1.3.RELEASE - - javax.servlet - javax.servlet-api - ${javax.servlet} - - com.google.code.gson gson @@ -154,14 +145,12 @@ mysql mysql-connector-java ${mysql.connector} - runtime org.hibernate hibernate-entitymanager ${hibernate.entitymanager} - runtime org.hibernate @@ -174,6 +163,7 @@ slf4j-nop 1.7.13 + org.sadtech consultant-core diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java index 012ceb4..69f7e42 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java @@ -1,14 +1,15 @@ package org.sadtech.vkbot; import lombok.extern.log4j.Log4j; -import org.sadtech.vkbot.config.DataConfig; +import org.sadtech.consultant.processing.MessageHandler; import org.sadtech.vkbot.config.SpringConfigVk; import org.sadtech.vkbot.listener.EventListenable; -import org.sadtech.vkbot.listener.handlers.Handled; +import org.sadtech.vkbot.handlers.Handled; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @Log4j public class Main { + public static void main(String[] args) throws Exception { Main main = new Main(); main.run(); @@ -17,11 +18,13 @@ public class Main { public void run() throws Exception { log.info("\n\n\n\n=== Запуск прогарммы ===\n\n"); - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class, DataConfig.class); + 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(); log.info("\n\n=== Конец программы ===\n\n"); } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java b/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java new file mode 100644 index 0000000..659b304 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java @@ -0,0 +1,47 @@ +package org.sadtech.vkbot; + +import com.google.gson.Gson; +import com.vk.api.sdk.client.VkApiClient; +import com.vk.api.sdk.client.actors.GroupActor; +import com.vk.api.sdk.exceptions.ApiException; +import com.vk.api.sdk.exceptions.ClientException; +import com.vk.api.sdk.objects.users.User; +import com.vk.api.sdk.objects.users.UserFull; +import com.vk.api.sdk.objects.users.UserXtrCounters; +import lombok.extern.log4j.Log4j; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Log4j +@Component +public class VkApi { + + private static VkApiClient vk; + private static GroupActor actor; + + public VkApi(VkApiClient vk, GroupActor actor) { + this.vk = vk; + this.actor = actor; + } + + public static void sendMessage(Integer id, String text) { + try { + vk.messages().send(actor).userId(id).message(text).execute(); + } catch (ApiException | ClientException e) { + e.printStackTrace(); + } + } + + public static String getUserName(Integer id) { + List user = null; + UserFull userFull = null; + try { + user = vk.users().get(actor).userIds(String.valueOf(id)).execute(); + } catch (ApiException | ClientException e) { + e.printStackTrace(); + } + return user.get(0).getLastName() + " " + user.get(0).getFirstName(); + } + +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java deleted file mode 100644 index 6308980..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.sadtech.vkbot; - -import com.vk.api.sdk.client.VkApiClient; -import com.vk.api.sdk.client.actors.GroupActor; -import lombok.extern.log4j.Log4j; -import org.springframework.stereotype.Component; - -@Log4j -@Component -public class VkOpenMethod { - - private VkApiClient vk; - private GroupActor actor; - - public VkOpenMethod(VkApiClient vk, GroupActor actor) { - this.vk = vk; - this.actor = actor; - } - - public void sendMessage(Integer id, String text) { - vk.messages().send(actor).userId(id).peerId(id).message(text); - } - -} 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 4a93c53..3069b6a 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 @@ -3,7 +3,9 @@ package org.sadtech.vkbot.config; import org.hibernate.jpa.HibernatePersistenceProvider; 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.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; @@ -14,7 +16,8 @@ import java.util.Properties; @Configuration @EnableTransactionManagement - +@ComponentScan("org.sadtech.consultant.database.service") +@EnableJpaRepositories("org.sadtech.consultant.database.repository") public class DataConfig { @Value("${db.driver}") 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 f1f06b4..231aa60 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 @@ -12,7 +12,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.*; import org.springframework.core.task.TaskExecutor; import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; import java.util.concurrent.Executors; @@ -20,9 +19,10 @@ import java.util.concurrent.Executors; @Configuration @EnableAsync -@Import({DataConfig.class}) @PropertySource("classpath:config.properties") -@ComponentScan("org.sadtech.vkbot.listener") +@Import({DataConfig.class}) +@ComponentScan({"org.sadtech.vkbot", "org.sadtech.consultant.processing"}) + public class SpringConfigVk { @Value("${vk.groupID}") @@ -74,9 +74,7 @@ public class SpringConfigVk { GetLongPollServerResponse getLongPollServerResponse = null; try { getLongPollServerResponse = vkApiClient().groups().getLongPollServer(groupActor()).execute(); - } catch (ApiException e) { - e.printStackTrace(); - } catch (ClientException e) { + } catch (ApiException | ClientException e) { e.printStackTrace(); } return getLongPollServerResponse; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/Handled.java b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/Handled.java similarity index 61% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/Handled.java rename to vk-bot/src/main/java/org/sadtech/vkbot/handlers/Handled.java index 7a5513f..f82c1b6 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/Handled.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/Handled.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.listener.handlers; +package org.sadtech.vkbot.handlers; public interface Handled { diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/DispetcherHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/DispetcherHandlerVk.java similarity index 91% rename from vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/DispetcherHandlerVk.java rename to vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/DispetcherHandlerVk.java index ba1c642..03908b5 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/DispetcherHandlerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/DispetcherHandlerVk.java @@ -1,11 +1,11 @@ -package org.sadtech.vkbot.listener.handlers.impl; +package org.sadtech.vkbot.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.listener.handlers.Handled; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java new file mode 100644 index 0000000..dfb6e5d --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java @@ -0,0 +1,46 @@ +package org.sadtech.vkbot.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.entity.Messages; +import org.sadtech.consultant.database.entity.SourceMessage; +import org.sadtech.consultant.database.service.MessageService; +import org.sadtech.vkbot.VkApi; +import org.sadtech.vkbot.listener.Observable; +import org.sadtech.vkbot.listener.Observer; +import org.springframework.stereotype.Component; + +@Log4j +@Component + +public class MessageHandlerVk implements Observer { + + private MessageService service; + + public MessageHandlerVk(Observable dispetcherHandler, MessageService messageService) { + this.service = messageService; + 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 userMessage) { + log.info(userMessage.getBody()); + Messages message = new Messages(); + message.setIdUser(Long.valueOf(userMessage.getUserId())); + message.setText(userMessage.getBody()); + message.setDate(Long.valueOf(userMessage.getDate())); + message.setSource(SourceMessage.VK); + VkApi.sendMessage(userMessage.getUserId(), "Здравствуйте, " + VkApi.getUserName(userMessage.getUserId()) + "!\nВаше сообщение получено!\n"); + service.addMessage(message); + } +} 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 deleted file mode 100644 index 79d0881..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/impl/MessageHandlerVk.java +++ /dev/null @@ -1,39 +0,0 @@ -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 2261bf1..3c2cfa5 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 @@ -1,7 +1,5 @@ package org.sadtech.vkbot.listener.impl; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import com.vk.api.sdk.actions.LongPoll; import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; import com.vk.api.sdk.callback.longpoll.responses.GetLongPollEventsResponse; @@ -10,15 +8,15 @@ import com.vk.api.sdk.client.actors.GroupActor; import com.vk.api.sdk.exceptions.ApiException; import com.vk.api.sdk.exceptions.ClientException; import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; -import jdk.nashorn.internal.parser.JSONParser; import lombok.extern.log4j.Log4j; -import org.json.JSONObject; +import org.sadtech.vkbot.VkApi; import org.sadtech.vkbot.listener.EventListenable; import org.sadtech.vkbot.listener.data.ResponsibleData; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import java.util.Date; + @Log4j @Component public class EventListenerVk implements EventListenable { @@ -57,8 +55,6 @@ public class EventListenerVk implements EventListenable { 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\"}]]}"; - vk.messages().send(actor).peerId(244319573).keyboard(test).message("Сообщение получено").execute(); - } longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20); } while (true); From 5177fee3911f70616670d2809b00538d22f968d5 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Tue, 8 Jan 2019 23:39:00 +0300 Subject: [PATCH 12/29] =?UTF-8?q?=D0=90=D1=80=D1=85=D0=B8=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D1=83=D1=80=D0=BD=D1=8B=D0=B5=20=D1=80=D0=B5=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Добавлен новый слой логики приложения. Модуль обращается к этому слою, и только этот слой может обращаться к БД * Начал связывать таблицы * Переместил классы --- .../entity/{Messages.java => Message.java} | 10 +++-- .../consultant/database/entity/NextUnit.java | 1 + .../consultant/database/entity/Person.java | 33 ++++++++++++++ .../consultant/database/entity/SaveUnit.java | 1 + .../database/entity/SourceMessage.java | 5 --- .../consultant/database/entity/Unit.java | 1 + .../consultant/database/entity/User.java | 24 ---------- .../repository/MessageRepository.java | 9 ++-- .../database/repository/PersonRepository.java | 13 ++++++ .../database/repository/UserRepositoriy.java | 8 ---- .../database/service/MessageService.java | 6 +-- .../database/service/PersonService.java | 14 ++++++ .../database/service/UserService.java | 10 ----- .../service/impl/MessageServiceImpl.java | 8 ++-- .../service/impl/PersonServiceImpl.java | 41 +++++++++++++++++ .../service/impl/UserServiceImpl.java | 22 ---------- .../consultant/processing/MessageHandler.java | 22 +++++----- .../processing/MessageLogicService.java | 25 +++++++++++ .../processing/PersonLogicService.java | 29 ++++++++++++ .../src/main/java/org/sadtech/vkbot/Main.java | 4 +- .../java/org/sadtech/vkbot/SourceMessage.java | 5 +++ .../vkbot/handlers/impl/MessageHandlerVk.java | 44 ++++++++++++------- 22 files changed, 219 insertions(+), 116 deletions(-) rename core/src/main/java/org/sadtech/consultant/database/entity/{Messages.java => Message.java} (59%) create mode 100644 core/src/main/java/org/sadtech/consultant/database/entity/Person.java delete mode 100644 core/src/main/java/org/sadtech/consultant/database/entity/SourceMessage.java delete mode 100644 core/src/main/java/org/sadtech/consultant/database/entity/User.java create mode 100644 core/src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java delete mode 100644 core/src/main/java/org/sadtech/consultant/database/repository/UserRepositoriy.java create mode 100644 core/src/main/java/org/sadtech/consultant/database/service/PersonService.java delete 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/PersonServiceImpl.java delete mode 100644 core/src/main/java/org/sadtech/consultant/database/service/impl/UserServiceImpl.java create mode 100644 core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java create mode 100644 core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Messages.java b/core/src/main/java/org/sadtech/consultant/database/entity/Message.java similarity index 59% rename from core/src/main/java/org/sadtech/consultant/database/entity/Messages.java rename to core/src/main/java/org/sadtech/consultant/database/entity/Message.java index f752173..b1d0ff3 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/Messages.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Message.java @@ -6,16 +6,18 @@ import javax.persistence.*; @Data @Entity -public class Messages { +public class Message { @Id @GeneratedValue private Long idMess; - private Long idUser; private String text; private Long date; - @Enumerated(EnumType.STRING) - private SourceMessage source; + private String sourceMessage; + + @ManyToOne + @JoinColumn(name = "idUser", nullable = false) + private Person user; } diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java b/core/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java index 64281d3..5e896fe 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java @@ -4,6 +4,7 @@ import lombok.Data; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.Table; @Entity @Data 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 new file mode 100644 index 0000000..5a3e580 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Person.java @@ -0,0 +1,33 @@ +package org.sadtech.consultant.database.entity; + +import lombok.Data; + +import javax.persistence.*; +import java.util.HashMap; +import java.util.Map; + +@Entity +@Data +public class Person { + + @Id + @GeneratedValue + private Long id; + + @Column(length = 20) + private String name; + + @Column(length = 20) + private String lastName; + + @Column(length = 20) + private String city; + + private String token; + + @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..68c696c 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 @@ -4,6 +4,7 @@ import lombok.Data; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.Table; @Entity @Data diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/SourceMessage.java b/core/src/main/java/org/sadtech/consultant/database/entity/SourceMessage.java deleted file mode 100644 index df6497a..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/entity/SourceMessage.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.sadtech.consultant.database.entity; - -public enum SourceMessage { - VK, FACEBOOK; -} diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java b/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java index a267686..247df8b 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java @@ -4,6 +4,7 @@ import lombok.Data; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.Table; @Entity @Data diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/User.java b/core/src/main/java/org/sadtech/consultant/database/entity/User.java deleted file mode 100644 index 17267fa..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/entity/User.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.sadtech.consultant.database.entity; - -import lombok.Data; - -import javax.persistence.*; -import java.util.List; - -@Entity -@Data -public class User { - - @Id - private Long id; - private String name; - private String token; - private String lastName; - private String city; - - @ElementCollection - @CollectionTable(name="SocialNetworks", joinColumns=@JoinColumn(name="id")) - private List socialNetworks; - - -} diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java b/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java index cedfccb..8dfc122 100644 --- a/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java +++ b/core/src/main/java/org/sadtech/consultant/database/repository/MessageRepository.java @@ -1,16 +1,15 @@ package org.sadtech.consultant.database.repository; -import org.sadtech.consultant.database.entity.Messages; +import org.sadtech.consultant.database.entity.Message; 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; -import java.util.List; -public interface MessageRepository extends JpaRepository { +public interface MessageRepository extends JpaRepository { - @Query("SELECT u FROM Messages u WHERE u.date > :date") - Collection getMessagesByRange(@Param("date") Long date); + @Query("SELECT u FROM Message u WHERE u.date > :date") + Collection getMessagesByRange(@Param("date") Long date); } diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java b/core/src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java new file mode 100644 index 0000000..a00fa83 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java @@ -0,0 +1,13 @@ +package org.sadtech.consultant.database.repository; + +import org.sadtech.consultant.database.entity.Person; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface PersonRepository extends JpaRepository { + + @Query("SELECT u FROM Person u INNER JOIN u.socialNetworks p WHERE KEY(p) = :type2 AND VALUE(p) = :socialId") + Person getUserBySocialNetworksId(@Param("type2") String type, @Param("socialId") Integer socialNetworksId); + +} diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/UserRepositoriy.java b/core/src/main/java/org/sadtech/consultant/database/repository/UserRepositoriy.java deleted file mode 100644 index f92f0d1..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/repository/UserRepositoriy.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.sadtech.consultant.database.repository; - -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 index 9aa136e..53e2d37 100644 --- a/core/src/main/java/org/sadtech/consultant/database/service/MessageService.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/MessageService.java @@ -1,12 +1,12 @@ package org.sadtech.consultant.database.service; -import org.sadtech.consultant.database.entity.Messages; +import org.sadtech.consultant.database.entity.Message; import java.util.List; public interface MessageService { - void addMessage(Messages message); + void addMessage(Message message); - List getMessageRange(Long date); + List getMessageRange(Long date); } diff --git a/core/src/main/java/org/sadtech/consultant/database/service/PersonService.java b/core/src/main/java/org/sadtech/consultant/database/service/PersonService.java new file mode 100644 index 0000000..db476ea --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/PersonService.java @@ -0,0 +1,14 @@ +package org.sadtech.consultant.database.service; + +import org.sadtech.consultant.database.entity.Person; + +import java.util.Map; + +public interface PersonService { + + void addUser(Person user); + void removeUser(Long id); + Person getUserByID(Long id); + Map getSocialNetwork(Long id); + Person getUserBySocialNetworksId(String type, Integer socialNetworksId); +} 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 deleted file mode 100644 index 3e81573..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/service/UserService.java +++ /dev/null @@ -1,10 +0,0 @@ -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 index 23f6d65..f5d967b 100644 --- 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 @@ -1,6 +1,6 @@ package org.sadtech.consultant.database.service.impl; -import org.sadtech.consultant.database.entity.Messages; +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; @@ -14,12 +14,12 @@ public class MessageServiceImpl implements MessageService { @Autowired private MessageRepository repository; - public void addMessage(Messages message) { + public void addMessage(Message message) { repository.saveAndFlush(message); } @Override - public List getMessageRange(Long date) { - return (List) repository.getMessagesByRange(date); + 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 new file mode 100644 index 0000000..7acd025 --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java @@ -0,0 +1,41 @@ +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.service.PersonService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Map; + +@Service +public class PersonServiceImpl implements PersonService { + + @Autowired + private PersonRepository repositoriy; + + @Override + public void addUser(Person user) { + repositoriy.saveAndFlush(user); + } + + @Override + public void removeUser(Long id) { + repositoriy.deleteById(id); + } + + @Override + public Person getUserByID(Long id) { + return repositoriy.getOne(id); + } + + @Override + public Map getSocialNetwork(Long id) { + return repositoriy.getOne(id).getSocialNetworks(); + } + + @Override + public Person getUserBySocialNetworksId(String type, Integer socialNetworksId) { + return repositoriy.getUserBySocialNetworksId(type, socialNetworksId); + } +} diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/UserServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/UserServiceImpl.java deleted file mode 100644 index fe6c606..0000000 --- a/core/src/main/java/org/sadtech/consultant/database/service/impl/UserServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sadtech.consultant.database.service.impl; - -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; - -@Service -public class UserServiceImpl implements UserService { - - @Autowired - private UserRepositoriy repositoriy; - - public void addUser(User user) { - //@TODO: Написть добавление профиля в бд - } - - public void removeUser(Long id) { - //@TODO: Написать удаление профиля из бд - } -} 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 fdd84a8..232b33e 100644 --- a/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java +++ b/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java @@ -1,8 +1,7 @@ package org.sadtech.consultant.processing; import lombok.extern.log4j.Log4j; -import org.sadtech.consultant.database.entity.Messages; -import org.sadtech.consultant.database.service.MessageService; +import org.sadtech.consultant.database.entity.Message; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -13,27 +12,26 @@ import java.util.List; @Component public class MessageHandler { - private MessageService service; + private MessageLogicService messageLogicService; + private PersonLogicService userLogicService; private long data; - public MessageHandler(MessageService service) { - this.service = service; + public MessageHandler(MessageLogicService messageLogicService, PersonLogicService userLogicService) { + this.messageLogicService = messageLogicService; + this.userLogicService = userLogicService; data = new Date().getTime() / 1000; } @Async public void processing() { while (true) { - List messages = service.getMessageRange(data); - for (Messages message : messages) { + List messages = messageLogicService.getMessageRange(data); + for (Message message : messages) { System.out.println(message); + + data = message.getDate(); } - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); - } } } diff --git a/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java b/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java new file mode 100644 index 0000000..1ed910a --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java @@ -0,0 +1,25 @@ +package org.sadtech.consultant.processing; + +import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.service.MessageService; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class MessageLogicService { + + private MessageService messageService; + + public MessageLogicService(MessageService messageService) { + this.messageService = messageService; + } + + public void addMessage(Message message) { + messageService.addMessage(message); + } + + public List getMessageRange(long data) { + return messageService.getMessageRange(data); + } +} diff --git a/core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java b/core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java new file mode 100644 index 0000000..28c672c --- /dev/null +++ b/core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java @@ -0,0 +1,29 @@ +package org.sadtech.consultant.processing; + +import org.sadtech.consultant.database.entity.Person; +import org.sadtech.consultant.database.service.PersonService; +import org.springframework.stereotype.Component; + +@Component +public class PersonLogicService { + + private PersonService personService; + + public PersonLogicService(PersonService userService) { + this.personService = userService; + } + + public boolean addUser(Person user) { + personService.addUser(user); + return true; + } + + public Person getUserById(Long id) { + return personService.getUserByID(id); + } + + public Person getUserBySocialId(String type, Integer id) { + return personService.getUserBySocialNetworksId(type, id); + } + +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java index 69f7e42..2f5d11e 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java @@ -23,8 +23,8 @@ public class Main { eventListener.listen(); Handled dispetcherHandler = context.getBean(Handled.class); dispetcherHandler.sortAndSend(); - MessageHandler messageHandler = context.getBean(MessageHandler.class); - messageHandler.processing(); +// MessageHandler messageHandler = context.getBean(MessageHandler.class); +// messageHandler.processing(); log.info("\n\n=== Конец программы ===\n\n"); } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java b/vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java new file mode 100644 index 0000000..aca1153 --- /dev/null +++ b/vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java @@ -0,0 +1,5 @@ +package org.sadtech.vkbot; + +public enum SourceMessage { + VK, FB +} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java index dfb6e5d..dd1aaa5 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java @@ -2,25 +2,26 @@ package org.sadtech.vkbot.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.entity.Messages; -import org.sadtech.consultant.database.entity.SourceMessage; -import org.sadtech.consultant.database.service.MessageService; -import org.sadtech.vkbot.VkApi; +import org.sadtech.consultant.database.entity.Person; +import org.sadtech.consultant.processing.MessageLogicService; +import org.sadtech.consultant.processing.PersonLogicService; +import org.sadtech.consultant.database.entity.Message; +import org.sadtech.vkbot.SourceMessage; import org.sadtech.vkbot.listener.Observable; import org.sadtech.vkbot.listener.Observer; import org.springframework.stereotype.Component; @Log4j @Component - public class MessageHandlerVk implements Observer { - private MessageService service; + private MessageLogicService messageLogicService; + private PersonLogicService userLogicService; - public MessageHandlerVk(Observable dispetcherHandler, MessageService messageService) { - this.service = messageService; + public MessageHandlerVk(Observable dispetcherHandler, PersonLogicService userLogicService, MessageLogicService messageLogicService) { + this.userLogicService = userLogicService; + this.messageLogicService = messageLogicService; dispetcherHandler.registerObserver(this); } @@ -28,19 +29,28 @@ public class MessageHandlerVk implements Observer { 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); + com.vk.api.sdk.objects.messages.Message message = gson.fromJson(object.getAsJsonObject("object"), com.vk.api.sdk.objects.messages.Message.class); + sendProcessing(message); } } - private void send(Message userMessage) { + private void sendProcessing(com.vk.api.sdk.objects.messages.Message userMessage) { log.info(userMessage.getBody()); - Messages message = new Messages(); - message.setIdUser(Long.valueOf(userMessage.getUserId())); + Message message = new Message(); +// Person user = userLogicService.getUserBySocialId(SourceMessage.VK.name(), Long.valueOf(userMessage.getUserId())); + Person user; + user = new Person(); + user.getSocialNetworks().put(SourceMessage.VK.name(), userMessage.getUserId()); + user.setName("Name"); + user.setLastName("LastName"); + user.setCity("City"); + userLogicService.addUser(user); + log.info(user); + message.setUser(user); message.setText(userMessage.getBody()); message.setDate(Long.valueOf(userMessage.getDate())); - message.setSource(SourceMessage.VK); - VkApi.sendMessage(userMessage.getUserId(), "Здравствуйте, " + VkApi.getUserName(userMessage.getUserId()) + "!\nВаше сообщение получено!\n"); - service.addMessage(message); + message.setSourceMessage(SourceMessage.VK.name()); + log.info(message); + messageLogicService.addMessage(message); } } From e88563b94e1e77bebc1daf226a1a68c8231dbfbd Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 9 Jan 2019 11:02:38 +0300 Subject: [PATCH 13/29] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D0=B8=D0=B5=20=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consultant/database/entity/Message.java | 1 + .../consultant/database/entity/Person.java | 6 ++- .../service/impl/MessageServiceImpl.java | 1 + .../consultant/processing/MessageHandler.java | 4 +- .../processing/MessageLogicService.java | 1 + .../processing/PersonLogicService.java | 27 +++++++++++- .../src/main/java/org/sadtech/vkbot/Main.java | 4 -- .../java/org/sadtech/vkbot/SourceMessage.java | 13 +++++- .../main/java/org/sadtech/vkbot/VkApi.java | 15 ++++--- .../vkbot/handlers/impl/MessageHandlerVk.java | 42 ++++++++++++------- 10 files changed, 82 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Message.java b/core/src/main/java/org/sadtech/consultant/database/entity/Message.java index b1d0ff3..69afff2 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/Message.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Message.java @@ -14,6 +14,7 @@ public class Message { private String text; private Long date; private String sourceMessage; + private String sex; @ManyToOne @JoinColumn(name = "idUser", nullable = false) 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 5a3e580..7ab5275 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 @@ -3,8 +3,7 @@ package org.sadtech.consultant.database.entity; import lombok.Data; import javax.persistence.*; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @Entity @Data @@ -30,4 +29,7 @@ public class Person { @MapKeyColumn(name="KeysSocialNetworks", length = 20) private Map socialNetworks = new HashMap<>(); +// @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="idMess") +// private List messages; + } 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 index f5d967b..284a997 100644 --- 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 @@ -5,6 +5,7 @@ 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 org.springframework.transaction.annotation.Transactional; import java.util.List; 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 232b33e..e486947 100644 --- a/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java +++ b/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java @@ -27,9 +27,7 @@ public class MessageHandler { while (true) { List messages = messageLogicService.getMessageRange(data); for (Message message : messages) { - System.out.println(message); - - + log.info(message); 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..7b37ba7 100644 --- a/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java +++ b/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java @@ -1,6 +1,7 @@ package org.sadtech.consultant.processing; import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.entity.Person; import org.sadtech.consultant.database.service.MessageService; import org.springframework.stereotype.Component; diff --git a/core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java b/core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java index 28c672c..4da66f7 100644 --- a/core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java +++ b/core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java @@ -1,9 +1,11 @@ package org.sadtech.consultant.processing; +import lombok.extern.log4j.Log4j; import org.sadtech.consultant.database.entity.Person; import org.sadtech.consultant.database.service.PersonService; import org.springframework.stereotype.Component; +@Log4j @Component public class PersonLogicService { @@ -13,9 +15,30 @@ public class PersonLogicService { this.personService = userService; } - public boolean addUser(Person user) { + public void addUser(Person user) { personService.addUser(user); - return true; + log.info("Пользователь добавлен в бд"); + } + + public boolean checkPersonBySocialNetworksId(String socType, Integer socId) { + Person checkPerson = personService.getUserBySocialNetworksId(socType, socId); + if (checkPerson != null) { + log.info("Пользователь уже есть в бд"); + return true; + } + log.info("Пользователя нет в бд"); + return false; + } + + public Person getPersonBySocialNetworksId(Person person) { + for (String key : person.getSocialNetworks().keySet()) { + Person getPerson = personService.getUserBySocialNetworksId(key, person.getSocialNetworks().get(key)); + if (getPerson != null) { + log.info("Пользователь уже есть в бд"); + return getPerson; + } + } + return null; } public Person getUserById(Long id) { diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java index 2f5d11e..801fc20 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java @@ -16,8 +16,6 @@ public class Main { } public void run() throws Exception { - log.info("\n\n\n\n=== Запуск прогарммы ===\n\n"); - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class); EventListenable eventListener = context.getBean(EventListenable.class); eventListener.listen(); @@ -25,7 +23,5 @@ public class Main { dispetcherHandler.sortAndSend(); // MessageHandler messageHandler = context.getBean(MessageHandler.class); // messageHandler.processing(); - - log.info("\n\n=== Конец программы ===\n\n"); } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java b/vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java index aca1153..d76fef1 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/SourceMessage.java @@ -1,5 +1,16 @@ package org.sadtech.vkbot; public enum SourceMessage { - VK, FB + VK("VK"), + FB("FB"); + + private final String value; + + private SourceMessage(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java b/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java index 659b304..960820b 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java @@ -6,12 +6,16 @@ import com.vk.api.sdk.client.actors.GroupActor; import com.vk.api.sdk.exceptions.ApiException; import com.vk.api.sdk.exceptions.ClientException; import com.vk.api.sdk.objects.users.User; -import com.vk.api.sdk.objects.users.UserFull; +import com.vk.api.sdk.objects.users.UserMin; import com.vk.api.sdk.objects.users.UserXtrCounters; +import com.vk.api.sdk.queries.users.UserField; import lombok.extern.log4j.Log4j; import org.springframework.stereotype.Component; +import java.lang.reflect.Field; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Log4j @Component @@ -33,15 +37,14 @@ public class VkApi { } } - public static String getUserName(Integer id) { - List user = null; - UserFull userFull = null; + public static UserXtrCounters getUserVk(Integer id) { + List temp = null; try { - user = vk.users().get(actor).userIds(String.valueOf(id)).execute(); + temp = vk.users().get(actor).userIds(String.valueOf(id)).execute(); } catch (ApiException | ClientException e) { e.printStackTrace(); } - return user.get(0).getLastName() + " " + user.get(0).getFirstName(); + return temp.get(0); } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java index dd1aaa5..04c25ac 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java @@ -2,26 +2,34 @@ package org.sadtech.vkbot.handlers.impl; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.vk.api.sdk.objects.users.UserXtrCounters; +import com.vk.api.sdk.queries.users.UserField; import lombok.extern.log4j.Log4j; +import org.sadtech.consultant.database.entity.Message; import org.sadtech.consultant.database.entity.Person; import org.sadtech.consultant.processing.MessageLogicService; import org.sadtech.consultant.processing.PersonLogicService; -import org.sadtech.consultant.database.entity.Message; import org.sadtech.vkbot.SourceMessage; +import org.sadtech.vkbot.VkApi; import org.sadtech.vkbot.listener.Observable; import org.sadtech.vkbot.listener.Observer; import org.springframework.stereotype.Component; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + @Log4j @Component public class MessageHandlerVk implements Observer { private MessageLogicService messageLogicService; - private PersonLogicService userLogicService; + private PersonLogicService personLogicService; - public MessageHandlerVk(Observable dispetcherHandler, PersonLogicService userLogicService, MessageLogicService messageLogicService) { - this.userLogicService = userLogicService; + public MessageHandlerVk(Observable dispetcherHandler, PersonLogicService personLogicService, MessageLogicService messageLogicService) { this.messageLogicService = messageLogicService; + this.personLogicService = personLogicService; dispetcherHandler.registerObserver(this); } @@ -29,23 +37,29 @@ public class MessageHandlerVk implements Observer { 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); } } private void sendProcessing(com.vk.api.sdk.objects.messages.Message userMessage) { - log.info(userMessage.getBody()); - Message message = new Message(); -// Person user = userLogicService.getUserBySocialId(SourceMessage.VK.name(), Long.valueOf(userMessage.getUserId())); Person user; - user = new Person(); - user.getSocialNetworks().put(SourceMessage.VK.name(), userMessage.getUserId()); - user.setName("Name"); - user.setLastName("LastName"); - user.setCity("City"); - userLogicService.addUser(user); - log.info(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.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); message.setText(userMessage.getBody()); message.setDate(Long.valueOf(userMessage.getDate())); From 273356cd837268053455abc8cabb658358db71cb Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 9 Jan 2019 11:09:00 +0300 Subject: [PATCH 14/29] Refactoring: Code Style and Optimize import --- .../org/sadtech/consultant/database/entity/Person.java | 10 ++++------ .../sadtech/consultant/database/entity/SaveUnit.java | 1 - .../org/sadtech/consultant/database/entity/Unit.java | 1 - .../consultant/database/service/PersonService.java | 4 ++++ .../consultant/database/service/UnitService.java | 1 + .../database/service/impl/MessageServiceImpl.java | 1 - .../consultant/processing/MessageLogicService.java | 1 - vk-bot/src/main/java/org/sadtech/vkbot/Main.java | 4 ++-- vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java | 7 ------- .../sadtech/vkbot/handlers/impl/MessageHandlerVk.java | 6 ------ .../main/java/org/sadtech/vkbot/listener/Observer.java | 2 -- .../sadtech/vkbot/listener/impl/EventListenerVk.java | 4 ---- 12 files changed, 11 insertions(+), 31 deletions(-) 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 7ab5275..cf92adf 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 @@ -3,7 +3,8 @@ package org.sadtech.consultant.database.entity; import lombok.Data; import javax.persistence.*; -import java.util.*; +import java.util.HashMap; +import java.util.Map; @Entity @Data @@ -25,11 +26,8 @@ public class Person { private String token; @ElementCollection - @CollectionTable(name="PersonSocialNetworks") - @MapKeyColumn(name="KeysSocialNetworks", length = 20) + @CollectionTable(name = "PersonSocialNetworks") + @MapKeyColumn(name = "KeysSocialNetworks", length = 20) private Map socialNetworks = new HashMap<>(); -// @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="idMess") -// private List messages; - } 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 68c696c..b5df08e 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 @@ -4,7 +4,6 @@ import lombok.Data; import javax.persistence.Entity; import javax.persistence.Id; -import javax.persistence.Table; @Entity @Data diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java b/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java index 247df8b..a267686 100644 --- a/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java +++ b/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java @@ -4,7 +4,6 @@ import lombok.Data; import javax.persistence.Entity; import javax.persistence.Id; -import javax.persistence.Table; @Entity @Data diff --git a/core/src/main/java/org/sadtech/consultant/database/service/PersonService.java b/core/src/main/java/org/sadtech/consultant/database/service/PersonService.java index db476ea..0872760 100644 --- a/core/src/main/java/org/sadtech/consultant/database/service/PersonService.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/PersonService.java @@ -7,8 +7,12 @@ import java.util.Map; public interface PersonService { void addUser(Person user); + void removeUser(Long id); + Person getUserByID(Long id); + Map getSocialNetwork(Long id); + Person getUserBySocialNetworksId(String type, Integer socialNetworksId); } 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 index 9de39e8..eafedba 100644 --- a/core/src/main/java/org/sadtech/consultant/database/service/UnitService.java +++ b/core/src/main/java/org/sadtech/consultant/database/service/UnitService.java @@ -5,6 +5,7 @@ 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/impl/MessageServiceImpl.java b/core/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java index 284a997..f5d967b 100644 --- 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 @@ -5,7 +5,6 @@ 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 org.springframework.transaction.annotation.Transactional; import java.util.List; 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 7b37ba7..1ed910a 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,6 @@ package org.sadtech.consultant.processing; import org.sadtech.consultant.database.entity.Message; -import org.sadtech.consultant.database.entity.Person; import org.sadtech.consultant.database.service.MessageService; import org.springframework.stereotype.Component; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java index 801fc20..cbddefb 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/Main.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/Main.java @@ -11,8 +11,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext public class Main { public static void main(String[] args) throws Exception { - Main main = new Main(); - main.run(); + Main main = new Main(); + main.run(); } public void run() throws Exception { diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java b/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java index 960820b..2d436c5 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/VkApi.java @@ -1,21 +1,14 @@ package org.sadtech.vkbot; -import com.google.gson.Gson; import com.vk.api.sdk.client.VkApiClient; import com.vk.api.sdk.client.actors.GroupActor; import com.vk.api.sdk.exceptions.ApiException; import com.vk.api.sdk.exceptions.ClientException; -import com.vk.api.sdk.objects.users.User; -import com.vk.api.sdk.objects.users.UserMin; import com.vk.api.sdk.objects.users.UserXtrCounters; -import com.vk.api.sdk.queries.users.UserField; import lombok.extern.log4j.Log4j; import org.springframework.stereotype.Component; -import java.lang.reflect.Field; -import java.util.HashMap; import java.util.List; -import java.util.Map; @Log4j @Component diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java index 04c25ac..936af0e 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/handlers/impl/MessageHandlerVk.java @@ -3,7 +3,6 @@ package org.sadtech.vkbot.handlers.impl; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.vk.api.sdk.objects.users.UserXtrCounters; -import com.vk.api.sdk.queries.users.UserField; import lombok.extern.log4j.Log4j; import org.sadtech.consultant.database.entity.Message; import org.sadtech.consultant.database.entity.Person; @@ -15,11 +14,6 @@ import org.sadtech.vkbot.listener.Observable; import org.sadtech.vkbot.listener.Observer; import org.springframework.stereotype.Component; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - @Log4j @Component public class MessageHandlerVk implements Observer { 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 57a9b15..cdc652e 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 @@ -2,8 +2,6 @@ package org.sadtech.vkbot.listener; import com.google.gson.JsonObject; -import java.util.List; - public interface Observer { void update(JsonObject object); } 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 3c2cfa5..eb590f9 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 @@ -9,14 +9,11 @@ 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.VkApi; import org.sadtech.vkbot.listener.EventListenable; import org.sadtech.vkbot.listener.data.ResponsibleData; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; -import java.util.Date; - @Log4j @Component public class EventListenerVk implements EventListenable { @@ -61,5 +58,4 @@ public class EventListenerVk implements EventListenable { } - } From 863229f5b6b155a5a8114b29fbd22a2d5ad44cfc Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 9 Jan 2019 17:18:20 +0300 Subject: [PATCH 15/29] =?UTF-8?q?=D0=90=D1=80=D1=85=D0=B8=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D1=83=D1=80=D0=BD=D0=BE=D0=B5=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=B1=D0=B8=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D1=8B=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sadtech/consultant/MessageSender.java | 7 + .../entity/{Message.java => Mail.java} | 7 +- .../consultant/database/entity/Person.java | 3 + .../consultant/database/entity/SaveUnit.java | 7 +- ...ageRepository.java => MailRepository.java} | 8 +- .../database/service/MailService.java | 12 ++ .../database/service/MessageService.java | 12 -- .../service/impl/MailServiceImpl.java | 25 +++ .../service/impl/MessageServiceImpl.java | 25 --- .../service/impl/PersonServiceImpl.java | 2 +- .../service/impl/UnitServiceImpl.java | 2 +- .../consultant/processing/MessageHandler.java | 28 ++- .../processing/MessageLogicService.java | 12 +- facebook-bot/pom.xml | 15 -- fit-elit-consultant/pom.xml | 181 ++++++++++++++++++ .../java/ru/fitelit/consultant}/Main.java | 16 +- .../consultant}/config/DataConfig.java | 2 +- .../consultant}/config/SpringConfigVk.java | 4 +- .../fitelit/consultant}/config/WebConfig.java | 6 +- pom.xml | 2 +- vk-bot/WEB-INF/web.xml | 6 - vk-bot/pom.xml | 13 +- .../vkbot/{ => core}/SourceMessage.java | 2 +- .../org/sadtech/vkbot/{ => core}/VkApi.java | 2 +- .../data/ResponsibleData.java | 2 +- .../data/impl/ResponseDataVk.java | 4 +- .../sadtech/vkbot/core/handlers/Handled.java | 9 + .../handlers/impl/DispatcherHandlerVk.java} | 18 +- .../handlers/impl/MessageHandlerVk.java | 33 ++-- .../{ => core}/listener/EventListenable.java | 2 +- .../vkbot/{ => core}/listener/Observable.java | 3 +- .../vkbot/{ => core}/listener/Observer.java | 2 +- .../listener/impl/EventListenerVk.java | 8 +- .../vkbot/core/sendler/MessageSendVk.java | 20 ++ .../org/sadtech/vkbot/handlers/Handled.java | 7 - 35 files changed, 363 insertions(+), 144 deletions(-) create mode 100644 core/src/main/java/org/sadtech/consultant/MessageSender.java rename core/src/main/java/org/sadtech/consultant/database/entity/{Message.java => Mail.java} (68%) rename core/src/main/java/org/sadtech/consultant/database/repository/{MessageRepository.java => MailRepository.java} (50%) create mode 100644 core/src/main/java/org/sadtech/consultant/database/service/MailService.java delete 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/impl/MailServiceImpl.java delete mode 100644 core/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java delete mode 100644 facebook-bot/pom.xml create mode 100644 fit-elit-consultant/pom.xml rename {vk-bot/src/main/java/org/sadtech/vkbot => fit-elit-consultant/src/main/java/ru/fitelit/consultant}/Main.java (59%) rename {vk-bot/src/main/java/org/sadtech/vkbot => fit-elit-consultant/src/main/java/ru/fitelit/consultant}/config/DataConfig.java (98%) rename {vk-bot/src/main/java/org/sadtech/vkbot => fit-elit-consultant/src/main/java/ru/fitelit/consultant}/config/SpringConfigVk.java (94%) rename {vk-bot/src/main/java/org/sadtech/vkbot => fit-elit-consultant/src/main/java/ru/fitelit/consultant}/config/WebConfig.java (88%) delete mode 100644 vk-bot/WEB-INF/web.xml rename vk-bot/src/main/java/org/sadtech/vkbot/{ => core}/SourceMessage.java (87%) rename vk-bot/src/main/java/org/sadtech/vkbot/{ => core}/VkApi.java (97%) rename vk-bot/src/main/java/org/sadtech/vkbot/{listener => core}/data/ResponsibleData.java (84%) rename vk-bot/src/main/java/org/sadtech/vkbot/{listener => core}/data/impl/ResponseDataVk.java (86%) create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/Handled.java rename vk-bot/src/main/java/org/sadtech/vkbot/{handlers/impl/DispetcherHandlerVk.java => core/handlers/impl/DispatcherHandlerVk.java} (64%) rename vk-bot/src/main/java/org/sadtech/vkbot/{ => core}/handlers/impl/MessageHandlerVk.java (65%) rename vk-bot/src/main/java/org/sadtech/vkbot/{ => core}/listener/EventListenable.java (64%) rename vk-bot/src/main/java/org/sadtech/vkbot/{ => core}/listener/Observable.java (58%) rename vk-bot/src/main/java/org/sadtech/vkbot/{ => core}/listener/Observer.java (71%) rename vk-bot/src/main/java/org/sadtech/vkbot/{ => core}/listener/impl/EventListenerVk.java (74%) create mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/sendler/MessageSendVk.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/handlers/Handled.java 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; - -} From 1e053c95078cb0e542de35fe41999d260ea24986 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 9 Jan 2019 18:42:59 +0300 Subject: [PATCH 16/29] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=92=D0=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Он вынесен в отдельный проект для повторного использования --- vk-bot/pom.xml | 183 ------------------ .../org/sadtech/vkbot/core/SourceMessage.java | 16 -- .../java/org/sadtech/vkbot/core/VkApi.java | 43 ---- .../vkbot/core/data/ResponsibleData.java | 17 -- .../vkbot/core/data/impl/ResponseDataVk.java | 33 ---- .../sadtech/vkbot/core/handlers/Handled.java | 9 - .../handlers/impl/DispatcherHandlerVk.java | 48 ----- .../core/handlers/impl/MessageHandlerVk.java | 65 ------- .../vkbot/core/listener/EventListenable.java | 5 - .../vkbot/core/listener/Observable.java | 8 - .../sadtech/vkbot/core/listener/Observer.java | 7 - .../core/listener/impl/EventListenerVk.java | 61 ------ .../vkbot/core/sendler/MessageSendVk.java | 20 -- 13 files changed, 515 deletions(-) delete mode 100644 vk-bot/pom.xml delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/SourceMessage.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/data/impl/ResponseDataVk.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/Handled.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/DispatcherHandlerVk.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java delete mode 100644 vk-bot/src/main/java/org/sadtech/vkbot/core/sendler/MessageSendVk.java diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml deleted file mode 100644 index dad10a1..0000000 --- a/vk-bot/pom.xml +++ /dev/null @@ -1,183 +0,0 @@ - - - - consultant - org.sadtech - 1.0-SNAPSHOT - - 4.0.0 - - org.sadtech - vk-bot - 0.2-SNAPSHOT - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - - 7 - 7 - - - - - org.apache.maven.plugins - maven-war-plugin - - false - - - - - - - 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.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/core/SourceMessage.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/SourceMessage.java deleted file mode 100644 index 7385191..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/SourceMessage.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.vkbot.core; - -public enum SourceMessage { - VK("VK"), - FB("FB"); - - private final String value; - - private SourceMessage(String value) { - this.value = value; - } - - public String getValue() { - return this.value; - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java deleted file mode 100644 index 6c2e68e..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.sadtech.vkbot.core; - -import com.vk.api.sdk.client.VkApiClient; -import com.vk.api.sdk.client.actors.GroupActor; -import com.vk.api.sdk.exceptions.ApiException; -import com.vk.api.sdk.exceptions.ClientException; -import com.vk.api.sdk.objects.users.UserXtrCounters; -import lombok.extern.log4j.Log4j; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Log4j -@Component -public class VkApi { - - private static VkApiClient vk; - private static GroupActor actor; - - public VkApi(VkApiClient vk, GroupActor actor) { - this.vk = vk; - this.actor = actor; - } - - public static void sendMessage(Integer id, String text) { - try { - vk.messages().send(actor).userId(id).message(text).execute(); - } catch (ApiException | ClientException e) { - e.printStackTrace(); - } - } - - public static UserXtrCounters getUserVk(Integer id) { - List temp = null; - try { - temp = vk.users().get(actor).userIds(String.valueOf(id)).execute(); - } catch (ApiException | ClientException e) { - e.printStackTrace(); - } - return temp.get(0); - } - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java deleted file mode 100644 index 47e0dc8..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.sadtech.vkbot.core.data; - -import com.google.gson.JsonObject; - -import java.util.Queue; - -public interface ResponsibleData { - - void add(JsonObject jsonObject); - - void remove(int id); - - void cleanAll(); - - Queue getJsonObjects(); - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/data/impl/ResponseDataVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/data/impl/ResponseDataVk.java deleted file mode 100644 index a5532b4..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/data/impl/ResponseDataVk.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sadtech.vkbot.core.data.impl; - -import com.google.gson.JsonObject; -import org.sadtech.vkbot.core.data.ResponsibleData; -import org.springframework.stereotype.Component; - -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; - -@Component -public class ResponseDataVk implements ResponsibleData { - - private Queue jsonObjects = new ConcurrentLinkedQueue<>(); - - @Override - public void add(JsonObject jsonObject) { - jsonObjects.offer(jsonObject); - } - - @Override - public void remove(int id) { - jsonObjects.remove(id); - } - - @Override - public void cleanAll() { - jsonObjects.clear(); - } - - public Queue getJsonObjects() { - return jsonObjects; - } -} 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 deleted file mode 100644 index f5fe281..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/Handled.java +++ /dev/null @@ -1,9 +0,0 @@ -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/core/handlers/impl/DispatcherHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/DispatcherHandlerVk.java deleted file mode 100644 index fb7c5e9..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/DispatcherHandlerVk.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.sadtech.vkbot.core.handlers.impl; - -import com.google.gson.JsonObject; -import lombok.extern.log4j.Log4j; -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; - -import java.util.ArrayList; -import java.util.List; - -@Log4j -@Component("dispatcherHandler") -public class DispatcherHandlerVk implements Observable, Handled { - - private ResponsibleData date; - private List observers = new ArrayList<>(); - private JsonObject event; - - public DispatcherHandlerVk(ResponsibleData date) { - this.date = date; - } - - @Async - public void sortAndSend() { - while (true) { - if (date.getJsonObjects().peek() != null) { - event = date.getJsonObjects().poll(); - notifyObservers(); - } - } - } - - @Override - public void registerObserver(Observer o) { - observers.add(o); - } - - @Override - public void notifyObservers() { - for (Observer observer : observers) { - observer.update(event); - } - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java deleted file mode 100644 index aa1513c..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java +++ /dev/null @@ -1,65 +0,0 @@ -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.Mail; -import org.sadtech.consultant.database.entity.Person; -import org.sadtech.consultant.processing.MessageLogicService; -import org.sadtech.consultant.processing.PersonLogicService; -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 -@Component -public class MessageHandlerVk implements Observer { - - private MessageLogicService messageLogicService; - private PersonLogicService personLogicService; - private Message userMessage; - - public MessageHandlerVk(@Qualifier("dispatcherHandler") Handled dispatcherHandler, PersonLogicService personLogicService, MessageLogicService messageLogicService) { - this.messageLogicService = messageLogicService; - this.personLogicService = personLogicService; - dispatcherHandler.registerObserver(this); - } - - @Override - public void update(JsonObject object) { - if (object.get("type").toString().equals("\"message_new\"")) { - Gson gson = new Gson(); - userMessage = gson.fromJson(object.getAsJsonObject("object"), com.vk.api.sdk.objects.messages.Message.class); - sortAndSend(); - } - } - - public void sortAndSend() { - Person user; - Integer userVkId = userMessage.getUserId(); - 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("city"); - user.setName(userXtrCounters.getFirstName()); - user.setLastName(userXtrCounters.getLastName()); - user.getSocialNetworks().put(String.valueOf(SourceMessage.VK), userMessage.getUserId()); - personLogicService.addUser(user); - } - - Mail message = new Mail(); - message.setPerson(user); - message.setText(userMessage.getBody()); - message.setDate(Long.valueOf(userMessage.getDate())); - message.setSourceMessage(SourceMessage.VK.name()); - log.info(message); - messageLogicService.addMessage(message); - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java deleted file mode 100644 index 14308f4..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.sadtech.vkbot.core.listener; - -public interface EventListenable { - void listen() throws Exception; -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java deleted file mode 100644 index bcab5b7..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.sadtech.vkbot.core.listener; - -public interface Observable { - - // void removeObserver(Observer o); - void notifyObservers(); - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java deleted file mode 100644 index 2edd654..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.vkbot.core.listener; - -import com.google.gson.JsonObject; - -public interface Observer { - void update(JsonObject object); -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java deleted file mode 100644 index dca38d5..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.sadtech.vkbot.core.listener.impl; - -import com.vk.api.sdk.actions.LongPoll; -import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; -import com.vk.api.sdk.callback.longpoll.responses.GetLongPollEventsResponse; -import com.vk.api.sdk.client.VkApiClient; -import com.vk.api.sdk.client.actors.GroupActor; -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.core.listener.EventListenable; -import org.sadtech.vkbot.core.data.ResponsibleData; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -@Log4j -@Component -public class EventListenerVk implements EventListenable { - - private VkApiClient vk; - private GroupActor actor; - private ResponsibleData responseData; - - private GetLongPollEventsQuery longPollEventsQuery; - private LongPoll longPoll; - private GetLongPollServerResponse server; - - public EventListenerVk(VkApiClient vk, GroupActor actor, ResponsibleData responseData) { - this.vk = vk; - this.actor = actor; - this.responseData = responseData; - longPoll = new LongPoll(vk); - } - - private void initServer() throws ClientException, ApiException { - server = vk.groups().getLongPollServer(actor).execute(); - String key = server.getKey(); - String serverUrl = server.getServer(); - Integer ts = server.getTs(); - longPoll = new LongPoll(vk); - longPollEventsQuery = longPoll.getEvents(serverUrl, key, ts).waitTime(20); - } - - @Async - public void listen() throws Exception { - initServer(); - do { - GetLongPollEventsResponse eventsResponse; - eventsResponse = longPollEventsQuery.execute(); - 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\"}]]}"; - } - 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 deleted file mode 100644 index d250f01..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/sendler/MessageSendVk.java +++ /dev/null @@ -1,20 +0,0 @@ -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); - } -} From 955d1f2cff2cf764192ffd10335b61ff91fc3724 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 9 Jan 2019 18:44:34 +0300 Subject: [PATCH 17/29] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D1=83=D0=B1=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=92=D0=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 3 +++ vk-bot | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 vk-bot diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6b277d5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vk-bot"] + path = vk-bot + url = git@bitbucket.org:sadtech/vk-bot.git diff --git a/vk-bot b/vk-bot new file mode 160000 index 0000000..62415b8 --- /dev/null +++ b/vk-bot @@ -0,0 +1 @@ +Subproject commit 62415b810deab89a8608781bf884a0a2c65b5c53 From 183153e0aac638d3f2cd4f9f42fdf0b80342dd9e Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 9 Jan 2019 18:53:47 +0300 Subject: [PATCH 18/29] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=D1=83=D0=B1=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vk-bot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vk-bot b/vk-bot index 62415b8..61e6116 160000 --- a/vk-bot +++ b/vk-bot @@ -1 +1 @@ -Subproject commit 62415b810deab89a8608781bf884a0a2c65b5c53 +Subproject commit 61e6116e8556fb5668ead0ba49818807b5dfbcd5 From 9f9c24105875823483f5aee205909f2f0977fb67 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 9 Jan 2019 18:59:58 +0300 Subject: [PATCH 19/29] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D1=83=D0=B1=D0=BC=D0=BE=D0=B4=D1=83=D0=BB?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vk-bot | 1 - 1 file changed, 1 deletion(-) delete mode 160000 vk-bot diff --git a/vk-bot b/vk-bot deleted file mode 160000 index 61e6116..0000000 --- a/vk-bot +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 61e6116e8556fb5668ead0ba49818807b5dfbcd5 From b757287bea25d279e043e43f51c9954dd8b29e1b Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 9 Jan 2019 19:00:18 +0300 Subject: [PATCH 20/29] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D1=83=D0=B1=D0=BC=D0=BE=D0=B4=D1=83=D0=BB?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 6b277d5..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "vk-bot"] - path = vk-bot - url = git@bitbucket.org:sadtech/vk-bot.git From d9a7e09e221a06cd258150a4afe531ac9a6ad382 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 9 Jan 2019 21:38:06 +0300 Subject: [PATCH 21/29] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83?= =?UTF-8?q?=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/pom.xml | 65 ------- fit-elit-consultant/pom.xml | 181 ------------------ .../main/java/ru/fitelit/consultant/Main.java | 27 --- .../fitelit/consultant/config/DataConfig.java | 76 -------- .../consultant/config/SpringConfigVk.java | 90 --------- .../fitelit/consultant/config/WebConfig.java | 32 ---- pom.xml | 60 +++++- .../org/sadtech/consultant/MessageSender.java | 0 .../consultant/database/entity/Mail.java | 0 .../consultant/database/entity/NextUnit.java | 0 .../consultant/database/entity/Person.java | 0 .../consultant/database/entity/SaveUnit.java | 0 .../consultant/database/entity/Unit.java | 0 .../database/repository/MailRepository.java | 0 .../repository/NextUnitRepository.java | 0 .../database/repository/PersonRepository.java | 0 .../repository/SaveUnitRepositoriy.java | 0 .../database/repository/UnitRepositoriy.java | 0 .../database/service/MailService.java | 0 .../database/service/NextUnitService.java | 0 .../database/service/PersonService.java | 0 .../database/service/SaveUnitService.java | 0 .../database/service/UnitService.java | 0 .../service/impl/MailServiceImpl.java | 0 .../service/impl/NextUnitServiceImpl.java | 0 .../service/impl/PersonServiceImpl.java | 0 .../service/impl/SaveUnitServiceImpl.java | 0 .../service/impl/UnitServiceImpl.java | 0 .../consultant/processing/MessageHandler.java | 0 .../processing/MessageLogicService.java | 0 .../processing/PersonLogicService.java | 0 31 files changed, 51 insertions(+), 480 deletions(-) delete mode 100644 core/pom.xml delete mode 100644 fit-elit-consultant/pom.xml delete mode 100644 fit-elit-consultant/src/main/java/ru/fitelit/consultant/Main.java delete mode 100644 fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/DataConfig.java delete mode 100644 fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/SpringConfigVk.java delete mode 100644 fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/WebConfig.java rename {core/src => src}/main/java/org/sadtech/consultant/MessageSender.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/entity/Mail.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/entity/NextUnit.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/entity/Person.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/entity/SaveUnit.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/entity/Unit.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/repository/MailRepository.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/repository/PersonRepository.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/MailService.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/NextUnitService.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/PersonService.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/SaveUnitService.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/UnitService.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/processing/MessageHandler.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/processing/MessageLogicService.java (100%) rename {core/src => src}/main/java/org/sadtech/consultant/processing/PersonLogicService.java (100%) diff --git a/core/pom.xml b/core/pom.xml deleted file mode 100644 index 4a34740..0000000 --- a/core/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - consultant - org.sadtech - 1.0-SNAPSHOT - - 4.0.0 - - consultant-core - - - - org.apache.maven.plugins - maven-compiler-plugin - - 8 - 8 - - - - - - - 1.0.2 - 1.18.4 - 1.2.17 - - 2.1.3.RELEASE - - - - - javax.persistence - persistence-api - ${persistence.ver} - - - - org.projectlombok - lombok - ${lombok.ver} - - - - log4j - log4j - ${log4j} - - - - org.springframework.data - spring-data-jpa - ${spring.data} - - - javax.persistence - javax.persistence-api - 2.2 - - - - \ No newline at end of file diff --git a/fit-elit-consultant/pom.xml b/fit-elit-consultant/pom.xml deleted file mode 100644 index 63bbdc8..0000000 --- a/fit-elit-consultant/pom.xml +++ /dev/null @@ -1,181 +0,0 @@ - - - - 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/fit-elit-consultant/src/main/java/ru/fitelit/consultant/Main.java b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/Main.java deleted file mode 100644 index 0ce3138..0000000 --- a/fit-elit-consultant/src/main/java/ru/fitelit/consultant/Main.java +++ /dev/null @@ -1,27 +0,0 @@ -package ru.fitelit.consultant; - -import lombok.extern.log4j.Log4j; -import org.sadtech.consultant.processing.MessageHandler; -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 { - - public static void main(String[] args) throws Exception { - Main main = new Main(); - main.run(); - } - - public void run() throws Exception { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class); - EventListenable eventListener = context.getBean(EventListenable.class); - eventListener.listen(); - Handled dispatcherHandler = context.getBean(Handled.class); - dispatcherHandler.sortAndSend(); - MessageHandler messageHandler = context.getBean(MessageHandler.class); - messageHandler.processing(); - } -} diff --git a/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/DataConfig.java b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/DataConfig.java deleted file mode 100644 index ccef4cb..0000000 --- a/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/DataConfig.java +++ /dev/null @@ -1,76 +0,0 @@ -package ru.fitelit.consultant.config; - -import org.hibernate.jpa.HibernatePersistenceProvider; -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.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.sql.DataSource; -import java.util.Properties; - -@Configuration -@EnableTransactionManagement -@ComponentScan("org.sadtech.consultant.database.service") -@EnableJpaRepositories("org.sadtech.consultant.database.repository") -public class DataConfig { - - @Value("${db.driver}") - private String PROPERTY_NAME_DATABASE_DRIVER; - @Value("${db.url}") - private String PROPERTY_NAME_DATABASE_URL; - @Value("${db.username}") - private String PROPERTY_NAME_DATABASE_USERNAME; - @Value("${db.password}") - private String PROPERTY_NAME_DATABASE_PASSWORD; - - @Value("${db.hibernate.dialect}") - private String PROPERTY_NAME_HIBERNATE_DIALECT; - @Value("${db.hibernate.show_sql}") - private String PROPERTY_NAME_HIBERNATE_SHOW_SQL; - @Value("${db.entitymanager.packages.to.scan}") - private String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN; - @Value("${db.hibernate.hbm2ddl.auto}") - private String PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO; - - @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory() { - LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); - entityManagerFactoryBean.setDataSource(dataSource()); - entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); - entityManagerFactoryBean.setPackagesToScan(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN); - entityManagerFactoryBean.setJpaProperties(hibernateProp()); - return entityManagerFactoryBean; - } - - @Bean - public JpaTransactionManager transactionManager() { - JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(entityManagerFactory().getObject()); - return transactionManager; - } - - @Bean - public DataSource dataSource() { - DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(PROPERTY_NAME_DATABASE_DRIVER); - dataSource.setUrl(PROPERTY_NAME_DATABASE_URL); - dataSource.setUsername(PROPERTY_NAME_DATABASE_USERNAME); - dataSource.setPassword(PROPERTY_NAME_DATABASE_PASSWORD); - return dataSource; - } - - private Properties hibernateProp() { - Properties properties = new Properties(); - properties.put("hibernate.dialect", PROPERTY_NAME_HIBERNATE_DIALECT); - properties.put("hibernate.show_sql", PROPERTY_NAME_HIBERNATE_SHOW_SQL); - properties.put("hibernate.hbm2ddl.auto", PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO); - return properties; - } - -} \ No newline at end of file diff --git a/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/SpringConfigVk.java b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/SpringConfigVk.java deleted file mode 100644 index a700ffe..0000000 --- a/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/SpringConfigVk.java +++ /dev/null @@ -1,90 +0,0 @@ -package ru.fitelit.consultant.config; - -import com.vk.api.sdk.client.TransportClient; -import com.vk.api.sdk.client.VkApiClient; -import com.vk.api.sdk.client.actors.GroupActor; -import com.vk.api.sdk.client.actors.ServiceActor; -import com.vk.api.sdk.exceptions.ApiException; -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.*; -import org.springframework.core.task.TaskExecutor; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; - -import java.util.concurrent.Executors; - - -@Configuration -@EnableAsync -@PropertySource("classpath:config.properties") -@Import({DataConfig.class}) -@ComponentScan({"ru.fitelit.consultant", "org.sadtech.consultant.processing", "org.sadtech.vkbot.core"}) - -public class SpringConfigVk { - - @Value("${vk.groupID}") - private String groupId; - - @Value("${vk.appID}") - private String appID; - - @Value("${vk.secretKey}") - private String secretKey; - - @Value("${vk.redirectURL}") - private String redirectURL; - - @Value("${vk.code}") - private String code; - - @Value("${vk.token}") - private String token; - - @Value("${vk.service.token}") - private String serviceToken; - - @Bean - public TransportClient transportClient() { - return HttpTransportClient.getInstance(); - } - - @Bean - public VkApiClient vkApiClient() { - VkApiClient vk = new VkApiClient(transportClient()); - return vk; - } - - @Bean - public GroupActor groupActor() { - GroupActor actor = new GroupActor(new Integer(groupId), token); - return actor; - } - - @Bean - public ServiceActor serviceActor() { - ServiceActor actor = new ServiceActor(new Integer(appID), serviceToken); - return actor; - } - - @Bean - public GetLongPollServerResponse GroupsGetLongPollServerQuery() { - GetLongPollServerResponse getLongPollServerResponse = null; - try { - getLongPollServerResponse = vkApiClient().groups().getLongPollServer(groupActor()).execute(); - } catch (ApiException | ClientException e) { - e.printStackTrace(); - } - return getLongPollServerResponse; - } - - - @Bean - public TaskExecutor taskExecutor() { - return new ConcurrentTaskExecutor(Executors.newFixedThreadPool(5)); - } - - -} diff --git a/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/WebConfig.java b/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/WebConfig.java deleted file mode 100644 index df46ba0..0000000 --- a/fit-elit-consultant/src/main/java/ru/fitelit/consultant/config/WebConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -//package org.sadtech.vkbot.config; -// -//import com.vk.api.sdk.exceptions.ApiException; -//import com.vk.api.sdk.exceptions.ClientException; -//import EventListenable; -//import Observable; -//import EventListenerVk; -//import org.springframework.context.annotation.ComponentScan; -//import org.springframework.context.annotation.Configuration; -//import org.springframework.web.WebApplicationInitializer; -//import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -//import org.springframework.web.servlet.DispatcherServlet; -// -//import javax.servlet.ServletContext; -//import javax.servlet.ServletException; -// -//@Configuration -//public class WebConfig implements WebApplicationInitializer { -// -// @Override -// public void onStartup(ServletContext servletContext) throws ServletException { -// AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); -// context.register(SpringConfigVk.class, DataConfig.class, WebConfig.class); -// -//// context.setServletContext(servletContext); -//// -//// -//// ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); -//// dispatcher.setLoadOnStartup(1); -//// dispatcher.addMapping("/"); -// } -//} diff --git a/pom.xml b/pom.xml index 8d58c86..26b594b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,15 +4,57 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.sadtech - consultant - pom - 0.1-SNAPSHOT - - vk-bot - core - fit-elit-consultant - + consultant-core + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + 1.0.2 + 1.18.4 + 1.2.17 + + 2.1.3.RELEASE + + + + + javax.persistence + persistence-api + ${persistence.ver} + + + + org.projectlombok + lombok + ${lombok.ver} + + + + log4j + log4j + ${log4j} + + + + org.springframework.data + spring-data-jpa + ${spring.data} + + + javax.persistence + javax.persistence-api + 2.2 + + \ No newline at end of file diff --git a/core/src/main/java/org/sadtech/consultant/MessageSender.java b/src/main/java/org/sadtech/consultant/MessageSender.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/MessageSender.java rename to src/main/java/org/sadtech/consultant/MessageSender.java diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Mail.java b/src/main/java/org/sadtech/consultant/database/entity/Mail.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/entity/Mail.java rename to src/main/java/org/sadtech/consultant/database/entity/Mail.java diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java b/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java rename to src/main/java/org/sadtech/consultant/database/entity/NextUnit.java diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Person.java b/src/main/java/org/sadtech/consultant/database/entity/Person.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/entity/Person.java rename to src/main/java/org/sadtech/consultant/database/entity/Person.java diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java b/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java rename to src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java diff --git a/core/src/main/java/org/sadtech/consultant/database/entity/Unit.java b/src/main/java/org/sadtech/consultant/database/entity/Unit.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/entity/Unit.java rename to src/main/java/org/sadtech/consultant/database/entity/Unit.java diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/MailRepository.java b/src/main/java/org/sadtech/consultant/database/repository/MailRepository.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/repository/MailRepository.java rename to src/main/java/org/sadtech/consultant/database/repository/MailRepository.java diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java b/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java rename to src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java b/src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java rename to src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java b/src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java rename to src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java diff --git a/core/src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java b/src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java rename to src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/MailService.java b/src/main/java/org/sadtech/consultant/database/service/MailService.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/MailService.java rename to src/main/java/org/sadtech/consultant/database/service/MailService.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java b/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java rename to src/main/java/org/sadtech/consultant/database/service/NextUnitService.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/PersonService.java b/src/main/java/org/sadtech/consultant/database/service/PersonService.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/PersonService.java rename to src/main/java/org/sadtech/consultant/database/service/PersonService.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java b/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java rename to src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/UnitService.java b/src/main/java/org/sadtech/consultant/database/service/UnitService.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/UnitService.java rename to src/main/java/org/sadtech/consultant/database/service/UnitService.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java b/src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java rename to src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java b/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java rename to src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java b/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java rename to src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java b/src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java rename to src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java diff --git a/core/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java rename to src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java diff --git a/core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java b/src/main/java/org/sadtech/consultant/processing/MessageHandler.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/processing/MessageHandler.java rename to src/main/java/org/sadtech/consultant/processing/MessageHandler.java diff --git a/core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java b/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java rename to src/main/java/org/sadtech/consultant/processing/MessageLogicService.java diff --git a/core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java b/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java similarity index 100% rename from core/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java rename to src/main/java/org/sadtech/consultant/processing/PersonLogicService.java From b79c3c7cfe386e986cf394190e1574737b33d504 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 10 Jan 2019 01:11:19 +0300 Subject: [PATCH 22/29] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 +++- .../{consultant => autoresponder}/MessageSender.java | 2 +- .../database/entity/Mail.java | 2 +- .../database/entity/NextUnit.java | 3 +-- .../database/entity/Person.java | 2 +- .../database/entity/SaveUnit.java | 2 +- .../database/entity/Unit.java | 2 +- .../database/repository/MailRepository.java | 4 ++-- .../database/repository/NextUnitRepository.java | 4 ++-- .../database/repository/PersonRepository.java | 4 ++-- .../database/repository/SaveUnitRepositoriy.java | 4 ++-- .../database/repository/UnitRepositoriy.java | 4 ++-- .../database/service/MailService.java | 4 ++-- .../database/service/NextUnitService.java | 4 ++++ .../database/service/PersonService.java | 4 ++-- .../database/service/SaveUnitService.java | 4 ++++ .../autoresponder/database/service/UnitService.java | 11 +++++++++++ .../database/service/impl/MailServiceImpl.java | 8 ++++---- .../database/service/impl/NextUnitServiceImpl.java | 6 +++--- .../database/service/impl/PersonServiceImpl.java | 8 ++++---- .../database/service/impl/SaveUnitServiceImpl.java | 6 +++--- .../database/service/impl/UnitServiceImpl.java | 8 ++++---- .../processing/MessageHandler.java | 8 ++++---- .../processing/MessageLogicService.java | 6 +++--- .../processing/PersonLogicService.java | 6 +++--- .../consultant/database/service/NextUnitService.java | 4 ---- .../consultant/database/service/SaveUnitService.java | 4 ---- .../consultant/database/service/UnitService.java | 11 ----------- 28 files changed, 70 insertions(+), 69 deletions(-) rename src/main/java/org/sadtech/{consultant => autoresponder}/MessageSender.java (70%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/entity/Mail.java (86%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/entity/NextUnit.java (69%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/entity/Person.java (92%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/entity/SaveUnit.java (82%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/entity/Unit.java (80%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/repository/MailRepository.java (78%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/repository/NextUnitRepository.java (55%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/repository/PersonRepository.java (80%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/repository/SaveUnitRepositoriy.java (55%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/repository/UnitRepositoriy.java (55%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/service/MailService.java (56%) create mode 100644 src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java rename src/main/java/org/sadtech/{consultant => autoresponder}/database/service/PersonService.java (72%) create mode 100644 src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java create mode 100644 src/main/java/org/sadtech/autoresponder/database/service/UnitService.java rename src/main/java/org/sadtech/{consultant => autoresponder}/database/service/impl/MailServiceImpl.java (66%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/service/impl/NextUnitServiceImpl.java (55%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/service/impl/PersonServiceImpl.java (77%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/service/impl/SaveUnitServiceImpl.java (55%) rename src/main/java/org/sadtech/{consultant => autoresponder}/database/service/impl/UnitServiceImpl.java (59%) rename src/main/java/org/sadtech/{consultant => autoresponder}/processing/MessageHandler.java (88%) rename src/main/java/org/sadtech/{consultant => autoresponder}/processing/MessageLogicService.java (74%) rename src/main/java/org/sadtech/{consultant => autoresponder}/processing/PersonLogicService.java (90%) delete mode 100644 src/main/java/org/sadtech/consultant/database/service/NextUnitService.java delete mode 100644 src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java delete mode 100644 src/main/java/org/sadtech/consultant/database/service/UnitService.java diff --git a/pom.xml b/pom.xml index 26b594b..bd99519 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - consultant-core + org.sadtech.autoresponder + core + 0.1-SNAPSHOT diff --git a/src/main/java/org/sadtech/consultant/MessageSender.java b/src/main/java/org/sadtech/autoresponder/MessageSender.java similarity index 70% rename from src/main/java/org/sadtech/consultant/MessageSender.java rename to src/main/java/org/sadtech/autoresponder/MessageSender.java index 75ba12e..ad72975 100644 --- a/src/main/java/org/sadtech/consultant/MessageSender.java +++ b/src/main/java/org/sadtech/autoresponder/MessageSender.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant; +package org.sadtech.autoresponder; public interface MessageSender { diff --git a/src/main/java/org/sadtech/consultant/database/entity/Mail.java b/src/main/java/org/sadtech/autoresponder/database/entity/Mail.java similarity index 86% rename from src/main/java/org/sadtech/consultant/database/entity/Mail.java rename to src/main/java/org/sadtech/autoresponder/database/entity/Mail.java index 5ba4490..266d64b 100644 --- a/src/main/java/org/sadtech/consultant/database/entity/Mail.java +++ b/src/main/java/org/sadtech/autoresponder/database/entity/Mail.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.database.entity; +package org.sadtech.autoresponder.database.entity; import lombok.Data; diff --git a/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java b/src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java similarity index 69% rename from src/main/java/org/sadtech/consultant/database/entity/NextUnit.java rename to src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java index 5e896fe..82b8ff4 100644 --- a/src/main/java/org/sadtech/consultant/database/entity/NextUnit.java +++ b/src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java @@ -1,10 +1,9 @@ -package org.sadtech.consultant.database.entity; +package org.sadtech.autoresponder.database.entity; import lombok.Data; import javax.persistence.Entity; import javax.persistence.Id; -import javax.persistence.Table; @Entity @Data diff --git a/src/main/java/org/sadtech/consultant/database/entity/Person.java b/src/main/java/org/sadtech/autoresponder/database/entity/Person.java similarity index 92% rename from src/main/java/org/sadtech/consultant/database/entity/Person.java rename to src/main/java/org/sadtech/autoresponder/database/entity/Person.java index 847e228..bfe26a6 100644 --- a/src/main/java/org/sadtech/consultant/database/entity/Person.java +++ b/src/main/java/org/sadtech/autoresponder/database/entity/Person.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.database.entity; +package org.sadtech.autoresponder.database.entity; import lombok.Data; diff --git a/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java b/src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java similarity index 82% rename from src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java rename to src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java index d198992..8aebffd 100644 --- a/src/main/java/org/sadtech/consultant/database/entity/SaveUnit.java +++ b/src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.database.entity; +package org.sadtech.autoresponder.database.entity; import lombok.Data; diff --git a/src/main/java/org/sadtech/consultant/database/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/database/entity/Unit.java similarity index 80% rename from src/main/java/org/sadtech/consultant/database/entity/Unit.java rename to src/main/java/org/sadtech/autoresponder/database/entity/Unit.java index a267686..e26b54e 100644 --- a/src/main/java/org/sadtech/consultant/database/entity/Unit.java +++ b/src/main/java/org/sadtech/autoresponder/database/entity/Unit.java @@ -1,4 +1,4 @@ -package org.sadtech.consultant.database.entity; +package org.sadtech.autoresponder.database.entity; import lombok.Data; diff --git a/src/main/java/org/sadtech/consultant/database/repository/MailRepository.java b/src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java similarity index 78% rename from src/main/java/org/sadtech/consultant/database/repository/MailRepository.java rename to src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java index 8e5541c..ebb2354 100644 --- a/src/main/java/org/sadtech/consultant/database/repository/MailRepository.java +++ b/src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.database.repository; +package org.sadtech.autoresponder.database.repository; -import org.sadtech.consultant.database.entity.Mail; +import org.sadtech.autoresponder.database.entity.Mail; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java b/src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java similarity index 55% rename from src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java rename to src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java index 3f3f71f..4241f6e 100644 --- a/src/main/java/org/sadtech/consultant/database/repository/NextUnitRepository.java +++ b/src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.database.repository; +package org.sadtech.autoresponder.database.repository; -import org.sadtech.consultant.database.entity.NextUnit; +import org.sadtech.autoresponder.database.entity.NextUnit; import org.springframework.data.jpa.repository.JpaRepository; public interface NextUnitRepository extends JpaRepository { diff --git a/src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java b/src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java similarity index 80% rename from src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java rename to src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java index a00fa83..c810301 100644 --- a/src/main/java/org/sadtech/consultant/database/repository/PersonRepository.java +++ b/src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.database.repository; +package org.sadtech.autoresponder.database.repository; -import org.sadtech.consultant.database.entity.Person; +import org.sadtech.autoresponder.database.entity.Person; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java b/src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java similarity index 55% rename from src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java rename to src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java index 7ff8077..29b9f61 100644 --- a/src/main/java/org/sadtech/consultant/database/repository/SaveUnitRepositoriy.java +++ b/src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.database.repository; +package org.sadtech.autoresponder.database.repository; -import org.sadtech.consultant.database.entity.SaveUnit; +import org.sadtech.autoresponder.database.entity.SaveUnit; import org.springframework.data.jpa.repository.JpaRepository; public interface SaveUnitRepositoriy extends JpaRepository { diff --git a/src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java b/src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java similarity index 55% rename from src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java rename to src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java index 51e7cca..183a913 100644 --- a/src/main/java/org/sadtech/consultant/database/repository/UnitRepositoriy.java +++ b/src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.database.repository; +package org.sadtech.autoresponder.database.repository; -import org.sadtech.consultant.database.entity.Unit; +import org.sadtech.autoresponder.database.entity.Unit; import org.springframework.data.jpa.repository.JpaRepository; public interface UnitRepositoriy extends JpaRepository { diff --git a/src/main/java/org/sadtech/consultant/database/service/MailService.java b/src/main/java/org/sadtech/autoresponder/database/service/MailService.java similarity index 56% rename from src/main/java/org/sadtech/consultant/database/service/MailService.java rename to src/main/java/org/sadtech/autoresponder/database/service/MailService.java index 1ca820b..c5481e1 100644 --- a/src/main/java/org/sadtech/consultant/database/service/MailService.java +++ b/src/main/java/org/sadtech/autoresponder/database/service/MailService.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.database.service; +package org.sadtech.autoresponder.database.service; -import org.sadtech.consultant.database.entity.Mail; +import org.sadtech.autoresponder.database.entity.Mail; import java.util.List; diff --git a/src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java b/src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java new file mode 100644 index 0000000..48ed22f --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java @@ -0,0 +1,4 @@ +package org.sadtech.autoresponder.database.service; + +public interface NextUnitService { +} diff --git a/src/main/java/org/sadtech/consultant/database/service/PersonService.java b/src/main/java/org/sadtech/autoresponder/database/service/PersonService.java similarity index 72% rename from src/main/java/org/sadtech/consultant/database/service/PersonService.java rename to src/main/java/org/sadtech/autoresponder/database/service/PersonService.java index 0872760..d044d62 100644 --- a/src/main/java/org/sadtech/consultant/database/service/PersonService.java +++ b/src/main/java/org/sadtech/autoresponder/database/service/PersonService.java @@ -1,6 +1,6 @@ -package org.sadtech.consultant.database.service; +package org.sadtech.autoresponder.database.service; -import org.sadtech.consultant.database.entity.Person; +import org.sadtech.autoresponder.database.entity.Person; import java.util.Map; diff --git a/src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java b/src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java new file mode 100644 index 0000000..23b0273 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java @@ -0,0 +1,4 @@ +package org.sadtech.autoresponder.database.service; + +public interface SaveUnitService { +} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/database/service/UnitService.java new file mode 100644 index 0000000..7fb8e88 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/database/service/UnitService.java @@ -0,0 +1,11 @@ +package org.sadtech.autoresponder.database.service; + +import org.sadtech.autoresponder.database.entity.Unit; + +public interface UnitService { + + void addUnit(Unit unit); + + void removeUnit(Long id); + +} diff --git a/src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java similarity index 66% rename from src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java rename to src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java index 6432031..3bfada3 100644 --- a/src/main/java/org/sadtech/consultant/database/service/impl/MailServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java @@ -1,8 +1,8 @@ -package org.sadtech.consultant.database.service.impl; +package org.sadtech.autoresponder.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.sadtech.autoresponder.database.entity.Mail; +import org.sadtech.autoresponder.database.repository.MailRepository; +import org.sadtech.autoresponder.database.service.MailService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java similarity index 55% rename from src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java rename to src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java index 1e93a0f..6f52c91 100644 --- a/src/main/java/org/sadtech/consultant/database/service/impl/NextUnitServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java @@ -1,7 +1,7 @@ -package org.sadtech.consultant.database.service.impl; +package org.sadtech.autoresponder.database.service.impl; -import org.sadtech.consultant.database.repository.NextUnitRepository; -import org.sadtech.consultant.database.service.NextUnitService; +import org.sadtech.autoresponder.database.repository.NextUnitRepository; +import org.sadtech.autoresponder.database.service.NextUnitService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java similarity index 77% rename from src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java rename to src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java index 936d0d8..7be8a66 100644 --- a/src/main/java/org/sadtech/consultant/database/service/impl/PersonServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java @@ -1,8 +1,8 @@ -package org.sadtech.consultant.database.service.impl; +package org.sadtech.autoresponder.database.service.impl; -import org.sadtech.consultant.database.repository.PersonRepository; -import org.sadtech.consultant.database.entity.Person; -import org.sadtech.consultant.database.service.PersonService; +import org.sadtech.autoresponder.database.repository.PersonRepository; +import org.sadtech.autoresponder.database.entity.Person; +import org.sadtech.autoresponder.database.service.PersonService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java similarity index 55% rename from src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java rename to src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java index 2524815..603a89c 100644 --- a/src/main/java/org/sadtech/consultant/database/service/impl/SaveUnitServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java @@ -1,7 +1,7 @@ -package org.sadtech.consultant.database.service.impl; +package org.sadtech.autoresponder.database.service.impl; -import org.sadtech.consultant.database.repository.SaveUnitRepositoriy; -import org.sadtech.consultant.database.service.SaveUnitService; +import org.sadtech.autoresponder.database.repository.SaveUnitRepositoriy; +import org.sadtech.autoresponder.database.service.SaveUnitService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java similarity index 59% rename from src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java rename to src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java index eeec2d8..2cdddf2 100644 --- a/src/main/java/org/sadtech/consultant/database/service/impl/UnitServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java @@ -1,8 +1,8 @@ -package org.sadtech.consultant.database.service.impl; +package org.sadtech.autoresponder.database.service.impl; -import org.sadtech.consultant.database.repository.UnitRepositoriy; -import org.sadtech.consultant.database.entity.Unit; -import org.sadtech.consultant.database.service.UnitService; +import org.sadtech.autoresponder.database.repository.UnitRepositoriy; +import org.sadtech.autoresponder.database.entity.Unit; +import org.sadtech.autoresponder.database.service.UnitService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/org/sadtech/consultant/processing/MessageHandler.java b/src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java similarity index 88% rename from src/main/java/org/sadtech/consultant/processing/MessageHandler.java rename to src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java index d513930..ae1fab8 100644 --- a/src/main/java/org/sadtech/consultant/processing/MessageHandler.java +++ b/src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java @@ -1,9 +1,9 @@ -package org.sadtech.consultant.processing; +package org.sadtech.autoresponder.processing; import lombok.extern.log4j.Log4j; -import org.sadtech.consultant.database.entity.Mail; -import org.sadtech.consultant.MessageSender; -import org.sadtech.consultant.database.entity.Person; +import org.sadtech.autoresponder.database.entity.Mail; +import org.sadtech.autoresponder.MessageSender; +import org.sadtech.autoresponder.database.entity.Person; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java b/src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java similarity index 74% rename from src/main/java/org/sadtech/consultant/processing/MessageLogicService.java rename to src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java index 3eb2be4..6301456 100644 --- a/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java +++ b/src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java @@ -1,7 +1,7 @@ -package org.sadtech.consultant.processing; +package org.sadtech.autoresponder.processing; -import org.sadtech.consultant.database.entity.Mail; -import org.sadtech.consultant.database.service.MailService; +import org.sadtech.autoresponder.database.entity.Mail; +import org.sadtech.autoresponder.database.service.MailService; import org.springframework.stereotype.Component; import java.util.List; diff --git a/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java b/src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java similarity index 90% rename from src/main/java/org/sadtech/consultant/processing/PersonLogicService.java rename to src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java index 4da66f7..211dda8 100644 --- a/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java +++ b/src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java @@ -1,8 +1,8 @@ -package org.sadtech.consultant.processing; +package org.sadtech.autoresponder.processing; import lombok.extern.log4j.Log4j; -import org.sadtech.consultant.database.entity.Person; -import org.sadtech.consultant.database.service.PersonService; +import org.sadtech.autoresponder.database.entity.Person; +import org.sadtech.autoresponder.database.service.PersonService; import org.springframework.stereotype.Component; @Log4j diff --git a/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java b/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java deleted file mode 100644 index 0106520..0000000 --- a/src/main/java/org/sadtech/consultant/database/service/NextUnitService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.consultant.database.service; - -public interface NextUnitService { -} diff --git a/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java b/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java deleted file mode 100644 index 74250ae..0000000 --- a/src/main/java/org/sadtech/consultant/database/service/SaveUnitService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.consultant.database.service; - -public interface SaveUnitService { -} diff --git a/src/main/java/org/sadtech/consultant/database/service/UnitService.java b/src/main/java/org/sadtech/consultant/database/service/UnitService.java deleted file mode 100644 index eafedba..0000000 --- a/src/main/java/org/sadtech/consultant/database/service/UnitService.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sadtech.consultant.database.service; - -import org.sadtech.consultant.database.entity.Unit; - -public interface UnitService { - - void addUnit(Unit unit); - - void removeUnit(Long id); - -} From 1cf0b4dce6bae67e401b4a1d794da26f7b5ed0b0 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 11 Jan 2019 03:21:58 +0300 Subject: [PATCH 23/29] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=B0?= =?UTF-8?q?=D1=80=D1=85=D0=B8=D1=82=D0=B5=D0=BA=D1=82=D1=83=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 23 +++----- .../sadtech/autoresponder/Autoresponder.java | 17 ++++++ .../sadtech/autoresponder/MessageSender.java | 7 --- .../autoresponder/database/entity/Mail.java | 23 -------- .../database/entity/NextUnit.java | 16 ------ .../autoresponder/database/entity/Person.java | 36 ------------- .../database/entity/SaveUnit.java | 19 ------- .../autoresponder/database/entity/Unit.java | 17 ------ .../database/repository/MailRepository.java | 15 ------ .../repository/NextUnitRepository.java | 9 ---- .../database/repository/PersonRepository.java | 13 ----- .../repository/SaveUnitRepositoriy.java | 7 --- .../database/repository/UnitRepositoriy.java | 7 --- .../database/service/MailService.java | 12 ----- .../database/service/NextUnitService.java | 4 -- .../database/service/PersonService.java | 18 ------- .../database/service/SaveUnitService.java | 4 -- .../database/service/UnitService.java | 11 ---- .../service/impl/MailServiceImpl.java | 25 --------- .../service/impl/NextUnitServiceImpl.java | 14 ----- .../service/impl/PersonServiceImpl.java | 41 -------------- .../service/impl/SaveUnitServiceImpl.java | 14 ----- .../service/impl/UnitServiceImpl.java | 22 -------- .../sadtech/autoresponder/entity/Unit.java | 17 ++++++ .../processing/MessageHandler.java | 54 ------------------- .../processing/MessageLogicService.java | 25 --------- .../processing/PersonLogicService.java | 52 ------------------ .../repository/UnitRepository.java | 16 ++++++ .../repository/impl/UnitRepositoryImpl.java | 33 ++++++++++++ .../autoresponder/service/UnitService.java | 10 ++++ .../service/impl/UnitServiceImpl.java | 42 +++++++++++++++ .../submodule/parser/Parser.java | 26 +++++++++ 32 files changed, 168 insertions(+), 481 deletions(-) create mode 100644 src/main/java/org/sadtech/autoresponder/Autoresponder.java delete mode 100644 src/main/java/org/sadtech/autoresponder/MessageSender.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/Mail.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/Person.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/Unit.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/MailService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/PersonService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/UnitService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java create mode 100644 src/main/java/org/sadtech/autoresponder/entity/Unit.java delete mode 100644 src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java delete mode 100644 src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java create mode 100644 src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java create mode 100644 src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java create mode 100644 src/main/java/org/sadtech/autoresponder/service/UnitService.java create mode 100644 src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java create mode 100644 src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java diff --git a/pom.xml b/pom.xml index bd99519..dd014f0 100644 --- a/pom.xml +++ b/pom.xml @@ -21,19 +21,12 @@ - 1.0.2 1.18.4 1.2.17 - - 2.1.3.RELEASE + 4.12 - - javax.persistence - persistence-api - ${persistence.ver} - org.projectlombok @@ -47,16 +40,14 @@ ${log4j} + - org.springframework.data - spring-data-jpa - ${spring.data} - - - javax.persistence - javax.persistence-api - 2.2 + junit + junit + ${junit.ver} + test + \ No newline at end of file diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java new file mode 100644 index 0000000..254c6e8 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -0,0 +1,17 @@ +package org.sadtech.autoresponder; + +import lombok.AllArgsConstructor; +import org.sadtech.autoresponder.entity.Unit; +import org.sadtech.autoresponder.service.UnitService; + +@AllArgsConstructor +public class Autoresponder { + + private UnitService unitService; + + public Unit nextUnit(Integer idUnit, String message) { + Unit unit = unitService.getUnitById(idUnit); + return unitService.nextUnit(unit, message); + } + +} diff --git a/src/main/java/org/sadtech/autoresponder/MessageSender.java b/src/main/java/org/sadtech/autoresponder/MessageSender.java deleted file mode 100644 index ad72975..0000000 --- a/src/main/java/org/sadtech/autoresponder/MessageSender.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.autoresponder; - -public interface MessageSender { - - void send(Integer idNetSoc, String text); - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/entity/Mail.java b/src/main/java/org/sadtech/autoresponder/database/entity/Mail.java deleted file mode 100644 index 266d64b..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/Mail.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.sadtech.autoresponder.database.entity; - -import lombok.Data; - -import javax.persistence.*; - -@Data -@Entity -public class Mail { - - @Id - @GeneratedValue - private Long idMess; - private String text; - private Long date; - private String sourceMessage; - - @ManyToOne - @JoinColumn(name = "idPerson", nullable = false) - private Person person; - - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java b/src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java deleted file mode 100644 index 82b8ff4..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.autoresponder.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/src/main/java/org/sadtech/autoresponder/database/entity/Person.java b/src/main/java/org/sadtech/autoresponder/database/entity/Person.java deleted file mode 100644 index bfe26a6..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/Person.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.sadtech.autoresponder.database.entity; - -import lombok.Data; - -import javax.persistence.*; -import java.util.HashMap; -import java.util.Map; - -@Entity -@Data -public class Person { - - @Id - @GeneratedValue - private Long id; - - @Column(length = 20) - private String name; - - @Column(length = 20) - private String lastName; - - @Column(length = 20) - 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/src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java b/src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java deleted file mode 100644 index 8aebffd..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sadtech.autoresponder.database.entity; - -import lombok.Data; - -import javax.persistence.*; - -@Entity -@Data -public class SaveUnit { - - @Id - private Long id; - private Long idStage; - - @OneToOne - @JoinColumn(name = "idPerson", nullable = false) - private Person user; - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/database/entity/Unit.java deleted file mode 100644 index e26b54e..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/Unit.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.sadtech.autoresponder.database.entity; - -import lombok.Data; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -@Data -public class Unit { - - @Id - private Long id; - private String text; - private String wordKeys; - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java b/src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java deleted file mode 100644 index ebb2354..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.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 MailRepository extends JpaRepository { - - @Query("SELECT u FROM Mail u WHERE u.date > :date") - Collection getMessagesByRange(@Param("date") Long date); - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java b/src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java deleted file mode 100644 index 4241f6e..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.database.entity.NextUnit; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface NextUnitRepository extends JpaRepository { - - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java b/src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java deleted file mode 100644 index c810301..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.database.entity.Person; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -public interface PersonRepository extends JpaRepository { - - @Query("SELECT u FROM Person u INNER JOIN u.socialNetworks p WHERE KEY(p) = :type2 AND VALUE(p) = :socialId") - Person getUserBySocialNetworksId(@Param("type2") String type, @Param("socialId") Integer socialNetworksId); - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java b/src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java deleted file mode 100644 index 29b9f61..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.database.entity.SaveUnit; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface SaveUnitRepositoriy extends JpaRepository { -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java b/src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java deleted file mode 100644 index 183a913..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.database.entity.Unit; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface UnitRepositoriy extends JpaRepository { -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/MailService.java b/src/main/java/org/sadtech/autoresponder/database/service/MailService.java deleted file mode 100644 index c5481e1..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/MailService.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -import org.sadtech.autoresponder.database.entity.Mail; - -import java.util.List; - -public interface MailService { - - void addMessage(Mail message); - - List getMessageRange(Long date); -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java b/src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java deleted file mode 100644 index 48ed22f..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -public interface NextUnitService { -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/PersonService.java b/src/main/java/org/sadtech/autoresponder/database/service/PersonService.java deleted file mode 100644 index d044d62..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/PersonService.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -import org.sadtech.autoresponder.database.entity.Person; - -import java.util.Map; - -public interface PersonService { - - void addUser(Person user); - - void removeUser(Long id); - - Person getUserByID(Long id); - - Map getSocialNetwork(Long id); - - Person getUserBySocialNetworksId(String type, Integer socialNetworksId); -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java b/src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java deleted file mode 100644 index 23b0273..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -public interface SaveUnitService { -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/database/service/UnitService.java deleted file mode 100644 index 7fb8e88..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/UnitService.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -import org.sadtech.autoresponder.database.entity.Unit; - -public interface UnitService { - - void addUnit(Unit unit); - - void removeUnit(Long id); - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java deleted file mode 100644 index 3bfada3..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.entity.Mail; -import org.sadtech.autoresponder.database.repository.MailRepository; -import org.sadtech.autoresponder.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/src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java deleted file mode 100644 index 6f52c91..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.repository.NextUnitRepository; -import org.sadtech.autoresponder.database.service.NextUnitService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class NextUnitServiceImpl implements NextUnitService { - - @Autowired - private NextUnitRepository repository; - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java deleted file mode 100644 index 7be8a66..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.repository.PersonRepository; -import org.sadtech.autoresponder.database.entity.Person; -import org.sadtech.autoresponder.database.service.PersonService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Map; - -@Service -public class PersonServiceImpl implements PersonService { - - @Autowired - private PersonRepository repositoriy; - - @Override - public void addUser(Person user) { - repositoriy.saveAndFlush(user); - } - - @Override - public void removeUser(Long id) { - repositoriy.deleteById(id); - } - - @Override - public Person getUserByID(Long id) { - return repositoriy.getOne(id); - } - - @Override - public Map getSocialNetwork(Long id) { - return repositoriy.getOne(id).getSocialNetworks(); - } - - @Override - public Person getUserBySocialNetworksId(String type, Integer socialNetworksId) { - return repositoriy.getUserBySocialNetworksId(type, socialNetworksId); - } -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java deleted file mode 100644 index 603a89c..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.repository.SaveUnitRepositoriy; -import org.sadtech.autoresponder.database.service.SaveUnitService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class SaveUnitServiceImpl implements SaveUnitService { - - @Autowired - private SaveUnitRepositoriy repositoriy; - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java deleted file mode 100644 index 2cdddf2..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.repository.UnitRepositoriy; -import org.sadtech.autoresponder.database.entity.Unit; -import org.sadtech.autoresponder.database.service.UnitService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class UnitServiceImpl implements UnitService { - - @Autowired - private UnitRepositoriy repositoriy; - - public void addUnit(Unit unit) { - repositoriy.saveAndFlush(unit); - } - - public void removeUnit(Long id) { - - } -} diff --git a/src/main/java/org/sadtech/autoresponder/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/entity/Unit.java new file mode 100644 index 0000000..bf3a536 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/entity/Unit.java @@ -0,0 +1,17 @@ +package org.sadtech.autoresponder.entity; + +import lombok.Data; + +import java.util.List; +import java.util.Set; + +@Data +public class Unit { + + private Integer idUnit; + private List nextUnits; + private String answer; + private Integer priority; + private Set keyWords; + +} diff --git a/src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java b/src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java deleted file mode 100644 index ae1fab8..0000000 --- a/src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.sadtech.autoresponder.processing; - -import lombok.extern.log4j.Log4j; -import org.sadtech.autoresponder.database.entity.Mail; -import org.sadtech.autoresponder.MessageSender; -import org.sadtech.autoresponder.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 -public class MessageHandler { - - private MessageLogicService messageLogicService; - private PersonLogicService userLogicService; - private Map senderHashMap = new HashMap<>(); - private long data; - - public MessageHandler(MessageLogicService messageLogicService, PersonLogicService userLogicService) { - this.messageLogicService = messageLogicService; - this.userLogicService = userLogicService; - 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); - 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/src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java b/src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java deleted file mode 100644 index 6301456..0000000 --- a/src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.sadtech.autoresponder.processing; - -import org.sadtech.autoresponder.database.entity.Mail; -import org.sadtech.autoresponder.database.service.MailService; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -public class MessageLogicService { - - private MailService messageService; - - public MessageLogicService(MailService messageService) { - this.messageService = messageService; - } - - public void addMessage(Mail message) { - messageService.addMessage(message); - } - - public List getMessageRange(long data) { - return messageService.getMessageRange(data); - } -} diff --git a/src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java b/src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java deleted file mode 100644 index 211dda8..0000000 --- a/src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.sadtech.autoresponder.processing; - -import lombok.extern.log4j.Log4j; -import org.sadtech.autoresponder.database.entity.Person; -import org.sadtech.autoresponder.database.service.PersonService; -import org.springframework.stereotype.Component; - -@Log4j -@Component -public class PersonLogicService { - - private PersonService personService; - - public PersonLogicService(PersonService userService) { - this.personService = userService; - } - - public void addUser(Person user) { - personService.addUser(user); - log.info("Пользователь добавлен в бд"); - } - - public boolean checkPersonBySocialNetworksId(String socType, Integer socId) { - Person checkPerson = personService.getUserBySocialNetworksId(socType, socId); - if (checkPerson != null) { - log.info("Пользователь уже есть в бд"); - return true; - } - log.info("Пользователя нет в бд"); - return false; - } - - public Person getPersonBySocialNetworksId(Person person) { - for (String key : person.getSocialNetworks().keySet()) { - Person getPerson = personService.getUserBySocialNetworksId(key, person.getSocialNetworks().get(key)); - if (getPerson != null) { - log.info("Пользователь уже есть в бд"); - return getPerson; - } - } - return null; - } - - public Person getUserById(Long id) { - return personService.getUserByID(id); - } - - public Person getUserBySocialId(String type, Integer id) { - return personService.getUserBySocialNetworksId(type, id); - } - -} diff --git a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java new file mode 100644 index 0000000..1d918ac --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java @@ -0,0 +1,16 @@ +package org.sadtech.autoresponder.repository; + +import org.sadtech.autoresponder.entity.Unit; + +import java.util.Collection; + +public interface UnitRepository { + + Unit getUnitById(Integer idUnit); + + void addUnit(Unit unit); + + void addUnits(Collection units); + + void removeUnit(Integer idUnit); +} diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java new file mode 100644 index 0000000..f837ed4 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java @@ -0,0 +1,33 @@ +package org.sadtech.autoresponder.repository.impl; + +import org.sadtech.autoresponder.entity.Unit; +import org.sadtech.autoresponder.repository.UnitRepository; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class UnitRepositoryImpl implements UnitRepository { + + private Map units = new HashMap<>(); + + @Override + public Unit getUnitById(Integer idUnit) { + return units.get(idUnit); + } + + @Override + public void addUnit(Unit unit) { + units.put(unit.getIdUnit(), unit); + } + + @Override + public void addUnits(Collection units) { + units.addAll(units); + } + + @Override + public void removeUnit(Integer idUnit) { + units.remove(idUnit); + } +} diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/service/UnitService.java new file mode 100644 index 0000000..3cf507c --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/service/UnitService.java @@ -0,0 +1,10 @@ +package org.sadtech.autoresponder.service; + +import lombok.NonNull; +import org.sadtech.autoresponder.entity.Unit; + +public interface UnitService { + Unit nextUnit(Unit unit, String message); + + Unit getUnitById(Integer idUnit); +} diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java new file mode 100644 index 0000000..6563755 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java @@ -0,0 +1,42 @@ +package org.sadtech.autoresponder.service.impl; + +import com.sun.istack.internal.NotNull; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import org.sadtech.autoresponder.entity.Unit; +import org.sadtech.autoresponder.repository.UnitRepository; +import org.sadtech.autoresponder.submodule.parser.Parser; +import org.sadtech.autoresponder.service.UnitService; + +import java.util.ArrayList; + +@AllArgsConstructor +public class UnitServiceImpl implements UnitService { + + private UnitRepository unitRepository; + + public Unit nextUnit(@NotNull Unit unit, @NotNull String message) { + ArrayList nextUnits = (ArrayList) unit.getNextUnits(); + Unit unitReturn = new Unit(); + if (nextUnits.size() > 0) { + Parser parser = new Parser(); + parser.setText(message); + parser.parse(); + for (Unit nextUnit : nextUnits) { + if (nextUnit.getKeyWords().retainAll(parser.getWords()) && (nextUnit.getPriority()>unitReturn.getPriority())) { + unitReturn = nextUnit; + } + } + return unitReturn; + } else { + return null; + } + } + + @Override + public Unit getUnitById(@NotNull Integer idUnit) { + return unitRepository.getUnitById(idUnit); + } +} + diff --git a/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java b/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java new file mode 100644 index 0000000..3e64e4b --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java @@ -0,0 +1,26 @@ +package org.sadtech.autoresponder.submodule.parser; + +import lombok.Getter; +import lombok.Setter; + +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Parser { + + @Getter + private Set words; + + @Setter + private String text; + + public void parse() { + Pattern p = Pattern.compile("[а-яА-Я0-9]+"); + Matcher m = p.matcher(text); + while (m.find()) { + words.add(m.group()); + } + } + +} From a8a12bb3f88752f574ebbacf491f09da7397b579 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 12 Jan 2019 14:23:19 +0300 Subject: [PATCH 24/29] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B8=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Добавил класс, который вставляет слова в шаблонную строку Unit * Добавил тесты проверки этого класса * Добавил новый класс Person, который сохраняет текущий Unit --- .../sadtech/autoresponder/Autoresponder.java | 23 ++++++++-- .../sadtech/autoresponder/entity/Person.java | 11 +++++ .../repository/PersonRepository.java | 15 +++++++ .../repository/UnitRepository.java | 2 +- .../repository/impl/PersonRepositoryImpl.java | 31 +++++++++++++ .../repository/impl/UnitRepositoryImpl.java | 4 +- .../autoresponder/service/PersonService.java | 10 +++++ .../autoresponder/service/UnitService.java | 4 ++ .../service/impl/PersonServiceImpl.java | 21 +++++++++ .../service/impl/UnitServiceImpl.java | 7 +-- .../submodule/parser/InsertWords.java | 33 ++++++++++++++ .../submodule/parser/InsertWordsTest.java | 44 +++++++++++++++++++ 12 files changed, 196 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/sadtech/autoresponder/entity/Person.java create mode 100644 src/main/java/org/sadtech/autoresponder/repository/PersonRepository.java create mode 100644 src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java create mode 100644 src/main/java/org/sadtech/autoresponder/service/PersonService.java create mode 100644 src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java create mode 100644 src/main/java/org/sadtech/autoresponder/submodule/parser/InsertWords.java create mode 100644 src/test/java/org/sadtech/autoresponder/submodule/parser/InsertWordsTest.java diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index 254c6e8..b4b7f4b 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -1,17 +1,34 @@ package org.sadtech.autoresponder; +import com.sun.istack.internal.NotNull; import lombok.AllArgsConstructor; +import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.entity.Unit; +import org.sadtech.autoresponder.service.PersonService; import org.sadtech.autoresponder.service.UnitService; +import org.sadtech.autoresponder.submodule.parser.InsertWords; + +import java.util.List; @AllArgsConstructor public class Autoresponder { private UnitService unitService; + private PersonService personService; - public Unit nextUnit(Integer idUnit, String message) { - Unit unit = unitService.getUnitById(idUnit); - return unitService.nextUnit(unit, message); + public String answer(@NotNull Integer idPerson, @NotNull String message) { + Person person = personService.getPersonById(idPerson); + Unit unit = person.getUnit(); + return unitService.nextUnit(unit, message).getAnswer(); + } + + public String answer(@NotNull Integer idPerson, @NotNull String message, @NotNull List words) { + Person person = personService.getPersonById(idPerson); + Unit unit = unitService.nextUnit(person.getUnit(), message); + InsertWords insertWords = new InsertWords(); + insertWords.setInText(unit.getAnswer()); + insertWords.insert(words); + return insertWords.getOutText(); } } diff --git a/src/main/java/org/sadtech/autoresponder/entity/Person.java b/src/main/java/org/sadtech/autoresponder/entity/Person.java new file mode 100644 index 0000000..ab4a6b3 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/entity/Person.java @@ -0,0 +1,11 @@ +package org.sadtech.autoresponder.entity; + +import lombok.Data; + +@Data +public class Person { + + private Integer id; + private Unit unit; + +} diff --git a/src/main/java/org/sadtech/autoresponder/repository/PersonRepository.java b/src/main/java/org/sadtech/autoresponder/repository/PersonRepository.java new file mode 100644 index 0000000..a9c668e --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/repository/PersonRepository.java @@ -0,0 +1,15 @@ +package org.sadtech.autoresponder.repository; + +import org.sadtech.autoresponder.entity.Person; + +import java.util.Collection; +import java.util.Map; + +public interface PersonRepository { + + void addPerson(Person person); + void removePerson(Person person); + void addPersonAll(Map personCollection); + Person getPersonById(Integer idPerson); + +} diff --git a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java index 1d918ac..2b7817e 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java +++ b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java @@ -12,5 +12,5 @@ public interface UnitRepository { void addUnits(Collection units); - void removeUnit(Integer idUnit); + void removeUnit(Unit idUnit); } diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java b/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java new file mode 100644 index 0000000..f6822ff --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java @@ -0,0 +1,31 @@ +package org.sadtech.autoresponder.repository.impl; + +import org.sadtech.autoresponder.entity.Person; +import org.sadtech.autoresponder.repository.PersonRepository; + +import java.util.*; + +public class PersonRepositoryImpl implements PersonRepository { + + Map people = new HashMap<>(); + + @Override + public void addPerson(Person person) { + people.put(person.getId(), person); + } + + @Override + public void removePerson(Person person) { + people.remove(person); + } + + @Override + public void addPersonAll(Map personCollection) { + people.putAll(personCollection); + } + + @Override + public Person getPersonById(Integer idPerson) { + return people.get(idPerson); + } +} diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java index f837ed4..17b73a2 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java +++ b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java @@ -27,7 +27,7 @@ public class UnitRepositoryImpl implements UnitRepository { } @Override - public void removeUnit(Integer idUnit) { - units.remove(idUnit); + public void removeUnit(Unit idUnit) { + units.remove(idUnit.getIdUnit()); } } diff --git a/src/main/java/org/sadtech/autoresponder/service/PersonService.java b/src/main/java/org/sadtech/autoresponder/service/PersonService.java new file mode 100644 index 0000000..66b993a --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/service/PersonService.java @@ -0,0 +1,10 @@ +package org.sadtech.autoresponder.service; + +import org.sadtech.autoresponder.entity.Person; + +public interface PersonService { + + Person getPersonById(Integer integer); + void addPerson(Person person); + +} diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/service/UnitService.java index 3cf507c..326a1ad 100644 --- a/src/main/java/org/sadtech/autoresponder/service/UnitService.java +++ b/src/main/java/org/sadtech/autoresponder/service/UnitService.java @@ -1,10 +1,14 @@ package org.sadtech.autoresponder.service; import lombok.NonNull; +import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.entity.Unit; +import java.util.List; + public interface UnitService { Unit nextUnit(Unit unit, String message); Unit getUnitById(Integer idUnit); + } diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java new file mode 100644 index 0000000..32ed579 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java @@ -0,0 +1,21 @@ +package org.sadtech.autoresponder.service.impl; + +import org.sadtech.autoresponder.entity.Person; +import org.sadtech.autoresponder.repository.PersonRepository; +import org.sadtech.autoresponder.service.PersonService; + +public class PersonServiceImpl implements PersonService { + + private PersonRepository personRepository; + + + @Override + public Person getPersonById(Integer integer) { + return personRepository.getPersonById(integer); + } + + @Override + public void addPerson(Person person) { + personRepository.addPerson(person); + } +} diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java index 6563755..e4b58e9 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java @@ -2,14 +2,13 @@ package org.sadtech.autoresponder.service.impl; import com.sun.istack.internal.NotNull; import lombok.AllArgsConstructor; -import lombok.NonNull; -import lombok.Setter; import org.sadtech.autoresponder.entity.Unit; import org.sadtech.autoresponder.repository.UnitRepository; -import org.sadtech.autoresponder.submodule.parser.Parser; import org.sadtech.autoresponder.service.UnitService; +import org.sadtech.autoresponder.submodule.parser.Parser; import java.util.ArrayList; +import java.util.List; @AllArgsConstructor public class UnitServiceImpl implements UnitService { @@ -38,5 +37,7 @@ public class UnitServiceImpl implements UnitService { public Unit getUnitById(@NotNull Integer idUnit) { return unitRepository.getUnitById(idUnit); } + + } diff --git a/src/main/java/org/sadtech/autoresponder/submodule/parser/InsertWords.java b/src/main/java/org/sadtech/autoresponder/submodule/parser/InsertWords.java new file mode 100644 index 0000000..452e31f --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/submodule/parser/InsertWords.java @@ -0,0 +1,33 @@ +package org.sadtech.autoresponder.submodule.parser; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class InsertWords { + + @Setter + private String inText; + @Getter + private String outText; + + public void insert(List words) { + Pattern pattern = Pattern.compile("\\{(\\d+)}"); // Задаем шаблон + Matcher m = pattern.matcher(inText); // Инициализация Matcher + StringBuffer result = new StringBuffer(); // Буфер для конечного значения + while (m.find()) { // Проверка на совпадение + if (words.get(Integer.parseInt(m.group(1))) != null) { + m.appendReplacement(result, words.get(Integer.parseInt(m.group(1)))); // Подставляем значение из HashMap + } else { + m.appendReplacement(result, m.group(0)); + } + } + m.appendTail(result); // Добавить остаток строки + outText = result.toString(); + } + +} + diff --git a/src/test/java/org/sadtech/autoresponder/submodule/parser/InsertWordsTest.java b/src/test/java/org/sadtech/autoresponder/submodule/parser/InsertWordsTest.java new file mode 100644 index 0000000..f0d74b5 --- /dev/null +++ b/src/test/java/org/sadtech/autoresponder/submodule/parser/InsertWordsTest.java @@ -0,0 +1,44 @@ +package org.sadtech.autoresponder.submodule.parser; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +public class InsertWordsTest { + + private ArrayList arrayList = new ArrayList<>(); + private InsertWords insertWords = new InsertWords(); + + @After + public void setUp() { + + } + + @Test + public void insert() { + insertWords.setInText("Проверка {0} теста"); + arrayList.add("первого"); + insertWords.insert(arrayList); + Assert.assertEquals(insertWords.getOutText(),"Проверка первого теста"); + } + + @Test + public void insert2() { + insertWords.setInText("Проверка {0} теста и {1} {теста}"); + arrayList.add("первого"); + arrayList.add("второго"); + insertWords.insert(arrayList); + Assert.assertEquals(insertWords.getOutText(),"Проверка первого теста и второго {теста}"); + } + + @Test + public void insert3() { + insertWords.setInText("Проверка {1} теста и {0} {теста}"); + arrayList.add("первого"); + arrayList.add("второго"); + insertWords.insert(arrayList); + Assert.assertEquals(insertWords.getOutText(),"Проверка второго теста и первого {теста}"); + } +} \ No newline at end of file From f48f0691295ae6860e33d873c6a175a088550aad Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 14 Jan 2019 01:49:01 +0300 Subject: [PATCH 25/29] =?UTF-8?q?*=20=D0=A2=D0=B5=D1=81=D1=82=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0=20*=20=D0=A2=D0=B5=D1=81?= =?UTF-8?q?=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=B3=D0=BB=D0=B0=D0=B2=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 ++ .../sadtech/autoresponder/Autoresponder.java | 4 +- .../sadtech/autoresponder/entity/Unit.java | 1 + .../service/impl/PersonServiceImpl.java | 3 +- .../service/impl/UnitServiceImpl.java | 10 ++- .../submodule/parser/Parser.java | 5 +- .../autoresponder/AutoresponderTest.java | 76 +++++++++++++++++++ .../submodule/parser/ParserTest.java | 26 +++++++ 8 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 src/test/java/org/sadtech/autoresponder/AutoresponderTest.java create mode 100644 src/test/java/org/sadtech/autoresponder/submodule/parser/ParserTest.java diff --git a/pom.xml b/pom.xml index dd014f0..5473141 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ 1.18.4 1.2.17 4.12 + 2.23.4 @@ -47,6 +48,12 @@ ${junit.ver} test + + org.mockito + mockito-core + ${mocito.ver} + test + diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index b4b7f4b..50cb85f 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -19,7 +19,9 @@ public class Autoresponder { public String answer(@NotNull Integer idPerson, @NotNull String message) { Person person = personService.getPersonById(idPerson); Unit unit = person.getUnit(); - return unitService.nextUnit(unit, message).getAnswer(); + unit = unitService.nextUnit(unit, message); + person.setUnit(unit); + return unit.getAnswer(); } public String answer(@NotNull Integer idPerson, @NotNull String message, @NotNull List words) { diff --git a/src/main/java/org/sadtech/autoresponder/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/entity/Unit.java index bf3a536..3e3add3 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/Unit.java +++ b/src/main/java/org/sadtech/autoresponder/entity/Unit.java @@ -13,5 +13,6 @@ public class Unit { private String answer; private Integer priority; private Set keyWords; + private Integer matchThreshold; } diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java index 32ed579..0d41eb1 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java @@ -1,14 +1,15 @@ package org.sadtech.autoresponder.service.impl; +import lombok.AllArgsConstructor; import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.repository.PersonRepository; import org.sadtech.autoresponder.service.PersonService; +@AllArgsConstructor public class PersonServiceImpl implements PersonService { private PersonRepository personRepository; - @Override public Person getPersonById(Integer integer) { return personRepository.getPersonById(integer); diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java index e4b58e9..b209f6b 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java @@ -2,14 +2,19 @@ package org.sadtech.autoresponder.service.impl; import com.sun.istack.internal.NotNull; import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j; +import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.entity.Unit; import org.sadtech.autoresponder.repository.UnitRepository; import org.sadtech.autoresponder.service.UnitService; import org.sadtech.autoresponder.submodule.parser.Parser; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; +@Log4j @AllArgsConstructor public class UnitServiceImpl implements UnitService { @@ -17,13 +22,14 @@ public class UnitServiceImpl implements UnitService { public Unit nextUnit(@NotNull Unit unit, @NotNull String message) { ArrayList nextUnits = (ArrayList) unit.getNextUnits(); - Unit unitReturn = new Unit(); if (nextUnits.size() > 0) { Parser parser = new Parser(); parser.setText(message); parser.parse(); + Unit unitReturn = new Unit(); + unitReturn.setPriority(0); for (Unit nextUnit : nextUnits) { - if (nextUnit.getKeyWords().retainAll(parser.getWords()) && (nextUnit.getPriority()>unitReturn.getPriority())) { + if (!Collections.disjoint(nextUnit.getKeyWords(), parser.getWords()) && (nextUnit.getPriority()>unitReturn.getPriority())) { unitReturn = nextUnit; } } diff --git a/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java b/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java index 3e64e4b..d0bb508 100644 --- a/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java +++ b/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java @@ -3,6 +3,7 @@ package org.sadtech.autoresponder.submodule.parser; import lombok.Getter; import lombok.Setter; +import java.util.HashSet; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -10,7 +11,7 @@ import java.util.regex.Pattern; public class Parser { @Getter - private Set words; + private Set words = new HashSet<>(); @Setter private String text; @@ -19,7 +20,7 @@ public class Parser { Pattern p = Pattern.compile("[а-яА-Я0-9]+"); Matcher m = p.matcher(text); while (m.find()) { - words.add(m.group()); + words.add(m.group().toLowerCase()); } } diff --git a/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java new file mode 100644 index 0000000..5a95f98 --- /dev/null +++ b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java @@ -0,0 +1,76 @@ +package org.sadtech.autoresponder; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.sadtech.autoresponder.entity.Person; +import org.sadtech.autoresponder.entity.Unit; +import org.sadtech.autoresponder.repository.impl.PersonRepositoryImpl; +import org.sadtech.autoresponder.repository.impl.UnitRepositoryImpl; +import org.sadtech.autoresponder.service.impl.PersonServiceImpl; +import org.sadtech.autoresponder.service.impl.UnitServiceImpl; + +import java.util.ArrayList; +import java.util.HashSet; + +import static org.junit.Assert.*; + +public class AutoresponderTest { + + private Person person = new Person(); + private Unit unit = new Unit(); + private Unit unit2 = new Unit(); + private HashSet words = new HashSet<>(); + private ArrayList units = new ArrayList<>(); + private UnitRepositoryImpl unitRepository = new UnitRepositoryImpl(); + private PersonRepositoryImpl personRepository = new PersonRepositoryImpl(); + + private UnitServiceImpl unitService = new UnitServiceImpl(unitRepository); + private PersonServiceImpl personService = new PersonServiceImpl(personRepository); + private Autoresponder autoresponder = new Autoresponder(unitService, personService); + + + @Before + public void before() { + words.add("тест"); + + unit.setIdUnit(1); + unit.setMatchThreshold(100); + + units.add(unit2); + + unit.setNextUnits(units); + + unit2.setIdUnit(2); + unit2.setAnswer("Ответ с {0} параметрами!"); + unit2.setPriority(100); + unit2.setKeyWords(words); + unit2.setMatchThreshold(100); + + person.setUnit(unit); + person.setId(1); + + unitRepository.addUnit(unit); + unitRepository.addUnit(unit2); + personRepository.addPerson(person); + } + + @Test + public void answer() { + Assert.assertEquals(autoresponder.answer(person.getId(), "Привет это тест срабатывания"), "Ответ с {0} параметрами!"); + } + + @Test + public void answer1() { + ArrayList words = new ArrayList<>(); + words.add("одним"); + Assert.assertEquals(autoresponder.answer(person.getId(), "Привет это тест срабатывания", words), "Ответ с одним параметрами!"); + } + + @Test + public void answer2() { + String test = autoresponder.answer(person.getId(), "Привет это срабатывания"); + Assert.assertNull(test); + } +} \ No newline at end of file diff --git a/src/test/java/org/sadtech/autoresponder/submodule/parser/ParserTest.java b/src/test/java/org/sadtech/autoresponder/submodule/parser/ParserTest.java new file mode 100644 index 0000000..402a24a --- /dev/null +++ b/src/test/java/org/sadtech/autoresponder/submodule/parser/ParserTest.java @@ -0,0 +1,26 @@ +package org.sadtech.autoresponder.submodule.parser; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.*; + +public class ParserTest { + + private Parser parser = new Parser(); + private Set words = new HashSet<>(); + + @Test + public void parse() { + parser.setText("Проверка парсера на правильность"); + parser.parse(); + words.add("проверка"); + words.add("парсера"); + words.add("на"); + words.add("правильность"); + Assert.assertEquals(parser.getWords(), words); + } +} \ No newline at end of file From 386b2265c6d31824992b0fcd74580fdc2855878c Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 14 Jan 2019 14:09:03 +0300 Subject: [PATCH 26/29] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=B8=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * В Api внедрил проверку существования юзера и его добавление * В Unit добавленно новое поле для формирвоания меню * Исправления методов доступа * Настроена логика формирования меню * Добавлен новый метод проверки существования Person * Продолжаю покрытие тестами Api --- .../sadtech/autoresponder/Autoresponder.java | 24 +++++-- .../sadtech/autoresponder/entity/Unit.java | 1 + .../repository/UnitRepository.java | 3 + .../repository/impl/PersonRepositoryImpl.java | 2 +- .../repository/impl/UnitRepositoryImpl.java | 15 ++++- .../autoresponder/service/PersonService.java | 1 + .../autoresponder/service/UnitService.java | 6 +- .../service/impl/PersonServiceImpl.java | 5 ++ .../service/impl/UnitServiceImpl.java | 15 +++-- .../submodule/parser/InsertWords.java | 2 +- .../autoresponder/AutoresponderTest.java | 64 +++++++++++++++++-- 11 files changed, 115 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index 50cb85f..d895efe 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -17,15 +17,19 @@ public class Autoresponder { private PersonService personService; public String answer(@NotNull Integer idPerson, @NotNull String message) { - Person person = personService.getPersonById(idPerson); - Unit unit = person.getUnit(); - unit = unitService.nextUnit(unit, message); + Person person = addPerson(idPerson); + Unit unit; + if (person.getUnit() == null) { + unit = unitService.nextUnit(unitService.menuUnit(), message); + } else { + unit = unitService.nextUnit(person.getUnit(), message); + } person.setUnit(unit); return unit.getAnswer(); } public String answer(@NotNull Integer idPerson, @NotNull String message, @NotNull List words) { - Person person = personService.getPersonById(idPerson); + Person person = addPerson(idPerson); Unit unit = unitService.nextUnit(person.getUnit(), message); InsertWords insertWords = new InsertWords(); insertWords.setInText(unit.getAnswer()); @@ -33,4 +37,16 @@ public class Autoresponder { return insertWords.getOutText(); } + private Person addPerson(Integer idPerson) { + Person person; + if (personService.checkPerson(idPerson)) { + person = personService.getPersonById(idPerson); + } else { + person = new Person(); + person.setId(idPerson); + personService.addPerson(person); + } + return person; + } + } diff --git a/src/main/java/org/sadtech/autoresponder/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/entity/Unit.java index 3e3add3..18f408c 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/Unit.java +++ b/src/main/java/org/sadtech/autoresponder/entity/Unit.java @@ -14,5 +14,6 @@ public class Unit { private Integer priority; private Set keyWords; private Integer matchThreshold; + private Boolean level = false; } diff --git a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java index 2b7817e..0f4679a 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java +++ b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java @@ -3,6 +3,7 @@ package org.sadtech.autoresponder.repository; import org.sadtech.autoresponder.entity.Unit; import java.util.Collection; +import java.util.List; public interface UnitRepository { @@ -13,4 +14,6 @@ public interface UnitRepository { void addUnits(Collection units); void removeUnit(Unit idUnit); + + List menuUnits(); } diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java b/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java index f6822ff..8e48c26 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java +++ b/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java @@ -7,7 +7,7 @@ import java.util.*; public class PersonRepositoryImpl implements PersonRepository { - Map people = new HashMap<>(); + private Map people = new HashMap<>(); @Override public void addPerson(Person person) { diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java index 17b73a2..a9c58e0 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java +++ b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java @@ -3,9 +3,7 @@ package org.sadtech.autoresponder.repository.impl; import org.sadtech.autoresponder.entity.Unit; import org.sadtech.autoresponder.repository.UnitRepository; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.*; public class UnitRepositoryImpl implements UnitRepository { @@ -30,4 +28,15 @@ public class UnitRepositoryImpl implements UnitRepository { public void removeUnit(Unit idUnit) { units.remove(idUnit.getIdUnit()); } + + @Override + public List menuUnits() { + ArrayList unitsMenu = new ArrayList<>(); + for (Integer integer : units.keySet()) { + if (units.get(integer).getLevel()) { + unitsMenu.add(units.get(integer)); + } + } + return unitsMenu; + } } diff --git a/src/main/java/org/sadtech/autoresponder/service/PersonService.java b/src/main/java/org/sadtech/autoresponder/service/PersonService.java index 66b993a..da46400 100644 --- a/src/main/java/org/sadtech/autoresponder/service/PersonService.java +++ b/src/main/java/org/sadtech/autoresponder/service/PersonService.java @@ -6,5 +6,6 @@ public interface PersonService { Person getPersonById(Integer integer); void addPerson(Person person); + boolean checkPerson(Integer idPerson); } diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/service/UnitService.java index 326a1ad..42e6c4f 100644 --- a/src/main/java/org/sadtech/autoresponder/service/UnitService.java +++ b/src/main/java/org/sadtech/autoresponder/service/UnitService.java @@ -1,14 +1,12 @@ package org.sadtech.autoresponder.service; -import lombok.NonNull; -import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.entity.Unit; -import java.util.List; - public interface UnitService { Unit nextUnit(Unit unit, String message); Unit getUnitById(Integer idUnit); + Unit menuUnit(); + } diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java index 0d41eb1..5325b22 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java @@ -19,4 +19,9 @@ public class PersonServiceImpl implements PersonService { public void addPerson(Person person) { personRepository.addPerson(person); } + + @Override + public boolean checkPerson(Integer idPerson) { + return personRepository.getPersonById(idPerson) != null; + } } diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java index b209f6b..3d88777 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java @@ -3,16 +3,13 @@ package org.sadtech.autoresponder.service.impl; import com.sun.istack.internal.NotNull; import lombok.AllArgsConstructor; import lombok.extern.log4j.Log4j; -import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.entity.Unit; import org.sadtech.autoresponder.repository.UnitRepository; import org.sadtech.autoresponder.service.UnitService; import org.sadtech.autoresponder.submodule.parser.Parser; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.List; @Log4j @AllArgsConstructor @@ -20,7 +17,7 @@ public class UnitServiceImpl implements UnitService { private UnitRepository unitRepository; - public Unit nextUnit(@NotNull Unit unit, @NotNull String message) { + public Unit nextUnit(Unit unit, @NotNull String message) { ArrayList nextUnits = (ArrayList) unit.getNextUnits(); if (nextUnits.size() > 0) { Parser parser = new Parser(); @@ -29,7 +26,7 @@ public class UnitServiceImpl implements UnitService { Unit unitReturn = new Unit(); unitReturn.setPriority(0); for (Unit nextUnit : nextUnits) { - if (!Collections.disjoint(nextUnit.getKeyWords(), parser.getWords()) && (nextUnit.getPriority()>unitReturn.getPriority())) { + if (!Collections.disjoint(nextUnit.getKeyWords(), parser.getWords()) && (nextUnit.getPriority() > unitReturn.getPriority())) { unitReturn = nextUnit; } } @@ -37,6 +34,7 @@ public class UnitServiceImpl implements UnitService { } else { return null; } + } @Override @@ -44,6 +42,13 @@ public class UnitServiceImpl implements UnitService { return unitRepository.getUnitById(idUnit); } + @Override + public Unit menuUnit() { + Unit menuUnit = new Unit(); + menuUnit.setNextUnits(unitRepository.menuUnits()); + return menuUnit; + } + } diff --git a/src/main/java/org/sadtech/autoresponder/submodule/parser/InsertWords.java b/src/main/java/org/sadtech/autoresponder/submodule/parser/InsertWords.java index 452e31f..f44889e 100644 --- a/src/main/java/org/sadtech/autoresponder/submodule/parser/InsertWords.java +++ b/src/main/java/org/sadtech/autoresponder/submodule/parser/InsertWords.java @@ -19,7 +19,7 @@ public class InsertWords { Matcher m = pattern.matcher(inText); // Инициализация Matcher StringBuffer result = new StringBuffer(); // Буфер для конечного значения while (m.find()) { // Проверка на совпадение - if (words.get(Integer.parseInt(m.group(1))) != null) { + if (Integer.parseInt(m.group(1)) < words.size()) { m.appendReplacement(result, words.get(Integer.parseInt(m.group(1)))); // Подставляем значение из HashMap } else { m.appendReplacement(result, m.group(0)); diff --git a/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java index 5a95f98..63c2ad4 100644 --- a/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java +++ b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java @@ -21,7 +21,7 @@ public class AutoresponderTest { private Person person = new Person(); private Unit unit = new Unit(); private Unit unit2 = new Unit(); - private HashSet words = new HashSet<>(); + private Unit unit3 = new Unit(); private ArrayList units = new ArrayList<>(); private UnitRepositoryImpl unitRepository = new UnitRepositoryImpl(); private PersonRepositoryImpl personRepository = new PersonRepositoryImpl(); @@ -33,21 +33,36 @@ public class AutoresponderTest { @Before public void before() { + HashSet words = new HashSet<>(); + HashSet words2 = new HashSet<>(); words.add("тест"); + words2.add("тест"); + words2.add("привет"); unit.setIdUnit(1); + unit.setLevel(true); + unit.setPriority(50); + unit.setKeyWords(words); + unit.setAnswer("Здравствуйте, вы написали в нашу компанию!"); unit.setMatchThreshold(100); units.add(unit2); + units.add(unit3); unit.setNextUnits(units); unit2.setIdUnit(2); unit2.setAnswer("Ответ с {0} параметрами!"); - unit2.setPriority(100); + unit2.setPriority(60); unit2.setKeyWords(words); unit2.setMatchThreshold(100); + unit3.setIdUnit(3); + unit3.setAnswer("Второй Ответ с {0} параметрами!"); + unit3.setPriority(50); + unit3.setKeyWords(words2); + unit3.setMatchThreshold(100); + person.setUnit(unit); person.setId(1); @@ -57,20 +72,59 @@ public class AutoresponderTest { } @Test - public void answer() { + public void usualAnswer() { Assert.assertEquals(autoresponder.answer(person.getId(), "Привет это тест срабатывания"), "Ответ с {0} параметрами!"); } @Test - public void answer1() { + public void answerOneParameter() { ArrayList words = new ArrayList<>(); words.add("одним"); Assert.assertEquals(autoresponder.answer(person.getId(), "Привет это тест срабатывания", words), "Ответ с одним параметрами!"); } @Test - public void answer2() { + public void NoAnswer() { String test = autoresponder.answer(person.getId(), "Привет это срабатывания"); Assert.assertNull(test); } + + @Test + public void answerTwoParameter() { + ArrayList words = new ArrayList<>(); + words.add("одним"); + words.add("двумя"); + unit2.setAnswer("Ответ с {0} и {1}"); + Assert.assertEquals(autoresponder.answer(person.getId(), "Привет это тест срабатывания", words), "Ответ с одним и двумя"); + } + + @Test + public void incorrectSettingsWords() { + ArrayList words = new ArrayList<>(); + words.add("одним"); + words.add("двумя"); + unit2.setAnswer("Ответ с {1} и {3}"); + Assert.assertEquals(autoresponder.answer(person.getId(), "Привет это тест срабатывания", words), "Ответ с двумя и {3}"); + } + + @Test + public void answerRepeatSingleParameter() { + ArrayList words = new ArrayList<>(); + words.add("одним"); + words.add("двумя"); + unit2.setAnswer("Ответ с {1} и {1}"); + Assert.assertEquals(autoresponder.answer(person.getId(), "Привет это тест срабатывания", words), "Ответ с двумя и двумя"); + } + + @Test + public void answerByPriority() { + Assert.assertEquals(autoresponder.answer(person.getId(), "Привет это тест срабатывания"), "Ответ с {0} параметрами!"); + } + + @Test + public void answerNoPerson() { + Assert.assertEquals(autoresponder.answer(100, "Привет это тест срабатывания"), "Здравствуйте, вы написали в нашу компанию!"); + Assert.assertEquals(autoresponder.answer(100, "Привет это тест срабатывания"), "Ответ с {0} параметрами!"); + + } } \ No newline at end of file From 687954f799527d0f8986e7769928706c0e787630 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 14 Jan 2019 15:27:56 +0300 Subject: [PATCH 27/29] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D1=8B=D0=B5=20=D0=BA=D0=BE=D1=81=D0=BC=D0=B5=D1=82=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D1=83=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D1=88=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Немного изменил логику работы метода, который вставляет параметры в текст ответа --- .../java/org/sadtech/autoresponder/Autoresponder.java | 9 ++++----- .../org/sadtech/autoresponder/AutoresponderTest.java | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index d895efe..d30ea01 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -17,7 +17,7 @@ public class Autoresponder { private PersonService personService; public String answer(@NotNull Integer idPerson, @NotNull String message) { - Person person = addPerson(idPerson); + Person person = CheckAndAddPerson(idPerson); Unit unit; if (person.getUnit() == null) { unit = unitService.nextUnit(unitService.menuUnit(), message); @@ -29,15 +29,14 @@ public class Autoresponder { } public String answer(@NotNull Integer idPerson, @NotNull String message, @NotNull List words) { - Person person = addPerson(idPerson); - Unit unit = unitService.nextUnit(person.getUnit(), message); + String answer = answer(idPerson, message); InsertWords insertWords = new InsertWords(); - insertWords.setInText(unit.getAnswer()); + insertWords.setInText(answer); insertWords.insert(words); return insertWords.getOutText(); } - private Person addPerson(Integer idPerson) { + private Person CheckAndAddPerson(Integer idPerson) { Person person; if (personService.checkPerson(idPerson)) { person = personService.getPersonById(idPerson); diff --git a/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java index 63c2ad4..81ec996 100644 --- a/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java +++ b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java @@ -85,6 +85,7 @@ public class AutoresponderTest { @Test public void NoAnswer() { + person.setUnit(null); String test = autoresponder.answer(person.getId(), "Привет это срабатывания"); Assert.assertNull(test); } @@ -125,6 +126,5 @@ public class AutoresponderTest { public void answerNoPerson() { Assert.assertEquals(autoresponder.answer(100, "Привет это тест срабатывания"), "Здравствуйте, вы написали в нашу компанию!"); Assert.assertEquals(autoresponder.answer(100, "Привет это тест срабатывания"), "Ответ с {0} параметрами!"); - } } \ No newline at end of file From 59e4bcd2732ede37de2884e4e7ef612bab9294b9 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 14 Jan 2019 15:35:53 +0300 Subject: [PATCH 28/29] Release 1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Первый релиз. Возможности 1) Автоматический ответ на выбор по ключевым словам пользователя 2) Вставка слов в ответ от пользоваетля 3) Добавление пользователя, если его не было 4) Формирование меню --- pom.xml | 2 +- .../{PersonRepositoryImpl.java => PersonRepositoryMap.java} | 0 .../impl/{UnitRepositoryImpl.java => UnitRepositoryMap.java} | 0 .../java/org/sadtech/autoresponder/service/PersonService.java | 2 ++ .../java/org/sadtech/autoresponder/service/UnitService.java | 1 + 5 files changed, 4 insertions(+), 1 deletion(-) rename src/main/java/org/sadtech/autoresponder/repository/impl/{PersonRepositoryImpl.java => PersonRepositoryMap.java} (100%) rename src/main/java/org/sadtech/autoresponder/repository/impl/{UnitRepositoryImpl.java => UnitRepositoryMap.java} (100%) diff --git a/pom.xml b/pom.xml index 5473141..0763275 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.autoresponder core - 0.1-SNAPSHOT + 1.0 diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java b/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java similarity index 100% rename from src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryImpl.java rename to src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryMap.java similarity index 100% rename from src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java rename to src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryMap.java diff --git a/src/main/java/org/sadtech/autoresponder/service/PersonService.java b/src/main/java/org/sadtech/autoresponder/service/PersonService.java index da46400..ae963e4 100644 --- a/src/main/java/org/sadtech/autoresponder/service/PersonService.java +++ b/src/main/java/org/sadtech/autoresponder/service/PersonService.java @@ -5,7 +5,9 @@ import org.sadtech.autoresponder.entity.Person; public interface PersonService { Person getPersonById(Integer integer); + void addPerson(Person person); + boolean checkPerson(Integer idPerson); } diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/service/UnitService.java index 42e6c4f..c319e0e 100644 --- a/src/main/java/org/sadtech/autoresponder/service/UnitService.java +++ b/src/main/java/org/sadtech/autoresponder/service/UnitService.java @@ -3,6 +3,7 @@ package org.sadtech.autoresponder.service; import org.sadtech.autoresponder.entity.Unit; public interface UnitService { + Unit nextUnit(Unit unit, String message); Unit getUnitById(Integer idUnit); From 534bc12c8c3caf0fc2efe0355e8f79360fd26410 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 14 Jan 2019 15:36:07 +0300 Subject: [PATCH 29/29] Rename Impl --- .../repository/impl/PersonRepositoryMap.java | 2 +- .../repository/impl/UnitRepositoryMap.java | 2 +- .../org/sadtech/autoresponder/AutoresponderTest.java | 11 ++++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java b/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java index 8e48c26..d831350 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java +++ b/src/main/java/org/sadtech/autoresponder/repository/impl/PersonRepositoryMap.java @@ -5,7 +5,7 @@ import org.sadtech.autoresponder.repository.PersonRepository; import java.util.*; -public class PersonRepositoryImpl implements PersonRepository { +public class PersonRepositoryMap implements PersonRepository { private Map people = new HashMap<>(); diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryMap.java b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryMap.java index a9c58e0..7ed7c7e 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryMap.java +++ b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryMap.java @@ -5,7 +5,7 @@ import org.sadtech.autoresponder.repository.UnitRepository; import java.util.*; -public class UnitRepositoryImpl implements UnitRepository { +public class UnitRepositoryMap implements UnitRepository { private Map units = new HashMap<>(); diff --git a/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java index 81ec996..7d79844 100644 --- a/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java +++ b/src/test/java/org/sadtech/autoresponder/AutoresponderTest.java @@ -2,20 +2,17 @@ package org.sadtech.autoresponder; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.entity.Unit; -import org.sadtech.autoresponder.repository.impl.PersonRepositoryImpl; -import org.sadtech.autoresponder.repository.impl.UnitRepositoryImpl; +import org.sadtech.autoresponder.repository.impl.PersonRepositoryMap; +import org.sadtech.autoresponder.repository.impl.UnitRepositoryMap; import org.sadtech.autoresponder.service.impl.PersonServiceImpl; import org.sadtech.autoresponder.service.impl.UnitServiceImpl; import java.util.ArrayList; import java.util.HashSet; -import static org.junit.Assert.*; - public class AutoresponderTest { private Person person = new Person(); @@ -23,8 +20,8 @@ public class AutoresponderTest { private Unit unit2 = new Unit(); private Unit unit3 = new Unit(); private ArrayList units = new ArrayList<>(); - private UnitRepositoryImpl unitRepository = new UnitRepositoryImpl(); - private PersonRepositoryImpl personRepository = new PersonRepositoryImpl(); + private UnitRepositoryMap unitRepository = new UnitRepositoryMap(); + private PersonRepositoryMap personRepository = new PersonRepositoryMap(); private UnitServiceImpl unitService = new UnitServiceImpl(unitRepository); private PersonServiceImpl personService = new PersonServiceImpl(personRepository);