Reorganized utilities and their usage

This commit is contained in:
Luca Frosini 2023-04-21 15:57:26 +02:00
parent 02abe7e89f
commit b8d3fac55f
4 changed files with 20 additions and 25 deletions

View File

@ -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 <ERElem extends ERElement> List<ERElem> list(Class<ERElem> 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<ERElem>) ElementMapper.unmarshalList(ERElement.class, ret);
@ -315,12 +316,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
protected <ERElem extends ERElement> 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 <ERElem extends ERElement> 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 <ERElem extends ERElement> boolean exist(Class<ERElem> 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 extends ERElement> 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 extends ERElement> ERElem read(Class<ERElem> 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 extends ERElement> 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 <ERElem extends ERElement> 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<ERElement> 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<ERElement> 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 <ERElem extends ERElement> Map<UUID, String> 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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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);