Skip to content

Commit c61abd4

Browse files
committed
Handling exception that occured when property file not loaded
1 parent efbb852 commit c61abd4

File tree

8 files changed

+146
-47
lines changed

8 files changed

+146
-47
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@
99
import root.common.server.implement.AlertLogCommand;
1010
import root.common.server.implement.JschConnectionInfo;
1111
import root.core.domain.exceptions.PropertyNotFoundException;
12+
import root.core.domain.exceptions.PropertyNotLoadedException;
1213

1314
public interface PropertyRepository {
1415

1516
boolean isFileExist(String filePath);
1617

17-
PropertiesConfiguration getConfiguration(String config);
18+
PropertiesConfiguration getConfiguration(String config) throws PropertyNotLoadedException;
1819

1920
void save(String filePath, PropertiesConfiguration config);
2021

2122
void saveDBConnectionInfo(String filePath, Map<String, JdbcConnectionInfo> config);
2223

2324
void saveServerConnectionInfo(String filePath, Map<String, JschConnectionInfo> config);
2425

25-
void saveCommonConfig(Map<String, Object> values);
26+
void saveCommonConfig(Map<String, Object> values) throws PropertyNotLoadedException;
2627

27-
void saveCommonConfig(String key, String value);
28+
void saveCommonConfig(String key, String value) throws PropertyNotLoadedException;
2829

2930
void loadCombinedConfiguration() throws PropertyNotFoundException;
3031

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import root.core.domain.enums.RoundingDigits;
1212
import root.core.domain.enums.UsageUIType;
1313
import root.core.domain.exceptions.PropertyNotFoundException;
14+
import root.core.domain.exceptions.PropertyNotLoadedException;
1415
import root.utils.UnitUtils.FileSize;
1516

1617
public interface PropertyService {
@@ -26,6 +27,7 @@ public interface PropertyService {
2627
* 모니터링 접속정보 설정파일의 경로를 반환한다.
2728
*
2829
* @return
30+
* @throws PropertyNotFoundException
2931
*/
3032
List<String> getConnectionInfoList() throws PropertyNotFoundException;
3133

@@ -66,13 +68,13 @@ public interface PropertyService {
6668
*/
6769
List<MonitoringYN> getServerMonitoringYnList(String presetConfigFileName);
6870

69-
Map<String, String> getMonitoringPresetMap();
71+
Map<String, String> getMonitoringPresetMap() throws PropertyNotLoadedException;
7072

71-
List<String> getMonitoringPresetFilePathList();
73+
List<String> getMonitoringPresetFilePathList() throws PropertyNotLoadedException;
7274

73-
List<String> getMonitoringPresetNameList();
75+
List<String> getMonitoringPresetNameList() throws PropertyNotLoadedException;
7476

75-
String getMonitoringPresetFilePath(String presetName);
77+
String getMonitoringPresetFilePath(String presetName) throws PropertyNotLoadedException;
7678

7779
List<String> getMonitoringDBNameList();
7880

@@ -123,30 +125,32 @@ public interface PropertyService {
123125
* @param key 설정정보 키
124126
* @param value 설정정보 값
125127
*/
126-
void saveCommonConfig(String key, String value);
128+
void saveCommonConfig(String key, String value) throws PropertyNotLoadedException;
127129

128130
/**
129131
* 최근 사용한 접속정보 설정정보를 저장한다.
130132
*
131133
* @param filePath
134+
* @throws PropertyNotLoadedException
132135
*/
133-
void saveLastUseConnectionInfoSetting(String filePath);
136+
void saveLastUseConnectionInfoSetting(String filePath) throws PropertyNotLoadedException;
134137

135138
/**
136139
* 접속정보 설정을 추가한다.
137140
*
138141
* @param filePath
139142
* @return
143+
* @throws PropertyNotLoadedException
140144
*/
141-
String addConnectionInfoSetting(String filePath);
145+
String addConnectionInfoSetting(String filePath) throws PropertyNotLoadedException;
142146

143147
/**
144148
* 모니터링여부 Preset 설정을 추가한다.
145149
*
146150
* @param connInfoSetting
147151
* @param presetName
148152
*/
149-
void addMonitoringPreset(String connInfoSetting, String presetName);
153+
void addMonitoringPreset(String connInfoSetting, String presetName) throws PropertyNotLoadedException;
150154

151155
/**
152156
* 모니터링여부 Preset 설정을 저장한다.

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import root.common.server.implement.JschServer;
1818
import root.core.batch.DBCheckBatch;
1919
import root.core.batch.ServerCheckBatch;
20+
import root.core.domain.exceptions.PropertyNotLoadedException;
2021
import root.core.repository.constracts.DBCheckRepository;
2122
import root.core.repository.constracts.PropertyRepository;
2223
import root.core.repository.constracts.ServerMonitoringRepository;
@@ -98,8 +99,13 @@ public static void main(String[] args) throws IOException {
9899
while (true) {
99100
System.out.println(String.format("사용하실 모니터링여부 설정을 선택해주세요."));
100101

101-
List<String> presetNames = propService.getMonitoringPresetNameList();
102-
if (presetNames.size() == 0) {
102+
List<String> presetNames = null;
103+
try {
104+
presetNames = propService.getMonitoringPresetNameList();
105+
} catch (PropertyNotLoadedException e) {
106+
e.printStackTrace();
107+
}
108+
if (presetNames == null || presetNames.size() == 0) {
103109
System.out.println("모니터링여부 설정파일이 존재하지 않습니다. 프로그램을 종료합니다.");
104110
return;
105111
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import root.core.domain.enums.RoundingDigits;
4343
import root.core.domain.enums.UsageUIType;
4444
import root.core.domain.exceptions.PropertyNotFoundException;
45+
import root.core.domain.exceptions.PropertyNotLoadedException;
4546
import root.core.repository.constracts.DBCheckRepository;
4647
import root.core.repository.constracts.ServerMonitoringRepository;
4748
import root.core.service.contracts.PropertyService;
@@ -52,6 +53,7 @@
5253
import root.javafx.CustomView.CustomTreeTableView;
5354
import root.javafx.CustomView.CustomTreeView;
5455
import root.javafx.DI.DependencyInjection;
56+
import root.javafx.utils.AlertUtils;
5557
import root.javafx.utils.SceneUtils;
5658
import root.repository.implement.DBCheckRepositoryImpl;
5759
import root.repository.implement.LinuxServerMonitoringRepository;
@@ -226,7 +228,12 @@ public void runMonitoring(ActionEvent e) {
226228

227229
String connInfoConfigFilePath = connInfoFileListComboBox.getSelectionModel().getSelectedItem();
228230
String presetName = presetFileListComboBox.getSelectionModel().getSelectedItem();
229-
String presetConfigFilePath = propService.getMonitoringPresetFilePath(presetName);
231+
String presetConfigFilePath = null;
232+
try {
233+
presetConfigFilePath = propService.getMonitoringPresetFilePath(presetName);
234+
} catch (PropertyNotLoadedException e2) {
235+
AlertUtils.showPropertyNotLoadedAlert();
236+
}
230237
propService.loadConnectionInfoConfig(connInfoConfigFilePath);
231238
propService.loadMonitoringInfoConfig(presetConfigFilePath);
232239

@@ -345,7 +352,12 @@ private void initRunStep2() {
345352
// 2-1. 모니터링 여부 Preset 콤보박스 아이템 설정
346353
String curConnInfoFile = connInfoFileListComboBox.getSelectionModel().getSelectedItem();
347354
propService.loadMonitoringInfoConfig(curConnInfoFile);
348-
List<String> presetFileList = propService.getMonitoringPresetNameList();
355+
List<String> presetFileList = null;
356+
try {
357+
presetFileList = propService.getMonitoringPresetNameList();
358+
} catch (PropertyNotLoadedException e) {
359+
AlertUtils.showPropertyNotLoadedAlert();
360+
}
349361
if (presetFileList == null || presetFileList.size() == 0) {
350362
// TODO 모니터링 여부 Preset 설정파일이 없는 경우
351363
addMonitoringPresetPreview(new ArrayList<>(), new ArrayList<>());

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

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import root.core.domain.enums.MonitoringType;
3838
import root.core.domain.enums.RoundingDigits;
3939
import root.core.domain.enums.UsageUIType;
40+
import root.core.domain.exceptions.PropertyNotFoundException;
41+
import root.core.domain.exceptions.PropertyNotLoadedException;
4042
import root.core.service.contracts.PropertyService;
4143
import root.javafx.CustomView.ConnectionInfoVBox;
4244
import root.javafx.CustomView.DBConnInfoControl;
@@ -99,7 +101,12 @@ public void initialize(URL location, ResourceBundle resources) {
99101
// [설정] - [모니터링 여부 설정] - Preset 변경 Event
100102
monitoringPresetComboBox.valueProperty().addListener((options, oldValue, newValue) -> {
101103
if (newValue != null) {
102-
loadMonitoringConfigFile(propService.getMonitoringPresetFilePath(newValue));
104+
try {
105+
loadMonitoringConfigFile(propService.getMonitoringPresetFilePath(newValue));
106+
} catch (PropertyNotLoadedException e) {
107+
log.error(e.getMessage());
108+
AlertUtils.showPropertyNotLoadedAlert();
109+
}
103110
}
104111
});
105112
} else {
@@ -111,15 +118,25 @@ public void initialize(URL location, ResourceBundle resources) {
111118
fileSizeCB.getItems().addAll(FileSize.values());
112119
fileSizeCB.getSelectionModel().select(propService.getDefaultFileSizeUnit());
113120
fileSizeCB.valueProperty().addListener((options, oldValue, newValue) -> {
114-
propService.saveCommonConfig("unit.filesize", newValue.getUnit());
121+
try {
122+
propService.saveCommonConfig("unit.filesize", newValue.getUnit());
123+
} catch (PropertyNotLoadedException e) {
124+
log.error(e.getMessage());
125+
AlertUtils.showPropertyNotLoadedAlert();
126+
}
115127
});
116128

117129
/* 실행 설정 탭 - 반올림 자릿수 콤보박스 */
118130
// 반올림 자릿수 콤보박스 아이템 설정
119131
roundingDigitsCB.getItems().addAll(RoundingDigits.values());
120132
roundingDigitsCB.getSelectionModel().select(propService.getDefaultRoundingDigits());
121133
roundingDigitsCB.valueProperty().addListener((options, oldValue, newValue) -> {
122-
propService.saveCommonConfig("unit.rounding", String.valueOf(newValue.getDigits()));
134+
try {
135+
propService.saveCommonConfig("unit.rounding", String.valueOf(newValue.getDigits()));
136+
} catch (PropertyNotLoadedException e) {
137+
log.error(e.getMessage());
138+
AlertUtils.showPropertyNotLoadedAlert();
139+
}
123140
});
124141
roundingDigitsCB.setConverter(new StringConverter<RoundingDigits>() {
125142
@Override
@@ -137,7 +154,12 @@ public RoundingDigits fromString(String digits) {
137154
usageUICB.getItems().addAll(UsageUIType.values());
138155
usageUICB.getSelectionModel().select(propService.getDefaultUsageUIType());
139156
usageUICB.valueProperty().addListener((options, oldValue, newValue) -> {
140-
propService.saveCommonConfig("usage-ui-type", newValue.getCode());
157+
try {
158+
propService.saveCommonConfig("usage-ui-type", newValue.getCode());
159+
} catch (PropertyNotLoadedException e) {
160+
log.error(e.getMessage());
161+
AlertUtils.showPropertyNotLoadedAlert();
162+
}
141163
});
142164
usageUICB.setConverter(new StringConverter<UsageUIType>() {
143165
@Override
@@ -171,7 +193,12 @@ public void showMonitoringPresetPopup(ActionEvent e) {
171193
result.ifPresent(input -> {
172194
// TODO validate input value
173195
// 1. Preset명 이용하여 설정파일 생성 + 접속정보설정파일에 Preset 설정파일 경로 추가
174-
propService.addMonitoringPreset(fileChooserText.getText(), input);
196+
try {
197+
propService.addMonitoringPreset(fileChooserText.getText(), input);
198+
} catch (PropertyNotLoadedException e1) {
199+
log.error(e1.getMessage());
200+
AlertUtils.showPropertyNotLoadedAlert();
201+
}
175202

176203
// 3. 모니터링 여부 Config and Preset ComboBox 재로딩
177204
reloadingMonitoringSetting(input);
@@ -249,6 +276,7 @@ private void loadSelectedConfigFile(String absoluteFilePath) {
249276
* [설정] - [모니터링 여부 설정] - 모니터링 여부 설정파일을 불러온다.
250277
*
251278
* @param filePath
279+
* @throws PropertyNotFoundException
252280
*/
253281
private void loadMonitoringConfigFile(String filePath) {
254282
log.debug("Load monitoring config file: " + filePath);
@@ -347,9 +375,10 @@ private void createMonitoringElements(VBox rootVBox, List<MonitoringYN> dbYnList
347375

348376
/**
349377
* [설정] - 설정파일을 불러온 후, 동적 UI를 생성한다.
378+
* @throws PropertyNotFoundException
350379
*/
351380
@SuppressWarnings("unchecked")
352-
private void createSettingDynamicElements() {
381+
private void createSettingDynamicElements() throws PropertyNotFoundException {
353382

354383
List<JdbcConnectionInfo> jdbcConnInfoList = propService
355384
.getJdbcConnInfoList(propService.getMonitoringDBNameList());
@@ -392,14 +421,20 @@ private void createSettingDynamicElements() {
392421
* [설정] - [모니터링여부설정] - Preset을 다시 불러온다.
393422
*
394423
* @param curPresetName
424+
* @throws PropertyNotFoundException
395425
*/
396426
private void reloadingMonitoringSetting(String presetName) {
397427
// 최종 읽을 파일 경로
398428
String readPresetName = "";
399429

400430
// Preset Combo Clear
401431
monitoringPresetComboBox.getItems().clear();
402-
monitoringPresetComboBox.getItems().addAll(propService.getMonitoringPresetNameList());
432+
try {
433+
monitoringPresetComboBox.getItems().addAll(propService.getMonitoringPresetNameList());
434+
} catch (PropertyNotLoadedException e) {
435+
log.error(e.getMessage());
436+
AlertUtils.showPropertyNotLoadedAlert();
437+
}
403438

404439
// 지정된 Preset이 없다면 최근 사용된 Preset으로 세팅한다.
405440
// 만약 최근 사용된 Preset이 없다면 첫번째 Preset으로 세팅한다.
@@ -419,7 +454,12 @@ private void reloadingMonitoringSetting(String presetName) {
419454
// ComboBox 선택 및 Preset 파일 읽기
420455
if (!StringUtils.isEmpty(readPresetName)) {
421456
monitoringPresetComboBox.getSelectionModel().select(readPresetName);
422-
loadMonitoringConfigFile(propService.getMonitoringPresetFilePath(readPresetName));
457+
try {
458+
loadMonitoringConfigFile(propService.getMonitoringPresetFilePath(readPresetName));
459+
} catch (PropertyNotLoadedException e) {
460+
log.error(e.getMessage());
461+
AlertUtils.showPropertyNotLoadedAlert();
462+
}
423463
}
424464
}
425465

@@ -465,17 +505,22 @@ public void createNewConfigFile(ActionEvent e) {
465505
AlertUtils.showAlert(AlertType.ERROR, "접속정보 설정파일 생성", "설정파일명을 입력해주세요.");
466506
return;
467507
}
468-
469-
// TODO 입력값 검사 (영어만)
470-
// 1. 접속정보 설정파일 생성 + default 모니터링여부 Preset 설정파일 생성
471-
String newSettingFile = propService.addConnectionInfoSetting(input);
472-
473-
// 2. Set Node Visible
474-
setVisible(noConnInfoConfigAP, false);
475-
setVisible(noMonitoringConfigAP, false);
476-
477-
// 3. 생성된 설정파일 Load
478-
loadSelectedConfigFile(newSettingFile);
508+
509+
try {
510+
// TODO 입력값 검사 (영어만)
511+
// 1. 접속정보 설정파일 생성 + default 모니터링여부 Preset 설정파일 생성
512+
String newSettingFile = propService.addConnectionInfoSetting(input);
513+
514+
// 2. Set Node Visible
515+
setVisible(noConnInfoConfigAP, false);
516+
setVisible(noMonitoringConfigAP, false);
517+
518+
// 3. 생성된 설정파일 Load
519+
loadSelectedConfigFile(newSettingFile);
520+
} catch (PropertyNotLoadedException e1) {
521+
log.error(e1.getMessage());
522+
AlertUtils.showPropertyNotLoadedAlert();
523+
}
479524
});
480525
}
481526
}

DBMonitoringWindowApp/src/main/java/root/javafx/utils/AlertUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ public static void showAlert(AlertType alertType, String alertHeaderText, String
1313
alert.getDialogPane().getStyleClass().add("basic-font");
1414
alert.show();
1515
}
16+
17+
public static void showPropertyNotLoadedAlert() {
18+
showAlert(AlertType.ERROR, "설정파일 Load", "설정파일이 Load되지 않았습니다. 설정파일을 확인해주세요.");
19+
}
1620
}

0 commit comments

Comments
 (0)