From 198bb8599b92097136249c8ad201ab37da4fdccb Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sun, 28 Jul 2019 08:51:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B5=20=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BE?= =?UTF-8?q?=D1=82=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8F=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=B0=D0=BF=D0=B8=D0=BD=D0=B3?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=B1=D0=B4=20=D0=9F=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20findByTime=20?= =?UTF-8?q?=D0=B2=20betweenByTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 +++++ .../org/sadtech/social/core/domain/content/Mail.java | 3 ++- .../sadtech/social/core/domain/content/Message.java | 6 +++--- .../sadtech/social/core/domain/money/Account.java | 12 +++--------- .../social/core/repository/ContentRepository.java | 2 +- .../impl/jpa/AccountRepositoryJpaImpl.java | 4 ++-- .../repository/impl/jpa/MailRepositoryJpaImpl.java | 6 +++--- .../impl/local/BoardCommentRepositoryMap.java | 2 +- .../repository/impl/local/MailRepositoryList.java | 4 ++-- .../core/repository/jpa/AccountRepositoryJpa.java | 2 ++ .../core/repository/jpa/MailRepositoryJpa.java | 2 ++ .../core/service/impl/BoardCommentServiceImpl.java | 2 +- .../social/core/service/impl/MailServiceImpl.java | 4 ++-- 13 files changed, 29 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index a0fc767..4a4f3e5 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,11 @@ javax.persistence-api 2.2 + + javax.validation + validation-api + 2.0.1.Final + 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 f0b9a58..b69d972 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 @@ -7,6 +7,7 @@ import org.sadtech.social.core.utils.Description; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.OneToMany; import javax.persistence.Table; import java.util.List; @@ -22,7 +23,7 @@ import java.util.List; @EqualsAndHashCode(callSuper = true) public class Mail extends Message { - @OneToMany + @OneToMany(fetch = FetchType.EAGER) @Column(name = "attachment") @Description("Вложения к сообщению") private List attachments; 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 459eae3..5ec7b98 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,15 +1,15 @@ package org.sadtech.social.core.domain.content; -import com.sun.istack.internal.NotNull; import lombok.Data; import org.sadtech.social.core.utils.Description; import javax.persistence.Column; -import javax.persistence.Entity; 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; /** @@ -18,7 +18,7 @@ import java.time.LocalDateTime; * @author upagge [08/07/2019] */ @Data -@Entity +@MappedSuperclass public abstract class Message { @Id diff --git a/src/main/java/org/sadtech/social/core/domain/money/Account.java b/src/main/java/org/sadtech/social/core/domain/money/Account.java index d3cf621..2e4a5d2 100644 --- a/src/main/java/org/sadtech/social/core/domain/money/Account.java +++ b/src/main/java/org/sadtech/social/core/domain/money/Account.java @@ -1,13 +1,9 @@ package org.sadtech.social.core.domain.money; -import com.sun.istack.internal.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; +import lombok.Data; import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; import org.sadtech.social.core.utils.Description; import javax.persistence.Column; @@ -17,6 +13,7 @@ import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; +import javax.validation.constraints.NotNull; /** * Сущность, которая отвечает за выставленный пользователю счет. @@ -24,10 +21,7 @@ import javax.persistence.Table; * @author upagge [08/07/2019] */ @Builder -@Getter -@Setter -@EqualsAndHashCode -@ToString +@Data @NoArgsConstructor @AllArgsConstructor @Entity diff --git a/src/main/java/org/sadtech/social/core/repository/ContentRepository.java b/src/main/java/org/sadtech/social/core/repository/ContentRepository.java index 862fbb5..179d89b 100644 --- a/src/main/java/org/sadtech/social/core/repository/ContentRepository.java +++ b/src/main/java/org/sadtech/social/core/repository/ContentRepository.java @@ -27,6 +27,6 @@ public interface ContentRepository { * @param timeTo Конец диапазона * @return Список сообщений */ - List findByTime(LocalDateTime timeFrom, LocalDateTime timeTo); + List betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo); } 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 a6cfc6a..1fa2dcc 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 @@ -3,18 +3,18 @@ package org.sadtech.social.core.repository.impl.jpa; 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.stereotype.Repository; +import org.springframework.beans.factory.annotation.Autowired; /** * TODO: Добавить описание класса. * * @author upagge [27/07/2019] */ -@Repository public class AccountRepositoryJpaImpl implements AccountRepository { private final AccountRepositoryJpa accountRepositoryJpa; + @Autowired public AccountRepositoryJpaImpl(AccountRepositoryJpa accountRepositoryJpa) { this.accountRepositoryJpa = accountRepositoryJpa; } 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 595d651..894600d 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 @@ -3,7 +3,7 @@ package org.sadtech.social.core.repository.impl.jpa; 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.stereotype.Repository; +import org.springframework.beans.factory.annotation.Autowired; import java.time.LocalDateTime; import java.util.List; @@ -13,11 +13,11 @@ import java.util.List; * * @author upagge [25/07/2019] */ -@Repository public class MailRepositoryJpaImpl implements ContentRepository { private final MailRepositoryJpa mailRepositoryJpa; + @Autowired public MailRepositoryJpaImpl(MailRepositoryJpa mailRepositoryJpa) { this.mailRepositoryJpa = mailRepositoryJpa; } @@ -28,7 +28,7 @@ public class MailRepositoryJpaImpl implements ContentRepository { } @Override - public List findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + public List betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { return mailRepositoryJpa.findByCreateDateBetween(timeFrom, timeTo); } } diff --git a/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java b/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java index 53e7650..faaa6c6 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java @@ -22,7 +22,7 @@ public class BoardCommentRepositoryMap implements ContentRepository findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + public List betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { ArrayList rezultMails = new ArrayList<>(); for (int i = saveMap.size() - 1; i >= 0; i--) { if (!(saveMap.get(i).getCreateDate().isBefore(timeFrom) || saveMap.get(i).getCreateDate().isAfter(timeTo)) && saveMap.get(i).getCreateDate().equals(timeFrom)) { diff --git a/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java b/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java index 844b217..c5afdf3 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java @@ -24,10 +24,10 @@ public class MailRepositoryList implements ContentRepository { @Override - public List findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + public List betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { ArrayList rezultMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { - if (!(mails.get(i).getCreateDate().isBefore(timeFrom) || mails.get(i).getCreateDate().isAfter(timeTo)) && mails.get(i).getCreateDate().equals(timeFrom)) { + if (!(mails.get(i).getCreateDate().isBefore(timeFrom) || mails.get(i).getCreateDate().isAfter(timeTo))) { rezultMails.add(this.mails.get(i)); } else if (mails.get(i).getCreateDate().isBefore(timeFrom)) { break; diff --git a/src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java b/src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java index 36f59e0..b1e08e2 100644 --- a/src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java +++ b/src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java @@ -2,12 +2,14 @@ package org.sadtech.social.core.repository.jpa; import org.sadtech.social.core.domain.money.Account; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; /** * TODO: Добавить описание интерфейса. * * @author upagge [27/07/2019] */ +@Repository public interface AccountRepositoryJpa extends JpaRepository { } diff --git a/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java b/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java index 58bd49c..e953fcb 100644 --- a/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java +++ b/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java @@ -2,6 +2,7 @@ package org.sadtech.social.core.repository.jpa; import org.sadtech.social.core.domain.content.Mail; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import java.time.LocalDateTime; import java.util.List; @@ -12,6 +13,7 @@ import java.util.List; * * @author upagge [27/07/2019] */ +@Repository public interface MailRepositoryJpa extends JpaRepository { List findByCreateDateBetween(LocalDateTime from, LocalDateTime to); 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 772653f..7303730 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 @@ -35,7 +35,7 @@ public class BoardCommentServiceImpl implements BoardCommentService { @Override public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { log.info("Запрошены последние комментарии к обсуждению {} - {} ", timeFrom, timeTo); - List mails = commentRepository.findByTime(timeFrom, timeTo); + List mails = commentRepository.betweenByTime(timeFrom, timeTo); Set people = new HashSet<>(); List returnMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { 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 0b977c7..e94ad2e 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 @@ -31,7 +31,7 @@ public class MailServiceImpl implements MailService { @Override public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { log.info("Запрошены последние сообщения {} - {} ", timeFrom, timeTo); - List mails = mailRepository.findByTime(timeFrom, timeTo); + List mails = mailRepository.betweenByTime(timeFrom, timeTo); Set people = new HashSet<>(); List returnMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { @@ -46,7 +46,7 @@ public class MailServiceImpl implements MailService { @Override public List getByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { log.info("Запрошены все сообщения {} - {} ", timeFrom, timeTo); - return mailRepository.findByTime(timeFrom, timeTo); + return mailRepository.betweenByTime(timeFrom, timeTo); } }