From aba7d6a767f469ae2b577035bf8f97a0eaa85622 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 28 Sep 2019 13:46:33 +0200 Subject: [PATCH 001/126] Initial commit --- LICENSE | 21 +++++++++++++++++++++ README.md | 1 + 2 files changed, 22 insertions(+) create mode 100644 LICENSE create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..46da469 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Informatik-AG (NGL) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..96825b7 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# envoy-common \ No newline at end of file From 4773eed28c4e11122dde1084259e67998de3a097 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 28 Sep 2019 14:20:25 +0200 Subject: [PATCH 002/126] Added message schema --- .classpath | 45 ++++++++++++++++ .gitignore | 1 + .project | 48 +++++++++++++++++ .settings/org.eclipse.core.resources.prefs | 7 +++ .settings/org.eclipse.jdt.core.prefs | 11 ++++ .settings/org.eclipse.m2e.core.prefs | 4 ++ .settings/org.eclipse.wst.common.component | 7 +++ ....eclipse.wst.common.project.facet.core.xml | 5 ++ pom.xml | 51 +++++++++++++++++++ src/main/resources/message_schema.xsd | 34 +++++++++++++ 10 files changed, 213 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 .settings/org.eclipse.wst.common.component create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 pom.xml create mode 100644 src/main/resources/message_schema.xsd diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..29cf6e1 --- /dev/null +++ b/.classpath @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/.project b/.project new file mode 100644 index 0000000..6330f26 --- /dev/null +++ b/.project @@ -0,0 +1,48 @@ + + + envoy-common + + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.jboss.tools.jst.web.kb.kbbuilder + + + + + org.jboss.tools.cdi.core.cdibuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.jboss.tools.jst.web.kb.kbnature + org.jboss.tools.cdi.core.cdinature + org.eclipse.wst.common.project.facet.core.nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..93fb95b --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding//target/generated-sources/jaxb=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ddd0785 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..14b697b --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..9de5f51 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..6302d3e --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..50c664e --- /dev/null +++ b/pom.xml @@ -0,0 +1,51 @@ + + 4.0.0 + informatik-ag-ngl + envoy-common + 0.0.1-SNAPSHOT + + Envoy Common + https://github.com/informatik-ag-ngl/envoy-common + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + org.codehaus.mojo + jaxb2-maven-plugin + 2.5.0 + + + + + envoy-common + + + org.codehaus.mojo + jaxb2-maven-plugin + 2.5.0 + + + xjc + + xjc + + + + + envoy.schema + + src/main/resources + + + + + + \ No newline at end of file diff --git a/src/main/resources/message_schema.xsd b/src/main/resources/message_schema.xsd new file mode 100644 index 0000000..a6afc24 --- /dev/null +++ b/src/main/resources/message_schema.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 5254a83e8cf874f482bbf2e55c178e08e7754450 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 28 Sep 2019 16:21:07 +0200 Subject: [PATCH 003/126] Updated message schema to support JAXB --- .classpath | 2 +- .project | 10 ++-- .settings/org.eclipse.wst.validation.prefs | 2 + src/main/resources/message_schema.xsd | 58 +++++++++++----------- 4 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 .settings/org.eclipse.wst.validation.prefs diff --git a/.classpath b/.classpath index 29cf6e1..cd5c385 100644 --- a/.classpath +++ b/.classpath @@ -37,8 +37,8 @@ - + diff --git a/.project b/.project index 6330f26..e729774 100644 --- a/.project +++ b/.project @@ -15,11 +15,6 @@ - - org.eclipse.m2e.core.maven2Builder - - - org.jboss.tools.jst.web.kb.kbbuilder @@ -35,6 +30,11 @@ + + org.eclipse.m2e.core.maven2Builder + + + org.eclipse.jem.workbench.JavaEMFNature diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..6f1cba6 --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/src/main/resources/message_schema.xsd b/src/main/resources/message_schema.xsd index a6afc24..aebbd1a 100644 --- a/src/main/resources/message_schema.xsd +++ b/src/main/resources/message_schema.xsd @@ -1,34 +1,32 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 1e18b5b2b1b35c2d5aa27007697bb00aeb024b84 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 5 Oct 2019 15:05:41 +0200 Subject: [PATCH 004/126] Expanded message_schema.xsd to support message lists --- src/main/resources/message_schema.xsd | 45 ++++++++++++++++----------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main/resources/message_schema.xsd b/src/main/resources/message_schema.xsd index aebbd1a..1b2f451 100644 --- a/src/main/resources/message_schema.xsd +++ b/src/main/resources/message_schema.xsd @@ -4,29 +4,36 @@ xmlns="https://github.com/informatik-ag-ngl" elementFormDefault="qualified"> - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From d6d4452dd70b46d82f40bda16417e94127b07234 Mon Sep 17 00:00:00 2001 From: Maxi Date: Sat, 5 Oct 2019 22:45:24 +0200 Subject: [PATCH 005/126] New xsd schema to send all users to the client --- src/main/resources/userListSchema.xsd | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/resources/userListSchema.xsd diff --git a/src/main/resources/userListSchema.xsd b/src/main/resources/userListSchema.xsd new file mode 100644 index 0000000..ef107db --- /dev/null +++ b/src/main/resources/userListSchema.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 91a0ab8d55e2a40d89201412a0bd86a216839779 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sun, 6 Oct 2019 09:50:17 +0200 Subject: [PATCH 006/126] Renamed userListSchema to user_schema, changed id to long data type --- src/main/resources/{userListSchema.xsd => user_schema.xsd} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/resources/{userListSchema.xsd => user_schema.xsd} (79%) diff --git a/src/main/resources/userListSchema.xsd b/src/main/resources/user_schema.xsd similarity index 79% rename from src/main/resources/userListSchema.xsd rename to src/main/resources/user_schema.xsd index ef107db..93c18f9 100644 --- a/src/main/resources/userListSchema.xsd +++ b/src/main/resources/user_schema.xsd @@ -15,8 +15,8 @@ - - + + From cc8116b0dc5dc9759853d93d5bf7ad7d6e144f28 Mon Sep 17 00:00:00 2001 From: Maxi Date: Wed, 9 Oct 2019 21:55:50 +0200 Subject: [PATCH 007/126] Changed recipient type from String to long (now sending ID not name). --- src/main/resources/message_schema.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/message_schema.xsd b/src/main/resources/message_schema.xsd index 1b2f451..b902bcc 100644 --- a/src/main/resources/message_schema.xsd +++ b/src/main/resources/message_schema.xsd @@ -19,7 +19,7 @@ - + From a602e16372e661b2fc30f4da6c3878df93bc9e79 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Thu, 10 Oct 2019 21:23:51 +0200 Subject: [PATCH 008/126] Changed Sender element in message_schema.xsd to long to support user IDs --- src/main/resources/message_schema.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/message_schema.xsd b/src/main/resources/message_schema.xsd index b902bcc..4151e4b 100644 --- a/src/main/resources/message_schema.xsd +++ b/src/main/resources/message_schema.xsd @@ -18,7 +18,7 @@ - + From a195ed2c7e5afe0111961850c883d6c6e0733ba4 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Fri, 11 Oct 2019 15:10:56 +0200 Subject: [PATCH 009/126] Added MessageState enumeration and XJB file for message schema --- .classpath | 15 ++++++++----- .settings/org.eclipse.core.resources.prefs | 1 + .settings/org.eclipse.wst.common.component | 8 ++++++- pom.xml | 8 +++++++ src/main/java/envoy/schema/MessageState.java | 22 ++++++++++++++++++++ src/main/resources/message_schema.xsd | 11 +++++++++- src/main/xjb/bindings.xml | 15 +++++++++++++ 7 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 src/main/java/envoy/schema/MessageState.java create mode 100644 src/main/xjb/bindings.xml diff --git a/.classpath b/.classpath index cd5c385..a9a94b3 100644 --- a/.classpath +++ b/.classpath @@ -6,11 +6,6 @@ - - - - - @@ -41,5 +36,15 @@ + + + + + + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 93fb95b..8660235 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,6 +1,7 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 encoding//src/main/resources=UTF-8 +encoding//src/main/xjb=UTF-8 encoding//src/test/java=UTF-8 encoding//src/test/resources=UTF-8 encoding//target/generated-sources/jaxb=UTF-8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 9de5f51..08f1a01 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,7 +1,13 @@ + + - + + + + + diff --git a/pom.xml b/pom.xml index 50c664e..cf6ff6e 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,14 @@ envoy-common + + + src/main/resources + + + src/main/xjb + + org.codehaus.mojo diff --git a/src/main/java/envoy/schema/MessageState.java b/src/main/java/envoy/schema/MessageState.java new file mode 100644 index 0000000..0f174c6 --- /dev/null +++ b/src/main/java/envoy/schema/MessageState.java @@ -0,0 +1,22 @@ +package envoy.schema; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + +/** + * Project: envoy-common
+ * File: MessageState.java
+ * Created: 11 Oct 2019
+ * + * @author Kai S. K. Engelbart + */ +@XmlType(name = "") +@XmlEnum +public enum MessageState { + + Waiting, Sent, Received, Read; + + public String value() { return name(); } + + public static MessageState fromValue(String v) { return valueOf(v); } +} diff --git a/src/main/resources/message_schema.xsd b/src/main/resources/message_schema.xsd index 4151e4b..c3d09f9 100644 --- a/src/main/resources/message_schema.xsd +++ b/src/main/resources/message_schema.xsd @@ -21,7 +21,16 @@ - + + + + + + + + + + diff --git a/src/main/xjb/bindings.xml b/src/main/xjb/bindings.xml new file mode 100644 index 0000000..66ef12c --- /dev/null +++ b/src/main/xjb/bindings.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file From 430b99994620387dd163b1b2426c41b288fa9933 Mon Sep 17 00:00:00 2001 From: derharry333 Date: Sat, 12 Oct 2019 14:20:36 +0200 Subject: [PATCH 010/126] Fixed issue #5 in Envoy Server --- src/main/resources/message_schema.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/message_schema.xsd b/src/main/resources/message_schema.xsd index c3d09f9..0b27158 100644 --- a/src/main/resources/message_schema.xsd +++ b/src/main/resources/message_schema.xsd @@ -20,7 +20,7 @@ - + From a9b55ee1fb4bb9ceeb68577ea1efb019b1bada60 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sun, 27 Oct 2019 21:35:05 +0100 Subject: [PATCH 011/126] Added EnvoyException class --- .../java/envoy/exception/EnvoyException.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/envoy/exception/EnvoyException.java diff --git a/src/main/java/envoy/exception/EnvoyException.java b/src/main/java/envoy/exception/EnvoyException.java new file mode 100644 index 0000000..00f9946 --- /dev/null +++ b/src/main/java/envoy/exception/EnvoyException.java @@ -0,0 +1,20 @@ +package envoy.exception; + +/** + * Project: envoy-common
+ * File: EnvoyException.java
+ * Created: 27 Oct 2019
+ * + * @author Kai S. K. Engelbart + * @since Envoy v0.1-alpha + */ +public class EnvoyException extends Exception { + + private static final long serialVersionUID = 2096147309395387479L; + + public EnvoyException(String message, Throwable cause) { super(message, cause); } + + public EnvoyException(String message) { super(message); } + + public EnvoyException(Throwable cause) { super(cause); } +} From 81865e954c193508561cbb746af19f1db1f3acf5 Mon Sep 17 00:00:00 2001 From: Maxi Date: Sun, 27 Oct 2019 22:10:47 +0100 Subject: [PATCH 012/126] * Replacing the message_schema.xsd and the user_schema.xsd with sync_schema.xsd. * Added UserStatus * Changed bindings.xml to support the UserStatus Enum properly. --- src/main/java/envoy/schema/UserStatus.java | 22 ++++ .../{message_schema.xsd => sync_schema.xsd} | 116 ++++++++++-------- src/main/resources/user_schema.xsd | 23 ---- src/main/xjb/bindings.xml | 7 +- 4 files changed, 96 insertions(+), 72 deletions(-) create mode 100644 src/main/java/envoy/schema/UserStatus.java rename src/main/resources/{message_schema.xsd => sync_schema.xsd} (51%) delete mode 100644 src/main/resources/user_schema.xsd diff --git a/src/main/java/envoy/schema/UserStatus.java b/src/main/java/envoy/schema/UserStatus.java new file mode 100644 index 0000000..c4a5607 --- /dev/null +++ b/src/main/java/envoy/schema/UserStatus.java @@ -0,0 +1,22 @@ +package envoy.schema; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + +/** + * Project: envoy-common
+ * File: UserStatus.java
+ * Created: 27 Nov 2019
+ * + * @author Maximilian Käfer + */ +@XmlType(name = "") +@XmlEnum +public enum UserStatus { + + ONLINE, DONOTDISTURB, AFK, OFFLINE; + + public String value() { return name(); } + + public static UserStatus fromValue(String v) { return valueOf(v); } +} diff --git a/src/main/resources/message_schema.xsd b/src/main/resources/sync_schema.xsd similarity index 51% rename from src/main/resources/message_schema.xsd rename to src/main/resources/sync_schema.xsd index 0b27158..58d1ce7 100644 --- a/src/main/resources/message_schema.xsd +++ b/src/main/resources/sync_schema.xsd @@ -1,48 +1,68 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/user_schema.xsd b/src/main/resources/user_schema.xsd deleted file mode 100644 index 93c18f9..0000000 --- a/src/main/resources/user_schema.xsd +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/xjb/bindings.xml b/src/main/xjb/bindings.xml index 66ef12c..a690920 100644 --- a/src/main/xjb/bindings.xml +++ b/src/main/xjb/bindings.xml @@ -6,10 +6,15 @@ fixedAttributeAsConstantProperty="true"> - + + + + + \ No newline at end of file From 0251d120df24b509a2f3b8ccf3d0e16c450cfce7 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 28 Oct 2019 06:18:16 +0100 Subject: [PATCH 013/126] Fixed name of list properties --- .classpath | 1 + src/main/java/envoy/schema/UserStatus.java | 2 +- src/main/resources/sync_schema.xsd | 50 +++++++++++----------- src/main/xjb/bindings.xml | 17 +++++++- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/.classpath b/.classpath index a9a94b3..4482efd 100644 --- a/.classpath +++ b/.classpath @@ -32,6 +32,7 @@
+ diff --git a/src/main/java/envoy/schema/UserStatus.java b/src/main/java/envoy/schema/UserStatus.java index c4a5607..2ab571d 100644 --- a/src/main/java/envoy/schema/UserStatus.java +++ b/src/main/java/envoy/schema/UserStatus.java @@ -14,7 +14,7 @@ import javax.xml.bind.annotation.XmlType; @XmlEnum public enum UserStatus { - ONLINE, DONOTDISTURB, AFK, OFFLINE; + Online, DoNotDisturb, AFK, Offline; public String value() { return name(); } diff --git a/src/main/resources/sync_schema.xsd b/src/main/resources/sync_schema.xsd index 58d1ce7..7b20b87 100644 --- a/src/main/resources/sync_schema.xsd +++ b/src/main/resources/sync_schema.xsd @@ -4,17 +4,19 @@ xmlns="https://github.com/informatik-ag-ngl" elementFormDefault="qualified"> - - - - - - - - + + + + + + + + - + @@ -22,14 +24,14 @@ - + - - - - + + + + @@ -48,20 +50,20 @@ - + - - - - - - - - - + + + + + + + + + diff --git a/src/main/xjb/bindings.xml b/src/main/xjb/bindings.xml index a690920..4dc2c23 100644 --- a/src/main/xjb/bindings.xml +++ b/src/main/xjb/bindings.xml @@ -1,3 +1,5 @@ + + - + + + + + + + + + + - + + \ No newline at end of file From 57ecfcb9faa551cfe40077cefbbc62fb0aefa55c Mon Sep 17 00:00:00 2001 From: Maxi Date: Fri, 1 Nov 2019 12:17:00 +0100 Subject: [PATCH 014/126] Adjusted Java Doc Created --- .classpath | 6 ------ src/main/java/envoy/schema/UserStatus.java | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.classpath b/.classpath index 4482efd..d2c0172 100644 --- a/.classpath +++ b/.classpath @@ -13,12 +13,6 @@ - - - - - - diff --git a/src/main/java/envoy/schema/UserStatus.java b/src/main/java/envoy/schema/UserStatus.java index 2ab571d..f87d576 100644 --- a/src/main/java/envoy/schema/UserStatus.java +++ b/src/main/java/envoy/schema/UserStatus.java @@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlType; /** * Project: envoy-common
* File: UserStatus.java
- * Created: 27 Nov 2019
+ * Created: 27 Oct 2019
* * @author Maximilian Käfer */ From d47727a58441021685239eede6d0f312d7b28370 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 5 Nov 2019 06:01:17 +0100 Subject: [PATCH 015/126] Ignoring optional compile problems for generated sources --- .classpath | 1 + 1 file changed, 1 insertion(+) diff --git a/.classpath b/.classpath index a9a94b3..4482efd 100644 --- a/.classpath +++ b/.classpath @@ -32,6 +32,7 @@
+ From 16b935ca92119c1d556289c6fa1b1aede8bee937 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 4 Dec 2019 18:46:49 +0100 Subject: [PATCH 016/126] Removed unused project natures from .project --- .project | 2 -- 1 file changed, 2 deletions(-) diff --git a/.project b/.project index e729774..70cd37b 100644 --- a/.project +++ b/.project @@ -41,8 +41,6 @@ org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature - org.jboss.tools.jst.web.kb.kbnature - org.jboss.tools.cdi.core.cdinature org.eclipse.wst.common.project.facet.core.nature From 9dd3d9b22541803be01e088c4b327a61837e25fa Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 28 Dec 2019 22:03:41 +0200 Subject: [PATCH 017/126] Replaced sync XSD by custom objects * Removed JAXB dependencies * Added User, Message and TextMessage * Changed version to 0.2-alpha in POM --- .classpath | 12 --- .settings/org.eclipse.core.resources.prefs | 2 - .settings/org.eclipse.wst.common.component | 14 +-- pom.xml | 39 +------- src/main/java/envoy/data/Message.java | 97 ++++++++++++++++++++ src/main/java/envoy/data/TextMessage.java | 54 +++++++++++ src/main/java/envoy/data/User.java | 71 ++++++++++++++ src/main/java/envoy/schema/MessageState.java | 22 ----- src/main/java/envoy/schema/UserStatus.java | 22 ----- src/main/resources/sync_schema.xsd | 70 -------------- src/main/xjb/bindings.xml | 33 ------- 11 files changed, 231 insertions(+), 205 deletions(-) create mode 100644 src/main/java/envoy/data/Message.java create mode 100644 src/main/java/envoy/data/TextMessage.java create mode 100644 src/main/java/envoy/data/User.java delete mode 100644 src/main/java/envoy/schema/MessageState.java delete mode 100644 src/main/java/envoy/schema/UserStatus.java delete mode 100644 src/main/resources/sync_schema.xsd delete mode 100644 src/main/xjb/bindings.xml diff --git a/.classpath b/.classpath index d2c0172..88d37ef 100644 --- a/.classpath +++ b/.classpath @@ -24,18 +24,6 @@ - - - - - - - - - - - - diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 8660235..04cfa2c 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,8 +1,6 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 encoding//src/main/resources=UTF-8 -encoding//src/main/xjb=UTF-8 encoding//src/test/java=UTF-8 encoding//src/test/resources=UTF-8 -encoding//target/generated-sources/jaxb=UTF-8 encoding/=UTF-8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 08f1a01..a6896ac 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,13 +1,15 @@ - + + - + + - - - - + + + + diff --git a/pom.xml b/pom.xml index cf6ff6e..6e20167 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 informatik-ag-ngl envoy-common - 0.0.1-SNAPSHOT + 0.2-alpha Envoy Common https://github.com/informatik-ag-ngl/envoy-common @@ -16,44 +16,7 @@ 1.8 - - - org.codehaus.mojo - jaxb2-maven-plugin - 2.5.0 - - - envoy-common - - - src/main/resources - - - src/main/xjb - - - - - org.codehaus.mojo - jaxb2-maven-plugin - 2.5.0 - - - xjc - - xjc - - - - - envoy.schema - - src/main/resources - - - - \ No newline at end of file diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java new file mode 100644 index 0000000..555c751 --- /dev/null +++ b/src/main/java/envoy/data/Message.java @@ -0,0 +1,97 @@ +package envoy.data; + +import java.io.Serializable; +import java.util.Date; + +/** + * Represents a unique message with a unique, numeric ID. Further metadata + * includes the sender and recipient {@link User}s, as well as the creation + * date and the current {@link MessageStatus}.
+ *
+ * Project: envoy-common
+ * File: Message.java
+ * Created: 28.12.2019
+ * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.2-alpha + */ +public abstract class Message implements Serializable { + + private final long id; + private final User sender, recipient; + private final Date date; + + private MessageStatus status; + + private static final long serialVersionUID = -4393477412979594435L; + + /** + * Initializes a {@link Message} from the client's perspective. The current date + * is used as the message date and the status is set to + * {@link MessageStatus#WAITING}. + * + * @param id unique ID + * @param sender the user who sends the message + * @param recipient the user who receives the message + * @since Envoy Common v0.2-alpha + */ + public Message(long id, User sender, User recipient) { + this.id = id; + this.sender = sender; + this.recipient = recipient; + date = new Date(); + status = MessageStatus.WAITING; + } + + /** + * @return the ID of this message + * @since Envoy Common v0.2-alpha + */ + public long getId() { return id; } + + /** + * @return the sender of this message + * @since Envoy Common v0.2-alpha + */ + public User getSender() { return sender; } + + /** + * @return the recipient of this message + * @since Envoy Common v0.2-alpha + */ + public User getRecipient() { return recipient; } + + /** + * @return the date at which this message was created + * @since Envoy Common v0.2-alpha + */ + public Date getDate() { return date; } + + /** + * @return the current status of this message + * @since Envoy Common v0.2-alpha + */ + public MessageStatus getStatus() { return status; } + + /** + * Changes the current {@link MessageStatus} to the next logical status.
+ *
+ * The underlying order is as follows: + *
    + *
  1. {@link MessageStatus#WAITING} + *
  2. {@link MessageStatus#SENT} + *
  3. {@link MessageStatus#RECEIVED} + *
  4. {@link MessageStatus#READ} + *
+ * + * @since Envoy Common v0.2-alpha + */ + public void nextStatus() { + if (status == MessageStatus.READ) throw new IllegalStateException("Message status READ is already reached"); + status = MessageStatus.values()[status.ordinal() + 1]; + } + + public static enum MessageStatus { + WAITING, SENT, RECEIVED, READ + } +} \ No newline at end of file diff --git a/src/main/java/envoy/data/TextMessage.java b/src/main/java/envoy/data/TextMessage.java new file mode 100644 index 0000000..2ae7fc1 --- /dev/null +++ b/src/main/java/envoy/data/TextMessage.java @@ -0,0 +1,54 @@ +package envoy.data; + +import java.text.SimpleDateFormat; + +/** + * Represents a {@link Message} with content that is comprised of text.
+ *
+ * Project: envoy-common
+ * File: TextMessage.java
+ * Created: 28.12.2019
+ * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.2-alpha + */ +public class TextMessage extends Message { + + private final String content; + + private static final long serialVersionUID = 1538164720632899917L; + + /** + * Initializes a {@link TextMessage} from the client's perspective. The current + * date + * is used as the message date and the status is set to + * {@link MessageStatus#WAITING}. + * + * @param id unique ID + * @param sender the user who sends the message + * @param recipient the user who receives the message + * @param content the content of the message + * @since Envoy Common v0.2-alpha + */ + public TextMessage(long id, User sender, User recipient, String content) { + super(id, sender, recipient); + this.content = content; + } + + @Override + public String toString() { + return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,content=%s]", + getId(), + getSender(), + getRecipient(), + new SimpleDateFormat("dd.MM.yyyy hh:mm:ss").format(getDate()), + getStatus(), + content); + } + + /** + * @return the content of this {@link TextMessage} + * @since Envoy Common v0.2-alpha + */ + public String getContent() { return content; } +} \ No newline at end of file diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java new file mode 100644 index 0000000..afca690 --- /dev/null +++ b/src/main/java/envoy/data/User.java @@ -0,0 +1,71 @@ +package envoy.data; + +import java.io.Serializable; + +/** + * Represents a unique user with a unique, numeric ID, a name and a current + * {@link UserStatus}.
+ *
+ * Project: envoy-common
+ * File: User.java
+ * Created: 28.12.2019
+ * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.2-alpha + */ +public class User implements Serializable { + + private final long id; + private final String name; + + private UserStatus status; + + private static final long serialVersionUID = 3530947374856708236L; + + /** + * Initializes a {@link User}. The {@link UserStatus} is set to + * {@link UserStatus#OFFLINE}. + * + * @param id unique ID + * @param name user name + * @since Envoy Client v0.2-alpha + */ + public User(long id, String name) { + this.id = id; + this.name = name; + status = UserStatus.OFFLINE; + } + + @Override + public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } + + /** + * @return the ID of this {@link User} + * @since Envoy Client v0.2-alpha + */ + public long getId() { return id; } + + /** + * @return the name of this {@link User} + * @since Envoy Client v0.2-alpha + */ + public String getName() { return name; } + + /** + * @return the current status of this user + * @since Envoy Client v0.2-alpha + */ + public UserStatus getStatus() { return status; } + + /** + * Sets the current status of this user + * + * @param status the status to set + * @since Envoy Client v0.2-alpha + */ + public void setStatus(UserStatus status) { this.status = status; } + + public static enum UserStatus { + ONLINE, AWAY, BUSY, OFFLINE; + } +} \ No newline at end of file diff --git a/src/main/java/envoy/schema/MessageState.java b/src/main/java/envoy/schema/MessageState.java deleted file mode 100644 index 0f174c6..0000000 --- a/src/main/java/envoy/schema/MessageState.java +++ /dev/null @@ -1,22 +0,0 @@ -package envoy.schema; - -import javax.xml.bind.annotation.XmlEnum; -import javax.xml.bind.annotation.XmlType; - -/** - * Project: envoy-common
- * File: MessageState.java
- * Created: 11 Oct 2019
- * - * @author Kai S. K. Engelbart - */ -@XmlType(name = "") -@XmlEnum -public enum MessageState { - - Waiting, Sent, Received, Read; - - public String value() { return name(); } - - public static MessageState fromValue(String v) { return valueOf(v); } -} diff --git a/src/main/java/envoy/schema/UserStatus.java b/src/main/java/envoy/schema/UserStatus.java deleted file mode 100644 index f87d576..0000000 --- a/src/main/java/envoy/schema/UserStatus.java +++ /dev/null @@ -1,22 +0,0 @@ -package envoy.schema; - -import javax.xml.bind.annotation.XmlEnum; -import javax.xml.bind.annotation.XmlType; - -/** - * Project: envoy-common
- * File: UserStatus.java
- * Created: 27 Oct 2019
- * - * @author Maximilian Käfer - */ -@XmlType(name = "") -@XmlEnum -public enum UserStatus { - - Online, DoNotDisturb, AFK, Offline; - - public String value() { return name(); } - - public static UserStatus fromValue(String v) { return valueOf(v); } -} diff --git a/src/main/resources/sync_schema.xsd b/src/main/resources/sync_schema.xsd deleted file mode 100644 index 7b20b87..0000000 --- a/src/main/resources/sync_schema.xsd +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/xjb/bindings.xml b/src/main/xjb/bindings.xml deleted file mode 100644 index 4dc2c23..0000000 --- a/src/main/xjb/bindings.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From b59ed568b00f0640e9cd3e3e2f7c7610f05cf91b Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sun, 29 Dec 2019 10:53:48 +0200 Subject: [PATCH 018/126] Moved event classes to envoy-common --- src/main/java/envoy/data/TextMessage.java | 2 +- src/main/java/envoy/event/Event.java | 19 +++++ src/main/java/envoy/event/EventBus.java | 81 +++++++++++++++++++++ src/main/java/envoy/event/EventHandler.java | 18 +++++ src/main/java/envoy/event/MessageEvent.java | 27 +++++++ 5 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 src/main/java/envoy/event/Event.java create mode 100644 src/main/java/envoy/event/EventBus.java create mode 100644 src/main/java/envoy/event/EventHandler.java create mode 100644 src/main/java/envoy/event/MessageEvent.java diff --git a/src/main/java/envoy/data/TextMessage.java b/src/main/java/envoy/data/TextMessage.java index 2ae7fc1..3e4517b 100644 --- a/src/main/java/envoy/data/TextMessage.java +++ b/src/main/java/envoy/data/TextMessage.java @@ -41,7 +41,7 @@ public class TextMessage extends Message { getId(), getSender(), getRecipient(), - new SimpleDateFormat("dd.MM.yyyy hh:mm:ss").format(getDate()), + new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(getDate()), getStatus(), content); } diff --git a/src/main/java/envoy/event/Event.java b/src/main/java/envoy/event/Event.java new file mode 100644 index 0000000..f17b95b --- /dev/null +++ b/src/main/java/envoy/event/Event.java @@ -0,0 +1,19 @@ +package envoy.event; + +/** + * Project: envoy-common
+ * File: Event.java
+ * Created: 04.12.2019
+ * + * @author Kai S. K. Engelbart + * @param the type of the Event + * @since Envoy v0.2-alpha + */ +public interface Event { + + /** + * @return the data associated with this event + */ + T get(); +} + diff --git a/src/main/java/envoy/event/EventBus.java b/src/main/java/envoy/event/EventBus.java new file mode 100644 index 0000000..f2e5c9f --- /dev/null +++ b/src/main/java/envoy/event/EventBus.java @@ -0,0 +1,81 @@ +package envoy.event; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This class handles events by allowing {@link EventHandler} object to register + * themselves and then be notified about certain events dispatched by the event + * bus.
+ *
+ * The event bus is a singleton and can be used across the entire application to + * guarantee the propagation of events.
+ * + * Project: envoy-common
+ * File: EventBus.java
+ * Created: 04.12.2019
+ * + * @author Kai S. K. Engelbart + * @since Envoy v0.2-alpha + */ +public class EventBus { + + /** + * Contains all {@link EventHandler} instances registered at this + * {@link EventBus} as values mapped to by their supported {@link Event} + * classes. + */ + private Map>, List> handlers = new HashMap<>(); + + /** + * The singleton instance of this {@link EventBus} that is used across the + * entire application. + */ + private static EventBus eventBus = new EventBus(); + + /** + * This constructor is not accessible from outside this class because a + * singleton instance of it is provided by the {@link EventBus#getInstance()} + * method. + */ + private EventBus() {} + + /** + * @return the singleton instance of the {@link EventBus} + * @since Envoy v0.2-alpha + */ + public static EventBus getInstance() { return eventBus; } + + /** + * Registers an {@link EventHandler} to be notified when a + * {@link Event} of a certain type is dispatched. + * + * @param eventClass the class which the {@link EventHandler} is subscribed to + * @param handler the {@link EventHandler} to register + * @since Envoy v0.2-alpha + */ + public void register(Class> eventClass, EventHandler handler) { + if (!handlers.containsKey(eventClass)) handlers.put(eventClass, new ArrayList<>()); + handlers.get(eventClass).add(handler); + } + + /** + * Dispatches a {@link Event} to every {@link EventHandler} subscribed to it. + * + * @param event the {@link Event} to dispatch + * @since Envoy v0.2-alpha + */ + public void dispatch(Event event) { + handlers.keySet().stream().filter(event.getClass()::isAssignableFrom).map(handlers::get).flatMap(List::stream).forEach(h -> h.handle(event)); + } + + /** + * @return a map of all {@link EventHandler} instances currently registered at + * this {@link EventBus} with the {@link Event} classes they are + * subscribed to as keys + * @since Envoy v0.2-alpha + */ + public Map>, List> getHandlers() { return handlers; } +} diff --git a/src/main/java/envoy/event/EventHandler.java b/src/main/java/envoy/event/EventHandler.java new file mode 100644 index 0000000..f842476 --- /dev/null +++ b/src/main/java/envoy/event/EventHandler.java @@ -0,0 +1,18 @@ +package envoy.event; + +/** + * Project: envoy-common
+ * File: EventHandler.java
+ * Created: 04.12.2019
+ * + * @author Kai S. K. Engelbart + */ +public interface EventHandler { + + /** + * Consumes an event dispatched by the event bus. + * + * @param event The event dispatched by the event bus, only of supported type + */ + void handle(Event event); +} diff --git a/src/main/java/envoy/event/MessageEvent.java b/src/main/java/envoy/event/MessageEvent.java new file mode 100644 index 0000000..33a7607 --- /dev/null +++ b/src/main/java/envoy/event/MessageEvent.java @@ -0,0 +1,27 @@ +package envoy.event; + +import envoy.data.Message; + +/** + * Project: envoy-common
+ * File: MessageCreationEvent.java
+ * Created: 4 Dec 2019
+ * + * @author Kai S. K. Engelbart + */ +public class MessageEvent implements Event { + + protected final Message message; + + /** + * Initializes a {@link MessageEvent} conveying information about a + * {@link Message} object. + * + * @param message the {@link Message} object to attach to this event + * @since Envoy v0.2-alpha + */ + public MessageEvent(Message message) { this.message = message; } + + @Override + public Message get() { return message; } +} From 2e6b7ec2d05cf695f7c0293f5d12241e2666705f Mon Sep 17 00:00:00 2001 From: delvh Date: Sun, 29 Dec 2019 10:45:36 +0100 Subject: [PATCH 019/126] changed Javadoc error biggest commit of all times! --- src/main/java/envoy/data/TextMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/envoy/data/TextMessage.java b/src/main/java/envoy/data/TextMessage.java index 3e4517b..cbee210 100644 --- a/src/main/java/envoy/data/TextMessage.java +++ b/src/main/java/envoy/data/TextMessage.java @@ -22,7 +22,7 @@ public class TextMessage extends Message { * Initializes a {@link TextMessage} from the client's perspective. The current * date * is used as the message date and the status is set to - * {@link MessageStatus#WAITING}. + * {@link envoy.data.Message.MessageStatus#WAITING}. * * @param id unique ID * @param sender the user who sends the message From 974e86185e21bdbc07af19d162a7af4137f40021 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sun, 29 Dec 2019 11:47:35 +0200 Subject: [PATCH 020/126] Added LoginCredentials, moved SerializationUtils to envoy-common --- .../java/envoy/data/LoginCredentials.java | 59 ++++++++++++ .../java/envoy/util/SerializationUtils.java | 91 +++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 src/main/java/envoy/data/LoginCredentials.java create mode 100644 src/main/java/envoy/util/SerializationUtils.java diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java new file mode 100644 index 0000000..c7899d6 --- /dev/null +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -0,0 +1,59 @@ +package envoy.data; + +import java.io.Serializable; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * Project: envoy-common
+ * File: LoginCredentials.java
+ * Created: 29.12.2019
+ * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.2-alpha + */ +public class LoginCredentials implements Serializable { + + private final String name; + private final byte[] passwordHash; + + private static final long serialVersionUID = -7395245059059523314L; + + /** + * Creates an in stance of {@link LoginCredentials}. + * + * @param name the name of the user + * @param password the password of the user (will be converted to a hash) + * @throws NoSuchAlgorithmException + */ + public LoginCredentials(String name, char[] password) throws NoSuchAlgorithmException { + this.name = name; + passwordHash = getSha256(toByteArray(password)); + } + + private byte[] toByteArray(char[] chars) { + byte[] bytes = new byte[chars.length * 2]; + for (int i = 0; i < chars.length; ++i) { + bytes[i * 2] = (byte) (chars[i] >> 8); + bytes[i * 2 + 1] = (byte) (chars[i]); + } + return bytes; + } + + private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + return md.digest(input); + } + + /** + * @return the name of the user performing the login + * @since Envoy Common v0.2-alpha + */ + public String getName() { return name; } + + /** + * @return the password hash of the user performing the login + * @since Envoy Common v0.2-alpha + */ + public byte[] getPasswordHash() { return passwordHash; } +} \ No newline at end of file diff --git a/src/main/java/envoy/util/SerializationUtils.java b/src/main/java/envoy/util/SerializationUtils.java new file mode 100644 index 0000000..3813a00 --- /dev/null +++ b/src/main/java/envoy/util/SerializationUtils.java @@ -0,0 +1,91 @@ +package envoy.util; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.Serializable; + +import envoy.exception.EnvoyException; + +/** + * Project: envoy-client
+ * File: SerializationUtils.java
+ * Created: 23.12.2019
+ * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.2-alpha + */ +public class SerializationUtils { + + private SerializationUtils() {} + + /** + * Deserializes an arbitrary {@link Serializable} object from a file. + * + * @param the type of the object to deserialize + * @param file the file deserialize from + * @param serializedClass the class of the object to deserialize + * @return the deserialized object + * @throws EnvoyException if an error occurred during deserialization + * @since Envoy Common v0.2-alpha + */ + public static T read(File file, Class serializedClass) throws EnvoyException { + if (file == null) throw new NullPointerException("File is null"); + try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(file))) { + return serializedClass.cast(in.readObject()); + } catch (ClassNotFoundException | IOException e) { + throw new EnvoyException("Could not load serialized object", e); + } + } + + /** + * Serializes an arbitrary object to a file. + * + * @param file the file to serialize to + * @param obj the object to serialize + * @throws IOException if an error occurred during serialization + * @since Envoy Common v0.2-alpha + */ + public static void write(File file, Object obj) throws IOException { + if (file == null) throw new NullPointerException("File is null"); + if (obj == null) throw new NullPointerException("Object to serialize is null"); + if (!file.exists()) { + file.getParentFile().mkdirs(); + file.createNewFile(); + } + try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file))) { + out.writeObject(obj); + } + } + + /** + * Serializes an object and writes it into an output stream preceded by 4 bytes + * containing the number of serialized bytes. + * + * @param obj the object to serialize + * @param out the output stream to serialize to + * @throws IOException if an error occurred during serialization + */ + public static void writeBytesWithLength(Object obj, OutputStream out) throws IOException { + // Serialize object to byte array + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ObjectOutputStream oout = new ObjectOutputStream(baos)) { + oout.writeObject(obj); + } + byte[] objBytes = baos.toByteArray(); + + // Get length of byte array in bytes + byte[] objLen = getBytes(objBytes.length); + + // Write length and byte array + out.write(objLen); + out.write(objBytes); + } + + private static byte[] getBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8) }; } +} \ No newline at end of file From edae6ef7fd5bd02ef380a5403ca6a86922b4e241 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sun, 29 Dec 2019 12:53:16 +0200 Subject: [PATCH 021/126] Fixed bug in SerializationUtils, added toString to LoginCredentials --- src/main/java/envoy/data/LoginCredentials.java | 13 +++++++++++++ .../java/envoy/util/SerializationUtils.java | 17 ++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index c7899d6..86b166c 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -3,6 +3,7 @@ package envoy.data; import java.io.Serializable; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Formatter; /** * Project: envoy-common
@@ -31,6 +32,18 @@ public class LoginCredentials implements Serializable { passwordHash = getSha256(toByteArray(password)); } + @Override + public String toString() { + Formatter form = new Formatter(); + form.format("LoginCredentials[name=%s,passwordHash=", name); + for (int i = 0; i < passwordHash.length; i++) + form.format("%02x", passwordHash[i]); + form.format("]"); + String str = form.toString(); + form.close(); + return str; + } + private byte[] toByteArray(char[] chars) { byte[] bytes = new byte[chars.length * 2]; for (int i = 0; i < chars.length; ++i) { diff --git a/src/main/java/envoy/util/SerializationUtils.java b/src/main/java/envoy/util/SerializationUtils.java index 3813a00..dfd166b 100644 --- a/src/main/java/envoy/util/SerializationUtils.java +++ b/src/main/java/envoy/util/SerializationUtils.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; @@ -34,12 +35,14 @@ public class SerializationUtils { * @throws EnvoyException if an error occurred during deserialization * @since Envoy Common v0.2-alpha */ - public static T read(File file, Class serializedClass) throws EnvoyException { + public static T read(File file, Class serializedClass) throws IOException, ClassNotFoundException { if (file == null) throw new NullPointerException("File is null"); - try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(file))) { - return serializedClass.cast(in.readObject()); - } catch (ClassNotFoundException | IOException e) { - throw new EnvoyException("Could not load serialized object", e); + return read(new FileInputStream(file), serializedClass); + } + + public static T read(InputStream in, Class serializedClass) throws IOException, ClassNotFoundException { + try (ObjectInputStream oin = new ObjectInputStream(in)) { + return serializedClass.cast(oin.readObject()); } } @@ -80,12 +83,12 @@ public class SerializationUtils { byte[] objBytes = baos.toByteArray(); // Get length of byte array in bytes - byte[] objLen = getBytes(objBytes.length); + byte[] objLen = intToBytes(objBytes.length); // Write length and byte array out.write(objLen); out.write(objBytes); } - private static byte[] getBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8) }; } + private static byte[] intToBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n }; } } \ No newline at end of file From 45dc11e81cf5c57b38da2e5b2cb92096047d5b20 Mon Sep 17 00:00:00 2001 From: delvh Date: Mon, 30 Dec 2019 15:32:34 +0100 Subject: [PATCH 022/126] Create maven.yml Maven Build is automatically done on push --- .github/workflows/maven.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..91106d3 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,17 @@ +name: Java CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build with Maven + run: mvn -B package --file pom.xml From 4a8d5b5ef5017271c7b7bc1c0f977c756abff34a Mon Sep 17 00:00:00 2001 From: delvh Date: Mon, 30 Dec 2019 18:49:48 +0100 Subject: [PATCH 023/126] built general message class instead of subtypes of it additionally fixed malformed Javadoc in the entire repository --- .../java/envoy/data/LoginCredentials.java | 67 ++++----- src/main/java/envoy/data/Message.java | 136 +++++++++++++----- .../java/envoy/data/MessageAttachment.java | 26 ++++ src/main/java/envoy/data/TextMessage.java | 54 ------- src/main/java/envoy/data/User.java | 50 +++++-- .../java/envoy/exception/EnvoyException.java | 55 ++++--- .../java/envoy/util/SerializationUtils.java | 33 +++-- 7 files changed, 255 insertions(+), 166 deletions(-) create mode 100644 src/main/java/envoy/data/MessageAttachment.java delete mode 100644 src/main/java/envoy/data/TextMessage.java diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index 86b166c..a8d9c6b 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -9,55 +9,29 @@ import java.util.Formatter; * Project: envoy-common
* File: LoginCredentials.java
* Created: 29.12.2019
- * + * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ public class LoginCredentials implements Serializable { - private final String name; - private final byte[] passwordHash; - - private static final long serialVersionUID = -7395245059059523314L; + private static final long serialVersionUID = -7395245059059523314L; + private final String name; + private final byte[] passwordHash; /** * Creates an in stance of {@link LoginCredentials}. - * + * * @param name the name of the user * @param password the password of the user (will be converted to a hash) - * @throws NoSuchAlgorithmException + * @throws NoSuchAlgorithmException if the algorithm used is unknown + * @since Envoy Common v0.2-alpha */ public LoginCredentials(String name, char[] password) throws NoSuchAlgorithmException { this.name = name; passwordHash = getSha256(toByteArray(password)); } - @Override - public String toString() { - Formatter form = new Formatter(); - form.format("LoginCredentials[name=%s,passwordHash=", name); - for (int i = 0; i < passwordHash.length; i++) - form.format("%02x", passwordHash[i]); - form.format("]"); - String str = form.toString(); - form.close(); - return str; - } - - private byte[] toByteArray(char[] chars) { - byte[] bytes = new byte[chars.length * 2]; - for (int i = 0; i < chars.length; ++i) { - bytes[i * 2] = (byte) (chars[i] >> 8); - bytes[i * 2 + 1] = (byte) (chars[i]); - } - return bytes; - } - - private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { - MessageDigest md = MessageDigest.getInstance("SHA-256"); - return md.digest(input); - } - /** * @return the name of the user performing the login * @since Envoy Common v0.2-alpha @@ -69,4 +43,31 @@ public class LoginCredentials implements Serializable { * @since Envoy Common v0.2-alpha */ public byte[] getPasswordHash() { return passwordHash; } + + private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + return md.digest(input); + } + + private byte[] toByteArray(char[] chars) { + byte[] bytes = new byte[chars.length * 2]; + for (int i = 0; i < chars.length; ++i) { + bytes[i * 2] = (byte) (chars[i] >> 8); + bytes[i * 2 + 1] = (byte) (chars[i]); + } + return bytes; + } + + @Override + public String toString() { + try (Formatter form = new Formatter()) { + form.format("LoginCredentials[name=%s,passwordHash=", name); + for (byte element : passwordHash) { + form.format("%02x", element); + } + form.format("]"); + String str = form.toString(); + return str; + } + } } \ No newline at end of file diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index 555c751..acb3d6f 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -1,7 +1,9 @@ package envoy.data; import java.io.Serializable; +import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Optional; /** * Represents a unique message with a unique, numeric ID. Further metadata @@ -11,68 +13,121 @@ import java.util.Date; * Project: envoy-common
* File: Message.java
* Created: 28.12.2019
- * + * * @author Kai S. K. Engelbart + * @author Leon Hofmeister * @since Envoy Common v0.2-alpha */ public abstract class Message implements Serializable { - private final long id; - private final User sender, recipient; - private final Date date; + /** + * This enum defines all possible statuses a {link Message} can have. + * + * @since Envoy Common v0.2-alpha + */ + public static enum MessageStatus { + + /** + * is selected, if a message was sent but not received by the server yet. + */ + WAITING, + + /** + * is selected, if a sent message was received by the server. + */ + SENT, + + /** + * is selected, if a message was delivered from the server to the recipient, but + * has not been read yet. + */ + RECEIVED, + + /** + * is selected, if a recipient opened the corresponding chat of said message. + */ + READ + } + + private static final long serialVersionUID = -4393477412979594435L; + private final long id; + + private final User sender, recipient; + + private final Date date; + + private final String text; + + private final MessageAttachment messageAttachment; private MessageStatus status; - private static final long serialVersionUID = -4393477412979594435L; - /** * Initializes a {@link Message} from the client's perspective. The current date * is used as the message date and the status is set to * {@link MessageStatus#WAITING}. - * - * @param id unique ID - * @param sender the user who sends the message - * @param recipient the user who receives the message + * + * @param the type of the attachment + * @param id unique ID + * @param sender the user who sends the message + * @param recipient the user who receives the message + * @param text the text content of the message + * @param attachment the attachment of the message, if present * @since Envoy Common v0.2-alpha */ - public Message(long id, User sender, User recipient) { - this.id = id; - this.sender = sender; - this.recipient = recipient; - date = new Date(); - status = MessageStatus.WAITING; + public Message(long id, User sender, User recipient, String text, @SuppressWarnings("rawtypes") Optional attachment) { + this.id = id; + this.sender = sender; + this.recipient = recipient; + this.text = text; + this.messageAttachment = attachment.isEmpty() ? null : attachment.get(); + this.date = new Date(); + this.status = MessageStatus.WAITING; } - /** - * @return the ID of this message - * @since Envoy Common v0.2-alpha - */ - public long getId() { return id; } - - /** - * @return the sender of this message - * @since Envoy Common v0.2-alpha - */ - public User getSender() { return sender; } - - /** - * @return the recipient of this message - * @since Envoy Common v0.2-alpha - */ - public User getRecipient() { return recipient; } - /** * @return the date at which this message was created * @since Envoy Common v0.2-alpha */ public Date getDate() { return date; } + /** + * @return the ID of this message + * @since Envoy Common v0.2-alpha + */ + public long getId() { return id; } + + /** + * @param the type of the message attachment + * @return the messageAttachment + * @since Envoy Common v0.2-alpha + */ + public MessageAttachment getMessageAttachment() { return messageAttachment; } + + /** + * @return the recipient of this message + * @since Envoy Common v0.2-alpha + */ + public User getRecipient() { return recipient; } + + /** + * @return the sender of this message + * @since Envoy Common v0.2-alpha + */ + public User getSender() { return sender; } + /** * @return the current status of this message * @since Envoy Common v0.2-alpha */ public MessageStatus getStatus() { return status; } + /** + * @return the text content of this message + * @since Envoy Common v0.2-alpha + */ + public String getText() { return text; } + /** * Changes the current {@link MessageStatus} to the next logical status.
*
@@ -83,7 +138,7 @@ public abstract class Message implements Serializable { *
  • {@link MessageStatus#RECEIVED} *
  • {@link MessageStatus#READ} * - * + * * @since Envoy Common v0.2-alpha */ public void nextStatus() { @@ -91,7 +146,14 @@ public abstract class Message implements Serializable { status = MessageStatus.values()[status.ordinal() + 1]; } - public static enum MessageStatus { - WAITING, SENT, RECEIVED, READ + @Override + public String toString() { + return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,content=%s]", + id, + sender, + recipient, + new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(date), + status, + text); } } \ No newline at end of file diff --git a/src/main/java/envoy/data/MessageAttachment.java b/src/main/java/envoy/data/MessageAttachment.java new file mode 100644 index 0000000..fa86998 --- /dev/null +++ b/src/main/java/envoy/data/MessageAttachment.java @@ -0,0 +1,26 @@ +package envoy.data; + +import java.io.Serializable; + +import javax.swing.Scrollable; + +/** + * This Interface should be used for any type supposed to be a {@link Message} + * attachment (i.e. images or sound).
    + *
    + * Project: envoy-common
    + * File: MessageAttachment.java
    + * Created: 30 Dec 2019
    + * + * @author Leon Hofmeister + * @param the type of this message attachment + * @since Envoy Common v0.2-alpha + */ +public interface MessageAttachment extends Serializable, Scrollable { + + /** + * @return the type implementing this interface + * @since Envoy Common v0.2-alpha + */ + T get(); +} diff --git a/src/main/java/envoy/data/TextMessage.java b/src/main/java/envoy/data/TextMessage.java deleted file mode 100644 index cbee210..0000000 --- a/src/main/java/envoy/data/TextMessage.java +++ /dev/null @@ -1,54 +0,0 @@ -package envoy.data; - -import java.text.SimpleDateFormat; - -/** - * Represents a {@link Message} with content that is comprised of text.
    - *
    - * Project: envoy-common
    - * File: TextMessage.java
    - * Created: 28.12.2019
    - * - * @author Kai S. K. Engelbart - * @since Envoy Common v0.2-alpha - */ -public class TextMessage extends Message { - - private final String content; - - private static final long serialVersionUID = 1538164720632899917L; - - /** - * Initializes a {@link TextMessage} from the client's perspective. The current - * date - * is used as the message date and the status is set to - * {@link envoy.data.Message.MessageStatus#WAITING}. - * - * @param id unique ID - * @param sender the user who sends the message - * @param recipient the user who receives the message - * @param content the content of the message - * @since Envoy Common v0.2-alpha - */ - public TextMessage(long id, User sender, User recipient, String content) { - super(id, sender, recipient); - this.content = content; - } - - @Override - public String toString() { - return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,content=%s]", - getId(), - getSender(), - getRecipient(), - new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(getDate()), - getStatus(), - content); - } - - /** - * @return the content of this {@link TextMessage} - * @since Envoy Common v0.2-alpha - */ - public String getContent() { return content; } -} \ No newline at end of file diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java index afca690..6109218 100644 --- a/src/main/java/envoy/data/User.java +++ b/src/main/java/envoy/data/User.java @@ -9,23 +9,53 @@ import java.io.Serializable; * Project: envoy-common
    * File: User.java
    * Created: 28.12.2019
    - * + * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ public class User implements Serializable { - private final long id; - private final String name; + /** + * This enum defines all possible statuses a user can have. + * + * @since Envoy Common v0.2-alpha + */ + public static enum UserStatus { - private UserStatus status; + /** + * select this, if a user is online and can be interacted with + */ + ONLINE, + + /** + * select this, if a user is online but unavailable at the moment (sudden + * interruption) + */ + AWAY, + + /** + * select this, if a user is online but unavailable at the moment (polite way) + */ + BUSY, + + /** + * select this, if a user is offline + */ + OFFLINE; + } private static final long serialVersionUID = 3530947374856708236L; + private final long id; + + private final String name; + + private UserStatus status; + /** * Initializes a {@link User}. The {@link UserStatus} is set to * {@link UserStatus#OFFLINE}. - * + * * @param id unique ID * @param name user name * @since Envoy Client v0.2-alpha @@ -36,9 +66,6 @@ public class User implements Serializable { status = UserStatus.OFFLINE; } - @Override - public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } - /** * @return the ID of this {@link User} * @since Envoy Client v0.2-alpha @@ -59,13 +86,12 @@ public class User implements Serializable { /** * Sets the current status of this user - * + * * @param status the status to set * @since Envoy Client v0.2-alpha */ public void setStatus(UserStatus status) { this.status = status; } - public static enum UserStatus { - ONLINE, AWAY, BUSY, OFFLINE; - } + @Override + public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } } \ No newline at end of file diff --git a/src/main/java/envoy/exception/EnvoyException.java b/src/main/java/envoy/exception/EnvoyException.java index 00f9946..650e1bb 100644 --- a/src/main/java/envoy/exception/EnvoyException.java +++ b/src/main/java/envoy/exception/EnvoyException.java @@ -1,20 +1,35 @@ -package envoy.exception; - -/** - * Project: envoy-common
    - * File: EnvoyException.java
    - * Created: 27 Oct 2019
    - * - * @author Kai S. K. Engelbart - * @since Envoy v0.1-alpha - */ -public class EnvoyException extends Exception { - - private static final long serialVersionUID = 2096147309395387479L; - - public EnvoyException(String message, Throwable cause) { super(message, cause); } - - public EnvoyException(String message) { super(message); } - - public EnvoyException(Throwable cause) { super(cause); } -} +package envoy.exception; + +/** + * Project: envoy-common
    + * File: EnvoyException.java
    + * Created: 27 Oct 2019
    + * + * @author Kai S. K. Engelbart + * @since Envoy v0.1-alpha + */ +public class EnvoyException extends Exception { + + private static final long serialVersionUID = 2096147309395387479L; + + /** + * @param message the message to display once this Exception is thrown + * @since Envoy Common v0.2-alpha + */ + public EnvoyException(String message) { super(message); } + + /** + * @param message the message to display once this Exception is thrown + * @param cause the {@link Throwable} which resulted in the throw of an + * EnvoyException + * @since Envoy Common v0.2-alpha + */ + public EnvoyException(String message, Throwable cause) { super(message, cause); } + + /** + * @param cause the {@link Throwable} which resulted in the throw of an + * EnvoyException + * @since Envoy Common v0.2-alpha + */ + public EnvoyException(Throwable cause) { super(cause); } +} diff --git a/src/main/java/envoy/util/SerializationUtils.java b/src/main/java/envoy/util/SerializationUtils.java index dfd166b..c070733 100644 --- a/src/main/java/envoy/util/SerializationUtils.java +++ b/src/main/java/envoy/util/SerializationUtils.java @@ -11,28 +11,29 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; -import envoy.exception.EnvoyException; - /** * Project: envoy-client
    * File: SerializationUtils.java
    * Created: 23.12.2019
    - * + * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ public class SerializationUtils { - private SerializationUtils() {} + private static byte[] intToBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n }; } /** * Deserializes an arbitrary {@link Serializable} object from a file. - * + * * @param the type of the object to deserialize - * @param file the file deserialize from + * @param file the file to deserialize from * @param serializedClass the class of the object to deserialize * @return the deserialized object - * @throws EnvoyException if an error occurred during deserialization + * @throws IOException if something failed while deserializing the + * object + * @throws ClassNotFoundException if the deserialized object can not be linked + * to a class * @since Envoy Common v0.2-alpha */ public static T read(File file, Class serializedClass) throws IOException, ClassNotFoundException { @@ -40,6 +41,18 @@ public class SerializationUtils { return read(new FileInputStream(file), serializedClass); } + /** + * @param the deserialized object + * @param in the {@link InputStream} of a serialized Object + * @param serializedClass the object type to convert the deserialized object + * into + * @return the deserialized object + * @throws IOException if something failed while deserializing the + * object + * @throws ClassNotFoundException if the deserialized object can not be linked + * to a class + * @since Envoy Common v0.2-alpha + */ public static T read(InputStream in, Class serializedClass) throws IOException, ClassNotFoundException { try (ObjectInputStream oin = new ObjectInputStream(in)) { return serializedClass.cast(oin.readObject()); @@ -48,7 +61,7 @@ public class SerializationUtils { /** * Serializes an arbitrary object to a file. - * + * * @param file the file to serialize to * @param obj the object to serialize * @throws IOException if an error occurred during serialization @@ -69,7 +82,7 @@ public class SerializationUtils { /** * Serializes an object and writes it into an output stream preceded by 4 bytes * containing the number of serialized bytes. - * + * * @param obj the object to serialize * @param out the output stream to serialize to * @throws IOException if an error occurred during serialization @@ -90,5 +103,5 @@ public class SerializationUtils { out.write(objBytes); } - private static byte[] intToBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n }; } + private SerializationUtils() {} } \ No newline at end of file From b66900c8645ccdcabf8e5638dc8941829ba25d2b Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 31 Dec 2019 11:16:52 +0200 Subject: [PATCH 024/126] Added MessageBuilder, enhanced Javadoc --- .../java/envoy/data/LoginCredentials.java | 17 +-- src/main/java/envoy/data/Message.java | 83 ++++++------ .../java/envoy/data/MessageAttachment.java | 6 +- src/main/java/envoy/data/MessageBuilder.java | 125 ++++++++++++++++++ src/main/java/envoy/data/User.java | 7 +- src/main/java/envoy/event/MessageEvent.java | 3 + 6 files changed, 180 insertions(+), 61 deletions(-) create mode 100644 src/main/java/envoy/data/MessageBuilder.java diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index a8d9c6b..7166ad0 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -6,6 +6,8 @@ import java.security.NoSuchAlgorithmException; import java.util.Formatter; /** + * Contains a {@link User}'s login information.
    + *
    * Project: envoy-common
    * File: LoginCredentials.java
    * Created: 29.12.2019
    @@ -15,10 +17,11 @@ import java.util.Formatter; */ public class LoginCredentials implements Serializable { - private static final long serialVersionUID = -7395245059059523314L; private final String name; private final byte[] passwordHash; + private static final long serialVersionUID = -7395245059059523314L; + /** * Creates an in stance of {@link LoginCredentials}. * @@ -44,10 +47,7 @@ public class LoginCredentials implements Serializable { */ public byte[] getPasswordHash() { return passwordHash; } - private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { - MessageDigest md = MessageDigest.getInstance("SHA-256"); - return md.digest(input); - } + private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { return MessageDigest.getInstance("SHA-256").digest(input); } private byte[] toByteArray(char[] chars) { byte[] bytes = new byte[chars.length * 2]; @@ -62,12 +62,9 @@ public class LoginCredentials implements Serializable { public String toString() { try (Formatter form = new Formatter()) { form.format("LoginCredentials[name=%s,passwordHash=", name); - for (byte element : passwordHash) { + for (byte element : passwordHash) form.format("%02x", element); - } - form.format("]"); - String str = form.toString(); - return str; + return form.format("]").toString(); } } } \ No newline at end of file diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index acb3d6f..8e676a6 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -3,7 +3,6 @@ package envoy.data; import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.Optional; /** * Represents a unique message with a unique, numeric ID. Further metadata @@ -18,10 +17,10 @@ import java.util.Optional; * @author Leon Hofmeister * @since Envoy Common v0.2-alpha */ -public abstract class Message implements Serializable { +public class Message implements Serializable { /** - * This enum defines all possible statuses a {link Message} can have. + * This enumeration defines all possible statuses a {link Message} can have. * * @since Envoy Common v0.2-alpha */ @@ -49,48 +48,41 @@ public abstract class Message implements Serializable { READ } - private static final long serialVersionUID = -4393477412979594435L; - private final long id; - - private final User sender, recipient; - - private final Date date; - - private final String text; - - private final MessageAttachment messageAttachment; + private final long id; + private final User sender, recipient; + private final Date date; + private final String text; + private final MessageAttachment attachment; private MessageStatus status; + private static final long serialVersionUID = -4393477412979594435L; + /** - * Initializes a {@link Message} from the client's perspective. The current date - * is used as the message date and the status is set to - * {@link MessageStatus#WAITING}. + * Initializes a {@link Message} with values for all of its properties. The use + * of this constructor is only intended for the {@link MessageBuilder} class, as + * this class provides {@code null} checks and default values for all + * properties. * - * @param the type of the attachment * @param id unique ID * @param sender the user who sends the message * @param recipient the user who receives the message + * @param date the creation date of the message * @param text the text content of the message * @param attachment the attachment of the message, if present + * @param status the current {@link MessageStatus} of the message * @since Envoy Common v0.2-alpha */ - public Message(long id, User sender, User recipient, String text, @SuppressWarnings("rawtypes") Optional attachment) { - this.id = id; - this.sender = sender; - this.recipient = recipient; - this.text = text; - this.messageAttachment = attachment.isEmpty() ? null : attachment.get(); - this.date = new Date(); - this.status = MessageStatus.WAITING; + Message(long id, User sender, User recipient, Date date, String text, MessageAttachment attachment, MessageStatus status) { + this.id = id; + this.sender = sender; + this.recipient = recipient; + this.date = date; + this.text = text; + this.attachment = attachment; + this.status = status; } - /** - * @return the date at which this message was created - * @since Envoy Common v0.2-alpha - */ - public Date getDate() { return date; } - /** * @return the ID of this message * @since Envoy Common v0.2-alpha @@ -98,11 +90,10 @@ public abstract class Message implements Serializable { public long getId() { return id; } /** - * @param the type of the message attachment - * @return the messageAttachment + * @return the sender of this message * @since Envoy Common v0.2-alpha */ - public MessageAttachment getMessageAttachment() { return messageAttachment; } + public User getSender() { return sender; } /** * @return the recipient of this message @@ -111,16 +102,10 @@ public abstract class Message implements Serializable { public User getRecipient() { return recipient; } /** - * @return the sender of this message + * @return the date at which this message was created * @since Envoy Common v0.2-alpha */ - public User getSender() { return sender; } - - /** - * @return the current status of this message - * @since Envoy Common v0.2-alpha - */ - public MessageStatus getStatus() { return status; } + public Date getDate() { return date; } /** * @return the text content of this message @@ -128,6 +113,18 @@ public abstract class Message implements Serializable { */ public String getText() { return text; } + /** + * @return the messageAttachment + * @since Envoy Common v0.2-alpha + */ + public MessageAttachment getAttachment() { return attachment; } + + /** + * @return the current status of this message + * @since Envoy Common v0.2-alpha + */ + public MessageStatus getStatus() { return status; } + /** * Changes the current {@link MessageStatus} to the next logical status.
    *
    @@ -148,7 +145,7 @@ public abstract class Message implements Serializable { @Override public String toString() { - return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,content=%s]", + return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,text=%s]", id, sender, recipient, diff --git a/src/main/java/envoy/data/MessageAttachment.java b/src/main/java/envoy/data/MessageAttachment.java index fa86998..ee4db64 100644 --- a/src/main/java/envoy/data/MessageAttachment.java +++ b/src/main/java/envoy/data/MessageAttachment.java @@ -2,10 +2,8 @@ package envoy.data; import java.io.Serializable; -import javax.swing.Scrollable; - /** - * This Interface should be used for any type supposed to be a {@link Message} + * This interface should be used for any type supposed to be a {@link Message} * attachment (i.e. images or sound).
    *
    * Project: envoy-common
    @@ -16,7 +14,7 @@ import javax.swing.Scrollable; * @param the type of this message attachment * @since Envoy Common v0.2-alpha */ -public interface MessageAttachment extends Serializable, Scrollable { +public interface MessageAttachment extends Serializable { /** * @return the type implementing this interface diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java new file mode 100644 index 0000000..4217663 --- /dev/null +++ b/src/main/java/envoy/data/MessageBuilder.java @@ -0,0 +1,125 @@ +package envoy.data; + +import java.util.Date; + +import envoy.data.Message.MessageStatus; + +/** + * Provides a method of constructing the {@link Message} class.
    + *
    + * Project: envoy-common
    + * File: MessageBuilder.java
    + * Created: 31.12.2019
    + * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.2-alpha + */ +public class MessageBuilder { + + // Mandatory properties without default values + private final User sender, recipient; + + // Properties with default values + private long id; + private Date date; + private String text; + private MessageAttachment attachment; + private Message.MessageStatus status; + + /** + * Creates an instance of {@link MessageBuilder} with all mandatory values + * without defaults for the {@link Message} class. + * + * @param sender the user who sends the {@link Message} + * @param recipient the user who received the {@link Message} + * @since Envoy Common v0.2-alpha + */ + public MessageBuilder(User sender, User recipient) { + if (sender == null) throw new NullPointerException("Message sender is null"); + if (recipient == null) throw new NullPointerException("Message recipient is null"); + this.sender = sender; + this.recipient = recipient; + } + + /** + * Creates an instance of {@link Message} with the previously supplied values. + * If a mandatory value is not set, a default value will be used instead:
    + *
    + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    {@code date}{@code new Date()}
    {@code text}{@code ""}
    {@code status}{@code MessageStatus.WAITING}
    + * + * @return a new instance of {@link Message} + * @since Envoy Common v0.2-alpha + */ + public Message build() { + // Supplement default values + if (date == null) date = new Date(); + if (text == null) text = ""; + if (status == null) status = MessageStatus.WAITING; + + return new Message(id, sender, recipient, date, text, attachment, status); + } + + /** + * @param id the unique ID of the {@link Message} to create + * @return this {@link MessageBuilder} + * @since Envoy Common v0.2-alpha + */ + public MessageBuilder setId(long id) { + this.id = id; + return this; + } + + /** + * @param date the creation date of the {@link Message} to create + * @return this {@link MessageBuilder} + * @since Envoy Common v0.2-alpha + */ + public MessageBuilder setDate(Date date) { + this.date = date; + return this; + } + + /** + * @param text the text of the {@link Message} to create + * @return this {@link MessageBuilder} + * @since Envoy Common v0.2-alpha + */ + public MessageBuilder setText(String text) { + this.text = text; + return this; + } + + /** + * @param attachment the {@link MessageAttachment} of the {@link Message} to + * create + * @return this {@link MessageBuilder} + * @since Envoy Common v0.2-alpha + */ + public MessageBuilder setAttachment(MessageAttachment attachment) { + this.attachment = attachment; + return this; + } + + /** + * @param status the {@link MessageStatus} of the {@link Message} to create + * @return this {@link MessageBuilder} + * @since Envoy Common v0.2-alpha + */ + public MessageBuilder setStatus(Message.MessageStatus status) { + this.status = status; + return this; + } +} \ No newline at end of file diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java index 6109218..c49d361 100644 --- a/src/main/java/envoy/data/User.java +++ b/src/main/java/envoy/data/User.java @@ -16,7 +16,7 @@ import java.io.Serializable; public class User implements Serializable { /** - * This enum defines all possible statuses a user can have. + * This enumeration defines all possible statuses a user can have. * * @since Envoy Common v0.2-alpha */ @@ -44,14 +44,13 @@ public class User implements Serializable { OFFLINE; } - private static final long serialVersionUID = 3530947374856708236L; - private final long id; - private final String name; private UserStatus status; + private static final long serialVersionUID = 3530947374856708236L; + /** * Initializes a {@link User}. The {@link UserStatus} is set to * {@link UserStatus#OFFLINE}. diff --git a/src/main/java/envoy/event/MessageEvent.java b/src/main/java/envoy/event/MessageEvent.java index 33a7607..45a7f40 100644 --- a/src/main/java/envoy/event/MessageEvent.java +++ b/src/main/java/envoy/event/MessageEvent.java @@ -11,6 +11,9 @@ import envoy.data.Message; */ public class MessageEvent implements Event { + /** + * the {@link Message} attached to this {@link MessageEvent}. + */ protected final Message message; /** From 757f661e08322945a8b6767b1cf1f8bcfd41bcf4 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 31 Dec 2019 11:20:35 +0200 Subject: [PATCH 025/126] Fixed member orders in some classes --- .../java/envoy/data/LoginCredentials.java | 28 ++++----- src/main/java/envoy/data/Message.java | 58 +++++++++---------- src/main/java/envoy/data/User.java | 10 ++-- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index 7166ad0..58d14d4 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -17,8 +17,8 @@ import java.util.Formatter; */ public class LoginCredentials implements Serializable { - private final String name; - private final byte[] passwordHash; + private final String name; + private final byte[] passwordHash; private static final long serialVersionUID = -7395245059059523314L; @@ -35,18 +35,6 @@ public class LoginCredentials implements Serializable { passwordHash = getSha256(toByteArray(password)); } - /** - * @return the name of the user performing the login - * @since Envoy Common v0.2-alpha - */ - public String getName() { return name; } - - /** - * @return the password hash of the user performing the login - * @since Envoy Common v0.2-alpha - */ - public byte[] getPasswordHash() { return passwordHash; } - private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { return MessageDigest.getInstance("SHA-256").digest(input); } private byte[] toByteArray(char[] chars) { @@ -67,4 +55,16 @@ public class LoginCredentials implements Serializable { return form.format("]").toString(); } } + + /** + * @return the name of the user performing the login + * @since Envoy Common v0.2-alpha + */ + public String getName() { return name; } + + /** + * @return the password hash of the user performing the login + * @since Envoy Common v0.2-alpha + */ + public byte[] getPasswordHash() { return passwordHash; } } \ No newline at end of file diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index 8e676a6..b2f6545 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -83,6 +83,35 @@ public class Message implements Serializable { this.status = status; } + /** + * Changes the current {@link MessageStatus} to the next logical status.
    + *
    + * The underlying order is as follows: + *
      + *
    1. {@link MessageStatus#WAITING} + *
    2. {@link MessageStatus#SENT} + *
    3. {@link MessageStatus#RECEIVED} + *
    4. {@link MessageStatus#READ} + *
    + * + * @since Envoy Common v0.2-alpha + */ + public void nextStatus() { + if (status == MessageStatus.READ) throw new IllegalStateException("Message status READ is already reached"); + status = MessageStatus.values()[status.ordinal() + 1]; + } + + @Override + public String toString() { + return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,text=%s]", + id, + sender, + recipient, + new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(date), + status, + text); + } + /** * @return the ID of this message * @since Envoy Common v0.2-alpha @@ -124,33 +153,4 @@ public class Message implements Serializable { * @since Envoy Common v0.2-alpha */ public MessageStatus getStatus() { return status; } - - /** - * Changes the current {@link MessageStatus} to the next logical status.
    - *
    - * The underlying order is as follows: - *
      - *
    1. {@link MessageStatus#WAITING} - *
    2. {@link MessageStatus#SENT} - *
    3. {@link MessageStatus#RECEIVED} - *
    4. {@link MessageStatus#READ} - *
    - * - * @since Envoy Common v0.2-alpha - */ - public void nextStatus() { - if (status == MessageStatus.READ) throw new IllegalStateException("Message status READ is already reached"); - status = MessageStatus.values()[status.ordinal() + 1]; - } - - @Override - public String toString() { - return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,text=%s]", - id, - sender, - recipient, - new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(date), - status, - text); - } } \ No newline at end of file diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java index c49d361..de29fc4 100644 --- a/src/main/java/envoy/data/User.java +++ b/src/main/java/envoy/data/User.java @@ -44,8 +44,8 @@ public class User implements Serializable { OFFLINE; } - private final long id; - private final String name; + private final long id; + private final String name; private UserStatus status; @@ -65,6 +65,9 @@ public class User implements Serializable { status = UserStatus.OFFLINE; } + @Override + public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } + /** * @return the ID of this {@link User} * @since Envoy Client v0.2-alpha @@ -90,7 +93,4 @@ public class User implements Serializable { * @since Envoy Client v0.2-alpha */ public void setStatus(UserStatus status) { this.status = status; } - - @Override - public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } } \ No newline at end of file From a418d3efbcd26240f49ab73a6e30cd0901623bc1 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 31 Dec 2019 16:38:07 +0200 Subject: [PATCH 026/126] Storing sender and recipient IDs in message, added contact list to User --- src/main/java/envoy/data/Message.java | 19 +++++++++++++++++-- src/main/java/envoy/data/User.java | 13 +++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index b2f6545..ddbfba2 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -48,8 +48,8 @@ public class Message implements Serializable { READ } - private final long id; - private final User sender, recipient; + private final long id, senderId, recipientId; + private final transient User sender, recipient; private final Date date; private final String text; private final MessageAttachment attachment; @@ -81,6 +81,9 @@ public class Message implements Serializable { this.text = text; this.attachment = attachment; this.status = status; + + senderId = sender.getId(); + recipientId = recipient.getId(); } /** @@ -124,12 +127,24 @@ public class Message implements Serializable { */ public User getSender() { return sender; } + /** + * @return the sender ID of this message + * @since Envoy Common v0.2-alpha + */ + public long getSenderId() { return senderId; } + /** * @return the recipient of this message * @since Envoy Common v0.2-alpha */ public User getRecipient() { return recipient; } + /** + * @return the recipient ID of this message + * @since Envoy Common v0.2-alpha + */ + public long getRecipientId() { return recipientId; } + /** * @return the date at which this message was created * @since Envoy Common v0.2-alpha diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java index de29fc4..d5c0bbc 100644 --- a/src/main/java/envoy/data/User.java +++ b/src/main/java/envoy/data/User.java @@ -1,6 +1,8 @@ package envoy.data; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; /** * Represents a unique user with a unique, numeric ID, a name and a current @@ -44,8 +46,9 @@ public class User implements Serializable { OFFLINE; } - private final long id; - private final String name; + private final long id; + private final String name; + private final List contacts = new ArrayList<>(); private UserStatus status; @@ -80,6 +83,12 @@ public class User implements Serializable { */ public String getName() { return name; } + /** + * @return a list of all users this user can send messages to + * @since Envoy Client v0.2-alpha + */ + public List getContacts() { return contacts; } + /** * @return the current status of this user * @since Envoy Client v0.2-alpha From b84f05e1114856d0832c6187279b9832908e4347 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 31 Dec 2019 18:10:12 +0200 Subject: [PATCH 027/126] Added MessageIdGenerator for providing unique message IDs in the future. --- .../java/envoy/data/MessageIdGenerator.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/envoy/data/MessageIdGenerator.java diff --git a/src/main/java/envoy/data/MessageIdGenerator.java b/src/main/java/envoy/data/MessageIdGenerator.java new file mode 100644 index 0000000..ba52e83 --- /dev/null +++ b/src/main/java/envoy/data/MessageIdGenerator.java @@ -0,0 +1,41 @@ +package envoy.data; + +/** + * Generates increasing IDs between two numbers.
    + *
    + * Project: envoy-common
    + * File: MessageIdGenerator.java
    + * Created: 31.12.2019
    + * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.2-alpha + */ +public class MessageIdGenerator { + + private final long end; + private long current; + + /** + * Creates an instance of {@link MessageIdGenerator}. + * + * @param begin the first ID + * @param end the last ID + */ + public MessageIdGenerator(long begin, long end) { + current = begin; + this.end = end; + } + + /** + * @return {@code true} if there are unused IDs remaining + */ + public boolean hasNext() { return current < end; } + + /** + * @return the next ID + */ + public long next() { + if (!hasNext()) throw new IllegalStateException("All IDs have been used"); + return current++; + } +} From caabdaaf414691aa0ab740ace9d14abdb9b72c4d Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 31 Dec 2019 18:10:45 +0200 Subject: [PATCH 028/126] Added missing Javadoc tags. --- src/main/java/envoy/data/MessageIdGenerator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/envoy/data/MessageIdGenerator.java b/src/main/java/envoy/data/MessageIdGenerator.java index ba52e83..dbd27a2 100644 --- a/src/main/java/envoy/data/MessageIdGenerator.java +++ b/src/main/java/envoy/data/MessageIdGenerator.java @@ -20,6 +20,7 @@ public class MessageIdGenerator { * * @param begin the first ID * @param end the last ID + * @since Envoy Common v0.2-alpha */ public MessageIdGenerator(long begin, long end) { current = begin; @@ -28,11 +29,13 @@ public class MessageIdGenerator { /** * @return {@code true} if there are unused IDs remaining + * @since Envoy Common v0.2-alpha */ public boolean hasNext() { return current < end; } /** * @return the next ID + * @since Envoy Common v0.2-alpha */ public long next() { if (!hasNext()) throw new IllegalStateException("All IDs have been used"); From 66ab0c2d43347a82dfb1fa89d7be5b941db2f174 Mon Sep 17 00:00:00 2001 From: delvh Date: Wed, 1 Jan 2020 19:16:40 +0100 Subject: [PATCH 029/126] Improved Message.java and User.java to remain compatible with database --- src/main/java/envoy/data/Message.java | 80 +++++++++++++++++++++++++-- src/main/java/envoy/data/User.java | 64 ++++++++++++++------- 2 files changed, 118 insertions(+), 26 deletions(-) diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index ddbfba2..5ec1c03 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -48,11 +48,11 @@ public class Message implements Serializable { READ } - private final long id, senderId, recipientId; - private final transient User sender, recipient; - private final Date date; - private final String text; - private final MessageAttachment attachment; + private long id, senderId, recipientId; + private transient User sender, recipient; + private Date date; + private String text; + private MessageAttachment attachment; private MessageStatus status; @@ -168,4 +168,74 @@ public class Message implements Serializable { * @since Envoy Common v0.2-alpha */ public MessageStatus getStatus() { return status; } + + /** + * Only used for Hibernate. Please do not use. + * + * @param id the id to set + * @since Envoy Common v0.2-alpha + */ + public void setId(long id) { this.id = id; } + + /** + * Only used for Hibernate. Please do not use. + * + * @param senderId the senderId to set + * @since Envoy Common v0.2-alpha + */ + public void setSenderId(long senderId) { this.senderId = senderId; } + + /** + * Only used for Hibernate. Please do not use. + * + * @param recipientId the recipientId to set + * @since Envoy Common v0.2-alpha + */ + public void setRecipientId(long recipientId) { this.recipientId = recipientId; } + + /** + * Only used for Hibernate. Please do not use. + * + * @param sender the sender to set + * @since Envoy Common v0.2-alpha + */ + public void setSender(User sender) { this.sender = sender; } + + /** + * Only used for Hibernate. Please do not use. + * + * @param recipient the recipient to set + * @since Envoy Common v0.2-alpha + */ + public void setRecipient(User recipient) { this.recipient = recipient; } + + /** + * Only used for Hibernate. Please do not use. + * + * @param date the date to set + * @since Envoy Common v0.2-alpha + */ + public void setDate(Date date) { this.date = date; } + + /** + * Only used for Hibernate. Please do not use. + * + * @param text the text to set + * @since Envoy Common v0.2-alpha + */ + public void setText(String text) { this.text = text; } + + /** + * Only used for Hibernate. Please do not use. + * + * @param attachment the attachment to set + * @since Envoy Common v0.2-alpha + */ + public void setAttachment(MessageAttachment attachment) { this.attachment = attachment; } + + /** + * @param status the status to set + * @since Envoy Common v0.2-alpha + */ + public void setStatus(MessageStatus status) { this.status = status; } } \ No newline at end of file diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java index d5c0bbc..2049e75 100644 --- a/src/main/java/envoy/data/User.java +++ b/src/main/java/envoy/data/User.java @@ -1,8 +1,7 @@ package envoy.data; import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; +import java.util.Date; /** * Represents a unique user with a unique, numeric ID, a name and a current @@ -46,11 +45,10 @@ public class User implements Serializable { OFFLINE; } - private final long id; - private final String name; - private final List contacts = new ArrayList<>(); - - private UserStatus status; + private long id; + private String name; + private UserStatus status; + private Date lastOnline; private static final long serialVersionUID = 3530947374856708236L; @@ -60,46 +58,70 @@ public class User implements Serializable { * * @param id unique ID * @param name user name - * @since Envoy Client v0.2-alpha + * @since Envoy Common v0.2-alpha */ public User(long id, String name) { this.id = id; this.name = name; - status = UserStatus.OFFLINE; + status = UserStatus.ONLINE; + setLastOnline(new Date()); } + /** + * Used to let Hibernate modify the values of an {@link User} + * + * @since Envoy Common v0.2-alpha + */ + public User() {} + @Override public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } /** * @return the ID of this {@link User} - * @since Envoy Client v0.2-alpha + * @since Envoy Common v0.2-alpha */ public long getId() { return id; } /** * @return the name of this {@link User} - * @since Envoy Client v0.2-alpha + * @since Envoy Common v0.2-alpha */ public String getName() { return name; } - /** - * @return a list of all users this user can send messages to - * @since Envoy Client v0.2-alpha - */ - public List getContacts() { return contacts; } - /** * @return the current status of this user - * @since Envoy Client v0.2-alpha + * @since Envoy Common v0.2-alpha */ public UserStatus getStatus() { return status; } /** - * Sets the current status of this user - * * @param status the status to set - * @since Envoy Client v0.2-alpha + * @since Envoy Common v0.2-alpha */ public void setStatus(UserStatus status) { this.status = status; } + + /** + * @param id the id to set + * @since Envoy Common v0.2-alpha + */ + public void setId(long id) { this.id = id; } + + /** + * @param name the name to set + * @since Envoy Common v0.2-alpha + */ + public void setName(String name) { this.name = name; } + + /** + * @return the lastOnline + * @since Envoy Common v0.2-alpha + */ + public Date getLastOnline() { return lastOnline; } + + /** + * @param lastOnline the lastOnline to set + * @since Envoy Common v0.2-alpha + */ + public void setLastOnline(Date lastOnline) { this.lastOnline = lastOnline; } } \ No newline at end of file From af58e782638842f4bd1e6ff25d9bb09138de4377 Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 2 Jan 2020 14:16:05 +0100 Subject: [PATCH 030/126] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..86a4d3a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: CyB3RC0nN0R, delvh + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..7ecc386 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: CyB3RC0nN0R, delvh + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From 1783da3a703768f750a7edee2c5be7fe4c58952e Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 2 Jan 2020 15:04:35 +0100 Subject: [PATCH 031/126] Create CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..9d4ae77 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at kske@outlook.de. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq From 6ad38fba24a6821735623aa182a719f15cdfc3aa Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 2 Jan 2020 15:12:25 +0100 Subject: [PATCH 032/126] Update README.md --- README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 96825b7..491248c 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ -# envoy-common \ No newline at end of file +# Envoy Common + + + +**Envoy Common** is one of two repositories needed to use the messenger Envoy.
    +The other one is **Envoy Client**.
    +In the future, Envoy Common might be discarded, but for now, both Repositories are required in order to use Envoy to send messages to other people.
    +

    + +## Features + +Envoy Common consists of all classes that are used both on client side and the server side, thus making them "common". +Currently used features are: + +* Messages +* Users + * LoginCredentials +* Logging +* Event System +* EnvoyException + +## Resources + +* [API Reference (later on)](https://github.com/informatik-ag-ngl/envoy-common/wiki) +* [Release Notes](https://github.com/informatik-ag-ngl/envoy-common/releases) +* [Gallery (later on)](https://github.com/informatik-ag-ngl/envoy-common/wiki/Gallery) +* [Wiki](https://github.com/informatik-ag-ngl/envoy-common/wiki) From fe412fff66aa57f13ad18ba14d7bb6329c6d6f7a Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Thu, 2 Jan 2020 17:03:58 +0200 Subject: [PATCH 033/126] Added Contacts --- src/main/java/envoy/data/Contacts.java | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/envoy/data/Contacts.java diff --git a/src/main/java/envoy/data/Contacts.java b/src/main/java/envoy/data/Contacts.java new file mode 100644 index 0000000..8374168 --- /dev/null +++ b/src/main/java/envoy/data/Contacts.java @@ -0,0 +1,31 @@ +package envoy.data; + +import java.io.Serializable; +import java.util.List; + +/** + * Project: envoy-common
    + * File: Contacts.java
    + * Created: 02.01.2020
    + * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.2-alpha + */ +public class Contacts implements Serializable { + + private List contacts; + + private static final long serialVersionUID = 136970804968152871L; + + /** + * @return a list of users messages can be sent to + * @since Envoy Common v0.2-alpha + */ + public List getContacts() { return contacts; } + + /** + * @param contacts the contact list to set + * @since Envoy Common v0.2-alpha + */ + public void setContacts(List contacts) { this.contacts = contacts; } +} From 8b4205f222b41e8f18d121257665e4fa9a955cf1 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Thu, 2 Jan 2020 17:46:20 +0200 Subject: [PATCH 034/126] Adder userId to Contacts --- src/main/java/envoy/data/Contacts.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/envoy/data/Contacts.java b/src/main/java/envoy/data/Contacts.java index 8374168..5c5314c 100644 --- a/src/main/java/envoy/data/Contacts.java +++ b/src/main/java/envoy/data/Contacts.java @@ -13,10 +13,26 @@ import java.util.List; */ public class Contacts implements Serializable { - private List contacts; + private long userId; + private List contacts; private static final long serialVersionUID = 136970804968152871L; + @Override + public String toString() { return String.format("Contacts[%s]", contacts); } + + /** + * @return the ID of the user this contacts belong to + * @since Envoy Common v0.2-alpha + */ + public long getUserId() { return userId; } + + /** + * @param userId the ID of the user this contacts belong to + * @since Envoy Common v0.2-alpha + */ + public void setUserId(long userId) { this.userId = userId; } + /** * @return a list of users messages can be sent to * @since Envoy Common v0.2-alpha From 3b808f49383d9016f73c181160631a815001c812 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Thu, 2 Jan 2020 18:50:04 +0200 Subject: [PATCH 035/126] Reverted some changes related to ORM --- src/main/java/envoy/data/Contacts.java | 28 ++-- src/main/java/envoy/data/Message.java | 165 ++++++------------- src/main/java/envoy/data/MessageBuilder.java | 16 +- src/main/java/envoy/data/User.java | 43 +---- 4 files changed, 80 insertions(+), 172 deletions(-) diff --git a/src/main/java/envoy/data/Contacts.java b/src/main/java/envoy/data/Contacts.java index 5c5314c..bd19102 100644 --- a/src/main/java/envoy/data/Contacts.java +++ b/src/main/java/envoy/data/Contacts.java @@ -13,11 +13,23 @@ import java.util.List; */ public class Contacts implements Serializable { - private long userId; - private List contacts; + private final long userId; + private final List contacts; private static final long serialVersionUID = 136970804968152871L; + /** + * Creates an instance of {@link Contacts}. + * + * @param userId the ID of the user this contacts belong to + * @param contacts the contact list + * @since Envoy Common v0.2-alpha + */ + public Contacts(long userId, List contacts) { + this.userId = userId; + this.contacts = contacts; + } + @Override public String toString() { return String.format("Contacts[%s]", contacts); } @@ -27,21 +39,9 @@ public class Contacts implements Serializable { */ public long getUserId() { return userId; } - /** - * @param userId the ID of the user this contacts belong to - * @since Envoy Common v0.2-alpha - */ - public void setUserId(long userId) { this.userId = userId; } - /** * @return a list of users messages can be sent to * @since Envoy Common v0.2-alpha */ public List getContacts() { return contacts; } - - /** - * @param contacts the contact list to set - * @since Envoy Common v0.2-alpha - */ - public void setContacts(List contacts) { this.contacts = contacts; } } diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index 5ec1c03..ff0414c 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -48,13 +48,13 @@ public class Message implements Serializable { READ } - private long id, senderId, recipientId; - private transient User sender, recipient; - private Date date; - private String text; - private MessageAttachment attachment; + private final long id, senderId, recipientId; + private final Date creationDate; + private final String text; + private final MessageAttachment attachment; - private MessageStatus status; + private Date receivedDate, readDate; + private MessageStatus status; private static final long serialVersionUID = -4393477412979594435L; @@ -64,26 +64,24 @@ public class Message implements Serializable { * this class provides {@code null} checks and default values for all * properties. * - * @param id unique ID - * @param sender the user who sends the message - * @param recipient the user who receives the message - * @param date the creation date of the message - * @param text the text content of the message - * @param attachment the attachment of the message, if present - * @param status the current {@link MessageStatus} of the message + * @param id unique ID + * @param senderId the ID of the user who sends the message + * @param recipientId the ID of the user who receives the message + * @param date the creation date of the message + * @param text the text content of the message + * @param attachment the attachment of the message, if present + * @param status the current {@link MessageStatus} of the message * @since Envoy Common v0.2-alpha */ - Message(long id, User sender, User recipient, Date date, String text, MessageAttachment attachment, MessageStatus status) { - this.id = id; - this.sender = sender; - this.recipient = recipient; - this.date = date; - this.text = text; - this.attachment = attachment; - this.status = status; + Message(long id, long senderId, long recipientId, Date date, String text, MessageAttachment attachment, MessageStatus status) { + this.id = id; + this.senderId = senderId; + this.recipientId = recipientId; + this.creationDate = date; + this.text = text; + this.attachment = attachment; + this.status = status; - senderId = sender.getId(); - recipientId = recipient.getId(); } /** @@ -106,13 +104,14 @@ public class Message implements Serializable { @Override public String toString() { - return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,text=%s]", + return String.format("TextMessage[id=%d,sender=%s,recipient=%s,date=%s,status=%s,text=%s,hasAttachment=%b]", id, - sender, - recipient, - new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(date), + senderId, + recipientId, + new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(creationDate), status, - text); + text, + attachment != null); } /** @@ -121,24 +120,12 @@ public class Message implements Serializable { */ public long getId() { return id; } - /** - * @return the sender of this message - * @since Envoy Common v0.2-alpha - */ - public User getSender() { return sender; } - /** * @return the sender ID of this message * @since Envoy Common v0.2-alpha */ public long getSenderId() { return senderId; } - /** - * @return the recipient of this message - * @since Envoy Common v0.2-alpha - */ - public User getRecipient() { return recipient; } - /** * @return the recipient ID of this message * @since Envoy Common v0.2-alpha @@ -149,7 +136,33 @@ public class Message implements Serializable { * @return the date at which this message was created * @since Envoy Common v0.2-alpha */ - public Date getDate() { return date; } + public Date getDate() { return creationDate; } + + /** + * @return the date at which the message has been received by the sender + * @since Envoy Common v0.2-alpha + */ + public Date getReceivedDate() { return receivedDate; } + + /** + * + * @param receivedDate the date at which the message has been received by the + * sender + * @since Envoy Common v0.2-alpha + */ + public void setReceivedDate(Date receivedDate) { this.receivedDate = receivedDate; } + + /** + * @return the date at which the message has been read by the sender + * @since Envoy Common v0.2-alpha + */ + public Date getReadDate() { return readDate; } + + /** + * @param readDate at which the message has been read by the sender + * @since Envoy Common v0.2-alpha + */ + public void setReadDate(Date readDate) { this.readDate = readDate; } /** * @return the text content of this message @@ -168,74 +181,4 @@ public class Message implements Serializable { * @since Envoy Common v0.2-alpha */ public MessageStatus getStatus() { return status; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param id the id to set - * @since Envoy Common v0.2-alpha - */ - public void setId(long id) { this.id = id; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param senderId the senderId to set - * @since Envoy Common v0.2-alpha - */ - public void setSenderId(long senderId) { this.senderId = senderId; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param recipientId the recipientId to set - * @since Envoy Common v0.2-alpha - */ - public void setRecipientId(long recipientId) { this.recipientId = recipientId; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param sender the sender to set - * @since Envoy Common v0.2-alpha - */ - public void setSender(User sender) { this.sender = sender; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param recipient the recipient to set - * @since Envoy Common v0.2-alpha - */ - public void setRecipient(User recipient) { this.recipient = recipient; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param date the date to set - * @since Envoy Common v0.2-alpha - */ - public void setDate(Date date) { this.date = date; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param text the text to set - * @since Envoy Common v0.2-alpha - */ - public void setText(String text) { this.text = text; } - - /** - * Only used for Hibernate. Please do not use. - * - * @param attachment the attachment to set - * @since Envoy Common v0.2-alpha - */ - public void setAttachment(MessageAttachment attachment) { this.attachment = attachment; } - - /** - * @param status the status to set - * @since Envoy Common v0.2-alpha - */ - public void setStatus(MessageStatus status) { this.status = status; } } \ No newline at end of file diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java index 4217663..43e929e 100644 --- a/src/main/java/envoy/data/MessageBuilder.java +++ b/src/main/java/envoy/data/MessageBuilder.java @@ -17,7 +17,7 @@ import envoy.data.Message.MessageStatus; public class MessageBuilder { // Mandatory properties without default values - private final User sender, recipient; + private final long senderId, recipientId; // Properties with default values private long id; @@ -30,15 +30,13 @@ public class MessageBuilder { * Creates an instance of {@link MessageBuilder} with all mandatory values * without defaults for the {@link Message} class. * - * @param sender the user who sends the {@link Message} - * @param recipient the user who received the {@link Message} + * @param senderId the ID of the user who sends the {@link Message} + * @param recipientId the ID of the user who received the {@link Message} * @since Envoy Common v0.2-alpha */ - public MessageBuilder(User sender, User recipient) { - if (sender == null) throw new NullPointerException("Message sender is null"); - if (recipient == null) throw new NullPointerException("Message recipient is null"); - this.sender = sender; - this.recipient = recipient; + public MessageBuilder(long senderId, long recipientId) { + this.senderId = senderId; + this.recipientId = recipientId; } /** @@ -69,7 +67,7 @@ public class MessageBuilder { if (text == null) text = ""; if (status == null) status = MessageStatus.WAITING; - return new Message(id, sender, recipient, date, text, attachment, status); + return new Message(id, senderId, recipientId, date, text, attachment, status); } /** diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java index 2049e75..dc33851 100644 --- a/src/main/java/envoy/data/User.java +++ b/src/main/java/envoy/data/User.java @@ -1,7 +1,6 @@ package envoy.data; import java.io.Serializable; -import java.util.Date; /** * Represents a unique user with a unique, numeric ID, a name and a current @@ -45,10 +44,10 @@ public class User implements Serializable { OFFLINE; } - private long id; - private String name; - private UserStatus status; - private Date lastOnline; + private final long id; + private final String name; + + private UserStatus status; private static final long serialVersionUID = 3530947374856708236L; @@ -64,16 +63,8 @@ public class User implements Serializable { this.id = id; this.name = name; status = UserStatus.ONLINE; - setLastOnline(new Date()); } - /** - * Used to let Hibernate modify the values of an {@link User} - * - * @since Envoy Common v0.2-alpha - */ - public User() {} - @Override public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } @@ -96,32 +87,8 @@ public class User implements Serializable { public UserStatus getStatus() { return status; } /** - * @param status the status to set + * @param status the next status of this user * @since Envoy Common v0.2-alpha */ public void setStatus(UserStatus status) { this.status = status; } - - /** - * @param id the id to set - * @since Envoy Common v0.2-alpha - */ - public void setId(long id) { this.id = id; } - - /** - * @param name the name to set - * @since Envoy Common v0.2-alpha - */ - public void setName(String name) { this.name = name; } - - /** - * @return the lastOnline - * @since Envoy Common v0.2-alpha - */ - public Date getLastOnline() { return lastOnline; } - - /** - * @param lastOnline the lastOnline to set - * @since Envoy Common v0.2-alpha - */ - public void setLastOnline(Date lastOnline) { this.lastOnline = lastOnline; } } \ No newline at end of file From 5194e20a855d31e42065b8f838db7a9a03f637c2 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Fri, 3 Jan 2020 17:08:07 +0200 Subject: [PATCH 036/126] Added byte array serialization and deserialization methods. --- .../java/envoy/util/SerializationUtils.java | 51 +++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/src/main/java/envoy/util/SerializationUtils.java b/src/main/java/envoy/util/SerializationUtils.java index c070733..b26aa49 100644 --- a/src/main/java/envoy/util/SerializationUtils.java +++ b/src/main/java/envoy/util/SerializationUtils.java @@ -1,5 +1,6 @@ package envoy.util; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -21,12 +22,14 @@ import java.io.Serializable; */ public class SerializationUtils { + private SerializationUtils() {} + private static byte[] intToBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n }; } /** * Deserializes an arbitrary {@link Serializable} object from a file. * - * @param the type of the object to deserialize + * @param the type of the serialized object * @param file the file to deserialize from * @param serializedClass the class of the object to deserialize * @return the deserialized object @@ -42,7 +45,26 @@ public class SerializationUtils { } /** - * @param the deserialized object + * Deserializes an arbitrary {@link Serializable} object from a byte array. + * + * @param the type of the serialized object + * @param bytes the array in which the serialized object is stored + * @param serializedClass the class of the serialized object + * @return the deserialized object + * @throws IOException if something failed while deserializing the + * object + * @throws ClassNotFoundException if the deserialized object can not be linked + * to a class + * @since Envoy Common v0.2-alpha + */ + public static T read(byte[] bytes, Class serializedClass) throws IOException, ClassNotFoundException { + return read(new ByteArrayInputStream(bytes), serializedClass); + } + + /** + * Deserializes an arbitrary {@link Serializable} object from a stream. + * + * @param the type of the serialized object * @param in the {@link InputStream} of a serialized Object * @param serializedClass the object type to convert the deserialized object * into @@ -79,6 +101,22 @@ public class SerializationUtils { } } + /** + * Serializes an arbitrary object to a byte array. + * + * @param obj the object to serialize + * @return a byte array containing the serialized object + * @throws IOException if the serialization failed + * @since Envoy Common v0.2-alpha + */ + public static byte[] writeToByteArray(Object obj) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ObjectOutputStream oout = new ObjectOutputStream(baos)) { + oout.writeObject(obj); + } + return baos.toByteArray(); + } + /** * Serializes an object and writes it into an output stream preceded by 4 bytes * containing the number of serialized bytes. @@ -86,14 +124,11 @@ public class SerializationUtils { * @param obj the object to serialize * @param out the output stream to serialize to * @throws IOException if an error occurred during serialization + * @since Envoy Common v0.2-alpha */ public static void writeBytesWithLength(Object obj, OutputStream out) throws IOException { // Serialize object to byte array - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oout = new ObjectOutputStream(baos)) { - oout.writeObject(obj); - } - byte[] objBytes = baos.toByteArray(); + byte[] objBytes = writeToByteArray(obj); // Get length of byte array in bytes byte[] objLen = intToBytes(objBytes.length); @@ -102,6 +137,4 @@ public class SerializationUtils { out.write(objLen); out.write(objBytes); } - - private SerializationUtils() {} } \ No newline at end of file From ce73838ce2a2daf99251a0c7382cd3f99c885aa1 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 3 Jan 2020 21:32:47 +0100 Subject: [PATCH 037/126] Create CONTRIBUTING.md --- CONTRIBUTING.md | 161 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..7c7e768 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,161 @@ +# Contributing to Envoy + +Looking to contribute something to Envoy? **Here's how you can help.** + +Please take a moment to review this document in order to make the contribution +process easy and effective for everyone involved. + +Following these guidelines helps to communicate that you respect the time of +the developers managing and developing this open source project. In return, +they should reciprocate that respect in addressing your issue or assessing +patches and features. + + +## Using the issue tracker + +The [issue tracker](https://github.com/informatik-ag-ngl/envoy-common/issues) is +the preferred channel for [bug reports](#bug-reports), [features requests](#feature-requests) +and [submitting pull requests](#pull-requests), but please respect the following +restrictions: + +* Please **do not** derail or troll issues. Keep the discussion on topic and + respect the opinions of others. + +* Please **do not** post comments consisting solely of "+1" or ":thumbsup:". + Use [GitHub's "reactions" feature](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) + instead. We reserve the right to delete comments which violate this rule. + + However, as we know, we are all software engineers that like being funny hence doing it on purpose. Please also refrain from that kind of behaviour. + +## Issues and labels + +Our bug tracker utilizes several labels to help organize and identify issues. Here's what they represent and how we use them: + +- `Documentation` & `Javadoc`- Issues regarding the documentation of Envoy +- `Enhancement` & `Feature` - Issues suggesting a new feature +- `Maven` - Issues concerned with Maven problems +- `Bug` - Issues concerned with a general bug + +For a complete look at our labels, see the [project labels page](https://github.com/informatik-ag-ngl/envoy-common/labels). + +## Bug reports + +A bug is a _demonstrable problem_ that is caused by the code in the repository. +Good bug reports are extremely helpful, so thanks! + +Guidelines for bug reports: + +0. **ensure your problem isn't caused by a simple error in your own code**. + +1. **Use the GitHub issue search** — check if the issue has already been + reported. + +2. **Check if the issue has been fixed** — try to reproduce it using the + latest `master` or development branch in the repository. + +3. **Isolate the problem** — ideally create a reduced test + case and a live example. + + +A good bug report shouldn't leave others needing to chase you up for more +information. Please try to be as detailed as possible in your report. What is +your environment? What steps will reproduce the issue? These details will help people to fix +any potential bugs. + +Example: + +> Short and descriptive example bug report title +> +> 1. This is the first step +> 2. This is the second step +> 3. Further steps, etc. +> +> Any other information you want to share that is relevant to the issue being +> reported. This might include the lines of code that you have identified as +> causing the bug, and potential solutions (and your opinions on their +> merits). + +## Feature requests + +Feature requests are welcome. But take a moment to find out whether your idea +fits with the scope and aims of the project. It's up to *you* to make a strong +case to convince the project's developers of the merits of this feature. Please +provide as much detail and context as possible. + + +## Pull requests + +Good pull requests—patches, improvements, new features—are a fantastic +help. They should remain focused in scope and avoid containing unrelated +commits. + +**Please ask first** before embarking on any significant pull request (e.g. +implementing features, refactoring code, porting to a different language), +otherwise you risk spending a lot of time working on something that the +project's developers might not want to merge into the project. + +Please adhere to the [coding guidelines](#code-guidelines) used throughout the +project (indentation, accurate comments, etc.) and any other requirements +(such as test coverage). + +Adhering to the following process is the best way to get your work +included in the project: + +1. Download, clone or [Fork](https://help.github.com/articles/fork-a-repo/) the project, using [https://github.com/informatik-ag-ngl/envoy-common/](https://github.com/informatik-ag-ngl/envoy-common/)as Remote. + +2. If you cloned a while ago, get the latest changes from upstream: + + ```bash + git checkout master + git pull upstream master + ``` + Or, if your IDE of choice supports this, simply use `pull` + +3. Create a new topic branch (off the main project development branch) to + contain your feature, change, or fix: + + ```bash + git checkout -b + ``` + Or, simply use "New branch" if your IDE supports this + +4. Commit your changes in logical chunks. Please adhere to these [git commit + message guidelines](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) + or your code is unlikely be merged into the main project. Use Git's + [interactive rebase](https://help.github.com/articles/about-git-rebase/) + feature to tidy up your commits before making them public. + +5. Locally merge (or rebase) the upstream development branch into your topic branch: + + ```bash + git pull [--rebase] upstream master + ``` + +6. Push your topic branch up to your fork: + + ```bash + git push origin + ``` + +7. [Open a Pull Request](https://help.github.com/articles/about-pull-requests/) + with a clear title and description against the `master` branch. + +**IMPORTANT**: By submitting a patch, you agree to allow the project owners to +license your work under the terms of the [MIT License](../LICENSE) (if it +includes code changes) and under the terms of the +[Creative Commons Attribution 3.0 Unported License](https://creativecommons.org/licenses/by/3.0/) +(if it includes documentation changes). + + +## Code guidelines + +### Java + +Please use the formatter provided with this project. Especially before saving. For best results, select the option "format code" in the "Save Actions" tab in Preferences in Eclipse, so that you never accidentally forget it. +Every public function (not annotated with `@Override`) must be delivered with Javadoc. For best project-appropriate Javadoc please take a look at the other functions which are all already equipped with Javadoc. + + +## License + +By contributing your code, you agree to license your contribution under the [MIT License](../LICENSE). +By contributing to the documentation, you agree to license your contribution under the [Creative Commons Attribution 3.0 Unported License](https://creativecommons.org/licenses/by/3.0/). From eadd940a0d4308b99eeefbcaf104b045bc033cd6 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 4 Jan 2020 09:32:20 +0100 Subject: [PATCH 038/126] Added Pull Request templates --- .github/PULL_REQUEST_TEMPLATE/bugfix.md | 10 ++++++++++ .github/PULL_REQUEST_TEMPLATE/feature_integration.md | 9 +++++++++ .github/PULL_REQUEST_TEMPLATE/javadoc_upgrade.md | 9 +++++++++ 3 files changed, 28 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/bugfix.md create mode 100644 .github/PULL_REQUEST_TEMPLATE/feature_integration.md create mode 100644 .github/PULL_REQUEST_TEMPLATE/javadoc_upgrade.md diff --git a/.github/PULL_REQUEST_TEMPLATE/bugfix.md b/.github/PULL_REQUEST_TEMPLATE/bugfix.md new file mode 100644 index 0000000..e189f31 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/bugfix.md @@ -0,0 +1,10 @@ +--- +name: Bug fix +title: Fixed Bug +labels: bug +assignees: CyB3RC0nN0R, delvh, DieGurke +reviewers: CyB3RC0nN0R, delvh +projects: Envoy +milestone: Envoy v0.3-alpha +--- +Fixes #{issue} diff --git a/.github/PULL_REQUEST_TEMPLATE/feature_integration.md b/.github/PULL_REQUEST_TEMPLATE/feature_integration.md new file mode 100644 index 0000000..945e7d3 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/feature_integration.md @@ -0,0 +1,9 @@ +--- +name: Feature integration +title: Added feature +labels: enhancement +assignees: CyB3RC0nN0R, delvh, DieGurke +reviewers: CyB3RC0nN0R, delvh +projects: Envoy +milestone: Envoy v0.3-alpha +--- diff --git a/.github/PULL_REQUEST_TEMPLATE/javadoc_upgrade.md b/.github/PULL_REQUEST_TEMPLATE/javadoc_upgrade.md new file mode 100644 index 0000000..7f1786d --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/javadoc_upgrade.md @@ -0,0 +1,9 @@ +--- +name: Updated Javadoc +title: Updated Javadoc +labels: documentation +assignees: CyB3RC0nN0R, delvh +reviewers: CyB3RC0nN0R, delvh +projects: Envoy +milestone: Envoy v0.3-alpha +--- From 407a5bdbd85ae99884501ebcc7455523e4fa5ddf Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 6 Jan 2020 17:41:23 +0100 Subject: [PATCH 039/126] Added helper methods to SerializationUtils. Also exporting sources and Javadoc on build. --- .classpath | 5 --- .settings/org.eclipse.core.resources.prefs | 1 - .settings/org.eclipse.wst.common.component | 14 ++++--- pom.xml | 31 ++++++++++++++ .../java/envoy/util/SerializationUtils.java | 40 ++++++++++++------- 5 files changed, 64 insertions(+), 27 deletions(-) diff --git a/.classpath b/.classpath index 88d37ef..907ff21 100644 --- a/.classpath +++ b/.classpath @@ -24,10 +24,5 @@ - - - - - diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 04cfa2c..8bc0e1c 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,6 +1,5 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 -encoding//src/main/resources=UTF-8 encoding//src/test/java=UTF-8 encoding//src/test/resources=UTF-8 encoding/=UTF-8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index a6896ac..44f2db9 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,15 +1,17 @@ - + + - + + - - - + + - + + diff --git a/pom.xml b/pom.xml index 6e20167..eee2dcf 100644 --- a/pom.xml +++ b/pom.xml @@ -18,5 +18,36 @@ envoy-common + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + + attach-javadocs + + jar + + + + + none + + + \ No newline at end of file diff --git a/src/main/java/envoy/util/SerializationUtils.java b/src/main/java/envoy/util/SerializationUtils.java index b26aa49..3007bfe 100644 --- a/src/main/java/envoy/util/SerializationUtils.java +++ b/src/main/java/envoy/util/SerializationUtils.java @@ -1,16 +1,6 @@ package envoy.util; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.io.Serializable; +import java.io.*; /** * Project: envoy-client
    @@ -24,7 +14,27 @@ public class SerializationUtils { private SerializationUtils() {} - private static byte[] intToBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n }; } + /** + * Converts an integer into a byte array. + * + * @param n the integer to convert + * @return a byte array of length 4 + * @since Envoy Common v0.2-alpha + */ + public static byte[] intToBytes(int n) { return new byte[] { (byte) (n >>> 24), (byte) (n >>> 16), (byte) (n >>> 8), (byte) n }; } + + /** + * Converts four bytes in byte array to an integer + * + * @param bytes the bytes to convert from + * @param offset the offset at which four bytes are read + * @return the converted integer + * @since Envoy Common v0.2-alpha + */ + public static int bytesToInt(byte[] bytes, int offset) { + return ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) + | ((bytes[offset + 3] & 0xFF) << 0); + } /** * Deserializes an arbitrary {@link Serializable} object from a file. @@ -46,7 +56,7 @@ public class SerializationUtils { /** * Deserializes an arbitrary {@link Serializable} object from a byte array. - * + * * @param the type of the serialized object * @param bytes the array in which the serialized object is stored * @param serializedClass the class of the serialized object @@ -63,7 +73,7 @@ public class SerializationUtils { /** * Deserializes an arbitrary {@link Serializable} object from a stream. - * + * * @param the type of the serialized object * @param in the {@link InputStream} of a serialized Object * @param serializedClass the object type to convert the deserialized object @@ -103,7 +113,7 @@ public class SerializationUtils { /** * Serializes an arbitrary object to a byte array. - * + * * @param obj the object to serialize * @return a byte array containing the serialized object * @throws IOException if the serialization failed From 6fcfaee1aba933482c59dd8c86f9047a9685f860 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 6 Jan 2020 18:00:43 +0100 Subject: [PATCH 040/126] Added MessageStatusChangeEvent, moved MessageEvent back to envoy-client. --- src/main/java/envoy/event/MessageEvent.java | 30 ------------- .../envoy/event/MessageStatusChangeEvent.java | 43 +++++++++++++++++++ 2 files changed, 43 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/envoy/event/MessageEvent.java create mode 100644 src/main/java/envoy/event/MessageStatusChangeEvent.java diff --git a/src/main/java/envoy/event/MessageEvent.java b/src/main/java/envoy/event/MessageEvent.java deleted file mode 100644 index 45a7f40..0000000 --- a/src/main/java/envoy/event/MessageEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -package envoy.event; - -import envoy.data.Message; - -/** - * Project: envoy-common
    - * File: MessageCreationEvent.java
    - * Created: 4 Dec 2019
    - * - * @author Kai S. K. Engelbart - */ -public class MessageEvent implements Event { - - /** - * the {@link Message} attached to this {@link MessageEvent}. - */ - protected final Message message; - - /** - * Initializes a {@link MessageEvent} conveying information about a - * {@link Message} object. - * - * @param message the {@link Message} object to attach to this event - * @since Envoy v0.2-alpha - */ - public MessageEvent(Message message) { this.message = message; } - - @Override - public Message get() { return message; } -} diff --git a/src/main/java/envoy/event/MessageStatusChangeEvent.java b/src/main/java/envoy/event/MessageStatusChangeEvent.java new file mode 100644 index 0000000..bf17b0e --- /dev/null +++ b/src/main/java/envoy/event/MessageStatusChangeEvent.java @@ -0,0 +1,43 @@ +package envoy.event; + +import envoy.data.Message; + +/** + * Project: envoy-common
    + * File: MessageStatusChangeEvent.java
    + * Created: 6 Jan 2020
    + * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.2-alpha + */ +public class MessageStatusChangeEvent implements Event { + + private final long messageId; + private final Message.MessageStatus messageStatus; + + /** + * Initializes a {@link MessageStatusChangeEvent}. + * + * @param messageId the ID of the {@link Message} this event is related to + * @param messageStatus the status of the {@link Message} this event is related + * to + * @since Envoy Common v0.2-alpha + */ + public MessageStatusChangeEvent(long messageId, Message.MessageStatus messageStatus) { + this.messageId = messageId; + this.messageStatus = messageStatus; + } + + /** + * @return the status of the {@link Message} this event is related to + * @since Envoy Common v0.2-alpha + */ + @Override + public Message.MessageStatus get() { return messageStatus; } + + /** + * @return the ID of the {@link Message} this event is related to + * @since Envoy Common v0.2-alpha + */ + public long getMessageId() { return messageId; } +} From 1d42f573522a4403a8072ea8f30989c0094e3240 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 11 Jan 2020 11:36:38 +0100 Subject: [PATCH 041/126] Added date to the MessageStatusChangedEvent time of the Event can now be saved --- .../java/envoy/event/MessageStatusChangeEvent.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/envoy/event/MessageStatusChangeEvent.java b/src/main/java/envoy/event/MessageStatusChangeEvent.java index bf17b0e..ac532fa 100644 --- a/src/main/java/envoy/event/MessageStatusChangeEvent.java +++ b/src/main/java/envoy/event/MessageStatusChangeEvent.java @@ -1,5 +1,7 @@ package envoy.event; +import java.util.Date; + import envoy.data.Message; /** @@ -14,6 +16,7 @@ public class MessageStatusChangeEvent implements Event { private final long messageId; private final Message.MessageStatus messageStatus; + private final Date date; /** * Initializes a {@link MessageStatusChangeEvent}. @@ -21,11 +24,13 @@ public class MessageStatusChangeEvent implements Event { * @param messageId the ID of the {@link Message} this event is related to * @param messageStatus the status of the {@link Message} this event is related * to + * @param date the date at which the MessageStatus change occurred * @since Envoy Common v0.2-alpha */ - public MessageStatusChangeEvent(long messageId, Message.MessageStatus messageStatus) { + public MessageStatusChangeEvent(long messageId, Message.MessageStatus messageStatus, Date date) { this.messageId = messageId; this.messageStatus = messageStatus; + this.date = date; } /** @@ -40,4 +45,10 @@ public class MessageStatusChangeEvent implements Event { * @since Envoy Common v0.2-alpha */ public long getMessageId() { return messageId; } + + /** + * @return the date at which the messageStatus change occurred + * @since Envoy Common v0.2-alpha + */ + public Date getDate() { return date; } } From df9e4dd0c94982530de718eebabbb119c909b31c Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 11 Jan 2020 14:17:51 +0100 Subject: [PATCH 042/126] added byte array conversion for message attachment in addition reformatted variable names as per @CyB3RC0nN0R s request --- src/main/java/envoy/data/Message.java | 12 ++++++++-- .../java/envoy/data/MessageAttachment.java | 23 +++++++++++++++++-- .../envoy/event/MessageStatusChangeEvent.java | 20 ++++++++-------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index ff0414c..5d7ee33 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -136,7 +136,7 @@ public class Message implements Serializable { * @return the date at which this message was created * @since Envoy Common v0.2-alpha */ - public Date getDate() { return creationDate; } + public Date getCreationDate() { return creationDate; } /** * @return the date at which the message has been received by the sender @@ -145,7 +145,6 @@ public class Message implements Serializable { public Date getReceivedDate() { return receivedDate; } /** - * * @param receivedDate the date at which the message has been received by the * sender * @since Envoy Common v0.2-alpha @@ -181,4 +180,13 @@ public class Message implements Serializable { * @since Envoy Common v0.2-alpha */ public MessageStatus getStatus() { return status; } + + /** + * @param status the new {@link MessageStatus}, if permitted + * @since Envoy Common v0.2-alpha + */ + public void setStatus(MessageStatus status) { + if (status.ordinal() < this.status.ordinal()) throw new IllegalStateException("This message is moving backwards in time"); + else this.status = status; + } } \ No newline at end of file diff --git a/src/main/java/envoy/data/MessageAttachment.java b/src/main/java/envoy/data/MessageAttachment.java index ee4db64..23a2c2e 100644 --- a/src/main/java/envoy/data/MessageAttachment.java +++ b/src/main/java/envoy/data/MessageAttachment.java @@ -1,7 +1,10 @@ package envoy.data; +import java.io.IOException; import java.io.Serializable; +import envoy.util.SerializationUtils; + /** * This interface should be used for any type supposed to be a {@link Message} * attachment (i.e. images or sound).
    @@ -14,11 +17,27 @@ import java.io.Serializable; * @param the type of this message attachment * @since Envoy Common v0.2-alpha */ -public interface MessageAttachment extends Serializable { +public class MessageAttachment implements Serializable { + + private static final long serialVersionUID = 262683855157198013L; + private T value; /** * @return the type implementing this interface * @since Envoy Common v0.2-alpha */ - T get(); + T getValue() { return value; } + + /** + * @return the {@link MessageAttachment} as a byte array + * @throws IOException if the serialization failed + * @since Envoy Common v0.2-alpha + */ + byte[] toByteArray() throws IOException { return SerializationUtils.writeToByteArray(this); } + + /** + * @param value the value to set + * @since Envoy Common v0.2-alpha + */ + public void setValue(T value) { this.value = value; } } diff --git a/src/main/java/envoy/event/MessageStatusChangeEvent.java b/src/main/java/envoy/event/MessageStatusChangeEvent.java index ac532fa..b0aea1f 100644 --- a/src/main/java/envoy/event/MessageStatusChangeEvent.java +++ b/src/main/java/envoy/event/MessageStatusChangeEvent.java @@ -14,22 +14,22 @@ import envoy.data.Message; */ public class MessageStatusChangeEvent implements Event { - private final long messageId; - private final Message.MessageStatus messageStatus; + private final long id; + private final Message.MessageStatus status; private final Date date; /** * Initializes a {@link MessageStatusChangeEvent}. * - * @param messageId the ID of the {@link Message} this event is related to - * @param messageStatus the status of the {@link Message} this event is related + * @param id the ID of the {@link Message} this event is related to + * @param status the status of the {@link Message} this event is related * to * @param date the date at which the MessageStatus change occurred * @since Envoy Common v0.2-alpha */ - public MessageStatusChangeEvent(long messageId, Message.MessageStatus messageStatus, Date date) { - this.messageId = messageId; - this.messageStatus = messageStatus; + public MessageStatusChangeEvent(long id, Message.MessageStatus status, Date date) { + this.id = id; + this.status = status; this.date = date; } @@ -38,16 +38,16 @@ public class MessageStatusChangeEvent implements Event { * @since Envoy Common v0.2-alpha */ @Override - public Message.MessageStatus get() { return messageStatus; } + public Message.MessageStatus get() { return status; } /** * @return the ID of the {@link Message} this event is related to * @since Envoy Common v0.2-alpha */ - public long getMessageId() { return messageId; } + public long getId() { return id; } /** - * @return the date at which the messageStatus change occurred + * @return the date at which the status change occurred * @since Envoy Common v0.2-alpha */ public Date getDate() { return date; } From 19bbaf7d7ab6f109f46b2dc3faef5c8e93a0bdb6 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 18 Jan 2020 09:37:35 +0100 Subject: [PATCH 043/126] Added a constructor for User as well as for MessageStatusChangeEvent --- src/main/java/envoy/data/Message.java | 1 - src/main/java/envoy/data/User.java | 15 ++++++++++++++- .../envoy/event/MessageStatusChangeEvent.java | 14 +++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index 5d7ee33..50a2f09 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -81,7 +81,6 @@ public class Message implements Serializable { this.text = text; this.attachment = attachment; this.status = status; - } /** diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java index dc33851..bc9cf0f 100644 --- a/src/main/java/envoy/data/User.java +++ b/src/main/java/envoy/data/User.java @@ -53,7 +53,7 @@ public class User implements Serializable { /** * Initializes a {@link User}. The {@link UserStatus} is set to - * {@link UserStatus#OFFLINE}. + * {@link UserStatus#ONLINE}. * * @param id unique ID * @param name user name @@ -65,6 +65,19 @@ public class User implements Serializable { status = UserStatus.ONLINE; } + /** + * Initializes a {@link User}. + * + * @param id unique ID + * @param name user name + * @param status the status of the user + * @since Envoy Common v0.2-alpha + */ + public User(long id, String name, UserStatus status) { + this(id, name); + this.status = status; + } + @Override public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } diff --git a/src/main/java/envoy/event/MessageStatusChangeEvent.java b/src/main/java/envoy/event/MessageStatusChangeEvent.java index b0aea1f..ebe818b 100644 --- a/src/main/java/envoy/event/MessageStatusChangeEvent.java +++ b/src/main/java/envoy/event/MessageStatusChangeEvent.java @@ -23,16 +23,24 @@ public class MessageStatusChangeEvent implements Event { * * @param id the ID of the {@link Message} this event is related to * @param status the status of the {@link Message} this event is related - * to - * @param date the date at which the MessageStatus change occurred + * to + * @param date the date at which the MessageStatus change occurred * @since Envoy Common v0.2-alpha */ public MessageStatusChangeEvent(long id, Message.MessageStatus status, Date date) { this.id = id; this.status = status; - this.date = date; + this.date = date; } + /** + * Initialises a {@link MessageStatusChangeEvent} through a message. + * + * @param message the message from which to build the event + * @since Envoy Common v0.2-alpha + */ + public MessageStatusChangeEvent(Message message) { this(message.getId(), message.getStatus(), new Date()); } + /** * @return the status of the {@link Message} this event is related to * @since Envoy Common v0.2-alpha From e5c67b859bb16e894253501567668448d41afdcd Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 18 Jan 2020 10:27:29 +0100 Subject: [PATCH 044/126] Added boolean registration to LoginCredentials --- .classpath | 5 ++++ .settings/org.eclipse.core.resources.prefs | 1 + .settings/org.eclipse.wst.common.component | 13 +++++++---- .../java/envoy/data/LoginCredentials.java | 23 ++++++++++++++----- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.classpath b/.classpath index 907ff21..88d37ef 100644 --- a/.classpath +++ b/.classpath @@ -24,5 +24,10 @@
    + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 8bc0e1c..04cfa2c 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 encoding//src/test/java=UTF-8 encoding//src/test/resources=UTF-8 encoding/=UTF-8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 44f2db9..08f7658 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,17 +1,22 @@ - + + - + + - + + + - + + diff --git a/src/main/java/envoy/data/LoginCredentials.java b/src/main/java/envoy/data/LoginCredentials.java index 58d14d4..9b29c07 100644 --- a/src/main/java/envoy/data/LoginCredentials.java +++ b/src/main/java/envoy/data/LoginCredentials.java @@ -19,20 +19,24 @@ public class LoginCredentials implements Serializable { private final String name; private final byte[] passwordHash; + private final boolean registration; private static final long serialVersionUID = -7395245059059523314L; /** * Creates an in stance of {@link LoginCredentials}. * - * @param name the name of the user - * @param password the password of the user (will be converted to a hash) + * @param name the name of the user + * @param password the password of the user (will be converted to a hash) + * @param registration signifies that these credentials are used for user + * registration instead of user login * @throws NoSuchAlgorithmException if the algorithm used is unknown * @since Envoy Common v0.2-alpha */ - public LoginCredentials(String name, char[] password) throws NoSuchAlgorithmException { - this.name = name; - passwordHash = getSha256(toByteArray(password)); + public LoginCredentials(String name, char[] password, boolean registration) throws NoSuchAlgorithmException { + this.name = name; + passwordHash = getSha256(toByteArray(password)); + this.registration = registration; } private byte[] getSha256(byte[] input) throws NoSuchAlgorithmException { return MessageDigest.getInstance("SHA-256").digest(input); } @@ -52,7 +56,7 @@ public class LoginCredentials implements Serializable { form.format("LoginCredentials[name=%s,passwordHash=", name); for (byte element : passwordHash) form.format("%02x", element); - return form.format("]").toString(); + return form.format(",registration=%b]", registration).toString(); } } @@ -67,4 +71,11 @@ public class LoginCredentials implements Serializable { * @since Envoy Common v0.2-alpha */ public byte[] getPasswordHash() { return passwordHash; } + + /** + * @return {@code true} if these credentials are used for user registration + * instead of user login + * @since Envoy Common v0.2-alpha + */ + public boolean isRegistration() { return registration; } } \ No newline at end of file From 40f6d41fffc94fa5f37a68f89f7cace907385233 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 28 Jan 2020 17:01:02 +0100 Subject: [PATCH 045/126] Renamed MessageIdGenerator to IdGenerator, added IdGeneratorRequest Also removed src/test/resources from pom.xml. --- .classpath | 5 ----- pom.xml | 5 +++++ ...MessageIdGenerator.java => IdGenerator.java} | 17 ++++++++++++----- src/main/java/envoy/data/Message.java | 6 +++--- src/main/java/envoy/event/Event.java | 3 +-- .../java/envoy/event/IdGeneratorRequest.java | 14 ++++++++++++++ 6 files changed, 35 insertions(+), 15 deletions(-) rename src/main/java/envoy/data/{MessageIdGenerator.java => IdGenerator.java} (65%) create mode 100644 src/main/java/envoy/event/IdGeneratorRequest.java diff --git a/.classpath b/.classpath index 88d37ef..907ff21 100644 --- a/.classpath +++ b/.classpath @@ -24,10 +24,5 @@ - - - - - diff --git a/pom.xml b/pom.xml index eee2dcf..1feb64c 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,11 @@ envoy-common + + + src/main/resources + + org.apache.maven.plugins diff --git a/src/main/java/envoy/data/MessageIdGenerator.java b/src/main/java/envoy/data/IdGenerator.java similarity index 65% rename from src/main/java/envoy/data/MessageIdGenerator.java rename to src/main/java/envoy/data/IdGenerator.java index dbd27a2..9b61a20 100644 --- a/src/main/java/envoy/data/MessageIdGenerator.java +++ b/src/main/java/envoy/data/IdGenerator.java @@ -1,32 +1,39 @@ package envoy.data; +import java.io.Serializable; + /** * Generates increasing IDs between two numbers.
    *
    * Project: envoy-common
    - * File: MessageIdGenerator.java
    + * File: IdGenerator.java
    * Created: 31.12.2019
    - * + * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ -public class MessageIdGenerator { +public class IdGenerator implements Serializable { private final long end; private long current; + private static final long serialVersionUID = -1517378307055845147L; + /** - * Creates an instance of {@link MessageIdGenerator}. + * Creates an instance of {@link IdGenerator}. * * @param begin the first ID * @param end the last ID * @since Envoy Common v0.2-alpha */ - public MessageIdGenerator(long begin, long end) { + public IdGenerator(long begin, long end) { current = begin; this.end = end; } + @Override + public String toString() { return String.format("MessageIdGenerator[current=%d,end=%d]", current, end); } + /** * @return {@code true} if there are unused IDs remaining * @since Envoy Common v0.2-alpha diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index 50a2f09..dea58cf 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -24,7 +24,7 @@ public class Message implements Serializable { * * @since Envoy Common v0.2-alpha */ - public static enum MessageStatus { + public enum MessageStatus { /** * is selected, if a message was sent but not received by the server yet. @@ -77,7 +77,7 @@ public class Message implements Serializable { this.id = id; this.senderId = senderId; this.recipientId = recipientId; - this.creationDate = date; + creationDate = date; this.text = text; this.attachment = attachment; this.status = status; @@ -186,6 +186,6 @@ public class Message implements Serializable { */ public void setStatus(MessageStatus status) { if (status.ordinal() < this.status.ordinal()) throw new IllegalStateException("This message is moving backwards in time"); - else this.status = status; + this.status = status; } } \ No newline at end of file diff --git a/src/main/java/envoy/event/Event.java b/src/main/java/envoy/event/Event.java index f17b95b..1aee5a4 100644 --- a/src/main/java/envoy/event/Event.java +++ b/src/main/java/envoy/event/Event.java @@ -14,6 +14,5 @@ public interface Event { /** * @return the data associated with this event */ - T get(); + default T get() { return null; } } - diff --git a/src/main/java/envoy/event/IdGeneratorRequest.java b/src/main/java/envoy/event/IdGeneratorRequest.java new file mode 100644 index 0000000..ab80515 --- /dev/null +++ b/src/main/java/envoy/event/IdGeneratorRequest.java @@ -0,0 +1,14 @@ +package envoy.event; + +/** + * Signifies to the server that the client needs a new + * {@link envoy.data.IdGenerator} instance.
    + *
    + * Project: envoy-common
    + * File: IdGeneratorRequest.java
    + * Created: 28 Jan 2020
    + * + * @author Kai S. K. Engelbart + */ +public class IdGeneratorRequest implements Event { +} From 190b686cc69d47eae2d23de7386c6f41cc22e94b Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 28 Jan 2020 17:09:28 +0100 Subject: [PATCH 046/126] Changed IdGenerator constructor to accept size instead of end index --- src/main/java/envoy/data/IdGenerator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/envoy/data/IdGenerator.java b/src/main/java/envoy/data/IdGenerator.java index 9b61a20..1d5803d 100644 --- a/src/main/java/envoy/data/IdGenerator.java +++ b/src/main/java/envoy/data/IdGenerator.java @@ -23,12 +23,12 @@ public class IdGenerator implements Serializable { * Creates an instance of {@link IdGenerator}. * * @param begin the first ID - * @param end the last ID + * @param size the amount of IDs to provide * @since Envoy Common v0.2-alpha */ - public IdGenerator(long begin, long end) { - current = begin; - this.end = end; + public IdGenerator(long begin, long size) { + current = begin; + end = begin + size; } @Override From dee7d2245fbb34d39073b7fce318ee885874d2ac Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 28 Jan 2020 17:32:33 +0100 Subject: [PATCH 047/126] Made id a mandatory field in MessageBuilder Added support for IdGenerator in the MessageBuilder constructor. --- src/main/java/envoy/data/Message.java | 18 ++++---- src/main/java/envoy/data/MessageBuilder.java | 44 +++++++++++--------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index dea58cf..85702ca 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -64,20 +64,20 @@ public class Message implements Serializable { * this class provides {@code null} checks and default values for all * properties. * - * @param id unique ID - * @param senderId the ID of the user who sends the message - * @param recipientId the ID of the user who receives the message - * @param date the creation date of the message - * @param text the text content of the message - * @param attachment the attachment of the message, if present - * @param status the current {@link MessageStatus} of the message + * @param id unique ID + * @param senderId the ID of the user who sends the message + * @param recipientId the ID of the user who receives the message + * @param creationDate the creation date of the message + * @param text the text content of the message + * @param attachment the attachment of the message, if present + * @param status the current {@link MessageStatus} of the message * @since Envoy Common v0.2-alpha */ - Message(long id, long senderId, long recipientId, Date date, String text, MessageAttachment attachment, MessageStatus status) { + Message(long id, long senderId, long recipientId, Date creationDate, String text, MessageAttachment attachment, MessageStatus status) { this.id = id; this.senderId = senderId; this.recipientId = recipientId; - creationDate = date; + this.creationDate = creationDate; this.text = text; this.attachment = attachment; this.status = status; diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java index 43e929e..5166352 100644 --- a/src/main/java/envoy/data/MessageBuilder.java +++ b/src/main/java/envoy/data/MessageBuilder.java @@ -10,7 +10,7 @@ import envoy.data.Message.MessageStatus; * Project: envoy-common
    * File: MessageBuilder.java
    * Created: 31.12.2019
    - * + * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ @@ -21,7 +21,7 @@ public class MessageBuilder { // Properties with default values private long id; - private Date date; + private Date creationDate; private String text; private MessageAttachment attachment; private Message.MessageStatus status; @@ -32,11 +32,27 @@ public class MessageBuilder { * * @param senderId the ID of the user who sends the {@link Message} * @param recipientId the ID of the user who received the {@link Message} + * @param idGenerator the ID generator used to generate a unique {@link Message} + * id * @since Envoy Common v0.2-alpha */ - public MessageBuilder(long senderId, long recipientId) { + public MessageBuilder(long senderId, long recipientId, IdGenerator idGenerator) { + this(senderId, recipientId, idGenerator.next()); + } + + /** + * Creates an instance of {@link MessageBuilder} with all mandatory values + * without defaults for the {@link Message} class. + * + * @param senderId the ID of the user who sends the {@link Message} + * @param recipientId the ID of the user who received the {@link Message} + * @param messageId the ID of the {@link Message} + * @since Envoy Common v0.2-alpha + */ + public MessageBuilder(long senderId, long recipientId, long messageId) { this.senderId = senderId; this.recipientId = recipientId; + id = messageId; } /** @@ -57,36 +73,26 @@ public class MessageBuilder { * {@code MessageStatus.WAITING} * * - * + * * @return a new instance of {@link Message} * @since Envoy Common v0.2-alpha */ public Message build() { // Supplement default values - if (date == null) date = new Date(); + if (creationDate == null) creationDate = new Date(); if (text == null) text = ""; if (status == null) status = MessageStatus.WAITING; - return new Message(id, senderId, recipientId, date, text, attachment, status); + return new Message(id, senderId, recipientId, creationDate, text, attachment, status); } /** - * @param id the unique ID of the {@link Message} to create + * @param creationDate the creation date of the {@link Message} to create * @return this {@link MessageBuilder} * @since Envoy Common v0.2-alpha */ - public MessageBuilder setId(long id) { - this.id = id; - return this; - } - - /** - * @param date the creation date of the {@link Message} to create - * @return this {@link MessageBuilder} - * @since Envoy Common v0.2-alpha - */ - public MessageBuilder setDate(Date date) { - this.date = date; + public MessageBuilder setDate(Date creationDate) { + this.creationDate = creationDate; return this; } From 1fba872558a0a2dc4e1da5f70ca1e57d1f8263b5 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 28 Jan 2020 17:50:09 +0100 Subject: [PATCH 048/126] Made Event and its implementations serializable --- src/main/java/envoy/event/Event.java | 4 +++- src/main/java/envoy/event/IdGeneratorRequest.java | 2 ++ src/main/java/envoy/event/MessageStatusChangeEvent.java | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/envoy/event/Event.java b/src/main/java/envoy/event/Event.java index 1aee5a4..3be9d9c 100644 --- a/src/main/java/envoy/event/Event.java +++ b/src/main/java/envoy/event/Event.java @@ -1,5 +1,7 @@ package envoy.event; +import java.io.Serializable; + /** * Project: envoy-common
    * File: Event.java
    @@ -9,7 +11,7 @@ package envoy.event; * @param the type of the Event * @since Envoy v0.2-alpha */ -public interface Event { +public interface Event extends Serializable { /** * @return the data associated with this event diff --git a/src/main/java/envoy/event/IdGeneratorRequest.java b/src/main/java/envoy/event/IdGeneratorRequest.java index ab80515..ec3ae34 100644 --- a/src/main/java/envoy/event/IdGeneratorRequest.java +++ b/src/main/java/envoy/event/IdGeneratorRequest.java @@ -11,4 +11,6 @@ package envoy.event; * @author Kai S. K. Engelbart */ public class IdGeneratorRequest implements Event { + + private static final long serialVersionUID = 1431107413883364583L; } diff --git a/src/main/java/envoy/event/MessageStatusChangeEvent.java b/src/main/java/envoy/event/MessageStatusChangeEvent.java index ebe818b..88b6cad 100644 --- a/src/main/java/envoy/event/MessageStatusChangeEvent.java +++ b/src/main/java/envoy/event/MessageStatusChangeEvent.java @@ -18,6 +18,8 @@ public class MessageStatusChangeEvent implements Event { private final Message.MessageStatus status; private final Date date; + private static final long serialVersionUID = 4566145392192761313L; + /** * Initializes a {@link MessageStatusChangeEvent}. * From ae73fe32a7108d171eafbcb47ede0599fdc4ed36 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 28 Jan 2020 18:58:44 +0100 Subject: [PATCH 049/126] Added HandshakeRejectionEvent and fixed some Javadoc --- .../envoy/event/HandshakeRejectionEvent.java | 41 +++++++++++++++++++ .../java/envoy/event/IdGeneratorRequest.java | 1 + .../envoy/event/MessageStatusChangeEvent.java | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/main/java/envoy/event/HandshakeRejectionEvent.java diff --git a/src/main/java/envoy/event/HandshakeRejectionEvent.java b/src/main/java/envoy/event/HandshakeRejectionEvent.java new file mode 100644 index 0000000..aca655e --- /dev/null +++ b/src/main/java/envoy/event/HandshakeRejectionEvent.java @@ -0,0 +1,41 @@ +package envoy.event; + +/** + * Signifies to the client that the handshake failed for the attached + * reason.
    + *
    + * Project: envoy-common
    + * File: HandshakeRejectionEvent.java
    + * Created: 28 Jan 2020
    + * + * @author Kai S. K. Engelbart + * @since Envoy Common v0.3-alpha + */ +public class HandshakeRejectionEvent implements Event { + + private final String reason; + + private static final long serialVersionUID = -8723270093452609197L; + + /** + * Creates an instance of {@link HandshakeRejectionEvent} with an empty reason. + * + * @since Envoy Common v0.3-alpha + */ + public HandshakeRejectionEvent() { this(""); } + + /** + * Creates an instance of {@link HandshakeRejectionEvent}. + * + * @param reason the reason why the handshake was rejected + * @since Envoy Common v0.3-alpha + */ + public HandshakeRejectionEvent(String reason) { this.reason = reason; } + + /** + * @return the reason why the handshake was rejected + * @since Envoy Common v0.3-alpha + */ + @Override + public String get() { return reason; } +} diff --git a/src/main/java/envoy/event/IdGeneratorRequest.java b/src/main/java/envoy/event/IdGeneratorRequest.java index ec3ae34..885f40d 100644 --- a/src/main/java/envoy/event/IdGeneratorRequest.java +++ b/src/main/java/envoy/event/IdGeneratorRequest.java @@ -9,6 +9,7 @@ package envoy.event; * Created: 28 Jan 2020
    * * @author Kai S. K. Engelbart + * @since Envoy Common v0.3-alpha */ public class IdGeneratorRequest implements Event { diff --git a/src/main/java/envoy/event/MessageStatusChangeEvent.java b/src/main/java/envoy/event/MessageStatusChangeEvent.java index 88b6cad..c56f7a0 100644 --- a/src/main/java/envoy/event/MessageStatusChangeEvent.java +++ b/src/main/java/envoy/event/MessageStatusChangeEvent.java @@ -36,7 +36,7 @@ public class MessageStatusChangeEvent implements Event { } /** - * Initialises a {@link MessageStatusChangeEvent} through a message. + * Initializes a {@link MessageStatusChangeEvent} through a message. * * @param message the message from which to build the event * @since Envoy Common v0.2-alpha From e2013f7a09cf39c8ccc3c4157e1f28c143d91224 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 28 Jan 2020 19:58:23 +0100 Subject: [PATCH 050/126] Fixed typo --- src/main/java/envoy/data/IdGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/envoy/data/IdGenerator.java b/src/main/java/envoy/data/IdGenerator.java index 1d5803d..26b7131 100644 --- a/src/main/java/envoy/data/IdGenerator.java +++ b/src/main/java/envoy/data/IdGenerator.java @@ -32,7 +32,7 @@ public class IdGenerator implements Serializable { } @Override - public String toString() { return String.format("MessageIdGenerator[current=%d,end=%d]", current, end); } + public String toString() { return String.format("IdGenerator[current=%d,end=%d]", current, end); } /** * @return {@code true} if there are unused IDs remaining From 8afafa014b9ea2e214bd96fa7e4d31e26e29943f Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 1 Feb 2020 11:32:55 +0100 Subject: [PATCH 051/126] Added UserStatusChange - Event --- .settings/org.eclipse.jdt.ui.prefs | 3 ++ .../envoy/event/UserStatusChangeEvent.java | 54 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .settings/org.eclipse.jdt.ui.prefs create mode 100644 src/main/java/envoy/event/UserStatusChangeEvent.java diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..bbaba45 --- /dev/null +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.ui.javadoc=true +org.eclipse.jdt.ui.text.custom_code_templates=