Reorganized utilities and their usage

This commit is contained in:
Luca Frosini 2023-04-21 15:57:08 +02:00
parent ac164abb46
commit faa0642224
3 changed files with 47 additions and 45 deletions

View File

@ -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 <ERElem extends ERElement> boolean existType(Class<ERElem> clazz) throws ResourceRegistryException {
return existType(Utility.getTypeName(clazz));
return existType(TypeUtility.getTypeName(clazz));
}
@Override
@ -313,7 +313,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public <ERElem extends ERElement> List<Type> getType(Class<ERElem> 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 <ERElem extends ERElement> List<ERElem> getInstances(Class<ERElem> clazz, Boolean polymorphic)
throws ResourceRegistryException {
String type = Utility.getTypeName(clazz);
String type = TypeUtility.getTypeName(clazz);
String ret = getInstances(type, polymorphic);
try {
return (List<ERElem>) ElementMapper.unmarshalList(ERElement.class, ret);
@ -399,7 +399,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
@Override
public <ERElem extends ERElement> boolean existInstance(Class<ERElem> 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 extends ERElement> ERElem getInstance(Class<ERElem> 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 <R extends Resource, C extends ConsistsOf<?,?>, F extends Facet> List<R> getResourcesFromReferenceFacet(
Class<R> resourceClass, Class<C> consistsOfClass, Class<F> 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 <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> 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<R>) ElementMapper.unmarshalList(Resource.class, ret);
@ -639,9 +639,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
public <R extends Resource, I extends IsRelatedTo<?,?>, RR extends Resource> List<R> getRelatedResourcesFromReferenceResource(
Class<R> resourceClass, Class<I> isRelatedToClass, Class<RR> 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 <R extends Resource, I extends IsRelatedTo<?,?>, RR extends Resource> List<R> getRelatedResources(
Class<R> resourceClass, Class<I> isRelatedToClass, Class<RR> 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<R>) ElementMapper.unmarshalList(Resource.class, ret);
@ -686,9 +686,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
protected <E extends Entity, R extends Relation<?,?>, RE extends Entity> List<E> getRelated(Class<E> entityClass,
Class<R> relationClass, Class<RE> referenceEntityClass, Direction direction, boolean polymorphic,
Map<String,String> 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<E>) ElementMapper.unmarshalList(Resource.class, ret);
@ -717,9 +717,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
protected <E extends Entity, R extends Relation<?,?>, RE extends Entity> List<E> getRelated(Class<E> entityClass,
Class<R> relationClass, Class<RE> 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 <ERElem extends ERElement> Map<UUID, String> getInstanceContexts(Class<ERElem> clazz, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
String typeName = Utility.getTypeName(clazz);
String typeName = TypeUtility.getTypeName(clazz);
return getInstanceContexts(typeName, uuid);
}

View File

@ -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<EService> eServices = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, softwareFacet, true);

View File

@ -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<EService> 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<EService> 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<EService> 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<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");
public void testExample8() throws Exception {
UUID uuid = UUIDUtility.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{
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<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");
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<EService> list = ElementMapper.unmarshalList(EService.class, jsonString);
logger.debug("{}", list);