From b8d3fac55f68daa604807f409d9c429523b1b371 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 21 Apr 2023 15:57:26 +0200 Subject: [PATCH] Reorganized utilities and their usage --- .../ResourceRegistryPublisherImpl.java | 37 ++++++++----------- .../publisher/ERManagementTest.java | 4 +- .../publisher/SmartgearResourcesTest.java | 2 +- .../publisher/old/SmartgearResourcesTest.java | 2 +- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java index 15c6f2a..1ec14cb 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java @@ -43,8 +43,9 @@ import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath; import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation; import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility; import org.gcube.informationsystem.serialization.ElementMapper; +import org.gcube.informationsystem.utils.TypeUtility; import org.gcube.informationsystem.utils.UUIDManager; -import org.gcube.informationsystem.utils.Utility; +import org.gcube.informationsystem.utils.UUIDUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -249,7 +250,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public List list(Class clazz, Boolean polymorphic) throws ResourceRegistryException { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz); + String type = TypeUtility.getTypeName(clazz); String ret = list(type, polymorphic); try { return (List) ElementMapper.unmarshalList(ERElement.class, ret); @@ -315,12 +316,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher protected String internalCreate(ERElem er) throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { try { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility - .getTypeName(er); + String type = TypeUtility.getTypeName(er); String json = ElementMapper.marshal(er); UUID uuid = er.getUUID(); if (uuid == null) { - uuid = UUIDManager.getInstance().generateValidRandomUUID(); + uuid = UUIDManager.getInstance().generateValidUUID(); er.setUUID(uuid); } return create(type, json, uuid); @@ -367,7 +367,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public boolean exist(ERElem er) throws AvailableInAnotherContextException, ResourceRegistryException { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er); + String type = TypeUtility.getTypeName(er); UUID uuid = er.getUUID(); return exist(type, uuid); } @@ -375,7 +375,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public boolean exist(Class clazz, UUID uuid) throws AvailableInAnotherContextException, ResourceRegistryException { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz); + String type = TypeUtility.getTypeName(clazz); return exist(type, uuid); } @@ -416,8 +416,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public ERElem read(ERElem er) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { try { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility - .getTypeName(er); + String type = TypeUtility.getTypeName(er); UUID uuid = er.getUUID(); String ret = read(type, uuid); return (ERElem) ElementMapper.unmarshal(ERElement.class, ret); @@ -433,7 +432,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public ERElem read(Class clazz, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { try { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz); + String type = TypeUtility.getTypeName(clazz); String ret = read(type, uuid); return (ERElem) ElementMapper.unmarshal(ERElement.class, ret); } catch (ResourceRegistryException e) { @@ -477,8 +476,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public ERElem update(ERElem er) throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility - .getTypeName(er); + String type = TypeUtility.getTypeName(er); String json = ElementMapper.marshal(er); UUID uuid = er.getUUID(); String ret = update(type, json, uuid); @@ -496,7 +494,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public String update(String json) throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json); + String type = TypeUtility.getTypeName(json); return update(type, json); } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); @@ -511,7 +509,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public String update(String type, String json) throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { - UUID uuid = Utility.getUUIDFromJSONString(json); + UUID uuid = UUIDUtility.getUUID(json); return update(type, json, uuid); } catch (ResourceRegistryException e) { // logger.trace("Error Creating {}", facet, e); @@ -554,8 +552,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public boolean delete(ERElem er) throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility - .getTypeName(er); + String type = TypeUtility.getTypeName(er); UUID uuid = er.getUUID(); return delete(type, uuid); } catch (ResourceRegistryException e) { @@ -831,8 +828,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public List addToContext(ERElement er, UUID contextUUID, Boolean dryRun) throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { try { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility - .getTypeName(er); + String type = TypeUtility.getTypeName(er); UUID instanceUUID = er.getUUID(); return addToContext(type, instanceUUID, contextUUID, dryRun); } catch (ResourceRegistryException e) { @@ -899,8 +895,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher public List removeFromContext(ERElement er, UUID contextUUID, Boolean dryRun) throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { try { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility - .getTypeName(er); + String type = TypeUtility.getTypeName(er); UUID instanceUUID = er.getUUID(); return removeFromContext(type, instanceUUID, contextUUID, dryRun); } catch (ResourceRegistryException e) { @@ -959,7 +954,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public Map getElementContexts(ERElem er) throws NotFoundException, ResourceRegistryException { - String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er); + String type = TypeUtility.getTypeName(er); UUID instanceUUID = er.getUUID(); return getElementContexts(type, instanceUUID); } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java index 27765f2..9478e86 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ERManagementTest.java @@ -396,7 +396,7 @@ public class ERManagementTest extends ContextTest { @Test public void testReadResource() throws Exception { ResourceManagement resourceManagement = new ResourceManagement(); - resourceManagement.setUUID(UUID.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e")); + resourceManagement.setUUID(UUIDUtility.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e")); String read = resourceManagement.read().toString(); logger.debug(read); } @@ -406,7 +406,7 @@ public class ERManagementTest extends ContextTest { @Test public void testDeleteResource() throws Exception { ResourceManagement resourceManagement = new ResourceManagement(); - resourceManagement.setUUID(UUID.fromString("64635295-7ced-4931-a55f-40fc8199b280")); + resourceManagement.setUUID(UUIDUtility.fromString("64635295-7ced-4931-a55f-40fc8199b280")); boolean deleted = resourceManagement.delete(); Assert.assertTrue(deleted); } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/SmartgearResourcesTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/SmartgearResourcesTest.java index 29065c9..f28e468 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/SmartgearResourcesTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/SmartgearResourcesTest.java @@ -95,7 +95,7 @@ public class SmartgearResourcesTest extends ERManagementTest { @Test public void testHostingNodeOperations() throws ResourceRegistryException, IOException, URISyntaxException { - UUID uuid = UUIDManager.getInstance().generateValidRandomUUID(); + UUID uuid = UUIDManager.getInstance().generateValidUUID(); HostingNode hostingNode = new HostingNodeImpl(); hostingNode.setUUID(uuid); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/SmartgearResourcesTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/SmartgearResourcesTest.java index bddd697..4ff0a10 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/SmartgearResourcesTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/old/SmartgearResourcesTest.java @@ -130,7 +130,7 @@ public class SmartgearResourcesTest extends ContextTest { @Test public void testHostingNodeOperations() throws ResourceRegistryException, IOException{ - UUID uuid = UUIDManager.getInstance().generateValidRandomUUID(); + UUID uuid = UUIDManager.getInstance().generateValidUUID(); HostingNode hostingNode = new HostingNodeImpl(); hostingNode.setUUID(uuid);