Skip to content

Commit 49428b1

Browse files
committed
IPTE-165: Code Refactoring
1 parent bea1723 commit 49428b1

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/main/java/de/doubleslash/keeptime/view/SettingsController.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.nio.file.Paths;
2424
import java.sql.SQLException;
2525
import java.util.Comparator;
26+
import java.util.HashMap;
27+
import java.util.Map;
2628
import java.util.Properties;
2729

2830
import de.doubleslash.keeptime.model.Authorities;
@@ -591,8 +593,11 @@ private void handleApiOn() {
591593

592594
createAndSaveUser(username, password);
593595

594-
propertyWrite("server.port", authPort.getText());
595-
setWebApplicationType("");
596+
Map<String, String> propertiesToUpdate = new HashMap<>();
597+
propertiesToUpdate.put("spring.main.web-application-type", "");
598+
propertiesToUpdate.put("server.port", authPort.getText());
599+
600+
propertyWrite(propertiesToUpdate);
596601
}
597602

598603
private void setWebApplicationType(String value) {
@@ -621,9 +626,29 @@ private void propertyWrite(String key, String value) {
621626
Properties properties = new Properties();
622627
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertiesFilePath);
623628
FileOutputStream outputStream = new FileOutputStream(propertiesFilePath)) {
629+
624630
properties.load(inputStream);
625631
properties.setProperty(key, value);
626632
properties.store(outputStream, null);
633+
634+
} catch (IOException e) {
635+
e.printStackTrace();
636+
}
637+
}
638+
639+
private void propertyWrite(Map<String, String> propertiesToUpdate) {
640+
Properties properties = new Properties();
641+
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propertiesFilePath);
642+
FileOutputStream outputStream = new FileOutputStream(propertiesFilePath)) {
643+
644+
properties.load(inputStream);
645+
646+
for (Map.Entry<String, String> entry : propertiesToUpdate.entrySet()) {
647+
properties.setProperty(entry.getKey(), entry.getValue());
648+
}
649+
650+
properties.store(outputStream, null);
651+
627652
} catch (IOException e) {
628653
e.printStackTrace();
629654
}

0 commit comments

Comments
 (0)