Prepare handshake synchronization

Common
* Replace LocalDateTime with Instant everywhere

Client
* Display message creation date with system time zone in MessageControl
* LocalDB#users now strictly contains Users
* lastSync time stamp in LocalDB (saved per user)
* isOnline parameter in save function (lastSync updated if true)
* lastSync time stamp in LoginCredentials
* No ClientConfig#getLoginCredentials because of missing information,
  moved to LoginScene
* Pass LocalDB#lastSync to LoginCredentials in LoginScene

Server
* Explicit lastSync parameter for
  PersistenceManager#getPending(Group)Messages

This sends the correct time stamp to the server, however the JPQL
queries have yet to be adjusted.
This commit is contained in:
2020-07-16 17:04:35 +02:00
parent abd0113588
commit 07c4ccf3c8
23 changed files with 189 additions and 159 deletions

View File

@ -1,6 +1,6 @@
package envoy.data;
import java.time.LocalDateTime;
import java.time.Instant;
import java.util.Collections;
import java.util.Map;
@ -16,7 +16,7 @@ public final class GroupMessage extends Message {
private final Map<Long, MessageStatus> memberStatuses;
private static final long serialVersionUID = 0L;
private static final long serialVersionUID = 1L;
/**
* Initializes a {@link GroupMessage} with values for all of its properties. The
@ -38,9 +38,9 @@ public final class GroupMessage extends Message {
* @param forwarded whether this message was forwarded
* @param memberStatuses a map of all members and their status according to this
* {@link GroupMessage}
* @since Envoy Common v0.1-beta
* @since Envoy Common v0.2-beta
*/
GroupMessage(long id, long senderID, long groupID, LocalDateTime creationDate, LocalDateTime receivedDate, LocalDateTime readDate, String text,
GroupMessage(long id, long senderID, long groupID, Instant creationDate, Instant receivedDate, Instant readDate, String text,
Attachment attachment, MessageStatus status, boolean forwarded, Map<Long, MessageStatus> memberStatuses) {
super(id, senderID, groupID, creationDate, receivedDate, readDate, text, attachment, status, forwarded);
this.memberStatuses = memberStatuses;
@ -55,10 +55,10 @@ public final class GroupMessage extends Message {
setStatus(Collections.min(memberStatuses.values()));
switch (getStatus()) {
case RECEIVED:
setReceivedDate(LocalDateTime.now());
setReceivedDate(Instant.now());
break;
case READ:
setReadDate(LocalDateTime.now());
setReadDate(Instant.now());
break;
}
}

View File

@ -1,6 +1,7 @@
package envoy.data;
import java.io.Serializable;
import java.time.Instant;
/**
* Contains a {@link User}'s login / registration information as well as the
@ -17,8 +18,9 @@ public final class LoginCredentials implements Serializable {
private final String identifier, password, clientVersion;
private final boolean registration;
private final Instant lastSync;
private static final long serialVersionUID = 2;
private static final long serialVersionUID = 3;
/**
* Initializes login credentials for a handshake.
@ -28,18 +30,24 @@ public final class LoginCredentials implements Serializable {
* @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.1-beta
* @param lastSync the time stamp of the last synchronization
* @since Envoy Common v0.2-beta
*/
public LoginCredentials(String identifier, String password, boolean registration, String clientVersion) {
public LoginCredentials(String identifier, String password, boolean registration, String clientVersion, Instant lastSync) {
this.identifier = identifier;
this.password = password;
this.registration = registration;
this.clientVersion = clientVersion;
this.lastSync = lastSync;
}
@Override
public String toString() {
return String.format("LoginCredentials[identifier=%s,registration=%b,clientVersion=%s]", identifier, registration, clientVersion);
return String.format("LoginCredentials[identifier=%s,registration=%b,clientVersion=%s,lastSync=%s]",
identifier,
registration,
clientVersion,
lastSync);
}
/**
@ -66,4 +74,10 @@ public final class LoginCredentials implements Serializable {
* @since Envoy Common v0.1-beta
*/
public String getClientVersion() { return clientVersion; }
/**
* @return the time stamp of the last synchronization
* @since Envoy Common v0.2-beta
*/
public Instant getLastSync() { return lastSync; }
}

View File

@ -1,8 +1,7 @@
package envoy.data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.Instant;
/**
* Represents a unique message with a unique, numeric ID. Further metadata
@ -50,14 +49,14 @@ public class Message implements Serializable {
private final long id, senderID, recipientID;
private final boolean forwarded;
private final LocalDateTime creationDate;
private final Instant creationDate;
private final String text;
private final Attachment attachment;
private LocalDateTime receivedDate, readDate;
private Instant receivedDate, readDate;
private MessageStatus status;
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 2L;
/**
* Initializes a {@link Message} with values for all of its properties. The use
@ -75,9 +74,9 @@ public class Message implements Serializable {
* @param attachment the attachment of the message, if present
* @param status the current {@link MessageStatus} of the message
* @param forwarded whether this message was forwarded
* @since Envoy Common v0.2-alpha
* @since Envoy Common v0.2-beta
*/
Message(long id, long senderID, long recipientID, LocalDateTime creationDate, LocalDateTime receivedDate, LocalDateTime readDate, String text,
Message(long id, long senderID, long recipientID, Instant creationDate, Instant receivedDate, Instant readDate, String text,
Attachment attachment, MessageStatus status, boolean forwarded) {
this.id = id;
this.senderID = senderID;
@ -115,7 +114,7 @@ public class Message implements Serializable {
id,
senderID,
recipientID,
DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss").format(creationDate),
creationDate,
status,
text,
forwarded,
@ -142,34 +141,34 @@ public class Message implements Serializable {
/**
* @return the date at which this message was created
* @since Envoy Common v0.2-alpha
* @since Envoy Common v0.2-beta
*/
public LocalDateTime getCreationDate() { return creationDate; }
public Instant getCreationDate() { return creationDate; }
/**
* @return the date at which the message has been received by the sender
* @since Envoy Common v0.2-alpha
* @since Envoy Common v0.2-beta
*/
public LocalDateTime getReceivedDate() { return receivedDate; }
public Instant getReceivedDate() { return receivedDate; }
/**
* @param receivedDate the date at which the message has been received by the
* sender
* @since Envoy Common v0.2-alpha
* @since Envoy Common v0.2-beta
*/
public void setReceivedDate(LocalDateTime receivedDate) { this.receivedDate = receivedDate; }
public void setReceivedDate(Instant receivedDate) { this.receivedDate = receivedDate; }
/**
* @return the date at which the message has been read by the sender
* @since Envoy Common v0.2-alpha
* @since Envoy Common v0.2-beta
*/
public LocalDateTime getReadDate() { return readDate; }
public Instant getReadDate() { return readDate; }
/**
* @param readDate at which the message has been read by the sender
* @since Envoy Common v0.2-alpha
* @since Envoy Common v0.2-beta
*/
public void setReadDate(LocalDateTime readDate) { this.readDate = readDate; }
public void setReadDate(Instant readDate) { this.readDate = readDate; }
/**
* @return the text content of this message

View File

@ -1,6 +1,6 @@
package envoy.data;
import java.time.LocalDateTime;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
@ -23,7 +23,7 @@ public class MessageBuilder {
// Properties with default values
private long id;
private LocalDateTime creationDate, receivedDate, readDate;
private Instant creationDate, receivedDate, readDate;
private String text;
private Attachment 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 = LocalDateTime.now();
this.creationDate = Instant.now();
this.forwarded = true;
this.text = msg.getText();
this.status = MessageStatus.WAITING;
@ -83,7 +83,7 @@ public class MessageBuilder {
* <table border="1">
* <tr>
* <td>{@code date}</td>
* <td>{@code LocalDateTime.now()} and {@code null} for {@code receivedDate} and
* <td>{@code Instant.now()} and {@code null} for {@code receivedDate} and
* {@code readDate}</td>
* <tr>
* <tr>
@ -113,8 +113,8 @@ public class MessageBuilder {
* <br>
* <table border="1">
* <tr>
* <td>{@code date}</td>
* <td>{@code new Date()}</td>
* <td>{@code time stamp}</td>
* <td>{@code Instant.now()}</td>
* <tr>
* <tr>
* <td>{@code text}</td>
@ -140,8 +140,8 @@ public class MessageBuilder {
* <br>
* <table border="1">
* <tr>
* <td>{@code date}</td>
* <td>{@code new Date()}</td>
* <td>{@code time stamp}</td>
* <td>{@code Instant.now()}</td>
* <tr>
* <tr>
* <td>{@code text}</td>
@ -162,7 +162,7 @@ public class MessageBuilder {
}
private void supplyDefaults() {
if (creationDate == null) creationDate = LocalDateTime.now();
if (creationDate == null) creationDate = Instant.now();
if (text == null) text = "";
if (status == null) status = MessageStatus.WAITING;
}
@ -170,9 +170,9 @@ public class MessageBuilder {
/**
* @param creationDate the creation date of the {@link Message} to create
* @return this {@link MessageBuilder}
* @since Envoy Common v0.2-alpha
* @since Envoy Common v0.2-beta
*/
public MessageBuilder setCreationDate(LocalDateTime creationDate) {
public MessageBuilder setCreationDate(Instant creationDate) {
this.creationDate = creationDate;
return this;
}
@ -180,9 +180,9 @@ public class MessageBuilder {
/**
* @param receivedDate the received date of the {@link Message} to create
* @return this {@link MessageBuilder}
* @since Envoy Common v0.1-beta
* @since Envoy Common v0.2-beta
*/
public MessageBuilder setReceivedDate(LocalDateTime receivedDate) {
public MessageBuilder setReceivedDate(Instant receivedDate) {
this.receivedDate = receivedDate;
return this;
}
@ -190,9 +190,9 @@ public class MessageBuilder {
/**
* @param readDate the read date of the {@link Message} to create
* @return this {@link MessageBuilder}
* @since Envoy Common v0.1-beta
* @since Envoy Common v0.2-beta
*/
public MessageBuilder setReadDate(LocalDateTime readDate) {
public MessageBuilder setReadDate(Instant readDate) {
this.readDate = readDate;
return this;
}

View File

@ -1,6 +1,6 @@
package envoy.event;
import java.time.LocalDateTime;
import java.time.Instant;
import envoy.data.GroupMessage;
import envoy.data.Message.MessageStatus;
@ -27,9 +27,9 @@ public class GroupMessageStatusChange extends MessageStatusChange {
* @param date the date at which the MessageStatus change occurred for
* this specific member
* @param memberID the ID of the group member that caused the status change
* @since Envoy Common v0.1-beta
* @since Envoy Common v0.2-beta
*/
public GroupMessageStatusChange(long id, MessageStatus status, LocalDateTime date, long memberID) {
public GroupMessageStatusChange(long id, MessageStatus status, Instant date, long memberID) {
super(id, status, date);
this.memberID = memberID;
}

View File

@ -1,6 +1,6 @@
package envoy.event;
import java.time.LocalDateTime;
import java.time.Instant;
import envoy.data.Message;
@ -14,8 +14,8 @@ import envoy.data.Message;
*/
public class MessageStatusChange extends Event<Message.MessageStatus> {
private final long id;
private final LocalDateTime date;
private final long id;
private final Instant date;
private static final long serialVersionUID = 0L;
@ -26,9 +26,9 @@ public class MessageStatusChange extends Event<Message.MessageStatus> {
* @param status the status of the {@link Message} this event is related
* to
* @param date the date at which the MessageStatus change occurred
* @since Envoy Common v0.2-alpha
* @since Envoy Common v0.2-beta
*/
public MessageStatusChange(long id, Message.MessageStatus status, LocalDateTime date) {
public MessageStatusChange(long id, Message.MessageStatus status, Instant date) {
super(status);
this.id = id;
this.date = date;
@ -40,7 +40,7 @@ public class MessageStatusChange extends Event<Message.MessageStatus> {
* @param message the message from which to build the event
* @since Envoy Common v0.2-alpha
*/
public MessageStatusChange(Message message) { this(message.getID(), message.getStatus(), LocalDateTime.now()); }
public MessageStatusChange(Message message) { this(message.getID(), message.getStatus(), Instant.now()); }
/**
* @return the ID of the {@link Message} this event is related to
@ -50,9 +50,9 @@ public class MessageStatusChange extends Event<Message.MessageStatus> {
/**
* @return the date at which the status change occurred
* @since Envoy Common v0.2-alpha
* @since Envoy Common v0.2-beta
*/
public LocalDateTime getDate() { return date; }
public Instant getDate() { return date; }
@Override
public String toString() { return String.format("MessageStatusChange[id=%d,status=%s,date=%s]", id, value, date); }