ENAPSO Graph Database Admin Tools for Node.js
npm install @innotrade/enapso-graphdb-adminjavascript
npm i @innotrade/enapso-graphdb-admin --save
`
Create a connection with graph database
`javascript
const { EnapsoGraphDBClient } = require('@innotrade/enapso-graphdb-client');
const { EnapsoGraphDBAdmin } = require('@innotrade/enapso-graphdb-admin');
let graphDBEndpoint = new EnapsoGraphDBClient.Endpoint({
baseURL: 'http://localhost:7200',
repository: 'Test',
prefixes: [
{
prefix: 'entest',
iri: 'http://ont.enapso.com/test#'
}
],
triplestore: 'graphdb',
version: 9,
apiType: 'RDF4J'
});
`
$3
| Parameter | Type | Description | Values |
| --------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
| baseURL(required) | String | Pass the URL in which graph database is running. | |
| repository(required) | String | Pass the name of the repository or database of the graph databases with which you want to create a connection. | |
| prefixes(required) | Array of objects | Pass the prefix and its IRI as an object which will be used in the SPARQL query to perform crud operations. | |
| triplestore(optional) | String | Pass the name of the graph database with which you want to create a connection by default it creates a connection with Ontotext GraphDB. | ('graphdb' , 'stardog' , 'fuseki') |
| transform(optional) | String | Pass the type in which you want to show the result of the SPARQL query by default it shows the result in JSON format. | ('toJSON', 'toCSV' , 'toTSV') |
| version(optional) | Number | Pass the version of ontotext graphDB to make the tool compatible with an older version by default it works with the latest version of ontotext graphDB. | |
| apiType(optional) | String | Pass the type of API which will use for importing ontology in ontotext graphDB by default it uses ontotext graphDB workbench APIs. | ('workbench', 'RDF4J' ) |
📋 Features
| Feature | Description | Ontotext GraphDB | Apache Jena Fuseki | Stardog |
| --------------------------------------------------------- | ------------------------------------------------------------------ | ---------------- | ------------------ | ------- |
| Login | Authenticate against the graph database | ✔ | ✘ | ✔ |
| Query | To retrieve the information from graph database using SPARQL query | ✔ | ✔ | ✔ |
| Update | To update the triples in the graph database. | ✔ | ✔ | ✔ |
| Create Repository | Create new repository/database in the graph database. | ✔ | ✔ | ✔ |
| Delete Repository | Delete existing repository/database from graph database. | ✔ | ✔ | ✔ |
| Clear Repository | Remove all triples from graph database repository/database. | ✔ | ✔ | ✔ |
| Get Repositories | Get list of all repsoitory from graph database. | ✔ | ✔ | ✔ |
| Create User | Create new user and asign the roles in the graph database. | ✔ | ✘ | ✔ |
| Get Users | Get list of users from graph database. | ✔ | ✘ | ✔ |
| Get Resources | Get list of resources from graph database. | ✔ | ✘ | ✘ |
| Update User | Update existing user roles from graph database. | ✔ | ✘ | ✘ |
| Assign Role | Assign new roles to the existing user of the graph database. | ✘ | ✘ | ✔ |
| Remove Role | Remove roles of the existing user of the graph database. | ✘ | ✘ | ✔ |
| Delete User | Delete existing user of graph database. | ✔ | ✘ | ✔ |
| Drop SHACL Graph | Drop SHACL graph from graph database. | ✔ | ✘ | ✘ |
| Get Contexts | Get all context from graph database repository. | ✔ | ✔ | ✔ |
| Upload From File | Upload ontology from file in the graph database. | ✔ | ✔ | ✔ |
| Upload From Data | Upoad ontology from data in the graph database. | ✔ | ✘ | ✔ |
| Download To File | Download ontology to file from graph database. | ✔ | ✔ | ✔ |
| Download To Text | Download ontology to text from graph database. | ✔ | ✔ | ✔ |
| Clear Context | Clear specific named graph from graph database repository. | ✔ | ✔ | ✔ |
| Get Query | Get query from graph database repository. | ✔ | ✘ | ✔ |
| Get Locations | Get locations from graph database repository. | ✔ | ✘ | ✘ |
| Perform Garbage Collection | Perform garbage collection in the graph database repository. | ✔ | ✘ | ✘ |
| Get Saved Queries | Get saved queries from graph database. | ✔ | ✘ | ✘ |
Login
Login to authenticate the user against graph database and authorize the user according to his roles:
`javascript
graphDBEndpoint
.login('admin', 'root')
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
`
Query
Querying against the graph database
`
graphDBEndpoint
.query(
'select *
where {
?class rdf:type owl:Class
filter(regex(str(?class), "http://ont.enapso.com/test#TestClass", "i")) .
}',
{ transform: 'toJSON' }
)
.then((result) => {
console.log(
'Read the classes name:\n' + JSON.stringify(result, null, 2)
);
})
.catch((err) => {
console.log(err);
});
`
Update
Updating Triples in graph database
`
graphDBEndpoint
.update(
insert data {
)
.then((result) => {
console.log('inserted a class :\n' + JSON.stringify(result, null, 2));
})
.catch((err) => {
console.log(err);
Upload From File
Upload an ontology and import it into the graph database repository automatically if the upload was successful. context (graph) and baseIRI parameters are optional :
`javascript
graphDBEndpoint
.uploadFromFile({
filename: '../ontologies/EnapsoTest.owl',
format: 'application/rdf+xml',
baseIRI: 'http://ont.enapso.com/test#',
context: 'http://ont.enapso.com/test'
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
`
Upload From Data
Upload data (rather than a file) and automatically import the data into a graph database repository and context (graph) is an optional parameter:
`javascript
fsPromises
.readFile('../ontologies/EnapsoTest.owl', 'utf-8')
.then((data) => {
graphDBEndpoint
.uploadFromData({
data: data,
context: 'http://ont.enapso.com/test',
format: 'application/rdf+xml'
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
})
.catch((err) => {
console.log(err);
});
`
Download To Text
Download a Graph from graph database to a Text Variable.
For the available export formats, please refer to the EnapsoGraphDBClient.FORMAT_xxx constants.
The context (graph) is optional. If you do not pass a context (graph), the entire repository is exported.
`javascript
graphDBEndpoint
.downloadToText({
format: EnapsoGraphDBClient.FORMAT_TURTLE.type
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
`
Download To File
Download a graph from graph database directly to a Local File.
For the available export formats, please refer to the EnapsoGraphDBClient.FORMAT_xxx constants.
The context is optional. If you do not pass a context, the entire repository is exported.
`javascript
let lFormat = EnapsoGraphDBClient.FORMAT_TURTLE;
graphDBEndpoint
.downloadToFile({
format: lFormat.type,
filename:
'../ontologies/' +
graphDBEndpoint.getRepository() +
lFormat.extension
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
`
Perform Garbage Collection
Perform the garbage collection on the server side to release allocated resources:
if security is on then the Garbage Collection user role needs to be Administrator else operation is not performed
`javascript
graphDBEndpoint
.performGarbageCollection()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
`
Get Resources
Get resource details of the repository current connected to the endpoint:
`javascript
graphDBEndpoint
.getResources()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
`
Create User
Create a new user and provide a user with read/write access to certain repositories in a graph database instance:
if security is on then for Creating a new User, the user role needs to be Administrator else operation is not performed
`javascript
graphDBEndpoint
.createUser({
authorities: [
'WRITE_REPO_Test', // Writing excess wrote WRITE_ and in last name of Repository which excess provided like REPO_Test
'READ_REPO_Test', // Reading excess wrote READ_ and in last name of Repository which excess provided like REPO_Test
'READ_REPO_EnapsoDotNetProDemo',
'ROLE_USER' // Role of the user
],
username: 'TestUser2', // Username
password: 'TestUser2' // Password for the user
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Update User
Update the user's roles (read/write rights) for certain repositories:
if security is on then for Updating Existing User, the user role needs to be Administrator else operation is not performed
`javascript
graphDBEndpoint
.updateUser({
authorities: [
// Writing excess wrote WRITE_ and in the last name of Repository which excess provided like REPO_Test
'READ_REPO_Test', // Reading excess wrote READ_ and in the last name of Repository which excess provided like REPO_Test
'WRITE_REPO_EnapsoDotNetProDemo',
'READ_REPO_EnapsoDotNetProDemo',
'ROLE_USER' // Role of the user
],
username: 'TestUser' // Username
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Assign Role
Assign new roles to the user of the graph database instance
`javascript
graphDBEndpoint
.assignRoles({
userName: 'ashesh',
authorities: [
{
action: 'READ',
resource_type: 'db',
resource: ['Test']
},
{
action: 'WRITE',
resource_type: 'db',
resource: ['Test']
}
]
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Remove Role
Remove existing roles of a user in the graph database instance
`javascript
graphDBEndpoint
.removeRoles({
username: 'TestUser',
authorities: [
{
action: 'READ',
resource_type: 'db',
resource: ['Test']
},
{
action: 'WRITE',
resource_type: 'db',
resource: ['Test']
}
]
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Delete User
Caution! This deletes the user including all assigned authorities (roles)! This operation cannot be undone!
Deletes a user from the graph database instance:
if security is on then for Deleting User, the user role needs to be Administrator else operation is not performed
`javascript
graphDBEndpoint
.deleteUser({
user: 'TestUser2' // username which you want to delete
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Get Repositories
Get details of all repositories of the graph database repositories operated on the connected host:
`javascript
graphDBEndpoint
.getRepositories()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Clear Repository
Caution! This removes ALL triples of the given repository! This operation cannot be undone!
The entire repository will be emptied, i.e. all data of this repository will be removed. The repository remains active.
`javascript
graphDBEndpoint
.clearRepository()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Get Users
Get all details of all users of a certain graph database instance:
`javascript
graphDBEndpoint
.getUsers()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Get Query
Get Query from graph database:
`javascript
graphDBEndpoint
.getQuery()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Get Contexts
List all named graphs inside a given repository:
`javascript
graphDBEndpoint
.getContexts()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
`
Clear Context
Caution! This removes ALL triples of the given context! This operation cannot be undone!
The entire context will be emptied, i.e. all data from this context will be removed. The repository and other contexts remain active.
`javascript
graphDBEndpoint
.clearContext('http://ont.enapso.com/test')
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err, 'process error here...');
});
`
Get Locations
Get details of all locations which are associated with the connected graph database instance:
`javascript
graphDBEndpoint
.getLocations()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Get Saved Queries
Get details of all queries which are saved in a graph database instance:
`javascript
graphDBEndpoint
.getSavedQueries()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Create Repository
Create a new repository in the graph database instance, isShacl parameter is optional by default it is false.
if security is on then for creating a repository, the user role needs to be Repository Manager else operation is not performed
`javascript
graphDBEndpoint
.createRepository({
id: 'AutomatedTest4',
title: 'enapso Automated Test Repository',
location: '',
isShacl: true
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Delete Repository
Delete a repository in the connected graph database instance:
if security is on then for deleting the repository, the user role needs to be Repository Manager else operation is not performed
`javascript
graphDBEndpoint
.deleteRepository({
id: 'AutomatedTest'
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
`
Drop SHACL Graph
Drop a shacl Shape from graph database to remove all validations:
`javascript
graphDBEndpoint
.dropShaclGraph()
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
``