Difference between revisions of "Resource Registry Service - Query Templates Management"
Luca.frosini (Talk | contribs) (→Create via REST API Resource Example) |
Luca.frosini (Talk | contribs) m (→Query Templates Management) |
||
(44 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; | ||
* '''Delete''': it allows to delete a query template. | * '''Delete''': it allows to delete a query template. | ||
− | |||
The Query Templates Management implements the following policies: | The Query Templates Management implements the following policies: | ||
* it manages the Header automatically; | * it manages the Header automatically; | ||
− | * it allows identifying an instance via the | + | * it allows identifying an instance via the provided name; |
− | * it validates the query templates by applying the provided default values | + | * 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 [[Resource_Registry_Service_-_Query_%26_Access#JSON_Query| 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 [[Resource_Registry_Service_-_Query_%26_Access#JSON_Query| JSON Query]] documentation to understand how to create a JSON Query. | ||
+ | |||
== Query Template Collection == | == Query Template Collection == | ||
Line 49: | Line 56: | ||
== Resource Registry Query Template Client == | == Resource Registry Query Template Client == | ||
− | |||
− | |||
Resource Registry Query Template Client is a java library providing RPC facilities to interact with [[Resource Registry Service - Query Templates Management | Query Templates Management]]. | Resource Registry Query Template Client is a java library providing RPC facilities to interact with [[Resource Registry Service - Query Templates Management | Query Templates Management]]. | ||
Line 59: | Line 64: | ||
<dependency> | <dependency> | ||
<groupId>org.gcube.information-system</groupId> | <groupId>org.gcube.information-system</groupId> | ||
− | <artifactId>resource-registry-query- | + | <artifactId>resource-registry-query-template-client</artifactId> |
<version>[1.0.0,2.0.0-SNAPSHOT)</version> | <version>[1.0.0,2.0.0-SNAPSHOT)</version> | ||
<dependency> | <dependency> | ||
Line 68: | Line 73: | ||
<source lang="java"> | <source lang="java"> | ||
− | import org.gcube.informationsystem.resourceregistry.queries.templates. | + | import org.gcube.informationsystem.resourceregistry.queries.templates.ResourceRegistryQueryTemplateClient; |
− | import org.gcube.informationsystem.resourceregistry.queries.templates. | + | import org.gcube.informationsystem.resourceregistry.queries.templates.ResourceRegistryQueryTemplateClientFactory; |
... | ... | ||
− | + | ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create(); | |
</source> | </source> | ||
The provided client exposes the available methods and options as explained below. | The provided client exposes the available methods and options as explained below. | ||
− | The source code of the resource-registry-query- | + | The source code of the resource-registry-query-template-client is available at [https://code-repo.d4science.org/gCubeSystem/resource-registry-query-template-client https://code-repo.d4science.org/gCubeSystem/resource-registry-query-template-client] |
== APIs == | == APIs == | ||
Line 90: | Line 95: | ||
<source lang="java"> | <source lang="java"> | ||
− | + | public List<QueryTemplate> all() throws ResourceRegistryException; | |
</source> | </source> | ||
Line 99: | Line 104: | ||
<source lang="java"> | <source lang="java"> | ||
− | .. | + | |
+ | ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create(); | ||
+ | List<QueryTemplate> queryTemplates = resourceRegistryQueryTemplateClient.all(); | ||
</source> | </source> | ||
Line 113: | Line 120: | ||
<pre>GET /query-templates</pre> | <pre>GET /query-templates</pre> | ||
+ | '''Response Body''' | ||
+ | |||
+ | <source lang="JavaScript"> | ||
+ | [{ | ||
+ | "@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> | ||
=== Create Query Template === | === Create Query Template === | ||
Line 121: | 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 127: | 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 148: | Line 216: | ||
"@class": "QueryTemplate", | "@class": "QueryTemplate", | ||
"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\"}", |
− | + | ||
− | + | ||
"template": { | "template": { | ||
"@class": "EService", | "@class": "EService", | ||
Line 161: | Line 227: | ||
}] | }] | ||
}, | }, | ||
− | "templateVariables" | + | "templateVariables" : { |
"$state" : { | "$state" : { | ||
"@class": "TemplateVariable", | "@class": "TemplateVariable", | ||
Line 167: | Line 233: | ||
"description": "The state of the EService, e.g. down, ready.", | "description": "The state of the EService, e.g. down, ready.", | ||
"defaultValue": "ready" | "defaultValue": "ready" | ||
− | + | ||
} | } | ||
} | } | ||
− | + | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | '''Response Body''' | ||
+ | |||
+ | <source lang="JavaScript"> | ||
+ | { | ||
+ | "@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 178: | 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 186: | Line 294: | ||
<source lang="java"> | <source lang="java"> | ||
− | .. | + | ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create(); |
+ | QueryTemplate readQueryTemplate = resourceRegistryQueryTemplateClient.read("GetAllEServiceWithState"); | ||
</source> | </source> | ||
Line 203: | Line 312: | ||
<source lang="JavaScript"> | <source lang="JavaScript"> | ||
{ | { | ||
− | + | "@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 238: | 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 245: | 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> | ||
==== Update via REST API ==== | ==== Update via REST API ==== | ||
− | <pre>PUT /query-templates/{QUERY_TEMPLATE_NAME}</pre> | + | <pre>PUT /query-templates/{QUERY_TEMPLATE_NAME}</pre> |
− | ===== Update via REST API Example ===== | + | ===== Update via REST API Resource Example ===== |
+ | |||
+ | The following listing shows an example of a template update. | ||
'''Request URL''' | '''Request URL''' | ||
− | <pre>PUT /query-templates/ | + | <pre>PUT /query-templates/GetAllEServiceWithState</pre> |
'''Request Body''' | '''Request Body''' | ||
<source lang="JavaScript"> | <source lang="JavaScript"> | ||
− | ... | + | { |
+ | "@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" | ||
+ | } | ||
+ | } | ||
+ | } | ||
</source> | </source> | ||
+ | |||
'''Response Body''' | '''Response Body''' | ||
<source lang="JavaScript"> | <source lang="JavaScript"> | ||
− | ... | + | { |
+ | "@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" | ||
+ | } | ||
+ | } | ||
+ | } | ||
</source> | </source> | ||
Line 273: | 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> | ||
==== Run via REST API ==== | ==== Run via REST API ==== | ||
− | <pre> | + | <pre>POST /query-templates/{QUERY_TEMPLATE_NAME}</pre> |
===== Run via REST Example ===== | ===== Run via REST Example ===== | ||
Line 292: | Line 500: | ||
'''Request URL''' | '''Request URL''' | ||
− | <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''' | ||
+ | |||
+ | <source lang="JavaScript"> | ||
+ | { | ||
+ | "$state" : "down" | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | The response will contain a JSON array containing all the ''EService'' instances which are '''down'''. | ||
=== Delete Query Template === | === Delete Query Template === | ||
Line 299: | 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 305: | Line 529: | ||
<source lang="java"> | <source lang="java"> | ||
− | .. | + | ResourceRegistryQueryTemplateClient resourceRegistryQueryTemplateClient = ResourceRegistryQueryTemplateClientFactory.create(); |
+ | boolean deleted = resourceRegistryQueryTemplateClient.delete("GetAllEServiceWithState"); | ||
</source> | </source> | ||
==== Delete via REST API ==== | ==== Delete via REST API ==== | ||
− | <pre>DELETE /query-templates/{ | + | <pre>DELETE /query-templates/{QUERY_TEMPLATE_NAME}</pre> |
===== Delete via REST Example ===== | ===== Delete via REST Example ===== | ||
Line 316: | Line 541: | ||
'''Request URL''' | '''Request URL''' | ||
− | <pre>DELETE /query-templates/ | + | <pre>DELETE /query-templates/GetAllEServiceWithState</pre> |
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