From 85a9849c0acef68eaa81db69d17779ac3c292879 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 7 Feb 2019 00:05:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=83=20=D0=BD=D0=B0=D0=B4=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=BE=D0=B9=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B5=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../distribution/impl/CommentSubscriber.java | 25 +++++++++++++++---- .../distribution/impl/MailChatSubscriber.java | 2 +- .../distribution/impl/MailSubscriber.java | 2 +- .../distribution/impl/TerminalSubscriber.java | 2 +- .../sadtech/vkbot/core/entity/Comment.java | 6 +++++ .../core/repository/CommentRepository.java | 9 +++++++ .../impl/CommentRepositoryList.java | 17 +++++++++++++ .../service/distribution/CommentService.java | 10 ++++++++ .../service/distribution/MailService.java | 11 ++++++++ .../SortEventService.java | 2 +- .../distribution/impl/CommentServiceImpl.java | 19 ++++++++++++++ .../distribution/impl/EventService.java | 7 ++++++ .../impl/MailServiceImpl.java | 4 +-- .../core/service/handlers/MailService.java | 12 --------- 14 files changed, 105 insertions(+), 23 deletions(-) create mode 100644 src/main/java/org/sadtech/vkbot/core/repository/CommentRepository.java create mode 100644 src/main/java/org/sadtech/vkbot/core/repository/impl/CommentRepositoryList.java create mode 100644 src/main/java/org/sadtech/vkbot/core/service/distribution/CommentService.java create mode 100644 src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java rename src/main/java/org/sadtech/vkbot/core/service/{handlers => distribution}/SortEventService.java (82%) create mode 100644 src/main/java/org/sadtech/vkbot/core/service/distribution/impl/CommentServiceImpl.java create mode 100644 src/main/java/org/sadtech/vkbot/core/service/distribution/impl/EventService.java rename src/main/java/org/sadtech/vkbot/core/service/{handlers => distribution}/impl/MailServiceImpl.java (96%) delete mode 100644 src/main/java/org/sadtech/vkbot/core/service/handlers/MailService.java diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/impl/CommentSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/impl/CommentSubscriber.java index 7800ef8..729fd8a 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/impl/CommentSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/impl/CommentSubscriber.java @@ -1,13 +1,28 @@ package org.sadtech.vkbot.core.distribution.impl; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.vk.api.sdk.objects.wall.WallComment; +import org.apache.log4j.Logger; +import org.sadtech.vkbot.core.distribution.EventDistributable; import org.sadtech.vkbot.core.distribution.EventSubscribe; -import org.sadtech.vkbot.core.entity.Comment; +import org.sadtech.vkbot.core.service.distribution.CommentService; -public class CommentSubscriber implements EventSubscribe { - +public class CommentSubscriber implements EventSubscribe { + + public static final Logger log = Logger.getLogger(CommentSubscriber.class); + + private CommentService commentService; + + public CommentSubscriber(EventDistributable distributable, CommentService commentService) { + distributable.registerSubscriber("wall_reply_new", this); + this.commentService = commentService; + } @Override - public void update(Comment object) { - + public void update(JsonObject object) { + Gson gson = new Gson(); + WallComment wallComment = gson.fromJson(object, WallComment.class); + log.info(wallComment); } } diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailChatSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailChatSubscriber.java index 00c6fcc..9ed0c9d 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailChatSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailChatSubscriber.java @@ -3,7 +3,7 @@ package org.sadtech.vkbot.core.distribution.impl; import com.vk.api.sdk.objects.messages.Message; import org.sadtech.vkbot.core.distribution.EventDistributable; import org.sadtech.vkbot.core.distribution.EventSubscribe; -import org.sadtech.vkbot.core.service.handlers.MailService; +import org.sadtech.vkbot.core.service.distribution.MailService; public class MailChatSubscriber implements EventSubscribe { diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java index f55e9e4..a9675a1 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java @@ -6,7 +6,7 @@ import com.vk.api.sdk.objects.messages.Message; import org.apache.log4j.Logger; import org.sadtech.vkbot.core.distribution.EventDistributable; import org.sadtech.vkbot.core.distribution.EventSubscribe; -import org.sadtech.vkbot.core.service.handlers.MailService; +import org.sadtech.vkbot.core.service.distribution.MailService; import java.util.HashMap; import java.util.HashSet; diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/impl/TerminalSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/impl/TerminalSubscriber.java index 2ef8efb..75b4f7d 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/impl/TerminalSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/impl/TerminalSubscriber.java @@ -3,7 +3,7 @@ package org.sadtech.vkbot.core.distribution.impl; import com.vk.api.sdk.objects.messages.Message; import org.apache.log4j.Logger; import org.sadtech.vkbot.core.distribution.EventSubscribe; -import org.sadtech.vkbot.core.service.handlers.MailService; +import org.sadtech.vkbot.core.service.distribution.MailService; public class TerminalSubscriber implements EventSubscribe { diff --git a/src/main/java/org/sadtech/vkbot/core/entity/Comment.java b/src/main/java/org/sadtech/vkbot/core/entity/Comment.java index ebb76d9..c536f61 100644 --- a/src/main/java/org/sadtech/vkbot/core/entity/Comment.java +++ b/src/main/java/org/sadtech/vkbot/core/entity/Comment.java @@ -1,4 +1,10 @@ package org.sadtech.vkbot.core.entity; public class Comment { + + private Integer postId; + private Integer fromId; + private String text; + private Integer data; + } diff --git a/src/main/java/org/sadtech/vkbot/core/repository/CommentRepository.java b/src/main/java/org/sadtech/vkbot/core/repository/CommentRepository.java new file mode 100644 index 0000000..bd9bbf0 --- /dev/null +++ b/src/main/java/org/sadtech/vkbot/core/repository/CommentRepository.java @@ -0,0 +1,9 @@ +package org.sadtech.vkbot.core.repository; + +import org.sadtech.vkbot.core.entity.Comment; + +public interface CommentRepository { + + void add(Comment comment); + +} diff --git a/src/main/java/org/sadtech/vkbot/core/repository/impl/CommentRepositoryList.java b/src/main/java/org/sadtech/vkbot/core/repository/impl/CommentRepositoryList.java new file mode 100644 index 0000000..e460d1d --- /dev/null +++ b/src/main/java/org/sadtech/vkbot/core/repository/impl/CommentRepositoryList.java @@ -0,0 +1,17 @@ +package org.sadtech.vkbot.core.repository.impl; + +import org.sadtech.vkbot.core.entity.Comment; +import org.sadtech.vkbot.core.repository.CommentRepository; + +import java.util.ArrayList; +import java.util.List; + +public class CommentRepositoryList implements CommentRepository { + + private List comments = new ArrayList<>(); + + @Override + public void add(Comment comment) { + comments.add(comment); + } +} diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/CommentService.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/CommentService.java new file mode 100644 index 0000000..8aaafc3 --- /dev/null +++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/CommentService.java @@ -0,0 +1,10 @@ +package org.sadtech.vkbot.core.service.distribution; + +import org.sadtech.vkbot.core.entity.Comment; +import org.sadtech.vkbot.core.service.distribution.impl.EventService; + +public interface CommentService extends EventService { + + + +} diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java new file mode 100644 index 0000000..c860c88 --- /dev/null +++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java @@ -0,0 +1,11 @@ +package org.sadtech.vkbot.core.service.distribution; + +import com.vk.api.sdk.objects.messages.Message; +import org.sadtech.vkbot.core.entity.Mail; +import org.sadtech.vkbot.core.service.distribution.impl.EventService; + +public interface MailService extends EventService, SortEventService { + + void add(Message message); + +} diff --git a/src/main/java/org/sadtech/vkbot/core/service/handlers/SortEventService.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/SortEventService.java similarity index 82% rename from src/main/java/org/sadtech/vkbot/core/service/handlers/SortEventService.java rename to src/main/java/org/sadtech/vkbot/core/service/distribution/SortEventService.java index 9979287..d24b5ce 100644 --- a/src/main/java/org/sadtech/vkbot/core/service/handlers/SortEventService.java +++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/SortEventService.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.core.service.handlers; +package org.sadtech.vkbot.core.service.distribution; import java.util.List; diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/CommentServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/CommentServiceImpl.java new file mode 100644 index 0000000..39c5cfe --- /dev/null +++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/CommentServiceImpl.java @@ -0,0 +1,19 @@ +package org.sadtech.vkbot.core.service.distribution.impl; + +import org.sadtech.vkbot.core.entity.Comment; +import org.sadtech.vkbot.core.repository.CommentRepository; +import org.sadtech.vkbot.core.service.distribution.CommentService; + +public class CommentServiceImpl implements CommentService { + + private CommentRepository commentRepository; + + public CommentServiceImpl(CommentRepository commentRepository) { + this.commentRepository = commentRepository; + } + + @Override + public void add(Comment comment) { + commentRepository.add(comment); + } +} diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/EventService.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/EventService.java new file mode 100644 index 0000000..99bf15e --- /dev/null +++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/EventService.java @@ -0,0 +1,7 @@ +package org.sadtech.vkbot.core.service.distribution.impl; + +public interface EventService { + + void add(T event); + +} diff --git a/src/main/java/org/sadtech/vkbot/core/service/handlers/impl/MailServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java similarity index 96% rename from src/main/java/org/sadtech/vkbot/core/service/handlers/impl/MailServiceImpl.java rename to src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java index 2d26725..e589207 100644 --- a/src/main/java/org/sadtech/vkbot/core/service/handlers/impl/MailServiceImpl.java +++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java @@ -1,4 +1,4 @@ -package org.sadtech.vkbot.core.service.handlers.impl; +package org.sadtech.vkbot.core.service.distribution.impl; import com.vk.api.sdk.objects.messages.Message; import org.apache.log4j.Logger; @@ -7,7 +7,7 @@ import org.sadtech.vkbot.core.entity.Person; import org.sadtech.vkbot.core.repository.MailRepository; import org.sadtech.vkbot.core.repository.impl.MailRepositoryList; import org.sadtech.vkbot.core.service.PersonService; -import org.sadtech.vkbot.core.service.handlers.MailService; +import org.sadtech.vkbot.core.service.distribution.MailService; import java.util.ArrayList; import java.util.HashSet; diff --git a/src/main/java/org/sadtech/vkbot/core/service/handlers/MailService.java b/src/main/java/org/sadtech/vkbot/core/service/handlers/MailService.java deleted file mode 100644 index 89ac658..0000000 --- a/src/main/java/org/sadtech/vkbot/core/service/handlers/MailService.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.sadtech.vkbot.core.service.handlers; - -import com.vk.api.sdk.objects.messages.Message; -import org.sadtech.vkbot.core.entity.Mail; - -public interface MailService extends SortEventService { - - void add(Mail mail); - - void add(Message message); - -}