소스 검색

Add incremental rebuild button

Joeri Exelmans 2 년 전
부모
커밋
edd9060527
1개의 변경된 파일50개의 추가작업 그리고 71개의 파일을 삭제
  1. 50 71
      src/main/webapp/myPlugins/dtdesign.js

+ 50 - 71
src/main/webapp/myPlugins/dtdesign.js

@@ -3,7 +3,7 @@ Draw.loadPlugin(function(ui) {
 const WEE = "http://localhost:8081";
 
 const BACKEND = "http://localhost:5000";
-const EXPECTED_BACKEND_VERSION = 5; // expected backend version
+const EXPECTED_BACKEND_VERSION = 6; // expected backend version
 
 const SPARQL_SERVER   = "http://localhost:3030"
 const SPARQL_ENDPOINT = "/SystemDesignOntology2Layers/"
@@ -360,76 +360,51 @@ fetch(BACKEND+"/version")
     return Promise.resolve();
   }
 
-  function rebuildOML() {
+  function rebuildOMLForced() {
+    return executeSPARQL(QUERIES.getAllGraphs)
+    .then(results => {
+      const graphsToDelete = results
+        .map(({g,count}) => g.value)
+        .filter(graphIri => !GRAPHS_NOT_TO_DELETE.includes(graphIri));
+      // Delete all graphs first
+      return Promise.all(graphsToDelete.map(graphToDelete =>
+        fetch(SPARQL_SERVER+SPARQL_ENDPOINT+"?graph="+graphToDelete, {
+          method: "DELETE",
+        })
+        .then(rejectIfStatusAbove400)
+      ))
+      .then(() => {
+        // Build OML and load the resulting .owl files:
+        return fetch(BACKEND+"/owl_load", {
+          method: "PUT",
+        })
+        .then(rejectIfStatusAbove400)
+      });
+    });
+  }
+
+  function rebuildOMLIncremental() {
+    // Backend takes care of all the heavy work:
+    return fetch(BACKEND+"/owl_reload_incremental", { method: "PUT", })
+    .then(rejectIfStatusAbove400);
+  }
+
+  function showRebuildOMLResult(rebuildAsyncCallback) {
     // only perform one rebuild at a time -> queue rebuilds.
     rebuildOMLPromise = rebuildOMLPromise.then(() => {
       omlStatusDiv.style.color = null;
       omlStatusDiv.innerText = "Rebuilding OML...";
-
-      return executeSPARQL(QUERIES.getAllGraphs)
-      .then(results => {
-        const graphsToDelete = results
-          .map(({g,count}) => g.value)
-          .filter(graphIri => !GRAPHS_NOT_TO_DELETE.includes(graphIri));
-        console.log({graphsToDelete});
-        Promise.all(graphsToDelete.map(graphToDelete =>
-          fetch(SPARQL_SERVER+SPARQL_ENDPOINT+"?graph="+graphToDelete, {
-            method: "DELETE",
-          })
-          .then(rejectIfStatusAbove400)
-        ))
-        .then(() => {
-          omlStatusDiv.innerText = "Emptied Fuseki, uploading new triples...";
-          omlStatusDiv.style.color = "blue";
-          errWndDiv.innerText = "No error.";
-
-          return fetch(BACKEND+"/owl_load", {
-            method: "PUT",
-          })
-          .then(rejectIfStatusAbove400)
-          .then(() => {
-            omlStatusDiv.innerText = "✓ Built OML";
-            omlStatusDiv.style.color = "green";
-          })
-        })
-        .catch(errText => {
-          errWndDiv.innerText = errText;
-          omlStatusDiv.innerHTML = "✗ Failed to build OML ";
-          omlStatusDiv.style.color = "red";
-          omlStatusDiv.appendChild(getErrDetailsAnchor());
-        });
+      return rebuildAsyncCallback()
+      .then(() => {
+        omlStatusDiv.innerText = "✓ Built OML";
+        omlStatusDiv.style.color = "green";
+      })
+      .catch(errText => {
+        errWndDiv.innerText = errText;
+        omlStatusDiv.innerHTML = "✗ Failed to build OML ";
+        omlStatusDiv.style.color = "red";
+        omlStatusDiv.appendChild(getErrDetailsAnchor());        
       });
-
-      // return fetch(BACKEND + "/rebuild_oml", {
-      //   method: "PUT",
-      // }).then(res => {
-      //   res.text().then(text => {
-      //     if (text.length > 0) {
-      //       errWndDiv.innerText = text;
-      //     }
-      //     else {
-      //       errWndDiv.innerText = "No error."
-      //     }
-      //   });
-      //   if (res.status >= 500) {
-      //     omlStatusDiv.innerHTML = "✗ Failed to build OML ";
-      //     omlStatusDiv.style.color = "red";
-      //     omlStatusDiv.appendChild(getErrDetailsAnchor());
-      //   } 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.
-      //     // For now, however, the following is workable:
-      //     if (superclasses.size === 0) {
-      //       loadSuperclasses();
-      //     }
-      //   }
-      // });
     });
   }
 
@@ -446,7 +421,7 @@ fetch(BACKEND+"/version")
           statusDiv.style.color = "green";
         });
         refreshListCallback();
-        rebuildOML();
+        showRebuildOMLResult(rebuildOMLIncremental);
       }
       else {
         statusDiv.innerHTML = "✗ Failed to save/parse. ";
@@ -500,8 +475,12 @@ fetch(BACKEND+"/version")
     omlStatusDiv.innerText = "Ready";
     omlDiv.appendChild(omlStatusDiv);
 
-  const omlForceButton = mxUtils.button("Force rebuild", function() {
-    rebuildOML();
+  const omlIncButton = mxUtils.button("Incremental rebuild (faster)", function() {
+    showRebuildOMLResult(rebuildOMLIncremental);
+  });
+    omlDiv.appendChild(omlIncButton);
+  const omlForceButton = mxUtils.button("Forced rebuild (slow)", function() {
+    showRebuildOMLResult(rebuildOMLForced);
   });
     omlDiv.appendChild(omlForceButton);
 
@@ -597,7 +576,7 @@ fetch(BACKEND+"/version")
       .then(res => res.json())
       .then(models => {
         if (models.length > 0) {
-          modelListDiv.replaceChildren(...models.map(modelName => {
+          modelListDiv.replaceChildren(...models.sort().map(modelName => {
             const div = document.createElement('div');
               div.style.padding = '3px 0px';
             const loadButton = mxUtils.button(downloadButtonLabel, () => onDownloadClick(modelName));
@@ -640,7 +619,7 @@ fetch(BACKEND+"/version")
       .then(treatResponseAsPageXml)
       .then(() => {
         refreshDrawioModelList();
-        rebuildOML();
+        showRebuildOMLResult(rebuildOMLIncremental);
       });
     }
   }