/** * */ package org.gcube.informationsystem.resourceregistry.client; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.model.impl.properties.HeaderImpl; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.properties.Header; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.utils.ElementMapper; import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl; import org.gcube.resourcemanagement.model.reference.entities.facets.ContactFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.EService; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Hosts; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ public class ResourceRegistryClientTestWikiExamples extends ContextTest { private static Logger logger = LoggerFactory.getLogger(ResourceRegistryClientTestWikiExamples.class); protected ResourceRegistryClient resourceRegistryClient; public ResourceRegistryClientTestWikiExamples() { if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) { resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL); }else { resourceRegistryClient = ResourceRegistryClientFactory.create(); } } @Before public void before() throws Exception { setContextByName(PARENT_DEFAULT_TEST_SCOPE); } @Test public void testExample1() throws ResourceRegistryException { List list = resourceRegistryClient.getFilteredResources(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, true, null); logger.debug("{}", list); } @Test public void testExample1Alt() throws ResourceRegistryException, Exception { String jsonString = resourceRegistryClient.getFilteredResources("EService", "IsIdentifiedBy", "SoftwareFacet", true, null); List list = ElementMapper.unmarshalList(EService.class, jsonString); logger.debug("{}", list); } @Test public void testExample2() throws ResourceRegistryException { UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb"); List list = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, uuid, true); logger.debug("{}", list); } @Test public void testExample2Alt() throws ResourceRegistryException, Exception{ SoftwareFacet softwareFacetInstance = new SoftwareFacetImpl(); UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb"); Header header = new HeaderImpl(uuid); softwareFacetInstance.setHeader(header); List list = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, softwareFacetInstance, true); logger.debug("{}", list); } @Test public void testExample2Alt2() throws ResourceRegistryException, Exception{ UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb"); String jsonString = resourceRegistryClient.getResourcesFromReferenceFacet("EService", "IsIdentifiedBy", "SoftwareFacet", uuid, true); List list = ElementMapper.unmarshalList(EService.class, jsonString); logger.debug("{}", list); } @Test public void testExample3() throws ResourceRegistryException, Exception{ Map facetConstraints = new HashMap<>(); facetConstraints.put("group", "VREManagement"); facetConstraints.put("name", "WhnManager"); List list = resourceRegistryClient.getFilteredResources(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, true, facetConstraints); logger.debug("{}", list); } @Test public void testExample3Alt() throws ResourceRegistryException, Exception{ Map facetConstraints = new HashMap<>(); facetConstraints.put("group", "VREManagement"); facetConstraints.put("name", "WhnManager"); String jsonString = resourceRegistryClient.getFilteredResources("EService", "IsIdentifiedBy", "SoftwareFacet", true, facetConstraints); List list = ElementMapper.unmarshalList(EService.class, jsonString); logger.debug("{}", list); } @Test public void testExample4() throws ResourceRegistryException { List list = resourceRegistryClient.getFilteredResources(Resource.class, IsIdentifiedBy.class, ContactFacet.class, true, null); logger.debug("{}", list); } @Test public void testExample4Alt() throws ResourceRegistryException, Exception { String jsonString = resourceRegistryClient.getFilteredResources("Resource", "IsIdentifiedBy", "ContactFacet", true, null); List list = ElementMapper.unmarshalList(Resource.class, jsonString); logger.debug("{}", list); } @Test public void testExample5() throws ResourceRegistryException { List list = resourceRegistryClient.getFilteredResources(Resource.class, ConsistsOf.class, ContactFacet.class, true, null); logger.debug("{}", list); } @Test public void testExample5Alt() throws ResourceRegistryException, Exception { String jsonString = resourceRegistryClient.getFilteredResources("Resource", "ConsistsOf", "ContactFacet", true, null); List list = ElementMapper.unmarshalList(Resource.class, jsonString); logger.debug("{}", list); } @Test public void testExample6() throws ResourceRegistryException, Exception{ Map facetConstraints = new HashMap<>(); facetConstraints.put("name", "Luca"); facetConstraints.put("surname", "Frosini"); List list = resourceRegistryClient.getFilteredResources(Resource.class, ConsistsOf.class, ContactFacet.class, true, facetConstraints); logger.debug("{}", list); } @Test public void testExample6Alt() throws ResourceRegistryException, Exception{ Map facetConstraints = new HashMap<>(); facetConstraints.put("name", "Luca"); facetConstraints.put("surname", "Frosini"); String jsonString = resourceRegistryClient.getFilteredResources("Resource", "ConsistsOf", "ContactFacet", true, facetConstraints); List list = ElementMapper.unmarshalList(Resource.class, jsonString); logger.debug("{}", list); } @Test public void testExample7() throws ResourceRegistryException { List list = resourceRegistryClient.getRelatedResources(EService.class, Hosts.class, HostingNode.class, Direction.IN, true); logger.debug("{}", list); } @Test public void testExample7Alt() throws ResourceRegistryException, Exception { String jsonString = resourceRegistryClient.getRelatedResources("EService", "Hosts", "HostingNode", Direction.IN, true); List list = ElementMapper.unmarshalList(EService.class, jsonString); logger.debug("{}", list); } @Test public void testExample8() throws ResourceRegistryException { UUID uuid = UUID.fromString("16032d09-3823-444e-a1ff-a67de4f350a"); List list = resourceRegistryClient.getRelatedResourcesFromReferenceResource(EService.class, Hosts.class, HostingNode.class, uuid, Direction.IN, true); logger.debug("{}", list); } @Test public void testExample8Alt() throws ResourceRegistryException, Exception{ HostingNode hostingNodeInstance = new HostingNodeImpl(); UUID uuid = UUID.fromString("16032d09-3823-444e-a1ff-a67de4f350a"); Header header = new HeaderImpl(uuid); hostingNodeInstance.setHeader(header); List list = resourceRegistryClient.getRelatedResourcesFromReferenceResource(EService.class, Hosts.class, hostingNodeInstance, Direction.IN, true); logger.debug("{}", list); } @Test public void testExample8Alt2() throws ResourceRegistryException, Exception{ UUID uuid = UUID.fromString("16032d09-3823-444e-a1ff-a67de4f350a"); String jsonString = resourceRegistryClient.getRelatedResourcesFromReferenceResource("EService", "Hosts", "HostingNode", uuid, Direction.IN, true); List list = ElementMapper.unmarshalList(EService.class, jsonString); logger.debug("{}", list); } @Test public void rawQueryExample1() throws ResourceRegistryException, Exception{ String jsonString = resourceRegistryClient.rawQuery("SELECT FROM SoftwareFacet", true); logger.debug("{}", jsonString); } @Test public void rawQueryExample2() throws ResourceRegistryException, Exception{ String jsonString = resourceRegistryClient.rawQuery("SELECT FROM SoftwareFacet"); List list = ElementMapper.unmarshalList(SoftwareFacet.class, jsonString); logger.debug("{}", list); } @Test public void jsonQueryExample1() throws ResourceRegistryException, Exception{ String jsonQuery = "{\n" + " \"@class\": \"EService\",\n" + " \"consistsOf\": [\n" + " {\n" + " \"@class\": \"IsIdentifiedBy\",\n" + " \"target\": {\n" + " \"@class\": \"SoftwareFacet\",\n" + " \"group\": \"DataTransfer\",\n" + " \"name\": \"data-transfer-service\"\n" + " }\n" + " }\n" + " {\n" + " \"@class\": \"ConsistsOf\",\n" + " \"target\": {\n" + " \"@class\": \"StateFacet\",\n" + " \"value\": \"down\"\n" + " }\n" + " },\n" + " \n" + " ]\n" + "}"; String jsonString = resourceRegistryClient.jsonQuery(jsonQuery); List list = ElementMapper.unmarshalList(EService.class, jsonString); logger.debug("{}", list); } }