Skip to content

Commit

Permalink
Merge pull request #3711 from OriginTrail/chore/add-support-for-graphdb
Browse files Browse the repository at this point in the history
Add support for graphdb
  • Loading branch information
Mihajlo-Pavlovic authored Feb 5, 2025
2 parents 569f089 + 79db339 commit dd1023d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "origintrail_node",
"version": "8.0.1+hotfix.4",
"version": "8.0.1+hotfix.5",
"description": "OTNode V8",
"main": "index.js",
"type": "module",
Expand Down
83 changes: 83 additions & 0 deletions src/modules/triple-store/implementation/ot-graphdb/ot-graphdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,89 @@ class OtGraphdb extends OtTripleStore {
getName() {
return 'GraphDB';
}

async queryVoid(repository, query) {
const endpoint = `${this.repositories[repository].url}/repositories/${repository}/statements`;

try {
await axios.post(endpoint, query, {
headers: {
'Content-Type': 'application/sparql-update',
},
});

return true;
} catch (error) {
console.error(`SPARQL update failed: ${error.message}`);

Check warning on line 145 in src/modules/triple-store/implementation/ot-graphdb/ot-graphdb.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
throw error;
}
}

async ask(repository, query) {
const endpoint = `${this.repositories[repository].url}/repositories/${repository}`;

try {
const response = await axios.post(endpoint, query, {
headers: {
'Content-Type': 'application/sparql-query',
Accept: 'application/json',
},
});

return response.data.boolean; // true or false
} catch (error) {
console.error(`ASK query failed: ${error.message}`);

Check warning on line 163 in src/modules/triple-store/implementation/ot-graphdb/ot-graphdb.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
throw error;
}
}

async construct(repository, query, accept = 'application/n-triples') {
const endpoint = `${this.repositories[repository].url}/repositories/${repository}`;
try {
const response = await axios.post(endpoint, query, {
headers: {
'Content-Type': 'application/sparql-query',
Accept: accept,
},
});
return response.data;
} catch (error) {
console.error(`SPARQL query failed: ${error.message}`);

Check warning on line 179 in src/modules/triple-store/implementation/ot-graphdb/ot-graphdb.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
throw error;
}
}

async select(repository, query) {
// todo: add media type once bug is fixed
// no media type is passed because of comunica bug
// https://github.com/comunica/comunica/issues/1034
const result = await this._executeQuery(repository, query);
return result ?? [];
}

async _executeQuery(repository, query, mediaType, accept = 'application/sparql-results+json') {
const endpoint = `${this.repositories[repository].url}/repositories/${repository}`;
try {
const response = await axios.post(endpoint, query, {
headers: {
'Content-Type': 'application/sparql-query',
Accept: accept,
},
});
const result = [];
for (const elem of response.data.results.bindings) {
const obj = {};
Object.keys(elem).forEach((key) => {
obj[key] = elem[key].value;
});
result.push(obj);
}
return result;
} catch (error) {
console.error(`SPARQL query failed: ${error.message}`);

Check warning on line 211 in src/modules/triple-store/implementation/ot-graphdb/ot-graphdb.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
throw error;
}
}
}

export default OtGraphdb;

0 comments on commit dd1023d

Please sign in to comment.