diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c3232fc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+*.iml
+.idea/
+**/target/**
+*.log
+*.properties
+.DS_Store
diff --git a/pom.xml b/pom.xml
index 6f8e7c3..af7e00f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.sadtech.vkbot
vkbot-core
- 1.0-SNAPSHOT
+ 0.1.0-RELEASE
jar
diff --git a/src/main/java/org/sadtech/vkbot/core/VkApi.java b/src/main/java/org/sadtech/vkbot/core/VkApi.java
index faf453c..c4255b2 100644
--- a/src/main/java/org/sadtech/vkbot/core/VkApi.java
+++ b/src/main/java/org/sadtech/vkbot/core/VkApi.java
@@ -16,10 +16,10 @@ import java.util.List;
public class VkApi {
- public static final Logger log = Logger.getLogger(String.valueOf(VkApi.class));
+ private static final Logger log = Logger.getLogger(String.valueOf(VkApi.class));
- private VkApiClient vk;
- private GroupActor actor;
+ private final VkApiClient vk;
+ private final GroupActor actor;
public VkApi(VkConnect vkConnect) {
vk = vkConnect.getVkApiClient();
@@ -66,7 +66,6 @@ public class VkApi {
}
private boolean checkCity(List temp) {
- log.info("Запрошен город пользователя: " + temp.get(0).getCity().getTitle());
return temp.get(0).getCity() != null;
}
diff --git a/src/main/java/org/sadtech/vkbot/core/VkConnect.java b/src/main/java/org/sadtech/vkbot/core/VkConnect.java
index c10e7bd..d4c90ce 100644
--- a/src/main/java/org/sadtech/vkbot/core/VkConnect.java
+++ b/src/main/java/org/sadtech/vkbot/core/VkConnect.java
@@ -7,7 +7,7 @@ import com.vk.api.sdk.httpclient.HttpTransportClient;
public class VkConnect {
- private VkConfig vkConfig;
+ private final VkConfig vkConfig;
private VkApiClient vkApiClient;
private GroupActor groupActor;
diff --git a/src/main/java/org/sadtech/vkbot/core/VkInsertData.java b/src/main/java/org/sadtech/vkbot/core/VkInsertData.java
index 327ae22..bbaa9bd 100644
--- a/src/main/java/org/sadtech/vkbot/core/VkInsertData.java
+++ b/src/main/java/org/sadtech/vkbot/core/VkInsertData.java
@@ -5,7 +5,7 @@ import java.util.regex.Pattern;
public class VkInsertData {
- private VkApi vkApi;
+ private final VkApi vkApi;
public VkInsertData(VkConnect vkConnect) {
this.vkApi = new VkApi(vkConnect);
diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/CommentSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/CommentSubscriber.java
deleted file mode 100644
index 06a8b53..0000000
--- a/src/main/java/org/sadtech/vkbot/core/distribution/CommentSubscriber.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.sadtech.vkbot.core.distribution;
-
-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.service.distribution.CommentService;
-
-public class CommentSubscriber implements EventSubscribe {
-
- public static final Logger log = Logger.getLogger(CommentSubscriber.class);
-
- private CommentService commentService;
-
- public CommentSubscriber(CommentService commentService) {
- this.commentService = commentService;
- }
-
- @Override
- 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/EventDistributor.java b/src/main/java/org/sadtech/vkbot/core/distribution/EventDistributor.java
index 3d1c4d9..051f3bb 100644
--- a/src/main/java/org/sadtech/vkbot/core/distribution/EventDistributor.java
+++ b/src/main/java/org/sadtech/vkbot/core/distribution/EventDistributor.java
@@ -9,13 +9,14 @@ import java.util.Map;
public class EventDistributor implements Runnable {
- public static final Logger log = Logger.getLogger(EventDistributor.class);
+ private static final Logger log = Logger.getLogger(EventDistributor.class);
- private RawEventService rawEventService;
- private Map eventDistributionMap = new HashMap<>();
+ private final RawEventService rawEventService;
+ private final Map eventDistributionMap = new HashMap<>();
public EventDistributor(RawEventService rawEventService) {
this.rawEventService = rawEventService;
+ log.info("EventDistributor инициализирован");
}
public void update() {
@@ -41,6 +42,7 @@ public class EventDistributor implements Runnable {
@Override
public void run() {
+ log.info("EventDistributor запущен");
update();
}
}
diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java
index 7054895..f66f387 100644
--- a/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java
+++ b/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java
@@ -14,11 +14,11 @@ import java.util.Set;
public class MailSubscriber implements EventSubscribe {
- public static final Logger log = Logger.getLogger(MailSubscriber.class);
+ private static final Logger log = Logger.getLogger(MailSubscriber.class);
- private MailService mailService;
+ private final MailService mailService;
private Set admins = new HashSet<>();
- private Map> eventDistributionMap = new HashMap<>();
+ private final Map> eventDistributionMap = new HashMap<>();
public MailSubscriber(MailService mailService) {
this.mailService = mailService;
@@ -54,10 +54,10 @@ public class MailSubscriber implements EventSubscribe {
private Mail createMaail(Message message) {
Mail mail = new Mail();
- mail.setBody(message.getBody());
+ mail.setMessage(message.getBody());
mail.setDate(message.getDate());
mail.setId(message.getId());
- mail.setPeerId(message.getPeerId());
+ mail.setPersonId(message.getPeerId());
return mail;
}
diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/TerminalSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/TerminalSubscriber.java
deleted file mode 100644
index ad97fa9..0000000
--- a/src/main/java/org/sadtech/vkbot/core/distribution/TerminalSubscriber.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.sadtech.vkbot.core.distribution;
-
-import com.vk.api.sdk.objects.messages.Message;
-import org.apache.log4j.Logger;
-import org.sadtech.vkbot.core.service.distribution.MailService;
-
-public class TerminalSubscriber implements EventSubscribe {
-
- public static final Logger log = Logger.getLogger(TerminalSubscriber.class);
-
- private MailService mailService;
-
- public TerminalSubscriber(MailSubscriber mailSubscriber, MailService mailService) {
- this.mailService = mailService;
- }
-
- public MailService getMailService() {
- return mailService;
- }
-
- public void setMailService(MailService mailService) {
- this.mailService = mailService;
- }
-
- @Override
- public void update(Message object) {
- log.info("Сообщение отправленно на добавление в репозиторий команд");
- }
-
-}
diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java
index fa9612f..58802e4 100644
--- a/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java
+++ b/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java
@@ -4,20 +4,13 @@ import com.google.gson.JsonObject;
public class ButtonKeyBoard {
- private String type = "text";
+ private String type;
private String payload;
private String label;
- private ColorButton color = ColorButton.PRIMARY;
+ private ColorButton color;
- public ButtonKeyBoard() {
-
- }
-
- public ButtonKeyBoard(String type, String payload, String label, ColorButton color) {
- this.type = type;
- this.payload = payload;
- this.label = label;
- this.color = color;
+ private ButtonKeyBoard() {
+ throw new IllegalStateException();
}
public JsonObject getButton() {
@@ -45,22 +38,22 @@ public class ButtonKeyBoard {
}
- public Builder setColor(ColorButton color) {
+ public Builder color(ColorButton color) {
ButtonKeyBoard.this.color = color;
return this;
}
- public Builder setLabel(String label) {
+ public Builder label(String label) {
ButtonKeyBoard.this.label = label;
return this;
}
- public Builder setPayload(String payload) {
+ public Builder payload(String payload) {
ButtonKeyBoard.this.payload = payload;
return this;
}
- public Builder setType(String type) {
+ public Builder type(String type) {
ButtonKeyBoard.this.type = type;
return this;
}
diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java
index 08cdf86..537b05e 100644
--- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java
+++ b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java
@@ -8,20 +8,12 @@ import java.util.List;
public class KeyBoard {
- private List lineKeyBoards = new ArrayList<>();
+ private List lineKeyBoards;
private boolean oneTime;
- public KeyBoard() {
-
- }
-
- public KeyBoard(List lineKeyBoards, boolean oneTime) {
- this.lineKeyBoards = lineKeyBoards;
- this.oneTime = oneTime;
- }
-
- public void setOneTime(boolean oneTime) {
- this.oneTime = oneTime;
+ private KeyBoard() {
+ lineKeyBoards = new ArrayList<>();
+ throw new IllegalStateException();
}
public JsonObject getKeyboard() {
@@ -37,26 +29,26 @@ public class KeyBoard {
return keyboard;
}
- public void addLine(LineKeyBoard lineKeyBoard) {
- lineKeyBoards.add(lineKeyBoard);
- }
-
public static Builder builder() {
return new KeyBoard().new Builder();
}
+ public void addLine(LineKeyBoard lineKeyBoard) {
+ lineKeyBoards.add(lineKeyBoard);
+ }
+
public class Builder {
private Builder() {
}
- public Builder setLineKeyBoard(LineKeyBoard lineKeyBoard) {
+ public Builder lineKeyBoard(LineKeyBoard lineKeyBoard) {
KeyBoard.this.lineKeyBoards.add(lineKeyBoard);
return this;
}
- public Builder setOneTime(boolean oneTime) {
+ public Builder oneTime(boolean oneTime) {
KeyBoard.this.oneTime = oneTime;
return this;
}
diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java
index 910522e..11f70b1 100644
--- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java
+++ b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java
@@ -9,30 +9,26 @@ public class KeyBoardService {
}
public static KeyBoard keyBoardYesNo() {
- ButtonKeyBoard yesButton = ButtonKeyBoard.builder().setColor(ColorButton.POSITIVE).setLabel("Да").setPayload("{\"button\": \"yes\"}").build();
- ButtonKeyBoard noButton = ButtonKeyBoard.builder().setColor(ColorButton.NEGATIVE).setLabel("Нет").setPayload("{\"button\": \"no\"}").build();
+ ButtonKeyBoard yesButton = ButtonKeyBoard.builder().color(ColorButton.POSITIVE).label("Да").payload("{\"button\": \"yes\"}").build();
+ ButtonKeyBoard noButton = ButtonKeyBoard.builder().color(ColorButton.NEGATIVE).label("Нет").payload("{\"button\": \"no\"}").build();
LineKeyBoard lineKeyBoard = LineKeyBoard.builder().setButtonKeyBoard(yesButton).setButtonKeyBoard(noButton).build();
- KeyBoard keyBoard = KeyBoard.builder().setLineKeyBoard(lineKeyBoard).build();
- keyBoard.setOneTime(true);
- return keyBoard;
+ return KeyBoard.builder().lineKeyBoard(lineKeyBoard).oneTime(true).build();
}
public static KeyBoard verticalMenuString(List labelButtons) {
- KeyBoard keyBoard = new KeyBoard();
+ KeyBoard keyBoard = KeyBoard.builder().oneTime(true).build();
for (String labelButton : labelButtons) {
- ButtonKeyBoard buttonKeyBoard = ButtonKeyBoard.builder().setLabel(labelButton).setType("text").setPayload("{\"button\": \"" + labelButton + "\"}").build();
+ ButtonKeyBoard buttonKeyBoard = ButtonKeyBoard.builder().label(labelButton).type("text").payload("{\"button\": \"" + labelButton + "\"}").build();
keyBoard.addLine(LineKeyBoard.builder().setButtonKeyBoard(buttonKeyBoard).build());
}
- keyBoard.setOneTime(true);
return keyBoard;
}
public static KeyBoard verticalMenuButton(List buttonKeyBoards) {
- KeyBoard keyBoard = new KeyBoard();
+ KeyBoard keyBoard = KeyBoard.builder().oneTime(true).build();
for (ButtonKeyBoard buttonKeyBoard : buttonKeyBoards) {
keyBoard.addLine(LineKeyBoard.builder().setButtonKeyBoard(buttonKeyBoard).build());
}
- keyBoard.setOneTime(true);
return keyBoard;
}
}
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 25ed220..57c86cb 100644
--- a/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java
+++ b/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java
@@ -16,14 +16,14 @@ import org.sadtech.vkbot.core.VkConnect;
public class EventListenerVk implements Runnable {
- public static final Logger log = Logger.getLogger(EventListenerVk.class);
+ private static final Logger log = Logger.getLogger(EventListenerVk.class);
- private VkApiClient vk;
- private GroupActor actor;
+ private final VkApiClient vk;
+ private final GroupActor actor;
private static final Integer DEFAULT_WAIT_TIME = 25;
- private RawEventService rawEventService;
+ private final RawEventService rawEventService;
public EventListenerVk(VkConnect vkConnect) {
vk = vkConnect.getVkApiClient();
diff --git a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java
index 4326d5b..bf76e32 100644
--- a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java
+++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java
@@ -13,12 +13,12 @@ import org.sadtech.vkbot.core.VkInsertData;
public class MailSenderVk implements Sent {
- public static final Logger log = Logger.getLogger(MailSenderVk.class);
+ private static final Logger log = Logger.getLogger(MailSenderVk.class);
- private VkApiClient vkApiClient;
- private GroupActor groupActor;
+ private final VkApiClient vkApiClient;
+ private final GroupActor groupActor;
- private VkInsertData vkInsertData;
+ private final VkInsertData vkInsertData;
public MailSenderVk(VkConnect vkConnect) {
this.vkApiClient = vkConnect.getVkApiClient();
diff --git a/src/main/java/org/sadtech/vkbot/core/service/PersonServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/PersonServiceImpl.java
index 5c950ef..c14abb0 100644
--- a/src/main/java/org/sadtech/vkbot/core/service/PersonServiceImpl.java
+++ b/src/main/java/org/sadtech/vkbot/core/service/PersonServiceImpl.java
@@ -12,10 +12,10 @@ import org.sadtech.vkbot.core.VkConnect;
public class PersonServiceImpl implements PersonService {
- public static final Logger log = Logger.getLogger(PersonServiceImpl.class);
+ private static final Logger log = Logger.getLogger(PersonServiceImpl.class);
- private PersonRepository personRepository;
- private VkApi vkApi;
+ private final PersonRepository personRepository;
+ private final VkApi vkApi;
public PersonServiceImpl(VkConnect vkConnect) {
this.personRepository = new PersonRepositoryMap();
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
deleted file mode 100644
index 8641c94..0000000
--- a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/CommentServiceImpl.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.sadtech.vkbot.core.service.distribution.impl;
-
-import org.sadtech.bot.core.domain.Comment;
-import org.sadtech.bot.core.repository.CommentRepository;
-import org.sadtech.vkbot.core.service.distribution.CommentService;
-
-import java.util.List;
-
-public class CommentServiceImpl implements CommentService {
-
- private CommentRepository commentRepository;
-
- public CommentServiceImpl(CommentRepository commentRepository) {
- this.commentRepository = commentRepository;
- }
-
- @Override
- public void add(Comment comment) {
- commentRepository.add(comment);
- }
-
- @Override
- public List getEvent(Integer timeFrom, Integer timeTo) {
- return null;
- }
-
- @Override
- public List getFirstEventByTime(Integer timeFrom, Integer timeTo) {
- return null;
- }
-
- @Override
- public List getLastEventByTime(Integer timeFrom, Integer timeTo) {
- return null;
- }
-
-}
diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java
index 6fc8dc8..ebbef13 100644
--- a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java
+++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java
@@ -13,9 +13,9 @@ import java.util.Set;
public class MailServiceImpl implements MailService {
- public static final Logger log = Logger.getLogger(MailServiceImpl.class);
+ private static final Logger log = Logger.getLogger(MailServiceImpl.class);
- private MailRepository mailRepository;
+ private final MailRepository mailRepository;
public MailServiceImpl() {
this.mailRepository = new MailRepositoryList();
@@ -39,9 +39,9 @@ public class MailServiceImpl implements MailService {
Set people = new HashSet<>();
List returnMails = new ArrayList<>();
for (int i = mails.size() - 1; i >= 0; i--) {
- if (!people.contains(mails.get(i).getPeerId())) {
+ if (!people.contains(mails.get(i).getPersonId())) {
returnMails.add(mails.get(i));
- people.add(mails.get(i).getPeerId());
+ people.add(mails.get(i).getPersonId());
}
}
return returnMails;
@@ -53,9 +53,9 @@ public class MailServiceImpl implements MailService {
Set people = new HashSet<>();
List returnMails = new ArrayList<>();
for (Mail mail : mails) {
- if (!people.contains(mail.getPeerId())) {
+ if (!people.contains(mail.getPersonId())) {
returnMails.add(mail);
- people.add(mail.getPeerId());
+ people.add(mail.getPersonId());
}
}
return returnMails;