Рефакторинг сущностей с payload

This commit is contained in:
Struchkov Mark 2023-03-20 17:09:27 +03:00
parent 8aae8d5403
commit 3344b92dea
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
3 changed files with 16 additions and 43 deletions

View File

@ -1,5 +1,6 @@
package dev.struchkov.godfather.main.domain.content; package dev.struchkov.godfather.main.domain.content;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -15,6 +16,7 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Mail extends Message { public class Mail extends Message {
public static final String TYPE = "MAIL"; public static final String TYPE = "MAIL";
@ -43,26 +45,6 @@ public class Mail extends Message {
contentType = ContentType.MAIL; contentType = ContentType.MAIL;
} }
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public List<Attachment> getAttachments() {
return attachments;
}
public void addAttachment(Attachment attachment) { public void addAttachment(Attachment attachment) {
this.attachments.add(attachment); this.attachments.add(attachment);
} }
@ -71,12 +53,4 @@ public class Mail extends Message {
this.attachments.addAll(attachments); this.attachments.addAll(attachments);
} }
public List<Mail> getForwardMail() {
return forwardMail;
}
public void setForwardMail(List<Mail> forwardMail) {
this.forwardMail = forwardMail;
}
} }

View File

@ -44,7 +44,7 @@ public abstract class Message implements DeliverableText {
*/ */
protected String text; protected String text;
protected Map<ContextKey, Object> payload = new HashMap<>(); protected Map<String, Object> payload = new HashMap<>();
protected Message(Message source) { protected Message(Message source) {
this.id = source.getId(); this.id = source.getId();
@ -58,18 +58,14 @@ public abstract class Message implements DeliverableText {
protected Message() { protected Message() {
} }
public Map<ContextKey, Object> getPayload() { public <T> void addPayload(ContextKey<T> key, T value) {
return payload;
}
public <T> void setPayload(ContextKey<T> key, T value) {
if (checkNotNull(value)) { if (checkNotNull(value)) {
payload.put(key, value); payload.put(key.getValue(), value);
} }
} }
public <T> Optional<T> getPayLoad(ContextKey<T> contextKey) { public <T> Optional<T> getPayLoad(ContextKey<T> contextKey) {
return Optional.ofNullable(payload.get(contextKey)) return Optional.ofNullable(payload.get(contextKey.getValue()))
.map(value -> (T) value); .map(value -> (T) value);
} }

View File

@ -51,7 +51,7 @@ public class BoxAnswer {
/** /**
* Полезная нагрузка для реализаций. * Полезная нагрузка для реализаций.
*/ */
protected Map<ContextKey, Object> payload; protected Map<String, Object> payload;
private BoxAnswer(Builder builder) { private BoxAnswer(Builder builder) {
message = builder.message; message = builder.message;
@ -112,20 +112,23 @@ public class BoxAnswer {
} }
} }
public Map<ContextKey, Object> getPayload() { public Map<String, Object> getPayload() {
return payload; return payload;
} }
public <T> void setPayload(ContextKey<T> key, T value) { public <T> void setPayload(ContextKey<T> key, T value) {
if (checkNotNull(value)) { if (checkNotNull(value)) {
payload.put(key, value); payload.put(key.getValue(), value);
} }
} }
public <T> Optional<T> getPayLoad(ContextKey<T> contextKey) { public <T> Optional<T> getPayLoad(ContextKey<T> contextKey) {
return Optional.ofNullable(payload.get(contextKey)) if (checkNotNull(payload)) {
return Optional.ofNullable(payload.get(contextKey.getValue()))
.map(value -> (T) value); .map(value -> (T) value);
} }
return Optional.empty();
}
public static final class Builder { public static final class Builder {
@ -134,7 +137,7 @@ public class BoxAnswer {
private boolean replace; private boolean replace;
private String replaceMessageId; private String replaceMessageId;
private String recipientPersonId; private String recipientPersonId;
private Map<ContextKey, Object> payload = new HashMap<>(); private Map<String, Object> payload = new HashMap<>();
private Builder() { private Builder() {
} }
@ -166,7 +169,7 @@ public class BoxAnswer {
public <T> Builder payload(ContextKey<T> key, T value) { public <T> Builder payload(ContextKey<T> key, T value) {
if (checkNotNull(value)) { if (checkNotNull(value)) {
payload.put(key, value); payload.put(key.getValue(), value);
} }
return this; return this;
} }