Reorganized utilities and their usage
This commit is contained in:
parent
02abe7e89f
commit
b8d3fac55f
|
@ -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.SharingPath.SharingOperation;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
|
||||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||||
|
import org.gcube.informationsystem.utils.TypeUtility;
|
||||||
import org.gcube.informationsystem.utils.UUIDManager;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -249,7 +250,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
@Override
|
@Override
|
||||||
public <ERElem extends ERElement> List<ERElem> list(Class<ERElem> clazz, Boolean polymorphic)
|
public <ERElem extends ERElement> List<ERElem> list(Class<ERElem> clazz, Boolean polymorphic)
|
||||||
throws ResourceRegistryException {
|
throws ResourceRegistryException {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz);
|
String type = TypeUtility.getTypeName(clazz);
|
||||||
String ret = list(type, polymorphic);
|
String ret = list(type, polymorphic);
|
||||||
try {
|
try {
|
||||||
return (List<ERElem>) ElementMapper.unmarshalList(ERElement.class, ret);
|
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)
|
protected <ERElem extends ERElement> String internalCreate(ERElem er)
|
||||||
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
|
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
String type = TypeUtility.getTypeName(er);
|
||||||
.getTypeName(er);
|
|
||||||
String json = ElementMapper.marshal(er);
|
String json = ElementMapper.marshal(er);
|
||||||
UUID uuid = er.getUUID();
|
UUID uuid = er.getUUID();
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
uuid = UUIDManager.getInstance().generateValidRandomUUID();
|
uuid = UUIDManager.getInstance().generateValidUUID();
|
||||||
er.setUUID(uuid);
|
er.setUUID(uuid);
|
||||||
}
|
}
|
||||||
return create(type, json, uuid);
|
return create(type, json, uuid);
|
||||||
|
@ -367,7 +367,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
@Override
|
@Override
|
||||||
public <ERElem extends ERElement> boolean exist(ERElem er)
|
public <ERElem extends ERElement> boolean exist(ERElem er)
|
||||||
throws AvailableInAnotherContextException, ResourceRegistryException {
|
throws AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er);
|
String type = TypeUtility.getTypeName(er);
|
||||||
UUID uuid = er.getUUID();
|
UUID uuid = er.getUUID();
|
||||||
return exist(type, uuid);
|
return exist(type, uuid);
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
@Override
|
@Override
|
||||||
public <ERElem extends ERElement> boolean exist(Class<ERElem> clazz, UUID uuid)
|
public <ERElem extends ERElement> boolean exist(Class<ERElem> clazz, UUID uuid)
|
||||||
throws AvailableInAnotherContextException, ResourceRegistryException {
|
throws AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz);
|
String type = TypeUtility.getTypeName(clazz);
|
||||||
return exist(type, uuid);
|
return exist(type, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,8 +416,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
public <ERElem extends ERElement> ERElem read(ERElem er)
|
public <ERElem extends ERElement> ERElem read(ERElem er)
|
||||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
String type = TypeUtility.getTypeName(er);
|
||||||
.getTypeName(er);
|
|
||||||
UUID uuid = er.getUUID();
|
UUID uuid = er.getUUID();
|
||||||
String ret = read(type, uuid);
|
String ret = read(type, uuid);
|
||||||
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
|
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)
|
public <ERElem extends ERElement> ERElem read(Class<ERElem> clazz, UUID uuid)
|
||||||
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz);
|
String type = TypeUtility.getTypeName(clazz);
|
||||||
String ret = read(type, uuid);
|
String ret = read(type, uuid);
|
||||||
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
|
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
|
@ -477,8 +476,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
public <ERElem extends ERElement> ERElem update(ERElem er)
|
public <ERElem extends ERElement> ERElem update(ERElem er)
|
||||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
String type = TypeUtility.getTypeName(er);
|
||||||
.getTypeName(er);
|
|
||||||
String json = ElementMapper.marshal(er);
|
String json = ElementMapper.marshal(er);
|
||||||
UUID uuid = er.getUUID();
|
UUID uuid = er.getUUID();
|
||||||
String ret = update(type, json, uuid);
|
String ret = update(type, json, uuid);
|
||||||
|
@ -496,7 +494,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
public String update(String json)
|
public String update(String json)
|
||||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json);
|
String type = TypeUtility.getTypeName(json);
|
||||||
return update(type, json);
|
return update(type, json);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
// logger.trace("Error Creating {}", facet, e);
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
@ -511,7 +509,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
public String update(String type, String json)
|
public String update(String type, String json)
|
||||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
UUID uuid = Utility.getUUIDFromJSONString(json);
|
UUID uuid = UUIDUtility.getUUID(json);
|
||||||
return update(type, json, uuid);
|
return update(type, json, uuid);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
// logger.trace("Error Creating {}", facet, e);
|
// logger.trace("Error Creating {}", facet, e);
|
||||||
|
@ -554,8 +552,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
public <ERElem extends ERElement> boolean delete(ERElem er)
|
public <ERElem extends ERElement> boolean delete(ERElem er)
|
||||||
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
throws SchemaViolationException, NotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
String type = TypeUtility.getTypeName(er);
|
||||||
.getTypeName(er);
|
|
||||||
UUID uuid = er.getUUID();
|
UUID uuid = er.getUUID();
|
||||||
return delete(type, uuid);
|
return delete(type, uuid);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
|
@ -831,8 +828,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
public List<ERElement> addToContext(ERElement er, UUID contextUUID, Boolean dryRun)
|
public List<ERElement> addToContext(ERElement er, UUID contextUUID, Boolean dryRun)
|
||||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
String type = TypeUtility.getTypeName(er);
|
||||||
.getTypeName(er);
|
|
||||||
UUID instanceUUID = er.getUUID();
|
UUID instanceUUID = er.getUUID();
|
||||||
return addToContext(type, instanceUUID, contextUUID, dryRun);
|
return addToContext(type, instanceUUID, contextUUID, dryRun);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
|
@ -899,8 +895,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
public List<ERElement> removeFromContext(ERElement er, UUID contextUUID, Boolean dryRun)
|
public List<ERElement> removeFromContext(ERElement er, UUID contextUUID, Boolean dryRun)
|
||||||
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
|
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility
|
String type = TypeUtility.getTypeName(er);
|
||||||
.getTypeName(er);
|
|
||||||
UUID instanceUUID = er.getUUID();
|
UUID instanceUUID = er.getUUID();
|
||||||
return removeFromContext(type, instanceUUID, contextUUID, dryRun);
|
return removeFromContext(type, instanceUUID, contextUUID, dryRun);
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
|
@ -959,7 +954,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
||||||
@Override
|
@Override
|
||||||
public <ERElem extends ERElement> Map<UUID, String> getElementContexts(ERElem er)
|
public <ERElem extends ERElement> Map<UUID, String> getElementContexts(ERElem er)
|
||||||
throws NotFoundException, ResourceRegistryException {
|
throws NotFoundException, ResourceRegistryException {
|
||||||
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er);
|
String type = TypeUtility.getTypeName(er);
|
||||||
UUID instanceUUID = er.getUUID();
|
UUID instanceUUID = er.getUUID();
|
||||||
return getElementContexts(type, instanceUUID);
|
return getElementContexts(type, instanceUUID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,7 +396,7 @@ public class ERManagementTest extends ContextTest {
|
||||||
@Test
|
@Test
|
||||||
public void testReadResource() throws Exception {
|
public void testReadResource() throws Exception {
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
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();
|
String read = resourceManagement.read().toString();
|
||||||
logger.debug(read);
|
logger.debug(read);
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,7 @@ public class ERManagementTest extends ContextTest {
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteResource() throws Exception {
|
public void testDeleteResource() throws Exception {
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
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();
|
boolean deleted = resourceManagement.delete();
|
||||||
Assert.assertTrue(deleted);
|
Assert.assertTrue(deleted);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class SmartgearResourcesTest extends ERManagementTest {
|
||||||
@Test
|
@Test
|
||||||
public void testHostingNodeOperations() throws ResourceRegistryException,
|
public void testHostingNodeOperations() throws ResourceRegistryException,
|
||||||
IOException, URISyntaxException {
|
IOException, URISyntaxException {
|
||||||
UUID uuid = UUIDManager.getInstance().generateValidRandomUUID();
|
UUID uuid = UUIDManager.getInstance().generateValidUUID();
|
||||||
|
|
||||||
HostingNode hostingNode = new HostingNodeImpl();
|
HostingNode hostingNode = new HostingNodeImpl();
|
||||||
hostingNode.setUUID(uuid);
|
hostingNode.setUUID(uuid);
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class SmartgearResourcesTest extends ContextTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostingNodeOperations() throws ResourceRegistryException, IOException{
|
public void testHostingNodeOperations() throws ResourceRegistryException, IOException{
|
||||||
UUID uuid = UUIDManager.getInstance().generateValidRandomUUID();
|
UUID uuid = UUIDManager.getInstance().generateValidUUID();
|
||||||
|
|
||||||
HostingNode hostingNode = new HostingNodeImpl();
|
HostingNode hostingNode = new HostingNodeImpl();
|
||||||
hostingNode.setUUID(uuid);
|
hostingNode.setUUID(uuid);
|
||||||
|
|
Loading…
Reference in New Issue