From dfc4f36e55ddf9c063cc83392556f25e077b0468 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 24 May 2019 15:47:05 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B5=20=D0=B2=D0=BB=D0=BE?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20-=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sadtech/bot/core/domain/BoxAnswer.java | 49 ++++------ .../sadtech/bot/core/domain/EmptyContent.java | 9 +- .../org/sadtech/bot/core/domain/Person.java | 91 ------------------- .../core/domain/attachment/Attachment.java | 1 + .../domain/attachment/AttachmentType.java | 4 +- .../bot/core/domain/attachment/Geo.java | 81 +++++++++++++++++ .../core/domain/{ => content}/Content.java | 4 +- .../core/domain/content/GeoCoordinate.java | 28 ++++++ .../bot/core/domain/{ => content}/Mail.java | 2 +- .../bot/core/domain/keyboard/KeyBoard.java | 23 +++++ .../core/domain/keyboard/KeyBoardButton.java | 28 +++--- .../core/domain/keyboard/KeyBoardLine.java | 27 +++++- .../bot/core/domain/money/Account.java | 15 ++- .../bot/core/exception/AppBotException.java | 15 +-- .../bot/core/exception/MailSendException.java | 5 +- .../bot/core/exception/PaymentException.java | 8 +- .../org/sadtech/bot/core/filter/Filter.java | 9 -- .../bot/core/repository/MailRepository.java | 2 +- .../bot/core/repository/PersonRepository.java | 11 --- ...oryImpl.java => AccountRepositoryMap.java} | 2 +- .../repository/impl/MailRepositoryList.java | 2 +- .../repository/impl/PersonRepositoryMap.java | 35 ------- .../sadtech/bot/core/service/MailService.java | 2 +- .../bot/core/service/PersonService.java | 15 --- .../bot/core/service/filter/Filter.java | 9 ++ .../core/service/impl/AccountServiceImpl.java | 2 +- .../core/service/impl/MailServiceImpl.java | 14 +-- .../core/service/sender/email/EmailSent.java | 3 +- .../org/sadtech/bot/core/utils/Contents.java | 14 +++ 29 files changed, 254 insertions(+), 256 deletions(-) delete mode 100644 src/main/java/org/sadtech/bot/core/domain/Person.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/attachment/Geo.java rename src/main/java/org/sadtech/bot/core/domain/{ => content}/Content.java (89%) create mode 100644 src/main/java/org/sadtech/bot/core/domain/content/GeoCoordinate.java rename src/main/java/org/sadtech/bot/core/domain/{ => content}/Mail.java (97%) delete mode 100644 src/main/java/org/sadtech/bot/core/filter/Filter.java delete mode 100644 src/main/java/org/sadtech/bot/core/repository/PersonRepository.java rename src/main/java/org/sadtech/bot/core/repository/impl/{AccountRepositoryImpl.java => AccountRepositoryMap.java} (91%) delete mode 100644 src/main/java/org/sadtech/bot/core/repository/impl/PersonRepositoryMap.java delete mode 100644 src/main/java/org/sadtech/bot/core/service/PersonService.java create mode 100644 src/main/java/org/sadtech/bot/core/service/filter/Filter.java create mode 100644 src/main/java/org/sadtech/bot/core/utils/Contents.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 f417e6e..b84a414 100644 --- a/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java +++ b/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java @@ -1,5 +1,6 @@ package org.sadtech.bot.core.domain; +import org.sadtech.bot.core.domain.content.GeoCoordinate; import org.sadtech.bot.core.domain.keyboard.KeyBoard; import java.util.Objects; @@ -8,8 +9,7 @@ public class BoxAnswer { private String message; private KeyBoard keyboard; - private Float lat; - private Float aLong; + private GeoCoordinate coordinates; private Integer stickerId; 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 + + '}'; + } } diff --git a/src/main/java/org/sadtech/bot/core/domain/EmptyContent.java b/src/main/java/org/sadtech/bot/core/domain/EmptyContent.java index a2ac004..328eb32 100644 --- a/src/main/java/org/sadtech/bot/core/domain/EmptyContent.java +++ b/src/main/java/org/sadtech/bot/core/domain/EmptyContent.java @@ -1,11 +1,10 @@ package org.sadtech.bot.core.domain; +import org.sadtech.bot.core.domain.content.Content; +import org.sadtech.bot.core.exception.AppBotException; + public class EmptyContent extends Content { - public EmptyContent() { - - } - @Override public String getMessage() { return ""; @@ -13,6 +12,6 @@ public class EmptyContent extends Content { @Override public void setMessage(String message) { - + throw new AppBotException(0, "EmptyContent no setMessage"); } } diff --git a/src/main/java/org/sadtech/bot/core/domain/Person.java b/src/main/java/org/sadtech/bot/core/domain/Person.java deleted file mode 100644 index 646d076..0000000 --- a/src/main/java/org/sadtech/bot/core/domain/Person.java +++ /dev/null @@ -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 + '\'' + - '}'; - } -} diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java b/src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java index 1c7de29..ecf3782 100644 --- a/src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java +++ b/src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java @@ -7,4 +7,5 @@ public abstract class Attachment { public AttachmentType getType() { return type; } + } diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java b/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java index afce805..2487c99 100644 --- a/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java +++ b/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java @@ -1,5 +1,7 @@ package org.sadtech.bot.core.domain.attachment; public enum AttachmentType { - AUDIO_MESSAGE + + AUDIO_MESSAGE, GEO + } diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/Geo.java b/src/main/java/org/sadtech/bot/core/domain/attachment/Geo.java new file mode 100644 index 0000000..e6bc1bb --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/attachment/Geo.java @@ -0,0 +1,81 @@ +package org.sadtech.bot.core.domain.attachment; + +import org.sadtech.bot.core.domain.content.GeoCoordinate; + +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 + '\'' + + '}'; + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/Content.java b/src/main/java/org/sadtech/bot/core/domain/content/Content.java similarity index 89% rename from src/main/java/org/sadtech/bot/core/domain/Content.java rename to src/main/java/org/sadtech/bot/core/domain/content/Content.java index f65aa19..5e0c5b3 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Content.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/Content.java @@ -1,11 +1,9 @@ -package org.sadtech.bot.core.domain; +package org.sadtech.bot.core.domain.content; import java.util.Objects; public abstract class Content { - public static final EmptyContent EMPTY_CONTENT = new EmptyContent(); - private Integer personId; private String message; diff --git a/src/main/java/org/sadtech/bot/core/domain/content/GeoCoordinate.java b/src/main/java/org/sadtech/bot/core/domain/content/GeoCoordinate.java new file mode 100644 index 0000000..09998c0 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/content/GeoCoordinate.java @@ -0,0 +1,28 @@ +package org.sadtech.bot.core.domain.content; + +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; + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/Mail.java b/src/main/java/org/sadtech/bot/core/domain/content/Mail.java similarity index 97% rename from src/main/java/org/sadtech/bot/core/domain/Mail.java rename to src/main/java/org/sadtech/bot/core/domain/content/Mail.java index a69d39f..3d0c3fe 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/Mail.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.core.domain; +package org.sadtech.bot.core.domain.content; import org.sadtech.bot.core.domain.attachment.Attachment; diff --git a/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoard.java b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoard.java index 12dcf6e..70d0a7b 100644 --- a/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoard.java +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoard.java @@ -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 + + '}'; + } } 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 f59dff1..e5c0d80 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 @@ -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 + + '}'; + } } diff --git a/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardLine.java b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardLine.java index 43b0611..75d5639 100644 --- a/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardLine.java +++ b/src/main/java/org/sadtech/bot/core/domain/keyboard/KeyBoardLine.java @@ -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 keyBoardButtons = new ArrayList<>(); - public KeyBoardLine() { + private KeyBoardLine() { } - public KeyBoardLine(List keyBoardButtons) { - this.keyBoardButtons = keyBoardButtons; - } - public List getKeyBoardButtons() { return keyBoardButtons; } @@ -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 + + '}'; + } } 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 fa8ab67..836f802 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 @@ -67,12 +67,25 @@ public class Account { 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, description, accountStatus); + 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 + + '}'; } } diff --git a/src/main/java/org/sadtech/bot/core/exception/AppBotException.java b/src/main/java/org/sadtech/bot/core/exception/AppBotException.java index 6486ade..51e39f1 100644 --- a/src/main/java/org/sadtech/bot/core/exception/AppBotException.java +++ b/src/main/java/org/sadtech/bot/core/exception/AppBotException.java @@ -4,23 +4,18 @@ import java.time.LocalDateTime; public class AppBotException extends RuntimeException { - private final String type = "ERROR"; + private static final String TYPE = "ERROR"; private final LocalDateTime timeError = LocalDateTime.now(); - protected Integer code; - protected String description; + protected final Integer code; + protected final String description; - public AppBotException(String message, Integer code) { - super(message); + public AppBotException(Integer code, String message) { this.description = message; this.code = code; } - public AppBotException(Integer code) { - this.code = code; - } - public String getType() { - return type; + return TYPE; } public LocalDateTime getTimeError() { diff --git a/src/main/java/org/sadtech/bot/core/exception/MailSendException.java b/src/main/java/org/sadtech/bot/core/exception/MailSendException.java index 60c36a8..52db661 100644 --- a/src/main/java/org/sadtech/bot/core/exception/MailSendException.java +++ b/src/main/java/org/sadtech/bot/core/exception/MailSendException.java @@ -2,9 +2,8 @@ package org.sadtech.bot.core.exception; public class MailSendException extends AppBotException { - public final static Integer CODE = 1; - public MailSendException() { - super(CODE); + super(1, "Ошибка отправки сообщения"); } + } diff --git a/src/main/java/org/sadtech/bot/core/exception/PaymentException.java b/src/main/java/org/sadtech/bot/core/exception/PaymentException.java index 47dfe66..376a7f2 100644 --- a/src/main/java/org/sadtech/bot/core/exception/PaymentException.java +++ b/src/main/java/org/sadtech/bot/core/exception/PaymentException.java @@ -2,12 +2,8 @@ package org.sadtech.bot.core.exception; public class PaymentException extends AppBotException { - public PaymentException(String message, Integer code) { - super(message, code); - } - - public PaymentException(Integer code) { - super(code); + public PaymentException(Integer code, String message) { + super(code, message); } } diff --git a/src/main/java/org/sadtech/bot/core/filter/Filter.java b/src/main/java/org/sadtech/bot/core/filter/Filter.java deleted file mode 100644 index b64ab2e..0000000 --- a/src/main/java/org/sadtech/bot/core/filter/Filter.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.sadtech.bot.core.filter; - -import org.sadtech.bot.core.domain.Content; - -public interface Filter { - - void doFilter(T content); - -} diff --git a/src/main/java/org/sadtech/bot/core/repository/MailRepository.java b/src/main/java/org/sadtech/bot/core/repository/MailRepository.java index 697cb6f..f68576b 100644 --- a/src/main/java/org/sadtech/bot/core/repository/MailRepository.java +++ b/src/main/java/org/sadtech/bot/core/repository/MailRepository.java @@ -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; diff --git a/src/main/java/org/sadtech/bot/core/repository/PersonRepository.java b/src/main/java/org/sadtech/bot/core/repository/PersonRepository.java deleted file mode 100644 index d0dafb4..0000000 --- a/src/main/java/org/sadtech/bot/core/repository/PersonRepository.java +++ /dev/null @@ -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); - -} diff --git a/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryImpl.java b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java similarity index 91% rename from src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryImpl.java rename to src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java index 8742c34..66f8ed0 100644 --- a/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryImpl.java +++ b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java @@ -6,7 +6,7 @@ import org.sadtech.bot.core.repository.AccountRepository; import java.util.HashMap; import java.util.Map; -public class AccountRepositoryImpl implements AccountRepository { +public class AccountRepositoryMap implements AccountRepository { private final Map saveMap = new HashMap<>(); private Integer id = 0; 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 521b024..d0247d4 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,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; diff --git a/src/main/java/org/sadtech/bot/core/repository/impl/PersonRepositoryMap.java b/src/main/java/org/sadtech/bot/core/repository/impl/PersonRepositoryMap.java deleted file mode 100644 index 905befb..0000000 --- a/src/main/java/org/sadtech/bot/core/repository/impl/PersonRepositoryMap.java +++ /dev/null @@ -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, PersonRepository { - - private final Map personMap = new HashMap<>(); - - @Override - public void add(Person person) { - personMap.put(person.getId(), person); - } - - @Override - public void cleanAll() { - personMap.clear(); - } - - @Override - public Queue getEventQueue() { - return new ConcurrentLinkedQueue<>(personMap.values()); - } - - @Override - public Person get(Integer id) { - return personMap.get(id); - } -} 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 6a0db7e..c461d2f 100644 --- a/src/main/java/org/sadtech/bot/core/service/MailService.java +++ b/src/main/java/org/sadtech/bot/core/service/MailService.java @@ -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 { diff --git a/src/main/java/org/sadtech/bot/core/service/PersonService.java b/src/main/java/org/sadtech/bot/core/service/PersonService.java deleted file mode 100644 index 2c27e86..0000000 --- a/src/main/java/org/sadtech/bot/core/service/PersonService.java +++ /dev/null @@ -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 personId); - - Person createPerson(Integer userId); - -} diff --git a/src/main/java/org/sadtech/bot/core/service/filter/Filter.java b/src/main/java/org/sadtech/bot/core/service/filter/Filter.java new file mode 100644 index 0000000..1556412 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/filter/Filter.java @@ -0,0 +1,9 @@ +package org.sadtech.bot.core.service.filter; + +import org.sadtech.bot.core.domain.content.Content; + +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 4df8ca8..2a370e4 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 @@ -30,7 +30,7 @@ public class AccountServiceImpl implements AccountService { } else { account.setAccountStatus(AccountStatus.EXCEPTION); accountRepository.edit(accountId, account); - throw new PaymentException("Неверная сумма", 2); + throw new PaymentException(2, "Неверная сумма"); } return true; } 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 4cb0d04..cbc20c2 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,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 getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { - log.info("Запрошены сообщения " + timeFrom + " - " + timeTo); + log.info("Запрошены сообщения {} - {} ", timeFrom, timeTo); List mails = mailRepository.getMailByTime(timeFrom, timeTo); Set people = new HashSet<>(); List returnMails = new ArrayList<>(); @@ -65,7 +59,7 @@ public class MailServiceImpl implements MailService { @Override public List getEvent(LocalDateTime timeFrom, LocalDateTime timeTo) { - log.info("Запрос на получение сообщений в интервале от " + timeFrom + " до " + timeTo); + log.info("Запрошены сообщения {} - {} ", timeFrom, timeTo); return mailRepository.getMailByTime(timeFrom, timeTo); } 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 f746f00..c04d580 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 @@ -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(); } } diff --git a/src/main/java/org/sadtech/bot/core/utils/Contents.java b/src/main/java/org/sadtech/bot/core/utils/Contents.java new file mode 100644 index 0000000..c3d0c66 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/utils/Contents.java @@ -0,0 +1,14 @@ +package org.sadtech.bot.core.utils; + +import org.sadtech.bot.core.domain.EmptyContent; + +public class Contents { + + private Contents() { + throw new IllegalStateException("Utility class"); + } + + public static final EmptyContent EMPTY_CONTENT = new EmptyContent(); + + +}