Reverted some changes related to ORM

This commit is contained in:
Kai S. K. Engelbart 2020-01-02 18:50:04 +02:00
parent 8b4205f222
commit 3b808f4938
4 changed files with 80 additions and 172 deletions

View File

@ -13,11 +13,23 @@ import java.util.List;
*/
public class Contacts implements Serializable {
private long userId;
private List<User> contacts;
private final long userId;
private final List<User> 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<User> 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<User> getContacts() { return contacts; }
/**
* @param contacts the contact list to set
* @since Envoy Common v0.2-alpha
*/
public void setContacts(List<User> contacts) { this.contacts = contacts; }
}

View File

@ -48,12 +48,12 @@ 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 Date receivedDate, readDate;
private MessageStatus status;
private static final long serialVersionUID = -4393477412979594435L;
@ -65,25 +65,23 @@ public class Message implements Serializable {
* properties.
*
* @param id unique ID
* @param sender the user who sends the message
* @param recipient the user who receives 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 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) {
Message(long id, long senderId, long recipientId, Date date, String text, MessageAttachment<?> attachment, MessageStatus status) {
this.id = id;
this.sender = sender;
this.recipient = recipient;
this.date = date;
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; }
}

View File

@ -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);
}
/**

View File

@ -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 final long id;
private final String name;
private UserStatus status;
private Date lastOnline;
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; }
}