Resource Registry Service - Instances Management
These sections provide information regarding how to interact with Resource Registry Service for Entities and Relations instances Management.
REST and JAVA API are presented for each functionality.
Please note that the provided examples can intentionally hide some details in the response to avoid unneeded complexity.
Instances Management
Apart the REST API this port type can be used also by using Resource Registry Publisher java client.
Resource Registry Publisher has the following maven coordinates
<dependency> <groupId>org.gcube.information-system</groupId> <artifactId>resource-registry-publisher</artifactId> <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> </dependency>
To use the client, you need first get a ResourceRegistryPublisher instance.
By using ResourceRegistryPublisherFactory.create() method the library discovers the correct endpoint to interact with the Resource Registry for the current context.
SecurityTokenProvider.instance.set("Your-NextNext-Token-Here"); //If not already set ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
Facet Instances APIs
Create Facet Instance
REST API
PUT /resource-registry/er/facet/{FacetType}
Example
PUT /resource-registry/er/facet/CPUFacet
Request Body
{ "@class":"CPUFacet", "header":null, "model":"Opteron", "vendor":"AMD", "clockSpeed":"1 GHz" }
Response Body
{ "@class":"CPUFacet", "header": { "uuid":"69f0b376-38d2-4a85-bc63-37f9fa323f82", "creator":"luca.frosini", "lastUpdater":"luca.frosini", "creationTime":"2016-10-05 11:16:24", "lastUpdateTime":"2016-10-05 11:16:24 }, "model":"Opteron", "vendor":"AMD", "clockSpeed":"1 GHz" }
Java API
public <F extends Facet> F createFacet(F facet) throws FacetAlreadyPresentException, ResourceRegistryException;
Example
CPUFacet cpuFacet = new CPUFacetImpl(); cpuFacet.setClockSpeed("1 GHz"); cpuFacet.setModel("Opteron"); cpuFacet.setVendor("AMD"); CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet); UUID uuid = createdCpuFacet.getHeader().getUUID(); // 69f0b376-38d2-4a85-bc63-37f9fa323f82
Alternative JAVA API
There are also two other equivalent methods with the following signature:
public String createFacet(String facet) throws FacetAlreadyPresentException, ResourceRegistryException; public String createFacet(String facetType, String facet) throws FacetAlreadyPresentException, ResourceRegistryException;
The first methods get the Facet to be created as JSON string instead of as Java class. The second get also the facetType as parameter (which as to be specified as PATH PARAMETER in the request) avoiding to force client to retrieve it from the string. The second method is more efficient but you have to be sure that the facetType is the same specified in the header of the serialized facet.
Update Facet Instance
REST API
POST /resource-registry/er/facet/{Facet Instance UUID}
Example
POST /resource-registry/er/facet/69f0b376-38d2-4a85-bc63-37f9fa323f82
Request Body
{ "@class":"CPUFacet", "header":{"uuid":"69f0b376-38d2-4a85-bc63-37f9fa323f82"}, /* if you pass the header only the UUID is checked and must be the same of the one provided in the URL*/ "model":"Opteron", "vendor":"AMD", "clockSpeed":"2 GHz" }
Response Body
{ "@class":"CPUFacet", "header": { "uuid":"69f0b376-38d2-4a85-bc63-37f9fa323f82", "creator":"luca.frosini", "lastUpdater":"luca.frosini", "creationTime":"2016-10-05 11:16:24", "lastUpdateTime":"2016-10-05 11:17:32" }, "model":"Opteron", "vendor":"AMD", "clockSpeed":"2 GHz" }
Java API
public <F extends Facet> F updateFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
Example
createdCpuFacet.setClockSpeed("2 GHz"); CPUFacet updatedCpuFacet = resourceRegistryPublisher.updateFacet(createdCpuFacet);
Alternative JAVA API
There are also two other equivalent methods with the following signature:
public String updateFacet(String facet) throws FacetNotFoundException, ResourceRegistryException; public String updateFacet(UUID uuid, String facet) throws FacetNotFoundException, ResourceRegistryException;
The first methods get the Facet to be created as JSON string instead of as Java class. The second get also the uuid as parameter (which as to be specified as PATH PARAMETER in the request) avoiding to force client to retrieve it from the string. The second method is more efficient but you have to be sure that the provided uuid is the same specified in the header of the serialized facet.
Delete Facet Instance
REST API
DELETE /resource-registry/er/facet/{Facet Instance UUID}
Example
DELETE /resource-registry/er/facet/69f0b376-38d2-4a85-bc63-37f9fa323f82
Java API
public <F extends Facet> boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException;
Example
boolean deleted = resourceRegistryPublisher.deleteFacet(createdCpuFacet);
Alternative JAVA API
There is also another equivalent methods with the following signature:
public boolean deleteFacet(UUID uuid) throws FacetNotFoundException, ResourceRegistryException;
The method just need the UUID of the Facet to be deleted.