Skip to content

Commit d3a5ab8

Browse files
committed
Change report file reading policy from daily monitoring report file to full-term monitoring report file
1 parent 33121bd commit d3a5ab8

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import root.core.domain.JdbcConnectionInfo;
2828
import root.core.domain.JschConnectionInfo;
2929
import root.core.domain.Log;
30+
import root.core.domain.MonitoringResult;
3031
import root.core.domain.OSDiskUsage;
3132
import root.core.domain.TableSpaceUsage;
3233
import root.core.repository.constracts.DBCheckRepository;
@@ -188,7 +189,7 @@ public void initialize(URL location, ResourceBundle resources) {
188189
* @param comboBoxItems
189190
* @param tableColumns
190191
*/
191-
private <T> void initAndAddMonitoringAnchorPane(String name,
192+
private <T extends MonitoringResult> void initAndAddMonitoringAnchorPane(String name,
192193
MonitoringAnchorPane<T> monitoringAP,
193194
AnchorPane parentAP, String labelText, String[] comboBoxItems,
194195
Map<String, TypeAndFieldName> tableColumns) {
@@ -287,9 +288,9 @@ public void runMonitoring(ActionEvent e) {
287288
db.init();
288289
DBCheckRepository repo = new DBCheckRepositoryImpl(db);
289290
DBCheckUsecase usecase = new DBCheckUsecaseImpl(repo, reportRepository);
290-
archiveUsageMAP.addTableDataSet(jdbc.getJdbcDBName(), usecase.getCurrentArchiveUsage().getMonitoringResults());
291-
tableSpaceUsageMAP.addTableDataSet(jdbc.getJdbcDBName(), usecase.getCurrentTableSpaceUsage().getMonitoringResults());
292-
asmDiskUsageMAP.addTableDataSet(jdbc.getJdbcDBName(), usecase.getCurrentASMDiskUsage().getMonitoringResults());
291+
archiveUsageMAP.addTableDataSet(jdbc.getJdbcDBName(), usecase.getCurrentArchiveUsage());
292+
tableSpaceUsageMAP.addTableDataSet(jdbc.getJdbcDBName(), usecase.getCurrentTableSpaceUsage());
293+
asmDiskUsageMAP.addTableDataSet(jdbc.getJdbcDBName(), usecase.getCurrentASMDiskUsage());
293294
db.uninit();
294295
}
295296

@@ -310,7 +311,7 @@ public void runMonitoring(ActionEvent e) {
310311
AlertLogCommand alc = new AlertLogCommand("tail", alertLogReadLine, alertLogFilePath, alertLogDateFormat, alertLogDateFormatRegex);
311312
AlertLogCommandPeriod alcp = new AlertLogCommandPeriod(alc, alertLogStartDay, alertLogEndDay);
312313

313-
osDiskUsageMAP.addTableDataSet(server.getServerName(), usecase.getCurrentOSDiskUsage().getMonitoringResults());
314+
osDiskUsageMAP.addTableDataSet(server.getServerName(), usecase.getCurrentOSDiskUsage());
314315
alertLogMonitoringResultMap.put(server.getServerName(), usecase.getAlertLogDuringPeriod(alcp));
315316
}
316317

src/main/java/root/javafx/CustomView/MonitoringAnchorPane.java

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package root.javafx.CustomView;
22

33
import java.io.File;
4-
import java.io.FileReader;
54
import java.io.IOException;
65
import java.time.LocalDate;
76
import java.time.format.DateTimeFormatter;
@@ -10,10 +9,10 @@
109
import java.util.HashMap;
1110
import java.util.List;
1211
import java.util.Map;
12+
import java.util.stream.Collectors;
1313

1414
import com.jfoenix.controls.JFXButton;
1515
import com.jfoenix.controls.JFXComboBox;
16-
import com.opencsv.bean.CsvToBeanBuilder;
1716

1817
import javafx.event.ActionEvent;
1918
import javafx.fxml.FXML;
@@ -29,13 +28,19 @@
2928
import lombok.EqualsAndHashCode;
3029
import lombok.extern.slf4j.Slf4j;
3130
import root.core.domain.ArchiveUsage;
31+
import root.core.domain.MonitoringResult;
32+
import root.core.repository.constracts.ReportRepository;
33+
import root.core.repository.implement.ReportRepositoryImpl;
3234
import root.javafx.Model.TypeAndFieldName;
3335
import root.utils.AlertUtils;
36+
import root.utils.CsvUtils;
3437

35-
@EqualsAndHashCode(callSuper= false)
38+
@EqualsAndHashCode(callSuper = false)
3639
@Data
3740
@Slf4j
38-
public class MonitoringAnchorPane<T> extends AnchorPane {
41+
public class MonitoringAnchorPane<T extends MonitoringResult> extends AnchorPane {
42+
43+
private ReportRepository reportRepository = ReportRepositoryImpl.getInstance();
3944

4045
@FXML
4146
Label label;
@@ -55,7 +60,7 @@ public class MonitoringAnchorPane<T> extends AnchorPane {
5560

5661
@FXML
5762
TableView<T> monitoringResultTV;
58-
63+
5964
@FXML
6065
DatePicker inquiryDatePicker;
6166

@@ -78,10 +83,10 @@ public MonitoringAnchorPane(Class<T> clazz) {
7883
monitoringResultTV.getItems().addAll(tableDataMap.get(newValue));
7984
}
8085
});
81-
86+
8287
// Setting inquiry datepicker initial value
8388
this.inquiryDatePicker.setValue(LocalDate.now().minusDays(1));
84-
89+
8590
} catch (IOException e) {
8691
}
8792
}
@@ -217,41 +222,43 @@ public void setAnchor(double left, double top, double right, double bottom) {
217222
* @param e
218223
*/
219224
public void run(ActionEvent e) {
220-
225+
221226
// Get selected inquiry condition
222227
String inquiryDate = this.inquiryDatePicker.getValue().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
223228
String selected = getComboBox().getSelectionModel().getSelectedItem();
224-
String fileRootDir = getReportFilePath() + selected + "/";
225-
File reportList = new File(fileRootDir);
229+
File reportFile = new File(getReportFilePath() + "/" + selected + ".txt");
230+
231+
if (!reportFile.exists()) {
232+
AlertUtils.showAlert(AlertType.INFORMATION, "조회결과 없음", String.format("%s 의 모니터링 기록이 없습니다.", selected));
233+
return;
234+
}
235+
236+
// TODO Show Progress UI
226237

227238
// Clear data
228239
clearTableData(selected);
229240

230241
// Read csv report file and add table data
231-
List<T> tableDataList = new ArrayList<>();
232-
for (String fileName : reportList.list()) {
233-
234-
if(!fileName.startsWith(inquiryDate)) {
235-
continue;
236-
}
237-
238-
String filePath = fileRootDir + fileName;
239-
File reportFile = new File(filePath);
240-
241-
List<T> data = parseCsvReportFile(reportFile);
242-
if (data != null) {
243-
tableDataList.addAll(data);
244-
}
242+
List<T> allDataList = parseCsvReportFile(reportFile);
243+
if (allDataList == null) {
244+
AlertUtils.showAlert(AlertType.ERROR, "모니터링 기록 조회", "모니터링 기록 조회에 실패했습니다.\n데이터를 확인해주세요.");
245+
return;
245246
}
246247

248+
// Find data on inquiry date
249+
List<T> tableDataList = allDataList.stream()
250+
.filter(data -> data.getMonitoringDate().equals(inquiryDate))
251+
.collect(Collectors.toList());
252+
247253
if (tableDataList.size() == 0) {
248254
AlertUtils.showAlert(AlertType.INFORMATION, "조회결과 없음", "해당일자의 모니터링 기록이 없습니다.");
249255
}
250256

257+
// Add and Sync data
251258
addTableDataSet(selected, tableDataList);
252259
syncTableData(selected);
253260
}
254-
261+
255262
/**
256263
* csv 파일을 읽어 Model 객체로 변환한다.
257264
*
@@ -260,22 +267,20 @@ public void run(ActionEvent e) {
260267
*/
261268
private List<T> parseCsvReportFile(File file) {
262269
List<T> result = null;
270+
263271
try {
272+
List<String> headers = reportRepository.getReportHeaders(file);
273+
String csvString = reportRepository.getReportContentsInCsv(file);
264274

265-
result = new CsvToBeanBuilder<T>(new FileReader(file))
266-
.withSkipLines(1)
267-
.withSeparator(',')
268-
.withIgnoreEmptyLine(true)
269-
.withType(getClazz())
270-
.build()
271-
.parse();
272-
275+
result = CsvUtils.parseCsvToBeanList(headers, csvString, getClazz());
276+
273277
} catch (Exception e) {
274278
log.error("Parsing error!" + file);
275279
}
280+
276281
return result;
277282
}
278-
283+
279284
/**
280285
* 현재 선택된 조회조건으로 재검색한다.
281286
*
@@ -284,13 +289,13 @@ private List<T> parseCsvReportFile(File file) {
284289
public void refresh(ActionEvent e) {
285290
run(e);
286291
}
287-
292+
288293
/**
289294
* 현재 TableView에 세팅된 값을 Excel파일로 다운로드한다.
290295
*
291296
* @param e
292297
*/
293298
public void excelDownload(ActionEvent e) {
294-
299+
295300
}
296301
}

0 commit comments

Comments
 (0)