From 743aa6bc2db99bcd556271d712e72ca952b0e7f2 Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Sat, 18 Apr 2020 16:28:38 +0200
Subject: [PATCH] Implemented the GroupMessage class
---
.../java/envoy/server/data/GroupMessage.java | 221 ++++++++++++++++++
1 file changed, 221 insertions(+)
create mode 100644 src/main/java/envoy/server/data/GroupMessage.java
diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java
new file mode 100644
index 0000000..0d1e2bc
--- /dev/null
+++ b/src/main/java/envoy/server/data/GroupMessage.java
@@ -0,0 +1,221 @@
+package envoy.server.data;
+
+import java.util.Date;
+import java.util.Map;
+
+import javax.persistence.CascadeType;
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+/**
+ * Project: envoy-server-standalone
+ * File: GroupMessage.java
+ * Created: 18.04.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-beta
+ */
+
+@Entity
+@Table(name = "groupMessages")
+// @NamedQuery()
+// TODO Add Queries
+public class GroupMessage {
+
+ @Id
+ private long id;
+
+ @ManyToOne(cascade = CascadeType.PERSIST)
+ private User sender;
+
+ @ManyToOne(cascade = CascadeType.PERSIST)
+ private Group group;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date creationDate;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date receivedDate;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date readDate;
+
+ @ElementCollection
+ private Map memberMessageStatus;
+
+ private String text;
+ private envoy.data.Message.MessageStatus status;
+ private byte[] attachment;
+ private boolean forwarded;
+
+ /**
+ * The constructor for a database object.
+ *
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public GroupMessage() {}
+
+ /**
+ * Constructs a database groupMessage from a common groupMessage.
+ *
+ * @param groupMessage the {@link envoy.data.GroupMessage} to convert into a
+ * database {@link GroupMessage}
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public GroupMessage(envoy.data.GroupMessage groupMessage) {
+ PersistenceManager persistenceManager = PersistenceManager.getInstance();
+ id = groupMessage.getID();
+ status = groupMessage.getStatus();
+ text = groupMessage.getText();
+ creationDate = groupMessage.getCreationDate();
+ receivedDate = groupMessage.getReceivedDate();
+ readDate = groupMessage.getReadDate();
+ sender = persistenceManager.getUserByID(groupMessage.getSenderID());
+ group = persistenceManager.getGroupByID(groupMessage.getRecipientID());
+ forwarded = groupMessage.isForwarded();
+ memberMessageStatus = groupMessage.getMemberStatuses();
+ // TODO: attachment = groupMessage.getAttachment().toByteArray();DOES NOT WORK
+ // YET
+ }
+
+ // TODO Implement GroupMessageBuilder and add toCommonGroupMessage method here
+
+ /**
+ * @return the id
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public long getId() { return id; }
+
+ /**
+ * @param id the id to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setId(long id) { this.id = id; }
+
+ /**
+ * @return the sender
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public User getSender() { return sender; }
+
+ /**
+ * @param sender the sender to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setSender(User sender) { this.sender = sender; }
+
+ /**
+ * @return the group
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Group getGroup() { return group; }
+
+ /**
+ * @param group the group to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setGroup(Group group) { this.group = group; }
+
+ /**
+ * @return the creationDate
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Date getCreationDate() { return creationDate; }
+
+ /**
+ * @param creationDate the creationDate to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setCreationDate(Date creationDate) { this.creationDate = creationDate; }
+
+ /**
+ * @return the receivedDate
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Date getReceivedDate() { return receivedDate; }
+
+ /**
+ * @param receivedDate the receivedDate to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setReceivedDate(Date receivedDate) { this.receivedDate = receivedDate; }
+
+ /**
+ * @return the readDate
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Date getReadDate() { return readDate; }
+
+ /**
+ * @param readDate the readDate to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setReadDate(Date readDate) { this.readDate = readDate; }
+
+ /**
+ * @return the memberMessageStatus
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Map getMemberMessageStatus() { return memberMessageStatus; }
+
+ /**
+ * @param memberMessageStatus the memberMessageStatus to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setMemberMessageStatus(Map memberMessageStatus) {
+ this.memberMessageStatus = memberMessageStatus;
+ }
+
+ /**
+ * @return the text
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public String getText() { return text; }
+
+ /**
+ * @param text the text to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setText(String text) { this.text = text; }
+
+ /**
+ * @return the status
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public envoy.data.Message.MessageStatus getStatus() { return status; }
+
+ /**
+ * @param status the status to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setStatus(envoy.data.Message.MessageStatus status) { this.status = status; }
+
+ /**
+ * @return the attachment
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public byte[] getAttachment() { return attachment; }
+
+ /**
+ * @param attachment the attachment to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setAttachment(byte[] attachment) { this.attachment = attachment; }
+
+ /**
+ * @return the forwarded
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public boolean isForwarded() { return forwarded; }
+
+ /**
+ * @param forwarded the forwarded to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setForwarded(boolean forwarded) { this.forwarded = forwarded; }
+}