From 891d6e3c43c624d2625347292ee527160b42fafd Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 2 Jan 2020 18:50:04 +0200 Subject: [PATCH] Reverted some changes related to ORM --- src/main/java/envoy/data/Contacts.java | 28 ++-- src/main/java/envoy/data/Message.java | 165 ++++++------------- src/main/java/envoy/data/MessageBuilder.java | 16 +- src/main/java/envoy/data/User.java | 43 +---- 4 files changed, 80 insertions(+), 172 deletions(-) diff --git a/src/main/java/envoy/data/Contacts.java b/src/main/java/envoy/data/Contacts.java index 5c5314c..bd19102 100644 --- a/src/main/java/envoy/data/Contacts.java +++ b/src/main/java/envoy/data/Contacts.java @@ -13,11 +13,23 @@ import java.util.List; */ public class Contacts implements Serializable { - private long userId; - private List contacts; + private final long userId; + private final List contacts; private static final long serialVersionUID = 136970804968152871L; + /** + * Creates an instance of {@link Contacts}. + * + * @param userId the ID of the user this contacts belong to + * @param contacts the contact list + * @since Envoy Common v0.2-alpha + */ + public Contacts(long userId, List contacts) { + this.userId = userId; + this.contacts = contacts; + } + @Override public String toString() { return String.format("Contacts[%s]", contacts); } @@ -27,21 +39,9 @@ public class Contacts implements Serializable { */ public long getUserId() { return userId; } - /** - * @param userId the ID of the user this contacts belong to - * @since Envoy Common v0.2-alpha - */ - public void setUserId(long userId) { this.userId = userId; } - /** * @return a list of users messages can be sent to * @since Envoy Common v0.2-alpha */ public List getContacts() { return contacts; } - - /** - * @param contacts the contact list to set - * @since Envoy Common v0.2-alpha - */ - public void setContacts(List contacts) { this.contacts = contacts; } } diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index 5ec1c03..ff0414c 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -48,13 +48,13 @@ public class Message implements Serializable { READ } - private long id, senderId, recipientId; - private transient User sender, recipient; - private Date date; - private String text; - private MessageAttachment attachment; + private final long id, senderId, recipientId; + private final Date creationDate; + private final String text; + private final MessageAttachment attachment; - private MessageStatus status; + private Date receivedDate, readDate; + private MessageStatus status; private static final long serialVersionUID = -4393477412979594435L; @@ -64,26 +64,24 @@ public class Message implements Serializable { * this class provides {@code null} checks and default values for all * properties. * - * @param id unique ID - * @param sender the user who sends the message - * @param recipient the user who receives the message - * @param date the creation date of the message - * @param text the text content of the message - * @param attachment the attachment of the message, if present - * @param status the current {@link MessageStatus} of the message + * @param id unique ID + * @param senderId the ID of the user who sends the message + * @param recipientId the ID of the user who receives the message + * @param date the creation date of the message + * @param text the text content of the message + * @param attachment the attachment of the message, if present + * @param status the current {@link MessageStatus} of the message * @since Envoy Common v0.2-alpha */ - Message(long id, User sender, User recipient, Date date, String text, MessageAttachment attachment, MessageStatus status) { - this.id = id; - this.sender = sender; - this.recipient = recipient; - this.date = date; - this.text = text; - this.attachment = attachment; - this.status = status; + Message(long id, long senderId, long recipientId, Date date, String text, MessageAttachment attachment, MessageStatus status) { + this.id = id; + this.senderId = senderId; + this.recipientId = recipientId; + this.creationDate = date; + this.text = text; + this.attachment = attachment; + this.status = status; - senderId = sender.getId(); - recipientId = recipient.getId(); } /** @@ -106,13 +104,14 @@ public class Message implements Serializable { @Override public String toString() { - return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,text=%s]", + return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,text=%s,hasAttachment=%b]", id, - sender, - recipient, - new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(date), + senderId, + recipientId, + new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(creationDate), status, - text); + text, + attachment != null); } /** @@ -121,24 +120,12 @@ public class Message implements Serializable { */ public long getId() { return id; } - /** - * @return the sender of this message - * @since Envoy Common v0.2-alpha - */ - public User getSender() { return sender; } - /** * @return the sender ID of this message * @since Envoy Common v0.2-alpha */ public long getSenderId() { return senderId; } - /** - * @return the recipient of this message - * @since Envoy Common v0.2-alpha - */ - public User getRecipient() { return recipient; } - /** * @return the recipient ID of this message * @since Envoy Common v0.2-alpha @@ -149,7 +136,33 @@ public class Message implements Serializable { * @return the date at which this message was created * @since Envoy Common v0.2-alpha */ - public Date getDate() { return date; } + public Date getDate() { return creationDate; } + + /** + * @return the date at which the message has been received by the sender + * @since Envoy Common v0.2-alpha + */ + public Date getReceivedDate() { return receivedDate; } + + /** + * + * @param receivedDate the date at which the message has been received by the + * sender + * @since Envoy Common v0.2-alpha + */ + public void setReceivedDate(Date receivedDate) { this.receivedDate = receivedDate; } + + /** + * @return the date at which the message has been read by the sender + * @since Envoy Common v0.2-alpha + */ + public Date getReadDate() { return readDate; } + + /** + * @param readDate at which the message has been read by the sender + * @since Envoy Common v0.2-alpha + */ + public void setReadDate(Date readDate) { this.readDate = readDate; } /** * @return the text content of this message @@ -168,74 +181,4 @@ public class Message implements Serializable { * @since Envoy Common v0.2-alpha */ public MessageStatus getStatus() { return status; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param id the id to set - * @since Envoy Common v0.2-alpha - */ - public void setId(long id) { this.id = id; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param senderId the senderId to set - * @since Envoy Common v0.2-alpha - */ - public void setSenderId(long senderId) { this.senderId = senderId; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param recipientId the recipientId to set - * @since Envoy Common v0.2-alpha - */ - public void setRecipientId(long recipientId) { this.recipientId = recipientId; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param sender the sender to set - * @since Envoy Common v0.2-alpha - */ - public void setSender(User sender) { this.sender = sender; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param recipient the recipient to set - * @since Envoy Common v0.2-alpha - */ - public void setRecipient(User recipient) { this.recipient = recipient; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param date the date to set - * @since Envoy Common v0.2-alpha - */ - public void setDate(Date date) { this.date = date; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param text the text to set - * @since Envoy Common v0.2-alpha - */ - public void setText(String text) { this.text = text; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param attachment the attachment to set - * @since Envoy Common v0.2-alpha - */ - public void setAttachment(MessageAttachment attachment) { this.attachment = attachment; } - - /** - * @param status the status to set - * @since Envoy Common v0.2-alpha - */ - public void setStatus(MessageStatus status) { this.status = status; } } \ No newline at end of file diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java index 4217663..43e929e 100644 --- a/src/main/java/envoy/data/MessageBuilder.java +++ b/src/main/java/envoy/data/MessageBuilder.java @@ -17,7 +17,7 @@ import envoy.data.Message.MessageStatus; public class MessageBuilder { // Mandatory properties without default values - private final User sender, recipient; + private final long senderId, recipientId; // Properties with default values private long id; @@ -30,15 +30,13 @@ public class MessageBuilder { * Creates an instance of {@link MessageBuilder} with all mandatory values * without defaults for the {@link Message} class. * - * @param sender the user who sends the {@link Message} - * @param recipient the user who received the {@link Message} + * @param senderId the ID of the user who sends the {@link Message} + * @param recipientId the ID of the user who received the {@link Message} * @since Envoy Common v0.2-alpha */ - public MessageBuilder(User sender, User recipient) { - if (sender == null) throw new NullPointerException("Message sender is null"); - if (recipient == null) throw new NullPointerException("Message recipient is null"); - this.sender = sender; - this.recipient = recipient; + public MessageBuilder(long senderId, long recipientId) { + this.senderId = senderId; + this.recipientId = recipientId; } /** @@ -69,7 +67,7 @@ public class MessageBuilder { if (text == null) text = ""; if (status == null) status = MessageStatus.WAITING; - return new Message(id, sender, recipient, date, text, attachment, status); + return new Message(id, senderId, recipientId, date, text, attachment, status); } /** diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java index 2049e75..dc33851 100644 --- a/src/main/java/envoy/data/User.java +++ b/src/main/java/envoy/data/User.java @@ -1,7 +1,6 @@ package envoy.data; import java.io.Serializable; -import java.util.Date; /** * Represents a unique user with a unique, numeric ID, a name and a current @@ -45,10 +44,10 @@ public class User implements Serializable { OFFLINE; } - private long id; - private String name; - private UserStatus status; - private Date lastOnline; + private final long id; + private final String name; + + private UserStatus status; private static final long serialVersionUID = 3530947374856708236L; @@ -64,16 +63,8 @@ public class User implements Serializable { this.id = id; this.name = name; status = UserStatus.ONLINE; - setLastOnline(new Date()); } - /** - * Used to let Hibernate modify the values of an {@link User} - * - * @since Envoy Common v0.2-alpha - */ - public User() {} - @Override public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } @@ -96,32 +87,8 @@ public class User implements Serializable { public UserStatus getStatus() { return status; } /** - * @param status the status to set + * @param status the next status of this user * @since Envoy Common v0.2-alpha */ public void setStatus(UserStatus status) { this.status = status; } - - /** - * @param id the id to set - * @since Envoy Common v0.2-alpha - */ - public void setId(long id) { this.id = id; } - - /** - * @param name the name to set - * @since Envoy Common v0.2-alpha - */ - public void setName(String name) { this.name = name; } - - /** - * @return the lastOnline - * @since Envoy Common v0.2-alpha - */ - public Date getLastOnline() { return lastOnline; } - - /** - * @param lastOnline the lastOnline to set - * @since Envoy Common v0.2-alpha - */ - public void setLastOnline(Date lastOnline) { this.lastOnline = lastOnline; } } \ No newline at end of file