From a496ac00979362907cc19042398887ad9547842f Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 8 May 2019 17:14:51 +0300 Subject: [PATCH 1/9] =?UTF-8?q?=D0=91=D0=B0=D0=B3=D1=84=D0=B8=D0=BA=D1=81?= =?UTF-8?q?=20=D0=B8=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=8E=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=20=D1=81=D0=BA=D1=80=D1=8B=D1=82=D0=BE=D0=B9=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index add015f..185e3c8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.bot bot-core - 0.5.1-RELEASE + 0.5.2-SNAPSHOT jar From d8add9f109d90a4b172f779523de5bccbf66575e Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 11 May 2019 16:08:42 +0300 Subject: [PATCH 2/9] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 +-- .../sadtech/bot/core/domain/BoxAnswer.java | 41 +++++++++++- .../org/sadtech/bot/core/domain/MailSend.java | 66 ------------------- .../org/sadtech/bot/core/sender/Sent.java | 4 +- .../service/impl/RawEventServiceImpl.java | 5 +- 5 files changed, 49 insertions(+), 75 deletions(-) delete mode 100644 src/main/java/org/sadtech/bot/core/domain/MailSend.java diff --git a/pom.xml b/pom.xml index 185e3c8..7103068 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 2.8.5 0.5.13-SNAPSHOT - 1.2.17 + 1.7.26 @@ -43,9 +43,9 @@ ${gson.ver} - log4j - log4j - ${log4j.ver} + org.slf4j + slf4j-api + ${slf4j.ver} diff --git a/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java b/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java index e944b40..9248802 100644 --- a/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java +++ b/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java @@ -14,7 +14,7 @@ public class BoxAnswer { } - public BoxAnswer(BoxAnswer target) { + private BoxAnswer(BoxAnswer target) { if (target != null) { this.message = target.getMessage(); this.keyboard = target.getKeyboard(); @@ -69,6 +69,45 @@ public class BoxAnswer { return new BoxAnswer(this); } + public static Builder builder() { + return new BoxAnswer().new Builder(); + } + + public class Builder { + private Builder() { + + } + + public Builder message(String message) { + BoxAnswer.this.message = message; + return this; + } + + public Builder keyBoard(String keyBoard) { + BoxAnswer.this.keyboard = keyBoard; + return this; + } + + public Builder lat(Float lat) { + BoxAnswer.this.lat = lat; + return this; + } + + public Builder aLong(Float aLong) { + BoxAnswer.this.aLong = aLong; + return this; + } + + public Builder steckerId(Integer stickerId) { + BoxAnswer.this.stickerId = stickerId; + return this; + } + + public BoxAnswer build() { + return BoxAnswer.this; + } + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/org/sadtech/bot/core/domain/MailSend.java b/src/main/java/org/sadtech/bot/core/domain/MailSend.java deleted file mode 100644 index 8238818..0000000 --- a/src/main/java/org/sadtech/bot/core/domain/MailSend.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.sadtech.bot.core.domain; - -public class MailSend { - - private String message; - private String keyboard; - private Float lat; - private Float aLong; - private Integer stickerId; - - public MailSend() { - - } - - public String getKeyboard() { - return keyboard; - } - - public void setKeyboard(String keyboard) { - this.keyboard = keyboard; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public Float getLat() { - return lat; - } - - public void setLat(Float lat) { - this.lat = lat; - } - - public Float getaLong() { - return aLong; - } - - public void setaLong(Float aLong) { - this.aLong = aLong; - } - - public Integer getStickerId() { - return stickerId; - } - - public void setStickerId(Integer stickerId) { - this.stickerId = stickerId; - } - - @Override - public String toString() { - return "MailSend{" + - "message='" + message + '\'' + - ", keyboard='" + keyboard + '\'' + - ", lat=" + lat + - ", aLong=" + aLong + - ", stickerId=" + stickerId + - '}'; - } - -} diff --git a/src/main/java/org/sadtech/bot/core/sender/Sent.java b/src/main/java/org/sadtech/bot/core/sender/Sent.java index 63a33ba..120e56c 100644 --- a/src/main/java/org/sadtech/bot/core/sender/Sent.java +++ b/src/main/java/org/sadtech/bot/core/sender/Sent.java @@ -4,8 +4,8 @@ import org.sadtech.bot.core.domain.BoxAnswer; public interface Sent { - void send(Integer idPerson, String message); + void send(Integer personId, String message); - void send(Integer idPerson, BoxAnswer boxAnswer); + void send(Integer personId, BoxAnswer boxAnswer); } diff --git a/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java index 7232f89..c592287 100644 --- a/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java +++ b/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java @@ -1,15 +1,16 @@ package org.sadtech.bot.core.service.impl; import com.google.gson.JsonObject; -import org.apache.log4j.Logger; import org.sadtech.bot.core.repository.EventRepository; import org.sadtech.bot.core.service.RawEventService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Queue; public class RawEventServiceImpl implements RawEventService { - private static final Logger log = Logger.getLogger(RawEventServiceImpl.class); + private static final Logger log = LoggerFactory.getLogger(RawEventServiceImpl.class); private final EventRepository eventRepository; From 0eda787b44eba59d65cbf9e4b01a3f934e7083a7 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 15 May 2019 13:17:29 +0300 Subject: [PATCH 3/9] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D0=B2=D0=B8=D0=B0=D1=82=D1=83=D1=80=D1=8B=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sadtech/bot/core/domain/BoxAnswer.java | 10 ++- .../bot/core/domain/keyboard/ButtonColor.java | 7 ++ .../bot/core/domain/keyboard/KeyBoard.java | 48 +++++++++++ .../core/domain/keyboard/KeyBoardButton.java | 81 +++++++++++++++++++ .../core/domain/keyboard/KeyBoardLine.java | 41 ++++++++++ .../sadtech/bot/core/service/KeyBoards.java | 39 +++++++++ 6 files changed, 222 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/sadtech/bot/core/domain/keyboard/ButtonColor.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoard.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardButton.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardLine.java create mode 100644 src/main/java/org/sadtech/bot/core/service/KeyBoards.java diff --git a/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java b/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java index 9248802..3640594 100644 --- a/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java +++ b/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java @@ -1,11 +1,13 @@ package org.sadtech.bot.core.domain; +import org.sadtech.bot.core.domain.keyboard.KeyBoard; + import java.util.Objects; public class BoxAnswer { private String message; - private String keyboard; + private KeyBoard keyboard; private Float lat; private Float aLong; private Integer stickerId; @@ -33,11 +35,11 @@ public class BoxAnswer { this.message = message; } - public String getKeyboard() { + public KeyBoard getKeyboard() { return keyboard; } - public void setKeyboard(String keyboard) { + public void setKeyboard(KeyBoard keyboard) { this.keyboard = keyboard; } @@ -83,7 +85,7 @@ public class BoxAnswer { return this; } - public Builder keyBoard(String keyBoard) { + public Builder keyBoard(KeyBoard keyBoard) { BoxAnswer.this.keyboard = keyBoard; return this; } diff --git a/src/main/java/org/sadtech/bot/core/domain/keyboard/ButtonColor.java b/src/main/java/org/sadtech/bot/core/domain/keyboard/ButtonColor.java new file mode 100644 index 0000000..49263a2 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/ButtonColor.java @@ -0,0 +1,7 @@ +package org.sadtech.bot.core.domain.keyboard; + +public enum ButtonColor { + + PRIMARY, DEFAULT, NEGATIVE, POSITIVE + +} diff --git a/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoard.java b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoard.java new file mode 100644 index 0000000..12dcf6e --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoard.java @@ -0,0 +1,48 @@ +package org.sadtech.bot.core.domain.keyboard; + +import java.util.ArrayList; +import java.util.List; + +public class KeyBoard { + + private List keyBoardLines = new ArrayList<>(); + private boolean oneTime = true; + + private KeyBoard() { + + } + + public List getKeyBoardLines() { + return keyBoardLines; + } + + public boolean isOneTime() { + return oneTime; + } + + public static Builder builder() { + return new KeyBoard().new Builder(); + } + + public class Builder { + + private Builder() { + + } + + public Builder lineKeyBoard(KeyBoardLine keyBoardLine) { + KeyBoard.this.keyBoardLines.add(keyBoardLine); + return this; + } + + public Builder oneTime(boolean oneTime) { + KeyBoard.this.oneTime = oneTime; + return this; + } + + public KeyBoard build() { + return KeyBoard.this; + } + + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardButton.java b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardButton.java new file mode 100644 index 0000000..f59dff1 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardButton.java @@ -0,0 +1,81 @@ +package org.sadtech.bot.core.domain.keyboard; + +import com.google.gson.JsonObject; + +import java.util.Objects; + +public class KeyBoardButton { + + private String payload; + private String label; + private ButtonColor color = ButtonColor.DEFAULT; + + public KeyBoardButton() { + + } + + public String getPayload() { + return payload; + } + + public String getLabel() { + return label; + } + + public ButtonColor getColor() { + return color; + } + + private JsonObject generateAction() { + JsonObject action = new JsonObject(); + action.addProperty("payload", payload); + action.addProperty("label", label); + return action; + } + + public static Builder builder() { + return new KeyBoardButton().new Builder(); + } + + public class Builder { + + private Builder() { + + } + + public Builder color(ButtonColor color) { + KeyBoardButton.this.color = color; + return this; + } + + public Builder label(String label) { + KeyBoardButton.this.label = label; + return this; + } + + public Builder payload(String payload) { + KeyBoardButton.this.payload = payload; + return this; + } + + public KeyBoardButton build() { + return KeyBoardButton.this; + } + + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof KeyBoardButton)) return false; + KeyBoardButton that = (KeyBoardButton) o; + return Objects.equals(payload, that.payload) && + Objects.equals(label, that.label) && + color == that.color; + } + + @Override + public int hashCode() { + return Objects.hash(payload, label, color); + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardLine.java b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardLine.java new file mode 100644 index 0000000..236ccc9 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardLine.java @@ -0,0 +1,41 @@ +package org.sadtech.bot.core.domain.keyboard; + +import java.util.ArrayList; +import java.util.List; + +public class KeyBoardLine { + + private List keyBoardButtons = new ArrayList<>(); + + public KeyBoardLine() { + + } + + public KeyBoardLine(List keyBoardButtons) { + this.keyBoardButtons = keyBoardButtons; + } + + public List getKeyBoardButtons() { + return keyBoardButtons; + } + + public static Builder builder() { + return new KeyBoardLine().new Builder(); + } + + public class Builder { + + private Builder() { + + } + + public Builder setButtonKeyBoard(KeyBoardButton keyBoardButton) { + KeyBoardLine.this.keyBoardButtons.add(keyBoardButton); + return this; + } + + public KeyBoardLine build() { + return KeyBoardLine.this; + } + } +} diff --git a/src/main/java/org/sadtech/bot/core/service/KeyBoards.java b/src/main/java/org/sadtech/bot/core/service/KeyBoards.java new file mode 100644 index 0000000..a9b54d7 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/KeyBoards.java @@ -0,0 +1,39 @@ +package org.sadtech.bot.core.service; + +import org.sadtech.bot.core.domain.keyboard.ButtonColor; +import org.sadtech.bot.core.domain.keyboard.KeyBoard; +import org.sadtech.bot.core.domain.keyboard.KeyBoardButton; +import org.sadtech.bot.core.domain.keyboard.KeyBoardLine; + +import java.util.List; + +public class KeyBoards { + + private KeyBoards() { + throw new IllegalStateException(); + } + + public static KeyBoard keyBoardYesNo() { + KeyBoardButton yesButton = KeyBoardButton.builder().color(ButtonColor.POSITIVE).label("Да").payload("{\"button\": \"yes\"}").build(); + KeyBoardButton noButton = KeyBoardButton.builder().color(ButtonColor.NEGATIVE).label("Нет").payload("{\"button\": \"no\"}").build(); + KeyBoardLine keyBoardLine = KeyBoardLine.builder().setButtonKeyBoard(yesButton).setButtonKeyBoard(noButton).build(); + return KeyBoard.builder().lineKeyBoard(keyBoardLine).oneTime(true).build(); + } + + public static KeyBoard verticalMenuString(List labelButtons) { + KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true); + for (String labelButton : labelButtons) { + KeyBoardButton keyBoardButton = KeyBoardButton.builder().label(labelButton).payload("{\"button\": \"" + labelButton + "\"}").build(); + keyBoard.lineKeyBoard(KeyBoardLine.builder().setButtonKeyBoard(keyBoardButton).build()); + } + return keyBoard.build(); + } + + public static KeyBoard verticalMenuButton(List keyBoardButtons) { + KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true); + for (KeyBoardButton keyBoardButton : keyBoardButtons) { + keyBoard.lineKeyBoard(KeyBoardLine.builder().setButtonKeyBoard(keyBoardButton).build()); + } + return keyBoard.build(); + } +} From 1436331d61285354f7ead4da44751e89eb703f80 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 15 May 2019 22:34:01 +0300 Subject: [PATCH 4/9] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D0=B5=20=D1=81=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B5=D0=B9=20=D0=B0=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=87=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sadtech/bot/core/domain/Mail.java | 12 +++++++++++ .../core/domain/attachment/Attachment.java | 10 ++++++++++ .../domain/attachment/AttachmentType.java | 5 +++++ .../core/domain/attachment/AudioMessage.java | 20 +++++++++++++++++++ .../org/sadtech/bot/core/filter/Filter.java | 9 +++++++++ 5 files changed, 56 insertions(+) create mode 100644 src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java create mode 100644 src/main/java/org/sadtech/bot/core/filter/Filter.java diff --git a/src/main/java/org/sadtech/bot/core/domain/Mail.java b/src/main/java/org/sadtech/bot/core/domain/Mail.java index 0f5e67e..779f7d1 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/Mail.java @@ -1,5 +1,8 @@ package org.sadtech.bot.core.domain; +import org.sadtech.bot.core.domain.attachment.Attachment; + +import java.util.List; import java.util.Objects; public class Mail extends Content { @@ -7,6 +10,7 @@ public class Mail extends Content { private Integer id; private Integer date; private String message; + private List attachments; public Mail() { @@ -63,4 +67,12 @@ public class Mail extends Content { public int hashCode() { return Objects.hash(super.hashCode(), id, date, message); } + + public List getAttachments() { + return attachments; + } + + public void setAttachments(List attachments) { + this.attachments = attachments; + } } diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java b/src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java new file mode 100644 index 0000000..1c7de29 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java @@ -0,0 +1,10 @@ +package org.sadtech.bot.core.domain.attachment; + +public abstract class Attachment { + + AttachmentType type; + + public AttachmentType getType() { + return type; + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java b/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java new file mode 100644 index 0000000..afce805 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java @@ -0,0 +1,5 @@ +package org.sadtech.bot.core.domain.attachment; + +public enum AttachmentType { + AUDIO_MESSAGE +} diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java b/src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java new file mode 100644 index 0000000..66151f6 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java @@ -0,0 +1,20 @@ +package org.sadtech.bot.core.domain.attachment; + +import java.net.URL; + +public class AudioMessage extends Attachment { + + private URL linkOdd; + + public AudioMessage() { + type = AttachmentType.AUDIO_MESSAGE; + } + + public URL getLinkOdd() { + return linkOdd; + } + + public void setLinkOdd(URL linkOdd) { + this.linkOdd = linkOdd; + } +} diff --git a/src/main/java/org/sadtech/bot/core/filter/Filter.java b/src/main/java/org/sadtech/bot/core/filter/Filter.java new file mode 100644 index 0000000..b64ab2e --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/filter/Filter.java @@ -0,0 +1,9 @@ +package org.sadtech.bot.core.filter; + +import org.sadtech.bot.core.domain.Content; + +public interface Filter { + + void doFilter(T content); + +} From f759971840aced4bf1556c062aabcb9f22796182 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 16 May 2019 18:36:23 +0300 Subject: [PATCH 5/9] =?UTF-8?q?=D0=9D=D0=B5=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D1=8B=20?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BB=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=83=D1=8E=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D1=83=20=D1=81=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 --- .../org/sadtech/bot/core/domain/Mail.java | 22 ++++++++++++++----- .../core/domain/attachment/AudioMessage.java | 22 +++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/sadtech/bot/core/domain/Mail.java b/src/main/java/org/sadtech/bot/core/domain/Mail.java index 779f7d1..08a0746 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/Mail.java @@ -52,6 +52,14 @@ public class Mail extends Content { return new Mail(this); } + public List getAttachments() { + return attachments; + } + + public void setAttachments(List attachments) { + this.attachments = attachments; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -68,11 +76,13 @@ public class Mail extends Content { return Objects.hash(super.hashCode(), id, date, message); } - public List getAttachments() { - return attachments; - } - - public void setAttachments(List attachments) { - this.attachments = attachments; + @Override + public String toString() { + return "Mail{" + + "id=" + id + + ", date=" + date + + ", message='" + message + '\'' + + ", attachments=" + attachments + + '}'; } } diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java b/src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java index 66151f6..ef6583a 100644 --- a/src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java +++ b/src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java @@ -1,6 +1,7 @@ package org.sadtech.bot.core.domain.attachment; import java.net.URL; +import java.util.Objects; public class AudioMessage extends Attachment { @@ -17,4 +18,25 @@ public class AudioMessage extends Attachment { public void setLinkOdd(URL linkOdd) { this.linkOdd = linkOdd; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof AudioMessage)) return false; + AudioMessage that = (AudioMessage) o; + return Objects.equals(linkOdd, that.linkOdd); + } + + @Override + public int hashCode() { + return Objects.hash(linkOdd); + } + + @Override + public String toString() { + return "AudioMessage{" + + "linkOdd=" + linkOdd + + ", type=" + type + + '}'; + } } From b94ca5827fb7f95278d661c0584ac8c2acf88d47 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 17 May 2019 00:29:24 +0300 Subject: [PATCH 6/9] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D0=B4=D0=B0=D1=82?= =?UTF-8?q?=D1=8B=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B8=20=D0=B1=D0=B8?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8=20=D0=BD=D0=B0?= =?UTF-8?q?=20LocalDateTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sadtech/bot/core/domain/Mail.java | 7 +++--- .../bot/core/exception/MailSendException.java | 5 ++++ .../bot/core/repository/MailRepository.java | 3 ++- .../repository/impl/MailRepositoryList.java | 23 ++++++++++--------- .../bot/core/service/EventService.java | 7 +++--- 5 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/sadtech/bot/core/exception/MailSendException.java diff --git a/src/main/java/org/sadtech/bot/core/domain/Mail.java b/src/main/java/org/sadtech/bot/core/domain/Mail.java index 08a0746..9057d34 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/Mail.java @@ -2,13 +2,14 @@ package org.sadtech.bot.core.domain; import org.sadtech.bot.core.domain.attachment.Attachment; +import java.time.LocalDateTime; import java.util.List; import java.util.Objects; public class Mail extends Content { private Integer id; - private Integer date; + private LocalDateTime date; private String message; private List attachments; @@ -31,11 +32,11 @@ public class Mail extends Content { this.id = id; } - public Integer getDate() { + public LocalDateTime getDate() { return date; } - public void setDate(Integer date) { + public void setDate(LocalDateTime date) { this.date = date; } diff --git a/src/main/java/org/sadtech/bot/core/exception/MailSendException.java b/src/main/java/org/sadtech/bot/core/exception/MailSendException.java new file mode 100644 index 0000000..f627380 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/exception/MailSendException.java @@ -0,0 +1,5 @@ +package org.sadtech.bot.core.exception; + +public class MailSendException extends RuntimeException { + +} diff --git a/src/main/java/org/sadtech/bot/core/repository/MailRepository.java b/src/main/java/org/sadtech/bot/core/repository/MailRepository.java index 0ae005f..697cb6f 100644 --- a/src/main/java/org/sadtech/bot/core/repository/MailRepository.java +++ b/src/main/java/org/sadtech/bot/core/repository/MailRepository.java @@ -2,12 +2,13 @@ package org.sadtech.bot.core.repository; import org.sadtech.bot.core.domain.Mail; +import java.time.LocalDateTime; import java.util.List; public interface MailRepository { void add(Mail mail); - List getMailByTime(Integer timeFrom, Integer timeTo); + List getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo); } diff --git a/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java b/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java index 6012f54..4231cb1 100644 --- a/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java +++ b/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java @@ -4,6 +4,7 @@ import org.sadtech.bot.core.domain.Mail; import org.sadtech.bot.core.repository.EventRepository; import org.sadtech.bot.core.repository.MailRepository; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Queue; @@ -11,33 +12,33 @@ import java.util.concurrent.ConcurrentLinkedQueue; public class MailRepositoryList implements EventRepository, MailRepository { - private final List messages = new ArrayList<>(); + private final List mails = new ArrayList<>(); @Override public void add(Mail mail) { - messages.add(mail); + mails.add(mail); } @Override public void cleanAll() { - messages.clear(); + mails.clear(); } @Override public Queue getEventQueue() { - return new ConcurrentLinkedQueue<>(messages); + return new ConcurrentLinkedQueue<>(mails); } - public List getMailByTime(Integer timeFrom, Integer timeTo) { - ArrayList mails = new ArrayList<>(); - for (int i = messages.size() - 1; i >= 0; i--) { - if (messages.get(i).getDate() >= timeFrom && messages.get(i).getDate() < timeTo) { - mails.add(messages.get(i)); - } else if (messages.get(i).getDate() < timeFrom) { + public List getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + ArrayList rezultMails = new ArrayList<>(); + for (int i = mails.size() - 1; i >= 0; i--) { + if (!(mails.get(i).getDate().isBefore(timeFrom) || mails.get(i).getDate().isAfter(timeTo))) { + rezultMails.add(this.mails.get(i)); + } else if (mails.get(i).getDate().isBefore(timeFrom)) { break; } } - return mails; + return rezultMails; } diff --git a/src/main/java/org/sadtech/bot/core/service/EventService.java b/src/main/java/org/sadtech/bot/core/service/EventService.java index b62c1a9..fcb7a1e 100644 --- a/src/main/java/org/sadtech/bot/core/service/EventService.java +++ b/src/main/java/org/sadtech/bot/core/service/EventService.java @@ -1,15 +1,16 @@ package org.sadtech.bot.core.service; +import java.time.LocalDateTime; import java.util.List; public interface EventService { void add(T event); - List getEvent(Integer timeFrom, Integer timeTo); + List getEvent(LocalDateTime timeFrom, LocalDateTime timeTo); - List getFirstEventByTime(Integer timeFrom, Integer timeTo); + List getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo); - List getLastEventByTime(Integer timeFrom, Integer timeTo); + List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo); } From af4d2c1c5909eb4137a87278d511932a4f736d0d Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 17 May 2019 18:58:52 +0300 Subject: [PATCH 7/9] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 ++ .../org/sadtech/bot/core/domain/Person.java | 39 ++++++---- .../repository/impl/MailRepositoryList.java | 2 +- .../bot/core/sender/email/EmailConfig.java | 77 +++++++++++++++++++ .../bot/core/sender/email/EmailSent.java | 47 +++++++++++ .../sadtech/bot/core/service/MailService.java | 7 ++ .../core/service/impl/MailServiceImpl.java | 72 +++++++++++++++++ 7 files changed, 235 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/sadtech/bot/core/sender/email/EmailConfig.java create mode 100644 src/main/java/org/sadtech/bot/core/sender/email/EmailSent.java create mode 100644 src/main/java/org/sadtech/bot/core/service/MailService.java create mode 100644 src/main/java/org/sadtech/bot/core/service/impl/MailServiceImpl.java diff --git a/pom.xml b/pom.xml index 7103068..5533462 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,7 @@ 2.8.5 0.5.13-SNAPSHOT 1.7.26 + 1.4 @@ -48,6 +49,12 @@ ${slf4j.ver} + + javax.mail + mail + ${mail.ver} + + org.apache.logging.log4j log4j-slf4j-impl diff --git a/src/main/java/org/sadtech/bot/core/domain/Person.java b/src/main/java/org/sadtech/bot/core/domain/Person.java index 80970ee..646d076 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Person.java +++ b/src/main/java/org/sadtech/bot/core/domain/Person.java @@ -9,18 +9,7 @@ public class Person { private String lastName; private Integer sex; private String city; - - public Person() { - - } - - public Person(Integer id, String firstName, String lastName, Integer sex, String city) { - this.id = id; - this.firstName = firstName; - this.lastName = lastName; - this.sex = sex; - this.city = city; - } + private String email; public Integer getId() { return id; @@ -62,21 +51,41 @@ public class Person { this.city = city; } + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof Person)) return false; Person person = (Person) o; return Objects.equals(id, person.id) && Objects.equals(firstName, person.firstName) && Objects.equals(lastName, person.lastName) && Objects.equals(sex, person.sex) && - Objects.equals(city, person.city); + Objects.equals(city, person.city) && + Objects.equals(email, person.email); } @Override public int hashCode() { - return Objects.hash(id, firstName, lastName, sex, city); + return Objects.hash(id, firstName, lastName, sex, city, email); } + @Override + public String toString() { + return "Person{" + + "id=" + id + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", sex=" + sex + + ", city='" + city + '\'' + + ", email='" + email + '\'' + + '}'; + } } diff --git a/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java b/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java index 4231cb1..521b024 100644 --- a/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java +++ b/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java @@ -32,7 +32,7 @@ public class MailRepositoryList implements EventRepository, MailRepository public List getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { ArrayList rezultMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { - if (!(mails.get(i).getDate().isBefore(timeFrom) || mails.get(i).getDate().isAfter(timeTo))) { + if (!(mails.get(i).getDate().isBefore(timeFrom) || mails.get(i).getDate().isAfter(timeTo)) && mails.get(i).getDate().equals(timeFrom)) { rezultMails.add(this.mails.get(i)); } else if (mails.get(i).getDate().isBefore(timeFrom)) { break; diff --git a/src/main/java/org/sadtech/bot/core/sender/email/EmailConfig.java b/src/main/java/org/sadtech/bot/core/sender/email/EmailConfig.java new file mode 100644 index 0000000..abfbefe --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/sender/email/EmailConfig.java @@ -0,0 +1,77 @@ +package org.sadtech.bot.core.sender.email; + +import java.util.Properties; + +public class EmailConfig { + + private Properties props = new Properties(); + private String username; + private String password; + + private EmailConfig() { + + } + + public Properties getProps() { + return props; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public static Builder builder() { + return new EmailConfig().new Builder(); + } + + public class Builder { + + private Builder() { + + } + + public Builder smtpHost(String smtpHost) { + EmailConfig.this.props.setProperty("mail.smtp.host", smtpHost); + return this; + } + + public Builder smtpSocketFactoryPort(Integer smtpSocketFactoryPortort) { + EmailConfig.this.props.setProperty("mail.smtp.socketFactory.port", smtpSocketFactoryPortort.toString()); + return this; + } + + public Builder smtpSocketFactoryClass(String smtpSocketFactoryClass) { + EmailConfig.this.props.setProperty("mail.smtp.socketFactory.class", smtpSocketFactoryClass); + return this; + } + + public Builder smtpAuth(Boolean smtpAuth) { + EmailConfig.this.props.setProperty("mail.smtp.auth", (smtpAuth) ? "true" : "false"); + return this; + } + + public Builder smtpPort(Integer smtpPort) { + EmailConfig.this.props.setProperty("mail.smtp.port", smtpPort.toString()); + return this; + } + + public Builder email(String username) { + EmailConfig.this.username = username; + return this; + } + + public Builder password(String password) { + EmailConfig.this.password = password; + return this; + } + + public EmailConfig build() { + return EmailConfig.this; + } + + } +} diff --git a/src/main/java/org/sadtech/bot/core/sender/email/EmailSent.java b/src/main/java/org/sadtech/bot/core/sender/email/EmailSent.java new file mode 100644 index 0000000..9f20425 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/sender/email/EmailSent.java @@ -0,0 +1,47 @@ +package org.sadtech.bot.core.sender.email; + +import org.sadtech.bot.core.domain.BoxAnswer; +import org.sadtech.bot.core.exception.MailSendException; +import org.sadtech.bot.core.sender.Sent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.mail.*; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; + +public class EmailSent implements Sent { + + private static final Logger log = LoggerFactory.getLogger(Sent.class); + + private final EmailConfig emailConfig; + + public EmailSent(EmailConfig emailConfig) { + this.emailConfig = emailConfig; + } + + @Override + public void send(Integer personId, String htmlText) { + Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(emailConfig.getUsername(), emailConfig.getPassword()); + } + }); + + try { + Message message = new MimeMessage(session); + message.setFrom(new InternetAddress(emailConfig.getUsername())); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailConfig.getUsername())); + message.setContent(htmlText, "text/html; charset=utf-8"); + Transport.send(message); + } catch (MessagingException e) { + log.error(e.getMessage()); + throw new MailSendException(); + } + } + + @Override + public void send(Integer personId, BoxAnswer boxAnswer) { + + } +} diff --git a/src/main/java/org/sadtech/bot/core/service/MailService.java b/src/main/java/org/sadtech/bot/core/service/MailService.java new file mode 100644 index 0000000..6a0db7e --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/MailService.java @@ -0,0 +1,7 @@ +package org.sadtech.bot.core.service; + +import org.sadtech.bot.core.domain.Mail; + +public interface MailService extends EventService { + +} diff --git a/src/main/java/org/sadtech/bot/core/service/impl/MailServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/MailServiceImpl.java new file mode 100644 index 0000000..4cb0d04 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/impl/MailServiceImpl.java @@ -0,0 +1,72 @@ +package org.sadtech.bot.core.service.impl; + +import org.sadtech.bot.core.domain.Mail; +import org.sadtech.bot.core.repository.MailRepository; +import org.sadtech.bot.core.repository.impl.MailRepositoryList; +import org.sadtech.bot.core.service.MailService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class MailServiceImpl implements MailService { + + private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class); + + private final MailRepository mailRepository; + + public MailServiceImpl() { + this.mailRepository = new MailRepositoryList(); + } + + public MailServiceImpl(MailRepository mailRepository) { + this.mailRepository = mailRepository; + } + + @Override + public void add(Mail mail) { + mailRepository.add(mail); + log.info("Сообщение добавлено в репозиторий"); + log.info(mail.toString()); + } + + @Override + public List getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.info("Запрошены сообщения " + timeFrom + " - " + timeTo); + List mails = mailRepository.getMailByTime(timeFrom, timeTo); + Set people = new HashSet<>(); + List returnMails = new ArrayList<>(); + for (int i = mails.size() - 1; i >= 0; i--) { + if (!people.contains(mails.get(i).getPersonId())) { + returnMails.add(mails.get(i)); + people.add(mails.get(i).getPersonId()); + } + } + return returnMails; + } + + @Override + public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + List mails = mailRepository.getMailByTime(timeFrom, timeTo); + Set people = new HashSet<>(); + List returnMails = new ArrayList<>(); + for (Mail mail : mails) { + if (!people.contains(mail.getPersonId())) { + returnMails.add(mail); + people.add(mail.getPersonId()); + } + } + return returnMails; + } + + @Override + public List getEvent(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.info("Запрос на получение сообщений в интервале от " + timeFrom + " до " + timeTo); + return mailRepository.getMailByTime(timeFrom, timeTo); + } + +} From f46890edae710809b3f2ee455d059c3646c80295 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 18 May 2019 13:10:25 +0300 Subject: [PATCH 8/9] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B2=20=D0=B8=D0=B5=D1=80=D0=B0=D1=80=D1=85?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sadtech/bot/core/domain/Content.java | 15 +++++++++++++-- .../java/org/sadtech/bot/core/domain/Mail.java | 15 ++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/sadtech/bot/core/domain/Content.java b/src/main/java/org/sadtech/bot/core/domain/Content.java index 96ae304..1059a82 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Content.java +++ b/src/main/java/org/sadtech/bot/core/domain/Content.java @@ -5,6 +5,7 @@ import java.util.Objects; public abstract class Content { private Integer personId; + private String message; public Content() { @@ -12,6 +13,7 @@ public abstract class Content { public Content(Content source) { this.personId = source.getPersonId(); + this.message = source.getMessage(); } public Integer getPersonId() { @@ -22,16 +24,25 @@ public abstract class Content { this.personId = personId; } + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Content)) return false; Content content = (Content) o; - return Objects.equals(personId, content.personId); + return Objects.equals(personId, content.personId) && + Objects.equals(message, content.message); } @Override public int hashCode() { - return Objects.hash(personId); + return Objects.hash(personId, message); } } diff --git a/src/main/java/org/sadtech/bot/core/domain/Mail.java b/src/main/java/org/sadtech/bot/core/domain/Mail.java index 9057d34..a69d39f 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/Mail.java @@ -10,7 +10,6 @@ public class Mail extends Content { private Integer id; private LocalDateTime date; - private String message; private List attachments; public Mail() { @@ -21,7 +20,6 @@ public class Mail extends Content { super(source); this.id = source.getId(); this.date = source.getDate(); - this.message = source.getMessage(); } public Integer getId() { @@ -41,14 +39,6 @@ public class Mail extends Content { } - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - public Mail prototype() { return new Mail(this); } @@ -69,12 +59,12 @@ public class Mail extends Content { Mail mail = (Mail) o; return Objects.equals(id, mail.id) && Objects.equals(date, mail.date) && - Objects.equals(message, mail.message); + Objects.equals(attachments, mail.attachments); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), id, date, message); + return Objects.hash(super.hashCode(), id, date, attachments); } @Override @@ -82,7 +72,6 @@ public class Mail extends Content { return "Mail{" + "id=" + id + ", date=" + date + - ", message='" + message + '\'' + ", attachments=" + attachments + '}'; } From 657a8bcab5be0195b2170cba8a4554dd9ab15f4a Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 18 May 2019 13:12:50 +0300 Subject: [PATCH 9/9] release-0.6.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5533462..d58ffb5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.bot bot-core - 0.5.2-SNAPSHOT + 0.6.0-RELEASE jar