From 8cf244bb1cc154d39c7770babeb854bb8a2eee95 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Thu, 30 May 2019 15:48:32 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=20-=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B2=20=D0=BE=D0=B1=D1=81=D1=83=D0=B6=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../bot/core/domain/content/BoardComment.java | 41 ++++++++++++++++ .../bot/core/domain/content/Content.java | 49 ++++++++++++++++++- .../bot/core/domain/content/ContentType.java | 7 +++ .../sadtech/bot/core/domain/content/Mail.java | 37 +++----------- .../core/repository/ContentRepository.java | 14 ++++++ .../bot/core/repository/MailRepository.java | 14 ------ .../impl/BoardCommentRepositoryMap.java | 36 ++++++++++++++ .../repository/impl/MailRepositoryList.java | 26 +++------- .../bot/core/service/BoardCommentService.java | 6 +++ ...{EventService.java => ContentService.java} | 6 +-- .../sadtech/bot/core/service/MailService.java | 2 +- .../service/impl/BoardCommentServiceImpl.java | 49 +++++++++++++++++++ .../core/service/impl/MailServiceImpl.java | 32 ++++-------- .../bot/core/service/sender/SenderBox.java | 27 ++++++++++ .../sadtech/bot/core/service/sender/Sent.java | 4 +- .../core/service/sender/email/EmailSent.java | 6 +-- 17 files changed, 260 insertions(+), 98 deletions(-) create mode 100644 src/main/java/org/sadtech/bot/core/domain/content/BoardComment.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/content/ContentType.java create mode 100644 src/main/java/org/sadtech/bot/core/repository/ContentRepository.java delete mode 100644 src/main/java/org/sadtech/bot/core/repository/MailRepository.java create mode 100644 src/main/java/org/sadtech/bot/core/repository/impl/BoardCommentRepositoryMap.java create mode 100644 src/main/java/org/sadtech/bot/core/service/BoardCommentService.java rename src/main/java/org/sadtech/bot/core/service/{EventService.java => ContentService.java} (56%) create mode 100644 src/main/java/org/sadtech/bot/core/service/impl/BoardCommentServiceImpl.java create mode 100644 src/main/java/org/sadtech/bot/core/service/sender/SenderBox.java diff --git a/pom.xml b/pom.xml index 60d7819..bc9a476 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.bot bot-core - 0.6.1-RELEASE + 0.6.2-SNAPSHOT jar diff --git a/src/main/java/org/sadtech/bot/core/domain/content/BoardComment.java b/src/main/java/org/sadtech/bot/core/domain/content/BoardComment.java new file mode 100644 index 0000000..123619a --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/content/BoardComment.java @@ -0,0 +1,41 @@ +package org.sadtech.bot.core.domain.content; + +import java.util.Objects; + +public class BoardComment extends Content { + + private Integer topicId; + + public BoardComment() { + type = ContentType.BOARD_COMMENT; + } + + public Integer getTopicId() { + return topicId; + } + + public void setTopicId(Integer topicId) { + this.topicId = topicId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof BoardComment)) return false; + if (!super.equals(o)) return false; + BoardComment that = (BoardComment) o; + return Objects.equals(topicId, that.topicId); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), topicId); + } + + @Override + public String toString() { + return "BoardComment{" + + "topicId=" + topicId + + "} " + super.toString(); + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/content/Content.java b/src/main/java/org/sadtech/bot/core/domain/content/Content.java index 5e0c5b3..0ca99f2 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/Content.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/Content.java @@ -1,9 +1,13 @@ package org.sadtech.bot.core.domain.content; +import java.time.LocalDateTime; import java.util.Objects; public abstract class Content { + private Integer id; + protected ContentType type; + private LocalDateTime createDate; private Integer personId; private String message; @@ -14,6 +18,9 @@ public abstract class Content { public Content(Content source) { this.personId = source.getPersonId(); this.message = source.getMessage(); + this.createDate = source.getCreateDate(); + this.id = source.getPersonId(); + this.type = source.getType(); } public Integer getPersonId() { @@ -32,17 +39,55 @@ public abstract class Content { this.message = message; } + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public LocalDateTime getCreateDate() { + return createDate; + } + + public void setCreateDate(LocalDateTime createDate) { + this.createDate = createDate; + } + + public ContentType getType() { + return type; + } + + public void setType(ContentType type) { + this.type = type; + } + @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(id, content.id) && + type == content.type && + Objects.equals(createDate, content.createDate) && + Objects.equals(personId, content.personId) && Objects.equals(message, content.message); } @Override public int hashCode() { - return Objects.hash(personId, message); + return Objects.hash(id, type, createDate, personId, message); + } + + @Override + public String toString() { + return "Content{" + + "id=" + id + + ", type=" + type + + ", createDate=" + createDate + + ", personId=" + personId + + ", message='" + message + '\'' + + '}'; } } diff --git a/src/main/java/org/sadtech/bot/core/domain/content/ContentType.java b/src/main/java/org/sadtech/bot/core/domain/content/ContentType.java new file mode 100644 index 0000000..e6a9443 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/content/ContentType.java @@ -0,0 +1,7 @@ +package org.sadtech.bot.core.domain.content; + +public enum ContentType { + + MAIL, BOARD_COMMENT + +} diff --git a/src/main/java/org/sadtech/bot/core/domain/content/Mail.java b/src/main/java/org/sadtech/bot/core/domain/content/Mail.java index 0e4e720..6fa86d1 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/Mail.java @@ -2,40 +2,21 @@ package org.sadtech.bot.core.domain.content; import org.sadtech.bot.core.domain.content.attachment.Attachment; -import java.time.LocalDateTime; import java.util.List; import java.util.Objects; public class Mail extends Content { - private Integer id; - private LocalDateTime date; private List attachments; - public Mail() { + public Mail() { + type = ContentType.MAIL; } public Mail(Mail source) { super(source); - this.id = source.getId(); - this.date = source.getDate(); - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public LocalDateTime getDate() { - return date; - } - - public void setDate(LocalDateTime date) { - this.date = date; + this.attachments = source.getAttachments(); } @@ -57,22 +38,18 @@ public class Mail extends Content { if (!(o instanceof Mail)) return false; if (!super.equals(o)) return false; Mail mail = (Mail) o; - return Objects.equals(id, mail.id) && - Objects.equals(date, mail.date) && - Objects.equals(attachments, mail.attachments); + return Objects.equals(attachments, mail.attachments); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), id, date, attachments); + return Objects.hash(super.hashCode(), attachments); } @Override public String toString() { return "Mail{" + - "id=" + id + - ", date=" + date + - ", attachments=" + attachments + - '}'; + "attachments=" + attachments + + "} " + super.toString(); } } diff --git a/src/main/java/org/sadtech/bot/core/repository/ContentRepository.java b/src/main/java/org/sadtech/bot/core/repository/ContentRepository.java new file mode 100644 index 0000000..91a800a --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/repository/ContentRepository.java @@ -0,0 +1,14 @@ +package org.sadtech.bot.core.repository; + +import org.sadtech.bot.core.domain.content.Content; + +import java.time.LocalDateTime; +import java.util.List; + +public interface ContentRepository { + + Integer add(T content); + + List findByTime(LocalDateTime timeFrom, LocalDateTime timeTo); + +} diff --git a/src/main/java/org/sadtech/bot/core/repository/MailRepository.java b/src/main/java/org/sadtech/bot/core/repository/MailRepository.java deleted file mode 100644 index f68576b..0000000 --- a/src/main/java/org/sadtech/bot/core/repository/MailRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sadtech.bot.core.repository; - -import org.sadtech.bot.core.domain.content.Mail; - -import java.time.LocalDateTime; -import java.util.List; - -public interface MailRepository { - - void add(Mail mail); - - List getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo); - -} diff --git a/src/main/java/org/sadtech/bot/core/repository/impl/BoardCommentRepositoryMap.java b/src/main/java/org/sadtech/bot/core/repository/impl/BoardCommentRepositoryMap.java new file mode 100644 index 0000000..f3e443c --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/repository/impl/BoardCommentRepositoryMap.java @@ -0,0 +1,36 @@ +package org.sadtech.bot.core.repository.impl; + +import org.sadtech.bot.core.domain.content.BoardComment; +import org.sadtech.bot.core.repository.ContentRepository; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class BoardCommentRepositoryMap implements ContentRepository { + + private final Map saveMap = new HashMap<>(); + private Integer count = 0; + + @Override + public Integer add(BoardComment comment) { + comment.setId(count); + saveMap.put(count, comment); + return count++; + } + + @Override + public List findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + ArrayList rezultMails = new ArrayList<>(); + for (int i = saveMap.size() - 1; i >= 0; i--) { + if (!(saveMap.get(i).getCreateDate().isBefore(timeFrom) || saveMap.get(i).getCreateDate().isAfter(timeTo)) && saveMap.get(i).getCreateDate().equals(timeFrom)) { + rezultMails.add(this.saveMap.get(i)); + } else if (saveMap.get(i).getCreateDate().isBefore(timeFrom)) { + break; + } + } + return rezultMails; + } +} 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 d0247d4..480aa83 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 @@ -1,40 +1,30 @@ package org.sadtech.bot.core.repository.impl; import org.sadtech.bot.core.domain.content.Mail; -import org.sadtech.bot.core.repository.EventRepository; -import org.sadtech.bot.core.repository.MailRepository; +import org.sadtech.bot.core.repository.ContentRepository; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -public class MailRepositoryList implements EventRepository, MailRepository { +public class MailRepositoryList implements ContentRepository { private final List mails = new ArrayList<>(); @Override - public void add(Mail mail) { + public Integer add(Mail mail) { mails.add(mail); + return mails.size() - 1; } + @Override - public void cleanAll() { - mails.clear(); - } - - @Override - public Queue getEventQueue() { - return new ConcurrentLinkedQueue<>(mails); - } - - public List getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + public List findByTime(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)) && mails.get(i).getDate().equals(timeFrom)) { + if (!(mails.get(i).getCreateDate().isBefore(timeFrom) || mails.get(i).getCreateDate().isAfter(timeTo)) && mails.get(i).getCreateDate().equals(timeFrom)) { rezultMails.add(this.mails.get(i)); - } else if (mails.get(i).getDate().isBefore(timeFrom)) { + } else if (mails.get(i).getCreateDate().isBefore(timeFrom)) { break; } } diff --git a/src/main/java/org/sadtech/bot/core/service/BoardCommentService.java b/src/main/java/org/sadtech/bot/core/service/BoardCommentService.java new file mode 100644 index 0000000..7383614 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/BoardCommentService.java @@ -0,0 +1,6 @@ +package org.sadtech.bot.core.service; + +import org.sadtech.bot.core.domain.content.BoardComment; + +public interface BoardCommentService extends ContentService { +} diff --git a/src/main/java/org/sadtech/bot/core/service/EventService.java b/src/main/java/org/sadtech/bot/core/service/ContentService.java similarity index 56% rename from src/main/java/org/sadtech/bot/core/service/EventService.java rename to src/main/java/org/sadtech/bot/core/service/ContentService.java index 9527c4e..92ccab9 100644 --- a/src/main/java/org/sadtech/bot/core/service/EventService.java +++ b/src/main/java/org/sadtech/bot/core/service/ContentService.java @@ -5,13 +5,11 @@ import org.sadtech.bot.core.domain.content.Content; import java.time.LocalDateTime; import java.util.List; -public interface EventService { +public interface ContentService { void add(T event); - List getEvent(LocalDateTime timeFrom, LocalDateTime timeTo); - - List getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo); + List getByTime(LocalDateTime timeFrom, LocalDateTime timeTo); List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo); diff --git a/src/main/java/org/sadtech/bot/core/service/MailService.java b/src/main/java/org/sadtech/bot/core/service/MailService.java index c461d2f..4a4fbf1 100644 --- a/src/main/java/org/sadtech/bot/core/service/MailService.java +++ b/src/main/java/org/sadtech/bot/core/service/MailService.java @@ -2,6 +2,6 @@ package org.sadtech.bot.core.service; import org.sadtech.bot.core.domain.content.Mail; -public interface MailService extends EventService { +public interface MailService extends ContentService { } diff --git a/src/main/java/org/sadtech/bot/core/service/impl/BoardCommentServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/BoardCommentServiceImpl.java new file mode 100644 index 0000000..d4b7d3d --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/impl/BoardCommentServiceImpl.java @@ -0,0 +1,49 @@ +package org.sadtech.bot.core.service.impl; + +import org.sadtech.bot.core.domain.content.BoardComment; +import org.sadtech.bot.core.repository.ContentRepository; +import org.sadtech.bot.core.service.BoardCommentService; +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 BoardCommentServiceImpl implements BoardCommentService { + + private static final Logger log = LoggerFactory.getLogger(BoardCommentServiceImpl.class); + + private final ContentRepository commentRepository; + + public BoardCommentServiceImpl(ContentRepository commentRepository) { + this.commentRepository = commentRepository; + } + + @Override + public void add(BoardComment event) { + commentRepository.add(event); + } + + @Override + public List getByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + return null; + } + + @Override + public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.info("Запрошены последние комментарии к обсуждению {} - {} ", timeFrom, timeTo); + List mails = commentRepository.findByTime(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; + } +} 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 index cbc20c2..18554b4 100644 --- a/src/main/java/org/sadtech/bot/core/service/impl/MailServiceImpl.java +++ b/src/main/java/org/sadtech/bot/core/service/impl/MailServiceImpl.java @@ -1,7 +1,7 @@ package org.sadtech.bot.core.service.impl; import org.sadtech.bot.core.domain.content.Mail; -import org.sadtech.bot.core.repository.MailRepository; +import org.sadtech.bot.core.repository.ContentRepository; import org.sadtech.bot.core.service.MailService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,9 +16,9 @@ public class MailServiceImpl implements MailService { private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class); - private final MailRepository mailRepository; + private final ContentRepository mailRepository; - public MailServiceImpl(MailRepository mailRepository) { + public MailServiceImpl(ContentRepository mailRepository) { this.mailRepository = mailRepository; } @@ -29,9 +29,9 @@ public class MailServiceImpl implements MailService { } @Override - public List getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { - log.info("Запрошены сообщения {} - {} ", timeFrom, timeTo); - List mails = mailRepository.getMailByTime(timeFrom, timeTo); + public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.info("Запрошены последние сообщения {} - {} ", timeFrom, timeTo); + List mails = mailRepository.findByTime(timeFrom, timeTo); Set people = new HashSet<>(); List returnMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { @@ -44,23 +44,9 @@ public class MailServiceImpl implements MailService { } @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); + public List getByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.info("Запрошены все сообщения {} - {} ", timeFrom, timeTo); + return mailRepository.findByTime(timeFrom, timeTo); } } diff --git a/src/main/java/org/sadtech/bot/core/service/sender/SenderBox.java b/src/main/java/org/sadtech/bot/core/service/sender/SenderBox.java new file mode 100644 index 0000000..a5a9769 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/sender/SenderBox.java @@ -0,0 +1,27 @@ +package org.sadtech.bot.core.service.sender; + +import org.sadtech.bot.core.domain.BoxAnswer; +import org.sadtech.bot.core.domain.content.BoardComment; +import org.sadtech.bot.core.domain.content.Content; +import org.sadtech.bot.core.exception.MailSendException; + +public class SenderBox { + + private SenderBox() { + throw new IllegalStateException("Utility Class"); + } + + public static void sent(Sent sent, Content content, BoxAnswer boxAnswer) { + switch (content.getType()) { + case MAIL: + sent.send(content.getPersonId(), boxAnswer); + break; + case BOARD_COMMENT: + sent.send(((BoardComment) content).getTopicId(), content.getPersonId(), boxAnswer); + break; + default: + throw new MailSendException(); + } + } + +} diff --git a/src/main/java/org/sadtech/bot/core/service/sender/Sent.java b/src/main/java/org/sadtech/bot/core/service/sender/Sent.java index afab375..2f7a266 100644 --- a/src/main/java/org/sadtech/bot/core/service/sender/Sent.java +++ b/src/main/java/org/sadtech/bot/core/service/sender/Sent.java @@ -4,8 +4,8 @@ import org.sadtech.bot.core.domain.BoxAnswer; public interface Sent { - void send(Integer personId, String message); - void send(Integer personId, BoxAnswer boxAnswer); + void send(Integer contentId, Integer personId, BoxAnswer boxAnswer); + } diff --git a/src/main/java/org/sadtech/bot/core/service/sender/email/EmailSent.java b/src/main/java/org/sadtech/bot/core/service/sender/email/EmailSent.java index c04d580..eaf026d 100644 --- a/src/main/java/org/sadtech/bot/core/service/sender/email/EmailSent.java +++ b/src/main/java/org/sadtech/bot/core/service/sender/email/EmailSent.java @@ -21,7 +21,7 @@ public class EmailSent implements Sent { } @Override - public void send(Integer personId, String htmlText) { + public void send(Integer personId, BoxAnswer boxAnswer) { Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { @@ -33,7 +33,7 @@ public class EmailSent implements Sent { 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"); + message.setContent(boxAnswer.getMessage(), "text/html; charset=utf-8"); Transport.send(message); } catch (MessagingException e) { log.error(e.getMessage()); @@ -42,7 +42,7 @@ public class EmailSent implements Sent { } @Override - public void send(Integer personId, BoxAnswer boxAnswer) { + public void send(Integer contentId, Integer personId, BoxAnswer boxAnswer) { throw new MailSendException(); } } From c24239c6fe2a4471d64084041d88a75532831bc3 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 15 Jun 2019 15:15:11 +0300 Subject: [PATCH 2/3] =?UTF-8?q?*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B1=D0=B8=D0=BB=D0=B4=D0=B5=D1=80=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20Unit-=D0=B0=20=D1=81=D1=87=D0=B5=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B8=20=D0=90=D0=B2=D1=82=D0=BE=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D0=B5=20=D0=BE=D0=BF=D0=BB=D0=B0=D1=82=D1=8B=20?= =?UTF-8?q?=D1=81=D1=87=D0=B5=D1=82=D0=B0,=20=D0=B0=20=D1=82=D0=B0=D0=BA?= =?UTF-8?q?=20=D0=B6=D0=B5=20=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=88=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8F=20*=20?= =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=20Builder=20=D0=B2=20AnswerCheck=20*=20=D0=A3?= =?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9=20Unit=20*=20=D0=9F=D1=80=D0=BE=D1=87=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B0=D1=80=D1=85=D0=B8=D1=82=D0=B5=D0=BA=D1=82=D1=83=D1=80?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sadtech/bot/core/domain/BoxAnswer.java | 8 -- .../bot/core/domain/content/BoardComment.java | 34 +------- .../bot/core/domain/content/Comment.java | 30 +++++++ .../bot/core/domain/content/ContentType.java | 2 +- .../{EmptyContent.java => EmptyMessage.java} | 8 +- .../sadtech/bot/core/domain/content/Mail.java | 7 +- .../content/{Content.java => Message.java} | 22 +++--- .../bot/core/domain/keyboard/ButtonType.java | 7 ++ .../core/domain/keyboard/KeyBoardButton.java | 68 ++++------------ .../button/KeyBoardButtonAccount.java | 75 ++++++++++++++++++ .../keyboard/button/KeyBoardButtonText.java | 78 +++++++++++++++++++ .../bot/core/domain/money/Account.java | 6 +- .../core/exception/TimerSettingExceprion.java | 9 +++ .../core/repository/ContentRepository.java | 4 +- .../repository/impl/AccountRepositoryMap.java | 2 +- .../bot/core/service/AccountService.java | 2 +- .../bot/core/service/ContentService.java | 4 +- .../org/sadtech/bot/core/service/Filter.java | 4 +- .../core/service/impl/AccountServiceImpl.java | 2 +- .../bot/core/service/sender/SendBox.java | 26 +++++++ .../bot/core/service/sender/SenderBox.java | 27 ------- .../org/sadtech/bot/core/utils/Contents.java | 4 +- .../org/sadtech/bot/core/utils/KeyBoards.java | 39 +++++++++- 23 files changed, 311 insertions(+), 157 deletions(-) create mode 100644 src/main/java/org/sadtech/bot/core/domain/content/Comment.java rename src/main/java/org/sadtech/bot/core/domain/content/{EmptyContent.java => EmptyMessage.java} (58%) rename src/main/java/org/sadtech/bot/core/domain/content/{Content.java => Message.java} (77%) create mode 100644 src/main/java/org/sadtech/bot/core/domain/keyboard/ButtonType.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/keyboard/button/KeyBoardButtonAccount.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/keyboard/button/KeyBoardButtonText.java create mode 100644 src/main/java/org/sadtech/bot/core/exception/TimerSettingExceprion.java create mode 100644 src/main/java/org/sadtech/bot/core/service/sender/SendBox.java delete mode 100644 src/main/java/org/sadtech/bot/core/service/sender/SenderBox.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 1345258..1cc6246 100644 --- a/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java +++ b/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java @@ -38,10 +38,6 @@ public class BoxAnswer { return keyboard; } - public void setKeyboard(KeyBoard keyboard) { - this.keyboard = keyboard; - } - public GeoCoordinate getCoordinates() { return coordinates; } @@ -50,10 +46,6 @@ public class BoxAnswer { return stickerId; } - public void setStickerId(Integer stickerId) { - this.stickerId = stickerId; - } - public BoxAnswer prototype() { return new BoxAnswer(this); } diff --git a/src/main/java/org/sadtech/bot/core/domain/content/BoardComment.java b/src/main/java/org/sadtech/bot/core/domain/content/BoardComment.java index 123619a..9ca069b 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/BoardComment.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/BoardComment.java @@ -1,41 +1,9 @@ package org.sadtech.bot.core.domain.content; -import java.util.Objects; - -public class BoardComment extends Content { - - private Integer topicId; +public class BoardComment extends Comment { public BoardComment() { type = ContentType.BOARD_COMMENT; } - public Integer getTopicId() { - return topicId; - } - - public void setTopicId(Integer topicId) { - this.topicId = topicId; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BoardComment)) return false; - if (!super.equals(o)) return false; - BoardComment that = (BoardComment) o; - return Objects.equals(topicId, that.topicId); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), topicId); - } - - @Override - public String toString() { - return "BoardComment{" + - "topicId=" + topicId + - "} " + super.toString(); - } } diff --git a/src/main/java/org/sadtech/bot/core/domain/content/Comment.java b/src/main/java/org/sadtech/bot/core/domain/content/Comment.java new file mode 100644 index 0000000..ca32e31 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/content/Comment.java @@ -0,0 +1,30 @@ +package org.sadtech.bot.core.domain.content; + +import java.util.Objects; + +public abstract class Comment extends Message { + + private Integer contentId; + + public Integer getContentId() { + return contentId; + } + + public void setContentId(Integer contentId) { + this.contentId = contentId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Comment)) return false; + if (!super.equals(o)) return false; + Comment that = (Comment) o; + return Objects.equals(contentId, that.contentId); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), contentId); + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/content/ContentType.java b/src/main/java/org/sadtech/bot/core/domain/content/ContentType.java index e6a9443..89e1d4e 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/ContentType.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/ContentType.java @@ -2,6 +2,6 @@ package org.sadtech.bot.core.domain.content; public enum ContentType { - MAIL, BOARD_COMMENT + MAIL, BOARD_COMMENT, EMPTY } diff --git a/src/main/java/org/sadtech/bot/core/domain/content/EmptyContent.java b/src/main/java/org/sadtech/bot/core/domain/content/EmptyMessage.java similarity index 58% rename from src/main/java/org/sadtech/bot/core/domain/content/EmptyContent.java rename to src/main/java/org/sadtech/bot/core/domain/content/EmptyMessage.java index 2400a1e..16498c3 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/EmptyContent.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/EmptyMessage.java @@ -2,7 +2,11 @@ package org.sadtech.bot.core.domain.content; import org.sadtech.bot.core.exception.AppBotException; -public class EmptyContent extends Content { +public class EmptyMessage extends Message { + + public EmptyMessage() { + type = ContentType.EMPTY; + } @Override public String getMessage() { @@ -11,6 +15,6 @@ public class EmptyContent extends Content { @Override public void setMessage(String message) { - throw new AppBotException(0, "EmptyContent no setMessage"); + throw new AppBotException(0, "EmptyMessage no setMessage"); } } diff --git a/src/main/java/org/sadtech/bot/core/domain/content/Mail.java b/src/main/java/org/sadtech/bot/core/domain/content/Mail.java index 6fa86d1..f09e4a3 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/Mail.java @@ -5,11 +5,10 @@ import org.sadtech.bot.core.domain.content.attachment.Attachment; import java.util.List; import java.util.Objects; -public class Mail extends Content { +public class Mail extends Message { private List attachments; - public Mail() { type = ContentType.MAIL; } @@ -32,6 +31,7 @@ public class Mail extends Content { this.attachments = attachments; } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -50,6 +50,7 @@ public class Mail extends Content { public String toString() { return "Mail{" + "attachments=" + attachments + - "} " + super.toString(); + ", type=" + type + + '}'; } } diff --git a/src/main/java/org/sadtech/bot/core/domain/content/Content.java b/src/main/java/org/sadtech/bot/core/domain/content/Message.java similarity index 77% rename from src/main/java/org/sadtech/bot/core/domain/content/Content.java rename to src/main/java/org/sadtech/bot/core/domain/content/Message.java index 0ca99f2..ecaf204 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/Content.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/Message.java @@ -3,7 +3,7 @@ package org.sadtech.bot.core.domain.content; import java.time.LocalDateTime; import java.util.Objects; -public abstract class Content { +public abstract class Message { private Integer id; protected ContentType type; @@ -11,11 +11,11 @@ public abstract class Content { private Integer personId; private String message; - public Content() { + public Message() { } - public Content(Content source) { + public Message(Message source) { this.personId = source.getPersonId(); this.message = source.getMessage(); this.createDate = source.getCreateDate(); @@ -66,13 +66,13 @@ public abstract class Content { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof Content)) return false; - Content content = (Content) o; - return Objects.equals(id, content.id) && - type == content.type && - Objects.equals(createDate, content.createDate) && - Objects.equals(personId, content.personId) && - Objects.equals(message, content.message); + if (!(o instanceof Message)) return false; + Message message = (Message) o; + return Objects.equals(id, message.id) && + type == message.type && + Objects.equals(createDate, message.createDate) && + Objects.equals(personId, message.personId) && + Objects.equals(this.message, message.message); } @Override @@ -82,7 +82,7 @@ public abstract class Content { @Override public String toString() { - return "Content{" + + return "Message{" + "id=" + id + ", type=" + type + ", createDate=" + createDate + diff --git a/src/main/java/org/sadtech/bot/core/domain/keyboard/ButtonType.java b/src/main/java/org/sadtech/bot/core/domain/keyboard/ButtonType.java new file mode 100644 index 0000000..5a253e4 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/ButtonType.java @@ -0,0 +1,7 @@ +package org.sadtech.bot.core.domain.keyboard; + +public enum ButtonType { + + TEXT, ACCOUNT + +} 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 index e5c0d80..b783a13 100644 --- a/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardButton.java +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardButton.java @@ -2,80 +2,38 @@ package org.sadtech.bot.core.domain.keyboard; import java.util.Objects; -public class KeyBoardButton { +public abstract class KeyBoardButton { - private String payload; - private String label; - private ButtonColor color = ButtonColor.DEFAULT; - - private KeyBoardButton() { - - } + protected String payload; + protected ButtonType type = ButtonType.TEXT; public String getPayload() { return payload; } - public String getLabel() { - return label; + public void setPayload(String payload) { + this.payload = payload; } - public ButtonColor getColor() { - return color; + public ButtonType getType() { + return type; } - 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; - } - + public void setType(ButtonType type) { + this.type = type; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof KeyBoardButton)) return false; - KeyBoardButton button = (KeyBoardButton) o; - return Objects.equals(payload, button.payload) && - Objects.equals(label, button.label) && - color == button.color; + KeyBoardButton that = (KeyBoardButton) o; + return Objects.equals(payload, that.payload) && + type == that.type; } @Override public int hashCode() { - return Objects.hash(payload, label, color); - } - - @Override - public String toString() { - return "KeyBoardButton{" + - "payload='" + payload + '\'' + - ", label='" + label + '\'' + - ", color=" + color + - '}'; + return Objects.hash(payload, type); } } diff --git a/src/main/java/org/sadtech/bot/core/domain/keyboard/button/KeyBoardButtonAccount.java b/src/main/java/org/sadtech/bot/core/domain/keyboard/button/KeyBoardButtonAccount.java new file mode 100644 index 0000000..49fce62 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/button/KeyBoardButtonAccount.java @@ -0,0 +1,75 @@ +package org.sadtech.bot.core.domain.keyboard.button; + +import org.sadtech.bot.core.domain.keyboard.ButtonType; +import org.sadtech.bot.core.domain.keyboard.KeyBoardButton; + +import java.util.Objects; + +public class KeyBoardButtonAccount extends KeyBoardButton { + + private Integer amount; + private Integer accountId; + private String description; + + private KeyBoardButtonAccount() { + type = ButtonType.ACCOUNT; + } + + public Integer getAmount() { + return amount; + } + + public String getDescription() { + return description; + } + + public Integer getAccountId() { + return accountId; + } + + public static Builder builder() { + return new KeyBoardButtonAccount().new Builder(); + } + + public class Builder { + private Builder() { + + } + + public Builder amount(Integer amount) { + KeyBoardButtonAccount.this.amount = amount; + return this; + } + + public Builder description(String description) { + KeyBoardButtonAccount.this.description = description; + return this; + } + + public Builder accountId(Integer accountId) { + KeyBoardButtonAccount.this.accountId = accountId; + return this; + } + + + public KeyBoardButtonAccount build() { + return KeyBoardButtonAccount.this; + } + + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof KeyBoardButtonAccount)) return false; + if (!super.equals(o)) return false; + KeyBoardButtonAccount that = (KeyBoardButtonAccount) o; + return Objects.equals(amount, that.amount) && + Objects.equals(description, that.description); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), amount, description); + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/keyboard/button/KeyBoardButtonText.java b/src/main/java/org/sadtech/bot/core/domain/keyboard/button/KeyBoardButtonText.java new file mode 100644 index 0000000..ae00f2c --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/button/KeyBoardButtonText.java @@ -0,0 +1,78 @@ +package org.sadtech.bot.core.domain.keyboard.button; + +import org.sadtech.bot.core.domain.keyboard.ButtonColor; +import org.sadtech.bot.core.domain.keyboard.ButtonType; +import org.sadtech.bot.core.domain.keyboard.KeyBoardButton; + +import java.util.Objects; + +public class KeyBoardButtonText extends KeyBoardButton { + + private String label; + private ButtonColor color = ButtonColor.DEFAULT; + + public KeyBoardButtonText() { + type = ButtonType.TEXT; + } + + public ButtonColor getColor() { + return color; + } + + public String getLabel() { + return label; + } + + public static Builder builder() { + return new KeyBoardButtonText().new Builder(); + } + + public class Builder { + private Builder() { + + } + + public Builder label(String label) { + KeyBoardButtonText.this.label = label; + return this; + } + + public Builder color(ButtonColor color) { + KeyBoardButtonText.this.color = color; + return this; + } + + public Builder payload(String payload) { + KeyBoardButtonText.this.payload = payload; + return this; + } + + public KeyBoardButtonText build() { + return KeyBoardButtonText.this; + } + + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof KeyBoardButtonText)) return false; + if (!super.equals(o)) return false; + KeyBoardButtonText that = (KeyBoardButtonText) o; + return Objects.equals(label, that.label) && + color == that.color; + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), label, color); + } + + @Override + public String toString() { + return "KeyBoardButtonText{" + + "label='" + label + '\'' + + ", color=" + color + + '}'; + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/money/Account.java b/src/main/java/org/sadtech/bot/core/domain/money/Account.java index 836f802..bb7c996 100644 --- a/src/main/java/org/sadtech/bot/core/domain/money/Account.java +++ b/src/main/java/org/sadtech/bot/core/domain/money/Account.java @@ -5,7 +5,7 @@ import java.util.Objects; public class Account { private Integer id; - private Double totalSum; + private Integer totalSum; private Integer belongsPersonId; private Integer extinguishedPersonId; private String description; @@ -19,11 +19,11 @@ public class Account { this.id = id; } - public Double getTotalSum() { + public Integer getTotalSum() { return totalSum; } - public void setTotalSum(Double totalSum) { + public void setTotalSum(Integer totalSum) { this.totalSum = totalSum; } diff --git a/src/main/java/org/sadtech/bot/core/exception/TimerSettingExceprion.java b/src/main/java/org/sadtech/bot/core/exception/TimerSettingExceprion.java new file mode 100644 index 0000000..0691440 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/exception/TimerSettingExceprion.java @@ -0,0 +1,9 @@ +package org.sadtech.bot.core.exception; + +public class TimerSettingExceprion extends AppBotException { + + public TimerSettingExceprion(String message) { + super(54, message); + } + +} diff --git a/src/main/java/org/sadtech/bot/core/repository/ContentRepository.java b/src/main/java/org/sadtech/bot/core/repository/ContentRepository.java index 91a800a..bc78dfb 100644 --- a/src/main/java/org/sadtech/bot/core/repository/ContentRepository.java +++ b/src/main/java/org/sadtech/bot/core/repository/ContentRepository.java @@ -1,11 +1,11 @@ package org.sadtech.bot.core.repository; -import org.sadtech.bot.core.domain.content.Content; +import org.sadtech.bot.core.domain.content.Message; import java.time.LocalDateTime; import java.util.List; -public interface ContentRepository { +public interface ContentRepository { Integer add(T content); diff --git a/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java index a5fa3de..abc2fae 100644 --- a/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java +++ b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java @@ -43,6 +43,6 @@ public class AccountRepositoryMap implements AccountRepository { } private boolean check(Integer id) { - return saveMap.containsKey(id); + return !saveMap.containsKey(id); } } diff --git a/src/main/java/org/sadtech/bot/core/service/AccountService.java b/src/main/java/org/sadtech/bot/core/service/AccountService.java index 4a1bae7..2c0cd62 100644 --- a/src/main/java/org/sadtech/bot/core/service/AccountService.java +++ b/src/main/java/org/sadtech/bot/core/service/AccountService.java @@ -6,7 +6,7 @@ public interface AccountService { Integer add(Account account); - Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum); + Boolean pay(Integer accountId, Integer extinguishedPersonId, Integer sum); Boolean paymentVerification(Integer accountId); diff --git a/src/main/java/org/sadtech/bot/core/service/ContentService.java b/src/main/java/org/sadtech/bot/core/service/ContentService.java index 92ccab9..6fdf9e7 100644 --- a/src/main/java/org/sadtech/bot/core/service/ContentService.java +++ b/src/main/java/org/sadtech/bot/core/service/ContentService.java @@ -1,11 +1,11 @@ package org.sadtech.bot.core.service; -import org.sadtech.bot.core.domain.content.Content; +import org.sadtech.bot.core.domain.content.Message; import java.time.LocalDateTime; import java.util.List; -public interface ContentService { +public interface ContentService { void add(T event); diff --git a/src/main/java/org/sadtech/bot/core/service/Filter.java b/src/main/java/org/sadtech/bot/core/service/Filter.java index 4da035f..9662f2e 100644 --- a/src/main/java/org/sadtech/bot/core/service/Filter.java +++ b/src/main/java/org/sadtech/bot/core/service/Filter.java @@ -1,9 +1,9 @@ package org.sadtech.bot.core.service; -import org.sadtech.bot.core.domain.content.Content; +import org.sadtech.bot.core.domain.content.Message; @FunctionalInterface -public interface Filter { +public interface Filter { void processing(T content); diff --git a/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java index e13d53c..bc9a39a 100644 --- a/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java +++ b/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java @@ -21,7 +21,7 @@ public class AccountServiceImpl implements AccountService { } @Override - public Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum) { + public Boolean pay(Integer accountId, Integer extinguishedPersonId, Integer sum) { Account account = accountRepository.findById(accountId); if (validStatus(account.getAccountStatus())) { if (account.getTotalSum().equals(sum)) { diff --git a/src/main/java/org/sadtech/bot/core/service/sender/SendBox.java b/src/main/java/org/sadtech/bot/core/service/sender/SendBox.java new file mode 100644 index 0000000..942de5b --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/sender/SendBox.java @@ -0,0 +1,26 @@ +package org.sadtech.bot.core.service.sender; + +import org.sadtech.bot.core.domain.BoxAnswer; +import org.sadtech.bot.core.domain.content.Comment; +import org.sadtech.bot.core.domain.content.Message; + +public class SendBox { + + private SendBox() { + + } + + public static void sent(Message message, BoxAnswer boxAnswer, Sent sent) { + switch (message.getType()) { + case BOARD_COMMENT: + sent.send(((Comment) message).getContentId(), message.getPersonId(), boxAnswer); + break; + case MAIL: + sent.send(message.getPersonId(), boxAnswer); + break; + default: + sent.send(message.getPersonId(), boxAnswer); + } + } + +} diff --git a/src/main/java/org/sadtech/bot/core/service/sender/SenderBox.java b/src/main/java/org/sadtech/bot/core/service/sender/SenderBox.java deleted file mode 100644 index a5a9769..0000000 --- a/src/main/java/org/sadtech/bot/core/service/sender/SenderBox.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.sadtech.bot.core.service.sender; - -import org.sadtech.bot.core.domain.BoxAnswer; -import org.sadtech.bot.core.domain.content.BoardComment; -import org.sadtech.bot.core.domain.content.Content; -import org.sadtech.bot.core.exception.MailSendException; - -public class SenderBox { - - private SenderBox() { - throw new IllegalStateException("Utility Class"); - } - - public static void sent(Sent sent, Content content, BoxAnswer boxAnswer) { - switch (content.getType()) { - case MAIL: - sent.send(content.getPersonId(), boxAnswer); - break; - case BOARD_COMMENT: - sent.send(((BoardComment) content).getTopicId(), content.getPersonId(), boxAnswer); - break; - default: - throw new MailSendException(); - } - } - -} diff --git a/src/main/java/org/sadtech/bot/core/utils/Contents.java b/src/main/java/org/sadtech/bot/core/utils/Contents.java index 9b417b1..5f674d0 100644 --- a/src/main/java/org/sadtech/bot/core/utils/Contents.java +++ b/src/main/java/org/sadtech/bot/core/utils/Contents.java @@ -1,6 +1,6 @@ package org.sadtech.bot.core.utils; -import org.sadtech.bot.core.domain.content.EmptyContent; +import org.sadtech.bot.core.domain.content.EmptyMessage; public class Contents { @@ -8,7 +8,7 @@ public class Contents { throw new IllegalStateException("Utility class"); } - public static final EmptyContent EMPTY_CONTENT = new EmptyContent(); + public static final EmptyMessage EMPTY_CONTENT = new EmptyMessage(); } diff --git a/src/main/java/org/sadtech/bot/core/utils/KeyBoards.java b/src/main/java/org/sadtech/bot/core/utils/KeyBoards.java index cb878f5..d5cb42d 100644 --- a/src/main/java/org/sadtech/bot/core/utils/KeyBoards.java +++ b/src/main/java/org/sadtech/bot/core/utils/KeyBoards.java @@ -4,6 +4,7 @@ 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 org.sadtech.bot.core.domain.keyboard.button.KeyBoardButtonText; import java.util.List; @@ -14,8 +15,8 @@ public class KeyBoards { } 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(); + KeyBoardButton yesButton = KeyBoardButtonText.builder().color(ButtonColor.POSITIVE).label("Да").payload("{\"button\": \"yes\"}").build(); + KeyBoardButton noButton = KeyBoardButtonText.builder().color(ButtonColor.NEGATIVE).label("Нет").payload("{\"button\": \"no\"}").build(); KeyBoardLine keyBoardLine = KeyBoardLine.builder().buttonKeyBoard(yesButton).buttonKeyBoard(noButton).build(); return KeyBoard.builder().lineKeyBoard(keyBoardLine).oneTime(true).build(); } @@ -23,12 +24,39 @@ public class KeyBoards { 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(); + KeyBoardButton keyBoardButton = KeyBoardButtonText.builder().label(labelButton).payload("{\"button\": \"" + labelButton + "\"}").build(); keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build()); } return keyBoard.build(); } + public static KeyBoard verticalMenuString(String... labelButton) { + KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true); + for (String label : labelButton) { + KeyBoardButton keyBoardButton = KeyBoardButtonText.builder().label(label).payload("{\"button\": \"" + label + "\"}").build(); + keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build()); + } + return keyBoard.build(); + } + + public static KeyBoard verticalDuoMenuString(String... labelButton) { + KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true); + boolean flag = true; + KeyBoardLine.Builder keyBoardLine = KeyBoardLine.builder(); + for (String label : labelButton) { + if (flag) { + keyBoardLine.buttonKeyBoard(KeyBoardButtonText.builder().label(label).build()); + flag = false; + } else { + keyBoardLine.buttonKeyBoard(KeyBoardButtonText.builder().label(label).build()); + keyBoard.lineKeyBoard(keyBoardLine.build()); + keyBoardLine = KeyBoardLine.builder(); + flag = true; + } + } + return keyBoard.build(); + } + public static KeyBoard verticalMenuButton(List keyBoardButtons) { KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true); for (KeyBoardButton keyBoardButton : keyBoardButtons) { @@ -36,4 +64,9 @@ public class KeyBoards { } return keyBoard.build(); } + + public static KeyBoard singelton(KeyBoardButton keyBoardButton) { + KeyBoardLine line = KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build(); + return KeyBoard.builder().lineKeyBoard(line).build(); + } } From 3dc880f601e2d70cda3146fc9954b54b9189d8a0 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 15 Jun 2019 15:18:36 +0300 Subject: [PATCH 3/3] release-0.6.2 --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bc9a476..e00f490 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.bot bot-core - 0.6.2-SNAPSHOT + 0.6.2-RELEASE jar @@ -57,6 +57,7 @@ uPagge + SADTECH Struchkov Mark upagge@mail.ru