diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java index 66bbae0..eb82b2b 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisher.java @@ -16,31 +16,33 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour */ public interface ResourceRegistryPublisher { - public F createFacet(Class facetClass, F facet); + public F createFacet(Class facetClass, F facet) throws ResourceRegistryException; - public F updateFacet(Class facetClass, F facet); + public F updateFacet(Class facetClass, F facet) throws ResourceRegistryException; - public boolean deleteFacet(F facet); + public boolean deleteFacet(F facet) throws ResourceRegistryException; public R createResource(Class resourceClass, - R resource); + R resource) throws ResourceRegistryException; - public R updateResource(Class resourceClass, R resource); + public R updateResource(Class resourceClass, R resource) throws ResourceRegistryException; - public boolean deleteResource(R resource); + public boolean deleteResource(R resource) throws ResourceRegistryException; public > C createConsistsOf( - Class consistsOfClass, C consistsOf); + Class consistsOfClass, C consistsOf) throws ResourceRegistryException; public > boolean deleteConsistsOf( - C consistsOf); + C consistsOf) throws ResourceRegistryException; public > I createIsRelatedTo( - Class isRelatedToClass, I isRelatedTo); + Class isRelatedToClass, I isRelatedTo) throws ResourceRegistryException; public > boolean deleteIsRelatedTo( - I isRelatedTo); + I isRelatedTo) throws ResourceRegistryException; + + public boolean addResourceToContext(UUID uuid) throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java index 67ab9f5..e86a943 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/proxy/ResourceRegistryPublisherImpl.java @@ -57,7 +57,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public F createFacet(Class facetClass, F facet) { + public F createFacet(Class facetClass, F facet) throws ResourceRegistryException { try { logger.info("Going to create: {}", facet); @@ -80,6 +80,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher F f = delegate.make(call); logger.info("{} successfully created", f); return f; + + } catch (ResourceRegistryException e) { + logger.error("Error Creating {}", facet, e); + throw e; } catch (Exception e) { logger.error("Error Creating {}", facet, e); throw new ServiceException(e); @@ -87,7 +91,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public F updateFacet(Class facetClass, F facet) { + public F updateFacet(Class facetClass, F facet) throws ResourceRegistryException { try { logger.info("Going to update: {}", facet); StringWriter stringWriter = new StringWriter(); @@ -108,6 +112,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher F f = delegate.make(call); logger.info("{} successfully updated", f); return f; + + } catch (ResourceRegistryException e) { + logger.error("Error Updating {}", facet, e); + throw e; } catch (Exception e) { logger.error("Error Updating {}", facet, e); throw new ServiceException(e); @@ -115,7 +123,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public boolean deleteFacet(F facet) { + public boolean deleteFacet(F facet) throws ResourceRegistryException { try { logger.info("Going to delete: {}", facet); StringWriter stringWriter = new StringWriter(); @@ -136,6 +144,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher logger.info("{} {}", facet, deleted ? " successfully deleted" : "was NOT deleted"); return deleted; + + } catch (ResourceRegistryException e) { + logger.error("Error Removing {}", facet, e); + throw e; } catch (Exception e) { logger.error("Error Removing {}", facet, e); throw new ServiceException(e); @@ -144,7 +156,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public R createResource(Class resourceClass, - R resource) { + R resource) throws ResourceRegistryException { try { logger.info("Going to create: {}", resource); StringWriter stringWriter = new StringWriter(); @@ -166,6 +178,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher R r = delegate.make(call); logger.info("{} successfully created", r); return r; + + } catch (ResourceRegistryException e) { + logger.error("Error Creating {}", resource, e); + throw e; + } catch (Exception e) { logger.error("Error Creating {}", resource, e); throw new ServiceException(e); @@ -174,7 +191,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public R updateResource(Class resourceClass, - R resource) { + R resource) throws ResourceRegistryException { try { logger.info("Going to update: {}", resource); StringWriter stringWriter = new StringWriter(); @@ -196,6 +213,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher R r = delegate.make(call); logger.info("{} update created", r); return r; + + } catch (ResourceRegistryException e) { + logger.error("Error Creating {}", resource, e); + throw e; } catch (Exception e) { logger.error("Error Creating {}", resource, e); throw new ServiceException(e); @@ -203,7 +224,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public boolean deleteResource(R resource) { + public boolean deleteResource(R resource) throws ResourceRegistryException { try { logger.info("Going to delete: {}", resource); StringWriter stringWriter = new StringWriter(); @@ -224,6 +245,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher logger.info("{} {}", resource, deleted ? " successfully deleted" : "was NOT deleted"); return deleted; + + } catch (ResourceRegistryException e) { + logger.error("Error Removing {}", resource, e); + throw e; } catch (Exception e) { logger.error("Error Removing {}", resource, e); throw new ServiceException(e); @@ -232,7 +257,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public > C createConsistsOf( - Class consistsOfClass, C consistsOf) { + Class consistsOfClass, C consistsOf) throws ResourceRegistryException { try { logger.info("Going to create: {}", consistsOf); StringWriter stringWriter = new StringWriter(); @@ -264,6 +289,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher C c = delegate.make(call); logger.info("{} successfully created", c); return c; + + } catch (ResourceRegistryException e) { + logger.error("Error Creating {}", consistsOf, e); + throw e; } catch (Exception e) { logger.error("Error Creating {}", consistsOf, e); throw new ServiceException(e); @@ -272,7 +301,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public > boolean deleteConsistsOf( - C consistsOf) { + C consistsOf) throws ResourceRegistryException { try { logger.info("Going to delete: {}", consistsOf); StringWriter stringWriter = new StringWriter(); @@ -293,6 +322,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher logger.info("{} {}", consistsOf, deleted ? " successfully deleted" : "was NOT deleted"); return deleted; + + } catch (ResourceRegistryException e) { + logger.error("Error Removing {}", consistsOf, e); + throw e; } catch (Exception e) { logger.error("Error Removing {}", consistsOf, e); throw new ServiceException(e); @@ -301,7 +334,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public > I createIsRelatedTo( - Class isRelatedToClass, I isRelatedTo) { + Class isRelatedToClass, I isRelatedTo) throws ResourceRegistryException { try { logger.info("Going to create: {}", isRelatedTo); @@ -334,6 +367,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher I i = delegate.make(call); logger.info("{} successfully created", i); return i; + + } catch (ResourceRegistryException e) { + logger.error("Error Creating {}", isRelatedTo, e); + throw e; } catch (Exception e) { logger.error("Error Creating {}", isRelatedTo, e); throw new ServiceException(e); @@ -342,7 +379,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public > boolean deleteIsRelatedTo( - I isRelatedTo) { + I isRelatedTo) throws ResourceRegistryException { try { logger.info("Going to delete: {}", isRelatedTo); StringWriter stringWriter = new StringWriter(); @@ -363,6 +400,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher logger.info("{} {}", isRelatedTo, deleted ? " successfully deleted" : "was NOT deleted"); return deleted; + + } catch (ResourceRegistryException e) { + logger.error("Error Removing {}", isRelatedTo, e); + throw e; } catch (Exception e) { logger.error("Error Removing {}", isRelatedTo, e); throw new ServiceException(e); @@ -399,6 +440,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher Resource.NAME, uuid, added ? "successfully" : "NOT", Context.NAME, context); return added; + + } catch (ResourceRegistryException e) { + logger.error("Error Adding {} with UUID {} to current {} : {}", + Resource.NAME, uuid, Context.NAME, context, e); + throw e; } catch (Exception e) { logger.error("Error Adding {} with UUID {} to current {} : {}", Resource.NAME, uuid, Context.NAME, context, e); @@ -442,6 +488,11 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher Facet.NAME, uuid, added ? "successfully" : "NOT", Context.NAME, context); return added; + + } catch (ResourceRegistryException e) { + logger.error("Error Adding {} with UUID {} to current {} : {}", + Facet.NAME, uuid, Context.NAME, context, e); + throw e; } catch (Exception e) { logger.error("Error Adding {} with UUID {} to current {} : {}", Facet.NAME, uuid, Context.NAME, context, e); @@ -487,6 +538,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher Resource.NAME, uuid, removed ? "successfully" : "NOT", Context.NAME, context); return removed; + + } catch (ResourceRegistryException e) { + logger.error("Error Adding {} with UUID {} to current {} : {}", + Resource.NAME, uuid, Context.NAME, context, e); + throw e; + } catch (Exception e) { logger.error("Error Adding {} with UUID {} to current {} : {}", Resource.NAME, uuid, Context.NAME, context, e); @@ -531,6 +588,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher Facet.NAME, uuid, removed ? "successfully" : "NOT", Context.NAME, context); return removed; + + } catch (ResourceRegistryException e) { + logger.error("Error Adding {} with UUID {} to current {} : {}", + Facet.NAME, uuid, Context.NAME, context, e); + throw e; + } catch (Exception e) { logger.error("Error Adding {} with UUID {} to current {} : {}", Facet.NAME, uuid, Context.NAME, context, e); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java index 531dbfb..1fd1f2b 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java @@ -39,6 +39,7 @@ import org.gcube.informationsystem.model.relation.consistsof.HasPersistentMemory import org.gcube.informationsystem.model.relation.consistsof.HasVolatileMemory; import org.gcube.informationsystem.model.relation.isrelatedto.Hosts; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.proxy.ResourceRegistryClientFactory; import org.gcube.informationsystem.resourceregistry.publisher.proxy.ResourceRegistryPublisher; @@ -152,13 +153,13 @@ public class MultiContextTest extends ScopedTest { Assert.assertTrue(addedToContext); UUID eServiceUUID = createEService.getHeader().getUUID(); + try { resourceRegistryClient.getInstance(EService.class, eServiceUUID); - }catch(ResourceRegistryException e){ + }catch(ResourceNotFoundException e){ logger.debug("Resource with {} Not Found as Expected", uuid.toString()); } - boolean deleted = resourceRegistryPublisher.deleteResource(createdHN); Assert.assertTrue(deleted); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ScopedTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ScopedTest.java index 753ba72..4732ef8 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ScopedTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ScopedTest.java @@ -59,8 +59,8 @@ public class ScopedTest { GCUBE_DEVSEC = properties.getProperty(GCUBE_DEVSEC_VARNAME); GCUBE_DEVSEC_DEVVRE = properties.getProperty(GCUBE_DEVSEC_DEVVRE_VARNAME); - DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT; - ALTERNATIVE_TEST_SCOPE = GCUBE_DEVNEXT_NEXTNEXT; + DEFAULT_TEST_SCOPE = GCUBE_DEVSEC; + ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC_DEVVRE; } public static String getCurrentScope(String token) throws ObjectNotFound, Exception{