From faa064222442c472103c8dc31d8cf32a3e6ca50e Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 21 Apr 2023 15:57:08 +0200 Subject: [PATCH] Reorganized utilities and their usage --- .../client/ResourceRegistryClientImpl.java | 50 +++++++++---------- .../client/ResourceRegistryClientTest.java | 19 +++---- ...esourceRegistryClientTestWikiExamples.java | 23 +++++---- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java index e801117..aa08245 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientImpl.java @@ -40,10 +40,10 @@ import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath; import org.gcube.informationsystem.resourceregistry.api.rest.QueryTemplatePath; import org.gcube.informationsystem.resourceregistry.api.rest.TypePath; import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility; -import org.gcube.informationsystem.resourceregistry.api.utils.Utility; import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.reference.Type; +import org.gcube.informationsystem.utils.TypeUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -274,7 +274,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { @Override public boolean existType(Class clazz) throws ResourceRegistryException { - return existType(Utility.getTypeName(clazz)); + return existType(TypeUtility.getTypeName(clazz)); } @Override @@ -313,7 +313,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { public List getType(Class clazz, Boolean polymorphic) throws SchemaNotFoundException, ResourceRegistryException { try { - String json = getType(Utility.getTypeName(clazz), polymorphic); + String json = getType(TypeUtility.getTypeName(clazz), polymorphic); return TypeMapper.deserializeTypeDefinitions(json); } catch(ResourceRegistryException e) { throw e; @@ -358,7 +358,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { @Override public List getInstances(Class clazz, Boolean polymorphic) throws ResourceRegistryException { - String type = Utility.getTypeName(clazz); + String type = TypeUtility.getTypeName(clazz); String ret = getInstances(type, polymorphic); try { return (List) ElementMapper.unmarshalList(ERElement.class, ret); @@ -399,7 +399,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { @Override public boolean existInstance(Class clazz, UUID uuid) throws AvailableInAnotherContextException, ResourceRegistryException { - String type = Utility.getTypeName(clazz); + String type = TypeUtility.getTypeName(clazz); return existInstance(type, uuid); } @@ -438,7 +438,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { @Override public ERElem getInstance(Class clazz, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { - String type = Utility.getTypeName(clazz); + String type = TypeUtility.getTypeName(clazz); String ret = getInstance(type, uuid); try { return ElementMapper.unmarshal(clazz, ret); @@ -583,9 +583,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { public , F extends Facet> List getResourcesFromReferenceFacet( Class resourceClass, Class consistsOfClass, Class facetClass, UUID referenceFacetUUID, boolean polymorphic) throws ResourceRegistryException { - String resourceType = Utility.getTypeName(resourceClass); - String consistsOfType = Utility.getTypeName(consistsOfClass); - String facetType = Utility.getTypeName(facetClass); + String resourceType = TypeUtility.getTypeName(resourceClass); + String consistsOfType = TypeUtility.getTypeName(consistsOfClass); + String facetType = TypeUtility.getTypeName(facetClass); String ret = getResourcesFromReferenceFacet(resourceType, consistsOfType, facetType, referenceFacetUUID, polymorphic); try { @@ -606,9 +606,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { public , F extends Facet> List getFilteredResources( Class resourceClass, Class consistsOfClass, Class facetClass, boolean polymorphic, Map facetConstraints) throws ResourceRegistryException { - String resourceType = Utility.getTypeName(resourceClass); - String consistsOfType = Utility.getTypeName(consistsOfClass); - String facetType = Utility.getTypeName(facetClass); + String resourceType = TypeUtility.getTypeName(resourceClass); + String consistsOfType = TypeUtility.getTypeName(consistsOfClass); + String facetType = TypeUtility.getTypeName(facetClass); String ret = getFilteredResources(resourceType, consistsOfType, facetType, polymorphic, facetConstraints); try { return (List) ElementMapper.unmarshalList(Resource.class, ret); @@ -639,9 +639,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { public , RR extends Resource> List getRelatedResourcesFromReferenceResource( Class resourceClass, Class isRelatedToClass, Class referenceResourceClass, UUID referenceResourceUUID, Direction direction, boolean polymorphic) throws ResourceRegistryException { - String resourceType = Utility.getTypeName(resourceClass); - String isRelatedToType = Utility.getTypeName(isRelatedToClass); - String referenceResourceType = Utility.getTypeName(referenceResourceClass); + String resourceType = TypeUtility.getTypeName(resourceClass); + String isRelatedToType = TypeUtility.getTypeName(isRelatedToClass); + String referenceResourceType = TypeUtility.getTypeName(referenceResourceClass); String ret = getRelatedResourcesFromReferenceResource(resourceType, isRelatedToType, referenceResourceType, referenceResourceUUID, direction, polymorphic); try { @@ -664,9 +664,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { public , RR extends Resource> List getRelatedResources( Class resourceClass, Class isRelatedToClass, Class referenceResourceClass, Direction direction, boolean polymorphic) throws ResourceRegistryException { - String resourceType = Utility.getTypeName(resourceClass); - String isRelatedToType = Utility.getTypeName(isRelatedToClass); - String referenceResourceType = Utility.getTypeName(referenceResourceClass); + String resourceType = TypeUtility.getTypeName(resourceClass); + String isRelatedToType = TypeUtility.getTypeName(isRelatedToClass); + String referenceResourceType = TypeUtility.getTypeName(referenceResourceClass); String ret = getRelatedResources(resourceType, isRelatedToType, referenceResourceType, direction, polymorphic); try { return (List) ElementMapper.unmarshalList(Resource.class, ret); @@ -686,9 +686,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { protected , RE extends Entity> List getRelated(Class entityClass, Class relationClass, Class referenceEntityClass, Direction direction, boolean polymorphic, Map map) throws ResourceRegistryException { - String entityType = Utility.getTypeName(entityClass); - String relationType = Utility.getTypeName(relationClass); - String referenceEntityType = Utility.getTypeName(referenceEntityClass); + String entityType = TypeUtility.getTypeName(entityClass); + String relationType = TypeUtility.getTypeName(relationClass); + String referenceEntityType = TypeUtility.getTypeName(referenceEntityClass); String ret = getRelated(entityType, relationType, referenceEntityType, direction, polymorphic, map); try { return (List) ElementMapper.unmarshalList(Resource.class, ret); @@ -717,9 +717,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { protected , RE extends Entity> List getRelated(Class entityClass, Class relationClass, Class referenceEntityClass, UUID referenceEntityUUID, Direction direction, boolean polymorphic) throws ResourceRegistryException { - String entityType = Utility.getTypeName(entityClass); - String relationType = Utility.getTypeName(relationClass); - String referenceEntityType = Utility.getTypeName(referenceEntityClass); + String entityType = TypeUtility.getTypeName(entityClass); + String relationType = TypeUtility.getTypeName(relationClass); + String referenceEntityType = TypeUtility.getTypeName(referenceEntityClass); String ret = getRelated(entityType, relationType, referenceEntityType, referenceEntityUUID, direction, polymorphic); try { @@ -738,7 +738,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { @Override public Map getInstanceContexts(Class clazz, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { - String typeName = Utility.getTypeName(clazz); + String typeName = TypeUtility.getTypeName(clazz); return getInstanceContexts(typeName, uuid); } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java index 5327cd2..61e3501 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java @@ -22,6 +22,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaN import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.types.reference.Type; import org.gcube.informationsystem.utils.UUIDManager; +import org.gcube.informationsystem.utils.UUIDUtility; 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; @@ -90,21 +91,21 @@ public class ResourceRegistryClientTest extends ContextTest { } // @Test - public void testExistsByClass() throws ResourceRegistryException { - UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233"); + public void testExistsByClass() throws Exception { + UUID uuid = UUIDUtility.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233"); resourceRegistryClient.existInstance(EService.class, uuid); } // @Test - public void testGetInstance() throws ResourceRegistryException { - UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233"); + public void testGetInstance() throws Exception { + UUID uuid = UUIDUtility.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233"); String eService = resourceRegistryClient.getInstance(EService.NAME, uuid); logger.trace("{}", eService); } // @Test - public void testGetInstanceByClass() throws ResourceRegistryException { - UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233"); + public void testGetInstanceByClass() throws Exception { + UUID uuid = UUIDUtility.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233"); EService eService = resourceRegistryClient.getInstance(EService.class, uuid); logger.trace("{}", eService); } @@ -129,8 +130,8 @@ public class ResourceRegistryClientTest extends ContextTest { } // @Test - public void testGetRelatedResourcesFromReferenceResourceByClasses() throws ResourceRegistryException { - UUID uuid = UUID.fromString("b0d15e45-62af-4221-b785-7d014f10e631"); + public void testGetRelatedResourcesFromReferenceResourceByClasses() throws Exception { + UUID uuid = UUIDUtility.fromString("b0d15e45-62af-4221-b785-7d014f10e631"); HostingNode hostingNode = new HostingNodeImpl(); hostingNode.setUUID(uuid); Metadata metadata = new MetadataImpl(); @@ -156,7 +157,7 @@ public class ResourceRegistryClientTest extends ContextTest { // @Test public void testGetResourcesFromReferenceFacet() throws ResourceRegistryException, JsonProcessingException { SoftwareFacet softwareFacet = new SoftwareFacetImpl(); - softwareFacet.setUUID(UUIDManager.getInstance().generateValidRandomUUID()); + softwareFacet.setUUID(UUIDManager.getInstance().generateValidUUID()); Metadata metadata = new MetadataImpl(); softwareFacet.setMetadata(metadata); List eServices = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, softwareFacet, true); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTestWikiExamples.java b/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTestWikiExamples.java index b461ab6..fdfc57e 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTestWikiExamples.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTestWikiExamples.java @@ -13,6 +13,7 @@ import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.serialization.ElementMapper; +import org.gcube.informationsystem.utils.UUIDUtility; 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; @@ -62,8 +63,8 @@ public class ResourceRegistryClientTestWikiExamples extends ContextTest { } @Test - public void testExample2() throws ResourceRegistryException { - UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb"); + public void testExample2() throws Exception { + UUID uuid = UUIDUtility.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb"); List list = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, uuid, true); logger.debug("{}", list); } @@ -71,7 +72,7 @@ public class ResourceRegistryClientTestWikiExamples extends ContextTest { @Test public void testExample2Alt() throws ResourceRegistryException, Exception{ SoftwareFacet softwareFacetInstance = new SoftwareFacetImpl(); - UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb"); + UUID uuid = UUIDUtility.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb"); softwareFacetInstance.setUUID(uuid); List list = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, softwareFacetInstance, true); logger.debug("{}", list); @@ -79,7 +80,7 @@ public class ResourceRegistryClientTestWikiExamples extends ContextTest { @Test public void testExample2Alt2() throws ResourceRegistryException, Exception{ - UUID uuid = UUID.fromString("97984812-90e6-4eb7-b804-50a9ad3fe4fb"); + UUID uuid = UUIDUtility.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); @@ -161,31 +162,31 @@ public class ResourceRegistryClientTestWikiExamples extends ContextTest { } @Test - public void testExample7Alt() throws ResourceRegistryException, Exception { + public void testExample7Alt() throws 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"); + public void testExample8() throws Exception { + UUID uuid = UUIDUtility.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{ + public void testExample8Alt() throws Exception{ HostingNode hostingNodeInstance = new HostingNodeImpl(); - UUID uuid = UUID.fromString("16032d09-3823-444e-a1ff-a67de4f350a"); + UUID uuid = UUIDUtility.fromString("16032d09-3823-444e-a1ff-a67de4f350a"); hostingNodeInstance.setUUID(uuid); 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"); + public void testExample8Alt2() throws Exception{ + UUID uuid = UUIDUtility.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);