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 eb82b2b..5b24146 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 @@ -8,7 +8,9 @@ import org.gcube.informationsystem.model.relation.ConsistsOf; import org.gcube.informationsystem.model.relation.IsRelatedTo; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; /** @@ -16,31 +18,38 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resour */ public interface ResourceRegistryPublisher { - public F createFacet(Class facetClass, F facet) throws ResourceRegistryException; + + public F createFacet(Class facetClass, F facet) throws FacetAlreadyPresentException, ResourceRegistryException; - public F updateFacet(Class facetClass, F facet) throws ResourceRegistryException; + public F updateFacet(Class facetClass, F facet) throws FacetNotFoundException, ResourceRegistryException; - public boolean deleteFacet(F facet) throws ResourceRegistryException; + public boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException; + public R createResource(Class resourceClass, - R resource) throws ResourceRegistryException; + R resource) throws ResourceAlreadyPresentException, ResourceRegistryException; - public R updateResource(Class resourceClass, R resource) throws ResourceRegistryException; + public R updateResource(Class resourceClass, R resource) throws ResourceNotFoundException, ResourceRegistryException; - public boolean deleteResource(R resource) throws ResourceRegistryException; + public boolean deleteResource(R resource) throws ResourceNotFoundException, ResourceRegistryException; + public > C createConsistsOf( - Class consistsOfClass, C consistsOf) throws ResourceRegistryException; + Class consistsOfClass, C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException; public > boolean deleteConsistsOf( C consistsOf) throws ResourceRegistryException; - + + public boolean deleteConsistsOf(UUID uuid) throws ResourceRegistryException; + + public > I createIsRelatedTo( - Class isRelatedToClass, I isRelatedTo) throws ResourceRegistryException; + Class isRelatedToClass, I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException; public > boolean deleteIsRelatedTo( I isRelatedTo) throws ResourceRegistryException; + public boolean deleteIsRelatedTo(UUID uuid) throws ResourceRegistryException; public boolean addResourceToContext(UUID uuid) @@ -51,6 +60,7 @@ public interface ResourceRegistryPublisher { throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + public boolean addFacetToContext(UUID uuid) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException; @@ -67,6 +77,7 @@ public interface ResourceRegistryPublisher { throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException; + public boolean removeFacetFromContext(UUID uuid) throws FacetNotFoundException, 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 e86a943..d7404e2 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 @@ -20,7 +20,9 @@ import org.gcube.informationsystem.model.relation.ConsistsOf; import org.gcube.informationsystem.model.relation.IsRelatedTo; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.api.rest.ERPath; import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPCall; @@ -57,7 +59,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public F createFacet(Class facetClass, F facet) throws ResourceRegistryException { + public F createFacet(Class facetClass, F facet) throws FacetAlreadyPresentException, ResourceRegistryException { try { logger.info("Going to create: {}", facet); @@ -91,7 +93,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public F updateFacet(Class facetClass, F facet) throws ResourceRegistryException { + public F updateFacet(Class facetClass, F facet) throws FacetNotFoundException, ResourceRegistryException { try { logger.info("Going to update: {}", facet); StringWriter stringWriter = new StringWriter(); @@ -123,7 +125,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public boolean deleteFacet(F facet) throws ResourceRegistryException { + public boolean deleteFacet(F facet) throws FacetNotFoundException, ResourceRegistryException { try { logger.info("Going to delete: {}", facet); StringWriter stringWriter = new StringWriter(); @@ -154,9 +156,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @Override public R createResource(Class resourceClass, - R resource) throws ResourceRegistryException { + R resource) throws ResourceAlreadyPresentException, ResourceRegistryException { try { logger.info("Going to create: {}", resource); StringWriter stringWriter = new StringWriter(); @@ -191,7 +194,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public R updateResource(Class resourceClass, - R resource) throws ResourceRegistryException { + R resource) throws ResourceNotFoundException, ResourceRegistryException { try { logger.info("Going to update: {}", resource); StringWriter stringWriter = new StringWriter(); @@ -224,7 +227,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public boolean deleteResource(R resource) throws ResourceRegistryException { + public boolean deleteResource(R resource) throws ResourceNotFoundException, ResourceRegistryException { try { logger.info("Going to delete: {}", resource); StringWriter stringWriter = new StringWriter(); @@ -255,9 +258,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } } + @Override public > C createConsistsOf( - Class consistsOfClass, C consistsOf) throws ResourceRegistryException { + Class consistsOfClass, C consistsOf) throws FacetNotFoundException, ResourceNotFoundException, ResourceRegistryException { try { logger.info("Going to create: {}", consistsOf); StringWriter stringWriter = new StringWriter(); @@ -302,15 +306,21 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public > boolean deleteConsistsOf( C consistsOf) throws ResourceRegistryException { - try { - logger.info("Going to delete: {}", consistsOf); + return deleteConsistsOf(consistsOf.getHeader().getUUID()); + } + + @Override + public boolean deleteConsistsOf(UUID uuid) throws ResourceRegistryException { + try { + + logger.info("Going to delete {} with UUID {}", ConsistsOf.NAME, uuid); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(ERPath.ER_PATH_PART); stringWriter.append(PATH_SEPARATOR); stringWriter.append(ERPath.CONSISTS_OF_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(consistsOf.getHeader().getUUID().toString()); + stringWriter.append(uuid.toString()); HTTPCall httpCall = new HTTPCall<>(stringWriter.toString(), HTTPMETHOD.DELETE, null); @@ -319,22 +329,23 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher Boolean.class, httpCall); boolean deleted = delegate.make(call); - logger.info("{} {}", consistsOf, deleted ? " successfully deleted" + logger.info("{} with UUID {} {}", ConsistsOf.NAME, uuid, deleted ? " successfully deleted" : "was NOT deleted"); return deleted; } catch (ResourceRegistryException e) { - logger.error("Error Removing {}", consistsOf, e); + logger.error("Error Removing {} with UUID {}", ConsistsOf.NAME, uuid, e); throw e; } catch (Exception e) { - logger.error("Error Removing {}", consistsOf, e); + logger.error("Error Removing {} with UUID {}", ConsistsOf.NAME, uuid, e); throw new ServiceException(e); } } + @Override public > I createIsRelatedTo( - Class isRelatedToClass, I isRelatedTo) throws ResourceRegistryException { + Class isRelatedToClass, I isRelatedTo) throws ResourceNotFoundException, ResourceRegistryException { try { logger.info("Going to create: {}", isRelatedTo); @@ -380,15 +391,20 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public > boolean deleteIsRelatedTo( I isRelatedTo) throws ResourceRegistryException { + return deleteIsRelatedTo(isRelatedTo.getHeader().getUUID()); + } + + @Override + public boolean deleteIsRelatedTo(UUID uuid) throws ResourceRegistryException { try { - logger.info("Going to delete: {}", isRelatedTo); + logger.info("Going to delete {} with UUID {}", IsRelatedTo.NAME, uuid); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(ERPath.ER_PATH_PART); stringWriter.append(PATH_SEPARATOR); stringWriter.append(ERPath.IS_RELATED_TO_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(isRelatedTo.getHeader().getUUID().toString()); + stringWriter.append(uuid.toString()); HTTPCall httpCall = new HTTPCall<>(stringWriter.toString(), HTTPMETHOD.DELETE, null); @@ -397,19 +413,20 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher Boolean.class, httpCall); boolean deleted = delegate.make(call); - logger.info("{} {}", isRelatedTo, deleted ? " successfully deleted" + logger.info("{} with UUID {} {}", IsRelatedTo.NAME, uuid, deleted ? " successfully deleted" : "was NOT deleted"); return deleted; } catch (ResourceRegistryException e) { - logger.error("Error Removing {}", isRelatedTo, e); + logger.error("Error Removing {} with UUID {}", IsRelatedTo.NAME, uuid, e); throw e; } catch (Exception e) { - logger.error("Error Removing {}", isRelatedTo, e); + logger.error("Error Removing {} with UUID {}", IsRelatedTo.NAME, uuid, e); throw new ServiceException(e); } } + @Override public boolean addResourceToContext(UUID uuid) throws ResourceNotFoundException, ContextNotFoundException, @@ -459,6 +476,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher return addResourceToContext(resource.getHeader().getUUID()); } + @Override public boolean addFacetToContext(UUID uuid) throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { @@ -507,7 +525,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher return addFacetToContext(facet.getHeader().getUUID()); } - /* -------------------------------------------------------------------- */ + @Override public boolean removeResourceFromContext(UUID uuid) throws ResourceNotFoundException, ContextNotFoundException, @@ -558,6 +576,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher return removeResourceFromContext(resource.getHeader().getUUID()); } + @Override public boolean removeFacetFromContext(UUID uuid) throws FacetNotFoundException, ContextNotFoundException, @@ -608,4 +627,5 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher return removeFacetFromContext(facet.getHeader().getUUID()); } + } 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 1fd1f2b..2f0cb5d 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/MultiContextTest.java @@ -38,7 +38,6 @@ import org.gcube.informationsystem.model.relation.IsIdentifiedBy; 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;