From 809d17715e9075e7e0eecfe1a2539b81a3604271 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 7 Feb 2019 02:26:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B0=D0=B2=D1=82=D0=BE=D0=BE=D1=82=D0=B2?= =?UTF-8?q?=D0=B5=D1=82=D1=87=D0=B8=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Чтобы можно было реализовать автоответчики для комментариев и прочего --- .../distribution/impl/EventDistributorVK.java | 12 ++++++------ .../vkbot/core/listener/EventListenerVk.java | 18 +++++++++--------- ...{EventService.java => RawEventService.java} | 2 +- .../core/service/distribution/MailService.java | 2 +- .../service/distribution/SortEventService.java | 13 ------------- .../distribution/impl/CommentServiceImpl.java | 17 +++++++++++++++++ .../distribution/impl/EventService.java | 8 ++++++++ ...rviceImpl.java => RawEventServiceImpl.java} | 8 ++++---- 8 files changed, 46 insertions(+), 34 deletions(-) rename src/main/java/org/sadtech/vkbot/core/service/{EventService.java => RawEventService.java} (91%) delete mode 100644 src/main/java/org/sadtech/vkbot/core/service/distribution/SortEventService.java rename src/main/java/org/sadtech/vkbot/core/service/impl/{EventServiceImpl.java => RawEventServiceImpl.java} (79%) diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/impl/EventDistributorVK.java b/src/main/java/org/sadtech/vkbot/core/distribution/impl/EventDistributorVK.java index 9b16545..e32291c 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/impl/EventDistributorVK.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/impl/EventDistributorVK.java @@ -4,7 +4,7 @@ import com.google.gson.JsonObject; 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.EventService; +import org.sadtech.vkbot.core.service.RawEventService; import java.util.HashMap; import java.util.Map; @@ -13,18 +13,18 @@ public class EventDistributorVK implements EventDistributable, Runnable { public static final Logger log = Logger.getLogger(EventDistributorVK.class); - private EventService eventService; + private RawEventService rawEventService; private Map eventDistributionMap = new HashMap<>(); - public EventDistributorVK(EventService eventService) { - this.eventService = eventService; + public EventDistributorVK(RawEventService rawEventService) { + this.rawEventService = rawEventService; } @Override public void distribute() { while (true) { - if (eventService.getJsonObjects().peek() != null) { - JsonObject event = eventService.getJsonObjects().poll(); + if (rawEventService.getJsonObjects().peek() != null) { + JsonObject event = rawEventService.getJsonObjects().poll(); log.info("Главный дистрибьютор отправил событие дальше"); if (eventDistributionMap.containsKey(event.get("type").getAsString())) { eventDistributionMap.get(event.get("type").getAsString()).update(event.getAsJsonObject("object")); diff --git a/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java b/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java index 81b7e68..18df94c 100644 --- a/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java +++ b/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java @@ -12,8 +12,8 @@ import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; import org.apache.log4j.Logger; import org.sadtech.vkbot.core.VkConnect; import org.sadtech.vkbot.core.repository.impl.EventRepositoryQueue; -import org.sadtech.vkbot.core.service.EventService; -import org.sadtech.vkbot.core.service.impl.EventServiceImpl; +import org.sadtech.vkbot.core.service.RawEventService; +import org.sadtech.vkbot.core.service.impl.RawEventServiceImpl; public class EventListenerVk implements EventListener, Runnable { @@ -22,7 +22,7 @@ public class EventListenerVk implements EventListener, Runnable { private VkApiClient vk; private GroupActor actor; - private EventService eventService; + private RawEventService rawEventService; private GetLongPollEventsQuery longPollEventsQuery; private LongPoll longPoll; @@ -31,19 +31,19 @@ public class EventListenerVk implements EventListener, Runnable { public EventListenerVk(VkConnect vkConnect) { vk = vkConnect.getVkApiClient(); actor = vkConnect.getGroupActor(); - eventService = new EventServiceImpl(new EventRepositoryQueue()); + rawEventService = new RawEventServiceImpl(new EventRepositoryQueue()); longPoll = new LongPoll(vk); } - public EventListenerVk(VkConnect vkConnect, EventService eventService) { + public EventListenerVk(VkConnect vkConnect, RawEventService rawEventService) { this.vk = vkConnect.getVkApiClient(); this.actor = vkConnect.getGroupActor(); - this.eventService = eventService; + this.rawEventService = rawEventService; longPoll = new LongPoll(vk); } - public EventService getEventService() { - return eventService; + public RawEventService getRawEventService() { + return rawEventService; } public void listen() throws ClientException, ApiException { @@ -56,7 +56,7 @@ public class EventListenerVk implements EventListener, Runnable { log.info("Полученно событие от ВК"); log.info(eventsResponse.getUpdates()); for (JsonObject update : eventsResponse.getUpdates()) { - eventService.add(update); + rawEventService.add(update); } } longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20); diff --git a/src/main/java/org/sadtech/vkbot/core/service/EventService.java b/src/main/java/org/sadtech/vkbot/core/service/RawEventService.java similarity index 91% rename from src/main/java/org/sadtech/vkbot/core/service/EventService.java rename to src/main/java/org/sadtech/vkbot/core/service/RawEventService.java index 18c2925..7396312 100644 --- a/src/main/java/org/sadtech/vkbot/core/service/EventService.java +++ b/src/main/java/org/sadtech/vkbot/core/service/RawEventService.java @@ -5,7 +5,7 @@ import org.sadtech.vkbot.core.repository.EventRepository; import java.util.Queue; -public interface EventService { +public interface RawEventService { void cleanAll(); 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 index c860c88..1a830d6 100644 --- a/src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java +++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java @@ -4,7 +4,7 @@ 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 { +public interface MailService extends EventService { void add(Message message); diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/SortEventService.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/SortEventService.java deleted file mode 100644 index d24b5ce..0000000 --- a/src/main/java/org/sadtech/vkbot/core/service/distribution/SortEventService.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.sadtech.vkbot.core.service.distribution; - -import java.util.List; - -public interface SortEventService { - - List getEvent(Integer timeFrom, Integer timeTo); - - List getFirstMailByTime(Integer timeFrom, Integer timeTo); - - List getLastMailByTime(Integer timeFrom, Integer timeTo); - -} 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 index 39c5cfe..a22c868 100644 --- 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 @@ -4,6 +4,8 @@ import org.sadtech.vkbot.core.entity.Comment; import org.sadtech.vkbot.core.repository.CommentRepository; import org.sadtech.vkbot.core.service.distribution.CommentService; +import java.util.List; + public class CommentServiceImpl implements CommentService { private CommentRepository commentRepository; @@ -16,4 +18,19 @@ public class CommentServiceImpl implements CommentService { public void add(Comment comment) { commentRepository.add(comment); } + + @Override + public List getEvent(Integer timeFrom, Integer timeTo) { + return null; + } + + @Override + public List getFirstMailByTime(Integer timeFrom, Integer timeTo) { + return null; + } + + @Override + public List getLastMailByTime(Integer timeFrom, Integer timeTo) { + return null; + } } 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 index 99bf15e..e48ae28 100644 --- 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 @@ -1,7 +1,15 @@ package org.sadtech.vkbot.core.service.distribution.impl; +import java.util.List; + public interface EventService { void add(T event); + List getEvent(Integer timeFrom, Integer timeTo); + + List getFirstMailByTime(Integer timeFrom, Integer timeTo); + + List getLastMailByTime(Integer timeFrom, Integer timeTo); + } diff --git a/src/main/java/org/sadtech/vkbot/core/service/impl/EventServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/impl/RawEventServiceImpl.java similarity index 79% rename from src/main/java/org/sadtech/vkbot/core/service/impl/EventServiceImpl.java rename to src/main/java/org/sadtech/vkbot/core/service/impl/RawEventServiceImpl.java index e7fc7c2..7464f08 100644 --- a/src/main/java/org/sadtech/vkbot/core/service/impl/EventServiceImpl.java +++ b/src/main/java/org/sadtech/vkbot/core/service/impl/RawEventServiceImpl.java @@ -3,17 +3,17 @@ package org.sadtech.vkbot.core.service.impl; import com.google.gson.JsonObject; import org.apache.log4j.Logger; import org.sadtech.vkbot.core.repository.EventRepository; -import org.sadtech.vkbot.core.service.EventService; +import org.sadtech.vkbot.core.service.RawEventService; import java.util.Queue; -public class EventServiceImpl implements EventService { +public class RawEventServiceImpl implements RawEventService { - public static final Logger log = Logger.getLogger(EventServiceImpl.class); + public static final Logger log = Logger.getLogger(RawEventServiceImpl.class); private EventRepository eventRepository; - public EventServiceImpl(EventRepository eventRepository) { + public RawEventServiceImpl(EventRepository eventRepository) { this.eventRepository = eventRepository; }