From 8d1532b561cbcfec4469e97762c4386be7a84576 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sun, 28 Jul 2019 21:33:42 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=81=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=BC=D0=B0=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20=D1=81=D0=BE?= =?UTF-8?q?=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=9B=D0=BE=D0=BC?= =?UTF-8?q?=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 12 ++++-- .../social/core/domain/BasicEntity.java | 24 +++++++++++ .../social/core/domain/content/Mail.java | 2 + .../social/core/domain/content/Message.java | 15 +++---- .../social/core/domain/jpa/JsonObjectId.java | 30 +++++++++++++ .../impl/jpa/AccountRepositoryJpaImpl.java | 8 +--- .../impl/jpa/EventRepositoryJpaImpl.java | 42 +++++++++++++++++++ .../impl/jpa/MailRepositoryJpaImpl.java | 8 +--- .../repository/jpa/EventRepositoryJpa.java | 15 +++++++ .../core/service/impl/AccountServiceImpl.java | 6 +-- .../service/impl/BoardCommentServiceImpl.java | 12 ++---- .../core/service/impl/MailServiceImpl.java | 12 ++---- .../service/impl/RawEventServiceImpl.java | 12 ++---- .../service/sender/email/EmailConfig.java | 15 ++----- .../core/service/sender/email/EmailSent.java | 12 ++---- 15 files changed, 152 insertions(+), 73 deletions(-) create mode 100644 src/main/java/org/sadtech/social/core/domain/BasicEntity.java create mode 100644 src/main/java/org/sadtech/social/core/domain/jpa/JsonObjectId.java create mode 100644 src/main/java/org/sadtech/social/core/repository/impl/jpa/EventRepositoryJpaImpl.java create mode 100644 src/main/java/org/sadtech/social/core/repository/jpa/EventRepositoryJpa.java diff --git a/pom.xml b/pom.xml index 4a4f3e5..76dd72e 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,10 @@ 2.8.5 1.7.26 1.4 + 1.18.8 + 2.1.3.RELEASE + 2.2 + 2.0.1.Final @@ -50,22 +54,22 @@ org.projectlombok lombok - 1.18.8 + ${lombok.ver} org.springframework.data spring-data-jpa - 2.1.3.RELEASE + ${spring.data.jpa.ver} javax.persistence javax.persistence-api - 2.2 + ${javax.persistence.api.ver} javax.validation validation-api - 2.0.1.Final + ${validation.api.ver} diff --git a/src/main/java/org/sadtech/social/core/domain/BasicEntity.java b/src/main/java/org/sadtech/social/core/domain/BasicEntity.java new file mode 100644 index 0000000..b9e9955 --- /dev/null +++ b/src/main/java/org/sadtech/social/core/domain/BasicEntity.java @@ -0,0 +1,24 @@ +package org.sadtech.social.core.domain; + +import lombok.Data; +import lombok.ToString; + +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +/** + * Основная сущность для сокрытия id у других сущностей. + * + * @author upagge [28/07/2019] + */ +@Data +@ToString +@MappedSuperclass +public class BasicEntity { + + @Id + @GeneratedValue + protected Integer id; + +} diff --git a/src/main/java/org/sadtech/social/core/domain/content/Mail.java b/src/main/java/org/sadtech/social/core/domain/content/Mail.java index b69d972..3ac675f 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/Mail.java +++ b/src/main/java/org/sadtech/social/core/domain/content/Mail.java @@ -2,6 +2,7 @@ package org.sadtech.social.core.domain.content; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.ToString; import org.sadtech.social.core.domain.content.attachment.Attachment; import org.sadtech.social.core.utils.Description; @@ -21,6 +22,7 @@ import java.util.List; @Entity @Table(name = "mail") @EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) public class Mail extends Message { @OneToMany(fetch = FetchType.EAGER) diff --git a/src/main/java/org/sadtech/social/core/domain/content/Message.java b/src/main/java/org/sadtech/social/core/domain/content/Message.java index 5ec7b98..a1dc7fb 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/Message.java +++ b/src/main/java/org/sadtech/social/core/domain/content/Message.java @@ -1,13 +1,13 @@ package org.sadtech.social.core.domain.content; import lombok.Data; +import lombok.EqualsAndHashCode; +import org.sadtech.social.core.domain.BasicEntity; import org.sadtech.social.core.utils.Description; import javax.persistence.Column; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @@ -17,14 +17,11 @@ import java.time.LocalDateTime; * * @author upagge [08/07/2019] */ -@Data -@MappedSuperclass -public abstract class Message { - @Id - @GeneratedValue - @Description("Идентификатор сообщения") - private Integer id; +@Data +@EqualsAndHashCode(callSuper = true) +@MappedSuperclass +public abstract class Message extends BasicEntity { @Column(name = "type") @Enumerated(value = EnumType.STRING) diff --git a/src/main/java/org/sadtech/social/core/domain/jpa/JsonObjectId.java b/src/main/java/org/sadtech/social/core/domain/jpa/JsonObjectId.java new file mode 100644 index 0000000..d76186f --- /dev/null +++ b/src/main/java/org/sadtech/social/core/domain/jpa/JsonObjectId.java @@ -0,0 +1,30 @@ +package org.sadtech.social.core.domain.jpa; + +import com.google.gson.JsonObject; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.sadtech.social.core.domain.BasicEntity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +/** + * TODO: Добавить описание класса. + * + * @author upagge [28/07/2019] + */ +@Data +@RequiredArgsConstructor +@EqualsAndHashCode(callSuper = true) +@Entity +@Table(name = "event") +public class JsonObjectId extends BasicEntity { + + @Column(name = "json") + @NonNull + private JsonObject jsonObject; + +} diff --git a/src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java b/src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java index 1fa2dcc..e1fb171 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java @@ -1,24 +1,20 @@ package org.sadtech.social.core.repository.impl.jpa; +import lombok.RequiredArgsConstructor; import org.sadtech.social.core.domain.money.Account; import org.sadtech.social.core.repository.AccountRepository; import org.sadtech.social.core.repository.jpa.AccountRepositoryJpa; -import org.springframework.beans.factory.annotation.Autowired; /** * TODO: Добавить описание класса. * * @author upagge [27/07/2019] */ +@RequiredArgsConstructor public class AccountRepositoryJpaImpl implements AccountRepository { private final AccountRepositoryJpa accountRepositoryJpa; - @Autowired - public AccountRepositoryJpaImpl(AccountRepositoryJpa accountRepositoryJpa) { - this.accountRepositoryJpa = accountRepositoryJpa; - } - @Override public Integer add(Account account) { return accountRepositoryJpa.saveAndFlush(account).getId(); diff --git a/src/main/java/org/sadtech/social/core/repository/impl/jpa/EventRepositoryJpaImpl.java b/src/main/java/org/sadtech/social/core/repository/impl/jpa/EventRepositoryJpaImpl.java new file mode 100644 index 0000000..c7bea8d --- /dev/null +++ b/src/main/java/org/sadtech/social/core/repository/impl/jpa/EventRepositoryJpaImpl.java @@ -0,0 +1,42 @@ +package org.sadtech.social.core.repository.impl.jpa; + +import com.google.gson.JsonObject; +import org.sadtech.social.core.domain.jpa.JsonObjectId; +import org.sadtech.social.core.repository.EventRepository; +import org.sadtech.social.core.repository.jpa.EventRepositoryJpa; + +import java.util.List; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.stream.Collectors; + +/** + * TODO: Добавить описание класса. + * + * @author upagge [28/07/2019] + */ +public class EventRepositoryJpaImpl implements EventRepository { + + private final EventRepositoryJpa eventRepositoryJpa; + + public EventRepositoryJpaImpl(EventRepositoryJpa eventRepositoryJpa) { + this.eventRepositoryJpa = eventRepositoryJpa; + } + + @Override + public void add(JsonObject dataObject) { + eventRepositoryJpa.saveAndFlush(new JsonObjectId(dataObject)); + } + + @Override + public void cleanAll() { + eventRepositoryJpa.deleteAll(); + } + + @Override + public Queue getEventQueue() { + List allEvent = eventRepositoryJpa.findAll(); + eventRepositoryJpa.deleteAll(allEvent); + return allEvent.stream().map(JsonObjectId::getJsonObject).collect(Collectors.toCollection(ConcurrentLinkedQueue::new)); + } +} diff --git a/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java b/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java index 894600d..3d96ca2 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java @@ -1,9 +1,9 @@ package org.sadtech.social.core.repository.impl.jpa; +import lombok.RequiredArgsConstructor; import org.sadtech.social.core.domain.content.Mail; import org.sadtech.social.core.repository.ContentRepository; import org.sadtech.social.core.repository.jpa.MailRepositoryJpa; -import org.springframework.beans.factory.annotation.Autowired; import java.time.LocalDateTime; import java.util.List; @@ -13,15 +13,11 @@ import java.util.List; * * @author upagge [25/07/2019] */ +@RequiredArgsConstructor public class MailRepositoryJpaImpl implements ContentRepository { private final MailRepositoryJpa mailRepositoryJpa; - @Autowired - public MailRepositoryJpaImpl(MailRepositoryJpa mailRepositoryJpa) { - this.mailRepositoryJpa = mailRepositoryJpa; - } - @Override public Integer add(Mail content) { return mailRepositoryJpa.saveAndFlush(content).getId(); diff --git a/src/main/java/org/sadtech/social/core/repository/jpa/EventRepositoryJpa.java b/src/main/java/org/sadtech/social/core/repository/jpa/EventRepositoryJpa.java new file mode 100644 index 0000000..bb46f75 --- /dev/null +++ b/src/main/java/org/sadtech/social/core/repository/jpa/EventRepositoryJpa.java @@ -0,0 +1,15 @@ +package org.sadtech.social.core.repository.jpa; + +import org.sadtech.social.core.domain.jpa.JsonObjectId; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * TODO: Добавить описание интерфейса. + * + * @author upagge [28/07/2019] + */ +@Repository +public interface EventRepositoryJpa extends JpaRepository { + +} diff --git a/src/main/java/org/sadtech/social/core/service/impl/AccountServiceImpl.java b/src/main/java/org/sadtech/social/core/service/impl/AccountServiceImpl.java index 5617608..29797d3 100644 --- a/src/main/java/org/sadtech/social/core/service/impl/AccountServiceImpl.java +++ b/src/main/java/org/sadtech/social/core/service/impl/AccountServiceImpl.java @@ -1,19 +1,17 @@ package org.sadtech.social.core.service.impl; +import lombok.RequiredArgsConstructor; import org.sadtech.social.core.domain.money.Account; import org.sadtech.social.core.domain.money.AccountStatus; import org.sadtech.social.core.exception.PaymentException; import org.sadtech.social.core.repository.AccountRepository; import org.sadtech.social.core.service.AccountService; +@RequiredArgsConstructor 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); diff --git a/src/main/java/org/sadtech/social/core/service/impl/BoardCommentServiceImpl.java b/src/main/java/org/sadtech/social/core/service/impl/BoardCommentServiceImpl.java index 7303730..196d0b9 100644 --- a/src/main/java/org/sadtech/social/core/service/impl/BoardCommentServiceImpl.java +++ b/src/main/java/org/sadtech/social/core/service/impl/BoardCommentServiceImpl.java @@ -1,10 +1,10 @@ package org.sadtech.social.core.service.impl; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.sadtech.social.core.domain.content.BoardComment; import org.sadtech.social.core.repository.ContentRepository; import org.sadtech.social.core.service.BoardCommentService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.time.LocalDateTime; import java.util.ArrayList; @@ -12,16 +12,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +@Slf4j +@RequiredArgsConstructor public class BoardCommentServiceImpl implements BoardCommentService { - private static final Logger log = LoggerFactory.getLogger(BoardCommentServiceImpl.class); - private final ContentRepository commentRepository; - public BoardCommentServiceImpl(ContentRepository commentRepository) { - this.commentRepository = commentRepository; - } - @Override public void add(BoardComment event) { commentRepository.add(event); diff --git a/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java b/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java index e94ad2e..a390189 100644 --- a/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java +++ b/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java @@ -1,10 +1,10 @@ package org.sadtech.social.core.service.impl; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.sadtech.social.core.domain.content.Mail; import org.sadtech.social.core.repository.ContentRepository; import org.sadtech.social.core.service.MailService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.time.LocalDateTime; import java.util.ArrayList; @@ -12,16 +12,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +@Slf4j +@RequiredArgsConstructor public class MailServiceImpl implements MailService { - private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class); - private final ContentRepository mailRepository; - public MailServiceImpl(ContentRepository mailRepository) { - this.mailRepository = mailRepository; - } - @Override public void add(Mail mail) { mailRepository.add(mail); diff --git a/src/main/java/org/sadtech/social/core/service/impl/RawEventServiceImpl.java b/src/main/java/org/sadtech/social/core/service/impl/RawEventServiceImpl.java index f1fc726..44ad42d 100644 --- a/src/main/java/org/sadtech/social/core/service/impl/RawEventServiceImpl.java +++ b/src/main/java/org/sadtech/social/core/service/impl/RawEventServiceImpl.java @@ -1,23 +1,19 @@ package org.sadtech.social.core.service.impl; import com.google.gson.JsonObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.sadtech.social.core.repository.EventRepository; import org.sadtech.social.core.service.RawEventService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Queue; +@Slf4j +@RequiredArgsConstructor public class RawEventServiceImpl implements RawEventService { - private static final Logger log = LoggerFactory.getLogger(RawEventServiceImpl.class); - private final EventRepository eventRepository; - public RawEventServiceImpl(EventRepository eventRepository) { - this.eventRepository = eventRepository; - } - @Override public void cleanAll() { eventRepository.cleanAll(); diff --git a/src/main/java/org/sadtech/social/core/service/sender/email/EmailConfig.java b/src/main/java/org/sadtech/social/core/service/sender/email/EmailConfig.java index d564b33..6793b38 100644 --- a/src/main/java/org/sadtech/social/core/service/sender/email/EmailConfig.java +++ b/src/main/java/org/sadtech/social/core/service/sender/email/EmailConfig.java @@ -1,7 +1,10 @@ package org.sadtech.social.core.service.sender.email; +import lombok.Getter; + import java.util.Properties; +@Getter public class EmailConfig { private Properties props = new Properties(); @@ -12,18 +15,6 @@ public class EmailConfig { } - public Properties getProps() { - return props; - } - - public String getUsername() { - return username; - } - - public String getPassword() { - return password; - } - public static Builder builder() { return new EmailConfig().new Builder(); } diff --git a/src/main/java/org/sadtech/social/core/service/sender/email/EmailSent.java b/src/main/java/org/sadtech/social/core/service/sender/email/EmailSent.java index 72598cf..a563136 100644 --- a/src/main/java/org/sadtech/social/core/service/sender/email/EmailSent.java +++ b/src/main/java/org/sadtech/social/core/service/sender/email/EmailSent.java @@ -1,10 +1,10 @@ package org.sadtech.social.core.service.sender.email; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.exception.MailSendException; import org.sadtech.social.core.service.sender.Sent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.mail.Authenticator; import javax.mail.Message; @@ -15,16 +15,12 @@ import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; +@Slf4j +@RequiredArgsConstructor public class EmailSent implements Sent { - private static final Logger log = LoggerFactory.getLogger(Sent.class); - private final EmailConfig emailConfig; - public EmailSent(EmailConfig emailConfig) { - this.emailConfig = emailConfig; - } - @Override public void send(Integer personId, BoxAnswer boxAnswer) { Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() {