Рефакторинг сущностей с payload
This commit is contained in:
parent
8aae8d5403
commit
3344b92dea
@ -1,5 +1,6 @@
|
||||
package dev.struchkov.godfather.main.domain.content;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@ -15,6 +16,7 @@ import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class Mail extends Message {
|
||||
|
||||
public static final String TYPE = "MAIL";
|
||||
@ -43,26 +45,6 @@ public class Mail extends Message {
|
||||
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) {
|
||||
this.attachments.add(attachment);
|
||||
}
|
||||
@ -71,12 +53,4 @@ public class Mail extends Message {
|
||||
this.attachments.addAll(attachments);
|
||||
}
|
||||
|
||||
public List<Mail> getForwardMail() {
|
||||
return forwardMail;
|
||||
}
|
||||
|
||||
public void setForwardMail(List<Mail> forwardMail) {
|
||||
this.forwardMail = forwardMail;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public abstract class Message implements DeliverableText {
|
||||
*/
|
||||
protected String text;
|
||||
|
||||
protected Map<ContextKey, Object> payload = new HashMap<>();
|
||||
protected Map<String, Object> payload = new HashMap<>();
|
||||
|
||||
protected Message(Message source) {
|
||||
this.id = source.getId();
|
||||
@ -58,18 +58,14 @@ public abstract class Message implements DeliverableText {
|
||||
protected Message() {
|
||||
}
|
||||
|
||||
public Map<ContextKey, Object> getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public <T> void setPayload(ContextKey<T> key, T value) {
|
||||
public <T> void addPayload(ContextKey<T> key, T value) {
|
||||
if (checkNotNull(value)) {
|
||||
payload.put(key, value);
|
||||
payload.put(key.getValue(), value);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class BoxAnswer {
|
||||
/**
|
||||
* Полезная нагрузка для реализаций.
|
||||
*/
|
||||
protected Map<ContextKey, Object> payload;
|
||||
protected Map<String, Object> payload;
|
||||
|
||||
private BoxAnswer(Builder builder) {
|
||||
message = builder.message;
|
||||
@ -112,19 +112,22 @@ public class BoxAnswer {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<ContextKey, Object> getPayload() {
|
||||
public Map<String, Object> getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public <T> void setPayload(ContextKey<T> key, T value) {
|
||||
if (checkNotNull(value)) {
|
||||
payload.put(key, value);
|
||||
payload.put(key.getValue(), value);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> Optional<T> getPayLoad(ContextKey<T> contextKey) {
|
||||
return Optional.ofNullable(payload.get(contextKey))
|
||||
.map(value -> (T) value);
|
||||
if (checkNotNull(payload)) {
|
||||
return Optional.ofNullable(payload.get(contextKey.getValue()))
|
||||
.map(value -> (T) value);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
@ -134,7 +137,7 @@ public class BoxAnswer {
|
||||
private boolean replace;
|
||||
private String replaceMessageId;
|
||||
private String recipientPersonId;
|
||||
private Map<ContextKey, Object> payload = new HashMap<>();
|
||||
private Map<String, Object> payload = new HashMap<>();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
@ -166,7 +169,7 @@ public class BoxAnswer {
|
||||
|
||||
public <T> Builder payload(ContextKey<T> key, T value) {
|
||||
if (checkNotNull(value)) {
|
||||
payload.put(key, value);
|
||||
payload.put(key.getValue(), value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user