diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java index 7556a74..2b64cbd 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisher.java @@ -33,7 +33,15 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema * @author Luca Frosini (ISTI - CNR) */ public interface ResourceRegistryPublisher { + + public List getAllContext() throws ResourceRegistryException; + + public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException; + public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException; + + /* ----- */ + public List list(Class clazz, Boolean polymorphic) throws ResourceRegistryException; @@ -56,8 +64,8 @@ public interface ResourceRegistryPublisher { public boolean exists(String type, UUID uuid) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException; - - + + public ERElem read(ERElem er) throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException; @@ -80,7 +88,6 @@ public interface ResourceRegistryPublisher { public String update(String type, String json, UUID uuid) throws SchemaViolationException, NotFoundException, ResourceRegistryException; - public boolean delete(ERElem er) throws SchemaViolationException, NotFoundException, ResourceRegistryException; @@ -136,10 +143,10 @@ public interface ResourceRegistryPublisher { throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException; public boolean deleteResource(R resource) - throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException; + throws ResourceNotFoundException, ResourceRegistryException; public boolean deleteResource(String resourceType, UUID uuid) - throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException; + throws ResourceNotFoundException, ResourceRegistryException; /* ----- */ @@ -218,7 +225,7 @@ public interface ResourceRegistryPublisher { public List removeFromCurrentContext(ERElement er, Boolean dryRun) throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException; - + public Set getElementContexts(String type, UUID instanceUUID) throws NotFoundException, ResourceRegistryException; @@ -289,12 +296,4 @@ public interface ResourceRegistryPublisher { public Set getFacetContexts(F facet) throws FacetNotFoundException, ResourceRegistryException; - /* ----- */ - - public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException; - - public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException; - - public List getAllContext() throws ResourceRegistryException; - } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java index 817637c..69d940d 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/publisher/ResourceRegistryPublisherImpl.java @@ -30,8 +30,14 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet. import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException; 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.ResourceAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAlreadyPresentException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAvailableInAnotherContextException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAlreadyPresentException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAvailableInAnotherContextException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath; @@ -492,7 +498,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public String update(String type, String json, UUID uuid) - throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ResourceRegistryException { try { logger.trace("Going to create {} : {}", type, json); GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); @@ -627,13 +633,14 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public R readResource(R resource) throws ResourceNotFoundException, ResourceRegistryException { + public R readResource(R resource) + throws ResourceNotFoundException, ResourceAvailableInAnotherContextException, ResourceRegistryException { return read(resource); } @Override public String readResource(String resourceType, UUID uuid) - throws ResourceNotFoundException, ResourceRegistryException { + throws ResourceNotFoundException, ResourceAvailableInAnotherContextException, ResourceRegistryException { return read(resourceType, uuid); } @@ -651,114 +658,115 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public boolean deleteResource(R resource) - throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { + throws ResourceNotFoundException, ResourceRegistryException { return delete(resource); } @Override public boolean deleteResource(String resourceType, UUID uuid) - throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { + throws ResourceNotFoundException, ResourceRegistryException { return delete(resourceType, uuid); } @Override public > C createConsistsOf(C consistsOf) - throws SchemaViolationException, ConsistsOfAlreadyPresentException, ResourceRegistryException { + throws SchemaViolationException, ConsistsOfAlreadyPresentException, ResourceNotFoundException, ResourceRegistryException { return create(consistsOf); } @Override public String createConsistsOf(String consistsOf) - throws SchemaViolationException, ConsistsOfAlreadyPresentException, ResourceRegistryException { + throws SchemaViolationException, ConsistsOfAlreadyPresentException, ResourceNotFoundException, ResourceRegistryException { return create(consistsOf); } @Override public > C readConsistsOf(C consistsOf) - throws NotFoundException, ResourceRegistryException { + throws ConsistsOfNotFoundException, ConsistsOfAvailableInAnotherContextException, ResourceRegistryException { return read(consistsOf); } @Override - public String readConsistsOf(String consistsOfType, UUID uuid) throws NotFoundException, ResourceRegistryException { + public String readConsistsOf(String consistsOfType, UUID uuid) + throws ConsistsOfNotFoundException, ConsistsOfAvailableInAnotherContextException, ResourceRegistryException { return read(consistsOfType, uuid); } @Override public > C updateConsistsOf(C consistsOf) - throws SchemaViolationException, NotFoundException, ResourceRegistryException { + throws SchemaViolationException, ConsistsOfNotFoundException, ResourceRegistryException { return update(consistsOf); } @Override public String updateConsistsOf(String consistsOf) - throws SchemaViolationException, NotFoundException, ResourceRegistryException { + throws SchemaViolationException, ConsistsOfNotFoundException, ResourceRegistryException { return update(consistsOf); } @Override public > boolean deleteConsistsOf(C consistsOf) - throws SchemaViolationException, ResourceRegistryException { + throws SchemaViolationException, ConsistsOfNotFoundException, ResourceRegistryException { return delete(consistsOf); } @Override public boolean deleteConsistsOf(String consistsOfType, UUID uuid) - throws SchemaViolationException, ResourceRegistryException { + throws SchemaViolationException, ConsistsOfNotFoundException, ResourceRegistryException { return delete(consistsOfType, uuid); } @Override public > I createIsRelatedTo(I isRelatedTo) - throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { + throws SchemaViolationException, IsRelatedToAlreadyPresentException, ResourceNotFoundException, ResourceRegistryException { return create(isRelatedTo); } @Override public String createIsRelatedTo(String isRelatedTo) - throws SchemaViolationException, ResourceNotFoundException, ResourceRegistryException { + throws SchemaViolationException, IsRelatedToAlreadyPresentException, ResourceNotFoundException, ResourceRegistryException { return create(isRelatedTo); } @Override public > I readIsRelatedTo(I isRelatedTo) - throws NotFoundException, ResourceRegistryException { + throws IsRelatedToNotFoundException, IsRelatedToAvailableInAnotherContextException, ResourceRegistryException { return read(isRelatedTo); } @Override public String readIsRelatedTo(String isRelatedToType, UUID uuid) - throws NotFoundException, ResourceRegistryException { + throws IsRelatedToNotFoundException, IsRelatedToAvailableInAnotherContextException, ResourceRegistryException { return read(isRelatedToType, uuid); } @Override public > I updateIsRelatedTo(I isRelatedTo) - throws SchemaViolationException, NotFoundException, ResourceRegistryException { + throws SchemaViolationException, IsRelatedToNotFoundException, ResourceRegistryException { return update(isRelatedTo); } @Override public String updateIsRelatedTo(String isRelatedTo) - throws SchemaViolationException, NotFoundException, ResourceRegistryException { + throws SchemaViolationException, IsRelatedToNotFoundException, ResourceRegistryException { return update(isRelatedTo); } @Override public > boolean deleteIsRelatedTo(I isRelatedTo) - throws SchemaViolationException, ResourceRegistryException { + throws IsRelatedToNotFoundException, ResourceRegistryException { return delete(isRelatedTo); } @Override public boolean deleteIsRelatedTo(String isRelatedToType, UUID uuid) - throws SchemaViolationException, ResourceRegistryException { + throws IsRelatedToNotFoundException, ResourceRegistryException { return delete(isRelatedToType, uuid); } @Override public List addToContext(String type, UUID instanceUUID, UUID contextUUID, Boolean dryRun) - throws SchemaViolationException, NotFoundException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { try { logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME, contextUUID); @@ -796,7 +804,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public List addToContext(ERElement er, UUID contextUUID, Boolean dryRun) - throws SchemaViolationException, NotFoundException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { try { String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility .getTypeName(er); @@ -813,21 +821,21 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public List addToCurrentContext(String type, UUID instanceUUID, Boolean dryRun) - throws SchemaViolationException, NotFoundException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { UUID contextUUID = getCurrentContextUUID(); return addToContext(type, instanceUUID, contextUUID, dryRun); } @Override public List addToCurrentContext(ERElement er, Boolean dryRun) - throws SchemaViolationException, NotFoundException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { UUID contextUUID = getCurrentContextUUID(); return addToContext(er, contextUUID, dryRun); } @Override public List removeFromContext(String type, UUID instanceUUID, UUID contextUUID, Boolean dryRun) - throws SchemaViolationException, NotFoundException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { try { logger.trace("Going to add {} with UUID {} to {} with UUID {} ", type, instanceUUID, Context.NAME, contextUUID); @@ -865,8 +873,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public List removeFromContext(ERElement er, UUID contextUUID, Boolean dryRun) - throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, - ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { try { String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility .getTypeName(er); @@ -882,8 +889,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher } @Override - public List removeFromCurrentContext(String type, UUID instanceUUID, Boolean dryRun) throws SchemaViolationException, - ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + public List removeFromCurrentContext(String type, UUID instanceUUID, Boolean dryRun) + throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { UUID contextUUID = getCurrentContextUUID(); return removeFromContext(type, instanceUUID, contextUUID, dryRun); } @@ -898,7 +905,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public Set getElementContexts(String type, UUID instanceUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws NotFoundException, ResourceRegistryException { try { logger.trace("Going to get contexts of {} with UUID {}", type, instanceUUID); GXHTTPStringRequest gxHTTPStringRequest = GXHTTPStringRequest.newRequest(address); @@ -927,7 +934,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public Set getElementContexts(ERElem er) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws NotFoundException, ResourceRegistryException { String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er); UUID instanceUUID = er.getHeader().getUUID(); return getElementContexts(type, instanceUUID); @@ -935,48 +942,43 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher @Override public List addResourceToContext(String resourceType, UUID resourceUUID, UUID contextUUID, Boolean dryRun) - throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, - ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToContext(resourceType, resourceUUID, contextUUID, dryRun); } @Override public List addResourceToContext(R resource, UUID contextUUID, Boolean dryRun) - throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, - ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToContext(resource, contextUUID, dryRun); } @Override - public List addResourceToCurrentContext(String resourceType, UUID resourceUUID, Boolean dryRun) throws SchemaViolationException, - ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + public List addResourceToCurrentContext(String resourceType, UUID resourceUUID, Boolean dryRun) + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToCurrentContext(resourceType, resourceUUID, dryRun); } @Override - public List addResourceToCurrentContext(R resource, Boolean dryRun) throws SchemaViolationException, - ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + public List addResourceToCurrentContext(R resource, Boolean dryRun) + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return addToCurrentContext(resource, dryRun); } @Override public List removeResourceFromContext(String resourceType, UUID resourceUUID, UUID contextUUID, Boolean dryRun) - throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, - ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return removeFromContext(resourceType, resourceUUID, contextUUID, dryRun); } @Override public List removeResourceFromContext(R resource, UUID contextUUID, Boolean dryRun) - throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, - ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return removeFromContext(resource, contextUUID, dryRun); } @Override public List removeResourceFromCurrentContext(String resourceType, UUID resourceUUID, Boolean dryRun) - throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, - ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { return removeFromCurrentContext(resourceType, resourceUUID, dryRun); } @@ -986,76 +988,75 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher return removeFromCurrentContext(resource, dryRun); } - @Override - public List addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID, Boolean dryRun) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - return addToContext(facetType, facetUUID, contextUUID, dryRun); - } - - @Override - public List addFacetToContext(F facet, UUID contextUUID, Boolean dryRun) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - return addToContext(facet, contextUUID, dryRun); - } - - @Override - public List addFacetToCurrentContext(String facetType, UUID facetUUID, Boolean dryRun) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - return addToCurrentContext(facetType, facetUUID, dryRun); - } - - @Override - public List addFacetToCurrentContext(F facet, Boolean dryRun) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - return addToCurrentContext(facet, dryRun); - } - - @Override - public List removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID, Boolean dryRun) - throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, - ResourceRegistryException { - return removeFromContext(facetType, facetUUID, contextUUID, dryRun); - } - - @Override - public List removeFacetFromContext(F facet, UUID contextUUID, Boolean dryRun) throws SchemaViolationException, - FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - return removeFromContext(facet, contextUUID, dryRun); - } - - @Override - public List removeFacetFromCurrentContext(String facetType, UUID facetUUID, Boolean dryRun) throws SchemaViolationException, - FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - return removeFromCurrentContext(facetType, facetUUID, dryRun); - } - - @Override - public List removeFacetFromCurrentContext(F facet, Boolean dryRun) throws SchemaViolationException, - FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { - return removeFromCurrentContext(facet, dryRun); - } - @Override public Set getResourceContexts(String resourceType, UUID resourceUUID) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws ResourceNotFoundException, ResourceRegistryException { return getElementContexts(resourceType, resourceUUID); } @Override public Set getResourceContexts(R resource) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws ResourceNotFoundException, ResourceRegistryException { return getElementContexts(resource); } + + @Override + public List addFacetToContext(String facetType, UUID facetUUID, UUID contextUUID, Boolean dryRun) + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToContext(facetType, facetUUID, contextUUID, dryRun); + } + + @Override + public List addFacetToContext(F facet, UUID contextUUID, Boolean dryRun) + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToContext(facet, contextUUID, dryRun); + } + + @Override + public List addFacetToCurrentContext(String facetType, UUID facetUUID, Boolean dryRun) + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToCurrentContext(facetType, facetUUID, dryRun); + } + + @Override + public List addFacetToCurrentContext(F facet, Boolean dryRun) + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return addToCurrentContext(facet, dryRun); + } + + @Override + public List removeFacetFromContext(String facetType, UUID facetUUID, UUID contextUUID, Boolean dryRun) + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromContext(facetType, facetUUID, contextUUID, dryRun); + } + + @Override + public List removeFacetFromContext(F facet, UUID contextUUID, Boolean dryRun) + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromContext(facet, contextUUID, dryRun); + } + + @Override + public List removeFacetFromCurrentContext(String facetType, UUID facetUUID, Boolean dryRun) + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromCurrentContext(facetType, facetUUID, dryRun); + } + + @Override + public List removeFacetFromCurrentContext(F facet, Boolean dryRun) + throws SchemaViolationException, FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + return removeFromCurrentContext(facet, dryRun); + } @Override public Set getFacetContexts(String facetType, UUID facetUUID) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws FacetNotFoundException, ResourceRegistryException { return getElementContexts(facetType, facetUUID); } @Override public Set getFacetContexts(F facet) - throws FacetNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws FacetNotFoundException, ResourceRegistryException { return getElementContexts(facet); }