From fe37358ea7466069d91a6ebc41f3735b8bb55798 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 16 Feb 2021 17:17:40 +0100 Subject: [PATCH] Adding SchemaViolationException --- .../instances/model/ERManagement.java | 7 ++++--- .../model/entities/EntityManagement.java | 5 +++-- .../model/entities/ResourceManagement.java | 3 ++- .../model/relations/ConsistsOfManagement.java | 3 ++- .../model/relations/IsRelatedToManagement.java | 3 ++- .../resourceregistry/rest/SharingManager.java | 18 ++++++++++-------- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagement.java index f2e3ed3..d2c12c1 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagement.java @@ -8,6 +8,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAn import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; public interface ERManagement { @@ -24,15 +25,15 @@ public interface ERManagement { throws ContextException, ResourceRegistryException; public Map addToContext(UUID contextUUID) - throws NotFoundException, ContextException, ResourceRegistryException; + throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException; public Map internalRemoveFromContext(SecurityContext targetSecurityContext) throws ContextException, ResourceRegistryException; public Map removeFromContext(UUID contextUUID) - throws NotFoundException, ContextException, ResourceRegistryException; + throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException; - public void sanityCheck(Map expectedInstances) throws ResourceRegistryException; + public void sanityCheck(Map expectedInstances) throws SchemaViolationException, ResourceRegistryException; public AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java index 9862eaf..194253d 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java @@ -28,6 +28,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.context.Conte import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; @@ -336,7 +337,7 @@ public abstract class EntityManagement extends EntityElementMa } } - public Map addToContext(UUID contextUUID) throws NotFoundException, ContextException, ResourceRegistryException { + public Map addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException { logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { @@ -423,7 +424,7 @@ public abstract class EntityManagement extends EntityElementMa } public Map removeFromContext(UUID contextUUID) - throws NotFoundException, ContextException, ResourceRegistryException { + throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException { logger.debug("Going to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java index b83a599..e42d06b 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/ResourceManagement.java @@ -25,6 +25,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.context.Conte 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.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; @@ -309,7 +310,7 @@ public class ResourceManagement extends EntityManagement { } @Override - public void sanityCheck(Map expectedInstances) throws ResourceRegistryException { + public void sanityCheck(Map expectedInstances) throws SchemaViolationException, ResourceRegistryException { /* * Actually this function only check the Resource constraint, i.e., resource has at least a Facet * in any context. diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java index 5f65f7d..fdc0ed3 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java @@ -15,6 +15,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis 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.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; /** @@ -59,7 +60,7 @@ public class ConsistsOfManagement extends RelationManagement { } @Override - public void sanityCheck(Map expectedInstances) throws ResourceRegistryException { + public void sanityCheck(Map expectedInstances) throws SchemaViolationException, ResourceRegistryException { // TODO Auto-generated method stub } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/IsRelatedToManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/IsRelatedToManagement.java index 119fe89..16ebe72 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/IsRelatedToManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/IsRelatedToManagement.java @@ -15,6 +15,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis 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.instances.model.entities.ResourceManagement; /** @@ -59,7 +60,7 @@ public class IsRelatedToManagement extends RelationManagement expectedInstances) throws ResourceRegistryException { + public void sanityCheck(Map expectedInstances) throws SchemaViolationException, ResourceRegistryException { // TODO Auto-generated method stub } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SharingManager.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SharingManager.java index 19e59b1..d90b399 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SharingManager.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/SharingManager.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; +import javax.ws.rs.DefaultValue; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -21,6 +22,7 @@ import org.gcube.informationsystem.model.reference.properties.Header; 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.resource.ResourceNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath; import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation; @@ -65,11 +67,11 @@ public class SharingManager { * * Each instance is managed without considering the propagation constraint of relations. * - * PATCH /sharing/contexts/{CONTEXT_UUID}?operation=(ADD|REMOVE) + * POST /sharing/contexts/{CONTEXT_UUID}?operation=(ADD|REMOVE)&[dryRun=true] * * e.g - * PATCH /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=ADD - * PATCH /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=REMOVE + * POST /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=ADD&dryRun=true + * POST /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=REMOVE * * where * 67062c11-9c3a-4906-870d-7df6a43408b0/ is the Context UUID @@ -82,9 +84,9 @@ public class SharingManager { public String addRemoveNoPropagationConstraint( @PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId, @QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation, - @QueryParam(SharingPath.DRY_RUN_QUERY_PARAMETER) Boolean dryRun, + @QueryParam(SharingPath.DRY_RUN_QUERY_PARAMETER) @DefaultValue("false") Boolean dryRun, String body) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { try { StringBuffer calledMethod = new StringBuffer(); @@ -141,7 +143,7 @@ public class SharingManager { * * Return the list of instances affected by an add/remove to/from context the target instance identified by UUID path parameter * - * POST /sharing/contexts/{CONTEXT_UUID}/{TYPE_NAME}/{UUID}?operation=(ADD|REMOVE)&[dryRun=true] + * POST /sharing/contexts/{CONTEXT_UUID}/{TYPE_NAME}/{UUID}?operation=(ADD|REMOVE)&dryRun=true] * * e.g * POST /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8?operation=ADD&dryRun=true @@ -160,8 +162,8 @@ public class SharingManager { @PathParam(AccessPath.TYPE_PATH_PARAM) String type, @PathParam(AccessPath.UUID_PATH_PARAM) String instanceId, @QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation, - @QueryParam(SharingPath.DRY_RUN_QUERY_PARAMETER) Boolean dryRun) - throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { + @QueryParam(SharingPath.DRY_RUN_QUERY_PARAMETER) @DefaultValue("false") Boolean dryRun) + throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { StringBuffer calledMethod = new StringBuffer(); if(dryRun==null) {