From 2ebc3779377aa4c2da9378c1ddc8465deadbd0a5 Mon Sep 17 00:00:00 2001 From: delvh Date: Sun, 28 Jun 2020 09:49:51 +0200 Subject: [PATCH 1/4] Renamed wrongly named package (enovy.* to envoy.*) --- .../java/envoy/server/processors/LoginCredentialProcessor.java | 2 +- src/main/java/{enovy => envoy}/server/util/VersionUtils.java | 2 +- src/main/java/{enovy => envoy}/server/util/package-info.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/{enovy => envoy}/server/util/VersionUtils.java (99%) rename src/main/java/{enovy => envoy}/server/util/package-info.java (91%) diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java index 9877f36..8edc0f8 100755 --- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java +++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java @@ -11,7 +11,6 @@ import java.util.logging.Logger; import javax.persistence.NoResultException; -import enovy.server.util.VersionUtils; import envoy.data.LoginCredentials; import envoy.data.Message.MessageStatus; import envoy.event.HandshakeRejection; @@ -20,6 +19,7 @@ import envoy.server.data.PersistenceManager; import envoy.server.data.User; import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectWriteProxy; +import envoy.server.util.VersionUtils; import envoy.util.EnvoyLog; /** diff --git a/src/main/java/enovy/server/util/VersionUtils.java b/src/main/java/envoy/server/util/VersionUtils.java similarity index 99% rename from src/main/java/enovy/server/util/VersionUtils.java rename to src/main/java/envoy/server/util/VersionUtils.java index ab96890..db4a845 100644 --- a/src/main/java/enovy/server/util/VersionUtils.java +++ b/src/main/java/envoy/server/util/VersionUtils.java @@ -1,4 +1,4 @@ -package enovy.server.util; +package envoy.server.util; import java.util.regex.Pattern; diff --git a/src/main/java/enovy/server/util/package-info.java b/src/main/java/envoy/server/util/package-info.java similarity index 91% rename from src/main/java/enovy/server/util/package-info.java rename to src/main/java/envoy/server/util/package-info.java index f256f4c..f052882 100644 --- a/src/main/java/enovy/server/util/package-info.java +++ b/src/main/java/envoy/server/util/package-info.java @@ -8,4 +8,4 @@ * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-beta */ -package enovy.server.util; +package envoy.server.util; From 5e5a7273e42694be4ffa3b2aedb8e4989190db09 Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 2 Jul 2020 14:54:58 +0200 Subject: [PATCH 2/4] Add Attachment Support --- pom.xml | 2 +- .../java/envoy/server/data/GroupMessage.java | 12 +---- src/main/java/envoy/server/data/Message.java | 44 +++++++++++++++---- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 046ec55..b4a2621 100755 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ com.github.informatik-ag-ngl envoy-common - develop-SNAPSHOT + f~attachment-SNAPSHOT com.github.informatik-ag-ngl diff --git a/src/main/java/envoy/server/data/GroupMessage.java b/src/main/java/envoy/server/data/GroupMessage.java index 13dcc49..91ba538 100644 --- a/src/main/java/envoy/server/data/GroupMessage.java +++ b/src/main/java/envoy/server/data/GroupMessage.java @@ -5,7 +5,7 @@ import java.util.Map; import javax.persistence.*; -import envoy.data.MessageBuilder; +import envoy.data.Group; /** * Project: envoy-server-standalone
@@ -57,15 +57,7 @@ public class GroupMessage extends Message { */ @Override public envoy.data.GroupMessage toCommon() { - // TODO: Attachment - envoy.data.GroupMessage groupMessage = new MessageBuilder(sender.getID(), recipient.getID(), id).setDate(creationDate) - .setForwarded(forwarded) - .setStatus(status) - .setText(text) - .buildGroupMessage((envoy.data.Group) recipient.toCommon(), memberMessageStatus); - groupMessage.setReceivedDate(receivedDate); - groupMessage.setReadDate(readDate); - return groupMessage; + return prepareBuilder().buildGroupMessage((Group) recipient.toCommon(), memberMessageStatus); } /** diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java index 5b81e7d..afe66c7 100755 --- a/src/main/java/envoy/server/data/Message.java +++ b/src/main/java/envoy/server/data/Message.java @@ -6,6 +6,8 @@ import java.time.LocalDateTime; import javax.persistence.*; +import envoy.data.Attachment; +import envoy.data.Attachment.AttachmentType; import envoy.data.Message.MessageStatus; import envoy.data.MessageBuilder; @@ -63,6 +65,7 @@ public class Message { protected String text; protected envoy.data.Message.MessageStatus status; + protected AttachmentType attachmentType; protected byte[] attachment; protected boolean forwarded; @@ -91,7 +94,10 @@ public class Message { sender = persistenceManager.getUserByID(message.getSenderID()); recipient = persistenceManager.getContactByID(message.getRecipientID()); forwarded = message.isForwarded(); - // TODO: Attachment + if (message.hasAttachment()) { + attachment = message.getAttachment().getData(); + attachmentType = message.getAttachment().getType(); + } } /** @@ -102,15 +108,23 @@ public class Message { * @since Envoy Server Standalone v0.1-alpha */ public envoy.data.Message toCommon() { - // TODO: Attachment - envoy.data.Message message = new MessageBuilder(sender.getID(), recipient.getID(), id).setText(text) - .setDate(creationDate) + return prepareBuilder().build(); + } + + /** + * @return a message builder containing the state of this message + * @since Envoy Server Standalone v0.1-beta + */ + MessageBuilder prepareBuilder() { + var builder = new MessageBuilder(sender.getID(), recipient.getID(), id).setText( + text) + .setCreationDate(creationDate) + .setReceivedDate(receivedDate) + .setReadDate(readDate) .setStatus(status) - .setForwarded(forwarded) - .build(); - message.setReceivedDate(receivedDate); - message.setReadDate(readDate); - return message; + .setForwarded(forwarded); + if (attachment != null) builder.setAttachment(new Attachment(attachment, attachmentType)); + return builder; } /** @@ -250,6 +264,18 @@ public class Message { */ public void setAttachment(byte[] attachment) { this.attachment = attachment; } + /** + * @return the attachmentType + * @since Envoy Server Standalone v0.1-beta + */ + public AttachmentType getAttachmentType() { return attachmentType; } + + /** + * @param attachmentType the attachmentType to set + * @since Envoy Server Standalone v0.1-beta + */ + public void setAttachmentType(AttachmentType attachmentType) { this.attachmentType = attachmentType; } + /** * @return whether this message is a forwarded message * @since Envoy Server Standalone v0.1-alpha From ec143340322b61ef722ccf9aa86bd31104fb49dc Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 2 Jul 2020 18:04:27 +0200 Subject: [PATCH 3/4] Update envoy-common dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b4a2621..046ec55 100755 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ com.github.informatik-ag-ngl envoy-common - f~attachment-SNAPSHOT + develop-SNAPSHOT com.github.informatik-ag-ngl From ce7078ecad253adc96dd58ba08737a227a38eb7f Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 2 Jul 2020 20:01:28 +0200 Subject: [PATCH 4/4] Added capability to prevent the normal stop command of the server --- src/main/java/envoy/server/Startup.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java index 9ad4bc3..9306356 100755 --- a/src/main/java/envoy/server/Startup.java +++ b/src/main/java/envoy/server/Startup.java @@ -31,7 +31,7 @@ public class Startup { /** * Initializes the logger with a new config instance. - * + * * @since Envoy Server Standalone v0.1-beta */ private static void initLogging() { @@ -51,14 +51,15 @@ public class Startup { /** * Starts the server. * - * @param args the run configuration. Currently unused. + * @param args the run configuration. If it is "no-enter-to-stop" at position 0, + * no command to read in an enter press will be generated * @throws IOException if the server crashes * @since Envoy Server Standalone v0.1-alpha */ public static void main(String[] args) throws IOException { initLogging(); - Server server = new Server(8080, ObjectMessageReader::new, + final Server server = new Server(8080, ObjectMessageReader::new, new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(), new MessageProcessor(), new GroupCreationProcessor(), @@ -69,16 +70,18 @@ public class Startup { new ContactOperationProcessor()))); // Initialize the current message ID - PersistenceManager persistenceManager = PersistenceManager.getInstance(); + final PersistenceManager persistenceManager = PersistenceManager.getInstance(); if (persistenceManager.getConfigItemByID("currentMessageId") == null) persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0")); server.start(); server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance()); - System.out.println("Press the return key to stop the server..."); - System.in.read(); - System.out.println("Stopped"); - System.exit(0); + if (args.length == 0 || !args[0].equalsIgnoreCase("no-enter-to-stop")) { + System.out.println("Press the return key to stop the server..."); + System.in.read(); + System.out.println("Stopped"); + System.exit(0); + } } }