You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ki...@apache.org on 2023/04/07 11:10:23 UTC

[jena] 01/02: GH-1679: edit not working on non root g-sp

This is an automated email from the ASF dual-hosted git repository.

kinow pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git

commit 17c9205835dd1b94f07ec26dfa26fad7b1d779a8
Author: Simon Bin <sb...@informatik.uni-leipzig.de>
AuthorDate: Fri Dec 16 00:42:49 2022 +0100

    GH-1679: edit not working on non root g-sp
---
 .../jena-fuseki-ui/src/services/fuseki.service.js  | 40 +++++++++++++++++++---
 .../jena-fuseki-ui/src/views/dataset/Edit.vue      | 12 +++++--
 .../tests/unit/services/fuseki.service.spec.js     |  9 +++--
 3 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/jena-fuseki2/jena-fuseki-ui/src/services/fuseki.service.js b/jena-fuseki2/jena-fuseki-ui/src/services/fuseki.service.js
index 4183991deb..a090ec17f4 100644
--- a/jena-fuseki2/jena-fuseki-ui/src/services/fuseki.service.js
+++ b/jena-fuseki2/jena-fuseki-ui/src/services/fuseki.service.js
@@ -181,9 +181,31 @@ class FusekiService {
     return results
   }
 
-  async fetchGraph (datasetName, graphName) {
+  /**
+   * Get the data endpoint out of a list of server endpoints.
+   *
+   * For now we are simply returning the first non-empty, but that
+   * may change at some point.
+   *
+   * @private
+   * @param {string[]} serverEndpoints - list of server endpoints in the dataset (can be an empty list).
+   */
+  getDataEndpoint(serverEndpoints) {
+    return serverEndpoints.find(endpoint => endpoint !== '') || ''
+  }
+
+  /**
+   * Fetch a graph.
+   * @param {string} datasetName - Jena dataset name.
+   * @param {string[]} serverEndpoints - list of server endpoints in the dataset (can be an empty list).
+   * @param {string} graphName - name of the graph being accessed.
+   * @return {Promise<AxiosResponse<any>>}
+   */
+  async fetchGraph (datasetName, serverEndpoints, graphName) {
+    const dataEndpoint = this.getDataEndpoint(serverEndpoints)
+    const urlPart = `${datasetName}/${dataEndpoint}`
     return await axios
-      .get(this.getFusekiUrl(`/${datasetName}`), {
+      .get(this.getFusekiUrl(urlPart), {
         params: {
           graph: graphName
         },
@@ -193,9 +215,19 @@ class FusekiService {
       })
   }
 
-  async saveGraph (datasetName, graphName, code) {
+  /**
+   * Save a graph.
+   * @param {string} datasetName - Jena dataset name.
+   * @param {string[]} serverEndpoints - list of server endpoints in the dataset (can be an empty list).
+   * @param {string} graphName - name of the graph being accessed.
+   * @param {string} code - graph content.
+   * @return {Promise<AxiosResponse<any>>}
+   */
+  async saveGraph (datasetName, serverEndpoints, graphName, code) {
+    const dataEndpoint = this.getDataEndpoint(serverEndpoints)
+    const urlPart = `${datasetName}/${dataEndpoint}`
     return await axios
-      .put(this.getFusekiUrl(`/${datasetName}`), code, {
+      .put(this.getFusekiUrl(urlPart), code, {
         params: {
           graph: graphName
         },
diff --git a/jena-fuseki2/jena-fuseki-ui/src/views/dataset/Edit.vue b/jena-fuseki2/jena-fuseki-ui/src/views/dataset/Edit.vue
index e5458e1515..8dde59f7af 100644
--- a/jena-fuseki2/jena-fuseki-ui/src/views/dataset/Edit.vue
+++ b/jena-fuseki2/jena-fuseki-ui/src/views/dataset/Edit.vue
@@ -261,7 +261,11 @@ export default {
       this.loadingGraph = true
       this.selectedGraph = graphName
       try {
-        const result = await this.$fusekiService.fetchGraph(this.datasetName, graphName)
+        const dataEndpoint = this.services['gsp-rw']['srv.endpoints'].find(endpoint => endpoint !== '') || ''
+        const result = await this.$fusekiService.fetchGraph(
+          this.datasetName,
+          this.services['gsp-rw']['srv.endpoints'],
+          graphName)
         this.code = result.data
       } catch (error) {
         displayError(this, error)
@@ -277,7 +281,11 @@ export default {
       if (!this.saveGraphDisabled) {
         this.loadingGraph = true
         try {
-          await this.$fusekiService.saveGraph(this.datasetName, this.selectedGraph, this.content)
+          await this.$fusekiService.saveGraph(
+            this.datasetName,
+            this.services['gsp-rw']['srv.endpoints'],
+            this.selectedGraph,
+            this.content)
           displayNotification(this, `Graph updated for dataset "${this.datasetName}"`)
         } catch (error) {
           displayError(this, error)
diff --git a/jena-fuseki2/jena-fuseki-ui/tests/unit/services/fuseki.service.spec.js b/jena-fuseki2/jena-fuseki-ui/tests/unit/services/fuseki.service.spec.js
index 87db72cd7c..6c392bd8ab 100644
--- a/jena-fuseki2/jena-fuseki-ui/tests/unit/services/fuseki.service.spec.js
+++ b/jena-fuseki2/jena-fuseki-ui/tests/unit/services/fuseki.service.spec.js
@@ -283,8 +283,11 @@ describe('FusekiService', () => {
     stub.resolves(Promise.resolve({
       data: 42
     }))
-    const graph = await fusekiService.fetchGraph('jena', 'default')
+    const graph = await fusekiService.fetchGraph('jena', ['dataEndpoint'], 'default')
     expect(stub.called).to.equal(true)
+    const getArgs = stub.getCall(0).args
+    // See https://github.com/apache/jena/pull/1679
+    expect(getArgs[0]).to.equal('/jena/dataEndpoint')
     expect(graph).to.deep.equal({ data: 42 })
     stub.restore()
   })
@@ -293,7 +296,7 @@ describe('FusekiService', () => {
     stub.resolves(Promise.resolve({
       data: 42
     }))
-    const graph = await fusekiService.saveGraph('jena', 'default', 'abc')
+    const graph = await fusekiService.saveGraph('jena', [], 'default', 'abc')
     expect(stub.called).to.equal(true)
     expect(graph).to.deep.equal({ data: 42 })
     stub.restore()
@@ -306,7 +309,7 @@ describe('FusekiService', () => {
     }
     stub.resolves(Promise.reject(error))
     try {
-      await fusekiService.saveGraph('jena', 'default', 'abc')
+      await fusekiService.saveGraph('jena', [], 'default', 'abc')
       expect.fail('Not supposed to get here')
     } catch (error) {
       expect(error.message).to.be.equal('42')