2021-07-07 17:35:49 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.informationsystem.resourceregistry.client;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2021-10-15 17:29:30 +02:00
|
|
|
import org.gcube.informationsystem.base.reference.Direction;
|
2021-07-07 17:35:49 +02:00
|
|
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
|
|
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2023-02-09 17:07:58 +01:00
|
|
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
2023-04-21 15:57:08 +02:00
|
|
|
import org.gcube.informationsystem.utils.UUIDUtility;
|
2021-07-07 17:35:49 +02:00
|
|
|
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() {
|
2022-07-25 11:07:32 +02:00
|
|
|
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
|
|
|
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
|
|
|
}else {
|
|
|
|
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
|
|
}
|
2021-07-07 17:35:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void before() throws Exception {
|
|
|
|
setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExample1() throws ResourceRegistryException {
|
|
|
|
List<EService> 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<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2023-04-21 15:57:08 +02:00
|
|
|
public void testExample2() throws Exception {
|
|
|
|
UUID uuid = UUIDUtility.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
|
2021-07-07 17:35:49 +02:00
|
|
|
List<EService> 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();
|
2023-04-21 15:57:08 +02:00
|
|
|
UUID uuid = UUIDUtility.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
|
2023-04-18 17:51:47 +02:00
|
|
|
softwareFacetInstance.setUUID(uuid);
|
2021-07-07 17:35:49 +02:00
|
|
|
List<EService> list = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, softwareFacetInstance, true);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExample2Alt2() throws ResourceRegistryException, Exception{
|
2023-04-21 15:57:08 +02:00
|
|
|
UUID uuid = UUIDUtility.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
|
2021-07-07 17:35:49 +02:00
|
|
|
String jsonString = resourceRegistryClient.getResourcesFromReferenceFacet("EService", "IsIdentifiedBy", "SoftwareFacet", uuid, true);
|
|
|
|
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExample3() throws ResourceRegistryException, Exception{
|
|
|
|
Map<String, String> facetConstraints = new HashMap<>();
|
|
|
|
facetConstraints.put("group", "VREManagement");
|
|
|
|
facetConstraints.put("name", "WhnManager");
|
|
|
|
|
|
|
|
List<EService> list = resourceRegistryClient.getFilteredResources(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, true, facetConstraints);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExample3Alt() throws ResourceRegistryException, Exception{
|
|
|
|
Map<String, String> facetConstraints = new HashMap<>();
|
|
|
|
facetConstraints.put("group", "VREManagement");
|
|
|
|
facetConstraints.put("name", "WhnManager");
|
|
|
|
|
|
|
|
String jsonString = resourceRegistryClient.getFilteredResources("EService", "IsIdentifiedBy", "SoftwareFacet", true, facetConstraints);
|
|
|
|
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExample4() throws ResourceRegistryException {
|
|
|
|
List<Resource> 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<Resource> list = ElementMapper.unmarshalList(Resource.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExample5() throws ResourceRegistryException {
|
|
|
|
List<Resource> 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<Resource> list = ElementMapper.unmarshalList(Resource.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExample6() throws ResourceRegistryException, Exception{
|
|
|
|
Map<String, String> facetConstraints = new HashMap<>();
|
|
|
|
facetConstraints.put("name", "Luca");
|
|
|
|
facetConstraints.put("surname", "Frosini");
|
|
|
|
|
|
|
|
List<Resource> list = resourceRegistryClient.getFilteredResources(Resource.class, ConsistsOf.class, ContactFacet.class, true, facetConstraints);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExample6Alt() throws ResourceRegistryException, Exception{
|
|
|
|
Map<String, String> facetConstraints = new HashMap<>();
|
|
|
|
facetConstraints.put("name", "Luca");
|
|
|
|
facetConstraints.put("surname", "Frosini");
|
|
|
|
|
|
|
|
String jsonString = resourceRegistryClient.getFilteredResources("Resource", "ConsistsOf", "ContactFacet", true, facetConstraints);
|
|
|
|
List<Resource> list = ElementMapper.unmarshalList(Resource.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExample7() throws ResourceRegistryException {
|
|
|
|
List<EService> list = resourceRegistryClient.getRelatedResources(EService.class, Hosts.class, HostingNode.class, Direction.IN, true);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2023-04-21 15:57:08 +02:00
|
|
|
public void testExample7Alt() throws Exception {
|
2021-07-07 17:35:49 +02:00
|
|
|
String jsonString = resourceRegistryClient.getRelatedResources("EService", "Hosts", "HostingNode", Direction.IN, true);
|
|
|
|
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2023-04-21 15:57:08 +02:00
|
|
|
public void testExample8() throws Exception {
|
|
|
|
UUID uuid = UUIDUtility.fromString("16032d09-3823-444e-a1ff-a67de4f350a");
|
2021-07-07 17:35:49 +02:00
|
|
|
List<EService> list = resourceRegistryClient.getRelatedResourcesFromReferenceResource(EService.class, Hosts.class, HostingNode.class, uuid, Direction.IN, true);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2023-04-21 15:57:08 +02:00
|
|
|
public void testExample8Alt() throws Exception{
|
2021-07-07 17:35:49 +02:00
|
|
|
HostingNode hostingNodeInstance = new HostingNodeImpl();
|
2023-04-21 15:57:08 +02:00
|
|
|
UUID uuid = UUIDUtility.fromString("16032d09-3823-444e-a1ff-a67de4f350a");
|
2023-04-18 17:51:47 +02:00
|
|
|
hostingNodeInstance.setUUID(uuid);
|
2021-07-07 17:35:49 +02:00
|
|
|
List<EService> list = resourceRegistryClient.getRelatedResourcesFromReferenceResource(EService.class, Hosts.class, hostingNodeInstance, Direction.IN, true);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2023-04-21 15:57:08 +02:00
|
|
|
public void testExample8Alt2() throws Exception{
|
|
|
|
UUID uuid = UUIDUtility.fromString("16032d09-3823-444e-a1ff-a67de4f350a");
|
2021-07-07 17:35:49 +02:00
|
|
|
String jsonString = resourceRegistryClient.getRelatedResourcesFromReferenceResource("EService", "Hosts", "HostingNode", uuid, Direction.IN, true);
|
|
|
|
List<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
2021-07-07 19:39:33 +02:00
|
|
|
@Test
|
|
|
|
public void rawQueryExample1() throws ResourceRegistryException, Exception{
|
2022-07-19 14:04:26 +02:00
|
|
|
String jsonString = resourceRegistryClient.rawQuery("SELECT FROM SoftwareFacet", true);
|
2021-07-07 19:39:33 +02:00
|
|
|
logger.debug("{}", jsonString);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void rawQueryExample2() throws ResourceRegistryException, Exception{
|
2022-07-19 14:04:26 +02:00
|
|
|
String jsonString = resourceRegistryClient.rawQuery("SELECT FROM SoftwareFacet");
|
2021-07-07 19:39:33 +02:00
|
|
|
List<SoftwareFacet> list = ElementMapper.unmarshalList(SoftwareFacet.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
|
|
|
|
2022-02-09 15:15:00 +01:00
|
|
|
@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<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
|
|
|
|
logger.debug("{}", list);
|
|
|
|
}
|
2021-07-07 17:35:49 +02:00
|
|
|
}
|