Работа над отправкой ответов пользователю
* Переименования интерфейсов и методов Рефракторинг дженериков
This commit is contained in:
parent
b4835d1c78
commit
a9f329271b
@ -1,6 +1,7 @@
|
||||
package org.sadtech.social.core.domain.content;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.sadtech.social.core.utils.Description;
|
||||
|
||||
/**
|
||||
@ -8,6 +9,7 @@ import org.sadtech.social.core.utils.Description;
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public abstract class Comment extends Message {
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
package org.sadtech.social.core.service.sender;
|
||||
|
||||
import org.sadtech.social.core.domain.BoxAnswer;
|
||||
import org.sadtech.social.core.domain.content.Comment;
|
||||
import org.sadtech.social.core.domain.content.Message;
|
||||
|
||||
public class SendBox {
|
||||
|
||||
private SendBox() {
|
||||
throw new IllegalStateException("Утилитный класс");
|
||||
}
|
||||
|
||||
public static void sent(Message message, BoxAnswer boxAnswer, Sent sent) {
|
||||
switch (message.getType()) {
|
||||
case BOARD_COMMENT:
|
||||
sent.send(((Comment) message).getContentId(), message.getPersonId(), boxAnswer);
|
||||
break;
|
||||
case MAIL:
|
||||
sent.send(message.getPersonId(), boxAnswer);
|
||||
break;
|
||||
default:
|
||||
sent.send(message.getPersonId(), boxAnswer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.sadtech.social.core.service.sender;
|
||||
|
||||
/**
|
||||
* Тип объекта отправляющего ответы пользователю.
|
||||
*
|
||||
* @author upagge [17/08/2019]
|
||||
*/
|
||||
public enum SendType {
|
||||
|
||||
PRIVATE,
|
||||
PUBLIC
|
||||
|
||||
}
|
@ -7,7 +7,7 @@ import org.sadtech.social.core.domain.BoxAnswer;
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
public interface Sent {
|
||||
public interface Sending {
|
||||
|
||||
/**
|
||||
* Отрпавляет ответ пользователю
|
||||
@ -19,4 +19,10 @@ public interface Sent {
|
||||
|
||||
void send(Integer contentId, Integer personId, BoxAnswer boxAnswer);
|
||||
|
||||
/**
|
||||
* Возвращает тип объекта отправляющего ответ пользователя. В зависимости от типа ответ будет отправлен с помощью
|
||||
* разных методов.
|
||||
*/
|
||||
SendType getType();
|
||||
|
||||
}
|
@ -4,7 +4,8 @@ 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.sadtech.social.core.service.sender.SendType;
|
||||
import org.sadtech.social.core.service.sender.Sending;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.Message;
|
||||
@ -17,7 +18,7 @@ import javax.mail.internet.MimeMessage;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class EmailSent implements Sent {
|
||||
public class EmailSending implements Sending {
|
||||
|
||||
private final EmailConfig emailConfig;
|
||||
|
||||
@ -46,4 +47,9 @@ public class EmailSent implements Sent {
|
||||
public void send(Integer contentId, Integer personId, BoxAnswer boxAnswer) {
|
||||
throw new MailSendException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendType getType() {
|
||||
return SendType.PUBLIC;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package org.sadtech.social.core.utils;
|
||||
|
||||
/**
|
||||
* Класс утилита, содержащий сообщения об ошибках, и сообщения логирования.
|
||||
*
|
||||
* @author upagge [15/08/2019]
|
||||
*/
|
||||
public class ExceptionMessages {
|
||||
|
||||
public final static String UTILITY_CLASS = "Класс утилита";
|
||||
|
||||
private ExceptionMessages() {
|
||||
throw new IllegalStateException(UTILITY_CLASS);
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.sadtech.social.core.utils.ExceptionMessages.UTILITY_CLASS;
|
||||
|
||||
/**
|
||||
* Класс для вставки слов в текстовую строку вместо подстрок - шаблонов маркеров.
|
||||
*
|
||||
@ -11,8 +13,10 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class InsertWords {
|
||||
|
||||
private static final Pattern pattern = Pattern.compile("\\{(\\d+)}");
|
||||
|
||||
private InsertWords() {
|
||||
throw new IllegalStateException("Утилитный класс");
|
||||
throw new IllegalStateException(UTILITY_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -23,7 +27,6 @@ public class InsertWords {
|
||||
* @return Модифицированная строка
|
||||
*/
|
||||
public static String insert(String text, List<String> words) {
|
||||
Pattern pattern = Pattern.compile("\\{(\\d+)}");
|
||||
Matcher m = pattern.matcher(text);
|
||||
StringBuffer result = new StringBuffer();
|
||||
while (m.find()) {
|
||||
|
@ -3,6 +3,8 @@ package org.sadtech.social.core.utils;
|
||||
import org.sadtech.social.core.domain.content.EmptyMessage;
|
||||
import org.sadtech.social.core.domain.content.Message;
|
||||
|
||||
import static org.sadtech.social.core.utils.ExceptionMessages.UTILITY_CLASS;
|
||||
|
||||
/**
|
||||
* Класс для хранения объекта заглушки для {@link Message}.
|
||||
*
|
||||
@ -11,7 +13,7 @@ import org.sadtech.social.core.domain.content.Message;
|
||||
public class MessageUtils {
|
||||
|
||||
private MessageUtils() {
|
||||
throw new IllegalStateException("Утилитный класс");
|
||||
throw new IllegalStateException(UTILITY_CLASS);
|
||||
}
|
||||
|
||||
public static final EmptyMessage EMPTY_MESSAGE = new EmptyMessage();
|
||||
|
37
src/main/java/org/sadtech/social/core/utils/Sender.java
Normal file
37
src/main/java/org/sadtech/social/core/utils/Sender.java
Normal file
@ -0,0 +1,37 @@
|
||||
package org.sadtech.social.core.utils;
|
||||
|
||||
import org.sadtech.social.core.domain.BoxAnswer;
|
||||
import org.sadtech.social.core.domain.content.Comment;
|
||||
import org.sadtech.social.core.domain.content.Message;
|
||||
import org.sadtech.social.core.service.sender.Sending;
|
||||
|
||||
import static org.sadtech.social.core.utils.ExceptionMessages.UTILITY_CLASS;
|
||||
|
||||
public class Sender {
|
||||
|
||||
private Sender() {
|
||||
throw new IllegalStateException(UTILITY_CLASS);
|
||||
}
|
||||
|
||||
public static void sends(Message message, BoxAnswer boxAnswer, Sending sending) {
|
||||
switch (sending.getType()) {
|
||||
case PUBLIC:
|
||||
publicSend(message, boxAnswer, sending);
|
||||
break;
|
||||
case PRIVATE:
|
||||
privateSend(message, boxAnswer, sending);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void publicSend(Message message, BoxAnswer boxAnswer, Sending sending) {
|
||||
if (message instanceof Comment) {
|
||||
sending.send(((Comment) message).getContentId(), message.getPersonId(), boxAnswer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void privateSend(Message message, BoxAnswer boxAnswer, Sending sending) {
|
||||
sending.send(message.getPersonId(), boxAnswer);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user