Improving client

This commit is contained in:
Luca Frosini 2021-07-07 17:35:49 +02:00
parent 4cb760f4c3
commit 9909a87644
4 changed files with 216 additions and 20 deletions

View File

@ -43,7 +43,7 @@ public interface ResourceRegistryClient {
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException;
public <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getResourcesFromReferenceFacet(
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> facetClass, F referenceFacet,
Class<R> resourceClass, Class<C> consistsOfClass, F referenceFacet,
boolean polymorphic) throws ResourceRegistryException;
public <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getResourcesFromReferenceFacet(
@ -56,14 +56,14 @@ public interface ResourceRegistryClient {
public <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getFilteredResources(
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> facetClass, boolean polymorphic,
Map<String,String> map) throws ResourceRegistryException;
Map<String,String> facetConstraint) throws ResourceRegistryException;
public String getFilteredResources(String resourceType, String consistsOfType, String facetType,
boolean polymorphic, Map<String,String> map) throws ResourceRegistryException;
boolean polymorphic, Map<String,String> facetConstraint) throws ResourceRegistryException;
public <R extends Resource, I extends IsRelatedTo<?,?>, RR extends Resource> List<R> getRelatedResourcesFromReferenceResource(
Class<R> resourceClass, Class<I> isRelatedToClass, Class<RR> referenceResourceClass, RR referenceResource,
Class<R> resourceClass, Class<I> isRelatedToClass, RR referenceResource,
Direction direction, boolean polymorphic) throws ResourceRegistryException;
public <R extends Resource, I extends IsRelatedTo<?,?>, RR extends Resource> List<R> getRelatedResourcesFromReferenceResource(

View File

@ -385,7 +385,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
}
protected String getRelated(String entityType, String relationType, String referenceEntityType,
UUID referenceEntity, Direction direction, Boolean polymorphic, Map<String,String> map)
UUID referenceEntity, Direction direction, Boolean polymorphic, Map<String,String> facetConstraints)
throws ResourceRegistryException {
try {
@ -403,10 +403,10 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
parameters.put(AccessPath._POLYMORPHIC_PARAM, polymorphic.toString());
if(referenceEntity == null) {
if(map != null && map.size() > 0) {
if(facetConstraints != null && facetConstraints.size() > 0) {
logger.info("Going to get {} linked by a {} Relation to a {} having {}", entityType, relationType,
referenceEntityType, map);
parameters.putAll(map);
referenceEntityType, facetConstraints);
parameters.putAll(facetConstraints);
} else {
logger.info("Going to get {} linked by a {} Relation to a {}", entityType, relationType,
referenceEntityType);
@ -425,7 +425,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
if(referenceEntity == null) {
logger.info("{} linked by {} to/from {} having {} are {}", entityType, relationType,
referenceEntityType, map, json);
referenceEntityType, facetConstraints, json);
} else {
logger.info("{} linked by {} to/from {} with UUID {} are", entityType, relationType,
@ -443,9 +443,11 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getResourcesFromReferenceFacet(
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> facetClass, F referenceFacet,
Class<R> resourceClass, Class<C> consistsOfClass, F referenceFacet,
boolean polymorphic) throws ResourceRegistryException {
UUID referenceFacetUUID = referenceFacet.getHeader().getUUID();
@SuppressWarnings("unchecked")
Class<F> facetClass = (Class<F>) referenceFacet.getClass();
return getResourcesFromReferenceFacet(resourceClass, consistsOfClass, facetClass, referenceFacetUUID,
polymorphic);
}
@ -476,11 +478,11 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getFilteredResources(
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> facetClass, boolean polymorphic,
Map<String,String> map) throws ResourceRegistryException {
Map<String,String> facetConstraints) throws ResourceRegistryException {
String resourceType = Utility.getTypeName(resourceClass);
String consistsOfType = Utility.getTypeName(consistsOfClass);
String facetType = Utility.getTypeName(facetClass);
String ret = getFilteredResources(resourceType, consistsOfType, facetType, polymorphic, map);
String ret = getFilteredResources(resourceType, consistsOfType, facetType, polymorphic, facetConstraints);
try {
return (List<R>) ElementMapper.unmarshalList(Resource.class, ret);
} catch(Exception e) {
@ -490,15 +492,17 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public String getFilteredResources(String resourceType, String consistsOfType, String facetType,
boolean polymorphic, Map<String,String> map) throws ResourceRegistryException {
return getRelated(resourceType, consistsOfType, facetType, Direction.OUT, polymorphic, map);
boolean polymorphic, Map<String,String> facetConstraints) throws ResourceRegistryException {
return getRelated(resourceType, consistsOfType, facetType, Direction.OUT, polymorphic, facetConstraints);
}
@Override
public <R extends Resource, I extends IsRelatedTo<?,?>, RR extends Resource> List<R> getRelatedResourcesFromReferenceResource(
Class<R> resourceClass, Class<I> isRelatedToClass, Class<RR> referenceResourceClass, RR referenceResource,
Class<R> resourceClass, Class<I> isRelatedToClass, RR referenceResource,
Direction direction, boolean polymorphic) throws ResourceRegistryException {
UUID referenceResourceUUID = referenceResource.getHeader().getUUID();
@SuppressWarnings("unchecked")
Class<RR> referenceResourceClass = (Class<RR>) referenceResource.getClass();
return getRelatedResourcesFromReferenceResource(resourceClass, isRelatedToClass, referenceResourceClass,
referenceResourceUUID, direction, polymorphic);
}
@ -568,8 +572,8 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
// @Override
protected String getRelated(String entityType, String relationType, String referenceEntityType, Direction direction,
boolean polymorphic, Map<String,String> map) throws ResourceRegistryException {
return getRelated(entityType, relationType, referenceEntityType, null, direction, polymorphic, map);
boolean polymorphic, Map<String,String> facetConstraints) throws ResourceRegistryException {
return getRelated(entityType, relationType, referenceEntityType, null, direction, polymorphic, facetConstraints);
}
// @Override

View File

@ -129,7 +129,7 @@ public class ResourceRegistryClientTest extends ContextTest {
Header header = new HeaderImpl(uuid);
hostingNode.setHeader(header);
List<EService> eServices = resourceRegistryClient.getRelatedResourcesFromReferenceResource(EService.class,
IsRelatedTo.class, HostingNode.class, hostingNode, Direction.OUT, true);
IsRelatedTo.class, hostingNode, Direction.OUT, true);
logger.trace("{}", eServices);
}
@ -152,8 +152,7 @@ public class ResourceRegistryClientTest extends ContextTest {
UUID uuid = UUID.fromString("cbdf3e61-524c-4800-91a6-3ff3e06fbee3");
Header header = new HeaderImpl(uuid);
softwareFacet.setHeader(header);
List<EService> eServices = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class,
SoftwareFacet.class, softwareFacet, true);
List<EService> eServices = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, softwareFacet, true);
for(EService eService : eServices) {
logger.trace("{}", ElementMapper.marshal(eService));
}

View File

@ -0,0 +1,193 @@
/**
*
*/
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.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() {
resourceRegistryClient = ResourceRegistryClientFactory.create();
}
@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
public void testExample2() throws ResourceRegistryException {
UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
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();
UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb");
Header header = new HeaderImpl(uuid);
softwareFacetInstance.setHeader(header);
List<EService> 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<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
public void testExample7Alt() throws ResourceRegistryException, Exception {
String jsonString = resourceRegistryClient.getRelatedResources("EService", "Hosts", "HostingNode", Direction.IN, true);
List<EService> 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<EService> 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<EService> 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<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
logger.debug("{}", list);
}
}