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); - -}