diff --git a/pom.xml b/pom.xml index d58ffb5..60d7819 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.bot bot-core - 0.6.0-RELEASE + 0.6.1-RELEASE jar @@ -22,19 +22,11 @@ - - - uPagge - Struchkov Mark - upagge@mail.ru - - - 2.8.5 - 0.5.13-SNAPSHOT 1.7.26 1.4 + 4.12 @@ -55,28 +47,20 @@ ${mail.ver} - - org.apache.logging.log4j - log4j-slf4j-impl - 2.7 - - - - org.apache.logging.log4j - log4j-api - 2.7 - - - org.apache.logging.log4j - log4j-core - 2.7 - junit junit - 4.12 + ${junit.ver} + + + uPagge + Struchkov Mark + upagge@mail.ru + + + \ No newline at end of file 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 3640594..1345258 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.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 + + '}'; + } } 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/AttachmentType.java b/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java deleted file mode 100644 index afce805..0000000 --- a/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.sadtech.bot.core.domain.attachment; - -public enum AttachmentType { - AUDIO_MESSAGE -} 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 95% 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 1059a82..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,4 +1,4 @@ -package org.sadtech.bot.core.domain; +package org.sadtech.bot.core.domain.content; import java.util.Objects; diff --git a/src/main/java/org/sadtech/bot/core/domain/content/EmptyContent.java b/src/main/java/org/sadtech/bot/core/domain/content/EmptyContent.java new file mode 100644 index 0000000..2400a1e --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/content/EmptyContent.java @@ -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"); + } +} 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 93% 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..0e4e720 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,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; diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java similarity index 53% rename from src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java rename to src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java index 1c7de29..12698de 100644 --- a/src/main/java/org/sadtech/bot/core/domain/attachment/Attachment.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java @@ -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; } + } diff --git a/src/main/java/org/sadtech/bot/core/domain/content/attachment/AttachmentType.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/AttachmentType.java new file mode 100644 index 0000000..16fb351 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/AttachmentType.java @@ -0,0 +1,7 @@ +package org.sadtech.bot.core.domain.content.attachment; + +public enum AttachmentType { + + AUDIO_MESSAGE, GEO + +} diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/AudioMessage.java similarity index 93% rename from src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java rename to src/main/java/org/sadtech/bot/core/domain/content/attachment/AudioMessage.java index ef6583a..15f61eb 100644 --- a/src/main/java/org/sadtech/bot/core/domain/attachment/AudioMessage.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/AudioMessage.java @@ -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; diff --git a/src/main/java/org/sadtech/bot/core/domain/content/attachment/Geo.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Geo.java new file mode 100644 index 0000000..520ea14 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Geo.java @@ -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 + '\'' + + '}'; + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/content/attachment/GeoCoordinate.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/GeoCoordinate.java new file mode 100644 index 0000000..69dfa8b --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/GeoCoordinate.java @@ -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; + } +} 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 236ccc9..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; } @@ -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 + + '}'; + } } 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 new file mode 100644 index 0000000..836f802 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/money/Account.java @@ -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 + + '}'; + } +} diff --git a/src/main/java/org/sadtech/bot/core/domain/money/AccountStatus.java b/src/main/java/org/sadtech/bot/core/domain/money/AccountStatus.java new file mode 100644 index 0000000..5ea1cec --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/money/AccountStatus.java @@ -0,0 +1,7 @@ +package org.sadtech.bot.core.domain.money; + +public enum AccountStatus { + + EXPOSED, CLOSED, CANCELLED, EXCEPTION + +} diff --git a/src/main/java/org/sadtech/bot/core/exception/AccessException.java b/src/main/java/org/sadtech/bot/core/exception/AccessException.java new file mode 100644 index 0000000..5c722ad --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/exception/AccessException.java @@ -0,0 +1,7 @@ +package org.sadtech.bot.core.exception; + +public class AccessException extends AppBotException { + public AccessException(Integer code, String message) { + super(code, message); + } +} diff --git a/src/main/java/org/sadtech/bot/core/exception/AppBotException.java b/src/main/java/org/sadtech/bot/core/exception/AppBotException.java new file mode 100644 index 0000000..51e39f1 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/exception/AppBotException.java @@ -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; + } +} 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 f627380..52db661 100644 --- a/src/main/java/org/sadtech/bot/core/exception/MailSendException.java +++ b/src/main/java/org/sadtech/bot/core/exception/MailSendException.java @@ -1,5 +1,9 @@ package org.sadtech.bot.core.exception; -public class MailSendException extends RuntimeException { +public class MailSendException extends AppBotException { + + public MailSendException() { + super(1, "Ошибка отправки сообщения"); + } } diff --git a/src/main/java/org/sadtech/bot/core/exception/NotFoundException.java b/src/main/java/org/sadtech/bot/core/exception/NotFoundException.java new file mode 100644 index 0000000..d3c6351 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/exception/NotFoundException.java @@ -0,0 +1,7 @@ +package org.sadtech.bot.core.exception; + +public class NotFoundException extends AppBotException { + public NotFoundException(Integer code, String message) { + super(code, message); + } +} diff --git a/src/main/java/org/sadtech/bot/core/exception/PaymentException.java b/src/main/java/org/sadtech/bot/core/exception/PaymentException.java new file mode 100644 index 0000000..376a7f2 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/exception/PaymentException.java @@ -0,0 +1,9 @@ +package org.sadtech.bot.core.exception; + +public class PaymentException extends AppBotException { + + 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/AccountRepository.java b/src/main/java/org/sadtech/bot/core/repository/AccountRepository.java new file mode 100644 index 0000000..5c89e8a --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/repository/AccountRepository.java @@ -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); + +} 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/AccountRepositoryMap.java b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java new file mode 100644 index 0000000..a5fa3de --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java @@ -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 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); + } +} 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/repository/impl/TerminalComandRepositoryQueue.java b/src/main/java/org/sadtech/bot/core/repository/impl/TerminalComandRepositoryQueue.java deleted file mode 100644 index 3e6b681..0000000 --- a/src/main/java/org/sadtech/bot/core/repository/impl/TerminalComandRepositoryQueue.java +++ /dev/null @@ -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 { - - private final Queue mailQueue = new ConcurrentLinkedQueue<>(); - - @Override - public void add(Mail dataObject) { - mailQueue.offer(dataObject); - } - - @Override - public void cleanAll() { - mailQueue.clear(); - } - - @Override - public Queue getEventQueue() { - return mailQueue; - } -} diff --git a/src/main/java/org/sadtech/bot/core/service/AccountService.java b/src/main/java/org/sadtech/bot/core/service/AccountService.java new file mode 100644 index 0000000..4a1bae7 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/AccountService.java @@ -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); + +} diff --git a/src/main/java/org/sadtech/bot/core/service/EventService.java b/src/main/java/org/sadtech/bot/core/service/EventService.java index fcb7a1e..9527c4e 100644 --- a/src/main/java/org/sadtech/bot/core/service/EventService.java +++ b/src/main/java/org/sadtech/bot/core/service/EventService.java @@ -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 { +public interface EventService { void add(T event); diff --git a/src/main/java/org/sadtech/bot/core/service/Filter.java b/src/main/java/org/sadtech/bot/core/service/Filter.java new file mode 100644 index 0000000..4da035f --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/Filter.java @@ -0,0 +1,10 @@ +package org.sadtech.bot.core.service; + +import org.sadtech.bot.core.domain.content.Content; + +@FunctionalInterface +public interface Filter { + + void processing(T content); + +} 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 21adbd9..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 idPerson); - - Person createPerson(Integer userId); - -} diff --git a/src/main/java/org/sadtech/bot/core/service/RawEventService.java b/src/main/java/org/sadtech/bot/core/service/RawEventService.java index 46e43f3..168d2f9 100644 --- a/src/main/java/org/sadtech/bot/core/service/RawEventService.java +++ b/src/main/java/org/sadtech/bot/core/service/RawEventService.java @@ -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 getJsonObjects(); - EventRepository getEventRepository(); - } \ No newline at end of file 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 new file mode 100644 index 0000000..e13d53c --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java @@ -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()); + } +} 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/impl/RawEventServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java index c592287..16b7ad7 100644 --- a/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java +++ b/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java @@ -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 eventRepository; - public RawEventServiceImpl(EventRepository eventRepository) { + public RawEventServiceImpl(EventRepository eventRepository) { this.eventRepository = eventRepository; } @@ -35,9 +35,4 @@ public class RawEventServiceImpl implements RawEventService { return eventRepository.getEventQueue(); } - @Override - public EventRepository getEventRepository() { - return eventRepository; - } - } diff --git a/src/main/java/org/sadtech/bot/core/sender/Sent.java b/src/main/java/org/sadtech/bot/core/service/sender/Sent.java similarity index 80% rename from src/main/java/org/sadtech/bot/core/sender/Sent.java rename to src/main/java/org/sadtech/bot/core/service/sender/Sent.java index 120e56c..afab375 100644 --- a/src/main/java/org/sadtech/bot/core/sender/Sent.java +++ b/src/main/java/org/sadtech/bot/core/service/sender/Sent.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.core.sender; +package org.sadtech.bot.core.service.sender; import org.sadtech.bot.core.domain.BoxAnswer; diff --git a/src/main/java/org/sadtech/bot/core/sender/email/EmailConfig.java b/src/main/java/org/sadtech/bot/core/service/sender/email/EmailConfig.java similarity index 97% rename from src/main/java/org/sadtech/bot/core/sender/email/EmailConfig.java rename to src/main/java/org/sadtech/bot/core/service/sender/email/EmailConfig.java index abfbefe..974fce5 100644 --- a/src/main/java/org/sadtech/bot/core/sender/email/EmailConfig.java +++ b/src/main/java/org/sadtech/bot/core/service/sender/email/EmailConfig.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.core.sender.email; +package org.sadtech.bot.core.service.sender.email; import java.util.Properties; diff --git a/src/main/java/org/sadtech/bot/core/sender/email/EmailSent.java b/src/main/java/org/sadtech/bot/core/service/sender/email/EmailSent.java similarity index 90% rename from src/main/java/org/sadtech/bot/core/sender/email/EmailSent.java rename to src/main/java/org/sadtech/bot/core/service/sender/email/EmailSent.java index 9f20425..c04d580 100644 --- a/src/main/java/org/sadtech/bot/core/sender/email/EmailSent.java +++ b/src/main/java/org/sadtech/bot/core/service/sender/email/EmailSent.java @@ -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(); } } 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..9b417b1 --- /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.content.EmptyContent; + +public class Contents { + + private Contents() { + throw new IllegalStateException("Utility class"); + } + + public static final EmptyContent EMPTY_CONTENT = new EmptyContent(); + + +} diff --git a/src/main/java/org/sadtech/bot/core/insert/InsertWords.java b/src/main/java/org/sadtech/bot/core/utils/InsertWords.java similarity index 95% rename from src/main/java/org/sadtech/bot/core/insert/InsertWords.java rename to src/main/java/org/sadtech/bot/core/utils/InsertWords.java index 687d9a7..0dab215 100644 --- a/src/main/java/org/sadtech/bot/core/insert/InsertWords.java +++ b/src/main/java/org/sadtech/bot/core/utils/InsertWords.java @@ -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; diff --git a/src/main/java/org/sadtech/bot/core/service/KeyBoards.java b/src/main/java/org/sadtech/bot/core/utils/KeyBoards.java similarity index 79% rename from src/main/java/org/sadtech/bot/core/service/KeyBoards.java rename to src/main/java/org/sadtech/bot/core/utils/KeyBoards.java index a9b54d7..cb878f5 100644 --- a/src/main/java/org/sadtech/bot/core/service/KeyBoards.java +++ b/src/main/java/org/sadtech/bot/core/utils/KeyBoards.java @@ -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 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(); }