From 6834aa2801b67c5733fc4897a52b1316f5de5ae6 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sun, 19 May 2019 22:54:36 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=A3=D1=81=D0=BB=D0=B0=D0=B6=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F.?= =?UTF-8?q?=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d58ffb5..3a747be 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.bot bot-core - 0.6.0-RELEASE + 0.6.1-SNAPSHOT jar @@ -32,7 +32,6 @@ 2.8.5 - 0.5.13-SNAPSHOT 1.7.26 1.4 From b4baee35f091d01c96fe5896dbd77baaae1ed626 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 20 May 2019 15:46:04 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B5=D1=80,=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=BB=20=D0=B2=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sadtech/bot/core/domain/Content.java | 2 ++ .../sadtech/bot/core/domain/EmptyContent.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/java/org/sadtech/bot/core/domain/EmptyContent.java diff --git a/src/main/java/org/sadtech/bot/core/domain/Content.java b/src/main/java/org/sadtech/bot/core/domain/Content.java index 1059a82..f65aa19 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Content.java +++ b/src/main/java/org/sadtech/bot/core/domain/Content.java @@ -4,6 +4,8 @@ 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/EmptyContent.java b/src/main/java/org/sadtech/bot/core/domain/EmptyContent.java new file mode 100644 index 0000000..a2ac004 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/EmptyContent.java @@ -0,0 +1,18 @@ +package org.sadtech.bot.core.domain; + +public class EmptyContent extends Content { + + public EmptyContent() { + + } + + @Override + public String getMessage() { + return ""; + } + + @Override + public void setMessage(String message) { + + } +} From 0dfddc7f2de3881d96eebbc9bb4a742573ea6b83 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Tue, 21 May 2019 00:20:21 +0300 Subject: [PATCH 3/8] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D1=8E?= =?UTF-8?q?=D0=BD=D0=B8=D1=82=20=D1=81=D0=BA=D1=80=D1=8B=D1=82=D0=BE=D0=B9?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8,=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=B2=20=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=BE=D0=B9=20=D1=8E?= =?UTF-8?q?=D0=BD=D0=B8=D1=82=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=A0=D0=B0=D0=B7=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D1=81=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=8E=D0=BD=D0=B8=D1=82=D0=BE=D0=B2=20=D1=81=20?= =?UTF-8?q?AFTER=20=D1=81=D1=80=D0=B0=D0=B1=D0=B0=D1=82=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java | 2 +- .../org/sadtech/bot/core/domain/keyboard/KeyBoardLine.java | 2 +- src/main/java/org/sadtech/bot/core/service/KeyBoards.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) 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..f417e6e 100644 --- a/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java +++ b/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java @@ -12,7 +12,7 @@ public class BoxAnswer { private Float aLong; private Integer stickerId; - public BoxAnswer() { + private BoxAnswer() { } 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..43b0611 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 @@ -29,7 +29,7 @@ public class KeyBoardLine { } - public Builder setButtonKeyBoard(KeyBoardButton keyBoardButton) { + public Builder buttonKeyBoard(KeyBoardButton keyBoardButton) { KeyBoardLine.this.keyBoardButtons.add(keyBoardButton); return this; } diff --git a/src/main/java/org/sadtech/bot/core/service/KeyBoards.java b/src/main/java/org/sadtech/bot/core/service/KeyBoards.java index a9b54d7..4c04ed7 100644 --- a/src/main/java/org/sadtech/bot/core/service/KeyBoards.java +++ b/src/main/java/org/sadtech/bot/core/service/KeyBoards.java @@ -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(); } From fd8c8402d128a705cd770b3670063bdcaac8209c Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 24 May 2019 12:20:27 +0300 Subject: [PATCH 4/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D0=BF=D0=BB=D0=B0=D1=82=D0=B0=20=D0=A0?= =?UTF-8?q?=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bot/core/domain/money/Account.java | 78 +++++++++++++++++++ .../bot/core/domain/money/AccountStatus.java | 7 ++ .../bot/core/exception/AppBotException.java | 37 +++++++++ .../bot/core/exception/MailSendException.java | 7 +- .../bot/core/exception/PaymentException.java | 13 ++++ .../core/repository/AccountRepository.java | 13 ++++ .../impl/AccountRepositoryImpl.java | 31 ++++++++ .../impl/TerminalComandRepositoryQueue.java | 27 ------- .../bot/core/service/AccountService.java | 13 ++++ .../bot/core/service/PersonService.java | 2 +- .../core/service/impl/AccountServiceImpl.java | 42 ++++++++++ .../bot/core/{ => service}/sender/Sent.java | 2 +- .../sender/email/EmailConfig.java | 2 +- .../{ => service}/sender/email/EmailSent.java | 4 +- .../core/{insert => utils}/InsertWords.java | 2 +- .../core/{service => utils}/KeyBoards.java | 2 +- 16 files changed, 247 insertions(+), 35 deletions(-) create mode 100644 src/main/java/org/sadtech/bot/core/domain/money/Account.java create mode 100644 src/main/java/org/sadtech/bot/core/domain/money/AccountStatus.java create mode 100644 src/main/java/org/sadtech/bot/core/exception/AppBotException.java create mode 100644 src/main/java/org/sadtech/bot/core/exception/PaymentException.java create mode 100644 src/main/java/org/sadtech/bot/core/repository/AccountRepository.java create mode 100644 src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryImpl.java delete mode 100644 src/main/java/org/sadtech/bot/core/repository/impl/TerminalComandRepositoryQueue.java create mode 100644 src/main/java/org/sadtech/bot/core/service/AccountService.java create mode 100644 src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java rename src/main/java/org/sadtech/bot/core/{ => service}/sender/Sent.java (80%) rename src/main/java/org/sadtech/bot/core/{ => service}/sender/email/EmailConfig.java (97%) rename src/main/java/org/sadtech/bot/core/{ => service}/sender/email/EmailSent.java (93%) rename src/main/java/org/sadtech/bot/core/{insert => utils}/InsertWords.java (95%) rename src/main/java/org/sadtech/bot/core/{service => utils}/KeyBoards.java (97%) 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..fa8ab67 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/money/Account.java @@ -0,0 +1,78 @@ +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(description, account.description) && + accountStatus == account.accountStatus; + } + + @Override + public int hashCode() { + return Objects.hash(id, totalSum, belongsPersonId, description, 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..bbd8622 --- /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/AppBotException.java b/src/main/java/org/sadtech/bot/core/exception/AppBotException.java new file mode 100644 index 0000000..6486ade --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/exception/AppBotException.java @@ -0,0 +1,37 @@ +package org.sadtech.bot.core.exception; + +import java.time.LocalDateTime; + +public class AppBotException extends RuntimeException { + + private final String type = "ERROR"; + private final LocalDateTime timeError = LocalDateTime.now(); + protected Integer code; + protected String description; + + public AppBotException(String message, Integer code) { + super(message); + this.description = message; + this.code = code; + } + + public AppBotException(Integer code) { + 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..60c36a8 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,10 @@ package org.sadtech.bot.core.exception; -public class MailSendException extends RuntimeException { +public class MailSendException extends AppBotException { + public final static Integer CODE = 1; + + public MailSendException() { + super(CODE); + } } 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..47dfe66 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/exception/PaymentException.java @@ -0,0 +1,13 @@ +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); + } + +} 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/impl/AccountRepositoryImpl.java b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryImpl.java new file mode 100644 index 0000000..8742c34 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryImpl.java @@ -0,0 +1,31 @@ +package org.sadtech.bot.core.repository.impl; + +import org.sadtech.bot.core.domain.money.Account; +import org.sadtech.bot.core.repository.AccountRepository; + +import java.util.HashMap; +import java.util.Map; + +public class AccountRepositoryImpl implements AccountRepository { + + private final Map saveMap = new HashMap<>(); + private Integer id = 0; + + @Override + public Integer add(Account account) { + account.setId(id); + saveMap.put(id, account); + return id++; + } + + @Override + public void edit(Integer accountId, Account account) { + account.setId(accountId); + saveMap.put(accountId, account); + } + + @Override + public Account findById(Integer accountId) { + return saveMap.get(accountId); + } +} 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/PersonService.java b/src/main/java/org/sadtech/bot/core/service/PersonService.java index 21adbd9..2c27e86 100644 --- a/src/main/java/org/sadtech/bot/core/service/PersonService.java +++ b/src/main/java/org/sadtech/bot/core/service/PersonService.java @@ -8,7 +8,7 @@ public interface PersonService { Person get(Integer id); - boolean checkPerson(Integer idPerson); + boolean checkPerson(Integer personId); Person createPerson(Integer userId); 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..4df8ca8 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java @@ -0,0 +1,42 @@ +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 (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); + } + return true; + } + + @Override + public Boolean paymentVerification(Integer accountId) { + return AccountStatus.CLOSED.equals(accountRepository.findById(accountId).getAccountStatus()); + } +} 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 93% 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..f746f00 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; 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 97% 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 4c04ed7..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; From dfc4f36e55ddf9c063cc83392556f25e077b0468 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 24 May 2019 15:47:05 +0300 Subject: [PATCH 5/8] =?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(); + + +} From 8e5edc1e9e7f1e483b7e7ab1c66bc06f1de751e7 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sun, 26 May 2019 22:15:47 +0300 Subject: [PATCH 6/8] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sadtech/bot/core/domain/BoxAnswer.java | 2 +- .../domain/{ => content}/EmptyContent.java | 3 +- .../sadtech/bot/core/domain/content/Mail.java | 2 +- .../{ => content}/attachment/Attachment.java | 2 +- .../attachment/AttachmentType.java | 2 +- .../attachment/AudioMessage.java | 2 +- .../domain/{ => content}/attachment/Geo.java | 4 +-- .../{ => attachment}/GeoCoordinate.java | 2 +- .../bot/core/domain/money/AccountStatus.java | 2 +- .../bot/core/exception/AccessException.java | 7 +++++ .../bot/core/exception/NotFoundException.java | 7 +++++ .../repository/impl/AccountRepositoryMap.java | 31 ++++++++++++++----- .../bot/core/service/EventService.java | 4 ++- .../bot/core/service/{filter => }/Filter.java | 3 +- .../bot/core/service/RawEventService.java | 3 -- .../service/impl/RawEventServiceImpl.java | 5 --- .../org/sadtech/bot/core/utils/Contents.java | 2 +- 17 files changed, 53 insertions(+), 30 deletions(-) rename src/main/java/org/sadtech/bot/core/domain/{ => content}/EmptyContent.java (77%) rename src/main/java/org/sadtech/bot/core/domain/{ => content}/attachment/Attachment.java (70%) rename src/main/java/org/sadtech/bot/core/domain/{ => content}/attachment/AttachmentType.java (50%) rename src/main/java/org/sadtech/bot/core/domain/{ => content}/attachment/AudioMessage.java (93%) rename src/main/java/org/sadtech/bot/core/domain/{ => content}/attachment/Geo.java (94%) rename src/main/java/org/sadtech/bot/core/domain/content/{ => attachment}/GeoCoordinate.java (90%) create mode 100644 src/main/java/org/sadtech/bot/core/exception/AccessException.java create mode 100644 src/main/java/org/sadtech/bot/core/exception/NotFoundException.java rename src/main/java/org/sadtech/bot/core/service/{filter => }/Filter.java (69%) 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 b84a414..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,6 +1,6 @@ package org.sadtech.bot.core.domain; -import org.sadtech.bot.core.domain.content.GeoCoordinate; +import org.sadtech.bot.core.domain.content.attachment.GeoCoordinate; import org.sadtech.bot.core.domain.keyboard.KeyBoard; import java.util.Objects; diff --git a/src/main/java/org/sadtech/bot/core/domain/EmptyContent.java b/src/main/java/org/sadtech/bot/core/domain/content/EmptyContent.java similarity index 77% rename from src/main/java/org/sadtech/bot/core/domain/EmptyContent.java rename to src/main/java/org/sadtech/bot/core/domain/content/EmptyContent.java index 328eb32..2400a1e 100644 --- a/src/main/java/org/sadtech/bot/core/domain/EmptyContent.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/EmptyContent.java @@ -1,6 +1,5 @@ -package org.sadtech.bot.core.domain; +package org.sadtech.bot.core.domain.content; -import org.sadtech.bot.core.domain.content.Content; import org.sadtech.bot.core.exception.AppBotException; public class EmptyContent extends Content { diff --git a/src/main/java/org/sadtech/bot/core/domain/content/Mail.java b/src/main/java/org/sadtech/bot/core/domain/content/Mail.java index 3d0c3fe..0e4e720 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/Mail.java @@ -1,6 +1,6 @@ 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 70% 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 ecf3782..fef3973 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,4 +1,4 @@ -package org.sadtech.bot.core.domain.attachment; +package org.sadtech.bot.core.domain.content.attachment; public abstract class Attachment { diff --git a/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/AttachmentType.java similarity index 50% rename from src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java rename to src/main/java/org/sadtech/bot/core/domain/content/attachment/AttachmentType.java index 2487c99..16fb351 100644 --- a/src/main/java/org/sadtech/bot/core/domain/attachment/AttachmentType.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/AttachmentType.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.core.domain.attachment; +package org.sadtech.bot.core.domain.content.attachment; public enum AttachmentType { 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/attachment/Geo.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Geo.java similarity index 94% rename from src/main/java/org/sadtech/bot/core/domain/attachment/Geo.java rename to src/main/java/org/sadtech/bot/core/domain/content/attachment/Geo.java index e6bc1bb..520ea14 100644 --- a/src/main/java/org/sadtech/bot/core/domain/attachment/Geo.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Geo.java @@ -1,6 +1,4 @@ -package org.sadtech.bot.core.domain.attachment; - -import org.sadtech.bot.core.domain.content.GeoCoordinate; +package org.sadtech.bot.core.domain.content.attachment; import java.util.Objects; diff --git a/src/main/java/org/sadtech/bot/core/domain/content/GeoCoordinate.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/GeoCoordinate.java similarity index 90% rename from src/main/java/org/sadtech/bot/core/domain/content/GeoCoordinate.java rename to src/main/java/org/sadtech/bot/core/domain/content/attachment/GeoCoordinate.java index 09998c0..69dfa8b 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/GeoCoordinate.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/GeoCoordinate.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.core.domain.content; +package org.sadtech.bot.core.domain.content.attachment; public class GeoCoordinate { 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 index bbd8622..5ea1cec 100644 --- a/src/main/java/org/sadtech/bot/core/domain/money/AccountStatus.java +++ b/src/main/java/org/sadtech/bot/core/domain/money/AccountStatus.java @@ -2,6 +2,6 @@ package org.sadtech.bot.core.domain.money; public enum AccountStatus { - EXPOSED, CLOSED, CANCELLED, EXCEPTION; + 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/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/repository/impl/AccountRepositoryMap.java b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java index 66f8ed0..a5fa3de 100644 --- a/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java +++ b/src/main/java/org/sadtech/bot/core/repository/impl/AccountRepositoryMap.java @@ -1,31 +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 = 0; + private Integer id = 1; @Override public Integer add(Account account) { - account.setId(id); - saveMap.put(id, account); - return id++; + 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) { - account.setId(accountId); - saveMap.put(accountId, account); + if (check(id)) { + account.setId(accountId); + saveMap.put(accountId, account); + } else { + throw new NotFoundException(491, "Счет " + accountId + " не найден"); + } } @Override public Account findById(Integer accountId) { - return saveMap.get(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/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/Filter.java b/src/main/java/org/sadtech/bot/core/service/Filter.java similarity index 69% rename from src/main/java/org/sadtech/bot/core/service/filter/Filter.java rename to src/main/java/org/sadtech/bot/core/service/Filter.java index 1556412..4da035f 100644 --- a/src/main/java/org/sadtech/bot/core/service/filter/Filter.java +++ b/src/main/java/org/sadtech/bot/core/service/Filter.java @@ -1,7 +1,8 @@ -package org.sadtech.bot.core.service.filter; +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/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/RawEventServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java index c592287..a61880c 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 @@ -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/utils/Contents.java b/src/main/java/org/sadtech/bot/core/utils/Contents.java index c3d0c66..9b417b1 100644 --- a/src/main/java/org/sadtech/bot/core/utils/Contents.java +++ b/src/main/java/org/sadtech/bot/core/utils/Contents.java @@ -1,6 +1,6 @@ package org.sadtech.bot.core.utils; -import org.sadtech.bot.core.domain.EmptyContent; +import org.sadtech.bot.core.domain.content.EmptyContent; public class Contents { From 3184e46d1bcbf07481e92e427e07ba9f4bbb7b13 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 27 May 2019 09:57:51 +0300 Subject: [PATCH 7/8] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/content/attachment/Attachment.java | 2 +- .../core/service/impl/AccountServiceImpl.java | 22 +++++++++++++------ .../service/impl/RawEventServiceImpl.java | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java index fef3973..12698de 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java @@ -2,7 +2,7 @@ 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/service/impl/AccountServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java index 2a370e4..e13d53c 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 @@ -23,18 +23,26 @@ public class AccountServiceImpl implements AccountService { @Override public Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum) { Account account = accountRepository.findById(accountId); - if (account.getTotalSum().equals(sum)) { - account.setAccountStatus(AccountStatus.CLOSED); - account.setExtinguishedPersonId(extinguishedPersonId); - accountRepository.edit(accountId, account); + 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 { - account.setAccountStatus(AccountStatus.EXCEPTION); - accountRepository.edit(accountId, account); - throw new PaymentException(2, "Неверная сумма"); + 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/RawEventServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java index a61880c..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; } From 0e0e4397392ece4e6d00dede21f1a2f24ca3912b Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 27 May 2019 10:26:19 +0300 Subject: [PATCH 8/8] release-0.6.1 --- pom.xml | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/pom.xml b/pom.xml index 3a747be..60d7819 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.bot bot-core - 0.6.1-SNAPSHOT + 0.6.1-RELEASE jar @@ -22,18 +22,11 @@ - - - uPagge - Struchkov Mark - upagge@mail.ru - - - 2.8.5 1.7.26 1.4 + 4.12 @@ -54,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