From a2920baf5e698dddad625a184f7561e6ec71ccd2 Mon Sep 17 00:00:00 2001
From: martiivGylden <martin.iversen@gyldendal.no>
Date: Tue, 12 Mar 2024 14:42:15 +0100
Subject: [PATCH] Printer fixed for dynamic components

---
 diagramParser.py |  9 ++++++---
 dynamics.py      | 20 ++++++++++++--------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/diagramParser.py b/diagramParser.py
index 4b85330..af6f1bf 100644
--- a/diagramParser.py
+++ b/diagramParser.py
@@ -86,6 +86,7 @@ def parseDynamic(df, metricList):
                 joinMetrcs(threatDynamic.metrics, metricList)            # Adds the metrics to the global metric list
                 
                 threatDynamic.associateBowtie(df, threatDynamic.type)                  # Associate the dynamic with the correct components
+                print(threatDynamic, "\n")
                 
             elif df[const.textArea3][i] == const.ConsequenceDynamic:
                 consequenceDynamic = dynamic.BowtieDynamic(
@@ -94,7 +95,8 @@ def parseDynamic(df, metricList):
                 )
                 consequenceDynamic.metrics = extractMetrics(df, i, 4)   # Extracts metrics from the dynamic component
                 joinMetrcs(threatDynamic.metrics, metricList)            # Adds the metrics to the global metric list
-                consequenceDynamic.associateBowtie(df, consequenceDynamic.type)                  # Associate the dynamic with the correct components
+                consequenceDynamic.associateBowtie(df, consequenceDynamic.type)    
+                print(consequenceDynamic, "\n")# Associate the dynamic with the correct components
 
                 
             elif df[const.textArea3][i] == const.AttackDynamic:
@@ -105,7 +107,7 @@ def parseDynamic(df, metricList):
                 attackDynamic.metrics = extractMetrics(df, i, 4)
                 joinMetrcs(threatDynamic.metrics, metricList)            # Adds the metrics to the global metric list
                 attackDynamic.associateBowtie(df,attackDynamic.type)                     # Associate the dynamic with the correct components
-
+                print(attackDynamic, "\n")
                                                     
             elif df[const.textArea3][i] == const.ERDynamic:
                 erDynamic = dynamic.ERDynamic(
@@ -115,7 +117,8 @@ def parseDynamic(df, metricList):
                 )
                 erDynamic.metrics = extractMetrics(df, i, 8)
                 joinMetrcs(threatDynamic.metrics, metricList)            # Adds the metrics to the global metric list
-                #erDynamic.associatedERComponents(df)
+                erDynamic.associatER(df)
+                print(erDynamic , "\n")
                 
 
 def extractMetrics(df, index, startRange):
diff --git a/dynamics.py b/dynamics.py
index b77cc34..8ca8627 100644
--- a/dynamics.py
+++ b/dynamics.py
@@ -39,6 +39,16 @@ class BowtieDynamic(DynamicComponent):
         self.associatedAttack = None        # Attack associated with the dynamic
         self.associatedConsequence = None   # Consequence associated with the dynamic
         
+        
+    def __str__(self) -> str:
+        if self.type == const.ThreatDynamic:
+            return super().__str__() + f"Associated threat ID: {self.associatedThreat[const.Id].item()} Associated attack ID  {(self.associatedAttack[const.Id].item())}"
+        elif self.type == const.ConsequenceDynamic:
+            return super().__str__() + f"Associated consequence ID: {self.associatedConsequence[const.Id].item()} Assocaited attack ID:{(self.associatedAttack[const.Id].item())}"
+        elif self.type == const.AttackDynamic:
+            return super().__str__() + f"Associated attack ID: {self.associatedAttack[const.Id].item()}"
+        
+        
         """_summary_
         Handles the associated dynamics for the bowtie model as they are different from the ER model
         ER model has one type of dynamic component with metrics however, the bowtie model has three dynamic types and needs more parsing 
@@ -93,14 +103,6 @@ class BowtieDynamic(DynamicComponent):
                 self.associatedAttack = sourceComponent
                 
             
-            
-        
-            
-        
-        
-        
-        
-
 class ERDynamic(DynamicComponent):
     def __init__(self, componentID, type, description) -> None:
         super().__init__(componentID)
@@ -109,6 +111,8 @@ class ERDynamic(DynamicComponent):
         self.associatedERComponents = []   # Associated ER component
         self.type = type 
         
+    def __str__(self) -> str:
+        return super().__str__() + f"ER Dynamic: {self.type}, {self.description}, Amount of associated components {len(self.associatedERComponents)}"
         
         """_summary_
         Function will use the dynamic component ID to find linked threats, ER components, attacks and consequences
-- 
GitLab