Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarczuz committed May 14, 2019
1 parent a772690 commit 7ac95d2
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 112 deletions.
1 change: 1 addition & 0 deletions .~lock.new.xlsx#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,chjunchi,chjunchi-U45JC,14.05.2019 14:34,file:///home/chjunchi/snap/libreoffice/117/.config/libreoffice/4;
1 change: 0 additions & 1 deletion .~lock.temp.xlsx#

This file was deleted.

Binary file added new.db
Binary file not shown.
Binary file added new.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static void createNewTable() {
String sql3 = "CREATE TABLE IF NOT EXISTS roletoplay (id integer PRIMARY KEY,kind text NOT NULL, kindid integer NOT NULL, role text NOT NULL, roleid integer NOT NULL);";
String sql4 = "CREATE TABLE IF NOT EXISTS relator (id integer PRIMARY KEY,relator text NOT NULL);";
String sql5 = "CREATE TABLE IF NOT EXISTS relatortorole (id integer PRIMARY KEY, relator text NOT NULL, relatorid integer NOT NULL, role TEXT NOT NULL, roleid INTEGER NOT NULL);";
String sql6 = "CREATE TABLE IF NOT EXISTS hazard (id INTEGER PRIMARY KEY, hazard TEXT NOT NULL, harm TEXT NOT NULL, severity REAL, probability REAL, riskevaluation REAL, risk BIT);";
String sql7 = "CREATE TABLE IF NOT EXISTS cause (id INTEGER PRIMARY KEY, cause TEXT NOT NULL, hazardid INTEGER NOT NULL);";
String sql6 = "CREATE TABLE IF NOT EXISTS hazard (id INTEGER PRIMARY KEY, hazard TEXT NOT NULL, harm TEXT NOT NULL);";
String sql7 = "CREATE TABLE IF NOT EXISTS cause (id INTEGER PRIMARY KEY, cause TEXT NOT NULL, hazardid INTEGER NOT NULL, severity REAL, probability REAL, riskevaluation REAL, risk BIT);";
String sql8 = "CREATE TABLE IF NOT EXISTS mitigation (id INTEGER PRIMARY KEY, mitigation TEXT NOT NULL, hazardid INTEGER NOT NULL);";
try (Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement()) {
// create a new table
Expand Down
106 changes: 38 additions & 68 deletions src/main/java/hazard/HazardAnalysis/DataBase/DataBaseConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ public static void exportData(File file) {
headerCellCause = headerCause.createCell(1);
headerCellCause.setCellValue("Pre-Initiating event for H" + (index - 1));
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(2);
headerCellCause.setCellValue("Probability");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(3);
headerCellCause.setCellValue("Severity");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(4);
headerCellCause.setCellValue("RPN");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(5);
headerCellCause.setCellValue("Risk");
headerCellCause.setCellStyle(headerStyle);
Statement stmt2 = conn.createStatement();
String sql2 = "select * from hazard,cause where cause.hazardid=" + rs.getInt("id") + " AND hazard.id="
+ rs.getInt("id") + ";";
Expand All @@ -173,53 +185,28 @@ public static void exportData(File file) {
cellCauses = causes.createCell(1);
cellCauses.setCellValue(rs2.getString("cause"));
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(2);
cellCauses.setCellValue(rs2.getString("probability"));
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(3);
cellCauses.setCellValue(rs2.getString("severity"));
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(4);
cellCauses.setCellValue(rs2.getString("riskevaluation"));
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(5);
String risk = "Denied";
CellStyle styleRisk = workbook.createCellStyle();
styleRisk.setFillPattern(FillPatternType.SOLID_FOREGROUND);
if (rs2.getBoolean("risk")) {
risk = "Accept";
styleRisk.setFillForegroundColor(IndexedColors.GREEN.getIndex());
} else {
styleRisk.setFillForegroundColor(IndexedColors.RED.getIndex());
}
cellCauses.setCellValue(risk);
cellCauses.setCellStyle(styleRisk);
}
Statement stmt3 = conn.createStatement();
String sql3 = "select * from hazard where hazard.id=" + rs.getInt("id") + ";";
ResultSet rs3 = stmt3.executeQuery(sql3);
Row severityAndProbability = sheet.createRow(rowIndex);
rowIndex++;
Cell headerCellSAP = severityAndProbability.createCell(0);
headerCellSAP.setCellValue("Severity");
headerCellSAP.setCellStyle(headerStyle);
headerCellSAP = severityAndProbability.createCell(1);
headerCellSAP.setCellValue("Probability");
headerCellSAP.setCellStyle(headerStyle);
Row sapRow = sheet.createRow(rowIndex);
rowIndex++;
Cell sapCell = sapRow.createCell(0);
sapCell.setCellValue(rs3.getString("severity"));
sapCell.setCellStyle(style);
sapCell = sapRow.createCell(1);
sapCell.setCellValue(rs3.getString("probability"));
sapCell.setCellStyle(style);
Row riskRow = sheet.createRow(rowIndex);
rowIndex++;
Cell headerCellRisk = riskRow.createCell(0);
headerCellRisk.setCellValue("Risk Evaluation");
headerCellRisk.setCellStyle(headerStyle);
headerCellRisk = riskRow.createCell(1);
headerCellRisk.setCellValue("Risk");
headerCellRisk.setCellStyle(headerStyle);
Row riskValueRow = sheet.createRow(rowIndex);
rowIndex++;
Cell riskValueCell = riskValueRow.createCell(0);
riskValueCell.setCellValue(rs3.getString("riskevaluation"));
riskValueCell.setCellStyle(style);
riskValueCell = riskValueRow.createCell(1);
CellStyle styleRisk = workbook.createCellStyle();
styleRisk.setWrapText(false);
styleRisk.setFillPattern(FillPatternType.SOLID_FOREGROUND);
String risk = "Denied";
if (rs3.getBoolean("risk")) {
risk = "Accept";
styleRisk.setFillForegroundColor(IndexedColors.GREEN.getIndex());
} else {
styleRisk.setFillForegroundColor(IndexedColors.RED.getIndex());
}
riskValueCell.setCellValue(risk);
riskValueCell.setCellStyle(styleRisk);
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
Row headerMitigation = sheet.createRow(rowIndex);
rowIndex++;
Cell headerCellMitigation = headerMitigation.createCell(0);
Expand Down Expand Up @@ -342,24 +329,6 @@ public static void insertRoloeOrKind(String table, String name, Boolean start, b
}
}

public static void populateWithTestData() {
insertRoloeOrKind("role", "Being supported", true, false, true);
insertRoloeOrKind("role", "Being lifted", true, false, true);
insertRoloeOrKind("role", "Balance supporter", true, false, true);
insertRoloeOrKind("role", "Object lifter", true, false, true);
insertRoloeOrKind("role", "Electric consumer", true, false, true);
insertRoloeOrKind("role", "Electricity source", true, false, true);
insertRoloeOrKind("kind", "Patient", true, false, true);
insertRoloeOrKind("kind", "Robot Handle", true, false, true);
insertRoloeOrKind("kind", "Robot", true, false, true);
insertRoloeOrKind("kind", "Battery", true, false, true);
insertRelator("relator", "Balance support");
insertRelator("relator", "Liftup");
insertRelator("relator", "Electric consumption");
insert("INSERT INTO roletoplay (role,roleid,kind,kindid) VALUES('Being supported',0,'Patient',0)");
insert("INSERT INTO roletoplay (role,roleid,kind,kindid) VALUES('Being lifted',1,'Patient',0)");
}

@SuppressWarnings("unchecked")
public static <E> void selectAll(String table, ObservableList<E> list) {
String sql = "SELECT * FROM " + table;
Expand Down Expand Up @@ -428,13 +397,14 @@ public static <E> void sql(String sql, String table, ObservableList<E> list) {
rs.getString(5)));
} else if (table.contentEquals("hazard")) {
Hazard hz = new Hazard(rs.getInt("id"), rs.getString("hazard"), rs.getString("harm"));
list.add((E) hz);
} else if (table.contentEquals("cause")) {
Cause c = new Cause(rs.getInt("id"), rs.getString("cause"), rs.getInt("hazardid"));
Double d = rs.getDouble("riskevaluation");
if (d != 0) {
hz.setRisk(String.valueOf(rs.getBoolean("risk")));
c.setRisk(String.valueOf(rs.getBoolean("risk")));
}
list.add((E) hz);
} else if (table.contentEquals("cause")) {
list.add((E) new Cause(rs.getInt("id"), rs.getString("cause"), rs.getInt("hazardid")));
list.add((E) c);
} else if (table.contentEquals("mitigation")) {
list.add((E) new Mitigation(rs.getInt("id"), rs.getString("mitigation"), rs.getInt("hazardid")));
}
Expand Down
70 changes: 37 additions & 33 deletions src/main/java/hazard/HazardAnalysis/Steps/Views/ViewStep7.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ private void addClickEventToTbHazard(TableView<Hazard> tbHazard, ObservableList<
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
int index = tbHazard.getSelectionModel().selectedIndexProperty().get();
if (index > -1) {
int id = tbHazard.getItems().get(index).getId();
DataBaseConnection.sql("SELECT * FROM cause WHERE cause.hazardid=" + id + ";", "cause", list);
}
updateCauseList(tbHazard,list);
}
};
tbHazard.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
Expand All @@ -66,12 +62,29 @@ public GridPane addGridPane() {
id.setCellValueFactory(new PropertyValueFactory<Hazard, Integer>("id"));
hazard.setCellValueFactory(new PropertyValueFactory<Hazard, String>("hazard"));
hazardDescription.setCellValueFactory(new PropertyValueFactory<Hazard, String>("hazardDescription"));
tbHazard.setRowFactory(new Callback<TableView<Hazard>, TableRow<Hazard>>() {

tbHazard.getColumns().addAll(id, hazard, hazardDescription);
addClickEventToTbHazard(tbHazard, causeList);
updateHazardList();
tbHazard.setItems(hazardList);
grid.add(tbHazard, 0, 1);
Text category2 = new Text("Pre-initiating events that might lead to the hazard");
category2.getStyleClass().add("heading");
grid.add(category2, 0, 3);
final TableView<Cause> tbCause = new TableView<Cause>();
tbCause.setMinWidth(800);
tbCause.setMaxHeight(200);
TableColumn<Cause, String> cause = new TableColumn<Cause, String>("Pre-initiating event for hazard");
cause.setMinWidth(400);
cause.setCellValueFactory(new PropertyValueFactory<Cause, String>("cause"));
tbCause.getColumns().addAll(cause);
tbCause.setItems(causeList);
tbCause.setRowFactory(new Callback<TableView<Cause>, TableRow<Cause>>() {
@Override
public TableRow<Hazard> call(TableView<Hazard> param) {
final TableRow<Hazard> row = new TableRow<Hazard>() {
public TableRow<Cause> call(TableView<Cause> param) {
final TableRow<Cause> row = new TableRow<Cause>() {
@Override
protected void updateItem(Hazard item, boolean empty) {
protected void updateItem(Cause item, boolean empty) {
super.updateItem(item, empty);
if (!hazardList.isEmpty() && !empty) {
if (!item.getRisk().isEmpty()) {
Expand All @@ -87,43 +100,27 @@ protected void updateItem(Hazard item, boolean empty) {
return row;
}
});
tbHazard.getColumns().addAll(id, hazard, hazardDescription);
addClickEventToTbHazard(tbHazard, causeList);
updateHazardList();
tbHazard.setItems(hazardList);
grid.add(tbHazard, 0, 1);
Text category2 = new Text("Pre-initiating events that might lead to the hazard");
category2.getStyleClass().add("heading");
grid.add(category2, 0, 3);
final TableView<Cause> tbCause = new TableView<Cause>();
tbCause.setMinWidth(800);
tbCause.setMaxHeight(200);
TableColumn<Cause, String> cause = new TableColumn<Cause, String>("Pre-initiating event for hazard");
cause.setMinWidth(400);
cause.setCellValueFactory(new PropertyValueFactory<Cause, String>("cause"));
tbCause.getColumns().addAll(cause);
tbCause.setItems(causeList);
grid.add(tbCause, 0, 4);
Button btnAdd = new Button("Add Severity And Probability");
addSeverityAndProbabilityEvent(btnAdd, tbHazard);
addSeverityAndProbabilityEvent(btnAdd, tbCause,tbHazard);
GridPane gridBtn1 = new GridPane();
gridBtn1.add(btnAdd, 0, 0);
grid.add(gridBtn1, 0, 2);
return grid;
}

private void addSeverityAndProbabilityEvent(Button btnAdd, TableView<Hazard> tbHazard) {
private void addSeverityAndProbabilityEvent(Button btnAdd, TableView<Cause> tbCause, TableView<Hazard> tbHazard) {
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
int index = tbHazard.getSelectionModel().getSelectedIndex();
int index = tbCause.getSelectionModel().getSelectedIndex();
if (index < 0) {
return;
}
int id = tbHazard.getItems().get(index).getId();
int id = tbCause.getItems().get(index).getId();
TextInputDialog dialog = new TextInputDialog("");
dialog.setTitle("Add Severity And Probability");
dialog.setHeaderText("Enter the Severity of the Hazard And the Probability of it happening.");
dialog.setHeaderText("Enter the Severity of the Cause And the Probability of it happening.");
ObservableList<String> options = FXCollections.observableArrayList("High-75%", "Medium-50%", "Low-25%");
final ComboBox<String> comboBox = new ComboBox<String>(options);
ObservableList<String> options2 = FXCollections.observableArrayList("High-75%", "Medium-50%",
Expand Down Expand Up @@ -166,12 +163,12 @@ public void changed(ObservableValue ov, String t, String t1) {
});
Optional<String> op = dialog.showAndWait();
if (op.isPresent() && !riskEvaluationNr.getText().contentEquals("")) {
DataBaseConnection.sqlUpdate("UPDATE hazard SET severity=" + returnRiskValue(comboBox.getValue())
DataBaseConnection.sqlUpdate("UPDATE cause SET severity=" + returnRiskValue(comboBox.getValue())
+ ", probability=" + returnRiskValue(comboBox2.getValue()) + ", riskevaluation="
+ (returnRiskValue(comboBox2.getValue()) * returnRiskValue(comboBox.getValue())) + ", risk="
+ ch.isSelected() + " where hazard.id=" + id + ";");
+ ch.isSelected() + " where cause.id=" + id + ";");
}
updateHazardList();
updateCauseList(tbHazard, causeList);
}
};
btnAdd.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
Expand Down Expand Up @@ -206,4 +203,11 @@ private Double returnRiskValue(String s) {
public void updateHazardList() {
DataBaseConnection.sql("SELECT * FROM hazard;", "hazard", hazardList);
}
public void updateCauseList(TableView<Hazard> tbHazard, ObservableList<Cause> list) {
int index = tbHazard.getSelectionModel().selectedIndexProperty().get();
if (index > -1) {
int id = tbHazard.getItems().get(index).getId();
DataBaseConnection.sql("SELECT * FROM cause WHERE cause.hazardid=" + id + ";", "cause", list);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/hazard/HazardClasses/Cause.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
public class Cause extends Play {
private String cause;
private int hazardID;
String risk;

public Cause(int id, String cause, int hazardID) {
super(id);
this.cause = cause;
this.hazardID = hazardID;
this.risk = "";
}

public String getRisk() {
return risk;
}

public void setRisk(String risk) {
this.risk = risk;
}

public String getCause() {
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/hazard/HazardClasses/Hazard.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
public class Hazard extends Play {
String hazard;
String hazardDescription;
String risk;


public Hazard(int id, String hazard, String hazardDescription) {
super(id);
this.hazard = hazard;
this.hazardDescription = hazardDescription;
this.risk = "";

}

public String getHazard() {
Expand All @@ -20,9 +20,7 @@ public String getHazardDescription() {
return hazardDescription;
}

public String getRisk() {
return risk;
}


public void setHazard(String hazard) {
this.hazard = hazard;
Expand All @@ -32,7 +30,5 @@ public void setHazardDescription(String hazardDescription) {
this.hazardDescription = hazardDescription;
}

public void setRisk(String risk) {
this.risk = risk;
}

}
Binary file modified temp.xlsx
Binary file not shown.

0 comments on commit 7ac95d2

Please sign in to comment.