瀏覽代碼

Process trace parent links are rendered

Joeri Exelmans 2 年之前
父節點
當前提交
eec4b966c7
共有 3 個文件被更改,包括 23 次插入4 次删除
  1. 2 2
      backend/dtdesign-backend
  2. 8 2
      drawio2oml/pt/fetcher.py
  3. 13 0
      drawio2oml/pt/renderer.py

+ 2 - 2
backend/dtdesign-backend

@@ -242,7 +242,7 @@ def owl_reload_incremental():
 
     # Iterate old hashes to see what needs to be deleted:
     for file, (old_hash, old_mime_type) in old_hashes.items():
-        new_hash, new_mime_type = new_hashes.get(file, None)
+        new_hash, new_mime_type = new_hashes.get(file, (None,None))
         if old_hash != new_hash:
             graph_iri = "http://" + file[:-4]
             print("Deleting graph: ", graph_iri, '(changed: '+old_hash+' -> '+new_hash+')')
@@ -252,7 +252,7 @@ def owl_reload_incremental():
 
     # Iterate new hashes to see what needs to be (re-)created:
     for file, (new_hash, new_mime_type) in new_hashes.items():
-        old_hash, old_mime_type = old_hashes.get(file, None)
+        old_hash, old_mime_type = old_hashes.get(file, (None,None))
         if new_hash != old_hash:
             graph_iri = "http://" + file[:-4]
             print("Creating graph: " + graph_iri)

+ 8 - 2
drawio2oml/pt/fetcher.py

@@ -19,6 +19,8 @@ class Fetcher:
         For a given StartTraceEvent iri, gets all the events from the trace (from WEE), and produces the Python in-memory abstract syntax for it.
         """
         r = requests.get(self.wee_host + "/traces/events/" + urllib.parse.quote(pt_iri, safe=''))
+        if r.status_code >= 400:
+            raise Exception("Error getting trace events from WEE")
         json = r.json()
 
         pprint.pprint(json)
@@ -26,6 +28,7 @@ class Fetcher:
         # iri_to_as_event = {}
 
         iri_to_artifact = {}
+        parent_links_to_create = []
 
         def make_artifact(json_artifact):
             try:
@@ -40,8 +43,8 @@ class Fetcher:
                     iri=json_artifact['iri'],
                 )
                 iri_to_artifact[json_artifact['iri']] = artifact
-            if json_artifact['nextVersion'] in iri_to_artifact:
-                iri_to_artifact[json_artifact['nextVersion']].parentVersion = artifact
+            if json_artifact['nextVersion'] != None:
+                parent_links_to_create.append((json_artifact['nextVersion']['iri'], json_artifact['iri']))
             return artifact
 
         last_event = None
@@ -82,4 +85,7 @@ class Fetcher:
             last_event = as_event
             # iri_to_as_event[json_event['iri']] = as_event
 
+        for child_iri, parent_iri in parent_links_to_create:
+            iri_to_artifact[child_iri].parentVersion = iri_to_artifact[parent_iri]
+
         return last_event

+ 13 - 0
drawio2oml/pt/renderer.py

@@ -66,6 +66,8 @@ def render(shapelib_dir: str, last_event: pt_as.Event, parent: dio_as.Cell, id_g
 
     vpos = VertexPositionGenerator()
 
+    parent_links_to_create = []
+
     artifacts_visited = {}
     def create_artifact(artifact):
         if artifact not in artifacts_visited.keys():
@@ -76,6 +78,8 @@ def render(shapelib_dir: str, last_event: pt_as.Event, parent: dio_as.Cell, id_g
             set_property(vertex, "type", artifact.type)
             artifacts_visited[artifact] = vertex
             traceability_links.append(trace_as.TraceabilityLink(dio=vertex, pt=artifact))
+            if artifact.parentVersion != None:
+                parent_links_to_create.append((artifact, artifact.parentVersion))
         return artifacts_visited[artifact]
 
     # Construct list of events to render by following 'after'-links:
@@ -122,4 +126,13 @@ def render(shapelib_dir: str, last_event: pt_as.Event, parent: dio_as.Cell, id_g
                 source=prev_event_vertex, target=vertex)
         prev_event_vertex = vertex
 
+    print("will create", len(parent_links_to_create), "parent links")
+
+    for child_artifact, parent_artifact in parent_links_to_create:
+        print("artifacts_visited[child]", artifacts_visited[child_artifact])
+        print("artifacts_visited[parent]", artifacts_visited[parent_artifact])
+        cloner.clone_edge(pt_library["(Trace) Parent Version"], parent,
+            source=artifacts_visited[child_artifact],
+            target=artifacts_visited[parent_artifact])
+
     return traceability_links