|
| 1 | +package root.javafx.CustomView; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.net.URL; |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.List; |
| 7 | +import java.util.ResourceBundle; |
| 8 | + |
| 9 | +import javafx.beans.property.SimpleDoubleProperty; |
| 10 | +import javafx.beans.property.SimpleIntegerProperty; |
| 11 | +import javafx.collections.FXCollections; |
| 12 | +import javafx.fxml.FXML; |
| 13 | +import javafx.fxml.FXMLLoader; |
| 14 | +import javafx.fxml.Initializable; |
| 15 | +import javafx.scene.control.Label; |
| 16 | +import javafx.scene.control.ListView; |
| 17 | +import javafx.scene.control.TableColumn; |
| 18 | +import javafx.scene.control.TableView; |
| 19 | +import javafx.scene.layout.AnchorPane; |
| 20 | +import lombok.Data; |
| 21 | +import lombok.extern.slf4j.Slf4j; |
| 22 | +import root.core.domain.AlertLog; |
| 23 | +import root.core.domain.Log; |
| 24 | +import root.javafx.DI.DependencyInjection; |
| 25 | + |
| 26 | +@Slf4j |
| 27 | +public class AlertLogMonitoringSummaryAP extends AnchorPane implements Initializable { |
| 28 | + |
| 29 | + @FXML |
| 30 | + Label alertLogFileLB; |
| 31 | + |
| 32 | + @FXML |
| 33 | + private TableView<AlertLogSummary> summaryTV; |
| 34 | + |
| 35 | + @FXML |
| 36 | + private TableColumn<AlertLogSummary, Integer> totalCL; |
| 37 | + |
| 38 | + @FXML |
| 39 | + private TableColumn<AlertLogSummary, Integer> normalCL; |
| 40 | + |
| 41 | + @FXML |
| 42 | + private TableColumn<AlertLogSummary, Integer> errorCL; |
| 43 | + |
| 44 | + @FXML |
| 45 | + private TableColumn<AlertLogSummary, Double> errorRateCL; |
| 46 | + |
| 47 | + @FXML |
| 48 | + private ListView<Log> errorLogLV; |
| 49 | + |
| 50 | + private AlertLog alertLog; |
| 51 | + |
| 52 | + private List<Log> errorLogs = new ArrayList<>(); |
| 53 | + |
| 54 | + public AlertLogMonitoringSummaryAP(AlertLog alertLog) { |
| 55 | + this.alertLog = alertLog; |
| 56 | + try { |
| 57 | + FXMLLoader loader = DependencyInjection.getLoader("/fxml/AlertLogMonitoringSummary.fxml"); |
| 58 | + loader.setController(this); |
| 59 | + loader.setRoot(this); |
| 60 | + loader.load(); |
| 61 | + } catch (IOException e) { |
| 62 | + log.error(e.getMessage()); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public void initialize(URL location, ResourceBundle resources) { |
| 68 | + // Set cell value factory of summary table column |
| 69 | + totalCL.setCellValueFactory(cellData -> cellData.getValue().getTotalLogCount().asObject()); |
| 70 | + normalCL.setCellValueFactory(cellData -> cellData.getValue().getNormalLogCount().asObject()); |
| 71 | + errorCL.setCellValueFactory(cellData -> cellData.getValue().getErrorLogCount().asObject()); |
| 72 | + errorRateCL.setCellValueFactory(cellData -> cellData.getValue().getErrorRate().asObject()); |
| 73 | + |
| 74 | + // Set cell factory of error log listview |
| 75 | + errorLogLV.setCellFactory(categoryList -> new AlertLogListViewCell()); |
| 76 | + |
| 77 | + render(); |
| 78 | + } |
| 79 | + |
| 80 | + private void render() { |
| 81 | + // Set Alert log file path label text |
| 82 | + alertLogFileLB.setText(alertLog.getFilePath()); |
| 83 | + |
| 84 | + // Set summary tableview value |
| 85 | + summaryTV.setItems(FXCollections.observableArrayList(List.of(getSummaryData()))); |
| 86 | + |
| 87 | + errorLogLV.getItems().addAll(errorLogs); |
| 88 | + } |
| 89 | + |
| 90 | + private AlertLogSummary getSummaryData() { |
| 91 | + int total = 0; |
| 92 | + int normal = 0; |
| 93 | + int error = 0; |
| 94 | + |
| 95 | + for (Log l : alertLog.getAlertLogs()) { |
| 96 | + total++; |
| 97 | + boolean isErrorLog = false; |
| 98 | + for (String s : l.getLogContents()) { |
| 99 | + // TODO Remove hard-coding that identifying error log |
| 100 | + if (s.contains("ORA-")) { |
| 101 | + isErrorLog = true; |
| 102 | + break; |
| 103 | + } |
| 104 | + } |
| 105 | + if (isErrorLog) { |
| 106 | + error++; |
| 107 | + errorLogs.add(l); |
| 108 | + } else { |
| 109 | + normal++; |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + return new AlertLogSummary(total, normal, error); |
| 114 | + } |
| 115 | + |
| 116 | + @Data |
| 117 | + private static class AlertLogSummary { |
| 118 | + private SimpleIntegerProperty totalLogCount; |
| 119 | + private SimpleIntegerProperty normalLogCount; |
| 120 | + private SimpleIntegerProperty errorLogCount; |
| 121 | + private SimpleDoubleProperty errorRate; |
| 122 | + |
| 123 | + public AlertLogSummary(int totalLogCount, int normalLogCount, int errorLogCount) { |
| 124 | + double rate = (double) Math.round((errorLogCount / (double) totalLogCount * 100) * 100) / 100; |
| 125 | + |
| 126 | + this.totalLogCount = new SimpleIntegerProperty(totalLogCount); |
| 127 | + this.normalLogCount = new SimpleIntegerProperty(normalLogCount); |
| 128 | + this.errorLogCount = new SimpleIntegerProperty(errorLogCount); |
| 129 | + this.errorRate = new SimpleDoubleProperty(rate); |
| 130 | + } |
| 131 | + } |
| 132 | +} |
0 commit comments