Skip to content

Commit 55dae86

Browse files
committed
Handling exception that occured when property file not founded
1 parent d67a41a commit 55dae86

File tree

9 files changed

+100
-40
lines changed

9 files changed

+100
-40
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package root.core.domain.exceptions;
2+
3+
public class PropertyNotFoundException extends Exception {
4+
private static final long serialVersionUID = 196259383529491976L;
5+
6+
public PropertyNotFoundException(String message) {
7+
super(message);
8+
}
9+
}

Core/src/main/java/root/core/repository/constracts/PropertyRepository.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import root.common.database.implement.JdbcConnectionInfo;
99
import root.common.server.implement.AlertLogCommand;
1010
import root.common.server.implement.JschConnectionInfo;
11+
import root.core.domain.exceptions.PropertyNotFoundException;
1112

1213
public interface PropertyRepository {
1314

@@ -25,13 +26,13 @@ public interface PropertyRepository {
2526

2627
void saveCommonConfig(String key, String value);
2728

28-
void loadCombinedConfiguration();
29+
void loadCombinedConfiguration() throws PropertyNotFoundException;
2930

3031
void loadConnectionInfoConfig(String filePath);
3132

3233
void loadMonitoringInfoConfig(String filePath);
3334

34-
String[] getConnectionInfoFileNames();
35+
String[] getConnectionInfoFileNames() throws PropertyNotFoundException;
3536

3637
String getCommonResource(String key);
3738

Core/src/main/java/root/core/service/contracts/PropertyService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import root.core.domain.enums.MonitoringType;
1111
import root.core.domain.enums.RoundingDigits;
1212
import root.core.domain.enums.UsageUIType;
13+
import root.core.domain.exceptions.PropertyNotFoundException;
1314
import root.utils.UnitUtils.FileSize;
1415

1516
public interface PropertyService {
@@ -26,7 +27,7 @@ public interface PropertyService {
2627
*
2728
* @return
2829
*/
29-
List<String> getConnectionInfoList();
30+
List<String> getConnectionInfoList() throws PropertyNotFoundException;
3031

3132
/**
3233
* 최근 사용된 접속정보 설정파일의 경로를 반환한다.

DBMonitoringWindowApp/src/main/java/root/applications/Program.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import javafx.application.Application;
44
import javafx.scene.Parent;
55
import javafx.scene.Scene;
6+
import javafx.scene.control.Alert.AlertType;
67
import javafx.stage.Stage;
78
import lombok.extern.slf4j.Slf4j;
9+
import root.core.domain.exceptions.PropertyNotFoundException;
810
import root.core.repository.constracts.PropertyRepository;
911
import root.javafx.Controller.HomeController;
1012
import root.javafx.Controller.LeftMenuController;
1113
import root.javafx.DI.DependencyInjection;
14+
import root.javafx.utils.AlertUtils;
1215
import root.repository.implement.PropertyRepositoryImpl;
1316

1417
@Slf4j
@@ -26,7 +29,12 @@ public void start(Stage primaryStage) throws Exception {
2629
setUpDependecyInjector();
2730

2831
// configuration load
29-
propRepo.loadCombinedConfiguration();
32+
try {
33+
propRepo.loadCombinedConfiguration();
34+
} catch (PropertyNotFoundException e) {
35+
AlertUtils.showAlert(AlertType.ERROR, "설정 파일 Load", "설정 파일 읽기에 실패했습니다. 설정파일을 확인해주세요.");
36+
return;
37+
}
3038

3139
// fxml load
3240
System.setProperty("prism.lcdtext", "false"); // 안티앨리어싱 (Font 부드럽게)

DBMonitoringWindowApp/src/main/java/root/javafx/Controller/AlertLogMonitoringMenuController.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import root.common.server.implement.ServerOS;
3636
import root.core.domain.AlertLog;
3737
import root.core.domain.Log;
38+
import root.core.domain.exceptions.PropertyNotFoundException;
3839
import root.core.repository.constracts.ServerMonitoringRepository;
3940
import root.core.service.contracts.PropertyService;
4041
import root.core.usecase.constracts.ServerMonitoringUsecase;
@@ -107,18 +108,25 @@ public AlertLogMonitoringMenuController() {
107108
public void initialize(URL location, ResourceBundle resources) {
108109

109110
// 접속정보 설정 프로퍼티 파일
110-
List<String> connInfoFiles = propService.getConnectionInfoList();
111-
if (connInfoFiles != null && connInfoFiles.size() != 0) {
112-
// Connection Info ComboBox
113-
runConnInfoFileComboBox.getItems().addAll(connInfoFiles);
114-
runConnInfoFileComboBox.getSelectionModel().selectFirst();
115-
116-
// remember.properties 파일에서, 최근 사용된 설정파일 경로가 있다면 해당 설정파일을 불러온다.
117-
String lastUseConnInfoFilePath = propService.getLastUseConnectionInfoFilePath();
118-
if (lastUseConnInfoFilePath != null) {
119-
runConnInfoFileComboBox.getSelectionModel().select(lastUseConnInfoFilePath);
111+
List<String> connInfoFiles;
112+
try {
113+
connInfoFiles = propService.getConnectionInfoList();
114+
if (connInfoFiles != null && connInfoFiles.size() != 0) {
115+
// Connection Info ComboBox
116+
runConnInfoFileComboBox.getItems().addAll(connInfoFiles);
117+
runConnInfoFileComboBox.getSelectionModel().selectFirst();
118+
119+
// remember.properties 파일에서, 최근 사용된 설정파일 경로가 있다면 해당 설정파일을 불러온다.
120+
String lastUseConnInfoFilePath = propService.getLastUseConnectionInfoFilePath();
121+
if (lastUseConnInfoFilePath != null) {
122+
runConnInfoFileComboBox.getSelectionModel().select(lastUseConnInfoFilePath);
123+
}
124+
} else {
125+
AlertUtils.showAlert(AlertType.INFORMATION, "접속정보 설정", "설정된 접속정보가 없습니다.\n[설정]메뉴로 이동합니다.");
126+
return;
120127
}
121-
} else {
128+
} catch (PropertyNotFoundException e) {
129+
log.error(e.getMessage());
122130
AlertUtils.showAlert(AlertType.INFORMATION, "접속정보 설정", "설정된 접속정보가 없습니다.\n[설정]메뉴로 이동합니다.");
123131
return;
124132
}

DBMonitoringWindowApp/src/main/java/root/javafx/Controller/HistoryMenuController.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javafx.fxml.Initializable;
1212
import javafx.scene.control.Alert.AlertType;
1313
import javafx.scene.layout.AnchorPane;
14+
import lombok.extern.slf4j.Slf4j;
1415
import root.common.database.implement.JdbcConnectionInfo;
1516
import root.common.database.implement.JdbcDatabase;
1617
import root.common.server.implement.JschConnectionInfo;
@@ -20,6 +21,7 @@
2021
import root.core.domain.MonitoringResult;
2122
import root.core.domain.OSDiskUsage;
2223
import root.core.domain.TableSpaceUsage;
24+
import root.core.domain.exceptions.PropertyNotFoundException;
2325
import root.core.repository.constracts.DBCheckRepository;
2426
import root.core.repository.constracts.ServerMonitoringRepository;
2527
import root.core.service.contracts.PropertyService;
@@ -34,6 +36,7 @@
3436
import root.repository.implement.ReportFileRepo;
3537
import root.service.implement.FilePropertyService;
3638

39+
@Slf4j
3740
public class HistoryMenuController implements Initializable {
3841

3942
/* Dependency Injection */
@@ -76,18 +79,25 @@ public HistoryMenuController() {
7679
public void initialize(URL location, ResourceBundle resources) {
7780

7881
// 접속정보 설정 프로퍼티 파일
79-
List<String> connInfoFiles = propService.getConnectionInfoList();
80-
if (connInfoFiles != null && connInfoFiles.size() != 0) {
81-
// Connection Info ComboBox
82-
runConnInfoFileComboBox.getItems().addAll(connInfoFiles);
83-
runConnInfoFileComboBox.getSelectionModel().selectFirst();
84-
85-
// remember.properties 파일에서, 최근 사용된 설정파일 경로가 있다면 해당 설정파일을 불러온다.
86-
String lastUseConnInfoFilePath = propService.getLastUseConnectionInfoFilePath();
87-
if (lastUseConnInfoFilePath != null) {
88-
runConnInfoFileComboBox.getSelectionModel().select(lastUseConnInfoFilePath);
82+
List<String> connInfoFiles;
83+
try {
84+
connInfoFiles = propService.getConnectionInfoList();
85+
if (connInfoFiles != null && connInfoFiles.size() != 0) {
86+
// Connection Info ComboBox
87+
runConnInfoFileComboBox.getItems().addAll(connInfoFiles);
88+
runConnInfoFileComboBox.getSelectionModel().selectFirst();
89+
90+
// remember.properties 파일에서, 최근 사용된 설정파일 경로가 있다면 해당 설정파일을 불러온다.
91+
String lastUseConnInfoFilePath = propService.getLastUseConnectionInfoFilePath();
92+
if (lastUseConnInfoFilePath != null) {
93+
runConnInfoFileComboBox.getSelectionModel().select(lastUseConnInfoFilePath);
94+
}
95+
} else {
96+
AlertUtils.showAlert(AlertType.INFORMATION, "접속정보 설정", "설정된 DB/Server 접속정보가 없습니다.\n[설정]메뉴로 이동합니다.");
97+
return;
8998
}
90-
} else {
99+
} catch (PropertyNotFoundException e) {
100+
log.error(e.getMessage());
91101
AlertUtils.showAlert(AlertType.INFORMATION, "접속정보 설정", "설정된 DB/Server 접속정보가 없습니다.\n[설정]메뉴로 이동합니다.");
92102
return;
93103
}

DBMonitoringWindowApp/src/main/java/root/javafx/Controller/RunMenuController.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import javafx.scene.control.Label;
2323
import javafx.scene.control.ScrollPane;
2424
import javafx.scene.control.SplitPane;
25+
import javafx.scene.control.Alert.AlertType;
2526
import javafx.scene.input.ScrollEvent;
2627
import javafx.scene.layout.AnchorPane;
2728
import javafx.scene.layout.HBox;
2829
import javafx.util.StringConverter;
30+
import lombok.extern.slf4j.Slf4j;
2931
import root.common.database.contracts.AbstractDatabase;
3032
import root.common.database.implement.JdbcConnectionInfo;
3133
import root.common.database.implement.JdbcDatabase;
@@ -39,6 +41,7 @@
3941
import root.core.domain.enums.MonitoringType;
4042
import root.core.domain.enums.RoundingDigits;
4143
import root.core.domain.enums.UsageUIType;
44+
import root.core.domain.exceptions.PropertyNotFoundException;
4245
import root.core.repository.constracts.DBCheckRepository;
4346
import root.core.repository.constracts.ServerMonitoringRepository;
4447
import root.core.service.contracts.PropertyService;
@@ -48,13 +51,15 @@
4851
import root.core.usecase.implement.ServerMonitoringUsecaseImpl;
4952
import root.javafx.CustomView.CustomTreeTableView;
5053
import root.javafx.CustomView.CustomTreeView;
54+
import root.javafx.utils.AlertUtils;
5155
import root.repository.implement.DBCheckRepositoryImpl;
5256
import root.repository.implement.LinuxServerMonitoringRepository;
5357
import root.repository.implement.PropertyRepositoryImpl;
5458
import root.repository.implement.ReportFileRepo;
5559
import root.service.implement.FilePropertyService;
5660
import root.utils.UnitUtils.FileSize;
5761

62+
@Slf4j
5863
public class RunMenuController implements Initializable {
5964

6065
/* Dependency Injection */
@@ -114,15 +119,20 @@ public class RunMenuController implements Initializable {
114119
@Override
115120
public void initialize(URL location, ResourceBundle resources) {
116121

117-
/* 1. 모니터링 접속정보 설정 + 2. 모니터링 여부 설정 */
118-
initRunStep1();
122+
try {
123+
/* 1. 모니터링 접속정보 설정 + 2. 모니터링 여부 설정 */
124+
initRunStep1();
125+
126+
/* 3. 기타 설정 및 실행 */
127+
initRunStep3();
119128

120-
/* 3. 기타 설정 및 실행 */
121-
initRunStep3();
122-
123-
/* 4. 실행결과 */
124-
// initRunStep4();
129+
/* 4. 실행결과 */
130+
// initRunStep4();
125131

132+
} catch (PropertyNotFoundException e) {
133+
log.error(e.getMessage());
134+
AlertUtils.showAlert(AlertType.ERROR, "설정 파일 Load", "설정 파일 읽기에 실패했습니다. 설정파일을 확인해주세요.");
135+
}
126136
}
127137

128138
/**
@@ -282,8 +292,9 @@ public void runMonitoring(ActionEvent e) {
282292

283293
/**
284294
* 1. 모니터링 접속정보 설정 영역의 View를 초기화한다.
295+
* @throws PropertyNotFoundException
285296
*/
286-
private void initRunStep1() {
297+
private void initRunStep1() throws PropertyNotFoundException {
287298
// 1-0. Clear
288299
if (connInfoFileListComboBox.getItems().size() != 0) {
289300
connInfoFileListComboBox.getItems().clear();

Repository/src/main/java/root/repository/implement/PropertyRepositoryImpl.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import root.common.server.implement.AlertLogCommand;
3434
import root.common.server.implement.JschConnectionInfo;
3535
import root.common.server.implement.ServerOS;
36+
import root.core.domain.exceptions.PropertyNotFoundException;
3637
import root.core.repository.constracts.PropertyRepository;
3738

3839
@Slf4j
@@ -41,9 +42,13 @@ public class PropertyRepositoryImpl implements PropertyRepository {
4142
// Private 필드로 선언 후 Singletone으로 관리
4243
private static PropertyRepository propRepo = new PropertyRepositoryImpl();
4344

44-
// 생성자를 Private으로 선언함으로써 해당 객체를 생성할 수 있는 방법을 업애버림 => 안정적인 Singletone 관리방법
45+
// 생성자를 Private으로 선언함으로써 해당 객체를 생성할 수 있는 방법을 없애버림 => 안정적인 Singletone 관리방법
4546
private PropertyRepositoryImpl() {
46-
loadCombinedConfiguration();
47+
try {
48+
loadCombinedConfiguration();
49+
} catch (PropertyNotFoundException e) {
50+
log.error(e.getMessage());
51+
}
4752
}
4853

4954
// propertyService Field에 접근할 수 있는 유일한 방법 (Static Factory Pattern)
@@ -278,7 +283,7 @@ private static PropertiesConfiguration load(String filePath) {
278283
* @throws Exception
279284
*/
280285
@Override
281-
public void loadCombinedConfiguration() {
286+
public void loadCombinedConfiguration() throws PropertyNotFoundException {
282287
Parameters params = new Parameters();
283288

284289
CombinedConfigurationBuilder builder = new CombinedConfigurationBuilder();
@@ -292,7 +297,8 @@ public void loadCombinedConfiguration() {
292297
try {
293298
combinedConfig = builder.getConfiguration();
294299
} catch (ConfigurationException e) {
295-
e.printStackTrace();
300+
log.error(e.getMessage());
301+
throw new PropertyNotFoundException("there is no config_definition properties file");
296302
}
297303
}
298304

@@ -315,9 +321,13 @@ public void loadMonitoringInfoConfig(String filePath) {
315321
}
316322

317323
@Override
318-
public String[] getConnectionInfoFileNames() {
324+
public String[] getConnectionInfoFileNames() throws PropertyNotFoundException {
319325
String connInfoDirPath = "./config/connectioninfo";
320326
String[] connInfoFileList = new File(connInfoDirPath).list();
327+
if(connInfoFileList == null) {
328+
throw new PropertyNotFoundException("there is no ConnectionInfo properties file");
329+
}
330+
321331
for (int i = 0; i < connInfoFileList.length; i++) {
322332
connInfoFileList[i] = connInfoDirPath + "/" + connInfoFileList[i];
323333
}

Repository/src/main/java/root/service/implement/FilePropertyService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import root.core.domain.enums.MonitoringType;
2121
import root.core.domain.enums.RoundingDigits;
2222
import root.core.domain.enums.UsageUIType;
23+
import root.core.domain.exceptions.PropertyNotFoundException;
2324
import root.core.repository.constracts.PropertyRepository;
2425
import root.core.service.contracts.PropertyService;
2526
import root.utils.UnitUtils.FileSize;
@@ -45,9 +46,10 @@ public void loadConnectionInfoConfig(String filePath) {
4546

4647
/**
4748
* ./config/connectioninfo/ 디렉터리 하위에 있는 접속정보 설정파일 리스트를 반환한다.
49+
* @throws PropertyNotFoundException
4850
*/
4951
@Override
50-
public List<String> getConnectionInfoList() {
52+
public List<String> getConnectionInfoList() throws PropertyNotFoundException {
5153
return new ArrayList<>(Arrays.asList(propRepo.getConnectionInfoFileNames()));
5254
}
5355

0 commit comments

Comments
 (0)