Started integration of new server architecture

* Removed JAX-RS dependency from POM
* Changed version in POM to 0.3-alpha

The errors that appear throughout LocalDB and Client are caused by the
architecture change and will be removed in future commits.
This commit is contained in:
Kai S. K. Engelbart 2019-12-28 22:20:43 +02:00
parent c1182a97fe
commit 88c810c2f4
12 changed files with 51 additions and 91 deletions

14
pom.xml
View File

@ -5,7 +5,7 @@
<groupId>informatik-ag-ngl</groupId> <groupId>informatik-ag-ngl</groupId>
<artifactId>envoy-client</artifactId> <artifactId>envoy-client</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.3-alpha</version>
<name>Envoy Client</name> <name>Envoy Client</name>
<url>https://github.com/informatik-ag-ngl/envoy-client</url> <url>https://github.com/informatik-ag-ngl/envoy-client</url>
@ -18,20 +18,10 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>4.1.1.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency> <dependency>
<groupId>informatik-ag-ngl</groupId> <groupId>informatik-ag-ngl</groupId>
<artifactId>envoy-common</artifactId> <artifactId>envoy-common</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.2-alpha</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -4,8 +4,8 @@ import java.io.Serializable;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import envoy.schema.Message; import envoy.data.Message;
import envoy.schema.User; import envoy.data.User;
/** /**
* Represents a chat between two {@link User}s <br> * Represents a chat between two {@link User}s <br>

View File

@ -14,10 +14,8 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import envoy.client.util.EnvoyLog; import envoy.client.util.EnvoyLog;
import envoy.data.User;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
import envoy.schema.ObjectFactory;
import envoy.schema.Sync;
import envoy.schema.User;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -31,7 +29,6 @@ import envoy.schema.User;
*/ */
public class Client { public class Client {
private ObjectFactory objectFactory = new ObjectFactory();
private Config config; private Config config;
private User sender, recipient; private User sender, recipient;
private boolean online = false; private boolean online = false;

View File

@ -2,10 +2,10 @@ package envoy.client;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.naming.spi.ObjectFactory;
import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.DatatypeFactory;
@ -13,9 +13,9 @@ import envoy.client.event.EventBus;
import envoy.client.event.MessageCreationEvent; import envoy.client.event.MessageCreationEvent;
import envoy.client.util.EnvoyLog; import envoy.client.util.EnvoyLog;
import envoy.client.util.SerializationUtils; import envoy.client.util.SerializationUtils;
import envoy.data.Message;
import envoy.data.User;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
import envoy.schema.*;
import envoy.schema.Message.Metadata.MessageState;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -73,7 +73,7 @@ public class LocalDB {
*/ */
public void initializeDBFile() { public void initializeDBFile() {
if (user == null) throw new NullPointerException("Client user is null"); if (user == null) throw new NullPointerException("Client user is null");
localDBFile = new File(localDBDir, user.getID() + ".db"); localDBFile = new File(localDBDir, user.getId() + ".db");
} }
/** /**
@ -107,32 +107,6 @@ public class LocalDB {
*/ */
public void loadChats() throws EnvoyException { chats = SerializationUtils.read(localDBFile, ArrayList.class); } public void loadChats() throws EnvoyException { chats = SerializationUtils.read(localDBFile, ArrayList.class); }
/**
* Creates a {@link Message} object serializable to XML.
*
* @param textContent The content (text) of the message
* @param recipientID The recipient of the message
* @return prepared {@link Message} object
* @since Envoy v0.1-alpha
*/
public Message createMessage(String textContent, long recipientID) {
Message.Metadata metaData = objectFactory.createMessageMetadata();
metaData.setSender(user.getID());
metaData.setRecipient(recipientID);
metaData.setState(MessageState.WAITING);
metaData.setDate(datatypeFactory.newXMLGregorianCalendar(Instant.now().toString()));
Message.Content content = objectFactory.createMessageContent();
content.setType("text");
content.setText(textContent);
Message message = objectFactory.createMessage();
message.setMetadata(metaData);
message.getContent().add(content);
return message;
}
/** /**
* Creates a {@link Sync} object filled with the changes that occurred to the * Creates a {@link Sync} object filled with the changes that occurred to the
* local database since the last synchronization. * local database since the last synchronization.
@ -181,7 +155,7 @@ public class LocalDB {
} else { } else {
// Update Messages in localDB to state RECEIVED // Update Messages in localDB to state RECEIVED
for (Chat chat : getChats()) for (Chat chat : getChats())
if (chat.getRecipient().getID() == returnSync.getMessages().get(i).getMetadata().getRecipient()) if (chat.getRecipient().getId() == returnSync.getMessages().get(i).getMetadata().getRecipient())
for (int j = 0; j < chat.getModel().getSize(); j++) for (int j = 0; j < chat.getModel().getSize(); j++)
if (chat.getModel().get(j).getMetadata().getMessageId() == returnSync.getMessages() if (chat.getModel().get(j).getMetadata().getMessageId() == returnSync.getMessages()
.get(i) .get(i)
@ -195,8 +169,8 @@ public class LocalDB {
logger.info("Message with ID: " + returnSync.getMessages().get(i).getMetadata().getMessageId() logger.info("Message with ID: " + returnSync.getMessages().get(i).getMetadata().getMessageId()
+ "was initialized to be set to READ in localDB."); + "was initialized to be set to READ in localDB.");
for (Chat chat : getChats()) for (Chat chat : getChats())
if (chat.getRecipient().getID() == returnSync.getMessages().get(i).getMetadata().getRecipient()) { if (chat.getRecipient().getId() == returnSync.getMessages().get(i).getMetadata().getRecipient()) {
logger.info("Chat with: " + chat.getRecipient().getID() + "was selected."); logger.info("Chat with: " + chat.getRecipient().getId() + "was selected.");
for (int k = 0; k < chat.getModel().getSize(); k++) for (int k = 0; k < chat.getModel().getSize(); k++)
if (chat.getModel().get(k).getMetadata().getMessageId() == returnSync.getMessages() if (chat.getModel().get(k).getMetadata().getMessageId() == returnSync.getMessages()
.get(i) .get(i)
@ -215,7 +189,7 @@ public class LocalDB {
// Updating UserStatus of all users in LocalDB // Updating UserStatus of all users in LocalDB
for (User user : returnSync.getUsers()) for (User user : returnSync.getUsers())
for (Chat chat : getChats()) for (Chat chat : getChats())
if (user.getID() == chat.getRecipient().getID()) chat.getRecipient().setStatus(user.getStatus()); if (user.getId() == chat.getRecipient().getId()) chat.getRecipient().setStatus(user.getStatus());
sync.getMessages().clear(); sync.getMessages().clear();
sync.getUsers().clear(); sync.getUsers().clear();
@ -230,7 +204,7 @@ public class LocalDB {
public void addUnreadMessagesToLocalDB() { public void addUnreadMessagesToLocalDB() {
for (Message message : unreadMessagesSync.getMessages()) for (Message message : unreadMessagesSync.getMessages())
for (Chat chat : getChats()) for (Chat chat : getChats())
if (message.getMetadata().getSender() == chat.getRecipient().getID()) { if (message.getMetadata().getSender() == chat.getRecipient().getId()) {
chat.appendMessage(message); chat.appendMessage(message);
break; break;
} }
@ -247,7 +221,7 @@ public class LocalDB {
*/ */
public void setMessagesToRead(Chat currentChat) { public void setMessagesToRead(Chat currentChat) {
for (int i = currentChat.getModel().size() - 1; i >= 0; --i) for (int i = currentChat.getModel().size() - 1; i >= 0; --i)
if (currentChat.getModel().get(i).getMetadata().getRecipient() != currentChat.getRecipient().getID()) if (currentChat.getModel().get(i).getMetadata().getRecipient() != currentChat.getRecipient().getId())
if (currentChat.getModel().get(i).getMetadata().getState() == MessageState.RECEIVED) { if (currentChat.getModel().get(i).getMetadata().getState() == MessageState.RECEIVED) {
currentChat.getModel().get(i).getMetadata().setState(MessageState.READ); currentChat.getModel().get(i).getMetadata().setState(MessageState.READ);
readMessages.getMessages().add(currentChat.getModel().get(i)); readMessages.getMessages().add(currentChat.getModel().get(i));

View File

@ -1,6 +1,6 @@
package envoy.client.event; package envoy.client.event;
import envoy.schema.Message; import envoy.data.Message;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>

View File

@ -1,6 +1,6 @@
package envoy.client.event; package envoy.client.event;
import envoy.schema.Message; import envoy.data.Message;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>

View File

@ -1,6 +1,6 @@
package envoy.client.event; package envoy.client.event;
import envoy.schema.Message; import envoy.data.Message;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>

View File

@ -14,8 +14,9 @@ import envoy.client.event.EventBus;
import envoy.client.event.ThemeChangeEvent; import envoy.client.event.ThemeChangeEvent;
import envoy.client.ui.settings.SettingsScreen; import envoy.client.ui.settings.SettingsScreen;
import envoy.client.util.EnvoyLog; import envoy.client.util.EnvoyLog;
import envoy.schema.Message; import envoy.data.Message;
import envoy.schema.User; import envoy.data.TextMessage;
import envoy.data.User;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -164,7 +165,7 @@ public class ChatWindow extends JFrame {
final JList<User> selectedUserList = (JList<User>) listSelectionEvent.getSource(); final JList<User> selectedUserList = (JList<User>) listSelectionEvent.getSource();
final User user = selectedUserList.getSelectedValue(); final User user = selectedUserList.getSelectedValue();
currentChat = localDB.getChats().stream().filter(chat -> chat.getRecipient().getID() == user.getID()).findFirst().get(); currentChat = localDB.getChats().stream().filter(chat -> chat.getRecipient().getId() == user.getId()).findFirst().get();
// Set all unread messages in the chat to read // Set all unread messages in the chat to read
readCurrentChat(); readCurrentChat();
@ -246,7 +247,7 @@ public class ChatWindow extends JFrame {
if (!messageEnterTextArea.getText().isEmpty()) try { if (!messageEnterTextArea.getText().isEmpty()) try {
// Create and send message object // Create and send message object
final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient().getID()); final Message message = new TextMessage(0, localDB.getUser(), currentChat.getRecipient(), messageEnterTextArea.getText());
currentChat.appendMessage(message); currentChat.appendMessage(message);
messageList.setModel(currentChat.getModel()); messageList.setModel(currentChat.getModel());
@ -275,7 +276,7 @@ public class ChatWindow extends JFrame {
userListModel.addElement(user); userListModel.addElement(user);
// Check if user exists in local DB // Check if user exists in local DB
if (localDB.getChats().stream().filter(c -> c.getRecipient().getID() == user.getID()).count() == 0) if (localDB.getChats().stream().filter(c -> c.getRecipient().getId() == user.getId()).count() == 0)
localDB.getChats().add(new Chat(user)); localDB.getChats().add(new Chat(user));
}); });
SwingUtilities.invokeLater(() -> userList.setModel(userListModel)); SwingUtilities.invokeLater(() -> userList.setModel(userListModel));
@ -296,7 +297,7 @@ public class ChatWindow extends JFrame {
// Synchronize // Synchronize
try { try {
localDB.applySync(client.sendSync(client.getSender().getID(), localDB.fillSync(client.getSender().getID()))); localDB.applySync(client.sendSync(client.getSender().getId(), localDB.fillSync(client.getSender().getId())));
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.SEVERE, "Could not perform sync", e); logger.log(Level.SEVERE, "Could not perform sync", e);
} }
@ -317,7 +318,7 @@ public class ChatWindow extends JFrame {
private void updateUserStates() { private void updateUserStates() {
for (int i = 0; i < userList.getModel().getSize(); i++) for (int i = 0; i < userList.getModel().getSize(); i++)
for (int j = 0; j < localDB.getChats().size(); j++) for (int j = 0; j < localDB.getChats().size(); j++)
if (userList.getModel().getElementAt(i).getID() == localDB.getChats().get(j).getRecipient().getID()) if (userList.getModel().getElementAt(i).getId() == localDB.getChats().get(j).getRecipient().getId())
userList.getModel().getElementAt(i).setStatus(localDB.getChats().get(j).getRecipient().getStatus()); userList.getModel().getElementAt(i).setStatus(localDB.getChats().get(j).getRecipient().getStatus());
} }

View File

@ -8,7 +8,8 @@ import javax.swing.JList;
import javax.swing.ListCellRenderer; import javax.swing.ListCellRenderer;
import envoy.client.Settings; import envoy.client.Settings;
import envoy.schema.Message; import envoy.data.Message;
import envoy.data.TextMessage;
/** /**
* Defines how a message is displayed.<br> * Defines how a message is displayed.<br>
@ -37,19 +38,18 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer<Mess
setOpaque(true); setOpaque(true);
final String text = value.getContent().get(0).getText(); // TODO: Handle other message types
final String state = value.getMetadata().getState().toString(); final TextMessage message = (TextMessage) value;
final String date = value.getMetadata().getDate() == null ? ""
: new SimpleDateFormat("dd.MM.yyyy HH:mm ").format(value.getMetadata().getDate().toGregorianCalendar().getTime()); final String text = message.getContent();
final String state = message.getStatus().toString();
final String date = new SimpleDateFormat("dd.MM.yyyy HH.mm").format(message.getDate());
// Getting the MessageColor in the Chat of the current theme // Getting the MessageColor in the Chat of the current theme
String textColor = null; String textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat().toHex();
textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat().toHex();
// Getting the DateColor in the Chat of the current theme // Getting the DateColor in the Chat of the current theme
String dateColor = null; String dateColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat().toHex();
dateColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getDateColorChat().toHex();
setText(String.format("<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>", setText(String.format("<html><p style=\"color:%s\"><b><small>%s</b></small><br><p style=\"color:%s\">%s :%s</html>",
dateColor, dateColor,

View File

@ -12,8 +12,8 @@ import javax.swing.SwingUtilities;
import envoy.client.*; import envoy.client.*;
import envoy.client.util.EnvoyLog; import envoy.client.util.EnvoyLog;
import envoy.data.User;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
import envoy.schema.User;
/** /**
* Starts the Envoy client and prompts the user to enter their name.<br> * Starts the Envoy client and prompts the user to enter their name.<br>
@ -129,7 +129,7 @@ public class Startup {
JOptionPane.WARNING_MESSAGE); JOptionPane.WARNING_MESSAGE);
} }
logger.info("Client user ID: " + client.getSender().getID()); logger.info("Client user ID: " + client.getSender().getId());
// Save all users to the local database // Save all users to the local database
if (client.isOnline()) localDB.setUsers(client.getUsers()); if (client.isOnline()) localDB.setUsers(client.getUsers());

View File

@ -1,21 +1,15 @@
package envoy.client.ui; package envoy.client.ui;
import java.awt.AWTException; import java.awt.*;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType; import java.awt.TrayIcon.MessageType;
import java.awt.Window;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import envoy.client.event.EventBus; import envoy.client.event.EventBus;
import envoy.client.event.MessageCreationEvent; import envoy.client.event.MessageCreationEvent;
import envoy.data.Message;
import envoy.data.TextMessage;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
import envoy.schema.Message;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -81,9 +75,13 @@ public class StatusTrayIcon {
trayIcon.addActionListener((evt) -> { focusTarget.setVisible(true); focusTarget.requestFocus(); }); trayIcon.addActionListener((evt) -> { focusTarget.setVisible(true); focusTarget.requestFocus(); });
// Start processing message events // Start processing message events
EventBus.getInstance().register(MessageCreationEvent.class, (evt) -> { EventBus.getInstance()
if (displayMessages) .register(MessageCreationEvent.class,
trayIcon.displayMessage("New message received", ((MessageCreationEvent) evt).get().getContent().get(0).getText(), MessageType.INFO); (evt) -> {
// TODO: Handle other message types
if (displayMessages) trayIcon.displayMessage("New message received",
((TextMessage) ((MessageCreationEvent) evt).get()).getContent(),
MessageType.INFO);
}); });
} }

View File

@ -7,8 +7,8 @@ import javax.swing.JList;
import javax.swing.ListCellRenderer; import javax.swing.ListCellRenderer;
import envoy.client.Settings; import envoy.client.Settings;
import envoy.schema.User; import envoy.data.User;
import envoy.schema.User.UserStatus; import envoy.data.User.UserStatus;
/** /**
* Defines how the {@code UserList} is displayed.<br> * Defines how the {@code UserList} is displayed.<br>