Первая рабочая версия с lombok и javadoc

This commit is contained in:
Mark Struchkov 2019-07-12 11:41:25 +03:00
parent 5d80ce8faf
commit ad9a47d837
85 changed files with 965 additions and 1056 deletions

14
pom.xml
View File

@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sadtech.bot</groupId>
<artifactId>bot-core</artifactId>
<version>0.6.2-RELEASE</version>
<groupId>org.sadtech.social</groupId>
<artifactId>social-core</artifactId>
<version>0.6.3-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
@ -26,7 +26,6 @@
<gson.ver>2.8.5</gson.ver>
<slf4j.ver>1.7.26</slf4j.ver>
<mail.ver>1.4</mail.ver>
<junit.ver>4.12</junit.ver>
</properties>
<dependencies>
@ -35,6 +34,7 @@
<artifactId>gson</artifactId>
<version>${gson.ver}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -48,9 +48,9 @@
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.ver}</version>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
</dependencies>

View File

@ -1,9 +0,0 @@
package org.sadtech.bot.core.domain.content;
public class BoardComment extends Comment {
public BoardComment() {
type = ContentType.BOARD_COMMENT;
}
}

View File

@ -1,30 +0,0 @@
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);
}
}

View File

@ -1,7 +0,0 @@
package org.sadtech.bot.core.domain.content;
public enum ContentType {
MAIL, BOARD_COMMENT, EMPTY
}

View File

@ -1,20 +0,0 @@
package org.sadtech.bot.core.domain.content;
import org.sadtech.bot.core.exception.AppBotException;
public class EmptyMessage extends Message {
public EmptyMessage() {
type = ContentType.EMPTY;
}
@Override
public String getMessage() {
return "";
}
@Override
public void setMessage(String message) {
throw new AppBotException(0, "EmptyMessage no setMessage");
}
}

View File

@ -1,56 +0,0 @@
package org.sadtech.bot.core.domain.content;
import org.sadtech.bot.core.domain.content.attachment.Attachment;
import java.util.List;
import java.util.Objects;
public class Mail extends Message {
private List<Attachment> attachments;
public Mail() {
type = ContentType.MAIL;
}
public Mail(Mail source) {
super(source);
this.attachments = source.getAttachments();
}
public Mail prototype() {
return new Mail(this);
}
public List<Attachment> getAttachments() {
return attachments;
}
public void setAttachments(List<Attachment> attachments) {
this.attachments = attachments;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Mail)) return false;
if (!super.equals(o)) return false;
Mail mail = (Mail) o;
return Objects.equals(attachments, mail.attachments);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), attachments);
}
@Override
public String toString() {
return "Mail{" +
"attachments=" + attachments +
", type=" + type +
'}';
}
}

View File

@ -1,93 +0,0 @@
package org.sadtech.bot.core.domain.content;
import java.time.LocalDateTime;
import java.util.Objects;
public abstract class Message {
private Integer id;
protected ContentType type;
private LocalDateTime createDate;
private Integer personId;
private String message;
public Message() {
}
public Message(Message source) {
this.personId = source.getPersonId();
this.message = source.getMessage();
this.createDate = source.getCreateDate();
this.id = source.getPersonId();
this.type = source.getType();
}
public Integer getPersonId() {
return personId;
}
public void setPersonId(Integer personId) {
this.personId = personId;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
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 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
public int hashCode() {
return Objects.hash(id, type, createDate, personId, message);
}
@Override
public String toString() {
return "Message{" +
"id=" + id +
", type=" + type +
", createDate=" + createDate +
", personId=" + personId +
", message='" + message + '\'' +
'}';
}
}

View File

@ -1,11 +0,0 @@
package org.sadtech.bot.core.domain.content.attachment;
public abstract class Attachment {
protected AttachmentType type;
public AttachmentType getType() {
return type;
}
}

View File

@ -1,7 +0,0 @@
package org.sadtech.bot.core.domain.content.attachment;
public enum AttachmentType {
AUDIO_MESSAGE, GEO
}

View File

@ -1,42 +0,0 @@
package org.sadtech.bot.core.domain.content.attachment;
import java.net.URL;
import java.util.Objects;
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;
}
@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 +
'}';
}
}

View File

@ -1,79 +0,0 @@
package org.sadtech.bot.core.domain.content.attachment;
import java.util.Objects;
public class Geo extends Attachment {
private GeoCoordinate geoCoordinate;
private String country;
private String city;
private Geo() {
type = AttachmentType.GEO;
}
public GeoCoordinate getGeoCoordinate() {
return geoCoordinate;
}
public String getCountry() {
return country;
}
public String getCity() {
return city;
}
public static Builder builder() {
return new Geo().new Builder();
}
public class Builder {
private Builder() {
}
public Builder coordinate(Float lat, Float aLong) {
Geo.this.geoCoordinate = new GeoCoordinate(lat, aLong);
return this;
}
public Builder country(String countryName) {
Geo.this.country = countryName;
return this;
}
public Builder city(String cityName) {
Geo.this.city = cityName;
return this;
}
public Geo build() {
return Geo.this;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Geo)) return false;
Geo geo = (Geo) o;
return Objects.equals(geoCoordinate, geo.geoCoordinate) &&
Objects.equals(country, geo.country) &&
Objects.equals(city, geo.city);
}
@Override
public int hashCode() {
return Objects.hash(geoCoordinate, country, city);
}
@Override
public String toString() {
return "Geo{" +
"geoCoordinate=" + geoCoordinate +
", country='" + country + '\'' +
", city='" + city + '\'' +
'}';
}
}

View File

@ -1,28 +0,0 @@
package org.sadtech.bot.core.domain.content.attachment;
public class GeoCoordinate {
private Float latitude;
private Float longitude;
public GeoCoordinate(Float latitude, Float longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public Float getLatitude() {
return latitude;
}
public void setLatitude(Float latitude) {
this.latitude = latitude;
}
public Float getLongitude() {
return longitude;
}
public void setLongitude(Float longitude) {
this.longitude = longitude;
}
}

View File

@ -1,7 +0,0 @@
package org.sadtech.bot.core.domain.keyboard;
public enum ButtonColor {
PRIMARY, DEFAULT, NEGATIVE, POSITIVE
}

View File

@ -1,7 +0,0 @@
package org.sadtech.bot.core.domain.keyboard;
public enum ButtonType {
TEXT, ACCOUNT
}

View File

@ -1,71 +0,0 @@
package org.sadtech.bot.core.domain.keyboard;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class KeyBoard {
private List<KeyBoardLine> keyBoardLines = new ArrayList<>();
private boolean oneTime = true;
private KeyBoard() {
}
public List<KeyBoardLine> 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;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof KeyBoard)) return false;
KeyBoard keyBoard = (KeyBoard) o;
return oneTime == keyBoard.oneTime &&
Objects.equals(keyBoardLines, keyBoard.keyBoardLines);
}
@Override
public int hashCode() {
return Objects.hash(keyBoardLines, oneTime);
}
@Override
public String toString() {
return "KeyBoard{" +
"keyBoardLines=" + keyBoardLines +
", oneTime=" + oneTime +
'}';
}
}

View File

@ -1,39 +0,0 @@
package org.sadtech.bot.core.domain.keyboard;
import java.util.Objects;
public abstract class KeyBoardButton {
protected String payload;
protected ButtonType type = ButtonType.TEXT;
public String getPayload() {
return payload;
}
public void setPayload(String payload) {
this.payload = payload;
}
public ButtonType getType() {
return type;
}
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 that = (KeyBoardButton) o;
return Objects.equals(payload, that.payload) &&
type == that.type;
}
@Override
public int hashCode() {
return Objects.hash(payload, type);
}
}

View File

@ -1,58 +0,0 @@
package org.sadtech.bot.core.domain.keyboard;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class KeyBoardLine {
private List<KeyBoardButton> keyBoardButtons = new ArrayList<>();
private KeyBoardLine() {
}
public List<KeyBoardButton> getKeyBoardButtons() {
return keyBoardButtons;
}
public static Builder builder() {
return new KeyBoardLine().new Builder();
}
public class Builder {
private Builder() {
}
public Builder buttonKeyBoard(KeyBoardButton keyBoardButton) {
KeyBoardLine.this.keyBoardButtons.add(keyBoardButton);
return this;
}
public KeyBoardLine build() {
return KeyBoardLine.this;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof KeyBoardLine)) return false;
KeyBoardLine that = (KeyBoardLine) o;
return Objects.equals(keyBoardButtons, that.keyBoardButtons);
}
@Override
public int hashCode() {
return Objects.hash(keyBoardButtons);
}
@Override
public String toString() {
return "KeyBoardLine{" +
"keyBoardButtons=" + keyBoardButtons +
'}';
}
}

View File

@ -1,75 +0,0 @@
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);
}
}

View File

@ -1,78 +0,0 @@
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 +
'}';
}
}

View File

@ -1,91 +0,0 @@
package org.sadtech.bot.core.domain.money;
import java.util.Objects;
public class Account {
private Integer id;
private Integer totalSum;
private Integer belongsPersonId;
private Integer extinguishedPersonId;
private String description;
private AccountStatus accountStatus;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getTotalSum() {
return totalSum;
}
public void setTotalSum(Integer totalSum) {
this.totalSum = totalSum;
}
public Integer getBelongsPersonId() {
return belongsPersonId;
}
public void setBelongsPersonId(Integer belongsPersonId) {
this.belongsPersonId = belongsPersonId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public AccountStatus getAccountStatus() {
return accountStatus;
}
public void setAccountStatus(AccountStatus accountStatus) {
this.accountStatus = accountStatus;
}
public Integer getExtinguishedPersonId() {
return extinguishedPersonId;
}
public void setExtinguishedPersonId(Integer extinguishedPersonId) {
this.extinguishedPersonId = extinguishedPersonId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Account)) return false;
Account account = (Account) o;
return Objects.equals(id, account.id) &&
Objects.equals(totalSum, account.totalSum) &&
Objects.equals(belongsPersonId, account.belongsPersonId) &&
Objects.equals(extinguishedPersonId, account.extinguishedPersonId) &&
Objects.equals(description, account.description) &&
accountStatus == account.accountStatus;
}
@Override
public int hashCode() {
return Objects.hash(id, totalSum, belongsPersonId, extinguishedPersonId, description, accountStatus);
}
@Override
public String toString() {
return "Account{" +
"id=" + id +
", totalSum=" + totalSum +
", belongsPersonId=" + belongsPersonId +
", extinguishedPersonId=" + extinguishedPersonId +
", description='" + description + '\'' +
", accountStatus=" + accountStatus +
'}';
}
}

View File

@ -1,7 +0,0 @@
package org.sadtech.bot.core.domain.money;
public enum AccountStatus {
EXPOSED, CLOSED, CANCELLED, EXCEPTION
}

View File

@ -1,9 +0,0 @@
package org.sadtech.bot.core.exception;
public class TimerSettingExceprion extends AppBotException {
public TimerSettingExceprion(String message) {
super(54, message);
}
}

View File

@ -1,13 +0,0 @@
package org.sadtech.bot.core.repository;
import org.sadtech.bot.core.domain.money.Account;
public interface AccountRepository {
Integer add(Account account);
void edit(Integer accountId, Account account);
Account findById(Integer accountId);
}

View File

@ -1,14 +0,0 @@
package org.sadtech.bot.core.repository;
import org.sadtech.bot.core.domain.content.Message;
import java.time.LocalDateTime;
import java.util.List;
public interface ContentRepository<T extends Message> {
Integer add(T content);
List<T> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
}

View File

@ -1,13 +0,0 @@
package org.sadtech.bot.core.repository;
import java.util.Queue;
public interface EventRepository<T> {
void add(T dataObject);
void cleanAll();
Queue<T> getEventQueue();
}

View File

@ -1,13 +0,0 @@
package org.sadtech.bot.core.service;
import org.sadtech.bot.core.domain.money.Account;
public interface AccountService {
Integer add(Account account);
Boolean pay(Integer accountId, Integer extinguishedPersonId, Integer sum);
Boolean paymentVerification(Integer accountId);
}

View File

@ -1,6 +0,0 @@
package org.sadtech.bot.core.service;
import org.sadtech.bot.core.domain.content.BoardComment;
public interface BoardCommentService extends ContentService<BoardComment> {
}

View File

@ -1,16 +0,0 @@
package org.sadtech.bot.core.service;
import org.sadtech.bot.core.domain.content.Message;
import java.time.LocalDateTime;
import java.util.List;
public interface ContentService<T extends Message> {
void add(T event);
List<T> getByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
List<T> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
}

View File

@ -1,10 +0,0 @@
package org.sadtech.bot.core.service;
import org.sadtech.bot.core.domain.content.Message;
@FunctionalInterface
public interface Filter<T extends Message> {
void processing(T content);
}

View File

@ -1,7 +0,0 @@
package org.sadtech.bot.core.service;
import org.sadtech.bot.core.domain.content.Mail;
public interface MailService extends ContentService<Mail> {
}

View File

@ -1,11 +0,0 @@
package org.sadtech.bot.core.service.sender;
import org.sadtech.bot.core.domain.BoxAnswer;
public interface Sent {
void send(Integer personId, BoxAnswer boxAnswer);
void send(Integer contentId, Integer personId, BoxAnswer boxAnswer);
}

View File

@ -1,14 +0,0 @@
package org.sadtech.bot.core.utils;
import org.sadtech.bot.core.domain.content.EmptyMessage;
public class Contents {
private Contents() {
throw new IllegalStateException("Utility class");
}
public static final EmptyMessage EMPTY_CONTENT = new EmptyMessage();
}

View File

@ -1,15 +1,32 @@
package org.sadtech.bot.core.domain;
package org.sadtech.social.core.domain;
import org.sadtech.bot.core.domain.content.attachment.GeoCoordinate;
import org.sadtech.bot.core.domain.keyboard.KeyBoard;
import java.util.Objects;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.sadtech.social.core.domain.content.attachment.GeoCoordinate;
import org.sadtech.social.core.domain.keyboard.KeyBoard;
import org.sadtech.social.core.utils.Description;
/**
* Контейнер, которые содержит данные, которые будут отправлены пользователю как ответ на его запрос.
*
* @author upagge [08/07/2019]
*/
@EqualsAndHashCode
@ToString
@Getter
public class BoxAnswer {
@Description("Обычное текстовое сообщение")
private String message;
@Description("Клавиатура - меню")
private KeyBoard keyboard;
@Description("Географические координаты")
private GeoCoordinate coordinates;
@Description("Идентификатор стикера")
private Integer stickerId;
private BoxAnswer() {
@ -25,27 +42,10 @@ public class BoxAnswer {
}
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public KeyBoard getKeyboard() {
return keyboard;
}
public GeoCoordinate getCoordinates() {
return coordinates;
}
public Integer getStickerId() {
return stickerId;
}
public BoxAnswer prototype() {
return new BoxAnswer(this);
}
@ -84,29 +84,4 @@ public class BoxAnswer {
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof BoxAnswer)) return false;
BoxAnswer boxAnswer = (BoxAnswer) o;
return Objects.equals(message, boxAnswer.message) &&
Objects.equals(keyboard, boxAnswer.keyboard) &&
Objects.equals(coordinates, boxAnswer.coordinates) &&
Objects.equals(stickerId, boxAnswer.stickerId);
}
@Override
public int hashCode() {
return Objects.hash(message, keyboard, coordinates, stickerId);
}
@Override
public String toString() {
return "BoxAnswer{" +
"message='" + message + '\'' +
", keyboard=" + keyboard +
", coordinates=" + coordinates +
", stickerId=" + stickerId +
'}';
}
}

View File

@ -0,0 +1,14 @@
package org.sadtech.social.core.domain.content;
/**
* Сообщение от пользователя типа "Комментарий к обсуждению группы".
*
* @author upagge [08/07/2019]
*/
public class BoardComment extends Comment {
public BoardComment() {
type = ContentType.BOARD_COMMENT;
}
}

View File

@ -0,0 +1,17 @@
package org.sadtech.social.core.domain.content;
import lombok.Data;
import org.sadtech.social.core.utils.Description;
/**
* Абстрактная сущность для сообщений от пользователей с привязкой к какому-то контенту (картинка, видео).
*
* @author upagge [08/07/2019]
*/
@Data
public abstract class Comment extends Message {
@Description("Идентификатор контента, к которому ставлено сообщение")
private Integer contentId;
}

View File

@ -0,0 +1,12 @@
package org.sadtech.social.core.domain.content;
/**
* Тип сообщения от пользователя {@link Message}.
*
* @author upagge [08/07/2019]
*/
public enum ContentType {
MAIL, BOARD_COMMENT, EMPTY
}

View File

@ -0,0 +1,27 @@
package org.sadtech.social.core.domain.content;
import lombok.ToString;
import org.sadtech.social.core.exception.AppBotException;
/**
* Заглушка для сообщения от пользователя.
*
* @author upagge [08/07/2019]
*/
@ToString
public class EmptyMessage extends Message {
public EmptyMessage() {
type = ContentType.EMPTY;
}
@Override
public String getText() {
return "";
}
@Override
public void setText(String text) {
throw new AppBotException(0, "EmptyMessage no setText");
}
}

View File

@ -0,0 +1,36 @@
package org.sadtech.social.core.domain.content;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.sadtech.social.core.domain.content.attachment.Attachment;
import org.sadtech.social.core.utils.Description;
import java.util.List;
/**
* Сообщение от пользователя типа "Личное сообщение".
*
* @author upagge [08/07/2019]
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class Mail extends Message {
@Description("Вложения к сообщению")
private List<Attachment> attachments;
public Mail() {
type = ContentType.MAIL;
}
public Mail(Mail source) {
super(source);
this.attachments = source.getAttachments();
}
public Mail prototype() {
return new Mail(this);
}
}

View File

@ -0,0 +1,43 @@
package org.sadtech.social.core.domain.content;
import lombok.Data;
import org.sadtech.social.core.utils.Description;
import java.time.LocalDateTime;
/**
* Аьстрактная сущность - Сообщение от пользователя.
*
* @author upagge [08/07/2019]
*/
@Data
public abstract class Message {
@Description("Идентификатор сообщения")
private Integer id;
@Description("Тип сообщения")
protected ContentType type;
@Description("Дата создания")
private LocalDateTime createDate;
@Description("Идентификатор пользователя, отправившего сообщение")
private Integer personId;
@Description("Текстовое сообщение")
private String text;
public Message() {
}
public Message(Message source) {
this.personId = source.getPersonId();
this.text = source.getText();
this.createDate = source.getCreateDate();
this.id = source.getPersonId();
this.type = source.getType();
}
}

View File

@ -0,0 +1,21 @@
package org.sadtech.social.core.domain.content.attachment;
import lombok.EqualsAndHashCode;
import org.sadtech.social.core.utils.Description;
/**
* Абстрактная сущность, для всех вложений к сообщениям от пользователей.
*
* @author upagge [08/07/2019]
*/
@EqualsAndHashCode
public abstract class Attachment {
@Description("Тип сущности")
protected AttachmentType type;
public AttachmentType getType() {
return type;
}
}

View File

@ -0,0 +1,13 @@
package org.sadtech.social.core.domain.content.attachment;
/**
* Тип вложения {@link Attachment} к сообщению.
*
* @author upagge [08/07/2019]
*/
public enum AttachmentType {
AUDIO_MESSAGE,
GEO
}

View File

@ -0,0 +1,29 @@
package org.sadtech.social.core.domain.content.attachment;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.sadtech.social.core.utils.Description;
import java.net.URL;
/**
* Вложение типа "Аудиосообщение".
*
* @author upagge [08/07/2019]
*/
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString
@Setter
public class AudioMessage extends Attachment {
@Description("Ссылка на аудиозапись в формате odd")
private URL linkOdd;
public AudioMessage() {
type = AttachmentType.AUDIO_MESSAGE;
}
}

View File

@ -0,0 +1,60 @@
package org.sadtech.social.core.domain.content.attachment;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.sadtech.social.core.utils.Description;
/**
* Вложение типа "Карта".
*
* @author upagge [08/07/2019]
*/
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString
public class Geo extends Attachment {
@Description("Географические координаты")
private GeoCoordinate geoCoordinate;
@Description("Название страны")
private String country;
@Description("Название города")
private String city;
private Geo() {
type = AttachmentType.GEO;
}
public static Builder builder() {
return new Geo().new Builder();
}
public class Builder {
private Builder() {
}
public Builder coordinate(Float lat, Float aLong) {
Geo.this.geoCoordinate = new GeoCoordinate(lat, aLong);
return this;
}
public Builder country(String countryName) {
Geo.this.country = countryName;
return this;
}
public Builder city(String cityName) {
Geo.this.city = cityName;
return this;
}
public Geo build() {
return Geo.this;
}
}
}

View File

@ -0,0 +1,21 @@
package org.sadtech.social.core.domain.content.attachment;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.sadtech.social.core.utils.Description;
/**
* Сущность для хранения географических координат.
*
* @author upagge [08/07/2019]
*/
@Data
@AllArgsConstructor
public class GeoCoordinate {
@Description("Широта")
private Float latitude;
@Description("Долгота")
private Float longitude;
}

View File

@ -0,0 +1,15 @@
package org.sadtech.social.core.domain.keyboard;
/**
* Цвета кнопок на клавиатуре {@link KeyBoard}.
*
* @author upagge [08/07/2019]
*/
public enum ButtonColor {
PRIMARY,
DEFAULT,
NEGATIVE,
POSITIVE
}

View File

@ -0,0 +1,13 @@
package org.sadtech.social.core.domain.keyboard;
/**
* Тип кнопки на клавиатуре {@link KeyBoard}.
*
* @author upagge [08/07/2019]
*/
public enum ButtonType {
TEXT,
ACCOUNT
}

View File

@ -0,0 +1,31 @@
package org.sadtech.social.core.domain.keyboard;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Singular;
import lombok.ToString;
import org.sadtech.social.core.utils.Description;
import java.util.ArrayList;
import java.util.List;
/**
* Сущность клавиатуры, для создания меню с вариантами выбора.
*
* @author upagge [08/07/2019]
*/
@Builder
@Getter
@EqualsAndHashCode
@ToString
public class KeyBoard {
@Description("Строки меню")
@Singular(value = "lineKeyBoard")
private List<KeyBoardLine> keyBoardLines = new ArrayList<>();
@Description("Скрыть меню после ответа или нет")
private boolean oneTime = true;
}

View File

@ -0,0 +1,27 @@
package org.sadtech.social.core.domain.keyboard;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.sadtech.social.core.utils.Description;
/**
* Абстрактная сущность кнопки для клавиатуры.
*
* @author upagge [08/07/2019]
*/
@Getter
@EqualsAndHashCode
@ToString
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class KeyBoardButton {
@Description("Скрытое сообщение, отправляемое по нажатию")
protected String payload;
@Description("Тип кнопки")
protected ButtonType type;
}

View File

@ -0,0 +1,28 @@
package org.sadtech.social.core.domain.keyboard;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Singular;
import lombok.ToString;
import org.sadtech.social.core.utils.Description;
import java.util.ArrayList;
import java.util.List;
/**
* Строка в меню клавиатуры {@link KeyBoard}.
*
* @author upagge [08/07/2019]
*/
@Builder
@Getter
@EqualsAndHashCode
@ToString
public class KeyBoardLine {
@Description("Кнопки в строке")
@Singular(value = "buttonKeyBoard")
private List<KeyBoardButton> keyBoardButtons = new ArrayList<>();
}

View File

@ -0,0 +1,37 @@
package org.sadtech.social.core.domain.keyboard.button;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.sadtech.social.core.domain.keyboard.ButtonType;
import org.sadtech.social.core.domain.keyboard.KeyBoardButton;
import org.sadtech.social.core.utils.Description;
/**
* Кнопка клавиатуры для оплаты счета.
*
* @author upagge [08/07/2019]
*/
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString
public class KeyBoardButtonAccount extends KeyBoardButton {
@Description("Сумма к оплате")
private Integer amount;
@Description("Идентификатор счета")
private Integer accountId;
@Description("Описание")
private String description;
@Builder
private KeyBoardButtonAccount(String payload, Integer amount, Integer accountId, String description) {
super(payload, ButtonType.ACCOUNT);
this.amount = amount;
this.accountId = accountId;
this.description = description;
}
}

View File

@ -0,0 +1,29 @@
package org.sadtech.social.core.domain.keyboard.button;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.sadtech.social.core.domain.keyboard.ButtonColor;
import org.sadtech.social.core.domain.keyboard.ButtonType;
import org.sadtech.social.core.domain.keyboard.KeyBoardButton;
import org.sadtech.social.core.utils.Description;
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString
public class KeyBoardButtonText extends KeyBoardButton {
@Description("Надпись на кнопке")
private String label;
@Description("Цвет кнопки")
private ButtonColor color;
@Builder
private KeyBoardButtonText(String payload, String label, ButtonColor color) {
super(payload, ButtonType.TEXT);
this.label = label;
this.color = (color != null) ? color : ButtonColor.DEFAULT;
}
}

View File

@ -0,0 +1,44 @@
package org.sadtech.social.core.domain.money;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.sadtech.social.core.utils.Description;
/**
* Сущность, которая отвечает за выставленный пользователю счет.
*
* @author upagge [08/07/2019]
*/
@Builder
@Getter
@Setter
@EqualsAndHashCode
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Account {
@Description("Идентификатор счета")
private Integer id;
@Description("Сумма к оплате")
private Integer totalSum;
@Description("Идентификатор пользователя, которому выставлен счет")
private Integer belongsPersonId;
@Description("Идентификатор пользователя, который оплатил счет")
private Integer extinguishedPersonId;
@Description("Описание платежа")
private String description;
@Description("Статус оплаты счета")
private AccountStatus accountStatus;
}

View File

@ -0,0 +1,15 @@
package org.sadtech.social.core.domain.money;
/**
* Состояние счета.
*
* @author upagge [08/07/2019]
*/
public enum AccountStatus {
EXPOSED,
CLOSED,
CANCELLED,
EXCEPTION
}

View File

@ -1,5 +1,10 @@
package org.sadtech.bot.core.exception;
package org.sadtech.social.core.exception;
/**
* Ошибка доступа к чему-либо.
*
* @author upagge [08/07/2019]
*/
public class AccessException extends AppBotException {
public AccessException(Integer code, String message) {
super(code, message);

View File

@ -1,7 +1,12 @@
package org.sadtech.bot.core.exception;
package org.sadtech.social.core.exception;
import java.time.LocalDateTime;
/**
* Родитель всех исключений библиотеки.
*
* @author upagge [08/07/2019]
*/
public class AppBotException extends RuntimeException {
private static final String TYPE = "ERROR";

View File

@ -0,0 +1,12 @@
package org.sadtech.social.core.exception;
/**
* Исключения настройки бота.
*
* @author upagge [11/07/2019]
*/
public class ConfigAppException extends AppBotException {
public ConfigAppException(Integer code, String message) {
super(code, message);
}
}

View File

@ -1,5 +1,10 @@
package org.sadtech.bot.core.exception;
package org.sadtech.social.core.exception;
/**
* Ошибки при отправке сообщений.
*
* @author upagge [08/07/2019]
*/
public class MailSendException extends AppBotException {
public MailSendException() {

View File

@ -1,5 +1,10 @@
package org.sadtech.bot.core.exception;
package org.sadtech.social.core.exception;
/**
* Ошибка, когда что-то не найдено.
*
* @author upagge [08/07/2019]
*/
public class NotFoundException extends AppBotException {
public NotFoundException(Integer code, String message) {
super(code, message);

View File

@ -1,5 +1,10 @@
package org.sadtech.bot.core.exception;
package org.sadtech.social.core.exception;
/**
* Ошибка оплаты.
*
* @author upagge [08/07/2019]
*/
public class PaymentException extends AppBotException {
public PaymentException(Integer code, String message) {

View File

@ -0,0 +1,14 @@
package org.sadtech.social.core.exception;
/**
* Ошибка таймера.
*
* @author upagge [08/07/2019]
*/
public class TimerSettingException extends AppBotException {
public TimerSettingException(String message) {
super(54, message);
}
}

View File

@ -0,0 +1,18 @@
package org.sadtech.social.core.repository;
import org.sadtech.social.core.domain.money.Account;
/**
* Репозиторий для взаимодействия с хранилищем счетов {@link Account}.
*
* @author upagge [08/07/2019]
*/
public interface AccountRepository {
Integer add(Account account);
void edit(Integer accountId, Account account);
Account findById(Integer accountId);
}

View File

@ -0,0 +1,32 @@
package org.sadtech.social.core.repository;
import org.sadtech.social.core.domain.content.Message;
import java.time.LocalDateTime;
import java.util.List;
/**
* Интерфейс взаимодействия со всеми наследниками текстовых запросов пользователей.
*
* @author upagge [08/07/2019]
*/
public interface ContentRepository<T extends Message> {
/**
* Добавить сообщение в хранилище
*
* @param content Объект сообщени
* @return Идентификатор сообщения в хранилище
*/
Integer add(T content);
/**
* Получить все сообщения за определенный временной диапазон
*
* @param timeFrom Начало временного диапазона
* @param timeTo Конец диапазона
* @return Список сообщений
*/
List<T> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
}

View File

@ -0,0 +1,18 @@
package org.sadtech.social.core.repository;
import java.util.Queue;
/**
* Обработка событий социальной сети.
*
* @author upagge [08/07/2019]
*/
public interface EventRepository<T> {
void add(T dataObject);
void cleanAll();
Queue<T> getEventQueue();
}

View File

@ -1,10 +1,10 @@
package org.sadtech.bot.core.repository.impl;
package org.sadtech.social.core.repository.impl;
import org.sadtech.bot.core.domain.money.Account;
import org.sadtech.bot.core.exception.AccessException;
import org.sadtech.bot.core.exception.NotFoundException;
import org.sadtech.bot.core.exception.PaymentException;
import org.sadtech.bot.core.repository.AccountRepository;
import org.sadtech.social.core.domain.money.Account;
import org.sadtech.social.core.exception.AccessException;
import org.sadtech.social.core.exception.NotFoundException;
import org.sadtech.social.core.exception.PaymentException;
import org.sadtech.social.core.repository.AccountRepository;
import java.util.HashMap;
import java.util.Map;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.core.repository.impl;
package org.sadtech.social.core.repository.impl;
import org.sadtech.bot.core.domain.content.BoardComment;
import org.sadtech.bot.core.repository.ContentRepository;
import org.sadtech.social.core.domain.content.BoardComment;
import org.sadtech.social.core.repository.ContentRepository;
import java.time.LocalDateTime;
import java.util.ArrayList;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.core.repository.impl;
package org.sadtech.social.core.repository.impl;
import com.google.gson.JsonObject;
import org.sadtech.bot.core.repository.EventRepository;
import org.sadtech.social.core.repository.EventRepository;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.core.repository.impl;
package org.sadtech.social.core.repository.impl;
import org.sadtech.bot.core.domain.content.Mail;
import org.sadtech.bot.core.repository.ContentRepository;
import org.sadtech.social.core.domain.content.Mail;
import org.sadtech.social.core.repository.ContentRepository;
import java.time.LocalDateTime;
import java.util.ArrayList;

View File

@ -0,0 +1,32 @@
package org.sadtech.social.core.service;
import org.sadtech.social.core.domain.money.Account;
/**
* Интерфейс сервиса по работе с оплатой.
*
* @author upagge [08/07/2019]
*/
public interface AccountService {
Integer add(Account account);
/**
* Метод для оплаты счета
*
* @param accountId Идентификатор счета
* @param extinguishedPersonId Идентификатор пользователя, который внес оплату
* @param sum Сумма оплаты
* @return true - в случае успешной оплаты
*/
Boolean pay(Integer accountId, Integer extinguishedPersonId, Integer sum);
/**
* Проверка оплаты счета
*
* @param accountId Идентификатор счета
* @return true - если счет оплачен
*/
Boolean paymentVerification(Integer accountId);
}

View File

@ -0,0 +1,6 @@
package org.sadtech.social.core.service;
import org.sadtech.social.core.domain.content.BoardComment;
public interface BoardCommentService extends MessageService<BoardComment> {
}

View File

@ -0,0 +1,16 @@
package org.sadtech.social.core.service;
import org.sadtech.social.core.domain.content.Message;
/**
* Интерфес для изменения запроса пользователя перед тем, как он попадет в подсистему обработки.
* Например можно исправить опечатки, перевести сообщение на другой язык и так далее.
*
* @author upagge [08/07/2019]
*/
@FunctionalInterface
public interface Filter<T extends Message> {
void processing(T content);
}

View File

@ -0,0 +1,12 @@
package org.sadtech.social.core.service;
import org.sadtech.social.core.domain.content.Mail;
/**
* Интерфейс для взаимодействия с личными сообщениями.
*
* @author upagge [08/07/2019]
*/
public interface MailService extends MessageService<Mail> {
}

View File

@ -0,0 +1,33 @@
package org.sadtech.social.core.service;
import org.sadtech.social.core.domain.content.Message;
import java.time.LocalDateTime;
import java.util.List;
/**
* Интерфейс взаимодйствия с наследниками текстовых запросов пользователей.
*
* @author upagge [08/07/2019]
*/
public interface MessageService<T extends Message> {
void add(T event);
/**
* Получить список сообщений за заданный временной интервал
* @param timeFrom Начало интервала
* @param timeTo Конец интервала
* @return Список сообщений
*/
List<T> getByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
/**
* Получить список ПОСЛЕДНИХ сообщений для каждого пользователя за заданных временной интервал
* @param timeFrom Начало интервала
* @param timeTo Конец интервала
* @return Список сообщений
*/
List<T> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
}

View File

@ -1,9 +1,14 @@
package org.sadtech.bot.core.service;
package org.sadtech.social.core.service;
import com.google.gson.JsonObject;
import java.util.Queue;
/**
* Интерфейс для взаимодействия с событиями социальной сети.
*
* @author upagge [08/07/2019]
*/
public interface RawEventService {
void cleanAll();

View File

@ -1,10 +1,10 @@
package org.sadtech.bot.core.service.impl;
package org.sadtech.social.core.service.impl;
import org.sadtech.bot.core.domain.money.Account;
import org.sadtech.bot.core.domain.money.AccountStatus;
import org.sadtech.bot.core.exception.PaymentException;
import org.sadtech.bot.core.repository.AccountRepository;
import org.sadtech.bot.core.service.AccountService;
import org.sadtech.social.core.domain.money.Account;
import org.sadtech.social.core.domain.money.AccountStatus;
import org.sadtech.social.core.exception.PaymentException;
import org.sadtech.social.core.repository.AccountRepository;
import org.sadtech.social.core.service.AccountService;
public class AccountServiceImpl implements AccountService {

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.core.service.impl;
package org.sadtech.social.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.sadtech.social.core.domain.content.BoardComment;
import org.sadtech.social.core.repository.ContentRepository;
import org.sadtech.social.core.service.BoardCommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.core.service.impl;
package org.sadtech.social.core.service.impl;
import org.sadtech.bot.core.domain.content.Mail;
import org.sadtech.bot.core.repository.ContentRepository;
import org.sadtech.bot.core.service.MailService;
import org.sadtech.social.core.domain.content.Mail;
import org.sadtech.social.core.repository.ContentRepository;
import org.sadtech.social.core.service.MailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.core.service.impl;
package org.sadtech.social.core.service.impl;
import com.google.gson.JsonObject;
import org.sadtech.bot.core.repository.EventRepository;
import org.sadtech.bot.core.service.RawEventService;
import org.sadtech.social.core.repository.EventRepository;
import org.sadtech.social.core.service.RawEventService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,13 +1,13 @@
package org.sadtech.bot.core.service.sender;
package org.sadtech.social.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;
import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Comment;
import org.sadtech.social.core.domain.content.Message;
public class SendBox {
private SendBox() {
throw new IllegalStateException("Утилитный класс");
}
public static void sent(Message message, BoxAnswer boxAnswer, Sent sent) {

View File

@ -0,0 +1,22 @@
package org.sadtech.social.core.service.sender;
import org.sadtech.social.core.domain.BoxAnswer;
/**
* Интерфейс для отправки ответов пользователю.
*
* @author upagge [08/07/2019]
*/
public interface Sent {
/**
* Отрпавляет ответ пользователю
*
* @param personId Идентификатор пользователя
* @param boxAnswer Объект с данными, которые необходимо отправить
*/
void send(Integer personId, BoxAnswer boxAnswer);
void send(Integer contentId, Integer personId, BoxAnswer boxAnswer);
}

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.core.service.sender.email;
package org.sadtech.social.core.service.sender.email;
import java.util.Properties;

View File

@ -1,12 +1,17 @@
package org.sadtech.bot.core.service.sender.email;
package org.sadtech.social.core.service.sender.email;
import org.sadtech.bot.core.domain.BoxAnswer;
import org.sadtech.bot.core.exception.MailSendException;
import org.sadtech.bot.core.service.sender.Sent;
import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.exception.MailSendException;
import org.sadtech.social.core.service.sender.Sent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.mail.*;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

View File

@ -0,0 +1,21 @@
package org.sadtech.social.core.utils;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Используется для описания полей в классах.
*
* @author upagge [08/07/2019]
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface Description {
String value();
String example() default "";
}

View File

@ -1,15 +1,27 @@
package org.sadtech.bot.core.utils;
package org.sadtech.social.core.utils;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Класс для вставки слов в текстовую строку вместо подстрок - шаблонов маркеров.
*
* @author upagge [08/07/2019]
*/
public class InsertWords {
private InsertWords() {
throw new IllegalStateException();
throw new IllegalStateException("Утилитный класс");
}
/**
* Заменяет шаблон {n} в строке на слово из списка, где n - это порядковое число.
*
* @param text Текстовая строка
* @param words Список слов, которые необходимо поместить вместо шаблона
* @return Модифицированная строка
*/
public static String insert(String text, List<String> words) {
Pattern pattern = Pattern.compile("\\{(\\d+)}");
Matcher m = pattern.matcher(text);

View File

@ -1,19 +1,29 @@
package org.sadtech.bot.core.utils;
package org.sadtech.social.core.utils;
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 org.sadtech.social.core.domain.keyboard.ButtonColor;
import org.sadtech.social.core.domain.keyboard.KeyBoard;
import org.sadtech.social.core.domain.keyboard.KeyBoardButton;
import org.sadtech.social.core.domain.keyboard.KeyBoardLine;
import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonText;
import java.util.List;
/**
* Используется для быстрого создания клавиаутр {@link KeyBoard}.
*
* @author upagge [08/07/2019]
*/
public class KeyBoards {
private KeyBoards() {
throw new IllegalStateException();
}
/**
* Возвращает клавиатуру формата 1х2, с кнопками "Да | Нет"
*
* @return {@link KeyBoard}
*/
public static KeyBoard keyBoardYesNo() {
KeyBoardButton yesButton = KeyBoardButtonText.builder().color(ButtonColor.POSITIVE).label("Да").payload("{\"button\": \"yes\"}").build();
KeyBoardButton noButton = KeyBoardButtonText.builder().color(ButtonColor.NEGATIVE).label("Нет").payload("{\"button\": \"no\"}").build();
@ -21,8 +31,14 @@ public class KeyBoards {
return KeyBoard.builder().lineKeyBoard(keyBoardLine).oneTime(true).build();
}
/**
* Возвращает клавиатуру формата 1хN, где N - это количество элементов в переданном списке
*
* @param labelButtons Список названий для кнопок
* @return {@link KeyBoard}
*/
public static KeyBoard verticalMenuString(List<String> labelButtons) {
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true);
for (String labelButton : labelButtons) {
KeyBoardButton keyBoardButton = KeyBoardButtonText.builder().label(labelButton).payload("{\"button\": \"" + labelButton + "\"}").build();
keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build());
@ -30,8 +46,14 @@ public class KeyBoards {
return keyBoard.build();
}
/**
* Возвращает клавиатуру формата 1хN, где N - это количество элементов в переданном списке
*
* @param labelButton Список названий для кнопок
* @return {@link KeyBoard}
*/
public static KeyBoard verticalMenuString(String... labelButton) {
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
KeyBoard.KeyBoardBuilder 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());
@ -39,10 +61,16 @@ public class KeyBoards {
return keyBoard.build();
}
/**
* Возвращает клавиатуру формата 2х(N/2), где N - это количество элементов в переданном списке
*
* @param labelButton Список названий для кнопок
* @return {@link KeyBoard}
*/
public static KeyBoard verticalDuoMenuString(String... labelButton) {
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true);
boolean flag = true;
KeyBoardLine.Builder keyBoardLine = KeyBoardLine.builder();
KeyBoardLine.KeyBoardLineBuilder keyBoardLine = KeyBoardLine.builder();
for (String label : labelButton) {
if (flag) {
keyBoardLine.buttonKeyBoard(KeyBoardButtonText.builder().label(label).build());
@ -57,14 +85,26 @@ public class KeyBoards {
return keyBoard.build();
}
/**
* Возвращает клавиатуру формата 1xN сформированную из списка кнопок, где N - количество кнопок в списке
*
* @param keyBoardButtons Список кнопок
* @return {@link KeyBoard}
*/
public static KeyBoard verticalMenuButton(List<KeyBoardButton> keyBoardButtons) {
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true);
for (KeyBoardButton keyBoardButton : keyBoardButtons) {
keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build());
}
return keyBoard.build();
}
/**
* Возвращает клавиатуру из одной кнопки
*
* @param keyBoardButton Кнопка
* @return {@link KeyBoard}
*/
public static KeyBoard singelton(KeyBoardButton keyBoardButton) {
KeyBoardLine line = KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build();
return KeyBoard.builder().lineKeyBoard(line).build();

View File

@ -0,0 +1,20 @@
package org.sadtech.social.core.utils;
import org.sadtech.social.core.domain.content.EmptyMessage;
import org.sadtech.social.core.domain.content.Message;
/**
* Класс для хранения объекта заглушки для {@link Message}.
*
* @author upagge [08/07/2019]
*/
public class MessageUtils {
private MessageUtils() {
throw new IllegalStateException("Утилитный класс");
}
public static final EmptyMessage EMPTY_MESSAGE = new EmptyMessage();
}