diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index baa2503..07c0a27 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,14 +4,15 @@
-
+
-
-
-
-
-
+
+
+
+
+
+
@@ -28,6 +29,8 @@
+
+
@@ -62,43 +65,68 @@
- {
- "keyToString": {
- "Gradle.Build forms.executor": "Run",
- "Gradle.TestForm.testFunctions.executor": "Debug",
- "Gradle.TestForm.testRetrieveForm.executor": "Run",
- "RequestMappingsPanelOrder0": "0",
- "RequestMappingsPanelOrder1": "1",
- "RequestMappingsPanelWidth0": "75",
- "RequestMappingsPanelWidth1": "75",
- "RunOnceActivity.OpenProjectViewOnStart": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "Spring Boot.Main.executor": "Run",
- "Tomcat Server.Tomcat 10.1.17.executor": "Run",
- "git-widget-placeholder": "master",
- "ignore.virus.scanning.warn.message": "true",
- "kotlin-language-version-configured": "true",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "project.structure.last.edited": "Project",
- "project.structure.proportion": "0.0",
- "project.structure.side.proportion": "0.0",
- "run.code.analysis.last.selected.profile": "pProject Default",
- "settings.editor.selected.configurable": "preferences.lookFeel",
- "vue.rearranger.settings.migration": "true"
+
-
+}]]>
+
+
+
+
+
+
+
+
+
+
+
+ false
+ true
+ false
+ true
+
+
@@ -194,6 +222,7 @@
+
@@ -201,6 +230,7 @@
+
@@ -239,7 +269,7 @@
-
+
@@ -273,7 +303,15 @@
1705227608210
-
+
+
+ 1714319923708
+
+
+
+ 1714319923708
+
+
@@ -296,6 +334,7 @@
-
+
+
\ No newline at end of file
diff --git a/src/main/java/com/alttd/forms/Main.java b/src/main/java/com/alttd/forms/Main.java
index 0f6767b..aa296ac 100644
--- a/src/main/java/com/alttd/forms/Main.java
+++ b/src/main/java/com/alttd/forms/Main.java
@@ -10,9 +10,15 @@ import java.sql.SQLException;
@SpringBootApplication(exclude = ValidationAutoConfiguration.class)
public class Main {
+ private static String path;
+
public static void main(String[] args) throws SQLException {
+ path = args[0];
SpringApplication.run(Main.class, args);
- DatabaseConnection.initialize();
+ DatabaseConnection.initialize(args[0]);
}
+ public static String getConfigPath() {
+ return path;
+ }
}
diff --git a/src/main/java/com/alttd/forms/database/DatabaseConnection.java b/src/main/java/com/alttd/forms/database/DatabaseConnection.java
index cf5b392..0ff6efb 100644
--- a/src/main/java/com/alttd/forms/database/DatabaseConnection.java
+++ b/src/main/java/com/alttd/forms/database/DatabaseConnection.java
@@ -5,6 +5,7 @@ import com.alttd.forms.properties.PropertiesWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -26,6 +27,13 @@ public class DatabaseConnection {
Database.createTables();
}
+ public DatabaseConnection(String path) throws SQLException {
+ instance = this;
+ loadProperties(path);
+ instance.openConnection();
+ Database.createTables();
+ }
+
public static Connection getConnection() {
try {
instance.openConnection();
@@ -36,15 +44,21 @@ public class DatabaseConnection {
return instance.connection;
}
+ public static void initialize(String path) throws SQLException {
+ if (instance != null)
+ return;
+ instance = new DatabaseConnection(path);
+ }
+
public static void initialize() throws SQLException {
if (instance != null)
return;
instance = new DatabaseConnection();
}
- private void loadProperties() {
+ private void loadProperties(String path) {
String fileName = "database.properties";
- Optional optionalProperties = PropertiesLoader.loadProperties(fileName);
+ Optional optionalProperties = PropertiesLoader.loadProperties(path, fileName);
if (optionalProperties.isPresent()) {
properties = optionalProperties.get();
return;
@@ -58,7 +72,11 @@ public class DatabaseConnection {
properties.setProperty("user", "root");
properties.setProperty("password", "root");
properties.setProperty("parameters", "autoReconnect=true&useSSL=false");
- PropertiesWriter.writeProperties(properties, fileName);
+ PropertiesWriter.writeProperties(properties, path, fileName);
+ }
+
+ private void loadProperties() {
+ loadProperties("");
}
public void openConnection() throws SQLException {
diff --git a/src/main/java/com/alttd/forms/mail/MailSettings.java b/src/main/java/com/alttd/forms/mail/MailSettings.java
index d634926..f7efcc9 100644
--- a/src/main/java/com/alttd/forms/mail/MailSettings.java
+++ b/src/main/java/com/alttd/forms/mail/MailSettings.java
@@ -1,5 +1,6 @@
package com.alttd.forms.mail;
+import com.alttd.forms.Main;
import com.alttd.forms.properties.PropertiesLoader;
import com.alttd.forms.properties.PropertiesWriter;
@@ -20,8 +21,9 @@ public class MailSettings {
if (mailProperties != null)
return mailProperties;
+ String path = Main.getConfigPath();
String fileName = "mail_settings.properties";
- Optional properties = PropertiesLoader.loadProperties(fileName);
+ Optional properties = PropertiesLoader.loadProperties(path, fileName);
if (properties.isPresent()) {
mailProperties = properties.get();
return mailProperties;
@@ -33,7 +35,7 @@ public class MailSettings {
mailProperties.put("mail.smtp.auth", "true");
mailProperties.put("mail.smtp.socketFactory.port", "465");
mailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
- PropertiesWriter.writeProperties(mailProperties, fileName);
+ PropertiesWriter.writeProperties(mailProperties, path, fileName);
return mailProperties;
}
@@ -59,8 +61,10 @@ public class MailSettings {
return createPasswordAuthentication(accountDetails);
}
+ String path = Main.getConfigPath();
+
String fileName = "mail_account.properties";
- Optional properties = PropertiesLoader.loadProperties(fileName);
+ Optional properties = PropertiesLoader.loadProperties(path, fileName);
if (properties.isPresent()) {
accountDetails = properties.get();
return createPasswordAuthentication(accountDetails);
@@ -70,7 +74,7 @@ public class MailSettings {
accountDetails.put("username", "test@test.test");
accountDetails.put("password", "testpassword");
- PropertiesWriter.writeProperties(accountDetails, fileName);
+ PropertiesWriter.writeProperties(accountDetails, path, fileName);
return createPasswordAuthentication(accountDetails);
}
diff --git a/src/main/java/com/alttd/forms/properties/PropertiesLoader.java b/src/main/java/com/alttd/forms/properties/PropertiesLoader.java
index 14ee95d..123940a 100644
--- a/src/main/java/com/alttd/forms/properties/PropertiesLoader.java
+++ b/src/main/java/com/alttd/forms/properties/PropertiesLoader.java
@@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Path;
import java.util.Optional;
import java.util.Properties;
@@ -13,15 +15,21 @@ public class PropertiesLoader {
private static final Logger logger = LoggerFactory.getLogger(PropertiesLoader.class);
- public static Optional loadProperties(String fileName) {
+ public static Optional loadProperties(String path, String fileName) {
Properties prop = new Properties();
- Optional currentJarPath = JarPath.getCurrentJarDir();
- if (currentJarPath.isEmpty()) {
- logger.error("Unable to find jar path to load properties (" + fileName + ")");
- return Optional.empty();
+ File file;
+ if (path.isEmpty()) {
+ Optional currentJarPath = JarPath.getCurrentJarDir();
+ if (currentJarPath.isEmpty()) {
+ logger.error("Unable to find jar path to load properties (" + fileName + ")");
+ return Optional.empty();
+ }
+ file = new File(currentJarPath.get(), fileName);
+ } else {
+ file = Path.of(URI.create("file://" + path + File.separator + fileName)).toFile();
}
- File file = new File(currentJarPath.get(), fileName);
+
if (!file.exists()) {
logger.warn("Tried to load properties file that doesnt exists (" + fileName + ")");
return Optional.empty();
diff --git a/src/main/java/com/alttd/forms/properties/PropertiesWriter.java b/src/main/java/com/alttd/forms/properties/PropertiesWriter.java
index 72d7e16..102316d 100644
--- a/src/main/java/com/alttd/forms/properties/PropertiesWriter.java
+++ b/src/main/java/com/alttd/forms/properties/PropertiesWriter.java
@@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Path;
import java.util.Optional;
import java.util.Properties;
@@ -13,13 +15,19 @@ public class PropertiesWriter {
private static final Logger logger = LoggerFactory.getLogger(PropertiesWriter.class);
- public static void writeProperties(Properties prop, String fileName) {
- Optional currentJarPath = JarPath.getCurrentJarDir();
- if (currentJarPath.isEmpty()) {
- logger.error("Failed to get current jar directory");
- return;
+ public static void writeProperties(Properties prop, String path, String fileName) {
+ File file;
+ if (path.isEmpty()) {
+ Optional currentJarPath = JarPath.getCurrentJarDir();
+ if (currentJarPath.isEmpty()) {
+ logger.error("Unable to find jar path to write properties (" + fileName + ")");
+ return;
+ }
+ file = new File(currentJarPath.get(), fileName);
+ } else {
+ file = Path.of(URI.create("file://" + path + File.separator + fileName)).toFile();
}
- File file = new File(currentJarPath.get(), fileName);
+
if (file.exists()) {
logger.error("File already exists (" + fileName + ")");
return;
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index de85b08..a207671 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1 +1,2 @@
-logging.level.com.alttd.forms=warn
\ No newline at end of file
+logging.level.com.alttd.forms=warn
+server.port=8002
\ No newline at end of file
diff --git a/src/test/java/TestForm.java b/src/test/java/TestForm.java
index 06b352f..97553a6 100644
--- a/src/test/java/TestForm.java
+++ b/src/test/java/TestForm.java
@@ -15,7 +15,7 @@ public class TestForm {
@BeforeAll
public static void testInsert() {
- Assertions.assertDoesNotThrow(DatabaseConnection::initialize);
+ Assertions.assertDoesNotThrow(() -> DatabaseConnection.initialize());
StoreFormQuery storeFormQuery = new StoreFormQuery();
ContactFormData contactFormData = new ContactFormData("akastijn", "akastijn@alttd.com", "This is a test question.");
storeFormQuery.storeFormForVerificationCode("akastijn@alttd.com", contactFormData).
@@ -28,7 +28,7 @@ public class TestForm {
@Test
public void testRetrieveForm() {
- Assertions.assertDoesNotThrow(DatabaseConnection::initialize);
+ Assertions.assertDoesNotThrow(() -> DatabaseConnection.initialize());
new FormQuery().getFormForCode(String.valueOf(code), "akastijn@alttd.com").thenAccept(result -> {
Assertions.assertTrue(result.failReason().isEmpty());
Optional