From cf05f8e1d3937fd2c6389d1b07cf9c0d469dba74 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 28 Dec 2019 22:03:41 +0200 Subject: [PATCH] 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