Merge branch 'develop' of https://github.com/informatik-ag-ngl/envoy-client.git into develop
This commit is contained in:
		@@ -36,7 +36,7 @@ public class Client {
 | 
				
			|||||||
	private ObjectFactory	objectFactory	= new ObjectFactory();
 | 
						private ObjectFactory	objectFactory	= new ObjectFactory();
 | 
				
			||||||
	private DatatypeFactory	datatypeFactory;
 | 
						private DatatypeFactory	datatypeFactory;
 | 
				
			||||||
	private Config			config;
 | 
						private Config			config;
 | 
				
			||||||
	private User user;
 | 
						private User			user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public Client(Config config, String username) {
 | 
						public Client(Config config, String username) {
 | 
				
			||||||
		this.config = config;
 | 
							this.config = config;
 | 
				
			||||||
@@ -54,9 +54,9 @@ public class Client {
 | 
				
			|||||||
	 * Because sending a request is a blocking operation, it is executed
 | 
						 * Because sending a request is a blocking operation, it is executed
 | 
				
			||||||
	 * asynchronously.
 | 
						 * asynchronously.
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param sender      Name of the sender
 | 
						 * @param sender      name of the sender
 | 
				
			||||||
	 * @param recipient   Name of the recipient
 | 
						 * @param recipient   name of the recipient
 | 
				
			||||||
	 * @param textContent Content (text) of the message
 | 
						 * @param textContent content (text) of the message
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void sendMessage(Message message) {
 | 
						public void sendMessage(Message message) {
 | 
				
			||||||
		new Thread(() -> {
 | 
							new Thread(() -> {
 | 
				
			||||||
@@ -92,7 +92,7 @@ public class Client {
 | 
				
			|||||||
	 * @param senderID    The ID of the sender
 | 
						 * @param senderID    The ID of the sender
 | 
				
			||||||
	 * @param recipientID The ID of the recipient
 | 
						 * @param recipientID The ID of the recipient
 | 
				
			||||||
	 * @param textContent The content (text) of the message
 | 
						 * @param textContent The content (text) of the message
 | 
				
			||||||
	 * @return Prepared {@link Message} object
 | 
						 * @return prepared {@link Message} object
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public Message createMessage(long senderID, long recipientID, String textContent) {
 | 
						public Message createMessage(long senderID, long recipientID, String textContent) {
 | 
				
			||||||
		Message.MetaData metaData = objectFactory.createMessageMetaData();
 | 
							Message.MetaData metaData = objectFactory.createMessageMetaData();
 | 
				
			||||||
@@ -129,18 +129,18 @@ public class Client {
 | 
				
			|||||||
		client.close();
 | 
							client.close();
 | 
				
			||||||
		return users;
 | 
							return users;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Returns the user by name.
 | 
						 * Returns a {@link User} with a specific name by name.
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param name - the name of the user
 | 
						 * @param name - the name of the {@link User}
 | 
				
			||||||
	 * @return an user object
 | 
						 * @return a {@link User} with the specified name
 | 
				
			||||||
	 * @since Envoy 0.1
 | 
						 * @since Envoy 0.1
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private User getUser(String name) {
 | 
						private User getUser(String name) {
 | 
				
			||||||
		javax.ws.rs.client.Client	client		= ClientBuilder.newClient();
 | 
							javax.ws.rs.client.Client	client		= ClientBuilder.newClient();
 | 
				
			||||||
		WebTarget					target		= client
 | 
							WebTarget					target		= client.target(String
 | 
				
			||||||
			.target(String.format("%s:%d/envoy-server/rest/user/sender?name=" + name, config.getServer(), config.getPort()));
 | 
								.format("%s:%d/envoy-server/rest/user/sender?name=" + name, config.getServer(), config.getPort()));
 | 
				
			||||||
		Response					response	= target.request("application/xml").get();
 | 
							Response					response	= target.request("application/xml").get();
 | 
				
			||||||
		Users						users		= response.readEntity(Users.class);
 | 
							Users						users		= response.readEntity(Users.class);
 | 
				
			||||||
		System.out.println("Response code: " + response.getStatus());
 | 
							System.out.println("Response code: " + response.getStatus());
 | 
				
			||||||
@@ -148,4 +148,10 @@ public class Client {
 | 
				
			|||||||
		client.close();
 | 
							client.close();
 | 
				
			||||||
		return users.getUser().get(0);
 | 
							return users.getUser().get(0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * @return the user id of this client
 | 
				
			||||||
 | 
						 * @since Envoy 0.1
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public long getSenderID() { return user.getID(); }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -2,13 +2,10 @@ package envoy.client.ui;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.awt.Color;
 | 
					import java.awt.Color;
 | 
				
			||||||
import java.awt.ComponentOrientation;
 | 
					import java.awt.ComponentOrientation;
 | 
				
			||||||
import java.awt.EventQueue;
 | 
					 | 
				
			||||||
import java.awt.Font;
 | 
					import java.awt.Font;
 | 
				
			||||||
import java.awt.GridBagConstraints;
 | 
					import java.awt.GridBagConstraints;
 | 
				
			||||||
import java.awt.GridBagLayout;
 | 
					import java.awt.GridBagLayout;
 | 
				
			||||||
import java.awt.Insets;
 | 
					import java.awt.Insets;
 | 
				
			||||||
import java.io.IOException;
 | 
					 | 
				
			||||||
import java.util.Properties;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.swing.DefaultListModel;
 | 
					import javax.swing.DefaultListModel;
 | 
				
			||||||
import javax.swing.JButton;
 | 
					import javax.swing.JButton;
 | 
				
			||||||
@@ -23,7 +20,6 @@ import javax.swing.SwingUtilities;
 | 
				
			|||||||
import javax.swing.border.EmptyBorder;
 | 
					import javax.swing.border.EmptyBorder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import envoy.client.Client;
 | 
					import envoy.client.Client;
 | 
				
			||||||
import envoy.client.Config;
 | 
					 | 
				
			||||||
import envoy.schema.Message;
 | 
					import envoy.schema.Message;
 | 
				
			||||||
import envoy.schema.User;
 | 
					import envoy.schema.User;
 | 
				
			||||||
import envoy.schema.Users;
 | 
					import envoy.schema.Users;
 | 
				
			||||||
@@ -51,7 +47,7 @@ public class ChatWindow extends JFrame {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	public ChatWindow(Client client) {
 | 
						public ChatWindow(Client client) {
 | 
				
			||||||
		this.client = client;
 | 
							this.client = client;
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 | 
							setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 | 
				
			||||||
		setBounds(100, 100, 600, 800);
 | 
							setBounds(100, 100, 600, 800);
 | 
				
			||||||
		setTitle("Envoy");
 | 
							setTitle("Envoy");
 | 
				
			||||||
@@ -138,7 +134,8 @@ public class ChatWindow extends JFrame {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			// TODO: Acquire proper sender id
 | 
								// TODO: Acquire proper sender id
 | 
				
			||||||
			if (!messageEnterTextfield.getText().isEmpty() && recipientID != 0) try {
 | 
								if (!messageEnterTextfield.getText().isEmpty() && recipientID != 0) try {
 | 
				
			||||||
				final Message message = client.createMessage(1, recipientID, messageEnterTextfield.getText());
 | 
									final Message message = client
 | 
				
			||||||
 | 
										.createMessage(client.getSenderID(), recipientID, messageEnterTextfield.getText());
 | 
				
			||||||
				client.sendMessage(message);
 | 
									client.sendMessage(message);
 | 
				
			||||||
				appendMessageToChat(message);
 | 
									appendMessageToChat(message);
 | 
				
			||||||
				messageEnterTextfield.setText("");
 | 
									messageEnterTextfield.setText("");
 | 
				
			||||||
@@ -214,5 +211,4 @@ public class ChatWindow extends JFrame {
 | 
				
			|||||||
				+ message.getMetaData().getSender() + "</b> </small>" + "<br>" + "<p style=\"color:white\">"
 | 
									+ message.getMetaData().getSender() + "</b> </small>" + "<br>" + "<p style=\"color:white\">"
 | 
				
			||||||
				+ getFirstTextContent(message) + "</span></html>");
 | 
									+ getFirstTextContent(message) + "</span></html>");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -5,15 +5,12 @@ import java.io.IOException;
 | 
				
			|||||||
import java.util.Properties;
 | 
					import java.util.Properties;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.swing.JOptionPane;
 | 
					import javax.swing.JOptionPane;
 | 
				
			||||||
import javax.ws.rs.client.Entity;
 | 
					 | 
				
			||||||
import javax.ws.rs.client.WebTarget;
 | 
					 | 
				
			||||||
import javax.ws.rs.core.Response;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import envoy.client.Client;
 | 
					import envoy.client.Client;
 | 
				
			||||||
import envoy.client.Config;
 | 
					import envoy.client.Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Starts Envoy and sets a user.
 | 
					 * Starts the Envoy client and prompts the user to enter their name.
 | 
				
			||||||
 * 
 | 
					 * 
 | 
				
			||||||
 * Project: <strong>envoy-client</strong><br>
 | 
					 * Project: <strong>envoy-client</strong><br>
 | 
				
			||||||
 * File: <strong>Startup.java</strong><br>
 | 
					 * File: <strong>Startup.java</strong><br>
 | 
				
			||||||
@@ -24,9 +21,7 @@ import envoy.client.Config;
 | 
				
			|||||||
 * @since Envoy 0.1
 | 
					 * @since Envoy 0.1
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class Startup {
 | 
					public class Startup {
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	private static String userName;
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public static void main(String[] args) {
 | 
						public static void main(String[] args) {
 | 
				
			||||||
		Config config = new Config();
 | 
							Config config = new Config();
 | 
				
			||||||
		if (args.length > 0) {
 | 
							if (args.length > 0) {
 | 
				
			||||||
@@ -42,15 +37,18 @@ public class Startup {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(!config.isInitialized()) {
 | 
							if (!config.isInitialized()) {
 | 
				
			||||||
			System.err.println("Server or port are not defined. Exiting...");
 | 
								System.err.println("Server or port are not defined. Exiting...");
 | 
				
			||||||
			System.exit(1);
 | 
								System.exit(1);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		userName = JOptionPane.showInputDialog("Please enter your username");
 | 
							String userName = JOptionPane.showInputDialog("Please enter your username");
 | 
				
			||||||
		
 | 
							if (userName == null || userName.isEmpty()) {
 | 
				
			||||||
 | 
								System.err.println("User name is not set or empty. Exiting...");
 | 
				
			||||||
 | 
								System.exit(1);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		Client client = new Client(config, userName);
 | 
							Client client = new Client(config, userName);
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		EventQueue.invokeLater(() -> {
 | 
							EventQueue.invokeLater(() -> {
 | 
				
			||||||
			try {
 | 
								try {
 | 
				
			||||||
				ChatWindow frame = new ChatWindow(client);
 | 
									ChatWindow frame = new ChatWindow(client);
 | 
				
			||||||
@@ -60,4 +58,4 @@ public class Startup {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user