From 88c810c2f4ecfb317078ff27447fc3af8c0413ab Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 28 Dec 2019 22:20:43 +0200 Subject: [PATCH] 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. --- pom.xml | 14 +----- src/main/java/envoy/client/Chat.java | 4 +- src/main/java/envoy/client/Client.java | 5 +- src/main/java/envoy/client/LocalDB.java | 46 ++++--------------- .../client/event/MessageCreationEvent.java | 2 +- .../java/envoy/client/event/MessageEvent.java | 2 +- .../event/MessageModificationEvent.java | 2 +- src/main/java/envoy/client/ui/ChatWindow.java | 15 +++--- .../envoy/client/ui/MessageListRenderer.java | 20 ++++---- src/main/java/envoy/client/ui/Startup.java | 4 +- .../java/envoy/client/ui/StatusTrayIcon.java | 24 +++++----- .../envoy/client/ui/UserListRenderer.java | 4 +- 12 files changed, 51 insertions(+), 91 deletions(-) diff --git a/pom.xml b/pom.xml index d688c37..28e6f60 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ informatik-ag-ngl envoy-client - 0.0.1-SNAPSHOT + 0.3-alpha Envoy Client https://github.com/informatik-ag-ngl/envoy-client @@ -18,20 +18,10 @@ - - org.jboss.resteasy - resteasy-client - 4.1.1.Final - - - org.jboss.resteasy - resteasy-jaxb-provider - 4.3.1.Final - informatik-ag-ngl envoy-common - 0.0.1-SNAPSHOT + 0.2-alpha diff --git a/src/main/java/envoy/client/Chat.java b/src/main/java/envoy/client/Chat.java index daca33a..ef762c4 100644 --- a/src/main/java/envoy/client/Chat.java +++ b/src/main/java/envoy/client/Chat.java @@ -4,8 +4,8 @@ import java.io.Serializable; import javax.swing.DefaultListModel; -import envoy.schema.Message; -import envoy.schema.User; +import envoy.data.Message; +import envoy.data.User; /** * Represents a chat between two {@link User}s
diff --git a/src/main/java/envoy/client/Client.java b/src/main/java/envoy/client/Client.java index edc4839..1d27d5b 100644 --- a/src/main/java/envoy/client/Client.java +++ b/src/main/java/envoy/client/Client.java @@ -14,10 +14,8 @@ import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import envoy.client.util.EnvoyLog; +import envoy.data.User; import envoy.exception.EnvoyException; -import envoy.schema.ObjectFactory; -import envoy.schema.Sync; -import envoy.schema.User; /** * Project: envoy-client
@@ -31,7 +29,6 @@ import envoy.schema.User; */ public class Client { - private ObjectFactory objectFactory = new ObjectFactory(); private Config config; private User sender, recipient; private boolean online = false; diff --git a/src/main/java/envoy/client/LocalDB.java b/src/main/java/envoy/client/LocalDB.java index b5e3971..c86e3a0 100644 --- a/src/main/java/envoy/client/LocalDB.java +++ b/src/main/java/envoy/client/LocalDB.java @@ -2,10 +2,10 @@ package envoy.client; import java.io.File; import java.io.IOException; -import java.time.Instant; import java.util.*; import java.util.logging.Logger; +import javax.naming.spi.ObjectFactory; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; @@ -13,9 +13,9 @@ import envoy.client.event.EventBus; import envoy.client.event.MessageCreationEvent; import envoy.client.util.EnvoyLog; import envoy.client.util.SerializationUtils; +import envoy.data.Message; +import envoy.data.User; import envoy.exception.EnvoyException; -import envoy.schema.*; -import envoy.schema.Message.Metadata.MessageState; /** * Project: envoy-client
@@ -73,7 +73,7 @@ public class LocalDB { */ public void initializeDBFile() { 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); } - /** - * 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 * local database since the last synchronization. @@ -181,7 +155,7 @@ public class LocalDB { } else { // Update Messages in localDB to state RECEIVED 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++) if (chat.getModel().get(j).getMetadata().getMessageId() == returnSync.getMessages() .get(i) @@ -195,8 +169,8 @@ public class LocalDB { logger.info("Message with ID: " + returnSync.getMessages().get(i).getMetadata().getMessageId() + "was initialized to be set to READ in localDB."); for (Chat chat : getChats()) - if (chat.getRecipient().getID() == returnSync.getMessages().get(i).getMetadata().getRecipient()) { - logger.info("Chat with: " + chat.getRecipient().getID() + "was selected."); + if (chat.getRecipient().getId() == returnSync.getMessages().get(i).getMetadata().getRecipient()) { + logger.info("Chat with: " + chat.getRecipient().getId() + "was selected."); for (int k = 0; k < chat.getModel().getSize(); k++) if (chat.getModel().get(k).getMetadata().getMessageId() == returnSync.getMessages() .get(i) @@ -215,7 +189,7 @@ public class LocalDB { // Updating UserStatus of all users in LocalDB for (User user : returnSync.getUsers()) 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.getUsers().clear(); @@ -230,7 +204,7 @@ public class LocalDB { public void addUnreadMessagesToLocalDB() { for (Message message : unreadMessagesSync.getMessages()) for (Chat chat : getChats()) - if (message.getMetadata().getSender() == chat.getRecipient().getID()) { + if (message.getMetadata().getSender() == chat.getRecipient().getId()) { chat.appendMessage(message); break; } @@ -247,7 +221,7 @@ public class LocalDB { */ public void setMessagesToRead(Chat currentChat) { 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) { currentChat.getModel().get(i).getMetadata().setState(MessageState.READ); readMessages.getMessages().add(currentChat.getModel().get(i)); diff --git a/src/main/java/envoy/client/event/MessageCreationEvent.java b/src/main/java/envoy/client/event/MessageCreationEvent.java index 28f1b58..36397d9 100644 --- a/src/main/java/envoy/client/event/MessageCreationEvent.java +++ b/src/main/java/envoy/client/event/MessageCreationEvent.java @@ -1,6 +1,6 @@ package envoy.client.event; -import envoy.schema.Message; +import envoy.data.Message; /** * Project: envoy-client
diff --git a/src/main/java/envoy/client/event/MessageEvent.java b/src/main/java/envoy/client/event/MessageEvent.java index 2e818e5..1dab6e7 100644 --- a/src/main/java/envoy/client/event/MessageEvent.java +++ b/src/main/java/envoy/client/event/MessageEvent.java @@ -1,6 +1,6 @@ package envoy.client.event; -import envoy.schema.Message; +import envoy.data.Message; /** * Project: envoy-client
diff --git a/src/main/java/envoy/client/event/MessageModificationEvent.java b/src/main/java/envoy/client/event/MessageModificationEvent.java index 0b83ef0..248c6f1 100644 --- a/src/main/java/envoy/client/event/MessageModificationEvent.java +++ b/src/main/java/envoy/client/event/MessageModificationEvent.java @@ -1,6 +1,6 @@ package envoy.client.event; -import envoy.schema.Message; +import envoy.data.Message; /** * Project: envoy-client
diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index dc68e10..5f8ff21 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -14,8 +14,9 @@ import envoy.client.event.EventBus; import envoy.client.event.ThemeChangeEvent; import envoy.client.ui.settings.SettingsScreen; import envoy.client.util.EnvoyLog; -import envoy.schema.Message; -import envoy.schema.User; +import envoy.data.Message; +import envoy.data.TextMessage; +import envoy.data.User; /** * Project: envoy-client
@@ -164,7 +165,7 @@ public class ChatWindow extends JFrame { final JList selectedUserList = (JList) listSelectionEvent.getSource(); 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 readCurrentChat(); @@ -246,7 +247,7 @@ public class ChatWindow extends JFrame { if (!messageEnterTextArea.getText().isEmpty()) try { // 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); messageList.setModel(currentChat.getModel()); @@ -275,7 +276,7 @@ public class ChatWindow extends JFrame { userListModel.addElement(user); // 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)); }); SwingUtilities.invokeLater(() -> userList.setModel(userListModel)); @@ -296,7 +297,7 @@ public class ChatWindow extends JFrame { // Synchronize 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) { logger.log(Level.SEVERE, "Could not perform sync", e); } @@ -317,7 +318,7 @@ public class ChatWindow extends JFrame { private void updateUserStates() { for (int i = 0; i < userList.getModel().getSize(); i++) 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()); } diff --git a/src/main/java/envoy/client/ui/MessageListRenderer.java b/src/main/java/envoy/client/ui/MessageListRenderer.java index ddd2230..967b1cc 100644 --- a/src/main/java/envoy/client/ui/MessageListRenderer.java +++ b/src/main/java/envoy/client/ui/MessageListRenderer.java @@ -8,7 +8,8 @@ import javax.swing.JList; import javax.swing.ListCellRenderer; import envoy.client.Settings; -import envoy.schema.Message; +import envoy.data.Message; +import envoy.data.TextMessage; /** * Defines how a message is displayed.
@@ -37,19 +38,18 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer

%s

%s :%s", dateColor, diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java index 8e57a08..1125030 100644 --- a/src/main/java/envoy/client/ui/Startup.java +++ b/src/main/java/envoy/client/ui/Startup.java @@ -12,8 +12,8 @@ import javax.swing.SwingUtilities; import envoy.client.*; import envoy.client.util.EnvoyLog; +import envoy.data.User; import envoy.exception.EnvoyException; -import envoy.schema.User; /** * Starts the Envoy client and prompts the user to enter their name.
@@ -129,7 +129,7 @@ public class Startup { 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 if (client.isOnline()) localDB.setUsers(client.getUsers()); diff --git a/src/main/java/envoy/client/ui/StatusTrayIcon.java b/src/main/java/envoy/client/ui/StatusTrayIcon.java index 4670377..68427f6 100644 --- a/src/main/java/envoy/client/ui/StatusTrayIcon.java +++ b/src/main/java/envoy/client/ui/StatusTrayIcon.java @@ -1,21 +1,15 @@ package envoy.client.ui; -import java.awt.AWTException; -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.*; import java.awt.TrayIcon.MessageType; -import java.awt.Window; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import envoy.client.event.EventBus; import envoy.client.event.MessageCreationEvent; +import envoy.data.Message; +import envoy.data.TextMessage; import envoy.exception.EnvoyException; -import envoy.schema.Message; /** * Project: envoy-client
@@ -81,10 +75,14 @@ public class StatusTrayIcon { trayIcon.addActionListener((evt) -> { focusTarget.setVisible(true); focusTarget.requestFocus(); }); // Start processing message events - EventBus.getInstance().register(MessageCreationEvent.class, (evt) -> { - if (displayMessages) - trayIcon.displayMessage("New message received", ((MessageCreationEvent) evt).get().getContent().get(0).getText(), MessageType.INFO); - }); + EventBus.getInstance() + .register(MessageCreationEvent.class, + (evt) -> { + // TODO: Handle other message types + if (displayMessages) trayIcon.displayMessage("New message received", + ((TextMessage) ((MessageCreationEvent) evt).get()).getContent(), + MessageType.INFO); + }); } /** diff --git a/src/main/java/envoy/client/ui/UserListRenderer.java b/src/main/java/envoy/client/ui/UserListRenderer.java index ca7214d..9441801 100644 --- a/src/main/java/envoy/client/ui/UserListRenderer.java +++ b/src/main/java/envoy/client/ui/UserListRenderer.java @@ -7,8 +7,8 @@ import javax.swing.JList; import javax.swing.ListCellRenderer; import envoy.client.Settings; -import envoy.schema.User; -import envoy.schema.User.UserStatus; +import envoy.data.User; +import envoy.data.User.UserStatus; /** * Defines how the {@code UserList} is displayed.