From 4bbc4189ec13584f93977be0440849c6265d2a2b Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 22 Aug 2020 13:15:42 +0200 Subject: [PATCH 1/4] Updated config mechanism and added config for the server Additionally fixed a small bug in EnvoyLog and envoy.server.Startup, fixed Receiver not stopping when the server was stopped and added access token authorization for the server config --- .../java/envoy/client/data/ClientConfig.java | 41 ++---- .../main/java/envoy/client/net/Receiver.java | 13 +- .../main/java/envoy/client/ui/Startup.java | 25 +--- client/src/main/resources/client.properties | 10 +- common/src/main/java/envoy/data/Config.java | 130 ++++++++++++++++-- .../src/main/java/envoy/data/ConfigItem.java | 12 +- common/src/main/java/envoy/util/EnvoyLog.java | 40 ++---- .../src/main/java/envoy/server/Startup.java | 35 ++--- .../java/envoy/server/data/ServerConfig.java | 82 +++++++++++ .../processors/IssueProposalProcessor.java | 45 +++--- server/src/main/resources/server.properties | 14 ++ 11 files changed, 287 insertions(+), 160 deletions(-) create mode 100644 server/src/main/java/envoy/server/data/ServerConfig.java create mode 100644 server/src/main/resources/server.properties diff --git a/client/src/main/java/envoy/client/data/ClientConfig.java b/client/src/main/java/envoy/client/data/ClientConfig.java index 3a18f08..2b3da37 100644 --- a/client/src/main/java/envoy/client/data/ClientConfig.java +++ b/client/src/main/java/envoy/client/data/ClientConfig.java @@ -3,10 +3,8 @@ package envoy.client.data; import static java.util.function.Function.identity; import java.io.File; -import java.util.logging.Level; import envoy.data.Config; -import envoy.data.ConfigItem; /** * Implements a configuration specific to the Envoy Client with default values @@ -33,15 +31,13 @@ public class ClientConfig extends Config { } private ClientConfig() { - items.put("server", new ConfigItem<>("server", "s", identity(), null, true)); - items.put("port", new ConfigItem<>("port", "p", Integer::parseInt, null, true)); - items.put("localDB", new ConfigItem<>("localDB", "db", File::new, new File("localDB"), true)); - items.put("ignoreLocalDB", new ConfigItem<>("ignoreLocalDB", "nodb", Boolean::parseBoolean, false, false)); - items.put("homeDirectory", new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy"), true)); - items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.OFF, true)); - items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.OFF, true)); - items.put("user", new ConfigItem<>("user", "u", identity())); - items.put("password", new ConfigItem<>("password", "pw", identity())); + super(".envoy"); + put("server", "s", identity(), true); + put("port", "p", Integer::parseInt, true); + put("localDB", "db", File::new, true); + put("ignoreLocalDB", "nodb", Boolean::parseBoolean); + put("user", "u", identity()); + put("password", "pw", identity()); } /** @@ -66,25 +62,10 @@ public class ClientConfig extends Config { * @return {@code true} if the local database is to be ignored * @since Envoy Client v0.3-alpha */ - public Boolean isIgnoreLocalDB() { return (Boolean) items.get("ignoreLocalDB").get(); } - - /** - * @return the directory in which all local files are saves - * @since Envoy Client v0.2-alpha - */ - public File getHomeDirectory() { return (File) items.get("homeDirectory").get(); } - - /** - * @return the minimal {@link Level} to log inside the log file - * @since Envoy Client v0.2-alpha - */ - public Level getFileLevelBarrier() { return (Level) items.get("fileLevelBarrier").get(); } - - /** - * @return the minimal {@link Level} to log inside the console - * @since Envoy Client v0.2-alpha - */ - public Level getConsoleLevelBarrier() { return (Level) items.get("consoleLevelBarrier").get(); } + public Boolean isIgnoreLocalDB() { + final var ignoreLocalDB = items.get("ignoreLocalDB").get(); + return ignoreLocalDB != null && (Boolean) ignoreLocalDB; + } /** * @return the user name diff --git a/client/src/main/java/envoy/client/net/Receiver.java b/client/src/main/java/envoy/client/net/Receiver.java index fdfa1e8..acbfeb5 100644 --- a/client/src/main/java/envoy/client/net/Receiver.java +++ b/client/src/main/java/envoy/client/net/Receiver.java @@ -24,6 +24,8 @@ import envoy.util.SerializationUtils; */ public class Receiver extends Thread { + private boolean isAlive = true; + private final InputStream in; private final Map, Consumer> processors = new HashMap<>(); @@ -49,7 +51,7 @@ public class Receiver extends Thread { @Override public void run() { - while (true) { + while (isAlive) try { // Read object length final byte[] lenBytes = new byte[4]; @@ -64,6 +66,12 @@ public class Receiver extends Thread { // Catch LV encoding errors if (len != bytesRead) { + // Server has stopped sending, i.e. because he went offline + if (len == 0 && bytesRead == -1) { + isAlive = false; + logger.log(Level.WARNING, "Lost connection to the server. Exiting receiver"); + continue; + } logger.log(Level.WARNING, String.format("LV encoding violated: expected %d bytes, received %d bytes. Discarding object...", len, bytesRead)); continue; @@ -87,7 +95,6 @@ public class Receiver extends Thread { } catch (final Exception e) { logger.log(Level.SEVERE, "Error on receiver thread", e); } - } } /** @@ -102,7 +109,7 @@ public class Receiver extends Thread { /** * Adds a map of object processors to this {@link Receiver}. - * + * * @param processors the processors to add the processors to add * @since Envoy Client v0.1-beta */ diff --git a/client/src/main/java/envoy/client/ui/Startup.java b/client/src/main/java/envoy/client/ui/Startup.java index 464b8e3..7c2bff6 100644 --- a/client/src/main/java/envoy/client/ui/Startup.java +++ b/client/src/main/java/envoy/client/ui/Startup.java @@ -2,7 +2,6 @@ package envoy.client.ui; import java.io.File; import java.io.IOException; -import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; @@ -19,7 +18,6 @@ import envoy.data.GroupMessage; import envoy.data.Message; import envoy.event.GroupMessageStatusChange; import envoy.event.MessageStatusChange; -import envoy.exception.EnvoyException; import envoy.util.EnvoyLog; /** @@ -57,30 +55,13 @@ public final class Startup extends Application { @Override public void start(Stage stage) throws Exception { try { - // Load the configuration from client.properties first - final Properties properties = new Properties(); - properties.load(Startup.class.getClassLoader().getResourceAsStream("client.properties")); - config.load(properties); - - // Override configuration values with command line arguments - final String[] args = getParameters().getRaw().toArray(new String[0]); - if (args.length > 0) config.load(args); - - // Check if all mandatory configuration values have been initialized - if (!config.isInitialized()) throw new EnvoyException("Configuration is not fully initialized"); - } catch (final Exception e) { + config.loadAll(Startup.class, "client.properties", getParameters().getRaw().toArray(new String[0])); + EnvoyLog.initialize(config); + } catch (final IllegalStateException e) { new Alert(AlertType.ERROR, "Error loading configuration values:\n" + e); logger.log(Level.SEVERE, "Error loading configuration values: ", e); - e.printStackTrace(); System.exit(1); } - - // Setup logger for the envoy package - EnvoyLog.initialize(config); - EnvoyLog.attach("envoy"); - EnvoyLog.setFileLevelBarrier(config.getFileLevelBarrier()); - EnvoyLog.setConsoleLevelBarrier(config.getConsoleLevelBarrier()); - logger.log(Level.INFO, "Envoy starting..."); // Initialize the local database diff --git a/client/src/main/resources/client.properties b/client/src/main/resources/client.properties index 25f1ffd..6f3d633 100644 --- a/client/src/main/resources/client.properties +++ b/client/src/main/resources/client.properties @@ -1,4 +1,6 @@ -server=localhost -port=8080 -localDB=localDB -consoleLevelBarrier=FINER +server=localhost +port=8080 +localDB=localDB +consoleLevelBarrier=FINER +fileLevelBarrier=OFF +ignoreLocalDB=false diff --git a/common/src/main/java/envoy/data/Config.java b/common/src/main/java/envoy/data/Config.java index bcff68c..b51acea 100644 --- a/common/src/main/java/envoy/data/Config.java +++ b/common/src/main/java/envoy/data/Config.java @@ -1,8 +1,13 @@ package envoy.data; +import java.io.File; +import java.io.IOException; import java.util.*; +import java.util.function.Function; +import java.util.logging.Level; +import java.util.stream.Collectors; -import envoy.exception.EnvoyException; +import envoy.util.EnvoyLog; /** * Manages all application settings that are set during application startup by @@ -21,13 +26,23 @@ public class Config { protected Map> items = new HashMap<>(); + private boolean modificationDisabled; + + protected Config(String folderName) { + final var rootDirectory = new File(System.getProperty("user.home"), folderName); + put("homeDirectory", "home", File::new, true); + ((ConfigItem) get("homeDirectory")).setValue(rootDirectory); + put("fileLevelBarrier", "fb", Level::parse, true); + put("consoleLevelBarrier", "cb", Level::parse, true); + } + /** * Parses config items from a properties object. * * @param properties the properties object to parse * @since Envoy Common v0.1-beta */ - public void load(Properties properties) { + private void load(Properties properties) { items.entrySet() .stream() .filter(e -> properties.containsKey(e.getKey())) @@ -38,43 +53,77 @@ public class Config { * Parses config items from an array of command line arguments. * * @param args the command line arguments to parse - * @throws EnvoyException if the command line arguments contain an unknown token + * @throws IllegalStateException if a malformed command line argument has been + * supplied * @since Envoy Common v0.1-beta */ - public void load(String[] args) throws EnvoyException { + private void load(String[] args) { for (int i = 0; i < args.length; i++) - for (ConfigItem item : items.values()) + for (final ConfigItem item : items.values()) if (args[i].startsWith("--")) { - if (args[i].length() == 2) throw new EnvoyException("Malformed command line argument at position " + i); + if (args[i].length() == 2) throw new IllegalStateException("Malformed command line argument at position " + i + ": " + args[i]); final String commandLong = args[i].substring(2); if (item.getCommandLong().equals(commandLong)) { item.parse(args[++i]); break; } } else if (args[i].startsWith("-")) { - if (args[i].length() == 1) throw new EnvoyException("Malformed command line argument at position " + i); + if (args[i].length() == 1) throw new IllegalStateException("Malformed command line argument at position " + i + ": " + args[i]); final String commandShort = args[i].substring(1); if (item.getCommandShort().equals(commandShort)) { item.parse(args[++i]); break; } - } else throw new EnvoyException("Malformed command line argument at position " + i); + } else throw new IllegalStateException("Malformed command line argument at position " + i + ": " + args[i]); } /** - * Initializes config items from a map. - * - * @param items the items to include in this config + * Supplies default values from the given .properties file and + * parses the configuration from an array of command line arguments. + * + * @param declaringClass the class calling this method + * @param propertiesFilePath the path to where the .properties file can be found + * - will be only the file name if it is located + * directly inside the {@code src/main/resources} + * folder + * @param args the command line arguments to parse + * @throws IllegalStateException if this method is getting called again or if a + * malformed command line argument has been + * supplied * @since Envoy Common v0.1-beta */ - public void load(Map> items) { this.items.putAll(items); } + public void loadAll(Class declaringClass, String propertiesFilePath, String[] args) { + if (modificationDisabled) throw new IllegalStateException("Cannot change config after isInitialized has been called"); + // Load the defaults from the given .properties file first + final var properties = new Properties(); + try { + properties.load(declaringClass.getClassLoader().getResourceAsStream(propertiesFilePath)); + } catch (final IOException e) { + EnvoyLog.getLogger(Config.class).log(Level.SEVERE, "An error occurred when reading in the configuration: ", e); + } + load(properties); + + // Override configuration values with command line arguments + if (args.length > 0) load(args); + + // Check if all mandatory configuration values have been initialized + isInitialized(); + // Disable further editing of the config + modificationDisabled = true; + } /** - * @return {@code true} if all mandatory config items are initialized + * @throws IllegalStateException if a mandatory {@link ConfigItem} has not been + * initialized * @since Envoy Common v0.1-beta */ - public boolean isInitialized() { - return items.values().stream().filter(ConfigItem::isMandatory).map(ConfigItem::get).noneMatch(Objects::isNull); + private void isInitialized() { + if (items.values().stream().filter(ConfigItem::isMandatory).map(ConfigItem::get).anyMatch(Objects::isNull)) + throw new IllegalStateException("config item(s) has/ have not been initialized:" + items.values() + .stream() + .filter(configItem -> configItem.isMandatory() && configItem.get() == null) + .map(ConfigItem::getCommandLong) + .collect(Collectors.toSet())); } /** @@ -83,4 +132,55 @@ public class Config { * @since Envoy Common v0.1-beta */ public ConfigItem get(String name) { return items.get(name); } + + /** + * Shorthand for
+ * {@code items.put(commandName, new ConfigItem<>(commandName, commandShort, parseFunction, defaultValue, mandatory))}. + * + * @param the type of the {@link ConfigItem} + * @param commandName the key for this config item as well as its long name + * @param commandShort the abbreviation of this config item + * @param parseFunction the {@code Function} that parses the value + * from a string + * @param mandatory indicated that this config item must be initialized with + * a non-null value + * @since Envoy Common v0.2-beta + */ + protected void put(String commandName, String commandShort, Function parseFunction, boolean mandatory) { + items.put(commandName, new ConfigItem<>(commandName, commandShort, parseFunction, mandatory)); + } + + /** + * Shorthand for
+ * {@code put(commandName, commandShort, parseFunction, false)}. + * + * @param the type of the {@link ConfigItem} + * @param commandName the key for this config item as well as its long name + * @param commandShort the abbreviation of this config item + * @param parseFunction the {@code Function} that parses the value + * from a string + * @since Envoy Common v0.2-beta + */ + protected void put(String commandName, String commandShort, Function parseFunction) { + put(commandName, commandShort, parseFunction, false); + } + + /** + * @return the directory in which all local files are saves + * @since Envoy Client v0.2-beta + */ + public File getHomeDirectory() { return (File) items.get("homeDirectory").get(); } + + /** + * @return the minimal {@link Level} to log inside the log file + * @since Envoy Client v0.2-beta + */ + public Level getFileLevelBarrier() { return (Level) items.get("fileLevelBarrier").get(); } + + /** + * @return the minimal {@link Level} to log inside the console + * @since Envoy Client v0.2-beta + */ + public Level getConsoleLevelBarrier() { return (Level) items.get("consoleLevelBarrier").get(); } + } diff --git a/common/src/main/java/envoy/data/ConfigItem.java b/common/src/main/java/envoy/data/ConfigItem.java index 028b599..9ed1462 100644 --- a/common/src/main/java/envoy/data/ConfigItem.java +++ b/common/src/main/java/envoy/data/ConfigItem.java @@ -29,17 +29,15 @@ public class ConfigItem { * @param commandShort the short command line argument to set this value * @param parseFunction the {@code Function} that parses the value * from a string - * @param defaultValue the optional default value to set before parsing * @param mandatory indicated that this config item must be initialized with * a non-null value * @since Envoy Common v0.1-beta */ - public ConfigItem(String commandLong, String commandShort, Function parseFunction, T defaultValue, boolean mandatory) { + public ConfigItem(String commandLong, String commandShort, Function parseFunction, boolean mandatory) { this.commandLong = commandLong; this.commandShort = commandShort; this.parseFunction = parseFunction; this.mandatory = mandatory; - value = defaultValue; } /** @@ -52,7 +50,7 @@ public class ConfigItem { * @since Envoy Common v0.1-beta */ public ConfigItem(String commandLong, String commandShort, Function parseFunction) { - this(commandLong, commandShort, parseFunction, null, false); + this(commandLong, commandShort, parseFunction, false); } /** @@ -83,6 +81,12 @@ public class ConfigItem { */ public T get() { return value; } + /** + * @param value the value to set + * @since Envoy Common v0.2-beta + */ + protected void setValue(T value) { this.value = value; } + /** * @return {@code true} if this {@link ConfigItem} is mandatory for successful * application initialization diff --git a/common/src/main/java/envoy/util/EnvoyLog.java b/common/src/main/java/envoy/util/EnvoyLog.java index d64e69f..c15c4d4 100644 --- a/common/src/main/java/envoy/util/EnvoyLog.java +++ b/common/src/main/java/envoy/util/EnvoyLog.java @@ -12,12 +12,9 @@ import envoy.data.Config; * Configures the {@link java.util.logging} API to output the log into the * console and a log file. *

- * Call the {@link EnvoyLog#attach(String)} method to configure a part of the - * logger hierarchy. - *

* Project: envoy-client
* File: EnvoyLogger.java
- * Created: 14 Dec 2019
+ * Created: 14.12.2019
* * @author Leon Hofmeister * @author Kai S. K. Engelbart @@ -32,8 +29,7 @@ public class EnvoyLog { private EnvoyLog() {} /** - * Initializes logging. Call this method before calling the - * {@link EnvoyLog#attach(String)} method. + * Initializes logging. * * @param config the config providing the console and log file barriers * @since Envoy Common v0.1-beta @@ -45,18 +41,19 @@ public class EnvoyLog { LogManager.getLogManager().reset(); // Configure log file - final File logFile = new File((File) config.get("homeDirectory").get(), - "log/envoy_user_" + DateTimeFormatter.ofPattern("yyyy-MM-dd--hh-mm-mm").format(LocalDateTime.now()) + ".log"); + final File logFile = new File(config.getHomeDirectory(), + "log/" + DateTimeFormatter.ofPattern("yyyy-MM-dd--hh-mm").format(LocalDateTime.now()) + ".log"); logFile.getParentFile().mkdirs(); // Configure formatting - // Sample log entry: [2020-06-13 16:50:26] [INFORMATION] [envoy.client.ui.Startup] Closing connection... + // Sample log entry: [2020-06-13 16:50:26] [INFORMATION] + // [envoy.client.ui.Startup] Closing connection... System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] [%4$-7s] [%3$s] %5$s %6$s%n"); final SimpleFormatter formatter = new SimpleFormatter(); try { fileHandler = new FileHandler(logFile.getAbsolutePath()); - fileHandler.setLevel((Level) config.get("fileLevelBarrier").get()); + fileHandler.setLevel(config.getFileLevelBarrier()); fileHandler.setFormatter(formatter); } catch (SecurityException | IOException e) { e.printStackTrace(); @@ -69,10 +66,11 @@ public class EnvoyLog { flush(); } }; - consoleHandler.setLevel((Level) config.get("consoleLevelBarrier").get()); + consoleHandler.setLevel(config.getConsoleLevelBarrier()); consoleHandler.setFormatter(formatter); initialized = true; + EnvoyLog.attach("envoy"); } /** @@ -82,7 +80,7 @@ public class EnvoyLog { * @param path the path to the loggers to configure * @since Envoy Common v0.1-beta */ - public static void attach(String path) { + private static void attach(String path) { if (!initialized) throw new IllegalStateException("EnvoyLog is not initialized"); // Get root logger @@ -105,22 +103,4 @@ public class EnvoyLog { * @since Envoy Common v0.1-beta */ public static Logger getLogger(Class logClass) { return Logger.getLogger(logClass.getCanonicalName()); } - - /** - * Defines the logger level required for a record to be written to the log file. - * - * @param fileLevelBarrier the log file level - * @since Envoy Common v0.1-beta - */ - public static void setFileLevelBarrier(Level fileLevelBarrier) { if (fileHandler != null) fileHandler.setLevel(fileLevelBarrier); } - - /** - * Defines the logger level required for a record to be written to the console. - * - * @param consoleLevelBarrier the console logger level - * @since Envoy Common v0.1-beta - */ - public static void setConsoleLevelBarrier(Level consoleLevelBarrier) { - if (consoleHandler != null) consoleHandler.setLevel(consoleLevelBarrier); - } } diff --git a/server/src/main/java/envoy/server/Startup.java b/server/src/main/java/envoy/server/Startup.java index 84b569c..7232cba 100755 --- a/server/src/main/java/envoy/server/Startup.java +++ b/server/src/main/java/envoy/server/Startup.java @@ -1,16 +1,13 @@ package envoy.server; -import java.io.File; import java.io.IOException; -import java.util.HashMap; import java.util.Set; import java.util.logging.Level; import com.jenkov.nioserver.Server; -import envoy.data.Config; -import envoy.data.ConfigItem; import envoy.server.data.PersistenceManager; +import envoy.server.data.ServerConfig; import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectMessageProcessor; import envoy.server.net.ObjectMessageReader; @@ -30,23 +27,9 @@ import envoy.util.EnvoyLog; public class Startup { /** - * Initializes the logger with a new config instance. - * - * @since Envoy Server Standalone v0.1-beta + * Stores the configuration used for the whole server */ - private static void initLogging() { - final var items = new HashMap>(); - items.put("homeDirectory", - new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy-server"), true)); - items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.WARNING, true)); - items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.FINEST, true)); - - final var config = new Config(); - config.load(items); - - EnvoyLog.initialize(config); - EnvoyLog.attach("envoy"); - } + public static final ServerConfig config = ServerConfig.getInstance(); /** * Starts the server. @@ -57,7 +40,13 @@ public class Startup { * @since Envoy Server Standalone v0.1-alpha */ public static void main(String[] args) throws IOException { - initLogging(); + try { + config.loadAll(Startup.class, "server.properties", args); + EnvoyLog.initialize(config); + } catch (final IllegalStateException e) { + EnvoyLog.getLogger(Startup.class).log(Level.SEVERE, "Error loading configuration values: ", e); + System.exit(1); + } final var server = new Server(8080, ObjectMessageReader::new, new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(), @@ -84,8 +73,8 @@ public class Startup { server.start(); server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance()); - if (args.length == 0 || !args[0].equalsIgnoreCase("no-enter-to-stop")) { - System.out.println("Press the return key to stop the server..."); + if (config.isEnterToStop()) { + System.out.println("Press Enter to stop the server..."); System.in.read(); System.out.println("Stopped"); System.exit(0); diff --git a/server/src/main/java/envoy/server/data/ServerConfig.java b/server/src/main/java/envoy/server/data/ServerConfig.java new file mode 100644 index 0000000..bb9a9ae --- /dev/null +++ b/server/src/main/java/envoy/server/data/ServerConfig.java @@ -0,0 +1,82 @@ +package envoy.server.data; + +import static java.util.function.Function.identity; + +import envoy.data.Config; + +/** + * Project: server
+ * File: ServerConfig.java
+ * Created: 21.08.2020
+ * + * @author Leon Hofmeister + * @since Envoy Server v0.2-beta + */ +public class ServerConfig extends Config { + + private static ServerConfig config; + + /** + * @return the singleton instance of the server config + * @since Envoy Client v0.1-beta + */ + public static ServerConfig getInstance() { return config == null ? config = new ServerConfig() : config; } + + private ServerConfig() { + super(".envoy-server"); + put("enter-to-stop", "dev-stop", Boolean::parseBoolean, true); + // parameters for issue reporting + put("issueCreationURL", "i-url", identity(), true); + put("issueAuthToken", "i-token", identity()); + put("userMadeLabel", "l-um", identity(), true); + put("bugLabel", "l-b", identity(), true); + put("featureLabel", "l-f", identity(), true); + // enabling/ disabling several processors + put("enableIssueReporting", "e-ir", Boolean::parseBoolean, true); + } + + /** + * @return true if this server should be stoppable by pressing enter + * @since Envoy Server v0.2-beta + */ + public Boolean isEnterToStop() { return (Boolean) items.get("enter-to-stop").get(); } + + /** + * @return {@code true} if issue reporting is enabled + * @since Envoy Client v0.3-alpha + */ + public Boolean isIssueReportingEnabled() { return (Boolean) items.get("enableIssueReporting").get(); } + + /** + * @return the URL where issues should be uploaded to + * @since Envoy Client v0.1-alpha + */ + public String getIssueReportingURL() { return (String) items.get("issueCreationURL").get(); } + + /** + * @return the String representation for the "{@code user made}" - label + * @since Envoy Client v0.1-alpha + */ + public String getUserMadeLabel() { return (String) items.get("userMadeLabel").get(); } + + /** + * @return the String representation for the "{@code user made}" - label + * @since Envoy Client v0.1-alpha + */ + public String getBugLabel() { return (String) items.get("bugLabel").get(); } + + /** + * @return the String representation for the "{@code user made}" - label + * @since Envoy Client v0.1-alpha + */ + public String getFeatureLabel() { return (String) items.get("featureLabel").get(); } + + /** + * @return the authorization token used to authenticate to + * {@link ServerConfig#getIssueReportingURL()}. If null, + * authorization is expected to occur via a query_param or via a basic + * user-password-combination + * @since Envoy Server v0.2-beta + */ + public String getIssueAuthToken() { return (String) items.get("issueAuthToken").get(); } +} diff --git a/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java b/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java index 97a9b54..8aa639c 100644 --- a/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java +++ b/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java @@ -1,5 +1,7 @@ package envoy.server.processors; +import static envoy.server.Startup.config; + import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; @@ -23,27 +25,32 @@ import envoy.util.EnvoyLog; */ public class IssueProposalProcessor implements ObjectProcessor { - private static boolean issueReportingEnabled = true; - private static final Logger logger = EnvoyLog.getLogger(IssueProposalProcessor.class); + private static final Logger logger = EnvoyLog.getLogger(IssueProposalProcessor.class); @Override public void process(IssueProposal issueProposal, long socketID, ObjectWriteProxy writeProxy) throws IOException { // Do nothing if manually disabled - if (!issueReportingEnabled) return; + if (!config.isIssueReportingEnabled()) return; try { - final var url = new URL( - "https://git.kske.dev/api/v1/repos/zdm/envoy/issues?access_token=6d8ec2a72d64cbaf6319434aa2e7caf0130701b3"); + final var url = new URL(config.getIssueReportingURL()); final var connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json; utf-8"); connection.setRequestProperty("Accept", "application/json"); + // Two types of authorization are currently supported: access token as + // query param or access token as authorization header + final var authenticationToken = config.getIssueAuthToken(); + if (authenticationToken != null) { + final String auth = "token " + authenticationToken; + connection.setRequestProperty("Authorization", auth); + } connection.setDoOutput(true); - final var json = String.format("{\"title\":\"%s\",\"body\":\"%s\",\"labels\":[240, %d]}", + final var json = String.format("{\"title\":\"%s\",\"body\":\"%s\",\"labels\":[%s, %s]}", issueProposal.get(), issueProposal.getDescription(), - // Label 240 should be user-made, label 117 bug and label 119 feature - issueProposal.isBug() ? 117 : 119); + config.getUserMadeLabel(), + issueProposal.isBug() ? config.getBugLabel() : config.getFeatureLabel()); try (final var os = connection.getOutputStream()) { final byte[] input = json.getBytes("utf-8"); os.write(input, 0, input.length); @@ -51,29 +58,9 @@ public class IssueProposalProcessor implements ObjectProcessor { final var status = connection.getResponseCode(); if (status == 201) logger.log(Level.INFO, "Successfully created an issue"); else logger.log(Level.WARNING, - String.format("Tried creating an issue for %s but received status code %d - Request params:title=%s,description=%s,json=%s", - url, - status, - issueProposal.get(), - issueProposal.getDescription(), - json)); + String.format("Tried creating an issue for %s but received status code %d - Request params:%s", url, status, json)); } catch (final IOException e) { logger.log(Level.WARNING, "An error occurred while creating an issue: ", e); } } - - /** - * @return whether issue reporting is enabled - * @since Envoy Server v0.2-beta - */ - public static boolean isIssueReportingEnabled() { return issueReportingEnabled; } - - /** - * @param issueReportingEnabled whether issue reporting should be enabled - true - * by default - * @since Envoy Server v0.2-beta - */ - public static void setIssueReportingEnabled(boolean issueReportingEnabled) { - IssueProposalProcessor.issueReportingEnabled = issueReportingEnabled; - } } diff --git a/server/src/main/resources/server.properties b/server/src/main/resources/server.properties new file mode 100644 index 0000000..216288d --- /dev/null +++ b/server/src/main/resources/server.properties @@ -0,0 +1,14 @@ +enter-to-stop=true +enableIssueReporting=true +# git.kske.dev config +issueCreationURL=https://git.kske.dev/api/v1/repos/zdm/envoy/issues?access_token=6d8ec2a72d64cbaf6319434aa2e7caf0130701b3 +userMadeLabel=240 +bugLabel=117 +featureLabel=119 +# api.github.com config - supply an additional auth token +#issueCreationURL=https://api.github.com/repos/informatik-ag-ngl/envoy/issues +#userMadeLabel="user made" +#bugLabel="bug" +#featureLabel="feature" +consoleLevelBarrier=FINEST +fileLevelBarrier=WARNING \ No newline at end of file From eb4e421974021ec2710b531151d3f439622451d9 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 22 Aug 2020 13:37:07 +0200 Subject: [PATCH 2/4] Made every class that can be final final --- client/src/main/java/envoy/client/Main.java | 2 +- .../java/envoy/client/data/ClientConfig.java | 2 +- .../java/envoy/client/data/GroupChat.java | 15 +++++------ .../main/java/envoy/client/data/Settings.java | 6 +++-- .../java/envoy/client/data/SettingsItem.java | 2 +- .../client/data/commands/SystemCommand.java | 2 +- .../data/commands/SystemCommandBuilder.java | 2 +- .../client/event/MessageCreationEvent.java | 2 +- .../event/MessageModificationEvent.java | 2 +- .../java/envoy/client/event/SendEvent.java | 2 +- .../envoy/client/event/ThemeChangeEvent.java | 2 +- .../main/java/envoy/client/net/Client.java | 2 +- .../GroupMessageStatusChangeProcessor.java | 6 ++--- .../net/MessageStatusChangeProcessor.java | 2 +- .../net/ReceivedGroupMessageProcessor.java | 4 +-- .../client/net/ReceivedMessageProcessor.java | 2 +- .../main/java/envoy/client/net/Receiver.java | 2 +- .../java/envoy/client/net/WriteProxy.java | 6 ++--- .../envoy/client/ui/ClearableTextField.java | 26 +++++++++---------- .../main/java/envoy/client/ui/IconUtil.java | 4 +-- .../java/envoy/client/ui/StatusTrayIcon.java | 6 ++--- .../ui/controller/ContactSearchScene.java | 2 +- .../ui/controller/GroupCreationScene.java | 2 +- .../client/ui/controller/SettingsScene.java | 2 +- .../envoy/client/ui/listcell/ChatControl.java | 6 ++--- .../client/ui/listcell/ContactControl.java | 6 ++--- .../client/ui/listcell/MessageControl.java | 5 ++-- .../client/ui/settings/BugReportPane.java | 2 +- .../ui/settings/DownloadSettingsPane.java | 2 +- .../ui/settings/GeneralSettingsPane.java | 2 +- .../client/ui/settings/UserSettingsPane.java | 2 +- .../java/envoy/client/util/IssueUtil.java | 2 +- .../envoy/client/util/ReflectionUtil.java | 2 +- .../src/main/java/envoy/data/Attachment.java | 2 +- .../src/main/java/envoy/data/ConfigItem.java | 2 +- .../src/main/java/envoy/data/IDGenerator.java | 2 +- .../main/java/envoy/data/MessageBuilder.java | 16 ++++++------ .../src/main/java/envoy/event/EventBus.java | 2 +- .../main/java/envoy/event/GroupCreation.java | 2 +- .../envoy/event/GroupMessageStatusChange.java | 2 +- .../main/java/envoy/event/GroupResize.java | 2 +- .../java/envoy/event/HandshakeRejection.java | 2 +- .../java/envoy/event/IDGeneratorRequest.java | 2 +- .../src/main/java/envoy/event/IsTyping.java | 2 +- .../main/java/envoy/event/IssueProposal.java | 2 +- .../src/main/java/envoy/event/NameChange.java | 2 +- .../envoy/event/PasswordChangeRequest.java | 2 +- .../envoy/event/PasswordChangeResult.java | 2 +- .../java/envoy/event/ProfilePicChange.java | 2 +- .../java/envoy/event/UserStatusChange.java | 2 +- .../envoy/event/contact/ContactOperation.java | 2 +- .../event/contact/UserSearchRequest.java | 2 +- .../envoy/event/contact/UserSearchResult.java | 2 +- .../java/envoy/exception/EnvoyException.java | 2 +- common/src/main/java/envoy/util/Bounds.java | 2 +- common/src/main/java/envoy/util/EnvoyLog.java | 2 +- .../java/envoy/util/SerializationUtils.java | 2 +- .../src/main/java/envoy/server/Startup.java | 2 +- .../java/envoy/server/data/ConfigItem.java | 2 +- .../main/java/envoy/server/data/Group.java | 2 +- .../java/envoy/server/data/GroupMessage.java | 2 +- .../envoy/server/data/PersistenceManager.java | 2 +- .../java/envoy/server/data/ServerConfig.java | 2 +- .../src/main/java/envoy/server/data/User.java | 2 +- .../envoy/server/net/ConnectionManager.java | 2 +- .../server/net/ObjectMessageProcessor.java | 2 +- .../envoy/server/net/ObjectMessageReader.java | 2 +- .../envoy/server/net/ObjectWriteProxy.java | 2 +- .../processors/ContactOperationProcessor.java | 2 +- .../processors/GroupCreationProcessor.java | 2 +- .../processors/GroupMessageProcessor.java | 2 +- .../GroupMessageStatusChangeProcessor.java | 2 +- .../processors/GroupResizeProcessor.java | 2 +- .../IDGeneratorRequestProcessor.java | 2 +- .../server/processors/IsTypingProcessor.java | 2 +- .../processors/IssueProposalProcessor.java | 2 +- .../server/processors/MessageProcessor.java | 2 +- .../MessageStatusChangeProcessor.java | 2 +- .../processors/NameChangeProcessor.java | 2 +- .../PasswordChangeRequestProcessor.java | 2 +- .../processors/ProfilePicChangeProcessor.java | 2 +- .../processors/UserSearchProcessor.java | 2 +- .../processors/UserStatusChangeProcessor.java | 2 +- .../java/envoy/server/util/PasswordUtil.java | 2 +- .../java/envoy/server/util/VersionUtil.java | 2 +- 85 files changed, 123 insertions(+), 129 deletions(-) diff --git a/client/src/main/java/envoy/client/Main.java b/client/src/main/java/envoy/client/Main.java index 6119062..842e37d 100644 --- a/client/src/main/java/envoy/client/Main.java +++ b/client/src/main/java/envoy/client/Main.java @@ -17,7 +17,7 @@ import envoy.client.ui.Startup; * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ -public class Main { +public final class Main { private static final boolean debug = false; diff --git a/client/src/main/java/envoy/client/data/ClientConfig.java b/client/src/main/java/envoy/client/data/ClientConfig.java index 2b3da37..fa5181d 100644 --- a/client/src/main/java/envoy/client/data/ClientConfig.java +++ b/client/src/main/java/envoy/client/data/ClientConfig.java @@ -17,7 +17,7 @@ import envoy.data.Config; * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ -public class ClientConfig extends Config { +public final class ClientConfig extends Config { private static ClientConfig config; diff --git a/client/src/main/java/envoy/client/data/GroupChat.java b/client/src/main/java/envoy/client/data/GroupChat.java index 6592e8e..39f5bd7 100644 --- a/client/src/main/java/envoy/client/data/GroupChat.java +++ b/client/src/main/java/envoy/client/data/GroupChat.java @@ -17,11 +17,11 @@ import envoy.event.GroupMessageStatusChange; * Project: envoy-client
* File: GroupChat.java
* Created: 05.07.2020
- * + * * @author Maximilian Käfer * @since Envoy Client v0.1-beta */ -public class GroupChat extends Chat { +public final class GroupChat extends Chat { private final User sender; @@ -41,13 +41,10 @@ public class GroupChat extends Chat { public void read(WriteProxy writeProxy) throws IOException { for (int i = messages.size() - 1; i >= 0; --i) { final GroupMessage gmsg = (GroupMessage) messages.get(i); - if (gmsg.getSenderID() != sender.getID()) { - if (gmsg.getMemberStatuses().get(sender.getID()) == MessageStatus.READ) break; - else { - gmsg.getMemberStatuses().replace(sender.getID(), MessageStatus.READ); - writeProxy - .writeMessageStatusChange(new GroupMessageStatusChange(gmsg.getID(), MessageStatus.READ, Instant.now(), sender.getID())); - } + if (gmsg.getSenderID() != sender.getID()) if (gmsg.getMemberStatuses().get(sender.getID()) == MessageStatus.READ) break; + else { + gmsg.getMemberStatuses().replace(sender.getID(), MessageStatus.READ); + writeProxy.writeMessageStatusChange(new GroupMessageStatusChange(gmsg.getID(), MessageStatus.READ, Instant.now(), sender.getID())); } } unreadAmount = 0; diff --git a/client/src/main/java/envoy/client/data/Settings.java b/client/src/main/java/envoy/client/data/Settings.java index 07bb354..1191c7d 100644 --- a/client/src/main/java/envoy/client/data/Settings.java +++ b/client/src/main/java/envoy/client/data/Settings.java @@ -22,7 +22,7 @@ import envoy.util.SerializationUtils; * @author Kai S. K. Engelbart * @since Envoy Client v0.2-alpha */ -public class Settings { +public final class Settings { // Actual settings accessible by the rest of the application private Map> items; @@ -139,7 +139,9 @@ public class Settings { * before * @since Envoy Client v0.2-beta */ - public void setDownloadSavedWithoutAsking(boolean autosaveDownload) { ((SettingsItem) items.get("autoSaveDownloads")).set(autosaveDownload); } + public void setDownloadSavedWithoutAsking(boolean autosaveDownload) { + ((SettingsItem) items.get("autoSaveDownloads")).set(autosaveDownload); + } /** * @return the path where downloads should be saved diff --git a/client/src/main/java/envoy/client/data/SettingsItem.java b/client/src/main/java/envoy/client/data/SettingsItem.java index d74e222..9261242 100644 --- a/client/src/main/java/envoy/client/data/SettingsItem.java +++ b/client/src/main/java/envoy/client/data/SettingsItem.java @@ -17,7 +17,7 @@ import javax.swing.JComponent; * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha */ -public class SettingsItem implements Serializable { +public final class SettingsItem implements Serializable { private T value; private String userFriendlyName, description; diff --git a/client/src/main/java/envoy/client/data/commands/SystemCommand.java b/client/src/main/java/envoy/client/data/commands/SystemCommand.java index 3f1a9a5..be13c83 100644 --- a/client/src/main/java/envoy/client/data/commands/SystemCommand.java +++ b/client/src/main/java/envoy/client/data/commands/SystemCommand.java @@ -24,7 +24,7 @@ import java.util.function.Supplier; * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public class SystemCommand implements OnCall { +public final class SystemCommand implements OnCall { protected int relevance; diff --git a/client/src/main/java/envoy/client/data/commands/SystemCommandBuilder.java b/client/src/main/java/envoy/client/data/commands/SystemCommandBuilder.java index fde7ba2..4d996f5 100644 --- a/client/src/main/java/envoy/client/data/commands/SystemCommandBuilder.java +++ b/client/src/main/java/envoy/client/data/commands/SystemCommandBuilder.java @@ -14,7 +14,7 @@ import java.util.function.Consumer; * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public class SystemCommandBuilder { +public final class SystemCommandBuilder { private int numberOfArguments; private Consumer> action; diff --git a/client/src/main/java/envoy/client/event/MessageCreationEvent.java b/client/src/main/java/envoy/client/event/MessageCreationEvent.java index 3238423..b9a4556 100644 --- a/client/src/main/java/envoy/client/event/MessageCreationEvent.java +++ b/client/src/main/java/envoy/client/event/MessageCreationEvent.java @@ -11,7 +11,7 @@ import envoy.event.Event; * @author Kai S. K. Engelbart * @since Envoy Client v0.2-alpha */ -public class MessageCreationEvent extends Event { +public final class MessageCreationEvent extends Event { private static final long serialVersionUID = 0L; diff --git a/client/src/main/java/envoy/client/event/MessageModificationEvent.java b/client/src/main/java/envoy/client/event/MessageModificationEvent.java index b2f114a..5f1c6f0 100644 --- a/client/src/main/java/envoy/client/event/MessageModificationEvent.java +++ b/client/src/main/java/envoy/client/event/MessageModificationEvent.java @@ -11,7 +11,7 @@ import envoy.event.Event; * @author Kai S. K. Engelbart * @since Envoy Client v0.2-alpha */ -public class MessageModificationEvent extends Event { +public final class MessageModificationEvent extends Event { private static final long serialVersionUID = 0L; diff --git a/client/src/main/java/envoy/client/event/SendEvent.java b/client/src/main/java/envoy/client/event/SendEvent.java index 8ea650b..f93e1d6 100644 --- a/client/src/main/java/envoy/client/event/SendEvent.java +++ b/client/src/main/java/envoy/client/event/SendEvent.java @@ -10,7 +10,7 @@ import envoy.event.Event; * @author: Maximilian Käfer * @since Envoy Client v0.3-alpha */ -public class SendEvent extends Event> { +public final class SendEvent extends Event> { private static final long serialVersionUID = 0L; diff --git a/client/src/main/java/envoy/client/event/ThemeChangeEvent.java b/client/src/main/java/envoy/client/event/ThemeChangeEvent.java index 572476b..1572b7a 100644 --- a/client/src/main/java/envoy/client/event/ThemeChangeEvent.java +++ b/client/src/main/java/envoy/client/event/ThemeChangeEvent.java @@ -10,7 +10,7 @@ import envoy.event.Event; * @author Kai S. K. Engelbart * @since Envoy Client v0.2-alpha */ -public class ThemeChangeEvent extends Event { +public final class ThemeChangeEvent extends Event { private static final long serialVersionUID = 0L; diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index 15e3c01..9c9a9c4 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -29,7 +29,7 @@ import envoy.util.SerializationUtils; * @author Leon Hofmeister * @since Envoy Client v0.1-alpha */ -public class Client implements Closeable { +public final class Client implements Closeable { // Connection handling private Socket socket; diff --git a/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java b/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java index ce3dc73..6f70ad6 100644 --- a/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java +++ b/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java @@ -12,14 +12,14 @@ import envoy.util.EnvoyLog; * Project: envoy-client
* File: GroupMessageStatusChangePocessor.java
* Created: 03.07.2020
- * + * * @author Maximilian Käfer * @since Envoy Client v0.1-beta */ -public class GroupMessageStatusChangeProcessor implements Consumer { +public final class GroupMessageStatusChangeProcessor implements Consumer { private static final Logger logger = EnvoyLog.getLogger(GroupMessageStatusChangeProcessor.class); - + @Override public void accept(GroupMessageStatusChange evt) { if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.warning("Received invalid group message status change " + evt); diff --git a/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java b/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java index 106cda4..d983012 100644 --- a/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java +++ b/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java @@ -16,7 +16,7 @@ import envoy.util.EnvoyLog; * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha */ -public class MessageStatusChangeProcessor implements Consumer { +public final class MessageStatusChangeProcessor implements Consumer { private static final Logger logger = EnvoyLog.getLogger(MessageStatusChangeProcessor.class); diff --git a/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java b/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java index 877d0f0..215c031 100644 --- a/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java +++ b/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java @@ -13,11 +13,11 @@ import envoy.util.EnvoyLog; * Project: envoy-client
* File: ReceivedGroupMessageProcessor.java
* Created: 13.06.2020
- * + * * @author Maximilian Käfer * @since Envoy Client v0.1-beta */ -public class ReceivedGroupMessageProcessor implements Consumer { +public final class ReceivedGroupMessageProcessor implements Consumer { private static final Logger logger = EnvoyLog.getLogger(ReceivedGroupMessageProcessor.class); diff --git a/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java b/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java index 84aa7dc..9cb6957 100644 --- a/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java +++ b/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java @@ -15,7 +15,7 @@ import envoy.event.EventBus; * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha */ -public class ReceivedMessageProcessor implements Consumer { +public final class ReceivedMessageProcessor implements Consumer { @Override public void accept(Message message) { diff --git a/client/src/main/java/envoy/client/net/Receiver.java b/client/src/main/java/envoy/client/net/Receiver.java index acbfeb5..dbc5220 100644 --- a/client/src/main/java/envoy/client/net/Receiver.java +++ b/client/src/main/java/envoy/client/net/Receiver.java @@ -22,7 +22,7 @@ import envoy.util.SerializationUtils; * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha */ -public class Receiver extends Thread { +public final class Receiver extends Thread { private boolean isAlive = true; diff --git a/client/src/main/java/envoy/client/net/WriteProxy.java b/client/src/main/java/envoy/client/net/WriteProxy.java index 0eccf6a..06b72e2 100644 --- a/client/src/main/java/envoy/client/net/WriteProxy.java +++ b/client/src/main/java/envoy/client/net/WriteProxy.java @@ -22,7 +22,7 @@ import envoy.util.EnvoyLog; * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha */ -public class WriteProxy { +public final class WriteProxy { private final Client client; private final LocalDB localDB; @@ -68,9 +68,7 @@ public class WriteProxy { * * @since Envoy Client v0.3-alpha */ - public void flushCache() { - localDB.getCacheMap().getMap().values().forEach(Cache::relay); - } + public void flushCache() { localDB.getCacheMap().getMap().values().forEach(Cache::relay); } /** * Delivers a message to the server if online. Otherwise the message is cached diff --git a/client/src/main/java/envoy/client/ui/ClearableTextField.java b/client/src/main/java/envoy/client/ui/ClearableTextField.java index fbe6926..9568629 100644 --- a/client/src/main/java/envoy/client/ui/ClearableTextField.java +++ b/client/src/main/java/envoy/client/ui/ClearableTextField.java @@ -22,7 +22,7 @@ import javafx.scene.layout.GridPane; * @author Leon Hofmeister * @since Envoy Client v0.1-beta */ -public class ClearableTextField extends GridPane { +public final class ClearableTextField extends GridPane { private final TextField textField; @@ -88,82 +88,82 @@ public class ClearableTextField extends GridPane { * @see javafx.scene.control.TextInputControl#promptTextProperty() * @since Envoy Client v0.1-beta */ - public final StringProperty promptTextProperty() { return textField.promptTextProperty(); } + public StringProperty promptTextProperty() { return textField.promptTextProperty(); } /** * @return the current prompt text * @see javafx.scene.control.TextInputControl#getPromptText() * @since Envoy Client v0.1-beta */ - public final String getPromptText() { return textField.getPromptText(); } + public String getPromptText() { return textField.getPromptText(); } /** * @param value the prompt text to display * @see javafx.scene.control.TextInputControl#setPromptText(java.lang.String) * @since Envoy Client v0.1-beta */ - public final void setPromptText(String value) { textField.setPromptText(value); } + public void setPromptText(String value) { textField.setPromptText(value); } /** * @return the current property of the tooltip * @see javafx.scene.control.Control#tooltipProperty() * @since Envoy Client v0.1-beta */ - public final ObjectProperty tooltipProperty() { return textField.tooltipProperty(); } + public ObjectProperty tooltipProperty() { return textField.tooltipProperty(); } /** * @param value the new tooltip * @see javafx.scene.control.Control#setTooltip(javafx.scene.control.Tooltip) * @since Envoy Client v0.1-beta */ - public final void setTooltip(Tooltip value) { textField.setTooltip(value); } + public void setTooltip(Tooltip value) { textField.setTooltip(value); } /** * @return the current tooltip * @see javafx.scene.control.Control#getTooltip() * @since Envoy Client v0.1-beta */ - public final Tooltip getTooltip() { return textField.getTooltip(); } + public Tooltip getTooltip() { return textField.getTooltip(); } /** * @return the current property of the context menu * @see javafx.scene.control.Control#contextMenuProperty() * @since Envoy Client v0.1-beta */ - public final ObjectProperty contextMenuProperty() { return textField.contextMenuProperty(); } + public ObjectProperty contextMenuProperty() { return textField.contextMenuProperty(); } /** * @param value the new context menu * @see javafx.scene.control.Control#setContextMenu(javafx.scene.control.ContextMenu) * @since Envoy Client v0.1-beta */ - public final void setContextMenu(ContextMenu value) { textField.setContextMenu(value); } + public void setContextMenu(ContextMenu value) { textField.setContextMenu(value); } /** * @return the current context menu * @see javafx.scene.control.Control#getContextMenu() * @since Envoy Client v0.1-beta */ - public final ContextMenu getContextMenu() { return textField.getContextMenu(); } + public ContextMenu getContextMenu() { return textField.getContextMenu(); } /** * @param value whether this ClearableTextField should be editable * @see javafx.scene.control.TextInputControl#setEditable(boolean) * @since Envoy Client v0.1-beta */ - public final void setEditable(boolean value) { textField.setEditable(value); } + public void setEditable(boolean value) { textField.setEditable(value); } /** * @return the current property whether this ClearableTextField is editable * @see javafx.scene.control.TextInputControl#editableProperty() * @since Envoy Client v0.1-beta */ - public final BooleanProperty editableProperty() { return textField.editableProperty(); } + public BooleanProperty editableProperty() { return textField.editableProperty(); } /** * @return whether this {@code ClearableTextField} is editable * @see javafx.scene.control.TextInputControl#isEditable() * @since Envoy Client v0.1-beta */ - public final boolean isEditable() { return textField.isEditable(); } + public boolean isEditable() { return textField.isEditable(); } } diff --git a/client/src/main/java/envoy/client/ui/IconUtil.java b/client/src/main/java/envoy/client/ui/IconUtil.java index f95d1a6..2da4d35 100644 --- a/client/src/main/java/envoy/client/ui/IconUtil.java +++ b/client/src/main/java/envoy/client/ui/IconUtil.java @@ -24,7 +24,7 @@ import envoy.util.EnvoyLog; * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ -public class IconUtil { +public final class IconUtil { private IconUtil() {} @@ -160,7 +160,7 @@ public class IconUtil { BufferedImage image = null; try { image = ImageIO.read(IconUtil.class.getResource(path)); - } catch (IOException e) { + } catch (final IOException e) { EnvoyLog.getLogger(IconUtil.class).log(Level.WARNING, String.format("Could not load image at path %s: ", path), e); } return image; diff --git a/client/src/main/java/envoy/client/ui/StatusTrayIcon.java b/client/src/main/java/envoy/client/ui/StatusTrayIcon.java index 10c5300..6d51955 100644 --- a/client/src/main/java/envoy/client/ui/StatusTrayIcon.java +++ b/client/src/main/java/envoy/client/ui/StatusTrayIcon.java @@ -18,7 +18,7 @@ import envoy.event.EventBus; * @author Kai S. K. Engelbart * @since Envoy Client v0.2-alpha */ -public class StatusTrayIcon { +public final class StatusTrayIcon { /** * The {@link TrayIcon} provided by the System Tray API for controlling the @@ -85,12 +85,12 @@ public class StatusTrayIcon { public void show() { try { SystemTray.getSystemTray().add(trayIcon); - } catch (AWTException e) {} + } catch (final AWTException e) {} } /** * Removes the icon from the system tray. - * + * * @since Envoy Client v0.2-beta */ public void hide() { SystemTray.getSystemTray().remove(trayIcon); } diff --git a/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index 3e6071a..7258f8b 100644 --- a/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -42,7 +42,7 @@ import envoy.util.EnvoyLog; * @author Leon Hofmeister * @since Envoy Client v0.1-beta */ -public class ContactSearchScene { +public final class ContactSearchScene { @FXML private ClearableTextField searchBar; diff --git a/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java b/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java index 71c7dd4..6b16d2e 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java @@ -39,7 +39,7 @@ import envoy.util.Bounds; * @author Maximilian Käfer * @since Envoy Client v0.1-beta */ -public class GroupCreationScene { +public final class GroupCreationScene { @FXML private Button createButton; diff --git a/client/src/main/java/envoy/client/ui/controller/SettingsScene.java b/client/src/main/java/envoy/client/ui/controller/SettingsScene.java index b8802fd..03c1048 100644 --- a/client/src/main/java/envoy/client/ui/controller/SettingsScene.java +++ b/client/src/main/java/envoy/client/ui/controller/SettingsScene.java @@ -18,7 +18,7 @@ import envoy.client.ui.settings.*; * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ -public class SettingsScene { +public final class SettingsScene { @FXML private ListView settingsList; diff --git a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java b/client/src/main/java/envoy/client/ui/listcell/ChatControl.java index 8e2a698..027527b 100644 --- a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java +++ b/client/src/main/java/envoy/client/ui/listcell/ChatControl.java @@ -23,7 +23,7 @@ import envoy.data.Group; * @author Leon Hofmeister * @since Envoy Client v0.1-beta */ -public class ChatControl extends HBox { +public final class ChatControl extends HBox { /** * @param chat the chat to display @@ -36,7 +36,7 @@ public class ChatControl extends HBox { ImageView contactProfilePic; if (chat.getRecipient() instanceof Group) contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("group_icon", 32)); else contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("user_icon", 32)); - Rectangle clip = new Rectangle(); + final var clip = new Rectangle(); clip.setWidth(32); clip.setHeight(32); clip.setArcHeight(32); @@ -44,7 +44,7 @@ public class ChatControl extends HBox { contactProfilePic.setClip(clip); getChildren().add(contactProfilePic); // spacing - Region leftSpacing = new Region(); + final var leftSpacing = new Region(); leftSpacing.setPrefSize(8, 0); leftSpacing.setMinSize(8, 0); leftSpacing.setMaxSize(8, 0); diff --git a/client/src/main/java/envoy/client/ui/listcell/ContactControl.java b/client/src/main/java/envoy/client/ui/listcell/ContactControl.java index eb4a483..99415cb 100644 --- a/client/src/main/java/envoy/client/ui/listcell/ContactControl.java +++ b/client/src/main/java/envoy/client/ui/listcell/ContactControl.java @@ -18,7 +18,7 @@ import envoy.data.User; * @author Kai S. K. Engelbart * @since Envoy Client v0.2-beta */ -public class ContactControl extends VBox { +public final class ContactControl extends VBox { /** * @param contact the contact to display @@ -36,9 +36,7 @@ public class ContactControl extends VBox { final var statusLabel = new Label(status); statusLabel.getStyleClass().add(status.toLowerCase()); getChildren().add(statusLabel); - } else { - getChildren().add(new Label(contact.getContacts().size() + " members")); - } + } else getChildren().add(new Label(contact.getContacts().size() + " members")); getStyleClass().add("listElement"); } } diff --git a/client/src/main/java/envoy/client/ui/listcell/MessageControl.java b/client/src/main/java/envoy/client/ui/listcell/MessageControl.java index 9b66c6c..95676ea 100644 --- a/client/src/main/java/envoy/client/ui/listcell/MessageControl.java +++ b/client/src/main/java/envoy/client/ui/listcell/MessageControl.java @@ -24,7 +24,6 @@ import envoy.client.data.Settings; import envoy.client.ui.AudioControl; import envoy.client.ui.IconUtil; import envoy.client.ui.SceneContext; - import envoy.data.GroupMessage; import envoy.data.Message; import envoy.data.Message.MessageStatus; @@ -42,7 +41,7 @@ import envoy.util.EnvoyLog; * @author Maximilian Käfer * @since Envoy Client v0.1-beta */ -public class MessageControl extends Label { +public final class MessageControl extends Label { private boolean ownMessage; @@ -179,7 +178,7 @@ public class MessageControl extends Label { } /** - * @param localDB the localDB used by the current user + * @param localDB the localDB used by the current user * @since Envoy Client v0.2-beta */ public static void setLocalDB(LocalDB localDB) { MessageControl.localDB = localDB; } diff --git a/client/src/main/java/envoy/client/ui/settings/BugReportPane.java b/client/src/main/java/envoy/client/ui/settings/BugReportPane.java index 6a3ca59..211d8d8 100644 --- a/client/src/main/java/envoy/client/ui/settings/BugReportPane.java +++ b/client/src/main/java/envoy/client/ui/settings/BugReportPane.java @@ -21,7 +21,7 @@ import envoy.event.IssueProposal; * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public class BugReportPane extends OnlyIfOnlineSettingsPane { +public final class BugReportPane extends OnlyIfOnlineSettingsPane { private final Label titleLabel = new Label("Suggest a title for the bug:"); private final TextField titleTextField = new TextField(); diff --git a/client/src/main/java/envoy/client/ui/settings/DownloadSettingsPane.java b/client/src/main/java/envoy/client/ui/settings/DownloadSettingsPane.java index cce597e..fe358c1 100644 --- a/client/src/main/java/envoy/client/ui/settings/DownloadSettingsPane.java +++ b/client/src/main/java/envoy/client/ui/settings/DownloadSettingsPane.java @@ -17,7 +17,7 @@ import envoy.client.ui.SceneContext; * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public class DownloadSettingsPane extends SettingsPane { +public final class DownloadSettingsPane extends SettingsPane { /** * Constructs a new {@code DownloadSettingsPane}. diff --git a/client/src/main/java/envoy/client/ui/settings/GeneralSettingsPane.java b/client/src/main/java/envoy/client/ui/settings/GeneralSettingsPane.java index 36755a9..bf48b5f 100644 --- a/client/src/main/java/envoy/client/ui/settings/GeneralSettingsPane.java +++ b/client/src/main/java/envoy/client/ui/settings/GeneralSettingsPane.java @@ -16,7 +16,7 @@ import envoy.event.EventBus; * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ -public class GeneralSettingsPane extends SettingsPane { +public final class GeneralSettingsPane extends SettingsPane { /** * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java b/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java index 098abac..d752c43 100644 --- a/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java +++ b/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java @@ -35,7 +35,7 @@ import envoy.util.EnvoyLog; * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public class UserSettingsPane extends OnlyIfOnlineSettingsPane { +public final class UserSettingsPane extends OnlyIfOnlineSettingsPane { private boolean profilePicChanged, usernameChanged, validPassword; private byte[] currentImageBytes; diff --git a/client/src/main/java/envoy/client/util/IssueUtil.java b/client/src/main/java/envoy/client/util/IssueUtil.java index c4f3e6e..6c6e165 100644 --- a/client/src/main/java/envoy/client/util/IssueUtil.java +++ b/client/src/main/java/envoy/client/util/IssueUtil.java @@ -10,7 +10,7 @@ package envoy.client.util; * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public class IssueUtil { +public final class IssueUtil { /** * diff --git a/client/src/main/java/envoy/client/util/ReflectionUtil.java b/client/src/main/java/envoy/client/util/ReflectionUtil.java index 92c243a..abdfd51 100644 --- a/client/src/main/java/envoy/client/util/ReflectionUtil.java +++ b/client/src/main/java/envoy/client/util/ReflectionUtil.java @@ -15,7 +15,7 @@ import javafx.scene.Node; * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public class ReflectionUtil { +public final class ReflectionUtil { private ReflectionUtil() {} diff --git a/common/src/main/java/envoy/data/Attachment.java b/common/src/main/java/envoy/data/Attachment.java index e231a76..292284a 100644 --- a/common/src/main/java/envoy/data/Attachment.java +++ b/common/src/main/java/envoy/data/Attachment.java @@ -14,7 +14,7 @@ import java.io.Serializable; * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ -public class Attachment implements Serializable { +public final class Attachment implements Serializable { /** * Defines the type of the attachment. diff --git a/common/src/main/java/envoy/data/ConfigItem.java b/common/src/main/java/envoy/data/ConfigItem.java index 9ed1462..91113ca 100644 --- a/common/src/main/java/envoy/data/ConfigItem.java +++ b/common/src/main/java/envoy/data/ConfigItem.java @@ -14,7 +14,7 @@ import java.util.function.Function; * @param the type of the config item's value * @since Envoy Common v0.1-beta */ -public class ConfigItem { +public final class ConfigItem { private final String commandLong, commandShort; private final Function parseFunction; diff --git a/common/src/main/java/envoy/data/IDGenerator.java b/common/src/main/java/envoy/data/IDGenerator.java index 91681e0..45d6966 100644 --- a/common/src/main/java/envoy/data/IDGenerator.java +++ b/common/src/main/java/envoy/data/IDGenerator.java @@ -12,7 +12,7 @@ import java.io.Serializable; * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ -public class IDGenerator implements Serializable { +public final class IDGenerator implements Serializable { private final long end; private long current; diff --git a/common/src/main/java/envoy/data/MessageBuilder.java b/common/src/main/java/envoy/data/MessageBuilder.java index 82df03d..2cddc6a 100644 --- a/common/src/main/java/envoy/data/MessageBuilder.java +++ b/common/src/main/java/envoy/data/MessageBuilder.java @@ -16,13 +16,13 @@ import envoy.data.Message.MessageStatus; * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ -public class MessageBuilder { +public final class MessageBuilder { // Mandatory properties without default values private final long senderID, recipientID; // Properties with default values - private long id; + private final long id; private Instant creationDate, receivedDate, readDate; private String text; private Attachment attachment; @@ -69,11 +69,11 @@ public class MessageBuilder { */ public MessageBuilder(Message msg, long recipientID, IDGenerator iDGenerator) { this(msg.getRecipientID(), recipientID, iDGenerator.next()); - this.attachment = msg.getAttachment(); - this.creationDate = Instant.now(); - this.forwarded = true; - this.text = msg.getText(); - this.status = MessageStatus.WAITING; + attachment = msg.getAttachment(); + creationDate = Instant.now(); + forwarded = true; + text = msg.getText(); + status = MessageStatus.WAITING; } /** @@ -128,7 +128,7 @@ public class MessageBuilder { * @since Envoy Common v0.2-alpha */ public GroupMessage buildGroupMessage(Group group) { - var memberStatuses = new HashMap(); + final var memberStatuses = new HashMap(); group.getContacts().forEach(user -> memberStatuses.put(user.getID(), MessageStatus.WAITING)); return buildGroupMessage(group, memberStatuses); } diff --git a/common/src/main/java/envoy/event/EventBus.java b/common/src/main/java/envoy/event/EventBus.java index 21e5f2c..51fb963 100644 --- a/common/src/main/java/envoy/event/EventBus.java +++ b/common/src/main/java/envoy/event/EventBus.java @@ -17,7 +17,7 @@ import java.util.function.Consumer; * @author Kai S. K. Engelbart * @since Envoy v0.2-alpha */ -public class EventBus { +public final class EventBus { /** * Contains all event handler instances registered at this event bus as values diff --git a/common/src/main/java/envoy/event/GroupCreation.java b/common/src/main/java/envoy/event/GroupCreation.java index b568081..e7a8a2c 100644 --- a/common/src/main/java/envoy/event/GroupCreation.java +++ b/common/src/main/java/envoy/event/GroupCreation.java @@ -15,7 +15,7 @@ import envoy.data.User; * @author Leon Hofmeister * @since Envoy Common v0.1-beta */ -public class GroupCreation extends Event { +public final class GroupCreation extends Event { private final Set initialMemberIDs; diff --git a/common/src/main/java/envoy/event/GroupMessageStatusChange.java b/common/src/main/java/envoy/event/GroupMessageStatusChange.java index 6bf4626..50f6ae3 100644 --- a/common/src/main/java/envoy/event/GroupMessageStatusChange.java +++ b/common/src/main/java/envoy/event/GroupMessageStatusChange.java @@ -13,7 +13,7 @@ import envoy.data.Message.MessageStatus; * @author Maximilian Käfer * @since Envoy Common v0.1-beta */ -public class GroupMessageStatusChange extends MessageStatusChange { +public final class GroupMessageStatusChange extends MessageStatusChange { private final long memberID; diff --git a/common/src/main/java/envoy/event/GroupResize.java b/common/src/main/java/envoy/event/GroupResize.java index 112229b..6aec843 100644 --- a/common/src/main/java/envoy/event/GroupResize.java +++ b/common/src/main/java/envoy/event/GroupResize.java @@ -17,7 +17,7 @@ import envoy.data.User; * @author Leon Hofmeister * @since Envoy Common v0.1-beta */ -public class GroupResize extends Event { +public final class GroupResize extends Event { private final long groupID; private final ElementOperation operation; diff --git a/common/src/main/java/envoy/event/HandshakeRejection.java b/common/src/main/java/envoy/event/HandshakeRejection.java index 3eeb1d9..4024772 100644 --- a/common/src/main/java/envoy/event/HandshakeRejection.java +++ b/common/src/main/java/envoy/event/HandshakeRejection.java @@ -11,7 +11,7 @@ package envoy.event; * @author Kai S. K. Engelbart * @since Envoy Common v0.3-alpha */ -public class HandshakeRejection extends Event { +public final class HandshakeRejection extends Event { /** * Select this value if a given password hash or user name was incorrect. diff --git a/common/src/main/java/envoy/event/IDGeneratorRequest.java b/common/src/main/java/envoy/event/IDGeneratorRequest.java index 2994c75..70b49bd 100644 --- a/common/src/main/java/envoy/event/IDGeneratorRequest.java +++ b/common/src/main/java/envoy/event/IDGeneratorRequest.java @@ -11,7 +11,7 @@ package envoy.event; * @author Kai S. K. Engelbart * @since Envoy Common v0.3-alpha */ -public class IDGeneratorRequest extends Event.Valueless { +public final class IDGeneratorRequest extends Event.Valueless { private static final long serialVersionUID = 1431107413883364583L; } diff --git a/common/src/main/java/envoy/event/IsTyping.java b/common/src/main/java/envoy/event/IsTyping.java index f720459..bb2d2c3 100644 --- a/common/src/main/java/envoy/event/IsTyping.java +++ b/common/src/main/java/envoy/event/IsTyping.java @@ -11,7 +11,7 @@ package envoy.event; * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public class IsTyping extends Event { +public final class IsTyping extends Event { private final long destinationID; diff --git a/common/src/main/java/envoy/event/IssueProposal.java b/common/src/main/java/envoy/event/IssueProposal.java index b032424..5150a25 100644 --- a/common/src/main/java/envoy/event/IssueProposal.java +++ b/common/src/main/java/envoy/event/IssueProposal.java @@ -11,7 +11,7 @@ package envoy.event; * @author Leon Hofmeister * @since Envoy Common v0.2-beta */ -public class IssueProposal extends Event { +public final class IssueProposal extends Event { private final String description; private final boolean bug; diff --git a/common/src/main/java/envoy/event/NameChange.java b/common/src/main/java/envoy/event/NameChange.java index ac3ae80..b4558a7 100644 --- a/common/src/main/java/envoy/event/NameChange.java +++ b/common/src/main/java/envoy/event/NameChange.java @@ -14,7 +14,7 @@ import envoy.data.Contact; * @author Leon Hofmeister * @since Envoy Common v0.1-beta */ -public class NameChange extends Event { +public final class NameChange extends Event { private final long id; diff --git a/common/src/main/java/envoy/event/PasswordChangeRequest.java b/common/src/main/java/envoy/event/PasswordChangeRequest.java index dd088df..0556e25 100644 --- a/common/src/main/java/envoy/event/PasswordChangeRequest.java +++ b/common/src/main/java/envoy/event/PasswordChangeRequest.java @@ -10,7 +10,7 @@ import envoy.data.Contact; * @author Leon Hofmeister * @since Envoy Common v0.2-beta */ -public class PasswordChangeRequest extends Event { +public final class PasswordChangeRequest extends Event { private final long id; private final String oldPassword; diff --git a/common/src/main/java/envoy/event/PasswordChangeResult.java b/common/src/main/java/envoy/event/PasswordChangeResult.java index 6252980..363e416 100644 --- a/common/src/main/java/envoy/event/PasswordChangeResult.java +++ b/common/src/main/java/envoy/event/PasswordChangeResult.java @@ -11,7 +11,7 @@ package envoy.event; * @author Leon Hofmeister * @since Envoy Common v0.2-beta */ -public class PasswordChangeResult extends Event { +public final class PasswordChangeResult extends Event { private static final long serialVersionUID = 1L; diff --git a/common/src/main/java/envoy/event/ProfilePicChange.java b/common/src/main/java/envoy/event/ProfilePicChange.java index c06c545..ceb2eff 100644 --- a/common/src/main/java/envoy/event/ProfilePicChange.java +++ b/common/src/main/java/envoy/event/ProfilePicChange.java @@ -8,7 +8,7 @@ package envoy.event; * @author Leon Hofmeister * @since Envoy Common v0.2-beta */ -public class ProfilePicChange extends Event { +public final class ProfilePicChange extends Event { private final long id; diff --git a/common/src/main/java/envoy/event/UserStatusChange.java b/common/src/main/java/envoy/event/UserStatusChange.java index ee2c79a..e8c1f94 100644 --- a/common/src/main/java/envoy/event/UserStatusChange.java +++ b/common/src/main/java/envoy/event/UserStatusChange.java @@ -11,7 +11,7 @@ import envoy.data.User.UserStatus; * @author Leon Hofmeister * @since Envoy Common v0.2-alpha */ -public class UserStatusChange extends Event { +public final class UserStatusChange extends Event { private final long id; diff --git a/common/src/main/java/envoy/event/contact/ContactOperation.java b/common/src/main/java/envoy/event/contact/ContactOperation.java index 7b84915..48427d5 100644 --- a/common/src/main/java/envoy/event/contact/ContactOperation.java +++ b/common/src/main/java/envoy/event/contact/ContactOperation.java @@ -14,7 +14,7 @@ import envoy.event.Event; * @author Maximilian Käfer * @since Envoy Common v0.2-alpha */ -public class ContactOperation extends Event { +public final class ContactOperation extends Event { private final ElementOperation operationType; diff --git a/common/src/main/java/envoy/event/contact/UserSearchRequest.java b/common/src/main/java/envoy/event/contact/UserSearchRequest.java index 51889d7..f615f0c 100644 --- a/common/src/main/java/envoy/event/contact/UserSearchRequest.java +++ b/common/src/main/java/envoy/event/contact/UserSearchRequest.java @@ -12,7 +12,7 @@ import envoy.event.Event; * @author Maximilian Käfer * @since Envoy Common v0.2-alpha */ -public class UserSearchRequest extends Event { +public final class UserSearchRequest extends Event { private static final long serialVersionUID = 0L; diff --git a/common/src/main/java/envoy/event/contact/UserSearchResult.java b/common/src/main/java/envoy/event/contact/UserSearchResult.java index a2aa4f7..86b4c09 100644 --- a/common/src/main/java/envoy/event/contact/UserSearchResult.java +++ b/common/src/main/java/envoy/event/contact/UserSearchResult.java @@ -15,7 +15,7 @@ import envoy.event.Event; * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ -public class UserSearchResult extends Event> { +public final class UserSearchResult extends Event> { private static final long serialVersionUID = 0L; diff --git a/common/src/main/java/envoy/exception/EnvoyException.java b/common/src/main/java/envoy/exception/EnvoyException.java index 650e1bb..0c02a52 100644 --- a/common/src/main/java/envoy/exception/EnvoyException.java +++ b/common/src/main/java/envoy/exception/EnvoyException.java @@ -8,7 +8,7 @@ package envoy.exception; * @author Kai S. K. Engelbart * @since Envoy v0.1-alpha */ -public class EnvoyException extends Exception { +public final class EnvoyException extends Exception { private static final long serialVersionUID = 2096147309395387479L; diff --git a/common/src/main/java/envoy/util/Bounds.java b/common/src/main/java/envoy/util/Bounds.java index 7540b88..c5575e0 100644 --- a/common/src/main/java/envoy/util/Bounds.java +++ b/common/src/main/java/envoy/util/Bounds.java @@ -12,7 +12,7 @@ import java.util.regex.Pattern; * @author Kai S. K. Engelbart * @since Envoy Common v0.1-beta */ -public class Bounds { +public final class Bounds { private Bounds() {} diff --git a/common/src/main/java/envoy/util/EnvoyLog.java b/common/src/main/java/envoy/util/EnvoyLog.java index c15c4d4..e28189e 100644 --- a/common/src/main/java/envoy/util/EnvoyLog.java +++ b/common/src/main/java/envoy/util/EnvoyLog.java @@ -20,7 +20,7 @@ import envoy.data.Config; * @author Kai S. K. Engelbart * @since Envoy Common v0.1-beta */ -public class EnvoyLog { +public final class EnvoyLog { private static FileHandler fileHandler; private static StreamHandler consoleHandler; diff --git a/common/src/main/java/envoy/util/SerializationUtils.java b/common/src/main/java/envoy/util/SerializationUtils.java index 558429c..54fca82 100644 --- a/common/src/main/java/envoy/util/SerializationUtils.java +++ b/common/src/main/java/envoy/util/SerializationUtils.java @@ -12,7 +12,7 @@ import java.io.*; * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ -public class SerializationUtils { +public final class SerializationUtils { private SerializationUtils() {} diff --git a/server/src/main/java/envoy/server/Startup.java b/server/src/main/java/envoy/server/Startup.java index 7232cba..4f3f0d1 100755 --- a/server/src/main/java/envoy/server/Startup.java +++ b/server/src/main/java/envoy/server/Startup.java @@ -24,7 +24,7 @@ import envoy.util.EnvoyLog; * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ -public class Startup { +public final class Startup { /** * Stores the configuration used for the whole server diff --git a/server/src/main/java/envoy/server/data/ConfigItem.java b/server/src/main/java/envoy/server/data/ConfigItem.java index 5f5d080..ba8a2fe 100755 --- a/server/src/main/java/envoy/server/data/ConfigItem.java +++ b/server/src/main/java/envoy/server/data/ConfigItem.java @@ -14,7 +14,7 @@ import javax.persistence.Table; */ @Entity @Table(name = "configuration") -public class ConfigItem { +public final class ConfigItem { @Id private String key; diff --git a/server/src/main/java/envoy/server/data/Group.java b/server/src/main/java/envoy/server/data/Group.java index bad4db9..232c13e 100644 --- a/server/src/main/java/envoy/server/data/Group.java +++ b/server/src/main/java/envoy/server/data/Group.java @@ -28,7 +28,7 @@ import javax.persistence.NamedQuery; query = "SELECT g FROM Group g WHERE g.creationDate > :lastSeen AND :user MEMBER OF g.contacts" ) }) -public class Group extends Contact { +public final class Group extends Contact { /** * Named query retrieving a group by name (parameter {@code :name}). diff --git a/server/src/main/java/envoy/server/data/GroupMessage.java b/server/src/main/java/envoy/server/data/GroupMessage.java index 45be27d..0bcd4e3 100644 --- a/server/src/main/java/envoy/server/data/GroupMessage.java +++ b/server/src/main/java/envoy/server/data/GroupMessage.java @@ -24,7 +24,7 @@ import envoy.data.Group; + "OR m.status = envoy.data.Message$MessageStatus.READ AND m.readDate > :lastSeen " + "OR m.lastStatusChangeDate > :lastSeen)" ) -public class GroupMessage extends Message { +public final class GroupMessage extends Message { /** * Named query retrieving pending group messages sent to a group containing a diff --git a/server/src/main/java/envoy/server/data/PersistenceManager.java b/server/src/main/java/envoy/server/data/PersistenceManager.java index 7ec3524..a9915e8 100755 --- a/server/src/main/java/envoy/server/data/PersistenceManager.java +++ b/server/src/main/java/envoy/server/data/PersistenceManager.java @@ -19,7 +19,7 @@ import envoy.server.net.ConnectionManager; * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-alpha */ -public class PersistenceManager { +public final class PersistenceManager { private final EntityManager entityManager = Persistence.createEntityManagerFactory("envoy").createEntityManager(); private final EntityTransaction transaction = entityManager.getTransaction(); diff --git a/server/src/main/java/envoy/server/data/ServerConfig.java b/server/src/main/java/envoy/server/data/ServerConfig.java index bb9a9ae..0a89792 100644 --- a/server/src/main/java/envoy/server/data/ServerConfig.java +++ b/server/src/main/java/envoy/server/data/ServerConfig.java @@ -12,7 +12,7 @@ import envoy.data.Config; * @author Leon Hofmeister * @since Envoy Server v0.2-beta */ -public class ServerConfig extends Config { +public final class ServerConfig extends Config { private static ServerConfig config; diff --git a/server/src/main/java/envoy/server/data/User.java b/server/src/main/java/envoy/server/data/User.java index b9e3d85..7ff3548 100755 --- a/server/src/main/java/envoy/server/data/User.java +++ b/server/src/main/java/envoy/server/data/User.java @@ -36,7 +36,7 @@ import envoy.data.User.UserStatus; query = "SELECT u FROM User u WHERE (lower(u.name) LIKE lower(:searchPhrase) AND u <> :context AND :context NOT MEMBER OF u.contacts)" ) }) -public class User extends Contact { +public final class User extends Contact { /** * Named query retrieving a user by name (parameter {@code :name}). diff --git a/server/src/main/java/envoy/server/net/ConnectionManager.java b/server/src/main/java/envoy/server/net/ConnectionManager.java index 99bc683..a43b357 100755 --- a/server/src/main/java/envoy/server/net/ConnectionManager.java +++ b/server/src/main/java/envoy/server/net/ConnectionManager.java @@ -19,7 +19,7 @@ import envoy.server.processors.UserStatusChangeProcessor; * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ -public class ConnectionManager implements ISocketIdListener { +public final class ConnectionManager implements ISocketIdListener { /** * Contains all socket IDs that have not yet performed a handshake / acquired diff --git a/server/src/main/java/envoy/server/net/ObjectMessageProcessor.java b/server/src/main/java/envoy/server/net/ObjectMessageProcessor.java index d75aa75..2e43079 100755 --- a/server/src/main/java/envoy/server/net/ObjectMessageProcessor.java +++ b/server/src/main/java/envoy/server/net/ObjectMessageProcessor.java @@ -25,7 +25,7 @@ import envoy.util.EnvoyLog; * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ -public class ObjectMessageProcessor implements IMessageProcessor { +public final class ObjectMessageProcessor implements IMessageProcessor { private final Set> processors; diff --git a/server/src/main/java/envoy/server/net/ObjectMessageReader.java b/server/src/main/java/envoy/server/net/ObjectMessageReader.java index 34c034b..ddd2dca 100755 --- a/server/src/main/java/envoy/server/net/ObjectMessageReader.java +++ b/server/src/main/java/envoy/server/net/ObjectMessageReader.java @@ -19,7 +19,7 @@ import envoy.util.SerializationUtils; * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ -public class ObjectMessageReader implements IMessageReader { +public final class ObjectMessageReader implements IMessageReader { private List completeMessages = new ArrayList<>(); private Message nextMessage; diff --git a/server/src/main/java/envoy/server/net/ObjectWriteProxy.java b/server/src/main/java/envoy/server/net/ObjectWriteProxy.java index 68c82bb..4e8229e 100755 --- a/server/src/main/java/envoy/server/net/ObjectWriteProxy.java +++ b/server/src/main/java/envoy/server/net/ObjectWriteProxy.java @@ -22,7 +22,7 @@ import envoy.util.SerializationUtils; * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ -public class ObjectWriteProxy { +public final class ObjectWriteProxy { private final WriteProxy writeProxy; diff --git a/server/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/server/src/main/java/envoy/server/processors/ContactOperationProcessor.java index 60952d3..ba4f240 100755 --- a/server/src/main/java/envoy/server/processors/ContactOperationProcessor.java +++ b/server/src/main/java/envoy/server/processors/ContactOperationProcessor.java @@ -17,7 +17,7 @@ import envoy.util.EnvoyLog; * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ -public class ContactOperationProcessor implements ObjectProcessor { +public final class ContactOperationProcessor implements ObjectProcessor { private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); private static final Logger logger = EnvoyLog.getLogger(ContactOperationProcessor.class); diff --git a/server/src/main/java/envoy/server/processors/GroupCreationProcessor.java b/server/src/main/java/envoy/server/processors/GroupCreationProcessor.java index 06a85a0..f00cd18 100644 --- a/server/src/main/java/envoy/server/processors/GroupCreationProcessor.java +++ b/server/src/main/java/envoy/server/processors/GroupCreationProcessor.java @@ -18,7 +18,7 @@ import envoy.server.net.ObjectWriteProxy; * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-beta */ -public class GroupCreationProcessor implements ObjectProcessor { +public final class GroupCreationProcessor implements ObjectProcessor { private final PersistenceManager persistenceManager = PersistenceManager.getInstance(); private final ConnectionManager connectionManager = ConnectionManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/GroupMessageProcessor.java b/server/src/main/java/envoy/server/processors/GroupMessageProcessor.java index 2099b76..5412595 100644 --- a/server/src/main/java/envoy/server/processors/GroupMessageProcessor.java +++ b/server/src/main/java/envoy/server/processors/GroupMessageProcessor.java @@ -23,7 +23,7 @@ import envoy.util.EnvoyLog; * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-beta */ -public class GroupMessageProcessor implements ObjectProcessor { +public final class GroupMessageProcessor implements ObjectProcessor { private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); private static final PersistenceManager persistenceManager = PersistenceManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java b/server/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java index e24902e..515639b 100644 --- a/server/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java @@ -24,7 +24,7 @@ import envoy.util.EnvoyLog; * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-beta */ -public class GroupMessageStatusChangeProcessor implements ObjectProcessor { +public final class GroupMessageStatusChangeProcessor implements ObjectProcessor { private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); private static final PersistenceManager persistenceManager = PersistenceManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/GroupResizeProcessor.java b/server/src/main/java/envoy/server/processors/GroupResizeProcessor.java index fede288..86ec875 100644 --- a/server/src/main/java/envoy/server/processors/GroupResizeProcessor.java +++ b/server/src/main/java/envoy/server/processors/GroupResizeProcessor.java @@ -14,7 +14,7 @@ import envoy.server.net.ObjectWriteProxy; * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-beta */ -public class GroupResizeProcessor implements ObjectProcessor { +public final class GroupResizeProcessor implements ObjectProcessor { private static final PersistenceManager persistenceManager = PersistenceManager.getInstance(); private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java b/server/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java index 73c7f11..edd6e7b 100755 --- a/server/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java +++ b/server/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java @@ -17,7 +17,7 @@ import envoy.server.net.ObjectWriteProxy; * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-alpha */ -public class IDGeneratorRequestProcessor implements ObjectProcessor { +public final class IDGeneratorRequestProcessor implements ObjectProcessor { private static final long ID_RANGE = 200; diff --git a/server/src/main/java/envoy/server/processors/IsTypingProcessor.java b/server/src/main/java/envoy/server/processors/IsTypingProcessor.java index bda22ee..a147ed1 100644 --- a/server/src/main/java/envoy/server/processors/IsTypingProcessor.java +++ b/server/src/main/java/envoy/server/processors/IsTypingProcessor.java @@ -18,7 +18,7 @@ import envoy.server.net.ObjectWriteProxy; * @author Leon Hofmeister * @since Envoy Server v0.2-beta */ -public class IsTypingProcessor implements ObjectProcessor { +public final class IsTypingProcessor implements ObjectProcessor { private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); private static final PersistenceManager persistenceManager = PersistenceManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java b/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java index 8aa639c..6f3dbbb 100644 --- a/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java +++ b/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java @@ -23,7 +23,7 @@ import envoy.util.EnvoyLog; * @author Leon Hofmeister * @since Envoy Server v0.2-beta */ -public class IssueProposalProcessor implements ObjectProcessor { +public final class IssueProposalProcessor implements ObjectProcessor { private static final Logger logger = EnvoyLog.getLogger(IssueProposalProcessor.class); diff --git a/server/src/main/java/envoy/server/processors/MessageProcessor.java b/server/src/main/java/envoy/server/processors/MessageProcessor.java index ae34581..cf5aea5 100755 --- a/server/src/main/java/envoy/server/processors/MessageProcessor.java +++ b/server/src/main/java/envoy/server/processors/MessageProcessor.java @@ -23,7 +23,7 @@ import envoy.util.EnvoyLog; * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-alpha */ -public class MessageProcessor implements ObjectProcessor { +public final class MessageProcessor implements ObjectProcessor { private static final PersistenceManager persistenceManager = PersistenceManager.getInstance(); private static final ConnectionManager connectionManager = ConnectionManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/server/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java index 507a83f..950f0c2 100755 --- a/server/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java @@ -19,7 +19,7 @@ import envoy.util.EnvoyLog; * @author Leon Hofmeister * @since Envoy Server Standalone v0.1-alpha */ -public class MessageStatusChangeProcessor implements ObjectProcessor { +public final class MessageStatusChangeProcessor implements ObjectProcessor { private final ConnectionManager connectionManager = ConnectionManager.getInstance(); private final PersistenceManager persistenceManager = PersistenceManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/NameChangeProcessor.java b/server/src/main/java/envoy/server/processors/NameChangeProcessor.java index 7e782f7..aa6897f 100644 --- a/server/src/main/java/envoy/server/processors/NameChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/NameChangeProcessor.java @@ -15,7 +15,7 @@ import envoy.server.net.ObjectWriteProxy; * @author Leon Hofmeister * @since Envoy Server Standalone v0.1-beta */ -public class NameChangeProcessor implements ObjectProcessor { +public final class NameChangeProcessor implements ObjectProcessor { private static final PersistenceManager persistenceManager = PersistenceManager.getInstance(); diff --git a/server/src/main/java/envoy/server/processors/PasswordChangeRequestProcessor.java b/server/src/main/java/envoy/server/processors/PasswordChangeRequestProcessor.java index 84ebc7a..4b811a8 100644 --- a/server/src/main/java/envoy/server/processors/PasswordChangeRequestProcessor.java +++ b/server/src/main/java/envoy/server/processors/PasswordChangeRequestProcessor.java @@ -18,7 +18,7 @@ import envoy.util.EnvoyLog; * @author Leon Hofmeister * @since Envoy Server v0.2-beta */ -public class PasswordChangeRequestProcessor implements ObjectProcessor { +public final class PasswordChangeRequestProcessor implements ObjectProcessor { @Override public void process(PasswordChangeRequest event, long socketID, ObjectWriteProxy writeProxy) throws IOException { diff --git a/server/src/main/java/envoy/server/processors/ProfilePicChangeProcessor.java b/server/src/main/java/envoy/server/processors/ProfilePicChangeProcessor.java index 10069a8..f777ed8 100644 --- a/server/src/main/java/envoy/server/processors/ProfilePicChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/ProfilePicChangeProcessor.java @@ -13,7 +13,7 @@ import envoy.server.net.ObjectWriteProxy; * @author Leon Hofmeister * @since Envoy Server v0.2-beta */ -public class ProfilePicChangeProcessor implements ObjectProcessor { +public final class ProfilePicChangeProcessor implements ObjectProcessor { @Override public void process(ProfilePicChange event, long socketID, ObjectWriteProxy writeProxy) throws IOException {} diff --git a/server/src/main/java/envoy/server/processors/UserSearchProcessor.java b/server/src/main/java/envoy/server/processors/UserSearchProcessor.java index 65679fb..3504217 100755 --- a/server/src/main/java/envoy/server/processors/UserSearchProcessor.java +++ b/server/src/main/java/envoy/server/processors/UserSearchProcessor.java @@ -20,7 +20,7 @@ import envoy.server.net.ObjectWriteProxy; * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-alpha */ -public class UserSearchProcessor implements ObjectProcessor { +public final class UserSearchProcessor implements ObjectProcessor { /** * Writes a list of contacts to the client containing all {@link Contact}s diff --git a/server/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java b/server/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java index 264f263..57a9b25 100755 --- a/server/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java @@ -19,7 +19,7 @@ import envoy.util.EnvoyLog; * @author Leon Hofmeister * @since Envoy Server Standalone v0.1-alpha */ -public class UserStatusChangeProcessor implements ObjectProcessor { +public final class UserStatusChangeProcessor implements ObjectProcessor { private static ObjectWriteProxy writeProxy; diff --git a/server/src/main/java/envoy/server/util/PasswordUtil.java b/server/src/main/java/envoy/server/util/PasswordUtil.java index 5d0ba7a..f3e3b3e 100644 --- a/server/src/main/java/envoy/server/util/PasswordUtil.java +++ b/server/src/main/java/envoy/server/util/PasswordUtil.java @@ -19,7 +19,7 @@ import javax.crypto.spec.PBEKeySpec; * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-beta */ -public class PasswordUtil { +public final class PasswordUtil { private static final int ITERATIONS = 1000; private static final int KEY_LENGTH = 64 * 8; diff --git a/server/src/main/java/envoy/server/util/VersionUtil.java b/server/src/main/java/envoy/server/util/VersionUtil.java index 8f623e1..2d50796 100644 --- a/server/src/main/java/envoy/server/util/VersionUtil.java +++ b/server/src/main/java/envoy/server/util/VersionUtil.java @@ -13,7 +13,7 @@ import java.util.regex.Pattern; * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-beta */ -public class VersionUtil { +public final class VersionUtil { /** * The minimal client version compatible with this server. From c784ebb787e7e68a465abf8b6af1fa48eafa0ff1 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 22 Aug 2020 18:14:26 +0200 Subject: [PATCH 3/4] Added option to disable attachments and groups on both client and server --- .../main/java/envoy/client/net/Client.java | 7 + .../main/java/envoy/client/net/Receiver.java | 2 +- .../envoy/client/ui/controller/ChatScene.java | 27 +++- .../ui/controller/ContactSearchScene.java | 9 +- .../ui/controller/GroupCreationScene.java | 22 ++- client/src/main/resources/fxml/ChatScene.fxml | 2 +- .../resources/fxml/ContactSearchScene.fxml | 2 +- .../java/envoy/event/GroupCreationResult.java | 25 +++ .../main/java/envoy/event/NoAttachments.java | 25 +++ .../main/java/envoy/server/data/Message.java | 3 +- .../java/envoy/server/data/ServerConfig.java | 14 ++ .../processors/GroupCreationProcessor.java | 10 +- .../processors/GroupMessageProcessor.java | 142 ++++++++++-------- .../server/processors/MessageProcessor.java | 10 +- server/src/main/resources/server.properties | 2 + 15 files changed, 219 insertions(+), 83 deletions(-) create mode 100644 common/src/main/java/envoy/event/GroupCreationResult.java create mode 100644 common/src/main/java/envoy/event/NoAttachments.java diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index 9c9a9c4..923f721 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -164,6 +164,13 @@ public final class Client implements Closeable { // Process ProfilePicChanges receiver.registerProcessor(ProfilePicChange.class, eventBus::dispatch); + // Process requests to not send anymore attachments as they will not be shown to + // other users + receiver.registerProcessor(NoAttachments.class, eventBus::dispatch); + + // Process group creation rejections - they have been disabled on the server + receiver.registerProcessor(GroupCreationResult.class, eventBus::dispatch); + // Send event eventBus.register(SendEvent.class, evt -> { try { diff --git a/client/src/main/java/envoy/client/net/Receiver.java b/client/src/main/java/envoy/client/net/Receiver.java index dbc5220..ce510cf 100644 --- a/client/src/main/java/envoy/client/net/Receiver.java +++ b/client/src/main/java/envoy/client/net/Receiver.java @@ -69,7 +69,7 @@ public final class Receiver extends Thread { // Server has stopped sending, i.e. because he went offline if (len == 0 && bytesRead == -1) { isAlive = false; - logger.log(Level.WARNING, "Lost connection to the server. Exiting receiver"); + logger.log(Level.INFO, "Lost connection to the server. Exiting receiver..."); continue; } logger.log(Level.WARNING, diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 173784f..fa788e4 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -87,6 +87,12 @@ public final class ChatScene implements Restorable { @FXML private Button rotateButton; + @FXML + private Button messageSearchButton; + + @FXML + private Button newGroupButton; + @FXML private TextArea messageTextArea; @@ -108,9 +114,6 @@ public final class ChatScene implements Restorable { @FXML private Label topBarStatusLabel; - @FXML - private Button messageSearchButton; - @FXML private ImageView clientProfilePic; @@ -129,7 +132,8 @@ public final class ChatScene implements Restorable { private AudioRecorder recorder; private boolean recording; private Attachment pendingAttachment; - private boolean postingPermanentlyDisabled; + + private boolean postingPermanentlyDisabled; private final SystemCommandsMap messageTextAreaCommands = new SystemCommandsMap(); @@ -237,6 +241,21 @@ public final class ChatScene implements Restorable { break; } }); + + // Disable attachment button if server says attachments will be filtered out + eventBus.register(NoAttachments.class, e -> { + Platform.runLater(() -> { + attachmentButton.setDisable(true); + voiceButton.setDisable(true); + final var alert = new Alert(AlertType.ERROR); + alert.setTitle("No attachments possible"); + alert.setHeaderText("Your current server does not support attachments."); + alert.setContentText("If this is unplanned, please contact your server administrator."); + alert.showAndWait(); + }); + }); + + eventBus.register(GroupCreationResult.class, e -> Platform.runLater(() -> { newGroupButton.setDisable(!e.get()); })); } /** diff --git a/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index 7258f8b..63f16b0 100644 --- a/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -6,10 +6,8 @@ import java.util.logging.Logger; import javafx.application.Platform; import javafx.fxml.FXML; -import javafx.scene.control.Alert; +import javafx.scene.control.*; import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.ButtonType; -import javafx.scene.control.ListView; import envoy.client.data.LocalDB; import envoy.client.event.SendEvent; @@ -20,6 +18,7 @@ import envoy.client.ui.listcell.ListCellFactory; import envoy.data.User; import envoy.event.ElementOperation; import envoy.event.EventBus; +import envoy.event.GroupCreationResult; import envoy.event.contact.ContactOperation; import envoy.event.contact.UserSearchRequest; import envoy.event.contact.UserSearchResult; @@ -50,6 +49,9 @@ public final class ContactSearchScene { @FXML private ListView userList; + @FXML + private Button newGroupButton; + private SceneContext sceneContext; private LocalDB localDB; @@ -86,6 +88,7 @@ public final class ContactSearchScene { eventBus.register(UserSearchResult.class, response -> Platform.runLater(() -> { userList.getItems().clear(); userList.getItems().addAll(response.get()); })); eventBus.register(ContactOperation.class, handler); + eventBus.register(GroupCreationResult.class, e -> Platform.runLater(() -> { newGroupButton.setDisable(!e.get()); })); } /** diff --git a/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java b/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java index 6b16d2e..da9e997 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationScene.java @@ -21,6 +21,7 @@ import envoy.data.Group; import envoy.data.User; import envoy.event.EventBus; import envoy.event.GroupCreation; +import envoy.event.GroupCreationResult; import envoy.util.Bounds; /** @@ -54,6 +55,8 @@ public final class GroupCreationScene { private LocalDB localDB; + private String groupName; + private static final EventBus eventBus = EventBus.getInstance(); @FXML @@ -61,6 +64,18 @@ public final class GroupCreationScene { userList.setCellFactory(new ListCellFactory<>(ContactControl::new)); userList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); groupNameField.setClearButtonListener(e -> { groupNameField.getTextField().clear(); createButton.setDisable(true); }); + eventBus.register(GroupCreationResult.class, e -> Platform.runLater(() -> { + if (e.get()) new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", groupName)).showAndWait(); + else { + createButton.setDisable(true); + final var alert = new Alert(AlertType.ERROR); + alert.setTitle("Groups are not allowed"); + alert.setHeaderText("Cannot create group as your current server disabled this feature"); + alert.setContentText("If this is unplanned, please contact your server administrator."); + alert.showAndWait(); + sceneContext.pop(); + } + })); } /** @@ -119,10 +134,7 @@ public final class GroupCreationScene { alert.setTitle("Create Group?"); alert.setHeaderText("Proceed?"); alert.showAndWait().filter(btn -> btn == ButtonType.OK).ifPresent(btn -> createGroup(name)); - } else { - new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", name)).showAndWait(); - createGroup(name); - } + } else createGroup(name); } /** @@ -133,9 +145,9 @@ public final class GroupCreationScene { * @since Envoy Client v0.1-beta */ private void createGroup(String name) { + groupName = name; eventBus.dispatch(new SendEvent( new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet())))); - sceneContext.pop(); } /** diff --git a/client/src/main/resources/fxml/ChatScene.fxml b/client/src/main/resources/fxml/ChatScene.fxml index 5bf8cd1..5b6bf77 100644 --- a/client/src/main/resources/fxml/ChatScene.fxml +++ b/client/src/main/resources/fxml/ChatScene.fxml @@ -62,7 +62,7 @@ -