From f1c49f0b95f16c8e6dfba87e2f373fd6aab0251b Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sun, 14 Jun 2020 16:30:46 +0200 Subject: [PATCH] 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