Add database configuration via command-line arguments
A new configuration setup now allows specifying a path for database properties via command-line arguments during application startup. This update also changes the call signature for `DatabaseConnection.initialize()` method to accept a path argument. Similarly, methods in `PropertiesLoader`, `PropertiesWriter`, and `MailSettings` classes were also updated to use the specified path when working with properties files. The `TestForm` class's tests were updated accordingly to handle these changes.
This commit is contained in:
parent
2f1d24598b
commit
49af4a3067
|
|
@ -4,14 +4,15 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="ce59df2a-8d56-446a-867b-80e627daf479" name="Changes" comment="Mark fields as final in VerificationData and ContactFormData The 'code', 'eMail' fields in the VerificationData class and 'username', 'email', 'question' fields in the ContactFormData class are now marked as 'final'. At the same time, some unused imports from ContactController, ContactFormData, FormQuery, and VerifyController have been removed for code cleanliness.">
|
<list default="true" id="ce59df2a-8d56-446a-867b-80e627daf479" name="Changes" comment="Update Form HTML output and disable validation auto-configuration The form-to-HTML output process has been switched from a `<div>` approach to using a `StringBuilder` with a table structure in `ContactFormData.java`. Also, the spring validation auto-configuration has been disabled by adding `exclude = ValidationAutoConfiguration.class` in the `@SpringBootApplication` annotation of `Main.java`. Some changes in `.idea/workspace.xml` and `VerifyController.java` were made as well.">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/Main.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/Main.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/beans/WebConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/beans/WebConfig.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/database/DatabaseConnection.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/database/DatabaseConnection.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/contact/ContactFormData.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/contact/ContactFormData.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/mail/MailSettings.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/mail/MailSettings.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/database/Database.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/database/Database.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/properties/PropertiesLoader.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/properties/PropertiesLoader.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/verify_mail/FormQuery.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/verify_mail/FormQuery.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/properties/PropertiesWriter.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/properties/PropertiesWriter.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/alttd/forms/verify_mail/VerifyController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/alttd/forms/verify_mail/VerifyController.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/resources/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/application.properties" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/test/java/TestForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/TestForm.java" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|
@ -28,6 +29,8 @@
|
||||||
<list>
|
<list>
|
||||||
<option value="Jsp File" />
|
<option value="Jsp File" />
|
||||||
<option value="Class" />
|
<option value="Class" />
|
||||||
|
<option value="package-info" />
|
||||||
|
<option value="package.json" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|
@ -62,43 +65,68 @@
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"Gradle.Build forms.executor": "Run",
|
"Gradle.Build forms.executor": "Run",
|
||||||
"Gradle.TestForm.testFunctions.executor": "Debug",
|
"Gradle.TestForm.executor": "Run",
|
||||||
"Gradle.TestForm.testRetrieveForm.executor": "Run",
|
"Gradle.TestForm.testFunctions.executor": "Debug",
|
||||||
"RequestMappingsPanelOrder0": "0",
|
"Gradle.TestForm.testRetrieveForm.executor": "Run",
|
||||||
"RequestMappingsPanelOrder1": "1",
|
"RequestMappingsPanelOrder0": "0",
|
||||||
"RequestMappingsPanelWidth0": "75",
|
"RequestMappingsPanelOrder1": "1",
|
||||||
"RequestMappingsPanelWidth1": "75",
|
"RequestMappingsPanelWidth0": "75",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RequestMappingsPanelWidth1": "75",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"Spring Boot.Main.executor": "Run",
|
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
"Tomcat Server.Tomcat 10.1.17.executor": "Run",
|
"Spring Boot.Main.executor": "Run",
|
||||||
"git-widget-placeholder": "master",
|
"Tomcat Server.Tomcat 10.1.17.executor": "Run",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"git-widget-placeholder": "master",
|
||||||
"kotlin-language-version-configured": "true",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"kotlin-language-version-configured": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"project.structure.last.edited": "Project",
|
"nodejs_package_manager_path": "npm",
|
||||||
"project.structure.proportion": "0.0",
|
"project.structure.last.edited": "Project",
|
||||||
"project.structure.side.proportion": "0.0",
|
"project.structure.proportion": "0.0",
|
||||||
"run.code.analysis.last.selected.profile": "pProject Default",
|
"project.structure.side.proportion": "0.0",
|
||||||
"settings.editor.selected.configurable": "preferences.lookFeel",
|
"run.code.analysis.last.selected.profile": "pProject Default",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"settings.editor.selected.configurable": "preferences.lookFeel",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
},
|
},
|
||||||
"keyToStringList": {
|
"keyToStringList": {
|
||||||
"DatabaseDriversLRU": [
|
"DatabaseDriversLRU": [
|
||||||
"mysql",
|
"mysql",
|
||||||
"mariadb"
|
"mariadb"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RunManager" selected="Spring Boot.Main">
|
<component name="RunManager" selected="Gradle.TestForm">
|
||||||
|
<configuration name="TestForm" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
||||||
|
<ExternalSystemSettings>
|
||||||
|
<option name="executionName" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="externalSystemIdString" value="GRADLE" />
|
||||||
|
<option name="scriptParameters" value="" />
|
||||||
|
<option name="taskDescriptions">
|
||||||
|
<list />
|
||||||
|
</option>
|
||||||
|
<option name="taskNames">
|
||||||
|
<list>
|
||||||
|
<option value=":test" />
|
||||||
|
<option value="--tests" />
|
||||||
|
<option value=""TestForm"" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="vmOptions" />
|
||||||
|
</ExternalSystemSettings>
|
||||||
|
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
|
||||||
|
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||||
|
<DebugAllEnabled>false</DebugAllEnabled>
|
||||||
|
<RunAsTest>true</RunAsTest>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
<configuration name="TestForm.testFunctions" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
<configuration name="TestForm.testFunctions" type="GradleRunConfiguration" factoryName="Gradle" temporary="true">
|
||||||
<ExternalSystemSettings>
|
<ExternalSystemSettings>
|
||||||
<option name="executionName" />
|
<option name="executionName" />
|
||||||
|
|
@ -194,6 +222,7 @@
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Gradle.TestForm" />
|
||||||
<item itemvalue="Gradle.TestForm.testFunctions" />
|
<item itemvalue="Gradle.TestForm.testFunctions" />
|
||||||
<item itemvalue="Gradle.TestForm.testRetrieveForm" />
|
<item itemvalue="Gradle.TestForm.testRetrieveForm" />
|
||||||
<item itemvalue="Spring Boot.Main" />
|
<item itemvalue="Spring Boot.Main" />
|
||||||
|
|
@ -201,6 +230,7 @@
|
||||||
</list>
|
</list>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Gradle.TestForm" />
|
||||||
<item itemvalue="Gradle.TestForm.testRetrieveForm" />
|
<item itemvalue="Gradle.TestForm.testRetrieveForm" />
|
||||||
<item itemvalue="Gradle.TestForm.testFunctions" />
|
<item itemvalue="Gradle.TestForm.testFunctions" />
|
||||||
</list>
|
</list>
|
||||||
|
|
@ -239,7 +269,7 @@
|
||||||
<workItem from="1707656217023" duration="2305000" />
|
<workItem from="1707656217023" duration="2305000" />
|
||||||
<workItem from="1708153393312" duration="669000" />
|
<workItem from="1708153393312" duration="669000" />
|
||||||
<workItem from="1708154142819" duration="609000" />
|
<workItem from="1708154142819" duration="609000" />
|
||||||
<workItem from="1714315469459" duration="3062000" />
|
<workItem from="1714315469459" duration="8118000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Initial commit for site for forms">
|
<task id="LOCAL-00001" summary="Initial commit for site for forms">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
|
@ -273,7 +303,15 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1705227608210</updated>
|
<updated>1705227608210</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="5" />
|
<task id="LOCAL-00005" summary="Update Form HTML output and disable validation auto-configuration The form-to-HTML output process has been switched from a `<div>` approach to using a `StringBuilder` with a table structure in `ContactFormData.java`. Also, the spring validation auto-configuration has been disabled by adding `exclude = ValidationAutoConfiguration.class` in the `@SpringBootApplication` annotation of `Main.java`. Some changes in `.idea/workspace.xml` and `VerifyController.java` were made as well.">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1714319923708</created>
|
||||||
|
<option name="number" value="00005" />
|
||||||
|
<option name="presentableId" value="LOCAL-00005" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1714319923708</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="6" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
|
@ -296,6 +334,7 @@
|
||||||
<MESSAGE value="Add TestForm class and set up related unit tests The changes add a new TestForm class to implement unit tests for form handling in the application. The included tests verify the storing, retrieving, and verification of forms from a database, as well as form object creation and confirmation of form data. This is a step towards improving the code's reliability and making it easier to catch potential bugs or issues." />
|
<MESSAGE value="Add TestForm class and set up related unit tests The changes add a new TestForm class to implement unit tests for form handling in the application. The included tests verify the storing, retrieving, and verification of forms from a database, as well as form object creation and confirmation of form data. This is a step towards improving the code's reliability and making it easier to catch potential bugs or issues." />
|
||||||
<MESSAGE value="Remove unnecessary Gson imports in ContactFormData The Gson and GsonBuilder imports in the ContactFormData class were unused and have been removed. This cleanup simplifies the code and reduces unnecessary dependencies. " />
|
<MESSAGE value="Remove unnecessary Gson imports in ContactFormData The Gson and GsonBuilder imports in the ContactFormData class were unused and have been removed. This cleanup simplifies the code and reduces unnecessary dependencies. " />
|
||||||
<MESSAGE value="Mark fields as final in VerificationData and ContactFormData The 'code', 'eMail' fields in the VerificationData class and 'username', 'email', 'question' fields in the ContactFormData class are now marked as 'final'. At the same time, some unused imports from ContactController, ContactFormData, FormQuery, and VerifyController have been removed for code cleanliness." />
|
<MESSAGE value="Mark fields as final in VerificationData and ContactFormData The 'code', 'eMail' fields in the VerificationData class and 'username', 'email', 'question' fields in the ContactFormData class are now marked as 'final'. At the same time, some unused imports from ContactController, ContactFormData, FormQuery, and VerifyController have been removed for code cleanliness." />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Mark fields as final in VerificationData and ContactFormData The 'code', 'eMail' fields in the VerificationData class and 'username', 'email', 'question' fields in the ContactFormData class are now marked as 'final'. At the same time, some unused imports from ContactController, ContactFormData, FormQuery, and VerifyController have been removed for code cleanliness." />
|
<MESSAGE value="Update Form HTML output and disable validation auto-configuration The form-to-HTML output process has been switched from a `<div>` approach to using a `StringBuilder` with a table structure in `ContactFormData.java`. Also, the spring validation auto-configuration has been disabled by adding `exclude = ValidationAutoConfiguration.class` in the `@SpringBootApplication` annotation of `Main.java`. Some changes in `.idea/workspace.xml` and `VerifyController.java` were made as well." />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Update Form HTML output and disable validation auto-configuration The form-to-HTML output process has been switched from a `<div>` approach to using a `StringBuilder` with a table structure in `ContactFormData.java`. Also, the spring validation auto-configuration has been disabled by adding `exclude = ValidationAutoConfiguration.class` in the `@SpringBootApplication` annotation of `Main.java`. Some changes in `.idea/workspace.xml` and `VerifyController.java` were made as well." />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -10,9 +10,15 @@ import java.sql.SQLException;
|
||||||
@SpringBootApplication(exclude = ValidationAutoConfiguration.class)
|
@SpringBootApplication(exclude = ValidationAutoConfiguration.class)
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
|
||||||
public static void main(String[] args) throws SQLException {
|
public static void main(String[] args) throws SQLException {
|
||||||
|
path = args[0];
|
||||||
SpringApplication.run(Main.class, args);
|
SpringApplication.run(Main.class, args);
|
||||||
DatabaseConnection.initialize();
|
DatabaseConnection.initialize(args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getConfigPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import com.alttd.forms.properties.PropertiesWriter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
@ -26,6 +27,13 @@ public class DatabaseConnection {
|
||||||
Database.createTables();
|
Database.createTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DatabaseConnection(String path) throws SQLException {
|
||||||
|
instance = this;
|
||||||
|
loadProperties(path);
|
||||||
|
instance.openConnection();
|
||||||
|
Database.createTables();
|
||||||
|
}
|
||||||
|
|
||||||
public static Connection getConnection() {
|
public static Connection getConnection() {
|
||||||
try {
|
try {
|
||||||
instance.openConnection();
|
instance.openConnection();
|
||||||
|
|
@ -36,15 +44,21 @@ public class DatabaseConnection {
|
||||||
return instance.connection;
|
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 {
|
public static void initialize() throws SQLException {
|
||||||
if (instance != null)
|
if (instance != null)
|
||||||
return;
|
return;
|
||||||
instance = new DatabaseConnection();
|
instance = new DatabaseConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadProperties() {
|
private void loadProperties(String path) {
|
||||||
String fileName = "database.properties";
|
String fileName = "database.properties";
|
||||||
Optional<Properties> optionalProperties = PropertiesLoader.loadProperties(fileName);
|
Optional<Properties> optionalProperties = PropertiesLoader.loadProperties(path, fileName);
|
||||||
if (optionalProperties.isPresent()) {
|
if (optionalProperties.isPresent()) {
|
||||||
properties = optionalProperties.get();
|
properties = optionalProperties.get();
|
||||||
return;
|
return;
|
||||||
|
|
@ -58,7 +72,11 @@ public class DatabaseConnection {
|
||||||
properties.setProperty("user", "root");
|
properties.setProperty("user", "root");
|
||||||
properties.setProperty("password", "root");
|
properties.setProperty("password", "root");
|
||||||
properties.setProperty("parameters", "autoReconnect=true&useSSL=false");
|
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 {
|
public void openConnection() throws SQLException {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.alttd.forms.mail;
|
package com.alttd.forms.mail;
|
||||||
|
|
||||||
|
import com.alttd.forms.Main;
|
||||||
import com.alttd.forms.properties.PropertiesLoader;
|
import com.alttd.forms.properties.PropertiesLoader;
|
||||||
import com.alttd.forms.properties.PropertiesWriter;
|
import com.alttd.forms.properties.PropertiesWriter;
|
||||||
|
|
||||||
|
|
@ -20,8 +21,9 @@ public class MailSettings {
|
||||||
if (mailProperties != null)
|
if (mailProperties != null)
|
||||||
return mailProperties;
|
return mailProperties;
|
||||||
|
|
||||||
|
String path = Main.getConfigPath();
|
||||||
String fileName = "mail_settings.properties";
|
String fileName = "mail_settings.properties";
|
||||||
Optional<Properties> properties = PropertiesLoader.loadProperties(fileName);
|
Optional<Properties> properties = PropertiesLoader.loadProperties(path, fileName);
|
||||||
if (properties.isPresent()) {
|
if (properties.isPresent()) {
|
||||||
mailProperties = properties.get();
|
mailProperties = properties.get();
|
||||||
return mailProperties;
|
return mailProperties;
|
||||||
|
|
@ -33,7 +35,7 @@ public class MailSettings {
|
||||||
mailProperties.put("mail.smtp.auth", "true");
|
mailProperties.put("mail.smtp.auth", "true");
|
||||||
mailProperties.put("mail.smtp.socketFactory.port", "465");
|
mailProperties.put("mail.smtp.socketFactory.port", "465");
|
||||||
mailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
mailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
||||||
PropertiesWriter.writeProperties(mailProperties, fileName);
|
PropertiesWriter.writeProperties(mailProperties, path, fileName);
|
||||||
return mailProperties;
|
return mailProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,8 +61,10 @@ public class MailSettings {
|
||||||
return createPasswordAuthentication(accountDetails);
|
return createPasswordAuthentication(accountDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String path = Main.getConfigPath();
|
||||||
|
|
||||||
String fileName = "mail_account.properties";
|
String fileName = "mail_account.properties";
|
||||||
Optional<Properties> properties = PropertiesLoader.loadProperties(fileName);
|
Optional<Properties> properties = PropertiesLoader.loadProperties(path, fileName);
|
||||||
if (properties.isPresent()) {
|
if (properties.isPresent()) {
|
||||||
accountDetails = properties.get();
|
accountDetails = properties.get();
|
||||||
return createPasswordAuthentication(accountDetails);
|
return createPasswordAuthentication(accountDetails);
|
||||||
|
|
@ -70,7 +74,7 @@ public class MailSettings {
|
||||||
accountDetails.put("username", "test@test.test");
|
accountDetails.put("username", "test@test.test");
|
||||||
accountDetails.put("password", "testpassword");
|
accountDetails.put("password", "testpassword");
|
||||||
|
|
||||||
PropertiesWriter.writeProperties(accountDetails, fileName);
|
PropertiesWriter.writeProperties(accountDetails, path, fileName);
|
||||||
return createPasswordAuthentication(accountDetails);
|
return createPasswordAuthentication(accountDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
@ -13,15 +15,21 @@ public class PropertiesLoader {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(PropertiesLoader.class);
|
private static final Logger logger = LoggerFactory.getLogger(PropertiesLoader.class);
|
||||||
|
|
||||||
public static Optional<Properties> loadProperties(String fileName) {
|
public static Optional<Properties> loadProperties(String path, String fileName) {
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
Optional<File> currentJarPath = JarPath.getCurrentJarDir();
|
File file;
|
||||||
if (currentJarPath.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
logger.error("Unable to find jar path to load properties (" + fileName + ")");
|
Optional<File> currentJarPath = JarPath.getCurrentJarDir();
|
||||||
return Optional.empty();
|
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()) {
|
if (!file.exists()) {
|
||||||
logger.warn("Tried to load properties file that doesnt exists (" + fileName + ")");
|
logger.warn("Tried to load properties file that doesnt exists (" + fileName + ")");
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
@ -13,13 +15,19 @@ public class PropertiesWriter {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(PropertiesWriter.class);
|
private static final Logger logger = LoggerFactory.getLogger(PropertiesWriter.class);
|
||||||
|
|
||||||
public static void writeProperties(Properties prop, String fileName) {
|
public static void writeProperties(Properties prop, String path, String fileName) {
|
||||||
Optional<File> currentJarPath = JarPath.getCurrentJarDir();
|
File file;
|
||||||
if (currentJarPath.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
logger.error("Failed to get current jar directory");
|
Optional<File> currentJarPath = JarPath.getCurrentJarDir();
|
||||||
return;
|
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()) {
|
if (file.exists()) {
|
||||||
logger.error("File already exists (" + fileName + ")");
|
logger.error("File already exists (" + fileName + ")");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
logging.level.com.alttd.forms=warn
|
logging.level.com.alttd.forms=warn
|
||||||
|
server.port=8002
|
||||||
|
|
@ -15,7 +15,7 @@ public class TestForm {
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void testInsert() {
|
public static void testInsert() {
|
||||||
Assertions.assertDoesNotThrow(DatabaseConnection::initialize);
|
Assertions.assertDoesNotThrow(() -> DatabaseConnection.initialize());
|
||||||
StoreFormQuery storeFormQuery = new StoreFormQuery();
|
StoreFormQuery storeFormQuery = new StoreFormQuery();
|
||||||
ContactFormData contactFormData = new ContactFormData("akastijn", "akastijn@alttd.com", "This is a test question.");
|
ContactFormData contactFormData = new ContactFormData("akastijn", "akastijn@alttd.com", "This is a test question.");
|
||||||
storeFormQuery.storeFormForVerificationCode("akastijn@alttd.com", contactFormData).
|
storeFormQuery.storeFormForVerificationCode("akastijn@alttd.com", contactFormData).
|
||||||
|
|
@ -28,7 +28,7 @@ public class TestForm {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRetrieveForm() {
|
public void testRetrieveForm() {
|
||||||
Assertions.assertDoesNotThrow(DatabaseConnection::initialize);
|
Assertions.assertDoesNotThrow(() -> DatabaseConnection.initialize());
|
||||||
new FormQuery().getFormForCode(String.valueOf(code), "akastijn@alttd.com").thenAccept(result -> {
|
new FormQuery().getFormForCode(String.valueOf(code), "akastijn@alttd.com").thenAccept(result -> {
|
||||||
Assertions.assertTrue(result.failReason().isEmpty());
|
Assertions.assertTrue(result.failReason().isEmpty());
|
||||||
Optional<Form> optionalForm = result.form();
|
Optional<Form> optionalForm = result.form();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user