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

Commit

Permalink
Update V2.2.0-Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarczuz committed May 17, 2019
1 parent 5dc38e0 commit 2f8d930
Show file tree
Hide file tree
Showing 17 changed files with 378 additions and 169 deletions.
1 change: 0 additions & 1 deletion .~lock.test.xlsx#

This file was deleted.

Binary file modified graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>Hazard</groupId>
<artifactId>HazardAnalysis</artifactId>
<version>2.0-Beta</version>
<version>2.2.0-Beta</version>
<packaging>jar</packaging>

<name>HazardAnalysis</name>
Expand Down
127 changes: 120 additions & 7 deletions src/main/java/hazard/HazardAnalysis/DataBase/DataBaseConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
Expand All @@ -22,6 +23,7 @@
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import hazard.HazardClasses.Cause;
import hazard.HazardClasses.CausesRiskAndMitigation;
import hazard.HazardClasses.Hazard;
import hazard.HazardClasses.HazardElement;
import hazard.HazardClasses.Kind;
Expand Down Expand Up @@ -91,12 +93,14 @@ public static void exportData(File file) {
ResultSet rs = stmt.executeQuery(sql);
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("Hazards");
ArrayList<CausesRiskAndMitigation> causeAndMitList = new ArrayList<CausesRiskAndMitigation>();
int rowIndex = 0;
int index = 1;
CellStyle headerStyle = workbook.createCellStyle();
CellStyle style = workbook.createCellStyle();
while (rs.next()) {
Row header = sheet.createRow(rowIndex);
rowIndex++;
CellStyle headerStyle = workbook.createCellStyle();
headerStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
headerStyle.setBorderTop(BorderStyle.THIN);
Expand All @@ -114,7 +118,6 @@ public static void exportData(File file) {
headerCell = header.createCell(1);
headerCell.setCellValue("HML-Style Hazard Description");
headerCell.setCellStyle(headerStyle);
CellStyle style = workbook.createCellStyle();
style.setWrapText(false);
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Expand Down Expand Up @@ -183,27 +186,43 @@ public static void exportData(File file) {
ResultSet rs2 = stmt2.executeQuery(sql2);
int i = 1;
while (rs2.next()) {
CausesRiskAndMitigation crm = new CausesRiskAndMitigation();
crm.setHarm(rs.getString("harm").trim());
crm.setNr("cause " + i + ", H:" + (index - 1));
crm.setHml(rs.getString("hazard").trim());
crm.setCause(rs2.getString("cause").trim());
crm.setProbability(rs2.getDouble("probability"));
crm.setSeverity(rs2.getDouble("severity"));
crm.setRpn(rs2.getDouble("riskevaluation"));
crm.setRisk(rs2.getBoolean("risk"));
crm.setRq("M:" + i);
crm.setMitigation(rs2.getString("mitigation"));
causeAndMitList.add(crm);
Row causes = sheet.createRow(rowIndex);
rowIndex++;
Cell cellCauses = causes.createCell(0);
cellCauses.setCellValue("Cause " + i);
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(1);
cellCauses.setCellValue(rs2.getString("cause"));
cellCauses.setCellValue(rs2.getString("cause").trim());
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(2);
cellCauses.setCellValue(rs2.getString("probability"));
cellCauses.setCellValue(rs2.getDouble("probability"));
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(3);
cellCauses.setCellValue(rs2.getString("severity"));
cellCauses.setCellValue(rs2.getDouble("severity"));
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(4);
cellCauses.setCellValue(rs2.getString("riskevaluation"));
cellCauses.setCellValue(rs2.getDouble("riskevaluation"));
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(5);
String risk = "Denied";
CellStyle styleRisk = workbook.createCellStyle();
styleRisk.setFillPattern(FillPatternType.SOLID_FOREGROUND);
styleRisk.setBorderTop(BorderStyle.THIN);
styleRisk.setBorderRight(BorderStyle.THIN);
styleRisk.setBorderBottom(BorderStyle.THIN);
styleRisk.setBorderLeft(BorderStyle.THIN);
String risk = "Denied";
if (rs2.getBoolean("risk")) {
risk = "Accept";
styleRisk.setFillForegroundColor(IndexedColors.GREEN.getIndex());
Expand All @@ -230,6 +249,100 @@ public static void exportData(File file) {
sheet.autoSizeColumn(5);
sheet.autoSizeColumn(6);
sheet.autoSizeColumn(7);
// Sheet 2 causes sorted by risk evaluation number
causeAndMitList.sort((c1, c2) -> c1.getRpn() > c2.getRpn() ? -1 : 1);
rowIndex = 0;
index = 1;
Sheet sheetCauses = workbook.createSheet("Causes");
Row headerCause = sheetCauses.createRow(rowIndex);
rowIndex++;
Cell headerCellCause = headerCause.createCell(0);
headerCellCause.setCellValue("No.");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(1);
headerCellCause.setCellValue("HML-Style Hazard Description");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(2);
headerCellCause.setCellValue("Natural Language Hazard Description");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(3);
headerCellCause.setCellValue("Cause");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(4);
headerCellCause.setCellValue("Probability");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(5);
headerCellCause.setCellValue("Severity");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(6);
headerCellCause.setCellValue("RPN");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(7);
headerCellCause.setCellValue("Risk");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(8);
headerCellCause.setCellValue("Rq.");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(9);
headerCellCause.setCellValue("Mitigation");
headerCellCause.setCellStyle(headerStyle);
for (int j = 0; j < causeAndMitList.size(); j++) {
Row causes = sheetCauses.createRow(rowIndex);
rowIndex++;
Cell cellCauses = causes.createCell(0);
cellCauses.setCellValue(causeAndMitList.get(j).getNr());
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(1);
cellCauses.setCellValue(causeAndMitList.get(j).getHml());
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(2);
cellCauses.setCellValue(causeAndMitList.get(j).getHarm());
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(3);
cellCauses.setCellValue(causeAndMitList.get(j).getCause());
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(4);
cellCauses.setCellValue(causeAndMitList.get(j).getProbability());
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(5);
cellCauses.setCellValue(causeAndMitList.get(j).getSeverity());
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(6);
cellCauses.setCellValue(causeAndMitList.get(j).getRpn());
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(7);
CellStyle styleRisk = workbook.createCellStyle();
styleRisk.setFillPattern(FillPatternType.SOLID_FOREGROUND);
styleRisk.setBorderTop(BorderStyle.THIN);
styleRisk.setBorderRight(BorderStyle.THIN);
styleRisk.setBorderBottom(BorderStyle.THIN);
styleRisk.setBorderLeft(BorderStyle.THIN);
String risk = "Denied";
if (causeAndMitList.get(j).isRisk()) {
risk = "Accept";
styleRisk.setFillForegroundColor(IndexedColors.GREEN.getIndex());
} else {
styleRisk.setFillForegroundColor(IndexedColors.RED.getIndex());
}
cellCauses.setCellValue(risk);
cellCauses.setCellStyle(styleRisk);
cellCauses = causes.createCell(8);
cellCauses.setCellValue(causeAndMitList.get(j).getRq());
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(9);
cellCauses.setCellValue(causeAndMitList.get(j).getMitigation());
cellCauses.setCellStyle(style);
}
sheetCauses.autoSizeColumn(0);
sheetCauses.autoSizeColumn(1);
sheetCauses.autoSizeColumn(2);
sheetCauses.autoSizeColumn(3);
sheetCauses.autoSizeColumn(4);
sheetCauses.autoSizeColumn(5);
sheetCauses.autoSizeColumn(6);
sheetCauses.autoSizeColumn(7);
sheetCauses.autoSizeColumn(8);
sheetCauses.autoSizeColumn(9);
PrintSetup ps = sheet.getPrintSetup();
ps.setFitWidth((short) 1);
ps.setFitHeight((short) 1);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/hazard/HazardAnalysis/Steps/Views/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ public ViewStep1 getAv1() {
return av1;
}

public ViewStep10 getAv10() {
return this.av10;
}

public ViewStep2 getAv2() {
return av2;
}
Expand Down Expand Up @@ -337,10 +341,6 @@ public ViewStep9 getAv9() {
return this.av9;
}

public ViewStep10 getAv10() {
return this.av10;
}

private void loadCenterViews() {
this.av2 = new ViewStep2();
this.av3 = new ViewStep3();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ public void handle(MouseEvent e) {
btnRemove.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
}

public void updateVictimList() {
DataBaseConnection.sql("Select * from mishapvictim", "mishapvictim", victimList);
}

public void updatePossibleVictimList() {
DataBaseConnection.sql(
"select roletoplay.role,roletoplay.kind,relatortorole.relator,roletoplay.roleid,roletoplay.kindid,relatortorole.relatorid from roletoplay, relatortorole where relatortorole.roleid = roletoplay.roleid",
"possiblevictim", possibleVictimList);
}

public void updateVictimList() {
DataBaseConnection.sql("Select * from mishapvictim", "mishapvictim", victimList);
}
}
85 changes: 45 additions & 40 deletions src/main/java/hazard/HazardAnalysis/Steps/Views/ViewStep6.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
Expand Down Expand Up @@ -108,38 +109,6 @@ public GridPane addGridPane() {
return grid;
}

private void clickEventToTbVictim(TableView<MishapVictim> tbVictim) {
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getClickCount() == 2) {
int index = tbVictim.getSelectionModel().getSelectedIndex();
if (index >= 0) {
MishapVictim mv = tbVictim.getItems().get(index);
RelatorGraph frame;
try {
frame = new RelatorGraph(mv.getRelator());
frame.setResizable(true);
frame.setSize(800, 400);
frame.setVisible(true);
} catch (SQLException err) {
err.printStackTrace();
}
}
}
int index = tbVictim.getSelectionModel().getSelectedIndex();
if (index > -1) {
MishapVictim mv = tbVictim.getItems().get(index);
DataBaseConnection.sql(
"SELECT roletoplay.role,roletoplay.kind FROM relatortorole, roletoplay WHERE relatortorole.relatorid ="
+ mv.getRelatorID() + " AND relatortorole.roleid = roletoplay.roleid;",
"hazardelement", hazardElementList);
}
}
};
tbVictim.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
}

private void addHazardEvent(Button btnAdd, TableView<MishapVictim> tbVictim,
TableView<HazardElement> tbHazardElement) {
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
Expand All @@ -162,7 +131,9 @@ public void handle(MouseEvent e) {
+ "<HarmTruthMaker>" + ":" + he.getKind() + ")");
description.setWrappingWidth(600);
t.setPromptText("HarmTruthMaker");
t.setTooltip(new Tooltip("The Short Description of the Harm"));
ta.setPromptText("Descrption of the Harm.");
ta.setTooltip(new Tooltip("The Detailed Description of the Harm"));
GridPane gp = new GridPane();
gp.setPadding(new Insets(15, 15, 15, 15));
t.setPadding(new Insets(10, 5, 5, 5));
Expand All @@ -186,6 +157,8 @@ public void handle(DialogEvent event) {
String harm = ta.getText();
DataBaseConnection.insertHazard(hazard, harm);
DataBaseConnection.sql("SELECT * FROM hazard;", "hazard", hazardList);
} else if (dialog.getResult() != null && (t.getText().isEmpty() || ta.getText().isEmpty())) {
event.consume();
}
}
};
Expand All @@ -197,20 +170,36 @@ public void handle(DialogEvent event) {
btnAdd.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
}

private void removeHazardEvent(Button btnRemove, TableView<Hazard> tbHazard) {
private void clickEventToTbVictim(TableView<MishapVictim> tbVictim) {
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
if (tbHazard.getItems().size() != 0) {
int index = tbHazard.getSelectionModel().selectedIndexProperty().get();
if (index != -1) {
Play o = tbHazard.getItems().remove(index);
DataBaseConnection.delete("hazard", o.getId());
public void handle(MouseEvent event) {
if (event.getClickCount() == 2) {
int index = tbVictim.getSelectionModel().getSelectedIndex();
if (index >= 0) {
MishapVictim mv = tbVictim.getItems().get(index);
RelatorGraph frame;
try {
frame = new RelatorGraph(mv.getRelator());
frame.setResizable(true);
frame.setSize(800, 400);
frame.setVisible(true);
} catch (SQLException err) {
err.printStackTrace();
}
}
}
int index = tbVictim.getSelectionModel().getSelectedIndex();
if (index > -1) {
MishapVictim mv = tbVictim.getItems().get(index);
DataBaseConnection.sql(
"SELECT roletoplay.role,roletoplay.kind FROM relatortorole, roletoplay WHERE relatortorole.relatorid ="
+ mv.getRelatorID() + " AND relatortorole.roleid = roletoplay.roleid;",
"hazardelement", hazardElementList);
}
}
};
btnRemove.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
tbVictim.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
}

@Override
Expand All @@ -231,6 +220,22 @@ public String getStepDescription() {
+ "explosion, etc.";
}

private void removeHazardEvent(Button btnRemove, TableView<Hazard> tbHazard) {
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
if (tbHazard.getItems().size() != 0) {
int index = tbHazard.getSelectionModel().selectedIndexProperty().get();
if (index != -1) {
Play o = tbHazard.getItems().remove(index);
DataBaseConnection.delete("hazard", o.getId());
}
}
}
};
btnRemove.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
}

public void updateHazardList() {
DataBaseConnection.sql("SELECT * FROM hazard;", "hazard", hazardList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public void handle(DialogEvent event) {
DataBaseConnection.insertCause(ta.getText(), h.getId());
DataBaseConnection.sql("SELECT * FROM cause WHERE cause.hazardid=" + h.getId() + ";",
"cause", list);
} else if (dialog.getResult() != null && ta.getText().isEmpty()) {
event.consume();
}
}
};
Expand Down
Loading

0 comments on commit 2f8d930

Please sign in to comment.