Difference between revisions of "Resource Registry Service - Query Templates Management"

From Gcube Wiki
Jump to: navigation, search
(Create via REST API Resource Example)
m (Query Templates Management)
 
(23 intermediate revisions by the same user not shown)
Line 18: Line 18:
 
* '''Read''': it allows to read a query template;
 
* '''Read''': it allows to read a query template;
 
* '''Update''': it allows to update a query template;
 
* '''Update''': it allows to update a query template;
* '''run''': it allows to run a query template by providing the template variable values;
+
* '''Run''': it allows to run a query template by providing the template variable values;
 
* '''Delete''': it allows to delete a query template.
 
* '''Delete''': it allows to delete a query template.
  
Line 95: Line 95:
 
<source lang="java">
 
<source lang="java">
  
public List<String> all() throws ResourceRegistryException;
+
public List<QueryTemplate> all() throws ResourceRegistryException;
  
 
</source>
 
</source>
Line 106: Line 106:
  
 
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
 
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
List<String> queryTemplates = resourceRegistryQueryTemplateClient.all();
+
List<QueryTemplate> queryTemplates = resourceRegistryQueryTemplateClient.all();
  
 
</source>
 
</source>
Line 123: Line 123:
  
 
<source lang="JavaScript">
 
<source lang="JavaScript">
[ "GetAllEServiceWithState", "GetAllSpecificEServiceWithState", ... ]
+
[{
 +
    "@class": "QueryTemplate",
 +
    "header": {
 +
        "@class": "Header",
 +
        "uuid": "fcc01dd3-5ee1-4228-87fd-92e205a86c40",
 +
        "createdBy": "luca.frosini",
 +
        "creationTime": "2022-02-07 17:53:46.528 +0100",
 +
        "lastUpdateBy": "luca.frosini",
 +
        "lastUpdateTime": "2022-02-07 17:53:46.528 +0100"
 +
    },
 +
    "name": "GetAllEServiceWithState",
 +
    "description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
 +
    "template": {
 +
"@class": "EService",
 +
"consistsOf": [{
 +
"@class": "ConsistsOf",
 +
"target": {
 +
"@class": "StateFacet",
 +
"value": "$state"
 +
}
 +
}]
 +
    },
 +
    "templateVariables": {
 +
        "$state": {
 +
            "@class": "TemplateVariable",
 +
            "name": "$state",
 +
            "description": "The state of the EService, e.g. down, ready.",
 +
            "defaultValue": "ready"
 +
        }
 +
    }
 +
}]
 
</source>
 
</source>
  
Line 133: Line 163:
  
 
<source lang="java">
 
<source lang="java">
...
+
public QueryTemplate create(QueryTemplate queryTemplate) throws QueryTemplateAlreadyPresentException, ResourceRegistryException;
 +
 
 +
public String create(String queryTemplate) throws QueryTemplateAlreadyPresentException, ResourceRegistryException;
 
</source>
 
</source>
  
Line 139: Line 171:
 
===== Create via Java Client Example =====
 
===== Create via Java Client Example =====
 
<source lang="Java">
 
<source lang="Java">
...
+
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
 +
QueryTemplate queryTemplate = new QueryTemplate();
 +
queryTemplate.setName("GetAllEServiceWithState");
 +
queryTemplate.setDescription("The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}");
 +
 
 +
String templateString = "{\n"
 +
+ " \"@class\": \"EService\",\n"
 +
+ " \"consistsOf\": [{\n"
 +
+ " \"@class\": \"ConsistsOf\",\n"
 +
+ " \"target\": {\n"
 +
+ " \"@class\": \"StateFacet\",\n"
 +
+ " \"value\": \"$state\"\n"
 +
+ " }\n"
 +
+ " }]\n"
 +
+ "    }";
 +
queryTemplate.setTemplate(templateString);
 +
 
 +
 
 +
TemplateVariable stateTemplateVariable = new TemplateVariableImpl();
 +
stateTemplateVariable.setName("$state");
 +
stateTemplateVariable.setDescription("The state of the EService, e.g. down, ready.");
 +
stateTemplateVariable.setDefaultValue("ready");
 +
queryTemplate.addTemplateVariable(stateTemplateVariable);
 +
 
 +
QueryTemplate createdQueryTemplate = resourceRegistryQueryTemplateClient.create(queryTemplate);
 
</source>
 
</source>
  
Line 212: Line 268:
 
         "$state": {
 
         "$state": {
 
             "@class": "TemplateVariable",
 
             "@class": "TemplateVariable",
            "defaultValue": "ready",
 
 
             "name": "$state",
 
             "name": "$state",
             "description": "The state of the EService, e.g. down, ready."
+
             "description": "The state of the EService, e.g. down, ready.",
 +
            "defaultValue": "ready"
 
         }
 
         }
 
     }
 
     }
Line 224: Line 280:
  
 
==== Read via Java Client ====
 
==== Read via Java Client ====
 +
 +
'''Signature'''
  
 
<source lang="java">
 
<source lang="java">
...
+
public QueryTemplate read(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
 +
 
 +
public QueryTemplate read(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException;
 +
 
 +
public String readAsString(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
</source>
 
</source>
  
Line 232: Line 294:
  
 
<source lang="java">
 
<source lang="java">
...
+
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
 +
QueryTemplate readQueryTemplate = resourceRegistryQueryTemplateClient.read("GetAllEServiceWithState");
 
</source>
 
</source>
  
Line 249: Line 312:
 
<source lang="JavaScript">
 
<source lang="JavaScript">
 
{
 
{
"@class": "QueryTemplate",
+
    "@class": "QueryTemplate",
"header": {
+
    "header": {
"@class": "Header",
+
        "@class": "Header",
"uuid": "459c1658-b9d9-4ec7-9ff2-a019af45f0e9",
+
        "uuid": "fcc01dd3-5ee1-4228-87fd-92e205a86c40",
"createdBy": "luca.frosini",
+
        "createdBy": "luca.frosini",
"creationTime": "2022-01-28 19:33:12.395 +0100",
+
        "creationTime": "2022-02-07 17:53:46.528 +0100",
"lastUpdateBy": "luca.frosini"
+
        "lastUpdateBy": "luca.frosini",
"lastUpdateTime": "2022-01-28 19:33:12.395 +0100"
+
        "lastUpdateTime": "2022-02-07 17:53:46.528 +0100"
}
+
    },
"name" : "GetAllEServiceWithState",
+
    "name": "GetAllEServiceWithState",
"description": "The following query return all the EService having the state provided as  
+
    "description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
parameters, e.g. down, ready. The content of the request to run this query  
+
    "template": {
template will be something like {"$state": "ready"}",
+
"@class": "EService",
"template": {
+
"consistsOf": [{
"@class": "EService",
+
"@class": "ConsistsOf",
"consistsOf": [{
+
"target": {
"@class": "ConsistsOf",
+
"@class": "StateFacet",
"target": {
+
"value": "$state"
"@class": "StateFacet",
+
"value": "$state"
+
}
+
}]
+
},
+
"templateVariables" = {
+
"$state" : {
+
"@class": "TemplateVariable",
+
"name": "$state",
+
"description": "The state of the EService, e.g. down, ready.",
+
"defaultValue": "ready"
+
+
 
}
 
}
}
+
}]
+
    },
 +
    "templateVariables": {
 +
        "$state": {
 +
            "@class": "TemplateVariable",
 +
            "name": "$state",
 +
            "description": "The state of the EService, e.g. down, ready.",
 +
            "defaultValue": "ready"
 +
        }
 +
    }
 
}
 
}
 
</source>
 
</source>
Line 292: Line 351:
  
 
<source lang="java">
 
<source lang="java">
...
+
public QueryTemplate update(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
 +
 
 +
public String update(String queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
</source>
 
</source>
  
Line 299: Line 360:
  
 
<source lang="java">
 
<source lang="java">
...
+
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
 +
 
 +
QueryTemplate readQueryTemplate = resourceRegistryQueryTemplateClient.read("GetAllEServiceWithState");
 +
TemplateVariable tv = readQueryTemplate.getTemplateVariables().get("$state");
 +
tv.setDefaultValue("down");
 +
 
 +
QueryTemplate updatedQueryTemplate = resourceRegistryQueryTemplateClient.update(readQueryTemplate);
 
</source>
 
</source>
  
Line 318: Line 385:
 
<source lang="JavaScript">
 
<source lang="JavaScript">
 
{
 
{
"@class": "QueryTemplate",
+
    "@class": "QueryTemplate",
"header": {
+
    "header": {
"@class": "Header",
+
        "@class": "Header",
"uuid": "459c1658-b9d9-4ec7-9ff2-a019af45f0e9"
+
        "uuid": "fcc01dd3-5ee1-4228-87fd-92e205a86c40",
}
+
        "createdBy": "luca.frosini",
"name" : "GetAllEServiceWithState",
+
        "creationTime": "2022-02-07 17:53:46.528 +0100",
"description": "The following query return all the EService having the state provided as  
+
        "lastUpdateBy": "luca.frosini",
parameters, e.g. down, ready. The content of the request to run this query  
+
        "lastUpdateTime": "2022-02-07 17:53:46.528 +0100"
template will be something like {\"$state\": \"down\"}",
+
    },
"template": {
+
    "name": "GetAllEServiceWithState",
"@class": "EService",
+
    "description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
"consistsOf": [{
+
    "template": {
"@class": "ConsistsOf",
+
"@class": "EService",
"target": {
+
"consistsOf": [{
"@class": "StateFacet",
+
"@class": "ConsistsOf",
"value": "$state"
+
"target": {
}
+
"@class": "StateFacet",
}]
+
"value": "$state"
},
+
"templateVariables" = {
+
"$state" : {
+
"@class": "TemplateVariable",
+
"name": "$state",
+
"description": "The state of the EService, e.g. down, ready.",
+
"defaultValue": "down"
+
+
 
}
 
}
}
+
}]
+
    },
 +
    "templateVariables": {
 +
        "$state": {
 +
            "@class": "TemplateVariable",
 +
            "name": "$state",
 +
            "description": "The state of the EService, e.g. down, ready.",
 +
            "defaultValue": "down"
 +
        }
 +
    }
 
}
 
}
 
</source>
 
</source>
 +
  
 
'''Response Body'''
 
'''Response Body'''
Line 354: Line 422:
 
<source lang="JavaScript">
 
<source lang="JavaScript">
 
{
 
{
"@class": "QueryTemplate",
+
    "@class": "QueryTemplate",
"header": {
+
    "header": {
"@class": "Header",
+
        "@class": "Header",
"uuid": "459c1658-b9d9-4ec7-9ff2-a019af45f0e9",
+
        "uuid": "fcc01dd3-5ee1-4228-87fd-92e205a86c40",
"createdBy": "luca.frosini",
+
        "createdBy": "luca.frosini",
"creationTime": "2022-01-28 19:33:12.395 +0100",
+
        "creationTime": "2022-02-07 17:53:46.528 +0100",
"lastUpdateBy": "luca.frosini"
+
        "lastUpdateBy": "luca.frosini",
"lastUpdateTime": "2022-01-28 19:35:32.125 +0100"
+
        "lastUpdateTime": "2022-02-07 18:03:08.281 +0100"
}
+
    },
"name" : "GetAllEServiceWithState",
+
    "name": "GetAllEServiceWithState",
"description": "The following query return all the EService having the state provided as  
+
    "description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
parameters, e.g. down, ready. The content of the request to run this query  
+
    "template": {
template will be something like {\"$state\": \"down\"}",
+
"@class": "EService",
"template": {
+
"consistsOf": [{
"@class": "EService",
+
"@class": "ConsistsOf",
"consistsOf": [{
+
"target": {
"@class": "ConsistsOf",
+
"@class": "StateFacet",
"target": {
+
"value": "$state"
"@class": "StateFacet",
+
"value": "$state"
+
}
+
}]
+
},
+
"templateVariables" = {
+
"$state" : {
+
"@class": "TemplateVariable",
+
"name": "$state",
+
"description": "The state of the EService, e.g. down, ready.",
+
"defaultValue": "down"
+
+
 
}
 
}
}
+
}]
+
    },
 +
    "templateVariables": {
 +
        "$state": {
 +
            "@class": "TemplateVariable",
 +
            "name": "$state",
 +
            "description": "The state of the EService, e.g. down, ready.",
 +
            "defaultValue": "down"
 +
        }
 +
    }
 
}
 
}
 
</source>
 
</source>
Line 393: Line 457:
  
 
==== Run via Java Client ====
 
==== Run via Java Client ====
 +
 +
'''Signature'''
  
 
<source lang="java">
 
<source lang="java">
...
+
public String runGetString(String name) throws QueryTemplateNotFoundException, ResourceRegistryException;
 +
 +
public <E extends Entity> List<E> run(String name) throws QueryTemplateNotFoundException, ResourceRegistryException;
 +
 +
public <E extends Entity> List<E> run(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
 +
 +
public String run(String name, String params) throws QueryTemplateNotFoundException, ResourceRegistryException;
 +
 
 +
public <E extends Entity> List<E> run(String name, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException;
 +
 +
public <E extends Entity> List<E> run(QueryTemplate queryTemplate, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
</source>
 
</source>
  
 
===== Run via Java Client Example =====
 
===== Run via Java Client Example =====
 +
 +
Run using default parameters:
  
 
<source lang="java">
 
<source lang="java">
...
+
List<Entity> entities = resourceRegistryQueryTemplateClient.run(queryTemplate);
 +
</source>
 +
 
 +
Run using desired parameter values:
 +
 
 +
<source lang="java">
 +
ObjectMapper objectMapper = new ObjectMapper();
 +
ObjectNode params = objectMapper.createObjectNode();
 +
params.put("$state", "down");
 +
 
 +
List<Entity> entities = resourceRegistryQueryTemplateClient.run(queryTemplate, params);
 
</source>
 
</source>
  
Line 413: Line 501:
  
 
<pre>POST /query-templates/GetAllEServiceWithState</pre>
 
<pre>POST /query-templates/GetAllEServiceWithState</pre>
 +
 +
The body of the request can be null to use the default parameters.
 +
 +
Provide a body as JSON to run the query using desired parameter values:
  
 
'''Request Body'''
 
'''Request Body'''
Line 429: Line 521:
  
 
<source lang="java">
 
<source lang="java">
...
+
public boolean delete(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
 +
 
 +
public boolean delete(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
</source>
 
</source>
  
Line 435: Line 529:
  
 
<source lang="java">
 
<source lang="java">
...
+
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
 +
boolean deleted = resourceRegistryQueryTemplateClient.delete("GetAllEServiceWithState");
 
</source>
 
</source>
  

Latest revision as of 19:41, 8 February 2022

These sections provide information regarding how to interact with Resource Registry Service for query templates management. This page presents REST and JAVA API for each functionality.

Please note that the provided examples can intentionally hide some details to avoid unneeded complexity.

Query Templates Management

Query Templates Management is responsible for the management of query templates. It offers the following APIs:

  • List: it allows to list query templates;
  • Create: it allows to create a new query template;
  • Exists: it allows to check if an query template exists;
  • Read: it allows to read a query template;
  • Update: it allows to update a query template;
  • Run: it allows to run a query template by providing the template variable values;
  • Delete: it allows to delete a query template.

The Query Templates Management implements the following policies:

  • it manages the Header automatically;
  • it allows identifying an instance via the provided name;
  • it validates the query templates by applying the provided default values by running the generated query.


Please note that a query template is composed by JSON Query that uses variables. The variables are in the form $avriableName. You can run a query template by providing the values of the variables.

Please refers to JSON Query documentation to understand how to create a JSON Query.

Query Template Collection

The following table shows the exposed APIs as REST Collection.

Operation HTTP Method URL
List GET /query-templates
Create PUT /query-templates/{QUERY_TEMPLATE_NAME}
Exists HEAD /query-templates/{QUERY_TEMPLATE_NAME}
Read GET /query-templates/{QUERY_TEMPLATE_NAME}
Update PUT /query-templates/{QUERY_TEMPLATE_NAME}
Run POST /query-templates/{QUERY_TEMPLATE_NAME}
Delete DELETE /query-templates/{QUERY_TEMPLATE_NAME}

Resource Registry Query Template Client

Resource Registry Query Template Client is a java library providing RPC facilities to interact with Query Templates Management.

To use the Java library to interact with Query Template collection declare the following dependency in your pom.xml file.

<dependency>
	<groupId>org.gcube.information-system</groupId>
	<artifactId>resource-registry-query-template-client</artifactId>
	<version>[1.0.0,2.0.0-SNAPSHOT)</version>
<dependency>


To use the client you just need to instantiate the client via the provided factory.

import org.gcube.informationsystem.resourceregistry.queries.templates.ResourceRegistryQueryTemplateClient;
import org.gcube.informationsystem.resourceregistry.queries.templates.ResourceRegistryQueryTemplateClientFactory;
 
...
 
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();

The provided client exposes the available methods and options as explained below.

The source code of the resource-registry-query-template-client is available at https://code-repo.d4science.org/gCubeSystem/resource-registry-query-template-client

APIs

List Query Templates

List via Java Client

Signature

public List<QueryTemplate> all() throws ResourceRegistryException;
List via Java Client Example

The following snippet of code shows how to list all the query templates.

ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
List<QueryTemplate> queryTemplates = resourceRegistryQueryTemplateClient.all();

List via REST API

List via REST API Example

The following request shows how to retrieve all the resource instances.

Request URL

GET /query-templates

Response Body

[{
    "@class": "QueryTemplate",
    "header": {
        "@class": "Header",
        "uuid": "fcc01dd3-5ee1-4228-87fd-92e205a86c40",
        "createdBy": "luca.frosini",
        "creationTime": "2022-02-07 17:53:46.528 +0100",
        "lastUpdateBy": "luca.frosini",
        "lastUpdateTime": "2022-02-07 17:53:46.528 +0100"
    },
    "name": "GetAllEServiceWithState",
    "description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
    "template": {
	"@class": "EService",
	"consistsOf": [{
		"@class": "ConsistsOf",
		"target": {
			"@class": "StateFacet",
			"value": "$state"
		}
	}]
    },
    "templateVariables": {
        "$state": {
            "@class": "TemplateVariable",
            "name": "$state",
            "description": "The state of the EService, e.g. down, ready.",
            "defaultValue": "ready"
        }
    }
}]

Create Query Template

Create via Java Client

Signature

public QueryTemplate create(QueryTemplate queryTemplate) throws QueryTemplateAlreadyPresentException, ResourceRegistryException;
 
public String create(String queryTemplate) throws QueryTemplateAlreadyPresentException, ResourceRegistryException;


Create via Java Client Example
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
QueryTemplate queryTemplate = new QueryTemplate();
queryTemplate.setName("GetAllEServiceWithState");
queryTemplate.setDescription("The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}");
 
String templateString = "{\n"
		+ "	\"@class\": \"EService\",\n"
		+ "	\"consistsOf\": [{\n"
		+ "		\"@class\": \"ConsistsOf\",\n"
		+ "		\"target\": {\n"
		+ "			\"@class\": \"StateFacet\",\n"
		+ "			\"value\": \"$state\"\n"
		+ "		}\n"
		+ "	}]\n"
		+ "    }";
queryTemplate.setTemplate(templateString);
 
 
TemplateVariable stateTemplateVariable = new TemplateVariableImpl();
stateTemplateVariable.setName("$state");
stateTemplateVariable.setDescription("The state of the EService, e.g. down, ready.");
stateTemplateVariable.setDefaultValue("ready");
queryTemplate.addTemplateVariable(stateTemplateVariable);
 
QueryTemplate createdQueryTemplate = resourceRegistryQueryTemplateClient.create(queryTemplate);

Create via REST API

PUT  /query-templates/{QUERY_TEMPLATE_NAME}
Create via REST API Resource Example

The following listing shows an example of EService representation to be created.

Request URL

PUT /query-templates/GetAllEServiceWithState

Request Body

{
	"@class": "QueryTemplate",
	"name" : "GetAllEServiceWithState",
	"description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
	"template": {
		"@class": "EService",
		"consistsOf": [{
			"@class": "ConsistsOf",
			"target": {
				"@class": "StateFacet",
				"value": "$state"
			}
		}]
	},
	"templateVariables" : {
		"$state" : {
			"@class": "TemplateVariable",
			"name": "$state",
			"description": "The state of the EService, e.g. down, ready.",
			"defaultValue": "ready"
 
		}
	}
 
}

Response Body

{
    "@class": "QueryTemplate",
    "header": {
        "@class": "Header",
        "uuid": "fcc01dd3-5ee1-4228-87fd-92e205a86c40",
        "createdBy": "luca.frosini",
        "creationTime": "2022-02-07 17:53:46.528 +0100",
        "lastUpdateBy": "luca.frosini",
        "lastUpdateTime": "2022-02-07 17:53:46.528 +0100"
    },
    "name": "GetAllEServiceWithState",
    "description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
    "template": {
	"@class": "EService",
	"consistsOf": [{
		"@class": "ConsistsOf",
		"target": {
			"@class": "StateFacet",
			"value": "$state"
		}
	}]
    },
    "templateVariables": {
        "$state": {
            "@class": "TemplateVariable",
            "name": "$state",
            "description": "The state of the EService, e.g. down, ready.",
            "defaultValue": "ready"
        }
    }
}

Read Query Template

Read via Java Client

Signature

public QueryTemplate read(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
public QueryTemplate read(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
public String readAsString(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException;
Read via Java Client Example
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
QueryTemplate readQueryTemplate = resourceRegistryQueryTemplateClient.read("GetAllEServiceWithState");

Read via REST API

GET /query-templates/{QUERY_TEMPLATE_NAME}
Read via REST Example

Request URL

GET /query-templates/GetAllEServiceWithState

Response Body

{
    "@class": "QueryTemplate",
    "header": {
        "@class": "Header",
        "uuid": "fcc01dd3-5ee1-4228-87fd-92e205a86c40",
        "createdBy": "luca.frosini",
        "creationTime": "2022-02-07 17:53:46.528 +0100",
        "lastUpdateBy": "luca.frosini",
        "lastUpdateTime": "2022-02-07 17:53:46.528 +0100"
    },
    "name": "GetAllEServiceWithState",
    "description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
    "template": {
	"@class": "EService",
	"consistsOf": [{
		"@class": "ConsistsOf",
		"target": {
			"@class": "StateFacet",
			"value": "$state"
		}
	}]
    },
    "templateVariables": {
        "$state": {
            "@class": "TemplateVariable",
            "name": "$state",
            "description": "The state of the EService, e.g. down, ready.",
            "defaultValue": "ready"
        }
    }
}

Update Instance

Update via Java Client

Signature

public QueryTemplate update(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
public String update(String queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;


Update via Java Client Example
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
 
QueryTemplate readQueryTemplate = resourceRegistryQueryTemplateClient.read("GetAllEServiceWithState");
TemplateVariable tv = readQueryTemplate.getTemplateVariables().get("$state");
tv.setDefaultValue("down");
 
QueryTemplate updatedQueryTemplate = resourceRegistryQueryTemplateClient.update(readQueryTemplate);

Update via REST API

PUT  /query-templates/{QUERY_TEMPLATE_NAME}
Update via REST API Resource Example

The following listing shows an example of a template update.

Request URL

PUT /query-templates/GetAllEServiceWithState

Request Body

{
    "@class": "QueryTemplate",
    "header": {
        "@class": "Header",
        "uuid": "fcc01dd3-5ee1-4228-87fd-92e205a86c40",
        "createdBy": "luca.frosini",
        "creationTime": "2022-02-07 17:53:46.528 +0100",
        "lastUpdateBy": "luca.frosini",
        "lastUpdateTime": "2022-02-07 17:53:46.528 +0100"
    },
    "name": "GetAllEServiceWithState",
    "description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
    "template": {
	"@class": "EService",
	"consistsOf": [{
		"@class": "ConsistsOf",
		"target": {
			"@class": "StateFacet",
			"value": "$state"
		}
	}]
    },
    "templateVariables": {
        "$state": {
            "@class": "TemplateVariable",
            "name": "$state",
            "description": "The state of the EService, e.g. down, ready.",
            "defaultValue": "down"
        }
    }
}


Response Body

{
    "@class": "QueryTemplate",
    "header": {
        "@class": "Header",
        "uuid": "fcc01dd3-5ee1-4228-87fd-92e205a86c40",
        "createdBy": "luca.frosini",
        "creationTime": "2022-02-07 17:53:46.528 +0100",
        "lastUpdateBy": "luca.frosini",
        "lastUpdateTime": "2022-02-07 18:03:08.281 +0100"
    },
    "name": "GetAllEServiceWithState",
    "description": "The following query return all the EService having the state provided as parameters, e.g. down, ready. The content of the request to run this query template will be something like {\"$state\": \"ready\"}",
    "template": {
	"@class": "EService",
	"consistsOf": [{
		"@class": "ConsistsOf",
		"target": {
			"@class": "StateFacet",
			"value": "$state"
		}
	}]
    },
    "templateVariables": {
        "$state": {
            "@class": "TemplateVariable",
            "name": "$state",
            "description": "The state of the EService, e.g. down, ready.",
            "defaultValue": "down"
        }
    }
}

Run Query Template

Run via Java Client

Signature

public String runGetString(String name) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
public <E extends Entity> List<E> run(String name) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
public <E extends Entity> List<E> run(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
public String run(String name, String params) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
public <E extends Entity> List<E> run(String name, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
public <E extends Entity> List<E> run(QueryTemplate queryTemplate, JsonNode jsonNode) throws QueryTemplateNotFoundException, ResourceRegistryException;
Run via Java Client Example

Run using default parameters:

List<Entity> entities = resourceRegistryQueryTemplateClient.run(queryTemplate);

Run using desired parameter values:

ObjectMapper objectMapper = new ObjectMapper();
ObjectNode params = objectMapper.createObjectNode();
params.put("$state", "down");
 
List<Entity> entities = resourceRegistryQueryTemplateClient.run(queryTemplate, params);

Run via REST API

POST /query-templates/{QUERY_TEMPLATE_NAME}
Run via REST Example

Request URL

POST /query-templates/GetAllEServiceWithState

The body of the request can be null to use the default parameters.

Provide a body as JSON to run the query using desired parameter values:

Request Body

{
	"$state" : "down"
}

The response will contain a JSON array containing all the EService instances which are down.

Delete Query Template

Delete via Java Client

public boolean delete(QueryTemplate queryTemplate) throws QueryTemplateNotFoundException, ResourceRegistryException;
 
public boolean delete(String queryTemplateName) throws QueryTemplateNotFoundException, ResourceRegistryException;
Delete via Java Client Example
ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create();
boolean deleted = resourceRegistryQueryTemplateClient.delete("GetAllEServiceWithState");

Delete via REST API

DELETE /query-templates/{QUERY_TEMPLATE_NAME}
Delete via REST Example

Request URL

DELETE /query-templates/GetAllEServiceWithState