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 16, 2019
1 parent d1a8e81 commit 28fa0fd
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 32 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.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public static void createNewDatabase() {
public static void createNewTable() {
// SQLite connection string
String url = "jdbc:sqlite:" + database;
String sql1 = "CREATE TABLE IF NOT EXISTS kind (id integer PRIMARY KEY, kind text NOT NULL, start bit NOT NULL, runtime bit NOT NULL, shutdown bit NOT NULL);";
String sql2 = "CREATE TABLE IF NOT EXISTS role (id integer PRIMARY KEY, role text NOT NULL, start bit NOT NULL, runtime bit NOT NULL, shutdown bit NOT NULL);";
String sql1 = "CREATE TABLE IF NOT EXISTS kind (id integer PRIMARY KEY, kind text NOT NULL, start bit NOT NULL, runtime bit NOT NULL, shutdown bit NOT NULL,unique(kind));";
String sql2 = "CREATE TABLE IF NOT EXISTS role (id integer PRIMARY KEY, role text NOT NULL, start bit NOT NULL, runtime bit NOT NULL, shutdown bit NOT NULL,unique(role));";
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 sql4 = "CREATE TABLE IF NOT EXISTS relator (id integer PRIMARY KEY,relator text NOT NULL,unique(relator));";
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);";
String sql7 = "CREATE TABLE IF NOT EXISTS cause (id INTEGER PRIMARY KEY, cause TEXT NOT NULL, mitigation TEXT, hazardid INTEGER NOT NULL, severity REAL, probability REAL, riskevaluation REAL, risk BIT);";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ public static <E> void sql(String sql, String table, ObservableList<E> list) {
} else if (table.contentEquals("cause")) {
Cause c = new Cause(rs.getInt("id"), rs.getString("cause"), rs.getInt("hazardid"));
Double d = rs.getDouble("riskevaluation");
c.setSeverity(rs.getDouble("severity"));
c.setProbability(rs.getDouble("probability"));
c.setRiskevaluation(d);
if (d != 0) {
c.setRisk(String.valueOf(rs.getBoolean("risk")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JFrame;
Expand All @@ -12,15 +13,14 @@
import com.mxgraph.view.mxGraph;

import hazard.HazardAnalysis.DataBase.DataBaseConnection;
import hazard.HazardClasses.PossibleVictim;

public class PossibleVictimGraph extends JFrame {
public class RelatorGraph extends JFrame {
/**
*
*/
private static final long serialVersionUID = -965262014458195774L;

public PossibleVictimGraph(PossibleVictim pv) throws SQLException {
public RelatorGraph(String relator) throws SQLException {
super("Possible Victim");
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
Expand All @@ -32,10 +32,11 @@ public PossibleVictimGraph(PossibleVictim pv) throws SQLException {
style = graph.getStylesheet().getDefaultEdgeStyle();
style.put(mxConstants.STYLE_STROKECOLOR, "black");
graph.getModel().beginUpdate();
HashMap<String, Object> diagram = new HashMap<String, Object>();
try {
ResultSet rs = DataBaseConnection.sql(
"Select relatortorole.relator, roletoplay.role,roletoplay.kind from relatortorole,roletoplay where relatortorole.relatorid =(Select relator.id from relator where relator.relator='"
+ pv.getRelator() + "') and roletoplay.roleid = relatortorole.roleid;");
+ relator + "') and roletoplay.roleid = relatortorole.roleid;");
Object r = null;
int index = 0;
while (rs.next()) {
Expand All @@ -46,10 +47,15 @@ public PossibleVictimGraph(PossibleVictim pv) throws SQLException {
r = graph.insertVertex(parent, null, rel, 100, 100, 120, 40, "fillColor=white;");
index++;
}
Object rr = graph.insertVertex(parent, null, role, 100, 100, 120, 40, "fillColor=#C4C4C4;");
Object rr = null;
if (!diagram.containsKey(role)) {
rr = graph.insertVertex(parent, null, role, 100, 100, 120, 40, "fillColor=#C4C4C4;");
diagram.put(role, rr);
graph.insertEdge(parent, null, "", diagram.get(role), r);
}
Object k = graph.insertVertex(parent, null, kin, 100, 100, 120, 40, "fillColor=#69D4D0;");
graph.insertEdge(parent, null, "", k, rr);
graph.insertEdge(parent, null, "", rr, r);
diagram.put(kin, k);
graph.insertEdge(parent, null, "", diagram.get(kin), diagram.get(role));
}
} finally {
graph.getModel().endUpdate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.sql.SQLException;

import hazard.HazardAnalysis.DataBase.DataBaseConnection;
import hazard.HazardAnalysis.Graph.PossibleVictimGraph;
import hazard.HazardAnalysis.Graph.RelatorGraph;
import hazard.HazardAnalysis.Graph.SystemGraph;
import hazard.HazardClasses.MishapVictim;
import hazard.HazardClasses.Play;
Expand Down Expand Up @@ -80,9 +80,9 @@ public void handle(MouseEvent event) {
int index = tbPossibleVictim.getSelectionModel().getSelectedIndex();
if (index >= 0) {
PossibleVictim pv = tbPossibleVictim.getItems().get(index);
PossibleVictimGraph frame;
RelatorGraph frame;
try {
frame = new PossibleVictimGraph(pv);
frame = new RelatorGraph(pv.getRelator());
frame.setResizable(true);
frame.setSize(800, 400);
frame.setVisible(true);
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/hazard/HazardAnalysis/Steps/Views/ViewStep6.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package hazard.HazardAnalysis.Steps.Views;

import java.sql.SQLException;

import hazard.HazardAnalysis.DataBase.DataBaseConnection;
import hazard.HazardAnalysis.Graph.RelatorGraph;
import hazard.HazardClasses.Hazard;
import hazard.HazardClasses.HazardElement;
import hazard.HazardClasses.MishapVictim;
Expand Down Expand Up @@ -109,6 +112,21 @@ 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);
Expand Down
44 changes: 27 additions & 17 deletions src/main/java/hazard/HazardAnalysis/Steps/Views/ViewStep8.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ public GridPane addGridPane() {
tbCause.setMinWidth(800);
tbCause.setMaxHeight(200);
TableColumn<Cause, String> cause = new TableColumn<Cause, String>("Pre-initiating event for hazard");
TableColumn<Cause, Double> severity = new TableColumn<Cause, Double>("Severity");
TableColumn<Cause, Double> probabilty = new TableColumn<Cause, Double>("Probability");
TableColumn<Cause, Double> risk = new TableColumn<Cause, Double>("Risk Evaluation");
cause.setMinWidth(400);
cause.setCellValueFactory(new PropertyValueFactory<Cause, String>("cause"));
tbCause.getColumns().addAll(cause);
severity.setCellValueFactory(new PropertyValueFactory<Cause, Double>("severity"));
probabilty.setCellValueFactory(new PropertyValueFactory<Cause, Double>("probability"));
risk.setCellValueFactory(new PropertyValueFactory<Cause, Double>("riskevaluation"));
tbCause.getColumns().addAll(cause, severity, probabilty, risk);
tbCause.setItems(causeList);
tbCause.setRowFactory(new Callback<TableView<Cause>, TableRow<Cause>>() {
@Override
Expand Down Expand Up @@ -131,6 +137,7 @@ private void removeCssClass() {

private void addSeverityAndProbabilityEvent(Button btnAdd, TableView<Cause> tbCause, TableView<Hazard> tbHazard) {
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@SuppressWarnings("rawtypes")
@Override
public void handle(MouseEvent e) {
int index = tbCause.getSelectionModel().getSelectedIndex();
Expand All @@ -141,10 +148,11 @@ public void handle(MouseEvent e) {
TextInputDialog dialog = new TextInputDialog("");
dialog.setTitle("Add Severity And Probability");
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%");
ObservableList<String> options = FXCollections.observableArrayList("Very-High-100%", "High-80%",
"Medium-60%", "Low-40%", "Very-Low-20%");
final ComboBox<String> comboBox = new ComboBox<String>(options);
ObservableList<String> options2 = FXCollections.observableArrayList("High-75%", "Medium-50%",
"Low-25%");
ObservableList<String> options2 = FXCollections.observableArrayList("Very-High-100%", "High-80%",
"Medium-60%", "Low-40%", "Very-Low-20%");
final ComboBox<String> comboBox2 = new ComboBox<String>(options2);
Text severity = new Text("Severity");
Text probability = new Text("Probability");
Expand All @@ -160,9 +168,7 @@ public void handle(MouseEvent e) {
CheckBox ch = new CheckBox("Accept Risk");
ch.setPadding(new Insets(15, 15, 15, 15));
gp.add(ch, 5, 1);
dialog.getDialogPane().setContent(gp);
comboBox.valueProperty().addListener(new ChangeListener<String>() {
@SuppressWarnings("rawtypes")
@Override
public void changed(ObservableValue ov, String t, String t1) {
if (comboBox2.getValue() != null) {
Expand All @@ -172,7 +178,6 @@ public void changed(ObservableValue ov, String t, String t1) {
}
});
comboBox2.valueProperty().addListener(new ChangeListener<String>() {
@SuppressWarnings("rawtypes")
@Override
public void changed(ObservableValue ov, String t, String t1) {
if (comboBox.getValue() != null) {
Expand All @@ -181,6 +186,7 @@ public void changed(ObservableValue ov, String t, String t1) {
}
}
});
dialog.getDialogPane().setContent(gp);
Optional<String> op = dialog.showAndWait();
if (op.isPresent() && !riskEvaluationNr.getText().contentEquals("")) {
DataBaseConnection.sqlUpdate("UPDATE cause SET severity=" + returnRiskValue(comboBox.getValue())
Expand All @@ -194,6 +200,20 @@ public void changed(ObservableValue ov, String t, String t1) {
btnAdd.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
}

private Double returnRiskValue(String s) {
if (s.toLowerCase().contentEquals("Very-High-100%"))
return 1D;
if (s.toLowerCase().contentEquals("High-80%"))
return .8D;
if (s.toLowerCase().contentEquals("Medium-60%"))
return .60D;
if (s.toLowerCase().contentEquals("Low-40%"))
return .4D;
if (s.toLowerCase().contentEquals("Very-Low-20%"))
return .2D;
return 0D;
}

@Override
public GridPane getGridPane() {
updateHazardList();
Expand All @@ -210,16 +230,6 @@ public String getStepDescription() {
return "For each Hazard and it's Pre-initiating events determine a Severity and a Probability for the Hazard.";
}

private Double returnRiskValue(String s) {
if (s.toLowerCase().contains("high"))
return .75D;
if (s.toLowerCase().contains("medium"))
return .50D;
if (s.toLowerCase().contains("low"))
return .25D;
return 0D;
}

public void updateHazardList() {
DataBaseConnection.sql("SELECT * FROM hazard;", "hazard", hazardList);
}
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/hazard/HazardClasses/Cause.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,40 @@ public class Cause extends Play {
private int hazardID;
private String risk;
private String mitigation;

private double severity,probability,riskevaluation;
public Cause(int id, String cause, int hazardID) {
super(id);
this.cause = cause;
this.hazardID = hazardID;
this.risk = "";
this.mitigation = "";
this.severity=0;
this.probability=0;
this.riskevaluation=0;
}

public double getRiskevaluation() {
return riskevaluation;
}

public void setRiskevaluation(double riskevaluation) {
this.riskevaluation = riskevaluation;
}

public double getSeverity() {
return severity;
}

public void setSeverity(double severity) {
this.severity = severity;
}

public double getProbability() {
return probability;
}

public void setProbability(double probability) {
this.probability = probability;
}

public String getMitigation() {
Expand Down
Binary file modified test.db
Binary file not shown.
Binary file modified test.xlsx
Binary file not shown.

0 comments on commit 28fa0fd

Please sign in to comment.