Новая система выборки новых сообщений

Ломбок
This commit is contained in:
Mark Struchkov 2019-07-28 21:33:42 +03:00
parent 198bb8599b
commit 8d1532b561
15 changed files with 152 additions and 73 deletions

12
pom.xml
View File

@ -26,6 +26,10 @@
<gson.ver>2.8.5</gson.ver> <gson.ver>2.8.5</gson.ver>
<slf4j.ver>1.7.26</slf4j.ver> <slf4j.ver>1.7.26</slf4j.ver>
<mail.ver>1.4</mail.ver> <mail.ver>1.4</mail.ver>
<lombok.ver>1.18.8</lombok.ver>
<spring.data.jpa.ver>2.1.3.RELEASE</spring.data.jpa.ver>
<javax.persistence.api.ver>2.2</javax.persistence.api.ver>
<validation.api.ver>2.0.1.Final</validation.api.ver>
</properties> </properties>
<dependencies> <dependencies>
@ -50,22 +54,22 @@
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.8</version> <version>${lombok.ver}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId> <artifactId>spring-data-jpa</artifactId>
<version>2.1.3.RELEASE</version> <version>${spring.data.jpa.ver}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.persistence</groupId> <groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId> <artifactId>javax.persistence-api</artifactId>
<version>2.2</version> <version>${javax.persistence.api.ver}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.validation</groupId> <groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId> <artifactId>validation-api</artifactId>
<version>2.0.1.Final</version> <version>${validation.api.ver}</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -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;
}

View File

@ -2,6 +2,7 @@ package org.sadtech.social.core.domain.content;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.sadtech.social.core.domain.content.attachment.Attachment; import org.sadtech.social.core.domain.content.attachment.Attachment;
import org.sadtech.social.core.utils.Description; import org.sadtech.social.core.utils.Description;
@ -21,6 +22,7 @@ import java.util.List;
@Entity @Entity
@Table(name = "mail") @Table(name = "mail")
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class Mail extends Message { public class Mail extends Message {
@OneToMany(fetch = FetchType.EAGER) @OneToMany(fetch = FetchType.EAGER)

View File

@ -1,13 +1,13 @@
package org.sadtech.social.core.domain.content; package org.sadtech.social.core.domain.content;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import org.sadtech.social.core.domain.BasicEntity;
import org.sadtech.social.core.utils.Description; import org.sadtech.social.core.utils.Description;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -17,14 +17,11 @@ import java.time.LocalDateTime;
* *
* @author upagge [08/07/2019] * @author upagge [08/07/2019]
*/ */
@Data
@MappedSuperclass
public abstract class Message {
@Id @Data
@GeneratedValue @EqualsAndHashCode(callSuper = true)
@Description("Идентификатор сообщения") @MappedSuperclass
private Integer id; public abstract class Message extends BasicEntity {
@Column(name = "type") @Column(name = "type")
@Enumerated(value = EnumType.STRING) @Enumerated(value = EnumType.STRING)

View File

@ -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;
}

View File

@ -1,24 +1,20 @@
package org.sadtech.social.core.repository.impl.jpa; package org.sadtech.social.core.repository.impl.jpa;
import lombok.RequiredArgsConstructor;
import org.sadtech.social.core.domain.money.Account; import org.sadtech.social.core.domain.money.Account;
import org.sadtech.social.core.repository.AccountRepository; import org.sadtech.social.core.repository.AccountRepository;
import org.sadtech.social.core.repository.jpa.AccountRepositoryJpa; import org.sadtech.social.core.repository.jpa.AccountRepositoryJpa;
import org.springframework.beans.factory.annotation.Autowired;
/** /**
* TODO: Добавить описание класса. * TODO: Добавить описание класса.
* *
* @author upagge [27/07/2019] * @author upagge [27/07/2019]
*/ */
@RequiredArgsConstructor
public class AccountRepositoryJpaImpl implements AccountRepository { public class AccountRepositoryJpaImpl implements AccountRepository {
private final AccountRepositoryJpa accountRepositoryJpa; private final AccountRepositoryJpa accountRepositoryJpa;
@Autowired
public AccountRepositoryJpaImpl(AccountRepositoryJpa accountRepositoryJpa) {
this.accountRepositoryJpa = accountRepositoryJpa;
}
@Override @Override
public Integer add(Account account) { public Integer add(Account account) {
return accountRepositoryJpa.saveAndFlush(account).getId(); return accountRepositoryJpa.saveAndFlush(account).getId();

View File

@ -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<JsonObject> {
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<JsonObject> getEventQueue() {
List<JsonObjectId> allEvent = eventRepositoryJpa.findAll();
eventRepositoryJpa.deleteAll(allEvent);
return allEvent.stream().map(JsonObjectId::getJsonObject).collect(Collectors.toCollection(ConcurrentLinkedQueue::new));
}
}

View File

@ -1,9 +1,9 @@
package org.sadtech.social.core.repository.impl.jpa; package org.sadtech.social.core.repository.impl.jpa;
import lombok.RequiredArgsConstructor;
import org.sadtech.social.core.domain.content.Mail; import org.sadtech.social.core.domain.content.Mail;
import org.sadtech.social.core.repository.ContentRepository; import org.sadtech.social.core.repository.ContentRepository;
import org.sadtech.social.core.repository.jpa.MailRepositoryJpa; import org.sadtech.social.core.repository.jpa.MailRepositoryJpa;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -13,15 +13,11 @@ import java.util.List;
* *
* @author upagge [25/07/2019] * @author upagge [25/07/2019]
*/ */
@RequiredArgsConstructor
public class MailRepositoryJpaImpl implements ContentRepository<Mail> { public class MailRepositoryJpaImpl implements ContentRepository<Mail> {
private final MailRepositoryJpa mailRepositoryJpa; private final MailRepositoryJpa mailRepositoryJpa;
@Autowired
public MailRepositoryJpaImpl(MailRepositoryJpa mailRepositoryJpa) {
this.mailRepositoryJpa = mailRepositoryJpa;
}
@Override @Override
public Integer add(Mail content) { public Integer add(Mail content) {
return mailRepositoryJpa.saveAndFlush(content).getId(); return mailRepositoryJpa.saveAndFlush(content).getId();

View File

@ -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<JsonObjectId, Integer> {
}

View File

@ -1,19 +1,17 @@
package org.sadtech.social.core.service.impl; 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.Account;
import org.sadtech.social.core.domain.money.AccountStatus; import org.sadtech.social.core.domain.money.AccountStatus;
import org.sadtech.social.core.exception.PaymentException; import org.sadtech.social.core.exception.PaymentException;
import org.sadtech.social.core.repository.AccountRepository; import org.sadtech.social.core.repository.AccountRepository;
import org.sadtech.social.core.service.AccountService; import org.sadtech.social.core.service.AccountService;
@RequiredArgsConstructor
public class AccountServiceImpl implements AccountService { public class AccountServiceImpl implements AccountService {
private final AccountRepository accountRepository; private final AccountRepository accountRepository;
public AccountServiceImpl(AccountRepository accountRepository) {
this.accountRepository = accountRepository;
}
@Override @Override
public Integer add(Account account) { public Integer add(Account account) {
account.setAccountStatus(AccountStatus.EXPOSED); account.setAccountStatus(AccountStatus.EXPOSED);

View File

@ -1,10 +1,10 @@
package org.sadtech.social.core.service.impl; 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.domain.content.BoardComment;
import org.sadtech.social.core.repository.ContentRepository; import org.sadtech.social.core.repository.ContentRepository;
import org.sadtech.social.core.service.BoardCommentService; import org.sadtech.social.core.service.BoardCommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,16 +12,12 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@Slf4j
@RequiredArgsConstructor
public class BoardCommentServiceImpl implements BoardCommentService { public class BoardCommentServiceImpl implements BoardCommentService {
private static final Logger log = LoggerFactory.getLogger(BoardCommentServiceImpl.class);
private final ContentRepository<BoardComment> commentRepository; private final ContentRepository<BoardComment> commentRepository;
public BoardCommentServiceImpl(ContentRepository<BoardComment> commentRepository) {
this.commentRepository = commentRepository;
}
@Override @Override
public void add(BoardComment event) { public void add(BoardComment event) {
commentRepository.add(event); commentRepository.add(event);

View File

@ -1,10 +1,10 @@
package org.sadtech.social.core.service.impl; 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.domain.content.Mail;
import org.sadtech.social.core.repository.ContentRepository; import org.sadtech.social.core.repository.ContentRepository;
import org.sadtech.social.core.service.MailService; import org.sadtech.social.core.service.MailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
@ -12,16 +12,12 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@Slf4j
@RequiredArgsConstructor
public class MailServiceImpl implements MailService { public class MailServiceImpl implements MailService {
private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class);
private final ContentRepository<Mail> mailRepository; private final ContentRepository<Mail> mailRepository;
public MailServiceImpl(ContentRepository<Mail> mailRepository) {
this.mailRepository = mailRepository;
}
@Override @Override
public void add(Mail mail) { public void add(Mail mail) {
mailRepository.add(mail); mailRepository.add(mail);

View File

@ -1,23 +1,19 @@
package org.sadtech.social.core.service.impl; package org.sadtech.social.core.service.impl;
import com.google.gson.JsonObject; 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.repository.EventRepository;
import org.sadtech.social.core.service.RawEventService; import org.sadtech.social.core.service.RawEventService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Queue; import java.util.Queue;
@Slf4j
@RequiredArgsConstructor
public class RawEventServiceImpl implements RawEventService { public class RawEventServiceImpl implements RawEventService {
private static final Logger log = LoggerFactory.getLogger(RawEventServiceImpl.class);
private final EventRepository<JsonObject> eventRepository; private final EventRepository<JsonObject> eventRepository;
public RawEventServiceImpl(EventRepository<JsonObject> eventRepository) {
this.eventRepository = eventRepository;
}
@Override @Override
public void cleanAll() { public void cleanAll() {
eventRepository.cleanAll(); eventRepository.cleanAll();

View File

@ -1,7 +1,10 @@
package org.sadtech.social.core.service.sender.email; package org.sadtech.social.core.service.sender.email;
import lombok.Getter;
import java.util.Properties; import java.util.Properties;
@Getter
public class EmailConfig { public class EmailConfig {
private Properties props = new Properties(); 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() { public static Builder builder() {
return new EmailConfig().new Builder(); return new EmailConfig().new Builder();
} }

View File

@ -1,10 +1,10 @@
package org.sadtech.social.core.service.sender.email; 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.domain.BoxAnswer;
import org.sadtech.social.core.exception.MailSendException; import org.sadtech.social.core.exception.MailSendException;
import org.sadtech.social.core.service.sender.Sent; import org.sadtech.social.core.service.sender.Sent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.mail.Authenticator; import javax.mail.Authenticator;
import javax.mail.Message; import javax.mail.Message;
@ -15,16 +15,12 @@ import javax.mail.Transport;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
@Slf4j
@RequiredArgsConstructor
public class EmailSent implements Sent { public class EmailSent implements Sent {
private static final Logger log = LoggerFactory.getLogger(Sent.class);
private final EmailConfig emailConfig; private final EmailConfig emailConfig;
public EmailSent(EmailConfig emailConfig) {
this.emailConfig = emailConfig;
}
@Override @Override
public void send(Integer personId, BoxAnswer boxAnswer) { public void send(Integer personId, BoxAnswer boxAnswer) {
Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() { Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() {