Изменил подход к возникающим событиям и их обработки

This commit is contained in:
Struchkov Mark 2022-07-15 17:47:40 +03:00
parent fc3f9563e2
commit 9192b7cd97
9 changed files with 40 additions and 18 deletions

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId>
<version>0.0.11</version>
<version>0.0.12</version>
</parent>
<artifactId>bot-context</artifactId>

View File

@ -10,7 +10,7 @@ import dev.struchkov.godfather.context.exception.AppBotException;
public class EmptyMessage extends Message {
public EmptyMessage() {
type = ContentType.EMPTY;
contentType = ContentType.EMPTY;
}
@Override

View File

@ -1,6 +1,7 @@
package dev.struchkov.godfather.context.domain.content;
import dev.struchkov.godfather.context.domain.content.attachment.Attachment;
import dev.struchkov.godfather.context.domain.event.Event;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -18,7 +19,9 @@ import java.util.List;
*/
@Entity
@Table(name = "mail")
public class Mail extends Message {
public class Mail extends Message implements Event {
public static final String TYPE = "MAIL";
/**
* Имя отправителя.
@ -47,7 +50,7 @@ public class Mail extends Message {
private List<Mail> forwardMail;
public Mail() {
type = ContentType.MAIL;
contentType = ContentType.MAIL;
}
public String getFirstName() {
@ -86,4 +89,9 @@ public class Mail extends Message {
this.forwardMail = forwardMail;
}
@Override
public String getType() {
return TYPE;
}
}

View File

@ -23,7 +23,7 @@ public abstract class Message extends BasicEntity {
*/
@Column(name = "type")
@Enumerated(value = EnumType.STRING)
protected ContentType type;
protected ContentType contentType;
/**
* Дата создания.
@ -56,18 +56,18 @@ public abstract class Message extends BasicEntity {
this.text = source.getText();
this.createDate = source.getCreateDate();
this.id = source.getPersonId();
this.type = source.getType();
this.contentType = source.getContentType();
}
public Message() {
}
public ContentType getType() {
return type;
public ContentType getContentType() {
return contentType;
}
public void setType(ContentType type) {
this.type = type;
public void setContentType(ContentType type) {
this.contentType = type;
}
public LocalDateTime getCreateDate() {
@ -107,12 +107,12 @@ public abstract class Message extends BasicEntity {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Message message = (Message) o;
return type == message.type && Objects.equals(createDate, message.createDate) && Objects.equals(addDate, message.addDate) && Objects.equals(personId, message.personId) && Objects.equals(text, message.text);
return contentType == message.contentType && Objects.equals(createDate, message.createDate) && Objects.equals(addDate, message.addDate) && Objects.equals(personId, message.personId) && Objects.equals(text, message.text);
}
@Override
public int hashCode() {
return Objects.hash(type, createDate, addDate, personId, text);
return Objects.hash(contentType, createDate, addDate, personId, text);
}
}

View File

@ -0,0 +1,7 @@
package dev.struchkov.godfather.context.domain.event;
public interface Event {
String getType();
}

View File

@ -1,9 +1,11 @@
package dev.struchkov.godfather.context.service;
import dev.struchkov.godfather.context.domain.content.Message;
import dev.struchkov.godfather.context.domain.event.Event;
public interface EventProvider<M extends Message> {
public interface EventProvider<T extends Event> {
void sendEvent(M message);
void sendEvent(T event);
String getEventType();
}

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId>
<version>0.0.11</version>
<version>0.0.12</version>
</parent>
<artifactId>bot-core</artifactId>

View File

@ -17,4 +17,9 @@ public class EventStoryLineProvider implements EventProvider<Mail> {
generalAutoResponder.processingNewMessage(message);
}
@Override
public String getEventType() {
return Mail.TYPE;
}
}

View File

@ -6,7 +6,7 @@
<groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId>
<version>0.0.11</version>
<version>0.0.12</version>
<packaging>pom</packaging>
<modules>
@ -32,7 +32,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<godfather.ver>0.0.11</godfather.ver>
<godfather.ver>0.0.12</godfather.ver>
<godfather.context.ver>${godfather.ver}</godfather.context.ver>
<godfather.core.ver>${godfather.ver}</godfather.core.ver>