Merge pull request #29 from informatik-ag-ngl/f/attachment
Reworked Attachment
This commit is contained in:
commit
470558086e
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<wb-module deploy-name="envoy-common">
|
<wb-module deploy-name="envoy-common">
|
||||||
|
|
||||||
|
|
||||||
@ -14,6 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||||
|
|
||||||
|
|
||||||
@ -22,6 +24,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</wb-module>
|
</wb-module>
|
||||||
|
|
||||||
|
|
||||||
@ -30,4 +33,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project-modules>
|
</project-modules>
|
||||||
|
84
src/main/java/envoy/data/Attachment.java
Normal file
84
src/main/java/envoy/data/Attachment.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package envoy.data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface should be used for any type supposed to be a {@link Message}
|
||||||
|
* attachment (i.e. images or sound).
|
||||||
|
* <p>
|
||||||
|
* Project: <strong>envoy-common</strong><br>
|
||||||
|
* File: <strong>Attachment.java</strong><br>
|
||||||
|
* Created: <strong>30 Dec 2019</strong><br>
|
||||||
|
*
|
||||||
|
* @author Leon Hofmeister
|
||||||
|
* @author Kai S. K. Engelbart
|
||||||
|
* @since Envoy Common v0.2-alpha
|
||||||
|
*/
|
||||||
|
public class Attachment implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the type of the attachment.
|
||||||
|
*
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
public enum AttachmentType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This attachment type denotes a picture.
|
||||||
|
*
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
PICTURE,
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This attachment type denotes a video.
|
||||||
|
*
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
VIDEO,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This attachment type denotes a voice message.
|
||||||
|
*
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
VOICE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This attachment type denotes a document.
|
||||||
|
*
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
DOCUMENT
|
||||||
|
}
|
||||||
|
|
||||||
|
private final byte[] data;
|
||||||
|
private final AttachmentType type;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an attachment.
|
||||||
|
*
|
||||||
|
* @param data the data of the attachment
|
||||||
|
* @param type the type of the attachment
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
public Attachment(byte[] data, AttachmentType type) {
|
||||||
|
this.data = data;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the data of the attachment
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
public byte[] getData() { return data; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the type of the attachment
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
public AttachmentType getType() { return type; }
|
||||||
|
}
|
@ -29,6 +29,8 @@ public final class GroupMessage extends Message {
|
|||||||
* @param senderID the ID of the user who sends the message
|
* @param senderID the ID of the user who sends the message
|
||||||
* @param groupID the ID of the group which receives the message
|
* @param groupID the ID of the group which receives the message
|
||||||
* @param creationDate the creation date of the message
|
* @param creationDate the creation date of the message
|
||||||
|
* @param receivedDate the received date of the message
|
||||||
|
* @param readDate the read date of the message
|
||||||
* @param text the text content of the message
|
* @param text the text content of the message
|
||||||
* @param attachment the attachment of the message, if present
|
* @param attachment the attachment of the message, if present
|
||||||
* @param status the current {@link Message.MessageStatus} of the
|
* @param status the current {@link Message.MessageStatus} of the
|
||||||
@ -38,10 +40,9 @@ public final class GroupMessage extends Message {
|
|||||||
* {@link GroupMessage}
|
* {@link GroupMessage}
|
||||||
* @since Envoy Common v0.1-beta
|
* @since Envoy Common v0.1-beta
|
||||||
*/
|
*/
|
||||||
GroupMessage(long id, long senderID, long groupID, LocalDateTime creationDate, String text, MessageAttachment<?> attachment,
|
GroupMessage(long id, long senderID, long groupID, LocalDateTime creationDate, LocalDateTime receivedDate, LocalDateTime readDate, String text,
|
||||||
MessageStatus status,
|
Attachment attachment, MessageStatus status, boolean forwarded, Map<Long, MessageStatus> memberStatuses) {
|
||||||
boolean forwarded, Map<Long, MessageStatus> memberStatuses) {
|
super(id, senderID, groupID, creationDate, receivedDate, readDate, text, attachment, status, forwarded);
|
||||||
super(id, senderID, groupID, creationDate, text, attachment, status, forwarded);
|
|
||||||
this.memberStatuses = memberStatuses;
|
this.memberStatuses = memberStatuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public class Message implements Serializable {
|
|||||||
private final boolean forwarded;
|
private final boolean forwarded;
|
||||||
private final LocalDateTime creationDate;
|
private final LocalDateTime creationDate;
|
||||||
private final String text;
|
private final String text;
|
||||||
private final MessageAttachment<?> attachment;
|
private final Attachment attachment;
|
||||||
|
|
||||||
private LocalDateTime receivedDate, readDate;
|
private LocalDateTime receivedDate, readDate;
|
||||||
private MessageStatus status;
|
private MessageStatus status;
|
||||||
@ -69,19 +69,22 @@ public class Message implements Serializable {
|
|||||||
* @param senderID the ID of the user who sends the message
|
* @param senderID the ID of the user who sends the message
|
||||||
* @param recipientID the ID of the user who receives the message
|
* @param recipientID the ID of the user who receives the message
|
||||||
* @param creationDate the creation date of the message
|
* @param creationDate the creation date of the message
|
||||||
|
* @param receivedDate the received date of the message
|
||||||
|
* @param readDate the read date of the message
|
||||||
* @param text the text content of the message
|
* @param text the text content of the message
|
||||||
* @param attachment the attachment of the message, if present
|
* @param attachment the attachment of the message, if present
|
||||||
* @param status the current {@link MessageStatus} of the message
|
* @param status the current {@link MessageStatus} of the message
|
||||||
* @param forwarded whether this message was forwarded
|
* @param forwarded whether this message was forwarded
|
||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
Message(long id, long senderID, long recipientID, LocalDateTime creationDate, String text, MessageAttachment<?> attachment,
|
Message(long id, long senderID, long recipientID, LocalDateTime creationDate, LocalDateTime receivedDate, LocalDateTime readDate, String text,
|
||||||
MessageStatus status,
|
Attachment attachment, MessageStatus status, boolean forwarded) {
|
||||||
boolean forwarded) {
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.senderID = senderID;
|
this.senderID = senderID;
|
||||||
this.recipientID = recipientID;
|
this.recipientID = recipientID;
|
||||||
this.creationDate = creationDate;
|
this.creationDate = creationDate;
|
||||||
|
this.receivedDate = receivedDate;
|
||||||
|
this.readDate = readDate;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.attachment = attachment;
|
this.attachment = attachment;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -178,7 +181,13 @@ public class Message implements Serializable {
|
|||||||
* @return the messageAttachment
|
* @return the messageAttachment
|
||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public MessageAttachment<?> getAttachment() { return attachment; }
|
public Attachment getAttachment() { return attachment; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@code true} if an attachment is present
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
public boolean hasAttachment() { return attachment != null; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the current status of this message
|
* @return the current status of this message
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
package envoy.data;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
import envoy.util.SerializationUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This interface should be used for any type supposed to be a {@link Message}
|
|
||||||
* attachment (i.e. images or sound).<br>
|
|
||||||
* <br>
|
|
||||||
* Project: <strong>envoy-common</strong><br>
|
|
||||||
* File: <strong>MessageAttachment.java</strong><br>
|
|
||||||
* Created: <strong>30 Dec 2019</strong><br>
|
|
||||||
*
|
|
||||||
* @author Leon Hofmeister
|
|
||||||
* @param <T> the type of this message attachment
|
|
||||||
* @since Envoy Common v0.2-alpha
|
|
||||||
*/
|
|
||||||
public class MessageAttachment<T> implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
private T value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the type implementing this interface
|
|
||||||
* @since Envoy Common v0.2-alpha
|
|
||||||
*/
|
|
||||||
T getValue() { return value; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the {@link MessageAttachment} as a byte array
|
|
||||||
* @throws IOException if the serialization failed
|
|
||||||
* @since Envoy Common v0.2-alpha
|
|
||||||
*/
|
|
||||||
byte[] toByteArray() throws IOException { return SerializationUtils.writeToByteArray(this); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param value the value to set
|
|
||||||
* @since Envoy Common v0.2-alpha
|
|
||||||
*/
|
|
||||||
public void setValue(T value) { this.value = value; }
|
|
||||||
}
|
|
@ -23,9 +23,9 @@ public class MessageBuilder {
|
|||||||
|
|
||||||
// Properties with default values
|
// Properties with default values
|
||||||
private long id;
|
private long id;
|
||||||
private LocalDateTime creationDate;
|
private LocalDateTime creationDate, receivedDate, readDate;
|
||||||
private String text;
|
private String text;
|
||||||
private MessageAttachment<?> attachment;
|
private Attachment attachment;
|
||||||
private Message.MessageStatus status;
|
private Message.MessageStatus status;
|
||||||
private boolean forwarded;
|
private boolean forwarded;
|
||||||
|
|
||||||
@ -83,7 +83,8 @@ public class MessageBuilder {
|
|||||||
* <table border="1">
|
* <table border="1">
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>{@code date}</td>
|
* <td>{@code date}</td>
|
||||||
* <td>{@code LocalDateTime.now()}</td>
|
* <td>{@code LocalDateTime.now()} and {@code null} for {@code receivedDate} and
|
||||||
|
* {@code readDate}</td>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>{@code text}</td>
|
* <td>{@code text}</td>
|
||||||
@ -100,7 +101,7 @@ public class MessageBuilder {
|
|||||||
*/
|
*/
|
||||||
public Message build() {
|
public Message build() {
|
||||||
supplyDefaults();
|
supplyDefaults();
|
||||||
return new Message(id, senderID, recipientID, creationDate, text, attachment, status, forwarded);
|
return new Message(id, senderID, recipientID, creationDate, receivedDate, readDate, text, attachment, status, forwarded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,7 +158,7 @@ public class MessageBuilder {
|
|||||||
public GroupMessage buildGroupMessage(Group group, Map<Long, MessageStatus> memberStatuses) {
|
public GroupMessage buildGroupMessage(Group group, Map<Long, MessageStatus> memberStatuses) {
|
||||||
if (group == null || memberStatuses == null) throw new NullPointerException();
|
if (group == null || memberStatuses == null) throw new NullPointerException();
|
||||||
supplyDefaults();
|
supplyDefaults();
|
||||||
return new GroupMessage(id, senderID, recipientID, creationDate, text, attachment, status, forwarded, memberStatuses);
|
return new GroupMessage(id, senderID, recipientID, creationDate, receivedDate, readDate, text, attachment, status, forwarded, memberStatuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void supplyDefaults() {
|
private void supplyDefaults() {
|
||||||
@ -171,11 +172,31 @@ public class MessageBuilder {
|
|||||||
* @return this {@link MessageBuilder}
|
* @return this {@link MessageBuilder}
|
||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public MessageBuilder setDate(LocalDateTime creationDate) {
|
public MessageBuilder setCreationDate(LocalDateTime creationDate) {
|
||||||
this.creationDate = creationDate;
|
this.creationDate = creationDate;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param receivedDate the received date of the {@link Message} to create
|
||||||
|
* @return this {@link MessageBuilder}
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
public MessageBuilder setReceivedDate(LocalDateTime receivedDate) {
|
||||||
|
this.receivedDate = receivedDate;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param readDate the read date of the {@link Message} to create
|
||||||
|
* @return this {@link MessageBuilder}
|
||||||
|
* @since Envoy Common v0.1-beta
|
||||||
|
*/
|
||||||
|
public MessageBuilder setReadDate(LocalDateTime readDate) {
|
||||||
|
this.readDate = readDate;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param text the text of the {@link Message} to create
|
* @param text the text of the {@link Message} to create
|
||||||
* @return this {@link MessageBuilder}
|
* @return this {@link MessageBuilder}
|
||||||
@ -187,12 +208,12 @@ public class MessageBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param attachment the {@link MessageAttachment} of the {@link Message} to
|
* @param attachment the {@link Attachment} of the {@link Message} to
|
||||||
* create
|
* create
|
||||||
* @return this {@link MessageBuilder}
|
* @return this {@link MessageBuilder}
|
||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public MessageBuilder setAttachment(MessageAttachment<?> attachment) {
|
public MessageBuilder setAttachment(Attachment attachment) {
|
||||||
this.attachment = attachment;
|
this.attachment = attachment;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user