diff --git a/src/main/java/envoy/data/GroupMessage.java b/src/main/java/envoy/data/GroupMessage.java index a2f8488..85b61e8 100644 --- a/src/main/java/envoy/data/GroupMessage.java +++ b/src/main/java/envoy/data/GroupMessage.java @@ -1,7 +1,7 @@ package envoy.data; +import java.time.LocalDateTime; import java.util.Collections; -import java.util.Date; import java.util.Map; /** @@ -38,7 +38,8 @@ public final class GroupMessage extends Message { * {@link GroupMessage} * @since Envoy Common v0.1-beta */ - GroupMessage(long id, long senderID, long groupID, Date creationDate, String text, MessageAttachment attachment, MessageStatus status, + GroupMessage(long id, long senderID, long groupID, LocalDateTime creationDate, String text, MessageAttachment attachment, + MessageStatus status, boolean forwarded, Map memberStatuses) { super(id, senderID, groupID, creationDate, text, attachment, status, forwarded); this.memberStatuses = memberStatuses; @@ -53,10 +54,10 @@ public final class GroupMessage extends Message { setStatus(Collections.min(memberStatuses.values())); switch (getStatus()) { case RECEIVED: - setReceivedDate(new Date()); + setReceivedDate(LocalDateTime.now()); break; case READ: - setReadDate(new Date()); + setReadDate(LocalDateTime.now()); break; } } diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index e097047..afffd4b 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -20,22 +20,25 @@ public class LoginCredentials implements Serializable { private final String identifier; private final byte[] passwordHash; private final boolean registration; + private final String clientVersion; - private static final long serialVersionUID = -7395245059059523314L; + private static final long serialVersionUID = 1; /** * Creates an instance of {@link LoginCredentials} for a new {@link User}. * - * @param identifier the identifier of the user - * @param password the password of the user (will be converted to a hash) - * @param registration signifies that these credentials are used for user - * registration instead of user login + * @param identifier the identifier of the user + * @param password the password of the user (will be converted to a hash) + * @param registration signifies that these credentials are used for user + * registration instead of user login + * @param clientVersion the version of the client sending these credentials * @since Envoy Common v0.2-alpha */ - public LoginCredentials(String identifier, char[] password, boolean registration) { + public LoginCredentials(String identifier, char[] password, boolean registration, String clientVersion) { this.identifier = identifier; passwordHash = getSha256(toByteArray(password)); this.registration = registration; + this.clientVersion = clientVersion; } private byte[] getSha256(byte[] input) { @@ -84,4 +87,10 @@ public class LoginCredentials implements Serializable { * @since Envoy Common v0.2-alpha */ public boolean isRegistration() { return registration; } + + /** + * @return the version of the client sending these credentials + * @since Envoy Common v0.1-beta + */ + public String getClientVersion() { return clientVersion; } } diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index ec7faf4..4b579bc 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -1,8 +1,8 @@ package envoy.data; import java.io.Serializable; -import java.text.SimpleDateFormat; -import java.util.Date; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; /** * Represents a unique message with a unique, numeric ID. Further metadata @@ -50,14 +50,14 @@ public class Message implements Serializable { private final long id, senderID, recipientID; private final boolean forwarded; - private final Date creationDate; + private final LocalDateTime creationDate; private final String text; private final MessageAttachment attachment; - private Date receivedDate, readDate; + private LocalDateTime receivedDate, readDate; private MessageStatus status; - private static final long serialVersionUID = 0L; + private static final long serialVersionUID = 1L; /** * Initializes a {@link Message} with values for all of its properties. The use @@ -75,7 +75,8 @@ public class Message implements Serializable { * @param forwarded whether this message was forwarded * @since Envoy Common v0.2-alpha */ - Message(long id, long senderID, long recipientID, Date creationDate, String text, MessageAttachment attachment, MessageStatus status, + Message(long id, long senderID, long recipientID, LocalDateTime creationDate, String text, MessageAttachment attachment, + MessageStatus status, boolean forwarded) { this.id = id; this.senderID = senderID; @@ -111,7 +112,7 @@ public class Message implements Serializable { id, senderID, recipientID, - new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(creationDate), + DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss").format(creationDate), status, text, forwarded, @@ -140,32 +141,32 @@ public class Message implements Serializable { * @return the date at which this message was created * @since Envoy Common v0.2-alpha */ - public Date getCreationDate() { return creationDate; } + public LocalDateTime getCreationDate() { 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; } + public LocalDateTime 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; } + public void setReceivedDate(LocalDateTime 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; } + public LocalDateTime 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; } + public void setReadDate(LocalDateTime readDate) { this.readDate = readDate; } /** * @return the text content of this message diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java index 87c6bf9..934f65b 100644 --- a/src/main/java/envoy/data/MessageBuilder.java +++ b/src/main/java/envoy/data/MessageBuilder.java @@ -1,6 +1,6 @@ package envoy.data; -import java.util.Date; +import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; @@ -23,7 +23,7 @@ public class MessageBuilder { // Properties with default values private long id; - private Date creationDate; + private LocalDateTime creationDate; private String text; private MessageAttachment attachment; private Message.MessageStatus status; @@ -70,7 +70,7 @@ public class MessageBuilder { public MessageBuilder(Message msg, long recipientID, IDGenerator iDGenerator) { this(msg.getRecipientID(), recipientID, iDGenerator.next()); this.attachment = msg.getAttachment(); - this.creationDate = new Date(); + this.creationDate = LocalDateTime.now(); this.forwarded = true; this.text = msg.getText(); this.status = MessageStatus.WAITING; @@ -83,7 +83,7 @@ public class MessageBuilder { * * * - * + * * * * @@ -161,7 +161,7 @@ public class MessageBuilder { } private void supplyDefaults() { - if (creationDate == null) creationDate = new Date(); + if (creationDate == null) creationDate = LocalDateTime.now(); if (text == null) text = ""; if (status == null) status = MessageStatus.WAITING; } @@ -171,7 +171,7 @@ public class MessageBuilder { * @return this {@link MessageBuilder} * @since Envoy Common v0.2-alpha */ - public MessageBuilder setDate(Date creationDate) { + public MessageBuilder setDate(LocalDateTime creationDate) { this.creationDate = creationDate; return this; } diff --git a/src/main/java/envoy/event/GroupCreationEvent.java b/src/main/java/envoy/event/GroupCreation.java similarity index 85% rename from src/main/java/envoy/event/GroupCreationEvent.java rename to src/main/java/envoy/event/GroupCreation.java index 88c405d..b568081 100644 --- a/src/main/java/envoy/event/GroupCreationEvent.java +++ b/src/main/java/envoy/event/GroupCreation.java @@ -9,13 +9,13 @@ import envoy.data.User; * This event creates a group with the given name.
*
* Project: envoy-common
- * File: GroupCreationEvent.java
+ * File: GroupCreation.java
* Created: 25 Mar 2020
* * @author Leon Hofmeister * @since Envoy Common v0.1-beta */ -public class GroupCreationEvent extends Event { +public class GroupCreation extends Event { private final Set initialMemberIDs; @@ -28,7 +28,7 @@ public class GroupCreationEvent extends Event { * of this group) * @since Envoy Common v0.1-beta */ - public GroupCreationEvent(String value, Set initialMemberIDs) { + public GroupCreation(String value, Set initialMemberIDs) { super(value); this.initialMemberIDs = (initialMemberIDs != null) ? initialMemberIDs : new HashSet<>(); } diff --git a/src/main/java/envoy/event/GroupMessageStatusChangeEvent.java b/src/main/java/envoy/event/GroupMessageStatusChange.java similarity index 70% rename from src/main/java/envoy/event/GroupMessageStatusChangeEvent.java rename to src/main/java/envoy/event/GroupMessageStatusChange.java index b02f980..01f63ae 100644 --- a/src/main/java/envoy/event/GroupMessageStatusChangeEvent.java +++ b/src/main/java/envoy/event/GroupMessageStatusChange.java @@ -1,26 +1,26 @@ package envoy.event; -import java.util.Date; +import java.time.LocalDateTime; import envoy.data.GroupMessage; import envoy.data.Message.MessageStatus; /** * Project: envoy-common
- * File: GroupMessageStatusChangeEvent.java
+ * File: GroupMessageStatusChange.java
* Created: 18.04.2020
* * @author Maximilian Käfer * @since Envoy Common v0.1-beta */ -public class GroupMessageStatusChangeEvent extends MessageStatusChangeEvent { +public class GroupMessageStatusChange extends MessageStatusChange { private final long memberID; private static final long serialVersionUID = 0L; /** - * Initializes a {@link GroupMessageStatusChangeEvent}. + * Initializes a {@link GroupMessageStatusChange}. * * @param id the ID of the {@link GroupMessage} this event is related to * @param status the status of this specific members {@link GroupMessage} @@ -29,7 +29,7 @@ public class GroupMessageStatusChangeEvent extends MessageStatusChangeEvent { * @param memberID the ID of the group member that caused the status change * @since Envoy Common v0.1-beta */ - public GroupMessageStatusChangeEvent(long id, MessageStatus status, Date date, long memberID) { + public GroupMessageStatusChange(long id, MessageStatus status, LocalDateTime date, long memberID) { super(id, status, date); this.memberID = memberID; } @@ -41,6 +41,5 @@ public class GroupMessageStatusChangeEvent extends MessageStatusChangeEvent { public long getMemberID() { return memberID; } @Override - public String toString() { return String.format("GroupMessageStatusChangeEvent[meta=%s,memberID=%d]", super.toString(), memberID); } - + public String toString() { return String.format("GroupMessageStatusChange[meta=%s,memberID=%d]", super.toString(), memberID); } } diff --git a/src/main/java/envoy/event/GroupResizeEvent.java b/src/main/java/envoy/event/GroupResize.java similarity index 81% rename from src/main/java/envoy/event/GroupResizeEvent.java rename to src/main/java/envoy/event/GroupResize.java index 46952d5..112229b 100644 --- a/src/main/java/envoy/event/GroupResizeEvent.java +++ b/src/main/java/envoy/event/GroupResize.java @@ -11,13 +11,13 @@ import envoy.data.User; * certain {@link Group}. *
* Project: envoy-common
- * File: GroupResizeEvent.java
+ * File: GroupResize.java
* Created: 25 Mar 2020
* * @author Leon Hofmeister * @since Envoy Common v0.1-beta */ -public class GroupResizeEvent extends Event { +public class GroupResize extends Event { private final long groupID; private final ElementOperation operation; @@ -25,7 +25,7 @@ public class GroupResizeEvent extends Event { private static final long serialVersionUID = 0L; /** - * Initializes a {@link GroupResizeEvent} through a Contact where the name has + * Initializes a {@link GroupResize} through a Contact where the name has * already been set. * * @param user the {@link User} who wants to join or leave a group @@ -34,7 +34,7 @@ public class GroupResizeEvent extends Event { * add him to this group or remove him from it * @since Envoy Common v0.2-alpha */ - public GroupResizeEvent(User user, Group group, ElementOperation operation) { + public GroupResize(User user, Group group, ElementOperation operation) { super(user); if (group.getContacts().contains(user)) { if (operation.equals(ElementOperation.ADD)) throw new IllegalArgumentException( @@ -61,5 +61,5 @@ public class GroupResizeEvent extends Event { * {@inheritDoc} */ @Override - public String toString() { return String.format("GroupResizeEvent[userid=%d,groupid=%d,operation=%s]", get(), groupID, operation); } + public String toString() { return String.format("GroupResize[userid=%d,groupid=%d,operation=%s]", get(), groupID, operation); } } diff --git a/src/main/java/envoy/event/HandshakeRejection.java b/src/main/java/envoy/event/HandshakeRejection.java new file mode 100644 index 0000000..3eeb1d9 --- /dev/null +++ b/src/main/java/envoy/event/HandshakeRejection.java @@ -0,0 +1,63 @@ +package envoy.event; + +/** + * Signifies to the client that the handshake failed for the attached + * reason. + *

+ * Project: envoy-common
+ * File: HandshakeRejection.java
+ * Created: 28 Jan 2020
+ * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.3-alpha + */ +public class HandshakeRejection extends Event { + + /** + * Select this value if a given password hash or user name was incorrect. + * + * @since Envoy Common v0.3-alpha + */ + public static final String WRONG_PASSWORD_OR_USER = "Incorrect user name or password."; + + /** + * Select this value if a given user name for a registration is already taken. + * + * @since Envoy Common v0.1-beta + */ + public static final String USERNAME_TAKEN = "Incorrect user name or password."; + + /** + * Select this value if the version of the client is incompatible with the + * server. + * + * @since Envoy Common v0.1-beta + */ + public static final String WRONG_VERSION = "Incompatible client version"; + + /** + * Select this value if the handshake could not be completed for some different + * reason. + * + * @since Envoy Common v0.3-alpha + */ + public static final String INTERNAL_ERROR = "An internal error occured."; + + private static final long serialVersionUID = 0L; + + /** + * Creates an instance of {@link HandshakeRejection} with the generic + * {@link HandshakeRejection#INTERNAL_ERROR} reason. + * + * @since Envoy Common v0.3-alpha + */ + public HandshakeRejection() { super(INTERNAL_ERROR); } + + /** + * Creates an instance of {@link HandshakeRejection}. + * + * @param reason the reason why the handshake was rejected + * @since Envoy Common v0.3-alpha + */ + public HandshakeRejection(String reason) { super(reason); } +} diff --git a/src/main/java/envoy/event/HandshakeRejectionEvent.java b/src/main/java/envoy/event/HandshakeRejectionEvent.java deleted file mode 100644 index fea1058..0000000 --- a/src/main/java/envoy/event/HandshakeRejectionEvent.java +++ /dev/null @@ -1,42 +0,0 @@ -package envoy.event; - -/** - * Signifies to the client that the handshake failed for the attached - * reason.
- *
- * Project: envoy-common
- * File: HandshakeRejectionEvent.java
- * Created: 28 Jan 2020
- * - * @author Kai S. K. Engelbart - * @since Envoy Common v0.3-alpha - */ -public class HandshakeRejectionEvent extends Event { - - /** - * Select this value if a given password hash or user was incorrect. - */ - public static final String WRONG_PASSWORD_OR_USER = "Incorrect user name or password."; - - /** - * Select this value if the handshake could not be completed for some reason. - */ - public static final String INTERNAL_ERROR = "An internal error occured."; - - private static final long serialVersionUID = 0L; - - /** - * Creates an instance of {@link HandshakeRejectionEvent} with an empty reason. - * - * @since Envoy Common v0.3-alpha - */ - public HandshakeRejectionEvent() { super(""); } - - /** - * Creates an instance of {@link HandshakeRejectionEvent}. - * - * @param reason the reason why the handshake was rejected - * @since Envoy Common v0.3-alpha - */ - public HandshakeRejectionEvent(String reason) { super(reason); } -} diff --git a/src/main/java/envoy/event/MessageStatusChangeEvent.java b/src/main/java/envoy/event/MessageStatusChange.java similarity index 63% rename from src/main/java/envoy/event/MessageStatusChangeEvent.java rename to src/main/java/envoy/event/MessageStatusChange.java index 2068c7f..01e5c70 100644 --- a/src/main/java/envoy/event/MessageStatusChangeEvent.java +++ b/src/main/java/envoy/event/MessageStatusChange.java @@ -1,26 +1,26 @@ package envoy.event; -import java.util.Date; +import java.time.LocalDateTime; import envoy.data.Message; /** * Project: envoy-common
- * File: MessageStatusChangeEvent.java
+ * File: MessageStatusChange.java
* Created: 6 Jan 2020
* * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ -public class MessageStatusChangeEvent extends Event { +public class MessageStatusChange extends Event { private final long id; - private final Date date; + private final LocalDateTime date; private static final long serialVersionUID = 0L; /** - * Initializes a {@link MessageStatusChangeEvent}. + * Initializes a {@link MessageStatusChange}. * * @param id the ID of the {@link Message} this event is related to * @param status the status of the {@link Message} this event is related @@ -28,19 +28,19 @@ public class MessageStatusChangeEvent extends Event { * @param date the date at which the MessageStatus change occurred * @since Envoy Common v0.2-alpha */ - public MessageStatusChangeEvent(long id, Message.MessageStatus status, Date date) { + public MessageStatusChange(long id, Message.MessageStatus status, LocalDateTime date) { super(status); this.id = id; this.date = date; } /** - * Initializes a {@link MessageStatusChangeEvent} through a message. + * Initializes a {@link MessageStatusChange} through a message. * * @param message the message from which to build the event * @since Envoy Common v0.2-alpha */ - public MessageStatusChangeEvent(Message message) { this(message.getID(), message.getStatus(), new Date()); } + public MessageStatusChange(Message message) { this(message.getID(), message.getStatus(), LocalDateTime.now()); } /** * @return the ID of the {@link Message} this event is related to @@ -52,8 +52,8 @@ public class MessageStatusChangeEvent extends Event { * @return the date at which the status change occurred * @since Envoy Common v0.2-alpha */ - public Date getDate() { return date; } + public LocalDateTime getDate() { return date; } @Override - public String toString() { return String.format("MessageStatusChangeEvent[id=%d,status=%s,date=%s]", id, value, date); } + public String toString() { return String.format("MessageStatusChange[id=%d,status=%s,date=%s]", id, value, date); } } diff --git a/src/main/java/envoy/event/NameChangeEvent.java b/src/main/java/envoy/event/NameChange.java similarity index 65% rename from src/main/java/envoy/event/NameChangeEvent.java rename to src/main/java/envoy/event/NameChange.java index bced039..ac3ae80 100644 --- a/src/main/java/envoy/event/NameChangeEvent.java +++ b/src/main/java/envoy/event/NameChange.java @@ -8,38 +8,38 @@ import envoy.data.Contact; * b) another user of this users name change. * * Project: envoy-common
- * File: NameChangeEvent.java
+ * File: NameChange.java
* Created: 25 Mar 2020
* * @author Leon Hofmeister * @since Envoy Common v0.1-beta */ -public class NameChangeEvent extends Event { +public class NameChange extends Event { private final long id; private static final long serialVersionUID = 0L; /** - * Creates a new {@link NameChangeEvent} for a user or a group. + * Creates a new {@link NameChange} for a user or a group. * * @param contactID the id of the {@link Contact} who wishes to change his name * @param newName the new name of this contact * @since Envoy Common v0.1-beta */ - public NameChangeEvent(long contactID, String newName) { + public NameChange(long contactID, String newName) { super(newName); id = contactID; } /** - * Initializes a {@link NameChangeEvent} through a Contact where the name has + * Initializes a {@link NameChange} through a Contact where the name has * already been set. * * @param contact the contact whose name was updated * @since Envoy Common v0.2-alpha */ - public NameChangeEvent(Contact contact) { this(contact.getID(), contact.getName()); } + public NameChange(Contact contact) { this(contact.getID(), contact.getName()); } /** * @return the ID of the {@link Contact} this event is related to @@ -48,5 +48,5 @@ public class NameChangeEvent extends Event { public long getID() { return id; } @Override - public String toString() { return String.format("NameChangeEvent[id=%d,name=%s]", id, value); } + public String toString() { return String.format("NameChange[id=%d,name=%s]", id, value); } } diff --git a/src/main/java/envoy/event/UserStatusChangeEvent.java b/src/main/java/envoy/event/UserStatusChange.java similarity index 68% rename from src/main/java/envoy/event/UserStatusChangeEvent.java rename to src/main/java/envoy/event/UserStatusChange.java index 2a85676..ee2c79a 100644 --- a/src/main/java/envoy/event/UserStatusChangeEvent.java +++ b/src/main/java/envoy/event/UserStatusChange.java @@ -5,38 +5,38 @@ import envoy.data.User.UserStatus; /** * Project: envoy-common
- * File: UserStatusChangeEvent.java
+ * File: UserStatusChange.java
* Created: 1 Feb 2020
* * @author Leon Hofmeister * @since Envoy Common v0.2-alpha */ -public class UserStatusChangeEvent extends Event { +public class UserStatusChange extends Event { private final long id; private static final long serialVersionUID = 0L; /** - * Initializes a {@link UserStatusChangeEvent}. + * Initializes a {@link UserStatusChange}. * * @param id the ID of the {@link User} this event is related to * @param status the status of the {@link User} this event is related * to * @since Envoy Common v0.2-alpha */ - public UserStatusChangeEvent(long id, User.UserStatus status) { + public UserStatusChange(long id, User.UserStatus status) { super(status); this.id = id; } /** - * Initializes a {@link UserStatusChangeEvent} through a User. + * Initializes a {@link UserStatusChange} through a User. * * @param user the User from which to build the event * @since Envoy Common v0.2-alpha */ - public UserStatusChangeEvent(User user) { this(user.getID(), user.getStatus()); } + public UserStatusChange(User user) { this(user.getID(), user.getStatus()); } /** * @return the ID of the {@link User} this event is related to @@ -45,5 +45,5 @@ public class UserStatusChangeEvent extends Event { public long getID() { return id; } @Override - public String toString() { return String.format("UserStatusChangeEvent[id=%d,status=%s]", id, value); } + public String toString() { return String.format("UserStatusChange[id=%d,status=%s]", id, value); } } diff --git a/src/main/java/envoy/event/contact/ContactOperationEvent.java b/src/main/java/envoy/event/contact/ContactOperation.java similarity index 77% rename from src/main/java/envoy/event/contact/ContactOperationEvent.java rename to src/main/java/envoy/event/contact/ContactOperation.java index 6758858..7b84915 100644 --- a/src/main/java/envoy/event/contact/ContactOperationEvent.java +++ b/src/main/java/envoy/event/contact/ContactOperation.java @@ -8,26 +8,26 @@ import envoy.event.Event; * Signifies the modification of a contact list.
*
* Project: envoy-common
- * File: ContactOperationEvent.java
+ * File: ContactOperation.java
* Created: 05.02.2020
* * @author Maximilian Käfer * @since Envoy Common v0.2-alpha */ -public class ContactOperationEvent extends Event { +public class ContactOperation extends Event { private final ElementOperation operationType; private static final long serialVersionUID = 1L; /** - * Initializes a {@link ContactOperationEvent}. + * Initializes a {@link ContactOperation}. * * @param contact the user on which the operation is performed * @param operationType the type of operation to perform * @since Envoy Common v0.2-alpha */ - public ContactOperationEvent(Contact contact, ElementOperation operationType) { + public ContactOperation(Contact contact, ElementOperation operationType) { super(contact); this.operationType = operationType; }

{@code date}{@code new Date()}{@code LocalDateTime.now()}
{@code text}