浏览代码

Want to try workaround of loading superclasses after first successful OML build.

Joeri Exelmans 2 年之前
父节点
当前提交
ee0fc395f3
共有 1 个文件被更改,包括 34 次插入16 次删除
  1. 34 16
      src/main/webapp/myPlugins/dtdesign.js

+ 34 - 16
src/main/webapp/myPlugins/dtdesign.js

@@ -64,10 +64,18 @@ WHERE {
 
 // (Hardcoded) link types exposed to the user.
 const typeToLinkType = new Map([
-  ["formalisms/drawio#Cell", {
+  ["formalisms/object_diagram#Object", {
     query: "formalisms/cs_as#parsedAs",
     name: "Is parsed as",
   }],
+  ["formalisms/object_diagram#Object", {
+    query: "formalisms/cs_as#renderedAs",
+    name: "Is rendered as",
+  }],
+  ["formalisms/object_diagram#Object", {
+    query: "formalisms/object_diagram#inModel",
+    name: "Part of model",
+  }],
   ["formalisms/pm#Activity", {
     query: "formalisms/pm#isTransformation",
     name: "Is typed by transformation",
@@ -76,10 +84,6 @@ const typeToLinkType = new Map([
     query: "formalisms/pm#hasType",
     name: "Is typed by formalism",
   }],
-  ["formalisms/object_diagram#Object", {
-    query: "formalisms/cs_as#renderedAs",
-    name: "Is rendered as",
-  }],
   ["formalisms/ftg#Transformation", {
     query: "formalisms/pm#occursAsActivity",
     name: "Occurs as activity",
@@ -138,17 +142,22 @@ fetch(BACKEND+"/version")
     console.log("All good.")
   }
 
-  executeSPARQL(getSubClassRelations)
-  .then(results => {
-    for (const {subclass, superclass} of results) {
-      const superclasslist = superclasses.get(subclass.value) || (() => {
-        const list = [];
-        superclasses.set(subclass.value, list);
-        return list;
-      })();
-      superclasslist.push(superclass.value);
-    }
-  });
+  // Loads all 'rdfs:subClassOf' relations and stores them in a mapping.
+  function loadSuperclasses() {
+    return executeSPARQL(getSubClassRelations)
+    .then(results => {
+      for (const {subclass, superclass} of results) {
+        const superclasslist = superclasses.get(subclass.value) || (() => {
+          const list = [];
+          superclasses.set(subclass.value, list);
+          return list;
+        })();
+        superclasslist.push(superclass.value);
+      }
+    });    
+  }
+
+  loadSuperclasses();
 
   function getSetting(prop) {
     const result = localStorage.getItem("dtdesign-"+prop);
@@ -208,6 +217,15 @@ fetch(BACKEND+"/version")
         } else {
           omlStatusDiv.innerText = "✓ Built OML";
           omlStatusDiv.style.color = "green";
+
+          // WORKAROUND:
+          // The 'superclasses'-mapping gets populated when the plugin is loaded.
+          // If the plugin was loaded while Fuseki was empty, superclasses will be empty as well.
+          // After a successful OML build, Fuseki won't be empty and we can load the superclass relations.
+          // A better way to handle this, would be to guarantee that even if the backend is empty (no models, and hence, no OML descriptions), the vocabularies are always built, and the resulting triples loaded into Fuseki.
+          if (superclasses.size === 0) {
+            loadSuperclasses();
+          }
         }
       });
     });