From 8c6a8e160be238cdcdd6657d1962172ee32e1fc9 Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Wed, 25 Mar 2020 16:34:55 +0100
Subject: [PATCH 01/38] Updated database implementation
*Added a contact abstract class that serves as a superclass for user and
group
* Added a group class
* Updated persistenceManager to fit the new contact system.
* Updated all classes that used methods, that were updated.
---
pom.xml | 2 +-
src/main/java/envoy/server/data/Contact.java | 62 ++++++++++++++++++
src/main/java/envoy/server/data/Group.java | 54 ++++++++++++++++
src/main/java/envoy/server/data/Message.java | 16 +++--
.../envoy/server/data/PersistenceManager.java | 63 +++++++++++++++----
src/main/java/envoy/server/data/User.java | 58 ++---------------
.../envoy/server/net/ConnectionManager.java | 6 +-
.../processors/ContactOperationProcessor.java | 4 +-
.../ContactsRequestEventProcessor.java | 2 +-
.../IDGeneratorRequestProcessor.java | 12 ++--
.../processors/LoginCredentialProcessor.java | 18 +++---
.../MessageStatusChangeProcessor.java | 2 +-
.../processors/UserStatusChangeProcessor.java | 6 +-
13 files changed, 215 insertions(+), 90 deletions(-)
create mode 100644 src/main/java/envoy/server/data/Contact.java
create mode 100644 src/main/java/envoy/server/data/Group.java
diff --git a/pom.xml b/pom.xml
index 046ec55..244170b 100755
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
com.github.informatik-ag-ngl
envoy-common
- develop-SNAPSHOT
+ f~groups-SNAPSHOT
com.github.informatik-ag-ngl
diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java
new file mode 100644
index 0000000..9f1320a
--- /dev/null
+++ b/src/main/java/envoy/server/data/Contact.java
@@ -0,0 +1,62 @@
+package envoy.server.data;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+/**
+ * This class acts as a superclass for all contacts, being {@link User}s and
+ * {@link Group}s.
+ *
+ * Project: envoy-server-standalone
+ * File: Contact.java
+ * Created: 24.03.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-alpha
+ */
+
+@MappedSuperclass
+// TODO add queries
+public abstract class Contact {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ protected long id;
+ protected String name;
+
+ /**
+ * @return a envoy.data.Contact object of this envoy.server.data.Contact object.
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public abstract envoy.data.Contact toCommon();
+
+ /**
+ * @return the ID of this contact.
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public long getID() { return id; }
+
+ /**
+ * Sets the ID of this contact.
+ *
+ * @param id to set for this contact
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setID(long id) { this.id = id; }
+
+ /**
+ * @return the name of this contact.
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public String getName() { return name; }
+
+ /**
+ * Sets the name of this contact.
+ *
+ * @param name to set for this contact
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setName(String name) { this.name = name; }
+}
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
new file mode 100644
index 0000000..a98f2db
--- /dev/null
+++ b/src/main/java/envoy/server/data/Group.java
@@ -0,0 +1,54 @@
+package envoy.server.data;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.ManyToMany;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+
+/**
+ * This class serves as a way to let Hibernate communicate with the server
+ * without bringing the dependency of JPA/Hibernate into the client.
+ * It will be referenced as "database group" to clarify between the different
+ * group objects.
+ *
+ * Project: envoy-server-standalone
+ * File: Group.java
+ * Created: 24.03.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-alpha
+ */
+@Entity
+@Table(name = "groups")
+@NamedQueries({ @NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName") })
+public class Group extends Contact {
+
+ @ManyToMany(targetEntity = Group.class, cascade = CascadeType.ALL)
+ private List members;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public envoy.data.Group toCommon() { return new envoy.data.Group(id, name, members.stream().map(User::getID).collect(Collectors.toList())); }
+
+ /**
+ * @return a list of all users that are a member of this group.
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public List getMembers() { return members; }
+
+ /**
+ * Sets the members of this group.
+ *
+ * @param Members a list of all users, that should be assigned to this group.
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setMembers(List members) { this.members = members; }
+
+}
diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java
index e5f600c..3a6604c 100755
--- a/src/main/java/envoy/server/data/Message.java
+++ b/src/main/java/envoy/server/data/Message.java
@@ -2,7 +2,15 @@ package envoy.server.data;
import java.util.Date;
-import javax.persistence.*;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import envoy.data.MessageBuilder;
@@ -89,7 +97,7 @@ public class Message {
*/
public envoy.data.Message toCommonMessage() {
// TODO: Attachment
- envoy.data.Message message = new MessageBuilder(sender.getId(), recipient.getId(), id).setText(text)
+ envoy.data.Message message = new MessageBuilder(sender.getID(), recipient.getID(), id).setText(text)
.setDate(creationDate)
.setStatus(status)
.setForwarded(forwarded)
@@ -103,12 +111,12 @@ public class Message {
* @return the id of a {link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
- public long getId() { return id; }
+ public long getID() { return id; }
/**
* @param id the id to set
* @since Envoy Server Standalone v0.1-alpha
- * @see Message#getId()
+ * @see Message#getID()
*/
public void setId(long id) { this.id = id; }
diff --git a/src/main/java/envoy/server/data/PersistenceManager.java b/src/main/java/envoy/server/data/PersistenceManager.java
index 57fc469..b7261c2 100755
--- a/src/main/java/envoy/server/data/PersistenceManager.java
+++ b/src/main/java/envoy/server/data/PersistenceManager.java
@@ -16,6 +16,7 @@ import envoy.server.net.ConnectionManager;
* Created: 1 Jan 2020
*
* @author Leon Hofmeister
+ * @author Maximilian Käfer
* @since Envoy Server Standalone v0.1-alpha
*/
public class PersistenceManager {
@@ -49,12 +50,12 @@ public class PersistenceManager {
public static PersistenceManager getInstance() { return persistenceManager; }
/**
- * Adds a {@link User} to the database.
+ * Adds a {@link Contact} to the database.
*
- * @param user the {@link User} to add to the database
+ * @param user the {@link Contact} to add to the database
* @since Envoy Server Standalone v0.1-alpha
*/
- public void addUser(User user) { persist(user); }
+ public void addContact(Contact contact) { persist(contact); }
/**
* Adds a {@link Message} to the database.
@@ -73,12 +74,12 @@ public class PersistenceManager {
public void addConfigItem(ConfigItem configItem) { persist(configItem); }
/**
- * Updates a {@link User} in the database
+ * Updates a {@link Contact} in the database
*
- * @param user the {@link User} to add to the database
+ * @param user the {@link Contact} to add to the database
* @since Envoy Server Standalone v0.1-alpha
*/
- public void updateUser(User user) { merge(user); }
+ public void updateContact(Contact contact) { merge(contact); }
/**
* Updates a {@link Message} in the database.
@@ -97,12 +98,12 @@ public class PersistenceManager {
public void updateConfigItem(ConfigItem configItem) { merge(configItem); }
/**
- * Deletes a {@link User} in the database.
+ * Deletes a {@link Contact} in the database.
*
- * @param user the {@link User} to delete
+ * @param user the {@link Contact} to delete
* @since Envoy Server Standalone v0.1-alpha
*/
- public void deleteUser(User user) { remove(user); }
+ public void deleteContact(Contact contact) { remove(contact); }
/**
* Deletes a {@link Message} in the database.
@@ -113,7 +114,7 @@ public class PersistenceManager {
public void deleteMessage(Message message) { remove(message); }
/**
- * Searches for a {@link User} with a specific id.
+ * Searches for a {@link User} with a specific ID.
*
* @param id the id to search for
* @return the user with the specified id
@@ -121,6 +122,24 @@ public class PersistenceManager {
*/
public User getUserById(long id) { return entityManager.find(User.class, id); }
+ /**
+ * Searches for a {@link Group} with a specific ID.
+ *
+ * @param id the id to search for
+ * @return the group with the specific id
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Group getGroupById(long id) { return entityManager.find(Group.class, id); }
+
+ /**
+ * Searches for a {@link Contact} with a specific ID.
+ *
+ * @param id the id to search for
+ * @return the contact with the specific id
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Contact getContactById(long id) { return entityManager.find(Contact.class, id); }
+
/**
* Searched for a {@link User} with a specific name.
*
@@ -132,6 +151,28 @@ public class PersistenceManager {
return (User) entityManager.createNamedQuery("getUserByName").setParameter("name", name).getSingleResult();
}
+ /**
+ * Searched for a {@link Group} with a specific name.
+ *
+ * @param name the name of the group
+ * @return the group with the specified name
+ * @since Envoy Server Standalone v0.1-alpha
+ */
+ public Group getGroupByName(String name) {
+ return (Group) entityManager.createNamedQuery("getGroupByName").setParameter("name", name).getSingleResult();
+ }
+
+ /**
+ * Searched for a {@link Contact} with a specific name.
+ *
+ * @param name the name of the contact
+ * @return the contact with the specified name
+ * @since Envoy Server Standalone v0.1-alpha
+ */
+ public Contact getContactByName(String name) {
+ return (Contact) entityManager.createNamedQuery("getContactByName").setParameter("name", name).getSingleResult();
+ }
+
/**
* Searches for a {@link Message} with a specific id.
*
@@ -183,7 +224,7 @@ public class PersistenceManager {
* @param userId2 the ID of the second user
* @since Envoy Server Standalone v0.1-alpha
*/
- public void addContact(long userId1, long userId2) {
+ public void addUserContact(long userId1, long userId2) {
// Get users by ID
User u1 = getUserById(userId1);
diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java
index b356147..15ecd4d 100755
--- a/src/main/java/envoy/server/data/User.java
+++ b/src/main/java/envoy/server/data/User.java
@@ -31,12 +31,8 @@ import javax.persistence.*;
name = "searchUsers"
) }
)
-public class User {
+public class User extends Contact {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private long id;
- private String name;
private byte[] passwordHash;
@Temporal(TemporalType.TIMESTAMP)
@@ -47,55 +43,10 @@ public class User {
private List contacts;
/**
- * Creates an instance of {@link User}.
- *
- * @since Envoy Server Standalone v0.1-alpha
+ * {@inheritDoc}
*/
- public User() {}
-
- /**
- * Creates an instance of {@link User}.
- *
- * @param user the {@link envoy.data.User} to convert
- * @since Envoy Server Standalone v0.1-alpha
- */
- public User(envoy.data.User user) {
- id = user.getId();
- name = user.getName();
- status = user.getStatus();
- }
-
- /**
- * @return a database {@link User} converted into an {@link envoy.data.User}
- * @since Envoy Server Standalone v0.1-alpha
- */
- public envoy.data.User toCommonUser() { return new envoy.data.User(id, name, status); }
-
- /**
- * @return the id of a {link envoy.data.User}
- * @since Envoy Server Standalone v0.1-alpha
- */
- public long getId() { return id; }
-
- /**
- * @param id the id to set
- * @since Envoy Server Standalone v0.1-alpha
- * @see User#getId
- */
- public void setId(long id) { this.id = id; }
-
- /**
- * @return the name of a {link envoy.data.User}
- * @since Envoy Server Standalone v0.1-alpha
- */
- public String getName() { return name; }
-
- /**
- * @param name the username to set
- * @since Envoy Server Standalone v0.1-alpha
- * @see User#getName()
- */
- public void setName(String name) { this.name = name; }
+ @Override
+ public envoy.data.User toCommon() { return new envoy.data.User(id, name, status); }
/**
* @return the passwordHash of a {link envoy.data.User}
@@ -148,4 +99,5 @@ public class User {
* @see User#getContacts()
*/
public void setContacts(List contacts) { this.contacts = contacts; }
+
}
diff --git a/src/main/java/envoy/server/net/ConnectionManager.java b/src/main/java/envoy/server/net/ConnectionManager.java
index e8ca932..bf79091 100755
--- a/src/main/java/envoy/server/net/ConnectionManager.java
+++ b/src/main/java/envoy/server/net/ConnectionManager.java
@@ -1,6 +1,10 @@
package envoy.server.net;
-import java.util.*;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import com.jenkov.nioserver.ISocketIdListener;
diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
index 3c6c6d8..f906fb7 100755
--- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java
+++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
@@ -29,11 +29,11 @@ public class ContactOperationProcessor implements ObjectProcessor {
+public class IDGeneratorRequestProcessor implements ObjectProcessor {
private static final long ID_RANGE = 200;
@Override
- public Class getInputClass() { return IdGeneratorRequest.class; }
+ public Class getInputClass() { return IDGeneratorRequest.class; }
@Override
- public void process(IdGeneratorRequest input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
+ public void process(IDGeneratorRequest input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
System.out.println("Received id generation request.");
ConfigItem currentId = PersistenceManager.getInstance().getConfigItemById("currentMessageId");
- IdGenerator generator = new IdGenerator(Integer.parseInt(currentId.getValue()), ID_RANGE);
+ IDGenerator generator = new IDGenerator(Integer.parseInt(currentId.getValue()), ID_RANGE);
currentId.setValue(String.valueOf(Integer.parseInt(currentId.getValue()) + ID_RANGE));
PersistenceManager.getInstance().updateConfigItem(currentId);
diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
index 1bc736f..acde251 100755
--- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
+++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
@@ -1,7 +1,11 @@
package envoy.server.processors;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.InputMismatchException;
+import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.NoResultException;
@@ -45,7 +49,7 @@ public class LoginCredentialProcessor implements ObjectProcessor());
- persistenceManager.addUser(user);
+ persistenceManager.addContact(user);
return user;
}
}
diff --git a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
index b01772e..3dce652 100755
--- a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
@@ -33,7 +33,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor
Date: Wed, 25 Mar 2020 18:22:58 +0100
Subject: [PATCH 02/38] Implemented groups support on server
Implemented support for group messages in MessageProcessor and adjusted
IdGeneratorRequestProcessor
---
.../IDGeneratorRequestProcessor.java | 17 +++++--
.../server/processors/MessageProcessor.java | 46 +++++++++++++++++--
2 files changed, 53 insertions(+), 10 deletions(-)
diff --git a/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java b/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
index 7800c9c..bb6be36 100755
--- a/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
+++ b/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
@@ -14,6 +14,7 @@ import envoy.server.net.ObjectWriteProxy;
* Created: 28 Jan 2020
*
* @author Kai S. K. Engelbart
+ * @author Maximilian Käfer
* @since Envoy Server Standalone v0.1-alpha
*/
public class IDGeneratorRequestProcessor implements ObjectProcessor {
@@ -26,13 +27,19 @@ public class IDGeneratorRequestProcessor implements ObjectProcessor30.12.2019
*
* @author Kai S. K. Engelbart
+ * @author Maximilian Käfer
* @since Envoy Server Standalone v0.1-alpha
*/
public class MessageProcessor implements ObjectProcessor {
@@ -24,23 +28,55 @@ public class MessageProcessor implements ObjectProcessor {
@Override
public void process(Message message, long socketId, ObjectWriteProxy writeProxy) {
- ConnectionManager connectionManager = ConnectionManager.getInstance();
message.nextStatus();
+ ConnectionManager connectionManager = ConnectionManager.getInstance();
+ Contact recipient = PersistenceManager.getInstance().getContactById(message.getId());
+
+ if (recipient instanceof envoy.server.data.User) {
+ System.out.println("The received message is a direct message.");
+ sendToUser(connectionManager, message, writeProxy);
+ // Sending a messageStatusChangeEvent to the sender
+ try {
+ writeProxy.write(socketId, new MessageStatusChangeEvent(message));
+ } catch (IOException e) {
+ System.err.println("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getId());
+ e.printStackTrace();
+ }
+ } else {
+ System.out.println("The received message is a group message.");
+ final var members = PersistenceManager.getInstance().getGroupById(message.getRecipientId()).getMembers();
+ final var generator = IDGeneratorRequestProcessor.createIDGenerator(members.size());
+ members.forEach(user -> {
+ envoy.data.Message returnMessage = new MessageBuilder(message.getRecipientId(), user.getID(), generator)
+ .setDate(message.getCreationDate())
+ .setText(message.getText())
+ .setAttachment(message.getAttachment())
+ .setStatus(MessageStatus.SENT)
+ .setForwarded(message.isForwarded())
+ .build();
+ sendToUser(connectionManager, returnMessage, writeProxy);
+
+ // TODO Handle messageStatusChangeEvent because we have many recipients and
+ // copies of the original message. (Not at this location)
+ });
+ }
+ PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
+ }
+
+ private void sendToUser(ConnectionManager connectionManager, Message message, ObjectWriteProxy writeProxy) {
if (connectionManager.isOnline(message.getRecipientId())) try {
// If recipient is online, send the message directly
writeProxy.write(connectionManager.getSocketId(message.getRecipientId()), message);
-
// Update the message status to RECEIVED
message.setReceivedDate(new Date());
message.nextStatus();
- writeProxy.write(socketId, new MessageStatusChangeEvent(message));
+
} catch (IOException e) {
System.err.println("Recipient online. Failed to send message" + message.getId());
e.printStackTrace();
}
- PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
}
-
+
@Override
public Class getInputClass() { return Message.class; }
}
From 422d38f0935b14b85fb75fa194d25c702b60a7db Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Thu, 26 Mar 2020 16:06:55 +0100
Subject: [PATCH 03/38] Refactored every identifier to fit the new naming
convention, pom.xml
---
pom.xml | 2 +-
src/main/java/envoy/server/data/Message.java | 6 +++---
.../processors/ContactOperationProcessor.java | 2 +-
.../envoy/server/processors/MessageProcessor.java | 14 +++++++-------
.../processors/MessageStatusChangeProcessor.java | 2 +-
.../processors/UserStatusChangeProcessor.java | 6 +++---
6 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/pom.xml b/pom.xml
index 244170b..046ec55 100755
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
com.github.informatik-ag-ngl
envoy-common
- f~groups-SNAPSHOT
+ develop-SNAPSHOT
com.github.informatik-ag-ngl
diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java
index 3a6604c..76c133c 100755
--- a/src/main/java/envoy/server/data/Message.java
+++ b/src/main/java/envoy/server/data/Message.java
@@ -76,14 +76,14 @@ public class Message {
*/
public Message(envoy.data.Message message) {
PersistenceManager persMan = PersistenceManager.getInstance();
- id = message.getId();
+ id = message.getID();
status = message.getStatus();
text = message.getText();
creationDate = message.getCreationDate();
receivedDate = message.getReceivedDate();
readDate = message.getReadDate();
- sender = persMan.getUserById(message.getSenderId());
- recipient = persMan.getUserById(message.getRecipientId());
+ sender = persMan.getUserById(message.getSenderID());
+ recipient = persMan.getUserById(message.getRecipientID());
forwarded = message.isForwarded();
// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
}
diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
index f906fb7..aaa9a29 100755
--- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java
+++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
@@ -26,7 +26,7 @@ public class ContactOperationProcessor implements ObjectProcessor {
message.nextStatus();
ConnectionManager connectionManager = ConnectionManager.getInstance();
- Contact recipient = PersistenceManager.getInstance().getContactById(message.getId());
+ Contact recipient = PersistenceManager.getInstance().getContactById(message.getID());
if (recipient instanceof envoy.server.data.User) {
System.out.println("The received message is a direct message.");
@@ -39,15 +39,15 @@ public class MessageProcessor implements ObjectProcessor {
try {
writeProxy.write(socketId, new MessageStatusChangeEvent(message));
} catch (IOException e) {
- System.err.println("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getId());
+ System.err.println("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID());
e.printStackTrace();
}
} else {
System.out.println("The received message is a group message.");
- final var members = PersistenceManager.getInstance().getGroupById(message.getRecipientId()).getMembers();
+ final var members = PersistenceManager.getInstance().getGroupById(message.getRecipientID()).getMembers();
final var generator = IDGeneratorRequestProcessor.createIDGenerator(members.size());
members.forEach(user -> {
- envoy.data.Message returnMessage = new MessageBuilder(message.getRecipientId(), user.getID(), generator)
+ envoy.data.Message returnMessage = new MessageBuilder(message.getRecipientID(), user.getID(), generator)
.setDate(message.getCreationDate())
.setText(message.getText())
.setAttachment(message.getAttachment())
@@ -64,15 +64,15 @@ public class MessageProcessor implements ObjectProcessor {
}
private void sendToUser(ConnectionManager connectionManager, Message message, ObjectWriteProxy writeProxy) {
- if (connectionManager.isOnline(message.getRecipientId())) try {
+ if (connectionManager.isOnline(message.getRecipientID())) try {
// If recipient is online, send the message directly
- writeProxy.write(connectionManager.getSocketId(message.getRecipientId()), message);
+ writeProxy.write(connectionManager.getSocketId(message.getRecipientID()), message);
// Update the message status to RECEIVED
message.setReceivedDate(new Date());
message.nextStatus();
} catch (IOException e) {
- System.err.println("Recipient online. Failed to send message" + message.getId());
+ System.err.println("Recipient online. Failed to send message" + message.getID());
e.printStackTrace();
}
}
diff --git a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
index 3dce652..bd9c215 100755
--- a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
@@ -27,7 +27,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor
Date: Thu, 26 Mar 2020 17:09:52 +0100
Subject: [PATCH 04/38] Implemented a GroupCreationProcessor and revised/added
Javadoc
---
src/main/java/envoy/server/data/Group.java | 2 +-
.../envoy/server/data/PersistenceManager.java | 6 ++--
.../processors/GroupCreationProcessor.java | 34 +++++++++++++++++++
.../IDGeneratorRequestProcessor.java | 9 +++++
4 files changed, 47 insertions(+), 4 deletions(-)
create mode 100644 src/main/java/envoy/server/processors/GroupCreationProcessor.java
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
index a98f2db..592475f 100644
--- a/src/main/java/envoy/server/data/Group.java
+++ b/src/main/java/envoy/server/data/Group.java
@@ -46,7 +46,7 @@ public class Group extends Contact {
/**
* Sets the members of this group.
*
- * @param Members a list of all users, that should be assigned to this group.
+ * @param members a list of all users, that should be assigned to this group.
* @since Envoy Server Standalone v0.1-beta
*/
public void setMembers(List members) { this.members = members; }
diff --git a/src/main/java/envoy/server/data/PersistenceManager.java b/src/main/java/envoy/server/data/PersistenceManager.java
index b7261c2..669cf7e 100755
--- a/src/main/java/envoy/server/data/PersistenceManager.java
+++ b/src/main/java/envoy/server/data/PersistenceManager.java
@@ -52,7 +52,7 @@ public class PersistenceManager {
/**
* Adds a {@link Contact} to the database.
*
- * @param user the {@link Contact} to add to the database
+ * @param contact the {@link Contact} to add to the database
* @since Envoy Server Standalone v0.1-alpha
*/
public void addContact(Contact contact) { persist(contact); }
@@ -76,7 +76,7 @@ public class PersistenceManager {
/**
* Updates a {@link Contact} in the database
*
- * @param user the {@link Contact} to add to the database
+ * @param contact the {@link Contact} to add to the database
* @since Envoy Server Standalone v0.1-alpha
*/
public void updateContact(Contact contact) { merge(contact); }
@@ -100,7 +100,7 @@ public class PersistenceManager {
/**
* Deletes a {@link Contact} in the database.
*
- * @param user the {@link Contact} to delete
+ * @param contact the {@link Contact} to delete
* @since Envoy Server Standalone v0.1-alpha
*/
public void deleteContact(Contact contact) { remove(contact); }
diff --git a/src/main/java/envoy/server/processors/GroupCreationProcessor.java b/src/main/java/envoy/server/processors/GroupCreationProcessor.java
new file mode 100644
index 0000000..85ac6af
--- /dev/null
+++ b/src/main/java/envoy/server/processors/GroupCreationProcessor.java
@@ -0,0 +1,34 @@
+package envoy.server.processors;
+
+import java.io.IOException;
+
+import envoy.event.GroupCreationEvent;
+import envoy.server.data.PersistenceManager;
+import envoy.server.net.ObjectWriteProxy;
+
+/**
+ * Project: envoy-server-standalone
+ * File: GroupCreationProcessor.java
+ * Created: 26.03.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-beta
+ */
+public class GroupCreationProcessor implements ObjectProcessor {
+
+ private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
+
+ @Override
+ public void process(GroupCreationEvent input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
+ envoy.server.data.Group group = new envoy.server.data.Group();
+ group.setName(input.get());
+ // TODO adjust event, so it sends a members list as well, which can be initially
+ // set here
+ persistenceManager.addContact(group);
+ writeProxy.write(socketId, group); // TODO Prepare the client to receive the group object after sending the
+ // groupCreationEvent to the server.
+ }
+
+ @Override
+ public Class getInputClass() { return GroupCreationEvent.class; }
+}
diff --git a/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java b/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
index bb6be36..38a799d 100755
--- a/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
+++ b/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
@@ -33,8 +33,17 @@ public class IDGeneratorRequestProcessor implements ObjectProcessor
Date: Thu, 26 Mar 2020 20:14:09 +0100
Subject: [PATCH 05/38] Created method to extract all currently online members
of a group
additionally, refactored every ".Id" to ".ID"
---
.../envoy/server/net/ConnectionManager.java | 59 +++++++++++--------
.../envoy/server/net/ObjectWriteProxy.java | 6 +-
.../processors/ContactOperationProcessor.java | 8 +--
.../ContactsRequestEventProcessor.java | 6 +-
.../processors/GroupCreationProcessor.java | 4 +-
.../IDGeneratorRequestProcessor.java | 12 ++--
.../processors/LoginCredentialProcessor.java | 38 ++++++------
.../server/processors/MessageProcessor.java | 4 +-
.../MessageStatusChangeProcessor.java | 2 +-
.../server/processors/ObjectProcessor.java | 4 +-
.../processors/UserStatusChangeProcessor.java | 2 +-
11 files changed, 79 insertions(+), 66 deletions(-)
diff --git a/src/main/java/envoy/server/net/ConnectionManager.java b/src/main/java/envoy/server/net/ConnectionManager.java
index bf79091..9314b5c 100755
--- a/src/main/java/envoy/server/net/ConnectionManager.java
+++ b/src/main/java/envoy/server/net/ConnectionManager.java
@@ -1,15 +1,14 @@
package envoy.server.net;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
import com.jenkov.nioserver.ISocketIdListener;
import envoy.data.User.UserStatus;
+import envoy.server.data.Group;
import envoy.server.data.PersistenceManager;
+import envoy.server.data.User;
import envoy.server.processors.UserStatusChangeProcessor;
/**
@@ -48,60 +47,74 @@ public class ConnectionManager implements ISocketIdListener {
public static ConnectionManager getInstance() { return connectionManager; }
@Override
- public void socketCancelled(long socketId) {
- if (!pendingSockets.remove(socketId)) {
+ public void socketCancelled(long socketID) {
+ if (!pendingSockets.remove(socketID)) {
// Notify contacts of this users offline-going
- envoy.server.data.User user = PersistenceManager.getInstance().getUserById(getUserIdBySocketId(socketId));
+ envoy.server.data.User user = PersistenceManager.getInstance().getUserById(getUserIdBySocketId(socketID));
user.setStatus(UserStatus.OFFLINE);
user.setLastSeen(new Date());
UserStatusChangeProcessor.updateUserStatus(user);
// Remove the socket
- sockets.entrySet().removeIf(e -> e.getValue() == socketId);
+ sockets.entrySet().removeIf(e -> e.getValue() == socketID);
}
}
@Override
- public void socketRegistered(long socketId) { pendingSockets.add(socketId); }
+ public void socketRegistered(long socketID) { pendingSockets.add(socketID); }
/**
* Associates a socket ID with a user ID.
*
- * @param userId the user ID
- * @param socketId the socket ID
+ * @param userID the user ID
+ * @param socketID the socket ID
* @since Envoy Server Standalone v0.1-alpha
*/
- public void registerUser(long userId, long socketId) {
- sockets.put(userId, socketId);
- pendingSockets.remove(socketId);
+ public void registerUser(long userID, long socketID) {
+ sockets.put(userID, socketID);
+ pendingSockets.remove(socketID);
}
/**
- * @param userId the ID of the user registered at a socket
+ * @param userID the ID of the user registered at a socket
* @return the ID of the socket
* @since Envoy Server Standalone v0.1-alpha
*/
- public long getSocketId(long userId) { return sockets.get(userId); }
+ public long getSocketId(long userID) { return sockets.get(userID); }
/**
- * @param socketId the id of the socket whose User is needed
+ * @param socketID the id of the socket whose User is needed
* @return the userId associated with this socketId
* @since Envoy Server Standalone v0.1-alpha
*/
- public long getUserIdBySocketId(long socketId) {
- return sockets.entrySet().stream().filter(entry -> entry.getValue().equals(socketId)).findFirst().get().getKey();
+ public long getUserIdBySocketId(long socketID) {
+ return sockets.entrySet().stream().filter(entry -> entry.getValue().equals(socketID)).findFirst().get().getKey();
}
/**
- * @param userId the ID of the user to check for
+ * @param userID the ID of the user to check for
* @return {@code true} if the user is online
* @since Envoy Server Standalone v0.1-alpha
*/
- public boolean isOnline(long userId) { return sockets.containsKey(userId); }
+ public boolean isOnline(long userID) { return sockets.containsKey(userID); }
/**
- * @return the userId of all users who are currently online
+ * @return the userIDs of all users who are currently online
* @since Envoy Server Standalone v0.1-alpha
*/
public Set getOnlineUsers() { return sockets.keySet(); }
+
+ /**
+ * Returns all members of a group who are currently online.
+ *
+ * @param group the group to search for
+ * @return a set of all IDs of currently active members in this group
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Set getOnlineUsersOfGroup(Group group) {
+ Set onlineMembers = new HashSet<>();
+ Set members = group.getMembers().stream().map(User::getID).collect(Collectors.toSet());
+ members.forEach(userID -> { if (isOnline(userID)) onlineMembers.add(userID); });
+ return onlineMembers;
+ }
}
diff --git a/src/main/java/envoy/server/net/ObjectWriteProxy.java b/src/main/java/envoy/server/net/ObjectWriteProxy.java
index 825daeb..238e817 100755
--- a/src/main/java/envoy/server/net/ObjectWriteProxy.java
+++ b/src/main/java/envoy/server/net/ObjectWriteProxy.java
@@ -30,15 +30,15 @@ public class ObjectWriteProxy {
public ObjectWriteProxy(WriteProxy writeProxy) { this.writeProxy = writeProxy; }
/**
- * @param recipientSocketId the socket id of the recipient
+ * @param recipientSocketID the socket id of the recipient
* @param obj the object to return to the client
* @throws IOException if the serialization of the object failed
* @since Envoy Server Standalone v0.1-alpha
*/
- public void write(long recipientSocketId, Object obj) throws IOException {
+ public void write(long recipientSocketID, Object obj) throws IOException {
// Create message targeted at the client
Message response = writeProxy.getMessage();
- response.socketId = recipientSocketId;
+ response.socketId = recipientSocketID;
// Serialize object to byte array
byte[] objBytes = SerializationUtils.writeToByteArray(obj);
diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
index aaa9a29..f9f9133 100755
--- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java
+++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
@@ -25,15 +25,15 @@ public class ContactOperationProcessor implements ObjectProcessor getInputClass() { return IDGeneratorRequest.class; }
@Override
- public void process(IDGeneratorRequest input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
+ public void process(IDGeneratorRequest input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
System.out.println("Received id generation request.");
var generator = createIDGenerator();
System.out.println("Sending new id generator " + generator);
- writeProxy.write(socketId, generator);
+ writeProxy.write(socketID, generator);
}
/**
@@ -44,10 +44,10 @@ public class IDGeneratorRequestProcessor implements ObjectProcessor pendingMessages = PersistenceManager.getInstance().getUnreadMessages(user);
for (Message msg : pendingMessages) {
System.out.println("Sending message " + msg.toCommonMessage());
- writeProxy.write(socketId, msg.toCommonMessage());
+ writeProxy.write(socketID, msg.toCommonMessage());
msg.setReceivedDate(new Date());
msg.setStatus(MessageStatus.RECEIVED);
PersistenceManager.getInstance().updateMessage(msg);
@@ -79,13 +79,13 @@ public class LoginCredentialProcessor implements ObjectProcessor getInputClass() { return LoginCredentials.class; }
- private envoy.server.data.User getUser(LoginCredentials credentials, long socketId, ObjectWriteProxy writeProxy) throws IOException {
- return credentials.isRegistration() ? newUser(credentials, socketId, writeProxy) : checkForExistingUser(credentials, socketId, writeProxy);
+ private envoy.server.data.User getUser(LoginCredentials credentials, long socketID, ObjectWriteProxy writeProxy) throws IOException {
+ return credentials.isRegistration() ? newUser(credentials, socketID, writeProxy) : checkForExistingUser(credentials, socketID, writeProxy);
}
/**
* @param credentials the input to evaluate
- * @param socketId the socket ID at which the client performing the handshake
+ * @param socketID the socket ID at which the client performing the handshake
* is connected
* @param writeProxy the {@link ObjectWriteProxy} to use if login was not
* successful
@@ -93,34 +93,34 @@ public class LoginCredentialProcessor implements ObjectProcessor {
@Override
- public void process(Message message, long socketId, ObjectWriteProxy writeProxy) {
+ public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
message.nextStatus();
ConnectionManager connectionManager = ConnectionManager.getInstance();
Contact recipient = PersistenceManager.getInstance().getContactById(message.getID());
@@ -36,7 +36,7 @@ public class MessageProcessor implements ObjectProcessor {
sendToUser(connectionManager, message, writeProxy);
// Sending a messageStatusChangeEvent to the sender
try {
- writeProxy.write(socketId, new MessageStatusChangeEvent(message));
+ writeProxy.write(socketID, new MessageStatusChangeEvent(message));
} catch (IOException e) {
System.err.println("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID());
e.printStackTrace();
diff --git a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
index bd9c215..587fd0e 100755
--- a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
@@ -23,7 +23,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor {
/**
* @param input the request object
- * @param socketId the ID of the socket from which the object was received
+ * @param socketID the ID of the socket from which the object was received
* @param writeProxy the object that allows writing to a client
* @throws IOException if something went wrong during processing
* @since Envoy Server Standalone v0.1-alpha
*/
- void process(T input, long socketId, ObjectWriteProxy writeProxy) throws IOException;
+ void process(T input, long socketID, ObjectWriteProxy writeProxy) throws IOException;
}
diff --git a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
index 82559ac..3e1b5d3 100755
--- a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
@@ -28,7 +28,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor getInputClass() { return UserStatusChangeEvent.class; }
@Override
- public void process(UserStatusChangeEvent input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
+ public void process(UserStatusChangeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
// new status should not equal old status
if (input.get().equals(persistenceManager.getUserById(input.getID()).getStatus())) {
System.out.println("Received an unnecessary UserStatusChangeEvent");
From b3ee23cd8da4c06e7fcc28b52aef91bd54ea39d9 Mon Sep 17 00:00:00 2001
From: delvh
Date: Thu, 2 Apr 2020 16:32:23 +0200
Subject: [PATCH 06/38] Restored compatability with envoy-common
additionally added NameChangeProcessor
---
pom.xml | 2 +-
src/main/java/envoy/server/data/Contact.java | 139 ++++++++++--------
src/main/java/envoy/server/data/Group.java | 88 +++++------
.../envoy/server/data/PersistenceManager.java | 8 +-
src/main/java/envoy/server/data/User.java | 23 +--
.../envoy/server/net/ConnectionManager.java | 3 +-
.../processors/ContactOperationProcessor.java | 5 +-
.../ContactsRequestEventProcessor.java | 8 +-
.../processors/LoginCredentialProcessor.java | 13 +-
.../server/processors/MessageProcessor.java | 2 +-
.../processors/NameChangeProcessor.java | 42 ++++++
.../processors/UserStatusChangeProcessor.java | 2 +-
12 files changed, 175 insertions(+), 160 deletions(-)
create mode 100644 src/main/java/envoy/server/processors/NameChangeProcessor.java
diff --git a/pom.xml b/pom.xml
index 046ec55..244170b 100755
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
com.github.informatik-ag-ngl
envoy-common
- develop-SNAPSHOT
+ f~groups-SNAPSHOT
com.github.informatik-ag-ngl
diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java
index 9f1320a..d1737d8 100644
--- a/src/main/java/envoy/server/data/Contact.java
+++ b/src/main/java/envoy/server/data/Contact.java
@@ -1,62 +1,77 @@
-package envoy.server.data;
-
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.MappedSuperclass;
-
-/**
- * This class acts as a superclass for all contacts, being {@link User}s and
- * {@link Group}s.
- *
- * Project: envoy-server-standalone
- * File: Contact.java
- * Created: 24.03.2020
- *
- * @author Maximilian Käfer
- * @since Envoy Server Standalone v0.1-alpha
- */
-
-@MappedSuperclass
-// TODO add queries
-public abstract class Contact {
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- protected long id;
- protected String name;
-
- /**
- * @return a envoy.data.Contact object of this envoy.server.data.Contact object.
- * @since Envoy Server Standalone v0.1-beta
- */
- public abstract envoy.data.Contact toCommon();
-
- /**
- * @return the ID of this contact.
- * @since Envoy Server Standalone v0.1-beta
- */
- public long getID() { return id; }
-
- /**
- * Sets the ID of this contact.
- *
- * @param id to set for this contact
- * @since Envoy Server Standalone v0.1-beta
- */
- public void setID(long id) { this.id = id; }
-
- /**
- * @return the name of this contact.
- * @since Envoy Server Standalone v0.1-beta
- */
- public String getName() { return name; }
-
- /**
- * Sets the name of this contact.
- *
- * @param name to set for this contact
- * @since Envoy Server Standalone v0.1-beta
- */
- public void setName(String name) { this.name = name; }
-}
+package envoy.server.data;
+
+import java.util.Set;
+
+import javax.persistence.*;
+
+/**
+ * This class acts as a superclass for all contacts, being {@link User}s and
+ * {@link Group}s.
+ *
+ * Project: envoy-server-standalone
+ * File: Contact.java
+ * Created: 24.03.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-alpha
+ */
+
+@MappedSuperclass
+// TODO add queries
+public abstract class Contact {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ protected long id;
+ protected String name;
+
+ @ManyToMany(targetEntity = Contact.class, cascade = CascadeType.ALL)
+ protected Set contacts;
+
+ /**
+ * @return a {@link envoy.data.Contact} object of this envoy.server.data.Contact
+ * object.
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public abstract envoy.data.Contact toCommon();
+
+ /**
+ * @return the ID of this contact.
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public long getID() { return id; }
+
+ /**
+ * Sets the ID of this contact.
+ *
+ * @param id to set for this contact
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setID(long id) { this.id = id; }
+
+ /**
+ * @return the name of this contact.
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public String getName() { return name; }
+
+ /**
+ * Sets the name of this contact.
+ *
+ * @param name to set for this contact
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setName(String name) { this.name = name; }
+
+ /**
+ * @return the contacts
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Set getContacts() { return contacts; }
+
+ /**
+ * @param contacts the contacts to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setContacts(Set contacts) { this.contacts = contacts; }
+}
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
index 592475f..6c76df9 100644
--- a/src/main/java/envoy/server/data/Group.java
+++ b/src/main/java/envoy/server/data/Group.java
@@ -1,54 +1,34 @@
-package envoy.server.data;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.ManyToMany;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
-
-/**
- * This class serves as a way to let Hibernate communicate with the server
- * without bringing the dependency of JPA/Hibernate into the client.
- * It will be referenced as "database group" to clarify between the different
- * group objects.
- *
- * Project: envoy-server-standalone
- * File: Group.java
- * Created: 24.03.2020
- *
- * @author Maximilian Käfer
- * @since Envoy Server Standalone v0.1-alpha
- */
-@Entity
-@Table(name = "groups")
-@NamedQueries({ @NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName") })
-public class Group extends Contact {
-
- @ManyToMany(targetEntity = Group.class, cascade = CascadeType.ALL)
- private List members;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public envoy.data.Group toCommon() { return new envoy.data.Group(id, name, members.stream().map(User::getID).collect(Collectors.toList())); }
-
- /**
- * @return a list of all users that are a member of this group.
- * @since Envoy Server Standalone v0.1-beta
- */
- public List getMembers() { return members; }
-
- /**
- * Sets the members of this group.
- *
- * @param members a list of all users, that should be assigned to this group.
- * @since Envoy Server Standalone v0.1-beta
- */
- public void setMembers(List members) { this.members = members; }
-
-}
+package envoy.server.data;
+
+import java.util.stream.Collectors;
+
+import javax.persistence.*;
+
+import envoy.data.User;
+
+/**
+ * This class serves as a way to let Hibernate communicate with the server
+ * without bringing the dependency of JPA/Hibernate into the client.
+ * It will be referenced as "database group" to clarify between the different
+ * group objects.
+ *
+ * Project: envoy-server-standalone
+ * File: Group.java
+ * Created: 24.03.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-alpha
+ */
+@Entity
+@Table(name = "groups")
+@NamedQueries({ @NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName") })
+public class Group extends Contact {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public envoy.data.Group toCommon() {
+ return new envoy.data.Group(id, name, contacts.parallelStream().map(Contact::toCommon).map(User.class::cast).collect(Collectors.toSet()));
+ }
+}
diff --git a/src/main/java/envoy/server/data/PersistenceManager.java b/src/main/java/envoy/server/data/PersistenceManager.java
index 669cf7e..1dd82a8 100755
--- a/src/main/java/envoy/server/data/PersistenceManager.java
+++ b/src/main/java/envoy/server/data/PersistenceManager.java
@@ -124,7 +124,7 @@ public class PersistenceManager {
/**
* Searches for a {@link Group} with a specific ID.
- *
+ *
* @param id the id to search for
* @return the group with the specific id
* @since Envoy Server Standalone v0.1-beta
@@ -133,7 +133,7 @@ public class PersistenceManager {
/**
* Searches for a {@link Contact} with a specific ID.
- *
+ *
* @param id the id to search for
* @return the contact with the specific id
* @since Envoy Server Standalone v0.1-beta
@@ -227,8 +227,8 @@ public class PersistenceManager {
public void addUserContact(long userId1, long userId2) {
// Get users by ID
- User u1 = getUserById(userId1);
- User u2 = getUserById(userId2);
+ Contact u1 = getContactById(userId1);
+ Contact u2 = getContactById(userId2);
// Add users to each others contact lists
u1.getContacts().add(u2);
diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java
index 2913a54..2f788f0 100755
--- a/src/main/java/envoy/server/data/User.java
+++ b/src/main/java/envoy/server/data/User.java
@@ -1,7 +1,7 @@
package envoy.server.data;
import java.util.Date;
-import java.util.List;
+import java.util.stream.Collectors;
import javax.persistence.*;
@@ -38,14 +38,13 @@ public class User extends Contact {
private Date lastSeen;
private envoy.data.User.UserStatus status;
- @ManyToMany(targetEntity = User.class, cascade = CascadeType.ALL)
- private List contacts;
-
/**
* {@inheritDoc}
*/
@Override
- public envoy.data.User toCommon() { return new envoy.data.User(id, name, status); }
+ public envoy.data.User toCommon() {
+ return new envoy.data.User(id, name, status, contacts.stream().map(Contact::toCommon).collect(Collectors.toSet()));
+ }
/**
* @return the passwordHash of a {link envoy.data.User}
@@ -85,18 +84,4 @@ public class User extends Contact {
* @see User#getStatus()
*/
public void setStatus(envoy.data.User.UserStatus status) { this.status = status; }
-
- /**
- * @return the contacts of a {link envoy.data.User}
- * @since Envoy Server Standalone v0.1-alpha
- */
- public List getContacts() { return contacts; }
-
- /**
- * @param contacts the contacts to set
- * @since Envoy Server Standalone v0.1-alpha
- * @see User#getContacts()
- */
- public void setContacts(List contacts) { this.contacts = contacts; }
-
}
diff --git a/src/main/java/envoy/server/net/ConnectionManager.java b/src/main/java/envoy/server/net/ConnectionManager.java
index 9314b5c..883f510 100755
--- a/src/main/java/envoy/server/net/ConnectionManager.java
+++ b/src/main/java/envoy/server/net/ConnectionManager.java
@@ -8,7 +8,6 @@ import com.jenkov.nioserver.ISocketIdListener;
import envoy.data.User.UserStatus;
import envoy.server.data.Group;
import envoy.server.data.PersistenceManager;
-import envoy.server.data.User;
import envoy.server.processors.UserStatusChangeProcessor;
/**
@@ -113,7 +112,7 @@ public class ConnectionManager implements ISocketIdListener {
*/
public Set getOnlineUsersOfGroup(Group group) {
Set onlineMembers = new HashSet<>();
- Set members = group.getMembers().stream().map(User::getID).collect(Collectors.toSet());
+ Set members = group.getContacts().stream().map(envoy.server.data.Contact::getID).collect(Collectors.toSet());
members.forEach(userID -> { if (isOnline(userID)) onlineMembers.add(userID); });
return onlineMembers;
}
diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
index f9f9133..fa67c55 100755
--- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java
+++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
@@ -3,8 +3,7 @@ package envoy.server.processors;
import java.io.IOException;
import java.util.Arrays;
-import envoy.data.Contacts;
-import envoy.event.ContactOperationEvent;
+import envoy.event.contact.ContactOperationEvent;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy;
@@ -33,7 +32,7 @@ public class ContactOperationProcessor implements ObjectProcessor {
/**
- * Writes a {@link Contacts} list to the client containing all {@link User}s
+ * Writes a list of contacts to the client containing all {@link Contact}s
* matching the search phrase contained inside the request. The client and their
* contacts are excluded from the result.
*
diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
index 523dce3..faa9f6c 100755
--- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
+++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
@@ -1,16 +1,11 @@
package envoy.server.processors;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.InputMismatchException;
-import java.util.List;
+import java.util.*;
import java.util.stream.Collectors;
import javax.persistence.NoResultException;
-import envoy.data.Contacts;
import envoy.data.LoginCredentials;
import envoy.data.Message.MessageStatus;
import envoy.data.User;
@@ -57,8 +52,8 @@ public class LoginCredentialProcessor implements ObjectProcessor());
+ user.setContacts(new HashSet<>());
persistenceManager.addContact(user);
return user;
}
diff --git a/src/main/java/envoy/server/processors/MessageProcessor.java b/src/main/java/envoy/server/processors/MessageProcessor.java
index 5e8d7f0..fd41a87 100755
--- a/src/main/java/envoy/server/processors/MessageProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageProcessor.java
@@ -43,7 +43,7 @@ public class MessageProcessor implements ObjectProcessor {
}
} else {
System.out.println("The received message is a group message.");
- final var members = PersistenceManager.getInstance().getGroupById(message.getRecipientID()).getMembers();
+ final var members = PersistenceManager.getInstance().getGroupById(message.getRecipientID()).getContacts();
final var generator = IDGeneratorRequestProcessor.createIDGenerator(members.size());
members.forEach(user -> {
envoy.data.Message returnMessage = new MessageBuilder(message.getRecipientID(), user.getID(), generator)
diff --git a/src/main/java/envoy/server/processors/NameChangeProcessor.java b/src/main/java/envoy/server/processors/NameChangeProcessor.java
new file mode 100644
index 0000000..319d302
--- /dev/null
+++ b/src/main/java/envoy/server/processors/NameChangeProcessor.java
@@ -0,0 +1,42 @@
+package envoy.server.processors;
+
+import java.io.IOException;
+
+import envoy.event.NameChangeEvent;
+import envoy.server.data.Contact;
+import envoy.server.data.PersistenceManager;
+import envoy.server.data.User;
+import envoy.server.net.ConnectionManager;
+import envoy.server.net.ObjectWriteProxy;
+
+/**
+ * Project: envoy-server-standalone
+ * File: NameChangeProcessor.java
+ * Created: 26 Mar 2020
+ *
+ * @author Leon Hofmeister
+ * @since Envoy Server Standalone v0.1-beta
+ */
+public class NameChangeProcessor implements ObjectProcessor {
+
+ @Override
+ public void process(NameChangeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
+ PersistenceManager persistenceManager = PersistenceManager.getInstance();
+ ConnectionManager connectionManager = ConnectionManager.getInstance();
+ Contact toUpdate = persistenceManager.getContactById(input.getID());
+ toUpdate.setName(input.get());
+ persistenceManager.updateContact(toUpdate);
+
+ // notifying online contacts of this client of his name change
+ toUpdate.getContacts().stream().filter(contact -> (contact instanceof User && connectionManager.isOnline(contact.getID()))).forEach(user -> {
+ try {
+ writeProxy.write(user.getID(), input);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+ }
+
+ @Override
+ public Class getInputClass() { return NameChangeEvent.class; }
+}
diff --git a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
index 3e1b5d3..68547fc 100755
--- a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
@@ -71,7 +71,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor
Date: Thu, 2 Apr 2020 20:41:05 +0200
Subject: [PATCH 07/38] Implemented Groups on the database and implemented
MSChange management
---
src/main/java/envoy/server/data/Contact.java | 15 ++++++++---
src/main/java/envoy/server/data/Group.java | 6 +++--
src/main/java/envoy/server/data/Message.java | 11 ++++----
.../envoy/server/data/PersistenceManager.java | 12 ++++++---
.../processors/LoginCredentialProcessor.java | 25 +++++++++++++------
5 files changed, 46 insertions(+), 23 deletions(-)
diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java
index d1737d8..81107d4 100644
--- a/src/main/java/envoy/server/data/Contact.java
+++ b/src/main/java/envoy/server/data/Contact.java
@@ -2,7 +2,14 @@ package envoy.server.data;
import java.util.Set;
-import javax.persistence.*;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.ManyToMany;
/**
* This class acts as a superclass for all contacts, being {@link User}s and
@@ -16,12 +23,12 @@ import javax.persistence.*;
* @since Envoy Server Standalone v0.1-alpha
*/
-@MappedSuperclass
-// TODO add queries
+@Entity
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Contact {
@Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @GeneratedValue(strategy = GenerationType.TABLE)
protected long id;
protected String name;
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
index 6c76df9..6301624 100644
--- a/src/main/java/envoy/server/data/Group.java
+++ b/src/main/java/envoy/server/data/Group.java
@@ -2,7 +2,9 @@ package envoy.server.data;
import java.util.stream.Collectors;
-import javax.persistence.*;
+import javax.persistence.Entity;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
import envoy.data.User;
@@ -21,7 +23,7 @@ import envoy.data.User;
*/
@Entity
@Table(name = "groups")
-@NamedQueries({ @NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName") })
+@NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName")
public class Group extends Contact {
/**
diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java
index 76c133c..17a12d8 100755
--- a/src/main/java/envoy/server/data/Message.java
+++ b/src/main/java/envoy/server/data/Message.java
@@ -6,7 +6,6 @@ import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
-import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
@@ -29,11 +28,11 @@ import envoy.data.MessageBuilder;
*/
@Entity
@Table(name = "messages")
-@NamedQueries(
- { @NamedQuery(
- query = "SELECT m FROM Message m WHERE m.recipient =:recipient AND m.status = envoy.data.Message$MessageStatus.SENT",
- name = "getUnreadMessages"
- ) }
+@NamedQuery(
+ query = "SELECT m FROM Message m WHERE (m.recipient = :user AND m.status = envoy.data.Message$MessageStatus.SENT) "
+ + "OR (m.sender = :user) AND ((m.status = envoy.data.Message$MessageStatus.RECEIVED) AND (m.receivedDate > :lastSeen)"
+ + "OR (m.status = envoy.data.Message$MessageStatus.READ) AND (m.readDate > :lastSeen))",
+ name = "getPendingMessages"
)
public class Message {
diff --git a/src/main/java/envoy/server/data/PersistenceManager.java b/src/main/java/envoy/server/data/PersistenceManager.java
index 1dd82a8..53eb670 100755
--- a/src/main/java/envoy/server/data/PersistenceManager.java
+++ b/src/main/java/envoy/server/data/PersistenceManager.java
@@ -190,14 +190,18 @@ public class PersistenceManager {
public ConfigItem getConfigItemById(String key) { return entityManager.find(ConfigItem.class, key); }
/**
- * Returns all messages received while being offline.
+ * Returns all messages received while being offline or the ones that have
+ * changed.
*
- * @param user - the user who wants to receive his unread messages
+ * @param user the user who wants to receive his unread messages
* @return all messages that the client does not yet have (unread messages)
* @since Envoy Server Standalone v0.1-alpha
*/
- public List getUnreadMessages(User user) {
- return entityManager.createNamedQuery("getUnreadMessages").setParameter("recipient", user).getResultList();
+ public List getPendingMessages(User user) {
+ return entityManager.createNamedQuery("getPendingMessages")
+ .setParameter("user", user)
+ .setParameter("lastSeen", user.getLastSeen())
+ .getResultList();
}
/**
diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
index faa9f6c..4051513 100755
--- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
+++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
@@ -1,7 +1,11 @@
package envoy.server.processors;
import java.io.IOException;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.InputMismatchException;
+import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.NoResultException;
@@ -11,6 +15,7 @@ import envoy.data.Message.MessageStatus;
import envoy.data.User;
import envoy.data.User.UserStatus;
import envoy.event.HandshakeRejectionEvent;
+import envoy.event.MessageStatusChangeEvent;
import envoy.server.data.Message;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
@@ -61,13 +66,19 @@ public class LoginCredentialProcessor implements ObjectProcessor pendingMessages = PersistenceManager.getInstance().getUnreadMessages(user);
+ List pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
for (Message msg : pendingMessages) {
- System.out.println("Sending message " + msg.toCommonMessage());
- writeProxy.write(socketID, msg.toCommonMessage());
- msg.setReceivedDate(new Date());
- msg.setStatus(MessageStatus.RECEIVED);
- PersistenceManager.getInstance().updateMessage(msg);
+ if (msg.getStatus() == MessageStatus.SENT) {
+ System.out.println("Sending message " + msg.toCommonMessage());
+ writeProxy.write(socketID, msg.toCommonMessage());
+ msg.setReceivedDate(new Date());
+ msg.setStatus(MessageStatus.RECEIVED);
+ PersistenceManager.getInstance().updateMessage(msg);
+ } else {
+ var evt = new MessageStatusChangeEvent(msg.toCommonMessage());
+ System.out.println("Sending messageStatusChangeEvent " + evt);
+ writeProxy.write(socketID, evt);
+ }
}
}
From 2fbff4775289cd150ec5ea1e31d2ae351617eb7a Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Fri, 3 Apr 2020 19:35:39 +0200
Subject: [PATCH 08/38] Implemented GroupCreationProcessor and
GroupResizeProcessor
---
.../processors/GroupCreationProcessor.java | 22 ++++++--
.../processors/GroupResizeProcessor.java | 54 +++++++++++++++++++
2 files changed, 72 insertions(+), 4 deletions(-)
create mode 100644 src/main/java/envoy/server/processors/GroupResizeProcessor.java
diff --git a/src/main/java/envoy/server/processors/GroupCreationProcessor.java b/src/main/java/envoy/server/processors/GroupCreationProcessor.java
index 01b133c..90dae85 100644
--- a/src/main/java/envoy/server/processors/GroupCreationProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupCreationProcessor.java
@@ -3,7 +3,9 @@ package envoy.server.processors;
import java.io.IOException;
import envoy.event.GroupCreationEvent;
+import envoy.server.data.Contact;
import envoy.server.data.PersistenceManager;
+import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy;
/**
@@ -17,16 +19,28 @@ import envoy.server.net.ObjectWriteProxy;
public class GroupCreationProcessor implements ObjectProcessor {
private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
+ private final ConnectionManager connectionManager = ConnectionManager.getInstance();
@Override
public void process(GroupCreationEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
envoy.server.data.Group group = new envoy.server.data.Group();
group.setName(input.get());
- // TODO adjust event, so it sends a members list as well, which can be initially
- // set here
+ input.getInitialMemberIDs().stream().map(persistenceManager::getUserById).forEach(group.getContacts()::add);
+ group.getContacts().add(persistenceManager.getUserById(connectionManager.getUserIdBySocketId(socketID)));
persistenceManager.addContact(group);
- writeProxy.write(socketID, group); // TODO Prepare the client to receive the group object after sending the
- // groupCreationEvent to the server.
+ writeProxy.write(socketID, group);
+ group.getContacts()
+ .stream()
+ .map(Contact::getID)
+ .filter(connectionManager::isOnline)
+ .map(connectionManager::getSocketId)
+ .forEach(memberSocketID -> {
+ try {
+ writeProxy.write(memberSocketID, group);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
}
@Override
diff --git a/src/main/java/envoy/server/processors/GroupResizeProcessor.java b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
new file mode 100644
index 0000000..d7ee615
--- /dev/null
+++ b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
@@ -0,0 +1,54 @@
+package envoy.server.processors;
+
+import java.io.IOException;
+
+import envoy.event.GroupResizeEvent;
+import envoy.server.data.Contact;
+import envoy.server.data.PersistenceManager;
+import envoy.server.net.ConnectionManager;
+import envoy.server.net.ObjectWriteProxy;
+
+/**
+ * Project: envoy-server-standalone
+ * File: GroupResizeProcessor.java
+ * Created: 03.04.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-beta
+ */
+public class GroupResizeProcessor implements ObjectProcessor {
+
+ PersistenceManager persistenceManager = PersistenceManager.getInstance();
+ ConnectionManager connectionManager = ConnectionManager.getInstance();
+
+ @Override
+ public void process(GroupResizeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
+ envoy.server.data.Group group = persistenceManager.getGroupById(input.getGroupID());
+ switch (input.getOperation()) {
+ case ADD:
+ group.getContacts().add(persistenceManager.getUserById(input.get().getID()));
+ break;
+
+ case REMOVE:
+ group.getContacts().remove(persistenceManager.getUserById(input.get().getID()));
+ break;
+ }
+ persistenceManager.updateContact(group);
+ writeProxy.write(socketID, group);
+ group.getContacts()
+ .stream()
+ .map(Contact::getID)
+ .filter(connectionManager::isOnline)
+ .map(connectionManager::getSocketId)
+ .forEach(memberSocketID -> {
+ try {
+ writeProxy.write(memberSocketID, group);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+ }
+
+ @Override
+ public Class getInputClass() { return GroupResizeEvent.class; }
+}
From c6f0bff957f0c52c90dee8f08276f413b0fff7df Mon Sep 17 00:00:00 2001
From: delvh
Date: Mon, 6 Apr 2020 22:55:27 +0200
Subject: [PATCH 09/38] fixes #129 - contacts are now sent as a part of the
user
(if they were not already)...
Additionally renamed some methods named `...Id()` to `...ID()`
---
src/main/java/envoy/server/Startup.java | 10 +-
src/main/java/envoy/server/data/Contact.java | 17 ++-
src/main/java/envoy/server/data/Group.java | 2 +-
src/main/java/envoy/server/data/Message.java | 6 +-
.../envoy/server/data/PersistenceManager.java | 18 +--
src/main/java/envoy/server/data/User.java | 2 +-
.../envoy/server/net/ConnectionManager.java | 2 +-
.../processors/ContactOperationProcessor.java | 2 +-
.../processors/GroupCreationProcessor.java | 96 ++++++++--------
.../processors/GroupResizeProcessor.java | 108 +++++++++---------
.../IDGeneratorRequestProcessor.java | 2 +-
.../processors/LoginCredentialProcessor.java | 16 +--
.../server/processors/MessageProcessor.java | 4 +-
.../MessageStatusChangeProcessor.java | 2 +-
.../processors/NameChangeProcessor.java | 2 +-
.../processors/UserStatusChangeProcessor.java | 4 +-
16 files changed, 139 insertions(+), 154 deletions(-)
diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index a4875ba..bf30945 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -43,7 +43,10 @@ public class Startup {
processors.add(new ContactOperationProcessor());
Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
- initializeCurrentMessageId();
+ // Initialize the current message ID
+ PersistenceManager persistenceManager = PersistenceManager.getInstance();
+ if (persistenceManager.getConfigItemByID("currentMessageId") == null)
+ persistenceManager.addConfigItem(new ConfigItem("currentMessageId", "0"));
server.start();
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
@@ -53,9 +56,4 @@ public class Startup {
System.out.println("Stopped");
System.exit(0);
}
-
- private static void initializeCurrentMessageId() {
- PersistenceManager persMan = PersistenceManager.getInstance();
- if (persMan.getConfigItemById("currentMessageId") == null) persMan.addConfigItem(new ConfigItem("currentMessageId", "0"));
- }
}
diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java
index 81107d4..eea8fe1 100644
--- a/src/main/java/envoy/server/data/Contact.java
+++ b/src/main/java/envoy/server/data/Contact.java
@@ -2,14 +2,7 @@ package envoy.server.data;
import java.util.Set;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.ManyToMany;
+import javax.persistence.*;
/**
* This class acts as a superclass for all contacts, being {@link User}s and
@@ -32,7 +25,7 @@ public abstract class Contact {
protected long id;
protected String name;
- @ManyToMany(targetEntity = Contact.class, cascade = CascadeType.ALL)
+ @ManyToMany(targetEntity = Contact.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
protected Set contacts;
/**
@@ -81,4 +74,10 @@ public abstract class Contact {
* @since Envoy Server Standalone v0.1-beta
*/
public void setContacts(Set contacts) { this.contacts = contacts; }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() { return String.format("%s[id=%d,name=%s, contacts=%s]", getClass().getSimpleName(), id, name, contacts); }
}
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
index 6301624..3b6cac8 100644
--- a/src/main/java/envoy/server/data/Group.java
+++ b/src/main/java/envoy/server/data/Group.java
@@ -24,7 +24,7 @@ import envoy.data.User;
@Entity
@Table(name = "groups")
@NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName")
-public class Group extends Contact {
+public final class Group extends Contact {
/**
* {@inheritDoc}
diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java
index 17a12d8..f82658a 100755
--- a/src/main/java/envoy/server/data/Message.java
+++ b/src/main/java/envoy/server/data/Message.java
@@ -74,15 +74,15 @@ public class Message {
* @since Envoy Server Standalone v0.1-alpha
*/
public Message(envoy.data.Message message) {
- PersistenceManager persMan = PersistenceManager.getInstance();
+ PersistenceManager persistenceManager = PersistenceManager.getInstance();
id = message.getID();
status = message.getStatus();
text = message.getText();
creationDate = message.getCreationDate();
receivedDate = message.getReceivedDate();
readDate = message.getReadDate();
- sender = persMan.getUserById(message.getSenderID());
- recipient = persMan.getUserById(message.getRecipientID());
+ sender = persistenceManager.getUserByID(message.getSenderID());
+ recipient = persistenceManager.getUserByID(message.getRecipientID());
forwarded = message.isForwarded();
// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
}
diff --git a/src/main/java/envoy/server/data/PersistenceManager.java b/src/main/java/envoy/server/data/PersistenceManager.java
index 53eb670..aeecf77 100755
--- a/src/main/java/envoy/server/data/PersistenceManager.java
+++ b/src/main/java/envoy/server/data/PersistenceManager.java
@@ -37,7 +37,7 @@ public class PersistenceManager {
ConnectionManager.getInstance()
.getOnlineUsers()
.stream()
- .map(this::getUserById)
+ .map(this::getUserByID)
.forEach(user -> { user.setStatus(UserStatus.OFFLINE); user.setLastSeen(new Date()); entityManager.merge(user); });
transaction.commit();
}));
@@ -120,7 +120,7 @@ public class PersistenceManager {
* @return the user with the specified id
* @since Envoy Server Standalone v0.1-alpha
*/
- public User getUserById(long id) { return entityManager.find(User.class, id); }
+ public User getUserByID(long id) { return entityManager.find(User.class, id); }
/**
* Searches for a {@link Group} with a specific ID.
@@ -129,7 +129,7 @@ public class PersistenceManager {
* @return the group with the specific id
* @since Envoy Server Standalone v0.1-beta
*/
- public Group getGroupById(long id) { return entityManager.find(Group.class, id); }
+ public Group getGroupByID(long id) { return entityManager.find(Group.class, id); }
/**
* Searches for a {@link Contact} with a specific ID.
@@ -138,7 +138,7 @@ public class PersistenceManager {
* @return the contact with the specific id
* @since Envoy Server Standalone v0.1-beta
*/
- public Contact getContactById(long id) { return entityManager.find(Contact.class, id); }
+ public Contact getContactByID(long id) { return entityManager.find(Contact.class, id); }
/**
* Searched for a {@link User} with a specific name.
@@ -180,14 +180,14 @@ public class PersistenceManager {
* @return the message with the specified id
* @since Envoy Server Standalone v0.1-alpha
*/
- public Message getMessageById(long id) { return entityManager.find(Message.class, id); }
+ public Message getMessageByID(long id) { return entityManager.find(Message.class, id); }
/**
* @param key the name of this {@link ConfigItem}
* @return the {@link ConfigItem} with the given name
* @since Envoy Server Standalone v0.1-alpha
*/
- public ConfigItem getConfigItemById(String key) { return entityManager.find(ConfigItem.class, key); }
+ public ConfigItem getConfigItemByID(String key) { return entityManager.find(ConfigItem.class, key); }
/**
* Returns all messages received while being offline or the ones that have
@@ -217,7 +217,7 @@ public class PersistenceManager {
public List searchUsers(String searchPhrase, long userId) {
return entityManager.createNamedQuery("searchUsers")
.setParameter("searchPhrase", searchPhrase + "%")
- .setParameter("context", getUserById(userId))
+ .setParameter("context", getUserByID(userId))
.getResultList();
}
@@ -231,8 +231,8 @@ public class PersistenceManager {
public void addUserContact(long userId1, long userId2) {
// Get users by ID
- Contact u1 = getContactById(userId1);
- Contact u2 = getContactById(userId2);
+ Contact u1 = getContactByID(userId1);
+ Contact u2 = getContactByID(userId2);
// Add users to each others contact lists
u1.getContacts().add(u2);
diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java
index 2f788f0..0e63ac1 100755
--- a/src/main/java/envoy/server/data/User.java
+++ b/src/main/java/envoy/server/data/User.java
@@ -30,7 +30,7 @@ import javax.persistence.*;
name = "searchUsers"
) }
)
-public class User extends Contact {
+public final class User extends Contact {
private byte[] passwordHash;
diff --git a/src/main/java/envoy/server/net/ConnectionManager.java b/src/main/java/envoy/server/net/ConnectionManager.java
index 883f510..ef384bb 100755
--- a/src/main/java/envoy/server/net/ConnectionManager.java
+++ b/src/main/java/envoy/server/net/ConnectionManager.java
@@ -49,7 +49,7 @@ public class ConnectionManager implements ISocketIdListener {
public void socketCancelled(long socketID) {
if (!pendingSockets.remove(socketID)) {
// Notify contacts of this users offline-going
- envoy.server.data.User user = PersistenceManager.getInstance().getUserById(getUserIdBySocketId(socketID));
+ envoy.server.data.User user = PersistenceManager.getInstance().getUserByID(getUserIdBySocketId(socketID));
user.setStatus(UserStatus.OFFLINE);
user.setLastSeen(new Date());
UserStatusChangeProcessor.updateUserStatus(user);
diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
index fa67c55..e187f60 100755
--- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java
+++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
@@ -32,7 +32,7 @@ public class ContactOperationProcessor implements ObjectProcessorenvoy-server-standalone
- * File: GroupCreationProcessor.java
- * Created: 26.03.2020
- *
- * @author Maximilian Käfer
- * @since Envoy Server Standalone v0.1-beta
- */
-public class GroupCreationProcessor implements ObjectProcessor {
-
- private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
- private final ConnectionManager connectionManager = ConnectionManager.getInstance();
-
- @Override
- public void process(GroupCreationEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
- envoy.server.data.Group group = new envoy.server.data.Group();
- group.setName(input.get());
- input.getInitialMemberIDs().stream().map(persistenceManager::getUserById).forEach(group.getContacts()::add);
- group.getContacts().add(persistenceManager.getUserById(connectionManager.getUserIdBySocketId(socketID)));
- persistenceManager.addContact(group);
- writeProxy.write(socketID, group);
- group.getContacts()
- .stream()
- .map(Contact::getID)
- .filter(connectionManager::isOnline)
- .map(connectionManager::getSocketId)
- .forEach(memberSocketID -> {
- try {
- writeProxy.write(memberSocketID, group);
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
- }
-
- @Override
- public Class getInputClass() { return GroupCreationEvent.class; }
-}
+package envoy.server.processors;
+
+import java.io.IOException;
+
+import envoy.event.GroupCreationEvent;
+import envoy.server.data.Contact;
+import envoy.server.data.PersistenceManager;
+import envoy.server.net.ConnectionManager;
+import envoy.server.net.ObjectWriteProxy;
+
+/**
+ * Project: envoy-server-standalone
+ * File: GroupCreationProcessor.java
+ * Created: 26.03.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-beta
+ */
+public class GroupCreationProcessor implements ObjectProcessor {
+
+ private final PersistenceManager persistenceManager = PersistenceManager.getInstance();
+ private final ConnectionManager connectionManager = ConnectionManager.getInstance();
+
+ @Override
+ public void process(GroupCreationEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
+ envoy.server.data.Group group = new envoy.server.data.Group();
+ group.setName(input.get());
+ input.getInitialMemberIDs().stream().map(persistenceManager::getUserByID).forEach(group.getContacts()::add);
+ group.getContacts().add(persistenceManager.getUserByID(connectionManager.getUserIdBySocketId(socketID)));
+ persistenceManager.addContact(group);
+ writeProxy.write(socketID, group);
+ group.getContacts()
+ .stream()
+ .map(Contact::getID)
+ .filter(connectionManager::isOnline)
+ .map(connectionManager::getSocketId)
+ .forEach(memberSocketID -> {
+ try {
+ writeProxy.write(memberSocketID, group);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+ }
+
+ @Override
+ public Class getInputClass() { return GroupCreationEvent.class; }
+}
diff --git a/src/main/java/envoy/server/processors/GroupResizeProcessor.java b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
index d7ee615..fbf39df 100644
--- a/src/main/java/envoy/server/processors/GroupResizeProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
@@ -1,54 +1,54 @@
-package envoy.server.processors;
-
-import java.io.IOException;
-
-import envoy.event.GroupResizeEvent;
-import envoy.server.data.Contact;
-import envoy.server.data.PersistenceManager;
-import envoy.server.net.ConnectionManager;
-import envoy.server.net.ObjectWriteProxy;
-
-/**
- * Project: envoy-server-standalone
- * File: GroupResizeProcessor.java
- * Created: 03.04.2020
- *
- * @author Maximilian Käfer
- * @since Envoy Server Standalone v0.1-beta
- */
-public class GroupResizeProcessor implements ObjectProcessor {
-
- PersistenceManager persistenceManager = PersistenceManager.getInstance();
- ConnectionManager connectionManager = ConnectionManager.getInstance();
-
- @Override
- public void process(GroupResizeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
- envoy.server.data.Group group = persistenceManager.getGroupById(input.getGroupID());
- switch (input.getOperation()) {
- case ADD:
- group.getContacts().add(persistenceManager.getUserById(input.get().getID()));
- break;
-
- case REMOVE:
- group.getContacts().remove(persistenceManager.getUserById(input.get().getID()));
- break;
- }
- persistenceManager.updateContact(group);
- writeProxy.write(socketID, group);
- group.getContacts()
- .stream()
- .map(Contact::getID)
- .filter(connectionManager::isOnline)
- .map(connectionManager::getSocketId)
- .forEach(memberSocketID -> {
- try {
- writeProxy.write(memberSocketID, group);
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
- }
-
- @Override
- public Class getInputClass() { return GroupResizeEvent.class; }
-}
+package envoy.server.processors;
+
+import java.io.IOException;
+
+import envoy.event.GroupResizeEvent;
+import envoy.server.data.Contact;
+import envoy.server.data.PersistenceManager;
+import envoy.server.net.ConnectionManager;
+import envoy.server.net.ObjectWriteProxy;
+
+/**
+ * Project: envoy-server-standalone
+ * File: GroupResizeProcessor.java
+ * Created: 03.04.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-beta
+ */
+public class GroupResizeProcessor implements ObjectProcessor {
+
+ PersistenceManager persistenceManager = PersistenceManager.getInstance();
+ ConnectionManager connectionManager = ConnectionManager.getInstance();
+
+ @Override
+ public void process(GroupResizeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
+ envoy.server.data.Group group = persistenceManager.getGroupByID(input.getGroupID());
+ switch (input.getOperation()) {
+ case ADD:
+ group.getContacts().add(persistenceManager.getUserByID(input.get()));
+ break;
+
+ case REMOVE:
+ group.getContacts().remove(persistenceManager.getUserByID(input.get()));
+ break;
+ }
+ persistenceManager.updateContact(group);
+ writeProxy.write(socketID, group);
+ group.getContacts()
+ .stream()
+ .map(Contact::getID)
+ .filter(connectionManager::isOnline)
+ .map(connectionManager::getSocketId)
+ .forEach(memberSocketID -> {
+ try {
+ writeProxy.write(memberSocketID, group);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+ }
+
+ @Override
+ public Class getInputClass() { return GroupResizeEvent.class; }
+}
diff --git a/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java b/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
index 6d27a93..4a00618 100755
--- a/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
+++ b/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
@@ -44,7 +44,7 @@ public class IDGeneratorRequestProcessor implements ObjectProcessor pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
- for (Message msg : pendingMessages) {
+ for (Message msg : pendingMessages)
if (msg.getStatus() == MessageStatus.SENT) {
System.out.println("Sending message " + msg.toCommonMessage());
writeProxy.write(socketID, msg.toCommonMessage());
@@ -79,7 +68,6 @@ public class LoginCredentialProcessor implements ObjectProcessor {
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
message.nextStatus();
ConnectionManager connectionManager = ConnectionManager.getInstance();
- Contact recipient = PersistenceManager.getInstance().getContactById(message.getID());
+ Contact recipient = PersistenceManager.getInstance().getContactByID(message.getID());
if (recipient instanceof envoy.server.data.User) {
System.out.println("The received message is a direct message.");
@@ -43,7 +43,7 @@ public class MessageProcessor implements ObjectProcessor {
}
} else {
System.out.println("The received message is a group message.");
- final var members = PersistenceManager.getInstance().getGroupById(message.getRecipientID()).getContacts();
+ final var members = PersistenceManager.getInstance().getGroupByID(message.getRecipientID()).getContacts();
final var generator = IDGeneratorRequestProcessor.createIDGenerator(members.size());
members.forEach(user -> {
envoy.data.Message returnMessage = new MessageBuilder(message.getRecipientID(), user.getID(), generator)
diff --git a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
index 587fd0e..d88e120 100755
--- a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
@@ -27,7 +27,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor {
public void process(NameChangeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
PersistenceManager persistenceManager = PersistenceManager.getInstance();
ConnectionManager connectionManager = ConnectionManager.getInstance();
- Contact toUpdate = persistenceManager.getContactById(input.getID());
+ Contact toUpdate = persistenceManager.getContactByID(input.getID());
toUpdate.setName(input.get());
persistenceManager.updateContact(toUpdate);
diff --git a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
index 68547fc..ad63480 100755
--- a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
@@ -30,7 +30,7 @@ public class UserStatusChangeProcessor implements ObjectProcessor
Date: Thu, 9 Apr 2020 13:53:06 +0200
Subject: [PATCH 10/38] Fixed several errors in GroupResizeProcessor
* a common user was passed to the persistence manager instead of its ID
* a server group was sent to its members instead of the common group
---
.../processors/GroupResizeProcessor.java | 23 ++++++++++++-------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/main/java/envoy/server/processors/GroupResizeProcessor.java b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
index fbf39df..7bcc72a 100644
--- a/src/main/java/envoy/server/processors/GroupResizeProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
@@ -18,23 +18,30 @@ import envoy.server.net.ObjectWriteProxy;
*/
public class GroupResizeProcessor implements ObjectProcessor {
- PersistenceManager persistenceManager = PersistenceManager.getInstance();
- ConnectionManager connectionManager = ConnectionManager.getInstance();
+ private static final PersistenceManager persistenceManager = PersistenceManager.getInstance();
+ private static final ConnectionManager connectionManager = ConnectionManager.getInstance();
@Override
public void process(GroupResizeEvent input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
- envoy.server.data.Group group = persistenceManager.getGroupByID(input.getGroupID());
+
+ // Acquire the group to resize from the database
+ var group = persistenceManager.getGroupByID(input.getGroupID());
+
+ // Perform the desired operation
switch (input.getOperation()) {
case ADD:
- group.getContacts().add(persistenceManager.getUserByID(input.get()));
+ group.getContacts().add(persistenceManager.getUserByID(input.get().getID()));
break;
-
case REMOVE:
- group.getContacts().remove(persistenceManager.getUserByID(input.get()));
+ group.getContacts().remove(persistenceManager.getUserByID(input.get().getID()));
break;
}
+
+ // Update the group in the database
persistenceManager.updateContact(group);
- writeProxy.write(socketID, group);
+
+ // Send the updated group to all of its members
+ var commonGroup = group.toCommon();
group.getContacts()
.stream()
.map(Contact::getID)
@@ -42,7 +49,7 @@ public class GroupResizeProcessor implements ObjectProcessor {
.map(connectionManager::getSocketId)
.forEach(memberSocketID -> {
try {
- writeProxy.write(memberSocketID, group);
+ writeProxy.write(memberSocketID, commonGroup);
} catch (IOException e) {
e.printStackTrace();
}
From 8096d3ff584ff7e1ee367c9bb712ee505bff32d6 Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Thu, 9 Apr 2020 14:15:39 +0200
Subject: [PATCH 11/38] Configured the project to use Hibernate validation
This requires the Hibernate Tools (a part of JBoss Tools) to be
installed in Eclipse.
---
.project | 6 ++++
...se.wst.common.project.facet.core.prefs.xml | 0
....eclipse.wst.common.project.facet.core.xml | 2 +-
src/main/java/envoy/server/data/Group.java | 2 +-
src/main/java/envoy/server/data/User.java | 31 +++++++++----------
5 files changed, 23 insertions(+), 18 deletions(-)
mode change 100755 => 100644 .settings/org.eclipse.wst.common.project.facet.core.prefs.xml
diff --git a/.project b/.project
index fdd0c87..d6ba176 100755
--- a/.project
+++ b/.project
@@ -25,10 +25,16 @@
+
+ org.hibernate.eclipse.console.hibernateBuilder
+
+
+
org.eclipse.jdt.core.javanature
org.eclipse.m2e.core.maven2Nature
org.eclipse.wst.common.project.facet.core.nature
+ org.hibernate.eclipse.console.hibernateNature
diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
old mode 100755
new mode 100644
diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml
index 2fcb919..fe1f404 100755
--- a/.settings/org.eclipse.wst.common.project.facet.core.xml
+++ b/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
index 3b6cac8..6301624 100644
--- a/src/main/java/envoy/server/data/Group.java
+++ b/src/main/java/envoy/server/data/Group.java
@@ -24,7 +24,7 @@ import envoy.data.User;
@Entity
@Table(name = "groups")
@NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName")
-public final class Group extends Contact {
+public class Group extends Contact {
/**
* {@inheritDoc}
diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java
index 0e63ac1..fa6db47 100755
--- a/src/main/java/envoy/server/data/User.java
+++ b/src/main/java/envoy/server/data/User.java
@@ -5,11 +5,12 @@ import java.util.stream.Collectors;
import javax.persistence.*;
+import envoy.data.User.UserStatus;
+
/**
- * This class serves as a way to let Hibernate communicate with the server
- * without bringing the dependency of JPA/Hibernate into the client.
- * It will be referenced as "database user" to clarify between the different
- * user objects.
+ * This class enables the storage of user specific data inside a database using
+ * Hibernate. Its objects will be referred to as database users as opposed to
+ * the common user objects present on both the client and the server.
*
* Project: envoy-server-standalone
* File: User.java
@@ -30,13 +31,14 @@ import javax.persistence.*;
name = "searchUsers"
) }
)
-public final class User extends Contact {
+public class User extends Contact {
private byte[] passwordHash;
@Temporal(TemporalType.TIMESTAMP)
- private Date lastSeen;
- private envoy.data.User.UserStatus status;
+ private Date lastSeen;
+
+ private UserStatus status;
/**
* {@inheritDoc}
@@ -47,7 +49,7 @@ public final class User extends Contact {
}
/**
- * @return the passwordHash of a {link envoy.data.User}
+ * @return the password hash
* @since Envoy Server Standalone v0.1-alpha
*/
public byte[] getPasswordHash() { return passwordHash; }
@@ -55,33 +57,30 @@ public final class User extends Contact {
/**
* @param passwordHash the password hash to set
* @since Envoy Server Standalone v0.1-alpha
- * @see User#getPasswordHash()
*/
public void setPasswordHash(byte[] passwordHash) { this.passwordHash = passwordHash; }
/**
- * @return the last date an {link envoy.data.User} has been online
+ * @return the last date the user has been online
* @since Envoy Server Standalone v0.1-alpha
*/
public Date getLastSeen() { return lastSeen; }
/**
- * @param lastSeen the latest date at which has been seen to set
+ * @param lastSeen the latest date at which the user has been online to set
* @since Envoy Server Standalone v0.1-alpha
- * @see User#getLastSeen()
*/
public void setLastSeen(Date lastSeen) { this.lastSeen = lastSeen; }
/**
- * @return the status of a {link envoy.data.User}
+ * @return the status
* @since Envoy Server Standalone v0.1-alpha
*/
- public envoy.data.User.UserStatus getStatus() { return status; }
+ public UserStatus getStatus() { return status; }
/**
* @param status the status to set
* @since Envoy Server Standalone v0.1-alpha
- * @see User#getStatus()
*/
- public void setStatus(envoy.data.User.UserStatus status) { this.status = status; }
+ public void setStatus(UserStatus status) { this.status = status; }
}
From 97545fc28531a8a40e95242c444e20e3b86b05b0 Mon Sep 17 00:00:00 2001
From: delvh
Date: Thu, 9 Apr 2020 21:01:19 +0200
Subject: [PATCH 12/38] Contact conversion does not result in endless recursion
anymore
---
src/main/java/envoy/server/data/Contact.java | 10 ++++++++++
src/main/java/envoy/server/data/Group.java | 10 +++++++---
src/main/java/envoy/server/data/User.java | 9 ++++++++-
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java
index eea8fe1..b629c37 100644
--- a/src/main/java/envoy/server/data/Contact.java
+++ b/src/main/java/envoy/server/data/Contact.java
@@ -35,6 +35,16 @@ public abstract class Contact {
*/
public abstract envoy.data.Contact toCommon();
+ /**
+ * Transforms this contact into a {@link envoy.data.Contact} where the contacts
+ * set of contacts is empty.
+ *
+ * @return a {@link envoy.data.Contact} object of this contact
+ * object.
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ protected abstract envoy.data.Contact toFlatCommon();
+
/**
* @return the ID of this contact.
* @since Envoy Server Standalone v0.1-beta
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
index 6301624..595b252 100644
--- a/src/main/java/envoy/server/data/Group.java
+++ b/src/main/java/envoy/server/data/Group.java
@@ -6,8 +6,6 @@ import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
-import envoy.data.User;
-
/**
* This class serves as a way to let Hibernate communicate with the server
* without bringing the dependency of JPA/Hibernate into the client.
@@ -31,6 +29,12 @@ public class Group extends Contact {
*/
@Override
public envoy.data.Group toCommon() {
- return new envoy.data.Group(id, name, contacts.parallelStream().map(Contact::toCommon).map(User.class::cast).collect(Collectors.toSet()));
+ return new envoy.data.Group(id, name, contacts.parallelStream().map(User.class::cast).map(User::toFlatCommon).collect(Collectors.toSet()));
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected envoy.data.Group toFlatCommon() { return toCommon(); }
}
diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java
index fa6db47..3fb167f 100755
--- a/src/main/java/envoy/server/data/User.java
+++ b/src/main/java/envoy/server/data/User.java
@@ -1,6 +1,7 @@
package envoy.server.data;
import java.util.Date;
+import java.util.Set;
import java.util.stream.Collectors;
import javax.persistence.*;
@@ -45,9 +46,15 @@ public class User extends Contact {
*/
@Override
public envoy.data.User toCommon() {
- return new envoy.data.User(id, name, status, contacts.stream().map(Contact::toCommon).collect(Collectors.toSet()));
+ return new envoy.data.User(id, name, status, contacts.parallelStream().map(Contact::toFlatCommon).collect(Collectors.toSet()));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected envoy.data.User toFlatCommon() { return new envoy.data.User(id, name, status, Set.of()); }
+
/**
* @return the password hash
* @since Envoy Server Standalone v0.1-alpha
From 551f83672e22a105b44d741d8c1856d8dd8ca5c0 Mon Sep 17 00:00:00 2001
From: delvh
Date: Thu, 9 Apr 2020 22:31:20 +0200
Subject: [PATCH 13/38] fixed bug using wrong id of message
---
.../envoy/server/processors/MessageProcessor.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/main/java/envoy/server/processors/MessageProcessor.java b/src/main/java/envoy/server/processors/MessageProcessor.java
index c265ee2..dff28ec 100755
--- a/src/main/java/envoy/server/processors/MessageProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageProcessor.java
@@ -3,6 +3,8 @@ package envoy.server.processors;
import java.io.IOException;
import java.util.Date;
+import javax.persistence.EntityExistsException;
+
import envoy.data.Message;
import envoy.data.Message.MessageStatus;
import envoy.data.MessageBuilder;
@@ -29,10 +31,9 @@ public class MessageProcessor implements ObjectProcessor {
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
message.nextStatus();
ConnectionManager connectionManager = ConnectionManager.getInstance();
- Contact recipient = PersistenceManager.getInstance().getContactByID(message.getID());
+ Contact recipient = PersistenceManager.getInstance().getContactByID(message.getRecipientID());
if (recipient instanceof envoy.server.data.User) {
- System.out.println("The received message is a direct message.");
sendToUser(connectionManager, message, writeProxy);
// Sending a messageStatusChangeEvent to the sender
try {
@@ -42,7 +43,6 @@ public class MessageProcessor implements ObjectProcessor {
e.printStackTrace();
}
} else {
- System.out.println("The received message is a group message.");
final var members = PersistenceManager.getInstance().getGroupByID(message.getRecipientID()).getContacts();
final var generator = IDGeneratorRequestProcessor.createIDGenerator(members.size());
members.forEach(user -> {
@@ -59,7 +59,11 @@ public class MessageProcessor implements ObjectProcessor {
// copies of the original message. (Not at this location)
});
}
- PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
+ try {
+ PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
+ } catch (EntityExistsException e) {
+ System.err.println("Received a message with an id that already exists");
+ }
}
private void sendToUser(ConnectionManager connectionManager, Message message, ObjectWriteProxy writeProxy) {
From a457261ee5d1fe6cf1cd15830fc0cc2409978412 Mon Sep 17 00:00:00 2001
From: delvh
Date: Fri, 10 Apr 2020 15:53:30 +0200
Subject: [PATCH 14/38] Improved Login security
---
.project | 4 ++--
.../server/processors/LoginCredentialProcessor.java | 10 +++++-----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/.project b/.project
index d6ba176..48ebc25 100755
--- a/.project
+++ b/.project
@@ -21,12 +21,12 @@
- org.eclipse.m2e.core.maven2Builder
+ org.hibernate.eclipse.console.hibernateBuilder
- org.hibernate.eclipse.console.hibernateBuilder
+ org.eclipse.m2e.core.maven2Builder
diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
index 3b4212e..5bc556f 100755
--- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
+++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
@@ -93,21 +93,21 @@ public class LoginCredentialProcessor implements ObjectProcessor
Date: Sat, 18 Apr 2020 13:27:43 +0200
Subject: [PATCH 15/38] MessageProcessor and GroupMessageProcessor
Moved groupMessage stuff form MessageProcessor to extra class and
finished both processors
---
.../processors/GroupMessageProcessor.java | 57 +++++++++++++++++++
.../server/processors/MessageProcessor.java | 36 +++---------
2 files changed, 64 insertions(+), 29 deletions(-)
create mode 100644 src/main/java/envoy/server/processors/GroupMessageProcessor.java
diff --git a/src/main/java/envoy/server/processors/GroupMessageProcessor.java b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
new file mode 100644
index 0000000..2b50e24
--- /dev/null
+++ b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
@@ -0,0 +1,57 @@
+package envoy.server.processors;
+
+import java.io.IOException;
+
+import envoy.data.GroupMessage;
+import envoy.data.Message.MessageStatus;
+import envoy.event.MessageStatusChangeEvent;
+import envoy.server.data.PersistenceManager;
+import envoy.server.net.ConnectionManager;
+import envoy.server.net.ObjectWriteProxy;
+
+/**
+ * Project: envoy-server-standalone
+ * File: GroupMessageProcessor.java
+ * Created: 18.04.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Server Standalone v0.1-beta
+ */
+public class GroupMessageProcessor implements ObjectProcessor {
+
+ @Override
+ public void process(GroupMessage groupMessage, long socketID, ObjectWriteProxy writeProxy) {
+ groupMessage.nextStatus();
+ ConnectionManager connectionManager = ConnectionManager.getInstance();
+ try {
+ writeProxy.write(socketID, new MessageStatusChangeEvent(groupMessage));
+ } catch (IOException e) {
+ System.err.println("Could not send messageStatusChangeEvent to the sender of this groupMessage with ID: " + groupMessage.getID());
+ e.printStackTrace();
+ }
+
+ final var members = PersistenceManager.getInstance().getGroupByID(groupMessage.getRecipientID()).getContacts();
+ members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); });
+ // TODO if all member message statuses are RECEIVED, send
+ // messageStatusChangeEvent to all members (we need to know if the sender is in
+ // the member list as well. If so insert continue on the loop one line above. If
+ // not we need to send the messageStatusChangeEvent separately to the sender).
+
+ // TODO Implement separate DB entity for groupMesages so we can persist here.
+ }
+
+ private void sendToMember(ConnectionManager connectionManager, GroupMessage groupMessage, long memberID, ObjectWriteProxy writeProxy) {
+ if (connectionManager.isOnline(memberID)) try {
+ // Update the message status of the member to RECEIVED
+ groupMessage.getMemberStatuses().replace(memberID, MessageStatus.RECEIVED);
+ // If recipient is online, send the groupMessage directly
+ writeProxy.write(connectionManager.getSocketId(memberID), groupMessage);
+ } catch (IOException e) {
+ System.err.println("Recipient online. Failed to send message" + groupMessage.getID());
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public Class getInputClass() { return GroupMessage.class; }
+}
diff --git a/src/main/java/envoy/server/processors/MessageProcessor.java b/src/main/java/envoy/server/processors/MessageProcessor.java
index dff28ec..ce86408 100755
--- a/src/main/java/envoy/server/processors/MessageProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageProcessor.java
@@ -6,10 +6,7 @@ import java.util.Date;
import javax.persistence.EntityExistsException;
import envoy.data.Message;
-import envoy.data.Message.MessageStatus;
-import envoy.data.MessageBuilder;
import envoy.event.MessageStatusChangeEvent;
-import envoy.server.data.Contact;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy;
@@ -31,33 +28,14 @@ public class MessageProcessor implements ObjectProcessor {
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
message.nextStatus();
ConnectionManager connectionManager = ConnectionManager.getInstance();
- Contact recipient = PersistenceManager.getInstance().getContactByID(message.getRecipientID());
- if (recipient instanceof envoy.server.data.User) {
- sendToUser(connectionManager, message, writeProxy);
- // Sending a messageStatusChangeEvent to the sender
- try {
- writeProxy.write(socketID, new MessageStatusChangeEvent(message));
- } catch (IOException e) {
- System.err.println("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID());
- e.printStackTrace();
- }
- } else {
- final var members = PersistenceManager.getInstance().getGroupByID(message.getRecipientID()).getContacts();
- final var generator = IDGeneratorRequestProcessor.createIDGenerator(members.size());
- members.forEach(user -> {
- envoy.data.Message returnMessage = new MessageBuilder(message.getRecipientID(), user.getID(), generator)
- .setDate(message.getCreationDate())
- .setText(message.getText())
- .setAttachment(message.getAttachment())
- .setStatus(MessageStatus.SENT)
- .setForwarded(message.isForwarded())
- .build();
- sendToUser(connectionManager, returnMessage, writeProxy);
-
- // TODO Handle messageStatusChangeEvent because we have many recipients and
- // copies of the original message. (Not at this location)
- });
+ sendToUser(connectionManager, message, writeProxy);
+ // Sending a messageStatusChangeEvent to the sender
+ try {
+ writeProxy.write(socketID, new MessageStatusChangeEvent(message));
+ } catch (IOException e) {
+ System.err.println("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID());
+ e.printStackTrace();
}
try {
PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
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 16/38] 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; }
+}
From 1b81b4b3d5bfeeb59e72a4f9355d5f3421ffbf9d Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Fri, 24 Apr 2020 21:24:19 +0200
Subject: [PATCH 17/38] Use constants as query names, joined inheritance for
contacts
---
src/main/java/envoy/server/data/Contact.java | 7 +--
src/main/java/envoy/server/data/Group.java | 18 +++++---
.../java/envoy/server/data/GroupMessage.java | 13 +-----
src/main/java/envoy/server/data/Message.java | 29 +++++++-----
.../envoy/server/data/PersistenceManager.java | 23 +++-------
src/main/java/envoy/server/data/User.java | 44 +++++++++++++++----
src/main/resources/META-INF/persistence.xml | 20 ++++-----
7 files changed, 89 insertions(+), 65 deletions(-)
diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java
index b629c37..c9700d5 100644
--- a/src/main/java/envoy/server/data/Contact.java
+++ b/src/main/java/envoy/server/data/Contact.java
@@ -17,15 +17,16 @@ import javax.persistence.*;
*/
@Entity
-@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Table(name = "contacts")
+@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Contact {
@Id
- @GeneratedValue(strategy = GenerationType.TABLE)
+ @GeneratedValue
protected long id;
protected String name;
- @ManyToMany(targetEntity = Contact.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
protected Set contacts;
/**
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
index 595b252..9c8ebf4 100644
--- a/src/main/java/envoy/server/data/Group.java
+++ b/src/main/java/envoy/server/data/Group.java
@@ -7,10 +7,8 @@ import javax.persistence.NamedQuery;
import javax.persistence.Table;
/**
- * This class serves as a way to let Hibernate communicate with the server
- * without bringing the dependency of JPA/Hibernate into the client.
- * It will be referenced as "database group" to clarify between the different
- * group objects.
+ * Represents a group inside the database. Referred to as "server group" as
+ * opposed to "group" from Envoy Common.
*
* Project: envoy-server-standalone
* File: Group.java
@@ -21,9 +19,19 @@ import javax.persistence.Table;
*/
@Entity
@Table(name = "groups")
-@NamedQuery(query = "SELECT g FROM Group g WHERE g.name = :name", name = "getGroupByName")
+@NamedQuery(
+ name = Group.findByName,
+ query = "SELECT g FROM Group g WHERRE g.name = :name"
+)
public class Group extends Contact {
+ /**
+ * Named query retrieving a group by name (parameter {@code :name}.
+ *
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public static final String findByName = "Group.findByName";
+
/**
* {@inheritDoc}
*/
diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java
index 0d1e2bc..f952621 100644
--- a/src/main/java/envoy/server/data/GroupMessage.java
+++ b/src/main/java/envoy/server/data/GroupMessage.java
@@ -3,14 +3,7 @@ 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;
+import javax.persistence.*;
/**
* Project: envoy-server-standalone
@@ -22,9 +15,7 @@ import javax.persistence.TemporalType;
*/
@Entity
-@Table(name = "groupMessages")
-// @NamedQuery()
-// TODO Add Queries
+@Table(name = "group_messages")
public class GroupMessage {
@Id
diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java
index f82658a..470f772 100755
--- a/src/main/java/envoy/server/data/Message.java
+++ b/src/main/java/envoy/server/data/Message.java
@@ -1,15 +1,10 @@
package envoy.server.data;
+import static javax.persistence.CascadeType.ALL;
+
import java.util.Date;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
+import javax.persistence.*;
import envoy.data.MessageBuilder;
@@ -29,20 +24,30 @@ import envoy.data.MessageBuilder;
@Entity
@Table(name = "messages")
@NamedQuery(
+ name = Message.getPending,
query = "SELECT m FROM Message m WHERE (m.recipient = :user AND m.status = envoy.data.Message$MessageStatus.SENT) "
+ "OR (m.sender = :user) AND ((m.status = envoy.data.Message$MessageStatus.RECEIVED) AND (m.receivedDate > :lastSeen)"
- + "OR (m.status = envoy.data.Message$MessageStatus.READ) AND (m.readDate > :lastSeen))",
- name = "getPendingMessages"
+ + "OR (m.status = envoy.data.Message$MessageStatus.READ) AND (m.readDate > :lastSeen))"
)
public class Message {
+ /**
+ * Named query retrieving pending messages for a user (parameter {@code :user})
+ * which was last seen after a specific date (parameter {@code :lastSeen}).
+ *
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public static final String getPending = "Message.getPending";
+
@Id
private long id;
- @ManyToOne(cascade = CascadeType.PERSIST)
+ @ManyToOne(cascade = ALL)
+ @JoinColumn
private User sender;
- @ManyToOne(cascade = CascadeType.PERSIST)
+ @ManyToOne(cascade = ALL)
+ @JoinColumn
private User recipient;
@Temporal(TemporalType.TIMESTAMP)
diff --git a/src/main/java/envoy/server/data/PersistenceManager.java b/src/main/java/envoy/server/data/PersistenceManager.java
index aeecf77..d4c9929 100755
--- a/src/main/java/envoy/server/data/PersistenceManager.java
+++ b/src/main/java/envoy/server/data/PersistenceManager.java
@@ -148,7 +148,7 @@ public class PersistenceManager {
* @since Envoy Server Standalone v0.1-alpha
*/
public User getUserByName(String name) {
- return (User) entityManager.createNamedQuery("getUserByName").setParameter("name", name).getSingleResult();
+ return (User) entityManager.createNamedQuery(User.findByName).setParameter("name", name).getSingleResult();
}
/**
@@ -159,18 +159,7 @@ public class PersistenceManager {
* @since Envoy Server Standalone v0.1-alpha
*/
public Group getGroupByName(String name) {
- return (Group) entityManager.createNamedQuery("getGroupByName").setParameter("name", name).getSingleResult();
- }
-
- /**
- * Searched for a {@link Contact} with a specific name.
- *
- * @param name the name of the contact
- * @return the contact with the specified name
- * @since Envoy Server Standalone v0.1-alpha
- */
- public Contact getContactByName(String name) {
- return (Contact) entityManager.createNamedQuery("getContactByName").setParameter("name", name).getSingleResult();
+ return (Group) entityManager.createNamedQuery(Group.findByName).setParameter("name", name).getSingleResult();
}
/**
@@ -198,7 +187,8 @@ public class PersistenceManager {
* @since Envoy Server Standalone v0.1-alpha
*/
public List getPendingMessages(User user) {
- return entityManager.createNamedQuery("getPendingMessages")
+ return entityManager
+ .createNamedQuery(Message.getPending)
.setParameter("user", user)
.setParameter("lastSeen", user.getLastSeen())
.getResultList();
@@ -215,7 +205,8 @@ public class PersistenceManager {
* @since Envoy Server Standalone v0.1-alpha
*/
public List searchUsers(String searchPhrase, long userId) {
- return entityManager.createNamedQuery("searchUsers")
+ return entityManager.createNamedQuery(
+ User.searchByName)
.setParameter("searchPhrase", searchPhrase + "%")
.setParameter("context", getUserByID(userId))
.getResultList();
@@ -251,7 +242,7 @@ public class PersistenceManager {
* @since Envoy Server Standalone v0.1-alpha
*/
public List getContacts(User user) {
- return entityManager.createNamedQuery("getContactsOfUser").setParameter("user", user).getResultList();
+ return entityManager.createNamedQuery(User.findContacts).setParameter("user", user).getResultList();
}
private void persist(Object obj) {
diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java
index 3fb167f..fba93ab 100755
--- a/src/main/java/envoy/server/data/User.java
+++ b/src/main/java/envoy/server/data/User.java
@@ -23,17 +23,45 @@ import envoy.data.User.UserStatus;
*/
@Entity
@Table(name = "users")
-@NamedQueries(
- { @NamedQuery(query = "SELECT u FROM User u WHERE u.name = :name", name = "getUserByName"), @NamedQuery(
- query = "SELECT u.contacts FROM User u WHERE u = :user",
- name = "getContactsOfUser"
+@NamedQueries({
+ @NamedQuery(
+ name = User.findByName,
+ query = "SELECT u FROM User u WHERE u.name = :name"
+ ),
+ @NamedQuery(
+ name = User.findContacts,
+ query = "SELECT u.contacts FROM User u WHERE u = :user"
), @NamedQuery(
- query = "SELECT u FROM User u WHERE (lower(u.name) LIKE lower(:searchPhrase) AND u <> :context AND NOT :context in elements(u.contacts))",
- name = "searchUsers"
- ) }
-)
+ name = User.searchByName,
+ query = "SELECT u FROM User u WHERE (lower(u.name) LIKE lower(:searchPhrase) AND u <> :context AND NOT :context in elements(u.contacts))"
+ )
+})
public class User extends Contact {
+ /**
+ * Named query retrieving a user by name (parameter {@code :name}).
+ *
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public static final String findByName = "User.findByName";
+
+ /**
+ * Named query retrieving the contacts of a given user (parameter
+ * {@code :user}).
+ *
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public static final String findContacts = "User.findContacts";
+
+ /**
+ * Named query searching for users with a name like a search phrase (parameter
+ * {@code :searchPhrase}) that are not in the contact list of a given user
+ * (parameter {@code :context}).
+ *
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public static final String searchByName = "User.searchByName";
+
private byte[] passwordHash;
@Temporal(TemporalType.TIMESTAMP)
diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml
index 10effe7..e013e04 100755
--- a/src/main/resources/META-INF/persistence.xml
+++ b/src/main/resources/META-INF/persistence.xml
@@ -3,25 +3,25 @@
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
-
-
+
+
+ value="org.postgresql.Driver" />
-
+ value="jdbc:postgresql://localhost/envoy" />
+
+ value="envoy" />
+
+
-
+ value="org.hibernate.dialect.PostgreSQL95Dialect" />
+
-
-
\ No newline at end of file
From ab789927eb7fe6aca5c0353a8105dd29c05da548 Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Tue, 28 Apr 2020 20:08:33 +0200
Subject: [PATCH 18/38] Changed unimportant stuff
---
.../java/envoy/server/data/GroupMessage.java | 23 ++++++++++++++++++-
src/main/java/envoy/server/data/Message.java | 1 +
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java
index f952621..19233d1 100644
--- a/src/main/java/envoy/server/data/GroupMessage.java
+++ b/src/main/java/envoy/server/data/GroupMessage.java
@@ -5,6 +5,8 @@ import java.util.Map;
import javax.persistence.*;
+import envoy.data.MessageBuilder;
+
/**
* Project: envoy-server-standalone
* File: GroupMessage.java
@@ -74,7 +76,26 @@ public class GroupMessage {
// YET
}
- // TODO Implement GroupMessageBuilder and add toCommonGroupMessage method here
+ /**
+ * Converts this groupMessage into an instance of
+ * {@link envoy.data.GroupMessage}.
+ *
+ * @return a {@link envoy.data.GroupMessage} containing the same values as this
+ * groupMessage
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public envoy.data.GroupMessage toCommonGroupMessage() {
+ // TODO: Attachment
+ envoy.data.GroupMessage groupMessage = new MessageBuilder(sender.getID(), group.getID(), id).setDate(creationDate)
+ .setForwarded(forwarded)
+ .setStatus(status)
+ .setText(text)
+ // .setAttachment(attachment) TODO make this work
+ .buildGroupMessage(group.toCommon(), memberMessageStatus);
+ groupMessage.setReceivedDate(receivedDate);
+ groupMessage.setReadDate(readDate);
+ return groupMessage;
+ }
/**
* @return the id
diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java
index 470f772..a21e6b4 100755
--- a/src/main/java/envoy/server/data/Message.java
+++ b/src/main/java/envoy/server/data/Message.java
@@ -105,6 +105,7 @@ public class Message {
.setDate(creationDate)
.setStatus(status)
.setForwarded(forwarded)
+ // .setAttachment(attachment) TODO make this work
.build();
message.setReceivedDate(receivedDate);
message.setReadDate(readDate);
From 673e2f74d8bd9992da569c00aedd14555e0bd9bb Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Sat, 30 May 2020 10:49:59 +0200
Subject: [PATCH 19/38] Fix typo in JPQL query
---
src/main/java/envoy/server/data/Group.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
index 9c8ebf4..688ad4c 100644
--- a/src/main/java/envoy/server/data/Group.java
+++ b/src/main/java/envoy/server/data/Group.java
@@ -21,7 +21,7 @@ import javax.persistence.Table;
@Table(name = "groups")
@NamedQuery(
name = Group.findByName,
- query = "SELECT g FROM Group g WHERRE g.name = :name"
+ query = "SELECT g FROM Group g WHERE g.name = :name"
)
public class Group extends Contact {
From cffe9b936f7c095fe03bb3e13150c073a35450ae Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Sat, 6 Jun 2020 15:42:10 +0200
Subject: [PATCH 20/38] Make GroupMessage extend Message, prepared
GroupMessageStatus processing
---
src/main/java/envoy/server/Startup.java | 1 +
.../java/envoy/server/data/GroupMessage.java | 170 +-----------------
src/main/java/envoy/server/data/Message.java | 44 +++--
.../processors/GroupMessageProcessor.java | 31 +++-
.../processors/LoginCredentialProcessor.java | 6 +-
5 files changed, 62 insertions(+), 190 deletions(-)
diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index bf30945..0811bbb 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -36,6 +36,7 @@ public class Startup {
Set> processors = new HashSet<>();
processors.add(new LoginCredentialProcessor());
processors.add(new MessageProcessor());
+ processors.add(new GroupMessageProcessor());
processors.add(new MessageStatusChangeProcessor());
processors.add(new UserStatusChangeProcessor());
processors.add(new IDGeneratorRequestProcessor());
diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java
index 19233d1..e397c8e 100644
--- a/src/main/java/envoy/server/data/GroupMessage.java
+++ b/src/main/java/envoy/server/data/GroupMessage.java
@@ -1,9 +1,10 @@
package envoy.server.data;
-import java.util.Date;
import java.util.Map;
-import javax.persistence.*;
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Table;
import envoy.data.MessageBuilder;
@@ -18,34 +19,11 @@ import envoy.data.MessageBuilder;
@Entity
@Table(name = "group_messages")
-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;
+public class GroupMessage extends Message {
@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.
*
@@ -61,19 +39,8 @@ public class 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();
+ super(groupMessage);
memberMessageStatus = groupMessage.getMemberStatuses();
- // TODO: attachment = groupMessage.getAttachment().toByteArray();DOES NOT WORK
- // YET
}
/**
@@ -84,91 +51,20 @@ public class GroupMessage {
* groupMessage
* @since Envoy Server Standalone v0.1-beta
*/
- public envoy.data.GroupMessage toCommonGroupMessage() {
+ @Override
+ public envoy.data.GroupMessage toCommon() {
// TODO: Attachment
- envoy.data.GroupMessage groupMessage = new MessageBuilder(sender.getID(), group.getID(), id).setDate(creationDate)
+ envoy.data.GroupMessage groupMessage = new MessageBuilder(sender.getID(), recipient.getID(), id).setDate(creationDate)
.setForwarded(forwarded)
.setStatus(status)
.setText(text)
// .setAttachment(attachment) TODO make this work
- .buildGroupMessage(group.toCommon(), memberMessageStatus);
+ .buildGroupMessage((envoy.data.Group) recipient.toCommon(), memberMessageStatus);
groupMessage.setReceivedDate(receivedDate);
groupMessage.setReadDate(readDate);
return groupMessage;
}
- /**
- * @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
@@ -182,52 +78,4 @@ public class GroupMessage {
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; }
}
diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java
index a21e6b4..128b122 100755
--- a/src/main/java/envoy/server/data/Message.java
+++ b/src/main/java/envoy/server/data/Message.java
@@ -1,10 +1,17 @@
package envoy.server.data;
-import static javax.persistence.CascadeType.ALL;
-
import java.util.Date;
-import javax.persistence.*;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQuery;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import envoy.data.MessageBuilder;
@@ -23,6 +30,7 @@ import envoy.data.MessageBuilder;
*/
@Entity
@Table(name = "messages")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@NamedQuery(
name = Message.getPending,
query = "SELECT m FROM Message m WHERE (m.recipient = :user AND m.status = envoy.data.Message$MessageStatus.SENT) "
@@ -40,29 +48,29 @@ public class Message {
public static final String getPending = "Message.getPending";
@Id
- private long id;
+ protected long id;
- @ManyToOne(cascade = ALL)
+ @ManyToOne
@JoinColumn
- private User sender;
+ protected User sender;
- @ManyToOne(cascade = ALL)
+ @ManyToOne
@JoinColumn
- private User recipient;
+ protected Contact recipient;
@Temporal(TemporalType.TIMESTAMP)
- private Date creationDate;
+ protected Date creationDate;
@Temporal(TemporalType.TIMESTAMP)
- private Date receivedDate;
+ protected Date receivedDate;
@Temporal(TemporalType.TIMESTAMP)
- private Date readDate;
+ protected Date readDate;
- private String text;
- private envoy.data.Message.MessageStatus status;
- private byte[] attachment;
- private boolean forwarded;
+ protected String text;
+ protected envoy.data.Message.MessageStatus status;
+ protected byte[] attachment;
+ protected boolean forwarded;
/**
* The constructor for a database object.
@@ -87,7 +95,7 @@ public class Message {
receivedDate = message.getReceivedDate();
readDate = message.getReadDate();
sender = persistenceManager.getUserByID(message.getSenderID());
- recipient = persistenceManager.getUserByID(message.getRecipientID());
+ recipient = persistenceManager.getContactByID(message.getRecipientID());
forwarded = message.isForwarded();
// TODO: attachment = message.getAttachment().toByteArray();DOES NOT WORK YET
}
@@ -99,7 +107,7 @@ public class Message {
* message
* @since Envoy Server Standalone v0.1-alpha
*/
- public envoy.data.Message toCommonMessage() {
+ public envoy.data.Message toCommon() {
// TODO: Attachment
envoy.data.Message message = new MessageBuilder(sender.getID(), recipient.getID(), id).setText(text)
.setDate(creationDate)
@@ -142,7 +150,7 @@ public class Message {
* @return the recipient of a {link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
- public User getRecipient() { return recipient; }
+ public Contact getRecipient() { return recipient; }
/**
* @param recipient the recipient to set
diff --git a/src/main/java/envoy/server/processors/GroupMessageProcessor.java b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
index 2b50e24..e1815b3 100644
--- a/src/main/java/envoy/server/processors/GroupMessageProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
@@ -2,6 +2,8 @@ package envoy.server.processors;
import java.io.IOException;
+import javax.persistence.EntityExistsException;
+
import envoy.data.GroupMessage;
import envoy.data.Message.MessageStatus;
import envoy.event.MessageStatusChangeEvent;
@@ -31,19 +33,26 @@ public class GroupMessageProcessor implements ObjectProcessor {
}
final var members = PersistenceManager.getInstance().getGroupByID(groupMessage.getRecipientID()).getContacts();
- members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); });
- // TODO if all member message statuses are RECEIVED, send
- // messageStatusChangeEvent to all members (we need to know if the sender is in
- // the member list as well. If so insert continue on the loop one line above. If
- // not we need to send the messageStatusChangeEvent separately to the sender).
+ for (long i = 0; i < groupMessage.getMemberStatuses().keySet().size(); i++) {
+ groupMessage.getMemberStatuses().replace(i, MessageStatus.SENT);
+ }
+ members.forEach(user -> { setMemberStatus(connectionManager, groupMessage, user.getID()); });
- // TODO Implement separate DB entity for groupMesages so we can persist here.
+ // Checks if all memberMessageStatuses are RECEIVED and if so sets the
+ // groupMessage Status to RECEIVED.
+ if (!groupMessage.getMemberStatuses().containsValue(MessageStatus.SENT)) groupMessage.setStatus(MessageStatus.RECEIVED);
+
+ members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); });
+
+ try {
+ PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(groupMessage));
+ } catch (EntityExistsException e) {
+ System.err.println("Received a groupMessage with an id that already exists");
+ }
}
private void sendToMember(ConnectionManager connectionManager, GroupMessage groupMessage, long memberID, ObjectWriteProxy writeProxy) {
if (connectionManager.isOnline(memberID)) try {
- // Update the message status of the member to RECEIVED
- groupMessage.getMemberStatuses().replace(memberID, MessageStatus.RECEIVED);
// If recipient is online, send the groupMessage directly
writeProxy.write(connectionManager.getSocketId(memberID), groupMessage);
} catch (IOException e) {
@@ -52,6 +61,12 @@ public class GroupMessageProcessor implements ObjectProcessor {
}
}
+ private void setMemberStatus(ConnectionManager connectionManager, GroupMessage groupMessage, long memberID) {
+ if (connectionManager.isOnline(memberID))
+ // Update the message status of the member to RECEIVED
+ groupMessage.getMemberStatuses().replace(memberID, MessageStatus.RECEIVED);
+ }
+
@Override
public Class getInputClass() { return GroupMessage.class; }
}
diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
index 5bc556f..bae3ca0 100755
--- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
+++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
@@ -58,13 +58,13 @@ public class LoginCredentialProcessor implements ObjectProcessor pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
for (Message msg : pendingMessages)
if (msg.getStatus() == MessageStatus.SENT) {
- System.out.println("Sending message " + msg.toCommonMessage());
- writeProxy.write(socketID, msg.toCommonMessage());
+ System.out.println("Sending message " + msg.toCommon());
+ writeProxy.write(socketID, msg.toCommon());
msg.setReceivedDate(new Date());
msg.setStatus(MessageStatus.RECEIVED);
PersistenceManager.getInstance().updateMessage(msg);
} else {
- var evt = new MessageStatusChangeEvent(msg.toCommonMessage());
+ var evt = new MessageStatusChangeEvent(msg.toCommon());
System.out.println("Sending messageStatusChangeEvent " + evt);
writeProxy.write(socketID, evt);
}
From 0c5645157b032f5ebfe2d575186c433ddbec4b7a Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Sun, 7 Jun 2020 21:27:51 +0200
Subject: [PATCH 21/38] Remove illegal table declaration for single-table
inheritance hierarchy
---
src/main/java/envoy/server/data/GroupMessage.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java
index e397c8e..ad9da17 100644
--- a/src/main/java/envoy/server/data/GroupMessage.java
+++ b/src/main/java/envoy/server/data/GroupMessage.java
@@ -4,7 +4,6 @@ import java.util.Map;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
-import javax.persistence.Table;
import envoy.data.MessageBuilder;
@@ -18,7 +17,6 @@ import envoy.data.MessageBuilder;
*/
@Entity
-@Table(name = "group_messages")
public class GroupMessage extends Message {
@ElementCollection
From f4301caba7afc6aa5d09f54fa83819237e9b8f57 Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Tue, 9 Jun 2020 17:05:52 +0200
Subject: [PATCH 22/38] Send ContactOperationEvent to the added contact
+ Updated formatter
---
.settings/org.eclipse.jdt.core.prefs | 361 ++++++++++++++++++
.settings/org.eclipse.jdt.ui.prefs | 2 +
.../processors/ContactOperationProcessor.java | 7 +-
3 files changed, 367 insertions(+), 3 deletions(-)
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index 5be8ad6..41ac628 100755
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -113,3 +113,364 @@ org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=11
+org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=true
+org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=1
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=true
+org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=true
+org.eclipse.jdt.core.formatter.align_with_spaces=false
+org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=84
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=80
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=20
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
+org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
+org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=84
+org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0
+org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0
+org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0
+org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=0
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=1
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=true
+org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=true
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
+org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=true
+org.eclipse.jdt.core.formatter.comment.format_header=true
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=true
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=false
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=false
+org.eclipse.jdt.core.formatter.comment.indent_tag_description=false
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert
+org.eclipse.jdt.core.formatter.comment.line_length=80
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=true
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
+org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert
+org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
+org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=false
+org.eclipse.jdt.core.formatter.join_wrapped_lines=true
+org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_if_single_item
+org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_if_empty
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=true
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_if_single_item
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_always
+org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_if_empty
+org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_if_single_item
+org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=true
+org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=true
+org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never
+org.eclipse.jdt.core.formatter.lineSplit=150
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
+org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=separate_lines_if_wrapped
+org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines
+org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.text_block_indentation=0
+org.eclipse.jdt.core.formatter.use_on_off_tags=false
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
+org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
+org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true
+org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
+org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs
index a2fdc79..cb37178 100755
--- a/.settings/org.eclipse.jdt.ui.prefs
+++ b/.settings/org.eclipse.jdt.ui.prefs
@@ -1,3 +1,5 @@
eclipse.preferences.version=1
+formatter_profile=_KSKE
+formatter_settings_version=18
org.eclipse.jdt.ui.javadoc=true
org.eclipse.jdt.ui.text.custom_code_templates=/**\n * @return the ${bare_field_name}\n * @since Envoy Server Standalone v0.1-beta\n *//**\n * @param ${param} the ${bare_field_name} to set\n * @since Envoy Server Standalone v0.1-beta\n *//**\n * Creates an instance of @link{${enclosing_type}}.\n *\n * ${tags}\n * @since Envoy Server Standalone v0.1-beta\n *//**\n * Project\: <strong>${project_name}</strong><br>\n * File\: <strong>${file_name}</strong><br>\n * Created\: <strong>${date}</strong><br>\n * \n * @author ${user}\n * @since Envoy Server Standalone v0.1-beta\n *//**\n * ${tags}\n * @since Envoy Server Standalone v0.1-beta\n *//**\n * @author ${user}\n *\n * ${tags}\n * @since Envoy Server Standalone v0.1-beta\n *//**\n * {@inheritDoc}\n *//**\n * ${tags}\n * ${see_to_target}\n * @since Envoy Server Standalone v0.1-beta\n */${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}\n\n\n\n${exception_var}.printStackTrace();${body_statement}\n${body_statement}\nreturn ${field};${field} \= ${param};
diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
index e187f60..c218059 100755
--- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java
+++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
@@ -1,8 +1,8 @@
package envoy.server.processors;
import java.io.IOException;
-import java.util.Arrays;
+import envoy.event.ElementOperation;
import envoy.event.contact.ContactOperationEvent;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
@@ -31,8 +31,9 @@ public class ContactOperationProcessor implements ObjectProcessor
Date: Tue, 9 Jun 2020 17:06:18 +0200
Subject: [PATCH 23/38] Add SQL script for dropping all tables
---
drop_all_tables.sql | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 drop_all_tables.sql
diff --git a/drop_all_tables.sql b/drop_all_tables.sql
new file mode 100644
index 0000000..bc70b26
--- /dev/null
+++ b/drop_all_tables.sql
@@ -0,0 +1,4 @@
+DROP SCHEMA public CASCADE;
+CREATE SCHEMA public;
+GRANT ALL ON SCHEMA public TO postgres;
+GRANT ALL ON SCHEMA public TO public;
\ No newline at end of file
From 90103d5c499f338245a2e47e4cdf9fc80f4dd400 Mon Sep 17 00:00:00 2001
From: delvh
Date: Tue, 9 Jun 2020 18:18:13 +0200
Subject: [PATCH 24/38] Added debugging statement when sending an object
---
src/main/java/envoy/server/net/ObjectWriteProxy.java | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/main/java/envoy/server/net/ObjectWriteProxy.java b/src/main/java/envoy/server/net/ObjectWriteProxy.java
index 238e817..bc37885 100755
--- a/src/main/java/envoy/server/net/ObjectWriteProxy.java
+++ b/src/main/java/envoy/server/net/ObjectWriteProxy.java
@@ -37,14 +37,16 @@ public class ObjectWriteProxy {
*/
public void write(long recipientSocketID, Object obj) throws IOException {
// Create message targeted at the client
- Message response = writeProxy.getMessage();
+ final Message response = writeProxy.getMessage();
response.socketId = recipientSocketID;
+ System.out.println("Sending object " + obj);
+
// Serialize object to byte array
- byte[] objBytes = SerializationUtils.writeToByteArray(obj);
+ final byte[] objBytes = SerializationUtils.writeToByteArray(obj);
// Acquire object length in bytes
- byte[] objLen = SerializationUtils.intToBytes(objBytes.length);
+ final byte[] objLen = SerializationUtils.intToBytes(objBytes.length);
response.writeToMessage(objLen);
response.writeToMessage(objBytes);
From 47e03dc4f46d475d6cd3619e8dd0a1f738124cb5 Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Tue, 9 Jun 2020 21:05:30 +0200
Subject: [PATCH 25/38] Started implementing group message status handling
* Group creation works
---
src/main/java/envoy/server/Startup.java | 12 ++++++++-
.../java/envoy/server/data/GroupMessage.java | 27 ++++++++++++++++---
.../processors/GroupCreationProcessor.java | 9 +++++--
.../processors/GroupMessageProcessor.java | 7 ++---
4 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index 0811bbb..bdcac7d 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -11,7 +11,16 @@ import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader;
-import envoy.server.processors.*;
+import envoy.server.processors.ContactOperationProcessor;
+import envoy.server.processors.ContactsRequestEventProcessor;
+import envoy.server.processors.GroupCreationProcessor;
+import envoy.server.processors.GroupMessageProcessor;
+import envoy.server.processors.IDGeneratorRequestProcessor;
+import envoy.server.processors.LoginCredentialProcessor;
+import envoy.server.processors.MessageProcessor;
+import envoy.server.processors.MessageStatusChangeProcessor;
+import envoy.server.processors.ObjectProcessor;
+import envoy.server.processors.UserStatusChangeProcessor;
/**
* Starts the server.
@@ -36,6 +45,7 @@ public class Startup {
Set> processors = new HashSet<>();
processors.add(new LoginCredentialProcessor());
processors.add(new MessageProcessor());
+ processors.add(new GroupCreationProcessor());
processors.add(new GroupMessageProcessor());
processors.add(new MessageStatusChangeProcessor());
processors.add(new UserStatusChangeProcessor());
diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java
index ad9da17..bc9fed7 100644
--- a/src/main/java/envoy/server/data/GroupMessage.java
+++ b/src/main/java/envoy/server/data/GroupMessage.java
@@ -1,9 +1,12 @@
package envoy.server.data;
+import java.util.Date;
import java.util.Map;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import envoy.data.MessageBuilder;
@@ -22,6 +25,9 @@ public class GroupMessage extends Message {
@ElementCollection
private Map memberMessageStatus;
+ @Temporal(TemporalType.TIMESTAMP)
+ protected Date lastStatusChangeDate;
+
/**
* The constructor for a database object.
*
@@ -32,13 +38,16 @@ public class GroupMessage extends Message {
/**
* Constructs a database groupMessage from a common groupMessage.
*
- * @param groupMessage the {@link envoy.data.GroupMessage} to convert into a
- * database {@link GroupMessage}
+ * @param groupMessage the {@link envoy.data.GroupMessage} to convert
+ * into a
+ * database {@link GroupMessage}
+ * @param lastStatusChangeDate the {@link Date} to set
* @since Envoy Server Standalone v0.1-beta
*/
- public GroupMessage(envoy.data.GroupMessage groupMessage) {
+ public GroupMessage(envoy.data.GroupMessage groupMessage, Date lastStatusChangeDate) {
super(groupMessage);
memberMessageStatus = groupMessage.getMemberStatuses();
+ this.lastStatusChangeDate = lastStatusChangeDate;
}
/**
@@ -76,4 +85,16 @@ public class GroupMessage extends Message {
public void setMemberMessageStatus(Map memberMessageStatus) {
this.memberMessageStatus = memberMessageStatus;
}
+
+ /**
+ * @return the date at which one of the member statuses changed last
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public Date getLastStatusChangeDate() { return lastStatusChangeDate; }
+
+ /**
+ * @param date the date to set
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public void setLastStatusChangeDate(Date date) { lastStatusChangeDate = date; }
}
diff --git a/src/main/java/envoy/server/processors/GroupCreationProcessor.java b/src/main/java/envoy/server/processors/GroupCreationProcessor.java
index 7bb71b3..8e4cf1b 100644
--- a/src/main/java/envoy/server/processors/GroupCreationProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupCreationProcessor.java
@@ -1,8 +1,11 @@
package envoy.server.processors;
import java.io.IOException;
+import java.util.HashSet;
+import envoy.event.ElementOperation;
import envoy.event.GroupCreationEvent;
+import envoy.event.contact.ContactOperationEvent;
import envoy.server.data.Contact;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
@@ -25,10 +28,12 @@ public class GroupCreationProcessor implements ObjectProcessor());
input.getInitialMemberIDs().stream().map(persistenceManager::getUserByID).forEach(group.getContacts()::add);
+ group.getContacts().add(persistenceManager.getContactByID(connectionManager.getUserIdBySocketId(socketID)));
+ group.getContacts().forEach(c -> c.getContacts().add(group));
group.getContacts().add(persistenceManager.getUserByID(connectionManager.getUserIdBySocketId(socketID)));
persistenceManager.addContact(group);
- writeProxy.write(socketID, group);
group.getContacts()
.stream()
.map(Contact::getID)
@@ -36,7 +41,7 @@ public class GroupCreationProcessor implements ObjectProcessor {
try {
- writeProxy.write(memberSocketID, group);
+ writeProxy.write(memberSocketID, new ContactOperationEvent(group.toCommon(), ElementOperation.ADD));
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/main/java/envoy/server/processors/GroupMessageProcessor.java b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
index e1815b3..48f1441 100644
--- a/src/main/java/envoy/server/processors/GroupMessageProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
@@ -1,6 +1,7 @@
package envoy.server.processors;
import java.io.IOException;
+import java.util.Date;
import javax.persistence.EntityExistsException;
@@ -33,7 +34,7 @@ public class GroupMessageProcessor implements ObjectProcessor {
}
final var members = PersistenceManager.getInstance().getGroupByID(groupMessage.getRecipientID()).getContacts();
- for (long i = 0; i < groupMessage.getMemberStatuses().keySet().size(); i++) {
+ for (long i = 0; i < groupMessage.getMemberStatuses().size(); i++) {
groupMessage.getMemberStatuses().replace(i, MessageStatus.SENT);
}
members.forEach(user -> { setMemberStatus(connectionManager, groupMessage, user.getID()); });
@@ -45,9 +46,9 @@ public class GroupMessageProcessor implements ObjectProcessor {
members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); });
try {
- PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(groupMessage));
+ PersistenceManager.getInstance().addMessage(new envoy.server.data.GroupMessage(groupMessage, new Date()));
} catch (EntityExistsException e) {
- System.err.println("Received a groupMessage with an id that already exists");
+ System.err.println("Received a groupMessage with an ID that already exists");
}
}
From 693ef0875d7f7fa74f0327851b5758af8f412d41 Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Wed, 10 Jun 2020 23:01:10 +0200
Subject: [PATCH 26/38] Fixed invalid MessageStatusChangeEvent sending
The sender got a messageStatusChangeEvent even if the status was still
sent from the server and couldn't process it.
The server does not send this unnecessary event even more
---
.../envoy/server/processors/MessageProcessor.java | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/main/java/envoy/server/processors/MessageProcessor.java b/src/main/java/envoy/server/processors/MessageProcessor.java
index ce86408..75757ab 100755
--- a/src/main/java/envoy/server/processors/MessageProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageProcessor.java
@@ -6,6 +6,7 @@ import java.util.Date;
import javax.persistence.EntityExistsException;
import envoy.data.Message;
+import envoy.data.Message.MessageStatus;
import envoy.event.MessageStatusChangeEvent;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
@@ -30,12 +31,14 @@ public class MessageProcessor implements ObjectProcessor {
ConnectionManager connectionManager = ConnectionManager.getInstance();
sendToUser(connectionManager, message, writeProxy);
- // Sending a messageStatusChangeEvent to the sender
- try {
- writeProxy.write(socketID, new MessageStatusChangeEvent(message));
- } catch (IOException e) {
- System.err.println("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID());
- e.printStackTrace();
+ if (message.getStatus() != MessageStatus.SENT) {
+ // Sending a messageStatusChangeEvent to the sender
+ try {
+ writeProxy.write(socketID, new MessageStatusChangeEvent(message));
+ } catch (IOException e) {
+ System.err.println("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID());
+ e.printStackTrace();
+ }
}
try {
PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
From 135e9b7f7676de2429f9c2446f38a8a15761886e Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Wed, 10 Jun 2020 23:23:35 +0200
Subject: [PATCH 27/38] Fixed issue regarding the sender of a message not
getting an MSCEvent
Added messageStatusChangeEvent sending to online sender if recipient
logs in and sender is online at the same time
---
.../envoy/server/processors/LoginCredentialProcessor.java | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
index bae3ca0..2835043 100755
--- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
+++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
@@ -62,6 +62,11 @@ public class LoginCredentialProcessor implements ObjectProcessor
Date: Thu, 11 Jun 2020 10:43:43 +0200
Subject: [PATCH 28/38] Fix privileges in drop_all_tables.sql
---
drop_all_tables.sql | 1 +
1 file changed, 1 insertion(+)
diff --git a/drop_all_tables.sql b/drop_all_tables.sql
index bc70b26..71f8a44 100644
--- a/drop_all_tables.sql
+++ b/drop_all_tables.sql
@@ -1,4 +1,5 @@
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO postgres;
+GRANT ALL ON SCHEMA public TO envoy;
GRANT ALL ON SCHEMA public TO public;
\ No newline at end of file
From 744f55de582e1f39033dda598e95486b7c75f334 Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Thu, 11 Jun 2020 11:17:22 +0200
Subject: [PATCH 29/38] Resolved JPA validation errors
These were partially caused by an old Hibernate validator which has now
been replaced by the EclipseLink validator for the current JPA standard.
Another error was caused by the use of non-standard JPQL in the user
search query which has now been replaced by a standardized one.
---
.settings/org.eclipse.jpt.core.prefs | 2 +-
src/main/java/envoy/server/data/User.java | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/.settings/org.eclipse.jpt.core.prefs b/.settings/org.eclipse.jpt.core.prefs
index 8aa2bb2..bc24399 100755
--- a/.settings/org.eclipse.jpt.core.prefs
+++ b/.settings/org.eclipse.jpt.core.prefs
@@ -1,3 +1,3 @@
eclipse.preferences.version=1
-org.eclipse.jpt.core.platform=hibernate2_1
+org.eclipse.jpt.core.platform=eclipselink2_5
org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=true
diff --git a/src/main/java/envoy/server/data/User.java b/src/main/java/envoy/server/data/User.java
index fba93ab..f1076c1 100755
--- a/src/main/java/envoy/server/data/User.java
+++ b/src/main/java/envoy/server/data/User.java
@@ -31,9 +31,10 @@ import envoy.data.User.UserStatus;
@NamedQuery(
name = User.findContacts,
query = "SELECT u.contacts FROM User u WHERE u = :user"
- ), @NamedQuery(
+ ),
+ @NamedQuery(
name = User.searchByName,
- query = "SELECT u FROM User u WHERE (lower(u.name) LIKE lower(:searchPhrase) AND u <> :context AND NOT :context in elements(u.contacts))"
+ query = "SELECT u FROM User u WHERE (lower(u.name) LIKE lower(:searchPhrase) AND u <> :context AND :context NOT MEMBER OF u.contacts)"
)
})
public class User extends Contact {
From 2f0fccb5362ec17c96aa82db936439350a2bc050 Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Thu, 11 Jun 2020 11:45:17 +0200
Subject: [PATCH 30/38] Use EnvoyLog for all packages
---
src/main/java/envoy/server/Startup.java | 43 +++++++++++++++++--------
1 file changed, 30 insertions(+), 13 deletions(-)
diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index bdcac7d..c14423f 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -1,26 +1,22 @@
package envoy.server;
+import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
+import java.util.logging.Level;
import com.jenkov.nioserver.Server;
-import envoy.server.data.ConfigItem;
+import envoy.data.Config;
+import envoy.data.ConfigItem;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader;
-import envoy.server.processors.ContactOperationProcessor;
-import envoy.server.processors.ContactsRequestEventProcessor;
-import envoy.server.processors.GroupCreationProcessor;
-import envoy.server.processors.GroupMessageProcessor;
-import envoy.server.processors.IDGeneratorRequestProcessor;
-import envoy.server.processors.LoginCredentialProcessor;
-import envoy.server.processors.MessageProcessor;
-import envoy.server.processors.MessageStatusChangeProcessor;
-import envoy.server.processors.ObjectProcessor;
-import envoy.server.processors.UserStatusChangeProcessor;
+import envoy.server.processors.*;
+import envoy.util.EnvoyLog;
/**
* Starts the server.
@@ -34,6 +30,25 @@ import envoy.server.processors.UserStatusChangeProcessor;
*/
public class Startup {
+ /**
+ * Initializes the logger with a new config instance.
+ *
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ private static void initLogging() {
+ final var items = new HashMap>();
+ items.put("homeDirectory",
+ new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy-server"), true));
+ items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.SEVERE, true));
+ items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.INFO, true));
+
+ final var config = new Config();
+ config.load(items);
+
+ EnvoyLog.initialize(config);
+ EnvoyLog.attach("");
+ }
+
/**
* Starts the server.
*
@@ -42,6 +57,8 @@ public class Startup {
* @since Envoy Server Standalone v0.1-alpha
*/
public static void main(String[] args) throws IOException {
+ initLogging();
+
Set> processors = new HashSet<>();
processors.add(new LoginCredentialProcessor());
processors.add(new MessageProcessor());
@@ -52,12 +69,12 @@ public class Startup {
processors.add(new IDGeneratorRequestProcessor());
processors.add(new ContactsRequestEventProcessor());
processors.add(new ContactOperationProcessor());
- Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
+ Server server = new Server(8080, ObjectMessageReader::new, new ObjectMessageProcessor(processors));
// Initialize the current message ID
PersistenceManager persistenceManager = PersistenceManager.getInstance();
if (persistenceManager.getConfigItemByID("currentMessageId") == null)
- persistenceManager.addConfigItem(new ConfigItem("currentMessageId", "0"));
+ persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0"));
server.start();
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
From bf60e9675d6c95a6e9db55b0d7027e6f1dd8707a Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Thu, 11 Jun 2020 12:06:06 +0200
Subject: [PATCH 31/38] Replaces print statements by logger calls
Closes #34
---
src/main/java/envoy/server/Startup.java | 2 +-
.../server/net/ObjectMessageProcessor.java | 8 ++++++--
.../envoy/server/net/ObjectWriteProxy.java | 6 +++++-
.../processors/ContactOperationProcessor.java | 7 +++++--
.../processors/GroupMessageProcessor.java | 10 +++++++---
.../IDGeneratorRequestProcessor.java | 7 +++++--
.../processors/LoginCredentialProcessor.java | 18 +++++++++++-------
.../server/processors/MessageProcessor.java | 11 +++++++----
.../processors/UserStatusChangeProcessor.java | 14 +++++++++-----
9 files changed, 56 insertions(+), 27 deletions(-)
diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index c14423f..e5d4fe7 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -40,7 +40,7 @@ public class Startup {
items.put("homeDirectory",
new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy-server"), true));
items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.SEVERE, true));
- items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.INFO, true));
+ items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.FINE, true));
final var config = new Config();
config.load(items);
diff --git a/src/main/java/envoy/server/net/ObjectMessageProcessor.java b/src/main/java/envoy/server/net/ObjectMessageProcessor.java
index a35f955..8fb120d 100755
--- a/src/main/java/envoy/server/net/ObjectMessageProcessor.java
+++ b/src/main/java/envoy/server/net/ObjectMessageProcessor.java
@@ -4,12 +4,14 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Set;
+import java.util.logging.Logger;
import com.jenkov.nioserver.IMessageProcessor;
import com.jenkov.nioserver.Message;
import com.jenkov.nioserver.WriteProxy;
import envoy.server.processors.ObjectProcessor;
+import envoy.util.EnvoyLog;
/**
* Handles incoming objects.
@@ -25,6 +27,8 @@ public class ObjectMessageProcessor implements IMessageProcessor {
private final Set> processors;
+ private static final Logger logger = EnvoyLog.getLogger(ObjectMessageProcessor.class);
+
/**
* The constructor to set the {@link ObjectProcessor}s.
*
@@ -39,11 +43,11 @@ public class ObjectMessageProcessor implements IMessageProcessor {
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(message.sharedArray, message.offset + 4, message.length - 4))) {
Object obj = in.readObject();
if (obj == null) {
- System.out.println("received a null object");
+ logger.warning("Received a null object");
return;
}
- System.out.println("Read object: " + obj);
+ logger.fine("Received " + obj);
// Process object
processors.stream().filter(p -> p.getInputClass().isInstance(obj)).forEach((@SuppressWarnings("rawtypes") ObjectProcessor p) -> {
diff --git a/src/main/java/envoy/server/net/ObjectWriteProxy.java b/src/main/java/envoy/server/net/ObjectWriteProxy.java
index bc37885..eea2908 100755
--- a/src/main/java/envoy/server/net/ObjectWriteProxy.java
+++ b/src/main/java/envoy/server/net/ObjectWriteProxy.java
@@ -1,10 +1,12 @@
package envoy.server.net;
import java.io.IOException;
+import java.util.logging.Logger;
import com.jenkov.nioserver.Message;
import com.jenkov.nioserver.WriteProxy;
+import envoy.util.EnvoyLog;
import envoy.util.SerializationUtils;
/**
@@ -21,6 +23,8 @@ public class ObjectWriteProxy {
private final WriteProxy writeProxy;
+ private static final Logger logger = EnvoyLog.getLogger(ObjectWriteProxy.class);
+
/**
* Creates an instance of {@link ObjectWriteProxy}.
*
@@ -40,7 +44,7 @@ public class ObjectWriteProxy {
final Message response = writeProxy.getMessage();
response.socketId = recipientSocketID;
- System.out.println("Sending object " + obj);
+ logger.fine("Sending " + obj);
// Serialize object to byte array
final byte[] objBytes = SerializationUtils.writeToByteArray(obj);
diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
index c218059..c47e516 100755
--- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java
+++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
@@ -1,12 +1,14 @@
package envoy.server.processors;
import java.io.IOException;
+import java.util.logging.Logger;
import envoy.event.ElementOperation;
import envoy.event.contact.ContactOperationEvent;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy;
+import envoy.util.EnvoyLog;
/**
* Project: envoy-server-standalone
@@ -19,6 +21,7 @@ import envoy.server.net.ObjectWriteProxy;
public class ContactOperationProcessor implements ObjectProcessor {
private static final ConnectionManager connectionManager = ConnectionManager.getInstance();
+ private static final Logger logger = EnvoyLog.getLogger(ContactOperationProcessor.class);
@Override
public void process(ContactOperationEvent evt, long socketId, ObjectWriteProxy writeProxy) throws IOException {
@@ -27,7 +30,7 @@ public class ContactOperationProcessor implements ObjectProcessorenvoy-server-standalone
@@ -22,6 +24,8 @@ import envoy.server.net.ObjectWriteProxy;
*/
public class GroupMessageProcessor implements ObjectProcessor {
+ private static final Logger logger = EnvoyLog.getLogger(GroupCreationProcessor.class);
+
@Override
public void process(GroupMessage groupMessage, long socketID, ObjectWriteProxy writeProxy) {
groupMessage.nextStatus();
@@ -29,7 +33,7 @@ public class GroupMessageProcessor implements ObjectProcessor {
try {
writeProxy.write(socketID, new MessageStatusChangeEvent(groupMessage));
} catch (IOException e) {
- System.err.println("Could not send messageStatusChangeEvent to the sender of this groupMessage with ID: " + groupMessage.getID());
+ logger.warning("Could not send messageStatusChangeEvent to the sender of this groupMessage with ID: " + groupMessage.getID());
e.printStackTrace();
}
@@ -48,7 +52,7 @@ public class GroupMessageProcessor implements ObjectProcessor {
try {
PersistenceManager.getInstance().addMessage(new envoy.server.data.GroupMessage(groupMessage, new Date()));
} catch (EntityExistsException e) {
- System.err.println("Received a groupMessage with an ID that already exists");
+ logger.warning("Received a groupMessage with an ID that already exists");
}
}
@@ -57,7 +61,7 @@ public class GroupMessageProcessor implements ObjectProcessor {
// If recipient is online, send the groupMessage directly
writeProxy.write(connectionManager.getSocketId(memberID), groupMessage);
} catch (IOException e) {
- System.err.println("Recipient online. Failed to send message" + groupMessage.getID());
+ logger.warning("Recipient online. Failed to send message" + groupMessage.getID());
e.printStackTrace();
}
}
diff --git a/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java b/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
index 4a00618..e30f18d 100755
--- a/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
+++ b/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java
@@ -1,12 +1,14 @@
package envoy.server.processors;
import java.io.IOException;
+import java.util.logging.Logger;
import envoy.data.IDGenerator;
import envoy.event.IDGeneratorRequest;
import envoy.server.data.ConfigItem;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ObjectWriteProxy;
+import envoy.util.EnvoyLog;
/**
* Project: envoy-server-standalone
@@ -20,15 +22,16 @@ import envoy.server.net.ObjectWriteProxy;
public class IDGeneratorRequestProcessor implements ObjectProcessor {
private static final long ID_RANGE = 200;
+ private static final Logger logger = EnvoyLog.getLogger(IDGeneratorRequestProcessor.class);
@Override
public Class getInputClass() { return IDGeneratorRequest.class; }
@Override
public void process(IDGeneratorRequest input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
- System.out.println("Received id generation request.");
+ logger.fine("Received id generation request.");
var generator = createIDGenerator();
- System.out.println("Sending new id generator " + generator);
+ logger.info("Sending new id generator " + generator);
writeProxy.write(socketID, generator);
}
diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
index 2835043..7c12ec2 100755
--- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
+++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
@@ -2,6 +2,7 @@ package envoy.server.processors;
import java.io.IOException;
import java.util.*;
+import java.util.logging.Logger;
import javax.persistence.NoResultException;
@@ -15,6 +16,7 @@ import envoy.server.data.Message;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy;
+import envoy.util.EnvoyLog;
/**
* This {@link ObjectProcessor} handles {@link LoginCredentials}.
@@ -32,16 +34,18 @@ public class LoginCredentialProcessor implements ObjectProcessor pendingMessages = PersistenceManager.getInstance().getPendingMessages(user);
for (Message msg : pendingMessages)
if (msg.getStatus() == MessageStatus.SENT) {
- System.out.println("Sending message " + msg.toCommon());
+ logger.info("Sending message " + msg.toCommon());
writeProxy.write(socketID, msg.toCommon());
msg.setReceivedDate(new Date());
msg.setStatus(MessageStatus.RECEIVED);
if (connectionManager.isOnline(msg.getSender().getID())) {
var evt = new MessageStatusChangeEvent(msg.toCommon());
- System.out.println("Sending messageStatusChangeEvent to sender " + evt);
+ logger.info("Sending messageStatusChangeEvent to sender " + evt);
writeProxy.write(connectionManager.getSocketId(msg.getSender().getID()), evt);
}
PersistenceManager.getInstance().updateMessage(msg);
} else {
var evt = new MessageStatusChangeEvent(msg.toCommon());
- System.out.println("Sending messageStatusChangeEvent " + evt);
+ logger.info("Sending messageStatusChangeEvent " + evt);
writeProxy.write(socketID, evt);
}
}
diff --git a/src/main/java/envoy/server/processors/MessageProcessor.java b/src/main/java/envoy/server/processors/MessageProcessor.java
index 75757ab..a326d8c 100755
--- a/src/main/java/envoy/server/processors/MessageProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageProcessor.java
@@ -2,6 +2,7 @@ package envoy.server.processors;
import java.io.IOException;
import java.util.Date;
+import java.util.logging.Logger;
import javax.persistence.EntityExistsException;
@@ -11,6 +12,7 @@ import envoy.event.MessageStatusChangeEvent;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy;
+import envoy.util.EnvoyLog;
/**
* This {@link ObjectProcessor} handles incoming {@link Message}s.
@@ -25,6 +27,8 @@ import envoy.server.net.ObjectWriteProxy;
*/
public class MessageProcessor implements ObjectProcessor {
+ private static final Logger logger = EnvoyLog.getLogger(MessageProcessor.class);
+
@Override
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
message.nextStatus();
@@ -36,14 +40,14 @@ public class MessageProcessor implements ObjectProcessor {
try {
writeProxy.write(socketID, new MessageStatusChangeEvent(message));
} catch (IOException e) {
- System.err.println("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID());
+ logger.warning("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID());
e.printStackTrace();
}
}
try {
PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
} catch (EntityExistsException e) {
- System.err.println("Received a message with an id that already exists");
+ logger.warning("Received a message with an id that already exists");
}
}
@@ -54,9 +58,8 @@ public class MessageProcessor implements ObjectProcessor {
// Update the message status to RECEIVED
message.setReceivedDate(new Date());
message.nextStatus();
-
} catch (IOException e) {
- System.err.println("Recipient online. Failed to send message" + message.getID());
+ logger.warning("Recipient online. Failed to send message" + message.getID());
e.printStackTrace();
}
}
diff --git a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
index ad63480..6cc6980 100755
--- a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java
@@ -1,6 +1,7 @@
package envoy.server.processors;
import java.io.IOException;
+import java.util.logging.Logger;
import envoy.data.User.UserStatus;
import envoy.event.UserStatusChangeEvent;
@@ -8,6 +9,7 @@ import envoy.server.data.PersistenceManager;
import envoy.server.data.User;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy;
+import envoy.util.EnvoyLog;
/**
* This processor handles incoming {@link UserStatusChangeEvent}.
@@ -24,6 +26,8 @@ public class UserStatusChangeProcessor implements ObjectProcessor getInputClass() { return UserStatusChangeEvent.class; }
@@ -31,11 +35,10 @@ public class UserStatusChangeProcessor implements ObjectProcessor
Date: Thu, 11 Jun 2020 12:08:51 +0200
Subject: [PATCH 32/38] Logging envoy messages only
---
src/main/java/envoy/server/Startup.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index e5d4fe7..150f9ff 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -46,7 +46,7 @@ public class Startup {
config.load(items);
EnvoyLog.initialize(config);
- EnvoyLog.attach("");
+ EnvoyLog.attach("envoy");
}
/**
From 638770c75f17260b78340dc7409de208663eb345 Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Thu, 11 Jun 2020 13:22:48 +0200
Subject: [PATCH 33/38] Added creationDate variable in Contact & added
pendingGroups query
---
src/main/java/envoy/server/data/Contact.java | 28 +++++++++++++++++++-
src/main/java/envoy/server/data/Group.java | 24 +++++++++++++----
2 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java
index c9700d5..b6bc402 100644
--- a/src/main/java/envoy/server/data/Contact.java
+++ b/src/main/java/envoy/server/data/Contact.java
@@ -1,8 +1,19 @@
package envoy.server.data;
+import java.util.Date;
import java.util.Set;
-import javax.persistence.*;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
/**
* This class acts as a superclass for all contacts, being {@link User}s and
@@ -26,6 +37,9 @@ public abstract class Contact {
protected long id;
protected String name;
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date creationDate;
+
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
protected Set contacts;
@@ -86,6 +100,18 @@ public abstract class Contact {
*/
public void setContacts(Set contacts) { this.contacts = contacts; }
+ /**
+ * @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; }
+
/**
* {@inheritDoc}
*/
diff --git a/src/main/java/envoy/server/data/Group.java b/src/main/java/envoy/server/data/Group.java
index 688ad4c..5f3be22 100644
--- a/src/main/java/envoy/server/data/Group.java
+++ b/src/main/java/envoy/server/data/Group.java
@@ -3,6 +3,7 @@ package envoy.server.data;
import java.util.stream.Collectors;
import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
@@ -19,18 +20,31 @@ import javax.persistence.Table;
*/
@Entity
@Table(name = "groups")
-@NamedQuery(
- name = Group.findByName,
- query = "SELECT g FROM Group g WHERE g.name = :name"
-)
+@NamedQueries({
+ @NamedQuery(
+ name = Group.findByName,
+ query = "SELECT g FROM Group g WHERE g.name = :name"
+ ),
+ @NamedQuery(
+ name = Group.findPendingGroups,
+ query = "SELECT g FROM Group g WHERE g.creationDate > :lastSeen AND :user MEMBER OF g.contacts"
+ )
+})
public class Group extends Contact {
/**
- * Named query retrieving a group by name (parameter {@code :name}.
+ * Named query retrieving a group by name (parameter {@code :name}).
*
* @since Envoy Server Standalone v0.1-beta
*/
public static final String findByName = "Group.findByName";
+
+ /**
+ * Named query retrieving all pending groups for a specific user (parameter {@code :user}, {@code :lastSeen}).
+ *
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ public static final String findPendingGroups = "Group.findPendingGroups";
/**
* {@inheritDoc}
From bbf688dbe9e412795fc6660ff98176fe99ac0b4e Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Thu, 11 Jun 2020 13:40:30 +0200
Subject: [PATCH 34/38] Adjusted pom.xml
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 244170b..046ec55 100755
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
com.github.informatik-ag-ngl
envoy-common
- f~groups-SNAPSHOT
+ develop-SNAPSHOT
com.github.informatik-ag-ngl
From 5ef46d80c33b66c3e0444f79401a1a13ff43189b Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Thu, 11 Jun 2020 15:06:06 +0200
Subject: [PATCH 35/38] Implemented suggestions from code review
---
src/main/java/envoy/server/data/GroupMessage.java | 1 -
src/main/java/envoy/server/data/Message.java | 11 +----------
src/main/java/envoy/server/net/ConnectionManager.java | 11 ++++++-----
.../server/processors/GroupMessageProcessor.java | 7 -------
.../envoy/server/processors/GroupResizeProcessor.java | 2 +-
5 files changed, 8 insertions(+), 24 deletions(-)
diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java
index bc9fed7..4c64cf7 100644
--- a/src/main/java/envoy/server/data/GroupMessage.java
+++ b/src/main/java/envoy/server/data/GroupMessage.java
@@ -18,7 +18,6 @@ import envoy.data.MessageBuilder;
* @author Maximilian Käfer
* @since Envoy Server Standalone v0.1-beta
*/
-
@Entity
public class GroupMessage extends Message {
diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java
index 128b122..9203a4f 100755
--- a/src/main/java/envoy/server/data/Message.java
+++ b/src/main/java/envoy/server/data/Message.java
@@ -2,16 +2,7 @@ package envoy.server.data;
import java.util.Date;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Inheritance;
-import javax.persistence.InheritanceType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
+import javax.persistence.*;
import envoy.data.MessageBuilder;
diff --git a/src/main/java/envoy/server/net/ConnectionManager.java b/src/main/java/envoy/server/net/ConnectionManager.java
index ef384bb..03f3810 100755
--- a/src/main/java/envoy/server/net/ConnectionManager.java
+++ b/src/main/java/envoy/server/net/ConnectionManager.java
@@ -1,6 +1,10 @@
package envoy.server.net;
-import java.util.*;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
import com.jenkov.nioserver.ISocketIdListener;
@@ -111,9 +115,6 @@ public class ConnectionManager implements ISocketIdListener {
* @since Envoy Server Standalone v0.1-beta
*/
public Set getOnlineUsersOfGroup(Group group) {
- Set onlineMembers = new HashSet<>();
- Set members = group.getContacts().stream().map(envoy.server.data.Contact::getID).collect(Collectors.toSet());
- members.forEach(userID -> { if (isOnline(userID)) onlineMembers.add(userID); });
- return onlineMembers;
+ return group.getContacts().stream().map(envoy.server.data.Contact::getID).filter(this::isOnline).collect(Collectors.toSet());
}
}
diff --git a/src/main/java/envoy/server/processors/GroupMessageProcessor.java b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
index 790f4e3..087e2c0 100644
--- a/src/main/java/envoy/server/processors/GroupMessageProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
@@ -8,7 +8,6 @@ import javax.persistence.EntityExistsException;
import envoy.data.GroupMessage;
import envoy.data.Message.MessageStatus;
-import envoy.event.MessageStatusChangeEvent;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectWriteProxy;
@@ -30,12 +29,6 @@ public class GroupMessageProcessor implements ObjectProcessor {
public void process(GroupMessage groupMessage, long socketID, ObjectWriteProxy writeProxy) {
groupMessage.nextStatus();
ConnectionManager connectionManager = ConnectionManager.getInstance();
- try {
- writeProxy.write(socketID, new MessageStatusChangeEvent(groupMessage));
- } catch (IOException e) {
- logger.warning("Could not send messageStatusChangeEvent to the sender of this groupMessage with ID: " + groupMessage.getID());
- e.printStackTrace();
- }
final var members = PersistenceManager.getInstance().getGroupByID(groupMessage.getRecipientID()).getContacts();
for (long i = 0; i < groupMessage.getMemberStatuses().size(); i++) {
diff --git a/src/main/java/envoy/server/processors/GroupResizeProcessor.java b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
index 7bcc72a..dc99535 100644
--- a/src/main/java/envoy/server/processors/GroupResizeProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
@@ -49,7 +49,7 @@ public class GroupResizeProcessor implements ObjectProcessor {
.map(connectionManager::getSocketId)
.forEach(memberSocketID -> {
try {
- writeProxy.write(memberSocketID, commonGroup);
+ writeProxy.write(memberSocketID, commonGroup);
} catch (IOException e) {
e.printStackTrace();
}
From a9de00371dcf78391cafd1f66f159bcc840ecf8f Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Fri, 12 Jun 2020 10:56:02 +0200
Subject: [PATCH 36/38] Change default logging level to finest, rename a class
---
src/main/java/envoy/server/Startup.java | 23 ++++++++-----------
...essor.java => ContactSearchProcessor.java} | 4 ++--
2 files changed, 12 insertions(+), 15 deletions(-)
rename src/main/java/envoy/server/processors/{ContactsRequestEventProcessor.java => ContactSearchProcessor.java} (89%)
diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index 150f9ff..63415aa 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -3,7 +3,6 @@ package envoy.server;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
@@ -40,7 +39,7 @@ public class Startup {
items.put("homeDirectory",
new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy-server"), true));
items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.SEVERE, true));
- items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.FINE, true));
+ items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.FINEST, true));
final var config = new Config();
config.load(items);
@@ -59,17 +58,15 @@ public class Startup {
public static void main(String[] args) throws IOException {
initLogging();
- Set> processors = new HashSet<>();
- processors.add(new LoginCredentialProcessor());
- processors.add(new MessageProcessor());
- processors.add(new GroupCreationProcessor());
- processors.add(new GroupMessageProcessor());
- processors.add(new MessageStatusChangeProcessor());
- processors.add(new UserStatusChangeProcessor());
- processors.add(new IDGeneratorRequestProcessor());
- processors.add(new ContactsRequestEventProcessor());
- processors.add(new ContactOperationProcessor());
- Server server = new Server(8080, ObjectMessageReader::new, new ObjectMessageProcessor(processors));
+ Server server = new Server(8080, ObjectMessageReader::new,
+ new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(),
+ new MessageProcessor(),
+ new GroupCreationProcessor(),
+ new MessageStatusChangeProcessor(),
+ new UserStatusChangeProcessor(),
+ new IDGeneratorRequestProcessor(),
+ new ContactSearchProcessor(),
+ new ContactOperationProcessor())));
// Initialize the current message ID
PersistenceManager persistenceManager = PersistenceManager.getInstance();
diff --git a/src/main/java/envoy/server/processors/ContactsRequestEventProcessor.java b/src/main/java/envoy/server/processors/ContactSearchProcessor.java
similarity index 89%
rename from src/main/java/envoy/server/processors/ContactsRequestEventProcessor.java
rename to src/main/java/envoy/server/processors/ContactSearchProcessor.java
index b1330c9..49fb33f 100755
--- a/src/main/java/envoy/server/processors/ContactsRequestEventProcessor.java
+++ b/src/main/java/envoy/server/processors/ContactSearchProcessor.java
@@ -13,14 +13,14 @@ import envoy.server.net.ObjectWriteProxy;
/**
* Project: envoy-server-standalone
- * File: ContactsRequestEventProcessor.java
+ * File: ContactSearchProcessor.java
* Created: 08.02.2020
*
* @author Kai S. K. Engelbart
* @author Maximilian Käfer
* @since Envoy Server Standalone v0.1-alpha
*/
-public class ContactsRequestEventProcessor implements ObjectProcessor {
+public class ContactSearchProcessor implements ObjectProcessor {
/**
* Writes a list of contacts to the client containing all {@link Contact}s
From f1c49f0b95f16c8e6dfba87e2f373fd6aab0251b Mon Sep 17 00:00:00 2001
From: CyB3RC0nN0R
Date: Sun, 14 Jun 2020 16:30:46 +0200
Subject: [PATCH 37/38] Apply suggestions from code review
Co-authored-by: delvh
---
drop_all_tables.sql | 2 +-
src/main/java/envoy/server/Startup.java | 2 +-
src/main/java/envoy/server/data/Contact.java | 2 +-
.../java/envoy/server/data/PersistenceManager.java | 8 ++++----
.../java/envoy/server/net/ObjectWriteProxy.java | 1 -
.../server/processors/GroupMessageProcessor.java | 1 -
.../envoy/server/processors/MessageProcessor.java | 13 ++++---------
.../processors/MessageStatusChangeProcessor.java | 4 ++--
8 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/drop_all_tables.sql b/drop_all_tables.sql
index 71f8a44..9eb29c1 100644
--- a/drop_all_tables.sql
+++ b/drop_all_tables.sql
@@ -2,4 +2,4 @@ DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO envoy;
-GRANT ALL ON SCHEMA public TO public;
\ No newline at end of file
+GRANT ALL ON SCHEMA public TO public;
diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index 63415aa..9ad4bc3 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -38,7 +38,7 @@ public class Startup {
final var items = new HashMap>();
items.put("homeDirectory",
new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy-server"), true));
- items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.SEVERE, true));
+ items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.WARNING, true));
items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.FINEST, true));
final var config = new Config();
diff --git a/src/main/java/envoy/server/data/Contact.java b/src/main/java/envoy/server/data/Contact.java
index b6bc402..475b3ef 100644
--- a/src/main/java/envoy/server/data/Contact.java
+++ b/src/main/java/envoy/server/data/Contact.java
@@ -40,7 +40,7 @@ public abstract class Contact {
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
- @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+ @ManyToMany(fetch = FetchType.EAGER)
protected Set contacts;
/**
diff --git a/src/main/java/envoy/server/data/PersistenceManager.java b/src/main/java/envoy/server/data/PersistenceManager.java
index d4c9929..26a7240 100755
--- a/src/main/java/envoy/server/data/PersistenceManager.java
+++ b/src/main/java/envoy/server/data/PersistenceManager.java
@@ -117,7 +117,7 @@ public class PersistenceManager {
* Searches for a {@link User} with a specific ID.
*
* @param id the id to search for
- * @return the user with the specified id
+ * @return the user with the specified ID or {@code null} if none was found
* @since Envoy Server Standalone v0.1-alpha
*/
public User getUserByID(long id) { return entityManager.find(User.class, id); }
@@ -126,7 +126,7 @@ public class PersistenceManager {
* Searches for a {@link Group} with a specific ID.
*
* @param id the id to search for
- * @return the group with the specific id
+ * @return the group with the specified ID or {@code null} if none was found
* @since Envoy Server Standalone v0.1-beta
*/
public Group getGroupByID(long id) { return entityManager.find(Group.class, id); }
@@ -135,7 +135,7 @@ public class PersistenceManager {
* Searches for a {@link Contact} with a specific ID.
*
* @param id the id to search for
- * @return the contact with the specific id
+ * @return the contact with the specified ID or {@code null} if none was found
* @since Envoy Server Standalone v0.1-beta
*/
public Contact getContactByID(long id) { return entityManager.find(Contact.class, id); }
@@ -166,7 +166,7 @@ public class PersistenceManager {
* Searches for a {@link Message} with a specific id.
*
* @param id the id to search for
- * @return the message with the specified id
+ * @return the message with the specified ID or {@code null} if none is found
* @since Envoy Server Standalone v0.1-alpha
*/
public Message getMessageByID(long id) { return entityManager.find(Message.class, id); }
diff --git a/src/main/java/envoy/server/net/ObjectWriteProxy.java b/src/main/java/envoy/server/net/ObjectWriteProxy.java
index eea2908..1e1c76b 100755
--- a/src/main/java/envoy/server/net/ObjectWriteProxy.java
+++ b/src/main/java/envoy/server/net/ObjectWriteProxy.java
@@ -43,7 +43,6 @@ public class ObjectWriteProxy {
// Create message targeted at the client
final Message response = writeProxy.getMessage();
response.socketId = recipientSocketID;
-
logger.fine("Sending " + obj);
// Serialize object to byte array
diff --git a/src/main/java/envoy/server/processors/GroupMessageProcessor.java b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
index 087e2c0..89b5527 100644
--- a/src/main/java/envoy/server/processors/GroupMessageProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
@@ -38,7 +38,6 @@ public class GroupMessageProcessor implements ObjectProcessor {
// Checks if all memberMessageStatuses are RECEIVED and if so sets the
// groupMessage Status to RECEIVED.
- if (!groupMessage.getMemberStatuses().containsValue(MessageStatus.SENT)) groupMessage.setStatus(MessageStatus.RECEIVED);
members.forEach(user -> { sendToMember(connectionManager, groupMessage, user.getID(), writeProxy); });
diff --git a/src/main/java/envoy/server/processors/MessageProcessor.java b/src/main/java/envoy/server/processors/MessageProcessor.java
index a326d8c..294a34d 100755
--- a/src/main/java/envoy/server/processors/MessageProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageProcessor.java
@@ -31,19 +31,14 @@ public class MessageProcessor implements ObjectProcessor {
@Override
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
+ if (message.getStatus!=MessageStatus.WAITING) {
+ logger.warning("Received message with invalid status: " + message);
+ return;
+ }
message.nextStatus();
ConnectionManager connectionManager = ConnectionManager.getInstance();
sendToUser(connectionManager, message, writeProxy);
- if (message.getStatus() != MessageStatus.SENT) {
- // Sending a messageStatusChangeEvent to the sender
- try {
- writeProxy.write(socketID, new MessageStatusChangeEvent(message));
- } catch (IOException e) {
- logger.warning("Could not send messageStatusChangeEvent to the sender of this message with ID: " + message.getID());
- e.printStackTrace();
- }
- }
try {
PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message));
} catch (EntityExistsException e) {
diff --git a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
index d88e120..242f627 100755
--- a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
@@ -33,8 +33,8 @@ public class MessageStatusChangeProcessor implements ObjectProcessor
Date: Sun, 14 Jun 2020 16:40:51 +0200
Subject: [PATCH 38/38] Some refactorings based on suggestions from @delvh
---
.../envoy/server/data/PersistenceManager.java | 20 +++++++++----------
.../envoy/server/net/ConnectionManager.java | 14 ++++---------
.../processors/ContactOperationProcessor.java | 6 +++---
.../processors/ContactSearchProcessor.java | 2 +-
.../processors/GroupCreationProcessor.java | 6 +++---
.../processors/GroupMessageProcessor.java | 8 +++-----
.../processors/GroupResizeProcessor.java | 2 +-
.../processors/LoginCredentialProcessor.java | 2 +-
.../server/processors/MessageProcessor.java | 5 ++---
.../MessageStatusChangeProcessor.java | 2 +-
.../processors/UserStatusChangeProcessor.java | 2 +-
src/main/resources/META-INF/persistence.xml | 2 +-
12 files changed, 31 insertions(+), 40 deletions(-)
diff --git a/src/main/java/envoy/server/data/PersistenceManager.java b/src/main/java/envoy/server/data/PersistenceManager.java
index 26a7240..0221fe9 100755
--- a/src/main/java/envoy/server/data/PersistenceManager.java
+++ b/src/main/java/envoy/server/data/PersistenceManager.java
@@ -213,26 +213,26 @@ public class PersistenceManager {
}
/**
- * Adds a user to the contact list of another user and vice versa.
+ * Adds a contact to the contact list of another contact and vice versa.
*
- * @param userId1 the ID of the first user
- * @param userId2 the ID of the second user
+ * @param contactID1 the ID of the first contact
+ * @param contactID2 the ID of the second contact
* @since Envoy Server Standalone v0.1-alpha
*/
- public void addUserContact(long userId1, long userId2) {
+ public void addContactBidirectional(long contactID1, long contactID2) {
// Get users by ID
- Contact u1 = getContactByID(userId1);
- Contact u2 = getContactByID(userId2);
+ Contact c1 = getContactByID(contactID1);
+ Contact c2 = getContactByID(contactID2);
// Add users to each others contact lists
- u1.getContacts().add(u2);
- u2.getContacts().add(u1);
+ c1.getContacts().add(c2);
+ c2.getContacts().add(c1);
// Synchronize changes with the database
transaction.begin();
- entityManager.merge(u1);
- entityManager.merge(u2);
+ entityManager.merge(c1);
+ entityManager.merge(c2);
transaction.commit();
}
diff --git a/src/main/java/envoy/server/net/ConnectionManager.java b/src/main/java/envoy/server/net/ConnectionManager.java
index 03f3810..6d9beea 100755
--- a/src/main/java/envoy/server/net/ConnectionManager.java
+++ b/src/main/java/envoy/server/net/ConnectionManager.java
@@ -1,10 +1,6 @@
package envoy.server.net;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.stream.Collectors;
import com.jenkov.nioserver.ISocketIdListener;
@@ -53,7 +49,7 @@ public class ConnectionManager implements ISocketIdListener {
public void socketCancelled(long socketID) {
if (!pendingSockets.remove(socketID)) {
// Notify contacts of this users offline-going
- envoy.server.data.User user = PersistenceManager.getInstance().getUserByID(getUserIdBySocketId(socketID));
+ envoy.server.data.User user = PersistenceManager.getInstance().getUserByID(getUserIdBySocketID(socketID));
user.setStatus(UserStatus.OFFLINE);
user.setLastSeen(new Date());
UserStatusChangeProcessor.updateUserStatus(user);
@@ -83,14 +79,14 @@ public class ConnectionManager implements ISocketIdListener {
* @return the ID of the socket
* @since Envoy Server Standalone v0.1-alpha
*/
- public long getSocketId(long userID) { return sockets.get(userID); }
+ public long getSocketID(long userID) { return sockets.get(userID); }
/**
* @param socketID the id of the socket whose User is needed
* @return the userId associated with this socketId
* @since Envoy Server Standalone v0.1-alpha
*/
- public long getUserIdBySocketId(long socketID) {
+ public long getUserIdBySocketID(long socketID) {
return sockets.entrySet().stream().filter(entry -> entry.getValue().equals(socketID)).findFirst().get().getKey();
}
@@ -108,8 +104,6 @@ public class ConnectionManager implements ISocketIdListener {
public Set getOnlineUsers() { return sockets.keySet(); }
/**
- * Returns all members of a group who are currently online.
- *
* @param group the group to search for
* @return a set of all IDs of currently active members in this group
* @since Envoy Server Standalone v0.1-beta
diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
index c47e516..9e181ae 100755
--- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java
+++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java
@@ -27,15 +27,15 @@ public class ContactOperationProcessor implements ObjectProcessor());
input.getInitialMemberIDs().stream().map(persistenceManager::getUserByID).forEach(group.getContacts()::add);
- group.getContacts().add(persistenceManager.getContactByID(connectionManager.getUserIdBySocketId(socketID)));
+ group.getContacts().add(persistenceManager.getContactByID(connectionManager.getUserIdBySocketID(socketID)));
group.getContacts().forEach(c -> c.getContacts().add(group));
- group.getContacts().add(persistenceManager.getUserByID(connectionManager.getUserIdBySocketId(socketID)));
+ group.getContacts().add(persistenceManager.getUserByID(connectionManager.getUserIdBySocketID(socketID)));
persistenceManager.addContact(group);
group.getContacts()
.stream()
.map(Contact::getID)
.filter(connectionManager::isOnline)
- .map(connectionManager::getSocketId)
+ .map(connectionManager::getSocketID)
.forEach(memberSocketID -> {
try {
writeProxy.write(memberSocketID, new ContactOperationEvent(group.toCommon(), ElementOperation.ADD));
diff --git a/src/main/java/envoy/server/processors/GroupMessageProcessor.java b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
index 89b5527..809df61 100644
--- a/src/main/java/envoy/server/processors/GroupMessageProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupMessageProcessor.java
@@ -31,10 +31,8 @@ public class GroupMessageProcessor implements ObjectProcessor {
ConnectionManager connectionManager = ConnectionManager.getInstance();
final var members = PersistenceManager.getInstance().getGroupByID(groupMessage.getRecipientID()).getContacts();
- for (long i = 0; i < groupMessage.getMemberStatuses().size(); i++) {
- groupMessage.getMemberStatuses().replace(i, MessageStatus.SENT);
- }
- members.forEach(user -> { setMemberStatus(connectionManager, groupMessage, user.getID()); });
+ groupMessage.getMemberStatuses().replaceAll((id, oldStatus) -> MessageStatus.SENT);
+ members.forEach(user -> setMemberStatus(connectionManager, groupMessage, user.getID()));
// Checks if all memberMessageStatuses are RECEIVED and if so sets the
// groupMessage Status to RECEIVED.
@@ -51,7 +49,7 @@ public class GroupMessageProcessor implements ObjectProcessor {
private void sendToMember(ConnectionManager connectionManager, GroupMessage groupMessage, long memberID, ObjectWriteProxy writeProxy) {
if (connectionManager.isOnline(memberID)) try {
// If recipient is online, send the groupMessage directly
- writeProxy.write(connectionManager.getSocketId(memberID), groupMessage);
+ writeProxy.write(connectionManager.getSocketID(memberID), groupMessage);
} catch (IOException e) {
logger.warning("Recipient online. Failed to send message" + groupMessage.getID());
e.printStackTrace();
diff --git a/src/main/java/envoy/server/processors/GroupResizeProcessor.java b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
index dc99535..79c2be6 100644
--- a/src/main/java/envoy/server/processors/GroupResizeProcessor.java
+++ b/src/main/java/envoy/server/processors/GroupResizeProcessor.java
@@ -46,7 +46,7 @@ public class GroupResizeProcessor implements ObjectProcessor {
.stream()
.map(Contact::getID)
.filter(connectionManager::isOnline)
- .map(connectionManager::getSocketId)
+ .map(connectionManager::getSocketID)
.forEach(memberSocketID -> {
try {
writeProxy.write(memberSocketID, commonGroup);
diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
index 7c12ec2..7e33f2b 100755
--- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
+++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java
@@ -69,7 +69,7 @@ public class LoginCredentialProcessor implements ObjectProcessor {
@Override
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
- if (message.getStatus!=MessageStatus.WAITING) {
+ if (message.getStatus() != MessageStatus.WAITING) {
logger.warning("Received message with invalid status: " + message);
return;
}
@@ -49,7 +48,7 @@ public class MessageProcessor implements ObjectProcessor {
private void sendToUser(ConnectionManager connectionManager, Message message, ObjectWriteProxy writeProxy) {
if (connectionManager.isOnline(message.getRecipientID())) try {
// If recipient is online, send the message directly
- writeProxy.write(connectionManager.getSocketId(message.getRecipientID()), message);
+ writeProxy.write(connectionManager.getSocketID(message.getRecipientID()), message);
// Update the message status to RECEIVED
message.setReceivedDate(new Date());
message.nextStatus();
diff --git a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
index 242f627..2ca7c46 100755
--- a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
+++ b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java
@@ -34,7 +34,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor
-
\ No newline at end of file
+