Replaced sync XSD by custom objects

* Removed JAXB dependencies
* Added User, Message and TextMessage
* Changed version to 0.2-alpha in POM
This commit is contained in:
2019-12-28 22:03:41 +02:00
parent 8bff9184b6
commit cf05f8e1d3
11 changed files with 231 additions and 205 deletions

View File

@ -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}.<br>
* <br>
* Project: <strong>envoy-common</strong><br>
* File: <strong>Message.java</strong><br>
* Created: <strong>28.12.2019</strong><br>
*
* @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.<br>
* <br>
* The underlying order is as follows:
* <ol>
* <li>{@link MessageStatus#WAITING}
* <li>{@link MessageStatus#SENT}
* <li>{@link MessageStatus#RECEIVED}
* <li>{@link MessageStatus#READ}
* </ol>
*
* @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
}
}

View File

@ -0,0 +1,54 @@
package envoy.data;
import java.text.SimpleDateFormat;
/**
* Represents a {@link Message} with content that is comprised of text.<br>
* <br>
* Project: <strong>envoy-common</strong><br>
* File: <strong>TextMessage.java</strong><br>
* Created: <strong>28.12.2019</strong><br>
*
* @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; }
}

View File

@ -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}.<br>
* <br>
* Project: <strong>envoy-common</strong><br>
* File: <strong>User.java</strong><br>
* Created: <strong>28.12.2019</strong><br>
*
* @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;
}
}

View File

@ -1,22 +0,0 @@
package envoy.schema;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
/**
* Project: <strong>envoy-common</strong><br>
* File: <strong>MessageState.java</strong><br>
* Created: <strong>11 Oct 2019</strong><br>
*
* @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); }
}

View File

@ -1,22 +0,0 @@
package envoy.schema;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
/**
* Project: <strong>envoy-common</strong><br>
* File: <strong>UserStatus.java</strong><br>
* Created: <strong>27 Oct 2019</strong><br>
*
* @author Maximilian K&auml;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); }
}