|
| 1 | +package root.javafx.Controller; |
| 2 | + |
| 3 | +import java.net.URL; |
| 4 | +import java.time.LocalDate; |
| 5 | +import java.util.HashMap; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Map; |
| 8 | +import java.util.ResourceBundle; |
| 9 | + |
| 10 | +import com.jfoenix.controls.JFXComboBox; |
| 11 | +import com.jfoenix.controls.JFXListView; |
| 12 | + |
| 13 | +import javafx.event.ActionEvent; |
| 14 | +import javafx.fxml.FXML; |
| 15 | +import javafx.fxml.Initializable; |
| 16 | +import javafx.scene.control.Alert.AlertType; |
| 17 | +import javafx.scene.control.DatePicker; |
| 18 | +import root.common.server.implement.JschServer; |
| 19 | +import root.core.domain.AlertLog; |
| 20 | +import root.core.domain.AlertLogCommandPeriod; |
| 21 | +import root.core.domain.JschConnectionInfo; |
| 22 | +import root.core.domain.Log; |
| 23 | +import root.core.repository.constracts.ServerCheckRepository; |
| 24 | +import root.core.repository.implement.PropertyRepositoryImpl; |
| 25 | +import root.core.repository.implement.ReportFileRepo; |
| 26 | +import root.core.repository.implement.ServerCheckRepositoryImpl; |
| 27 | +import root.core.service.contracts.PropertyService; |
| 28 | +import root.core.service.implement.FilePropertyService; |
| 29 | +import root.core.usecase.constracts.ServerCheckUsecase; |
| 30 | +import root.core.usecase.implement.ServerCheckUsecaseImpl; |
| 31 | +import root.javafx.CustomView.AlertLogListViewCell; |
| 32 | +import root.javafx.CustomView.dateCell.DisableAfterTodayDateCell; |
| 33 | +import root.utils.AlertUtils; |
| 34 | + |
| 35 | +public class AlertLogMonitoringMenuController implements Initializable { |
| 36 | + |
| 37 | + /* Dependency Injection */ |
| 38 | + PropertyService propService; |
| 39 | + |
| 40 | + /* View Binding */ |
| 41 | + @FXML |
| 42 | + JFXComboBox<String> runConnInfoFileComboBox; |
| 43 | + |
| 44 | + @FXML |
| 45 | + JFXComboBox<String> alertLogServerComboBox; |
| 46 | + |
| 47 | + @FXML |
| 48 | + DatePicker alertLogStartDayDP; |
| 49 | + |
| 50 | + @FXML |
| 51 | + DatePicker alertLogEndDayDP; |
| 52 | + |
| 53 | + @FXML |
| 54 | + JFXListView<Log> alertLogLV; |
| 55 | + |
| 56 | + Map<String, AlertLog> alertLogMonitoringResultMap; |
| 57 | + |
| 58 | + public AlertLogMonitoringMenuController() { |
| 59 | + this.propService = new FilePropertyService(PropertyRepositoryImpl.getInstance()); |
| 60 | + this.alertLogMonitoringResultMap = new HashMap<>(); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * 실행메뉴 화면 진입시 초기화를 수행한다. |
| 65 | + */ |
| 66 | + @Override |
| 67 | + public void initialize(URL location, ResourceBundle resources) { |
| 68 | + |
| 69 | + // 접속정보 설정 프로퍼티 파일 |
| 70 | + List<String> connInfoFiles = propService.getConnectionInfoList(); |
| 71 | + if (connInfoFiles != null && connInfoFiles.size() != 0) { |
| 72 | + // Connection Info ComboBox |
| 73 | + runConnInfoFileComboBox.getItems().addAll(connInfoFiles); |
| 74 | + runConnInfoFileComboBox.getSelectionModel().selectFirst(); |
| 75 | + |
| 76 | + // remember.properties 파일에서, 최근 사용된 설정파일 경로가 있다면 해당 설정파일을 불러온다. |
| 77 | + String lastUseConnInfoFilePath = propService.getLastUseConnectionInfoFilePath(); |
| 78 | + if (lastUseConnInfoFilePath != null) { |
| 79 | + runConnInfoFileComboBox.getSelectionModel().select(lastUseConnInfoFilePath); |
| 80 | + } |
| 81 | + } else { |
| 82 | + AlertUtils.showAlert(AlertType.INFORMATION, "접속정보 설정", "설정된 접속정보가 없습니다.\n[설정]메뉴로 이동합니다."); |
| 83 | + return; |
| 84 | + } |
| 85 | + |
| 86 | + // ComboBox 변경 이벤트 |
| 87 | + runConnInfoFileComboBox.getSelectionModel().selectedItemProperty() |
| 88 | + .addListener((options, oldValue, newValue) -> { |
| 89 | + // TODO 각 Tab별 콤보박스 아이템 변경 |
| 90 | + }); |
| 91 | + |
| 92 | + // AlertLog 화면의 UI 요소를 초기화한다. |
| 93 | + initAlertLogMonitoringElements(); |
| 94 | + } |
| 95 | + |
| 96 | + private void changeAlertLogListViewData(String serverID) { |
| 97 | + alertLogLV.getItems().clear(); |
| 98 | + AlertLog al = alertLogMonitoringResultMap.get(serverID); |
| 99 | + if (al != null) { |
| 100 | + alertLogLV.getItems().addAll(al.getAlertLogs()); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * AlertLog AnchorPane의 UI 요소들의 값을 초기화한다. |
| 106 | + */ |
| 107 | + private void initAlertLogMonitoringElements() { |
| 108 | + // ComboBox 변경 이벤트 |
| 109 | + alertLogServerComboBox.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> { |
| 110 | + changeAlertLogListViewData(newValue); |
| 111 | + }); |
| 112 | + alertLogServerComboBox.getItems().addAll(propService.getMonitoringServerNameList()); |
| 113 | + alertLogServerComboBox.getSelectionModel().selectFirst(); |
| 114 | + |
| 115 | + // AlertLog 조회기간 기본값 설정 |
| 116 | + alertLogStartDayDP.setValue(LocalDate.now().minusDays(1)); |
| 117 | + alertLogEndDayDP.setValue(LocalDate.now()); |
| 118 | + |
| 119 | + // AlertLog 조회기간 오늘 이후 날짜 선택 불가 |
| 120 | + alertLogStartDayDP.setDayCellFactory(picker -> new DisableAfterTodayDateCell()); |
| 121 | + alertLogEndDayDP.setDayCellFactory(picker -> new DisableAfterTodayDateCell()); |
| 122 | + |
| 123 | + // AlertLog 조회기간 변경 이벤트 |
| 124 | + alertLogStartDayDP.valueProperty().addListener((ov, oldValue, newValue) -> { |
| 125 | + if (alertLogEndDayDP.getValue().isBefore(newValue)) { |
| 126 | + alertLogEndDayDP.setValue(newValue); |
| 127 | + } |
| 128 | + }); |
| 129 | + alertLogEndDayDP.valueProperty().addListener((ov, oldValue, newValue) -> { |
| 130 | + if (alertLogStartDayDP.getValue().isAfter(newValue)) { |
| 131 | + alertLogStartDayDP.setValue(newValue); |
| 132 | + } |
| 133 | + }); |
| 134 | + |
| 135 | + // AlertLog ListView |
| 136 | + alertLogLV.setCellFactory(categoryList -> new AlertLogListViewCell()); |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * [실행] - 모니터링 실행 시, 입력값 검사 |
| 141 | + * |
| 142 | + * @return |
| 143 | + */ |
| 144 | + private boolean validateInput() { |
| 145 | + String alertHeaderText = ""; |
| 146 | + String alertContentText = ""; |
| 147 | + |
| 148 | + // 1. AlertLog 조회기간 |
| 149 | + alertHeaderText = "AlertLog 조회기간"; |
| 150 | + |
| 151 | + LocalDate alertLogStartDay = alertLogStartDayDP.getValue(); |
| 152 | + LocalDate alertLogEndDay = alertLogEndDayDP.getValue(); |
| 153 | + if (alertLogStartDay == null || alertLogEndDay == null) { |
| 154 | + alertContentText = "조회기간을 입력해주세요."; |
| 155 | + AlertUtils.showAlert(AlertType.ERROR, alertHeaderText, alertContentText); |
| 156 | + return false; |
| 157 | + } |
| 158 | + |
| 159 | + try { |
| 160 | + if (!alertLogStartDay.isBefore(alertLogEndDay) && !alertLogStartDay.isEqual(alertLogEndDay)) { |
| 161 | + alertContentText = "조회시작일은 조회종료일보다 이전 날짜여야 합니다."; |
| 162 | + AlertUtils.showAlert(AlertType.ERROR, alertHeaderText, alertContentText); |
| 163 | + return false; |
| 164 | + } |
| 165 | + } catch (Exception e) { |
| 166 | + alertContentText = "조회기간이 올바르지 않습니다."; |
| 167 | + AlertUtils.showAlert(AlertType.ERROR, alertHeaderText, alertContentText); |
| 168 | + return false; |
| 169 | + } |
| 170 | + |
| 171 | + return true; |
| 172 | + } |
| 173 | + |
| 174 | + public void monitoringAlertLog(ActionEvent e) { |
| 175 | + // 입력값 검사 |
| 176 | + if (!validateInput()) { |
| 177 | + return; |
| 178 | + } |
| 179 | + |
| 180 | + String alertLogStartDay = alertLogStartDayDP.getValue().toString(); |
| 181 | + String alertLogEndDay = alertLogEndDayDP.getValue().toString(); |
| 182 | + |
| 183 | + String selectedServer = alertLogServerComboBox.getSelectionModel().getSelectedItem(); |
| 184 | + JschConnectionInfo connInfo = propService.getJschConnInfo(selectedServer); |
| 185 | + |
| 186 | + JschServer server = new JschServer(connInfo); |
| 187 | + server.init(); |
| 188 | + ServerCheckRepository repo = new ServerCheckRepositoryImpl(server); |
| 189 | + ServerCheckUsecase usecase = new ServerCheckUsecaseImpl(repo, ReportFileRepo.getInstance()); |
| 190 | + |
| 191 | + AlertLogCommandPeriod alcp = new AlertLogCommandPeriod(connInfo.getAlc(), alertLogStartDay, alertLogEndDay); |
| 192 | + alertLogMonitoringResultMap.put(selectedServer, usecase.getAlertLogDuringPeriod(alcp)); |
| 193 | + |
| 194 | + changeAlertLogListViewData(alertLogServerComboBox.getSelectionModel().getSelectedItem()); |
| 195 | + } |
| 196 | +} |
0 commit comments