Merge branch 'release/release-0.6.1'
This commit is contained in:
commit
154ce19a79
38
pom.xml
38
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.sadtech.bot</groupId>
|
||||
<artifactId>bot-core</artifactId>
|
||||
<version>0.6.0-RELEASE</version>
|
||||
<version>0.6.1-RELEASE</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
@ -22,19 +22,11 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>uPagge</id>
|
||||
<name>Struchkov Mark</name>
|
||||
<email>upagge@mail.ru</email>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<gson.ver>2.8.5</gson.ver>
|
||||
<vksdk.ver>0.5.13-SNAPSHOT</vksdk.ver>
|
||||
<slf4j.ver>1.7.26</slf4j.ver>
|
||||
<mail.ver>1.4</mail.ver>
|
||||
<junit.ver>4.12</junit.ver>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -55,28 +47,20 @@
|
||||
<version>${mail.ver}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<version>${junit.ver}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>uPagge</id>
|
||||
<name>Struchkov Mark</name>
|
||||
<email>upagge@mail.ru</email>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
|
||||
</project>
|
@ -1,5 +1,6 @@
|
||||
package org.sadtech.bot.core.domain;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.attachment.GeoCoordinate;
|
||||
import org.sadtech.bot.core.domain.keyboard.KeyBoard;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -8,11 +9,10 @@ public class BoxAnswer {
|
||||
|
||||
private String message;
|
||||
private KeyBoard keyboard;
|
||||
private Float lat;
|
||||
private Float aLong;
|
||||
private GeoCoordinate coordinates;
|
||||
private Integer stickerId;
|
||||
|
||||
public BoxAnswer() {
|
||||
private BoxAnswer() {
|
||||
|
||||
}
|
||||
|
||||
@ -20,8 +20,7 @@ public class BoxAnswer {
|
||||
if (target != null) {
|
||||
this.message = target.getMessage();
|
||||
this.keyboard = target.getKeyboard();
|
||||
this.lat = target.getLat();
|
||||
this.aLong = target.getaLong();
|
||||
this.coordinates = target.getCoordinates();
|
||||
this.stickerId = target.getStickerId();
|
||||
}
|
||||
}
|
||||
@ -43,20 +42,8 @@ public class BoxAnswer {
|
||||
this.keyboard = keyboard;
|
||||
}
|
||||
|
||||
public Float getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat(Float lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public Float getaLong() {
|
||||
return aLong;
|
||||
}
|
||||
|
||||
public void setaLong(Float aLong) {
|
||||
this.aLong = aLong;
|
||||
public GeoCoordinate getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
public Integer getStickerId() {
|
||||
@ -90,13 +77,8 @@ public class BoxAnswer {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lat(Float lat) {
|
||||
BoxAnswer.this.lat = lat;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder aLong(Float aLong) {
|
||||
BoxAnswer.this.aLong = aLong;
|
||||
public Builder coordinate(Float lat, Float aLong) {
|
||||
BoxAnswer.this.coordinates = new GeoCoordinate(lat, aLong);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -113,19 +95,26 @@ public class BoxAnswer {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!(o instanceof BoxAnswer)) return false;
|
||||
BoxAnswer boxAnswer = (BoxAnswer) o;
|
||||
return Objects.equals(message, boxAnswer.message) &&
|
||||
Objects.equals(keyboard, boxAnswer.keyboard) &&
|
||||
Objects.equals(lat, boxAnswer.lat) &&
|
||||
Objects.equals(aLong, boxAnswer.aLong) &&
|
||||
Objects.equals(coordinates, boxAnswer.coordinates) &&
|
||||
Objects.equals(stickerId, boxAnswer.stickerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(message, keyboard, lat, aLong, stickerId);
|
||||
return Objects.hash(message, keyboard, coordinates, stickerId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BoxAnswer{" +
|
||||
"message='" + message + '\'' +
|
||||
", keyboard=" + keyboard +
|
||||
", coordinates=" + coordinates +
|
||||
", stickerId=" + stickerId +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -1,91 +0,0 @@
|
||||
package org.sadtech.bot.core.domain;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Person {
|
||||
|
||||
private Integer id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private Integer sex;
|
||||
private String city;
|
||||
private String email;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Integer getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(Integer sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Person)) return false;
|
||||
Person person = (Person) o;
|
||||
return Objects.equals(id, person.id) &&
|
||||
Objects.equals(firstName, person.firstName) &&
|
||||
Objects.equals(lastName, person.lastName) &&
|
||||
Objects.equals(sex, person.sex) &&
|
||||
Objects.equals(city, person.city) &&
|
||||
Objects.equals(email, person.email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, firstName, lastName, sex, city, email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"id=" + id +
|
||||
", firstName='" + firstName + '\'' +
|
||||
", lastName='" + lastName + '\'' +
|
||||
", sex=" + sex +
|
||||
", city='" + city + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package org.sadtech.bot.core.domain.attachment;
|
||||
|
||||
public enum AttachmentType {
|
||||
AUDIO_MESSAGE
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.domain;
|
||||
package org.sadtech.bot.core.domain.content;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -0,0 +1,16 @@
|
||||
package org.sadtech.bot.core.domain.content;
|
||||
|
||||
import org.sadtech.bot.core.exception.AppBotException;
|
||||
|
||||
public class EmptyContent extends Content {
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMessage(String message) {
|
||||
throw new AppBotException(0, "EmptyContent no setMessage");
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package org.sadtech.bot.core.domain;
|
||||
package org.sadtech.bot.core.domain.content;
|
||||
|
||||
import org.sadtech.bot.core.domain.attachment.Attachment;
|
||||
import org.sadtech.bot.core.domain.content.attachment.Attachment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
@ -1,10 +1,11 @@
|
||||
package org.sadtech.bot.core.domain.attachment;
|
||||
package org.sadtech.bot.core.domain.content.attachment;
|
||||
|
||||
public abstract class Attachment {
|
||||
|
||||
AttachmentType type;
|
||||
protected AttachmentType type;
|
||||
|
||||
public AttachmentType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.sadtech.bot.core.domain.content.attachment;
|
||||
|
||||
public enum AttachmentType {
|
||||
|
||||
AUDIO_MESSAGE, GEO
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.domain.attachment;
|
||||
package org.sadtech.bot.core.domain.content.attachment;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
@ -0,0 +1,79 @@
|
||||
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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package org.sadtech.bot.core.domain.keyboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class KeyBoard {
|
||||
|
||||
@ -45,4 +46,26 @@ public class KeyBoard {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.sadtech.bot.core.domain.keyboard;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class KeyBoardButton {
|
||||
@ -10,7 +8,7 @@ public class KeyBoardButton {
|
||||
private String label;
|
||||
private ButtonColor color = ButtonColor.DEFAULT;
|
||||
|
||||
public KeyBoardButton() {
|
||||
private KeyBoardButton() {
|
||||
|
||||
}
|
||||
|
||||
@ -26,13 +24,6 @@ public class KeyBoardButton {
|
||||
return color;
|
||||
}
|
||||
|
||||
private JsonObject generateAction() {
|
||||
JsonObject action = new JsonObject();
|
||||
action.addProperty("payload", payload);
|
||||
action.addProperty("label", label);
|
||||
return action;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new KeyBoardButton().new Builder();
|
||||
}
|
||||
@ -68,14 +59,23 @@ public class KeyBoardButton {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof KeyBoardButton)) return false;
|
||||
KeyBoardButton that = (KeyBoardButton) o;
|
||||
return Objects.equals(payload, that.payload) &&
|
||||
Objects.equals(label, that.label) &&
|
||||
color == that.color;
|
||||
KeyBoardButton button = (KeyBoardButton) o;
|
||||
return Objects.equals(payload, button.payload) &&
|
||||
Objects.equals(label, button.label) &&
|
||||
color == button.color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(payload, label, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KeyBoardButton{" +
|
||||
"payload='" + payload + '\'' +
|
||||
", label='" + label + '\'' +
|
||||
", color=" + color +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,16 @@ 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<>();
|
||||
|
||||
public KeyBoardLine() {
|
||||
private KeyBoardLine() {
|
||||
|
||||
}
|
||||
|
||||
public KeyBoardLine(List<KeyBoardButton> keyBoardButtons) {
|
||||
this.keyBoardButtons = keyBoardButtons;
|
||||
}
|
||||
|
||||
public List<KeyBoardButton> getKeyBoardButtons() {
|
||||
return keyBoardButtons;
|
||||
}
|
||||
@ -29,7 +26,7 @@ public class KeyBoardLine {
|
||||
|
||||
}
|
||||
|
||||
public Builder setButtonKeyBoard(KeyBoardButton keyBoardButton) {
|
||||
public Builder buttonKeyBoard(KeyBoardButton keyBoardButton) {
|
||||
KeyBoardLine.this.keyBoardButtons.add(keyBoardButton);
|
||||
return this;
|
||||
}
|
||||
@ -38,4 +35,24 @@ public class KeyBoardLine {
|
||||
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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
91
src/main/java/org/sadtech/bot/core/domain/money/Account.java
Normal file
91
src/main/java/org/sadtech/bot/core/domain/money/Account.java
Normal file
@ -0,0 +1,91 @@
|
||||
package org.sadtech.bot.core.domain.money;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Account {
|
||||
|
||||
private Integer id;
|
||||
private Double 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 Double getTotalSum() {
|
||||
return totalSum;
|
||||
}
|
||||
|
||||
public void setTotalSum(Double 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 +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.sadtech.bot.core.domain.money;
|
||||
|
||||
public enum AccountStatus {
|
||||
|
||||
EXPOSED, CLOSED, CANCELLED, EXCEPTION
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.sadtech.bot.core.exception;
|
||||
|
||||
public class AccessException extends AppBotException {
|
||||
public AccessException(Integer code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.sadtech.bot.core.exception;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class AppBotException extends RuntimeException {
|
||||
|
||||
private static final String TYPE = "ERROR";
|
||||
private final LocalDateTime timeError = LocalDateTime.now();
|
||||
protected final Integer code;
|
||||
protected final String description;
|
||||
|
||||
public AppBotException(Integer code, String message) {
|
||||
this.description = message;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public LocalDateTime getTimeError() {
|
||||
return timeError;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
package org.sadtech.bot.core.exception;
|
||||
|
||||
public class MailSendException extends RuntimeException {
|
||||
public class MailSendException extends AppBotException {
|
||||
|
||||
public MailSendException() {
|
||||
super(1, "Ошибка отправки сообщения");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package org.sadtech.bot.core.exception;
|
||||
|
||||
public class NotFoundException extends AppBotException {
|
||||
public NotFoundException(Integer code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package org.sadtech.bot.core.exception;
|
||||
|
||||
public class PaymentException extends AppBotException {
|
||||
|
||||
public PaymentException(Integer code, String message) {
|
||||
super(code, message);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package org.sadtech.bot.core.filter;
|
||||
|
||||
import org.sadtech.bot.core.domain.Content;
|
||||
|
||||
public interface Filter<T extends Content> {
|
||||
|
||||
void doFilter(T content);
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
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);
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package org.sadtech.bot.core.repository;
|
||||
|
||||
import org.sadtech.bot.core.domain.Mail;
|
||||
import org.sadtech.bot.core.domain.content.Mail;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
@ -1,11 +0,0 @@
|
||||
package org.sadtech.bot.core.repository;
|
||||
|
||||
import org.sadtech.bot.core.domain.Person;
|
||||
|
||||
public interface PersonRepository {
|
||||
|
||||
void add(Person person);
|
||||
|
||||
Person get(Integer id);
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package org.sadtech.bot.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 java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class AccountRepositoryMap implements AccountRepository {
|
||||
|
||||
private final Map<Integer, Account> saveMap = new HashMap<>();
|
||||
private Integer id = 1;
|
||||
|
||||
@Override
|
||||
public Integer add(Account account) {
|
||||
if (check(account.getId())) {
|
||||
account.setId(id);
|
||||
saveMap.put(id, account);
|
||||
return id++;
|
||||
} else {
|
||||
throw new AccessException(312, "Счет " + account.getId() + " уже существует");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(Integer accountId, Account account) {
|
||||
if (check(id)) {
|
||||
account.setId(accountId);
|
||||
saveMap.put(accountId, account);
|
||||
} else {
|
||||
throw new NotFoundException(491, "Счет " + accountId + " не найден");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account findById(Integer accountId) {
|
||||
return Optional.ofNullable(saveMap.get(accountId)).orElseThrow(() -> new PaymentException(43, "Счет " + accountId + " не найден"));
|
||||
}
|
||||
|
||||
private boolean check(Integer id) {
|
||||
return saveMap.containsKey(id);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package org.sadtech.bot.core.repository.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.Mail;
|
||||
import org.sadtech.bot.core.domain.content.Mail;
|
||||
import org.sadtech.bot.core.repository.EventRepository;
|
||||
import org.sadtech.bot.core.repository.MailRepository;
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
package org.sadtech.bot.core.repository.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.Person;
|
||||
import org.sadtech.bot.core.repository.EventRepository;
|
||||
import org.sadtech.bot.core.repository.PersonRepository;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class PersonRepositoryMap implements EventRepository<Person>, PersonRepository {
|
||||
|
||||
private final Map<Integer, Person> personMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void add(Person person) {
|
||||
personMap.put(person.getId(), person);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanAll() {
|
||||
personMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<Person> getEventQueue() {
|
||||
return new ConcurrentLinkedQueue<>(personMap.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Person get(Integer id) {
|
||||
return personMap.get(id);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.sadtech.bot.core.repository.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.Mail;
|
||||
import org.sadtech.bot.core.repository.EventRepository;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class TerminalComandRepositoryQueue implements EventRepository<Mail> {
|
||||
|
||||
private final Queue<Mail> mailQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
@Override
|
||||
public void add(Mail dataObject) {
|
||||
mailQueue.offer(dataObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanAll() {
|
||||
mailQueue.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<Mail> getEventQueue() {
|
||||
return mailQueue;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
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, Double sum);
|
||||
|
||||
Boolean paymentVerification(Integer accountId);
|
||||
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Content;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface EventService<T> {
|
||||
public interface EventService<T extends Content> {
|
||||
|
||||
void add(T event);
|
||||
|
||||
|
10
src/main/java/org/sadtech/bot/core/service/Filter.java
Normal file
10
src/main/java/org/sadtech/bot/core/service/Filter.java
Normal file
@ -0,0 +1,10 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Content;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Filter<T extends Content> {
|
||||
|
||||
void processing(T content);
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.Mail;
|
||||
import org.sadtech.bot.core.domain.content.Mail;
|
||||
|
||||
public interface MailService extends EventService<Mail> {
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.Person;
|
||||
|
||||
public interface PersonService {
|
||||
|
||||
void add(Person person);
|
||||
|
||||
Person get(Integer id);
|
||||
|
||||
boolean checkPerson(Integer idPerson);
|
||||
|
||||
Person createPerson(Integer userId);
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.sadtech.bot.core.repository.EventRepository;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
@ -13,6 +12,4 @@ public interface RawEventService {
|
||||
|
||||
Queue<JsonObject> getJsonObjects();
|
||||
|
||||
EventRepository getEventRepository();
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package org.sadtech.bot.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;
|
||||
|
||||
public class AccountServiceImpl implements AccountService {
|
||||
|
||||
private final AccountRepository accountRepository;
|
||||
|
||||
public AccountServiceImpl(AccountRepository accountRepository) {
|
||||
this.accountRepository = accountRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer add(Account account) {
|
||||
account.setAccountStatus(AccountStatus.EXPOSED);
|
||||
return accountRepository.add(account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum) {
|
||||
Account account = accountRepository.findById(accountId);
|
||||
if (validStatus(account.getAccountStatus())) {
|
||||
if (account.getTotalSum().equals(sum)) {
|
||||
account.setAccountStatus(AccountStatus.CLOSED);
|
||||
account.setExtinguishedPersonId(extinguishedPersonId);
|
||||
accountRepository.edit(accountId, account);
|
||||
} else {
|
||||
account.setAccountStatus(AccountStatus.EXCEPTION);
|
||||
accountRepository.edit(accountId, account);
|
||||
throw new PaymentException(2, "Неверная сумма");
|
||||
}
|
||||
} else {
|
||||
throw new PaymentException(3, "Счет уже оплачен");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean validStatus(AccountStatus accountStatus) {
|
||||
return AccountStatus.EXCEPTION.equals(accountStatus) || AccountStatus.EXPOSED.equals(accountStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean paymentVerification(Integer accountId) {
|
||||
return AccountStatus.CLOSED.equals(accountRepository.findById(accountId).getAccountStatus());
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package org.sadtech.bot.core.service.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.Mail;
|
||||
import org.sadtech.bot.core.domain.content.Mail;
|
||||
import org.sadtech.bot.core.repository.MailRepository;
|
||||
import org.sadtech.bot.core.repository.impl.MailRepositoryList;
|
||||
import org.sadtech.bot.core.service.MailService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -19,10 +18,6 @@ public class MailServiceImpl implements MailService {
|
||||
|
||||
private final MailRepository mailRepository;
|
||||
|
||||
public MailServiceImpl() {
|
||||
this.mailRepository = new MailRepositoryList();
|
||||
}
|
||||
|
||||
public MailServiceImpl(MailRepository mailRepository) {
|
||||
this.mailRepository = mailRepository;
|
||||
}
|
||||
@ -30,13 +25,12 @@ public class MailServiceImpl implements MailService {
|
||||
@Override
|
||||
public void add(Mail mail) {
|
||||
mailRepository.add(mail);
|
||||
log.info("Сообщение добавлено в репозиторий");
|
||||
log.info(mail.toString());
|
||||
log.info("Сообщение добавлено в репозиторий | {}", mail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mail> getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
log.info("Запрошены сообщения " + timeFrom + " - " + timeTo);
|
||||
log.info("Запрошены сообщения {} - {} ", timeFrom, timeTo);
|
||||
List<Mail> mails = mailRepository.getMailByTime(timeFrom, timeTo);
|
||||
Set<Integer> people = new HashSet<>();
|
||||
List<Mail> returnMails = new ArrayList<>();
|
||||
@ -65,7 +59,7 @@ public class MailServiceImpl implements MailService {
|
||||
|
||||
@Override
|
||||
public List<Mail> getEvent(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
log.info("Запрос на получение сообщений в интервале от " + timeFrom + " до " + timeTo);
|
||||
log.info("Запрошены сообщения {} - {} ", timeFrom, timeTo);
|
||||
return mailRepository.getMailByTime(timeFrom, timeTo);
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,9 @@ public class RawEventServiceImpl implements RawEventService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RawEventServiceImpl.class);
|
||||
|
||||
private final EventRepository eventRepository;
|
||||
private final EventRepository<JsonObject> eventRepository;
|
||||
|
||||
public RawEventServiceImpl(EventRepository eventRepository) {
|
||||
public RawEventServiceImpl(EventRepository<JsonObject> eventRepository) {
|
||||
this.eventRepository = eventRepository;
|
||||
}
|
||||
|
||||
@ -35,9 +35,4 @@ public class RawEventServiceImpl implements RawEventService {
|
||||
return eventRepository.getEventQueue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventRepository getEventRepository() {
|
||||
return eventRepository;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.sender;
|
||||
package org.sadtech.bot.core.service.sender;
|
||||
|
||||
import org.sadtech.bot.core.domain.BoxAnswer;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.sender.email;
|
||||
package org.sadtech.bot.core.service.sender.email;
|
||||
|
||||
import java.util.Properties;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package org.sadtech.bot.core.sender.email;
|
||||
package org.sadtech.bot.core.service.sender.email;
|
||||
|
||||
import org.sadtech.bot.core.domain.BoxAnswer;
|
||||
import org.sadtech.bot.core.exception.MailSendException;
|
||||
import org.sadtech.bot.core.sender.Sent;
|
||||
import org.sadtech.bot.core.service.sender.Sent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -23,6 +23,7 @@ public class EmailSent implements Sent {
|
||||
@Override
|
||||
public void send(Integer personId, String htmlText) {
|
||||
Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(emailConfig.getUsername(), emailConfig.getPassword());
|
||||
}
|
||||
@ -42,6 +43,6 @@ public class EmailSent implements Sent {
|
||||
|
||||
@Override
|
||||
public void send(Integer personId, BoxAnswer boxAnswer) {
|
||||
|
||||
throw new MailSendException();
|
||||
}
|
||||
}
|
14
src/main/java/org/sadtech/bot/core/utils/Contents.java
Normal file
14
src/main/java/org/sadtech/bot/core/utils/Contents.java
Normal file
@ -0,0 +1,14 @@
|
||||
package org.sadtech.bot.core.utils;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.EmptyContent;
|
||||
|
||||
public class Contents {
|
||||
|
||||
private Contents() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static final EmptyContent EMPTY_CONTENT = new EmptyContent();
|
||||
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.insert;
|
||||
package org.sadtech.bot.core.utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
package org.sadtech.bot.core.utils;
|
||||
|
||||
import org.sadtech.bot.core.domain.keyboard.ButtonColor;
|
||||
import org.sadtech.bot.core.domain.keyboard.KeyBoard;
|
||||
@ -16,7 +16,7 @@ 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();
|
||||
KeyBoardLine keyBoardLine = KeyBoardLine.builder().setButtonKeyBoard(yesButton).setButtonKeyBoard(noButton).build();
|
||||
KeyBoardLine keyBoardLine = KeyBoardLine.builder().buttonKeyBoard(yesButton).buttonKeyBoard(noButton).build();
|
||||
return KeyBoard.builder().lineKeyBoard(keyBoardLine).oneTime(true).build();
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class KeyBoards {
|
||||
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
|
||||
for (String labelButton : labelButtons) {
|
||||
KeyBoardButton keyBoardButton = KeyBoardButton.builder().label(labelButton).payload("{\"button\": \"" + labelButton + "\"}").build();
|
||||
keyBoard.lineKeyBoard(KeyBoardLine.builder().setButtonKeyBoard(keyBoardButton).build());
|
||||
keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build());
|
||||
}
|
||||
return keyBoard.build();
|
||||
}
|
||||
@ -32,7 +32,7 @@ public class KeyBoards {
|
||||
public static KeyBoard verticalMenuButton(List<KeyBoardButton> keyBoardButtons) {
|
||||
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
|
||||
for (KeyBoardButton keyBoardButton : keyBoardButtons) {
|
||||
keyBoard.lineKeyBoard(KeyBoardLine.builder().setButtonKeyBoard(keyBoardButton).build());
|
||||
keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build());
|
||||
}
|
||||
return keyBoard.build();
|
||||
}
|
Loading…
Reference in New Issue
Block a user