Adding SchemaViolationException

This commit is contained in:
Luca Frosini 2021-02-16 17:17:40 +01:00
parent e653081e55
commit fe37358ea7
6 changed files with 23 additions and 16 deletions

View File

@ -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.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; 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; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
public interface ERManagement { public interface ERManagement {
@ -24,15 +25,15 @@ public interface ERManagement {
throws ContextException, ResourceRegistryException; throws ContextException, ResourceRegistryException;
public Map<UUID, JsonNode> addToContext(UUID contextUUID) public Map<UUID, JsonNode> addToContext(UUID contextUUID)
throws NotFoundException, ContextException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException;
public Map<UUID, JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext) public Map<UUID, JsonNode> internalRemoveFromContext(SecurityContext targetSecurityContext)
throws ContextException, ResourceRegistryException; throws ContextException, ResourceRegistryException;
public Map<UUID, JsonNode> removeFromContext(UUID contextUUID) public Map<UUID, JsonNode> removeFromContext(UUID contextUUID)
throws NotFoundException, ContextException, ResourceRegistryException; throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException;
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException; public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException;
public AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message); public AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message);

View File

@ -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.entity.EntityAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; 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.SchemaException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
@ -336,7 +337,7 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
} }
} }
public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws NotFoundException, ContextException, ResourceRegistryException { public Map<UUID,JsonNode> addToContext(UUID contextUUID) throws SchemaViolationException, NotFoundException, ContextException, ResourceRegistryException {
logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID); logger.info("Going to add {} with UUID {} to Context with UUID {}", accessType.getName(), uuid, contextUUID);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try { try {
@ -423,7 +424,7 @@ public abstract class EntityManagement<E extends Entity> extends EntityElementMa
} }
public Map<UUID,JsonNode> removeFromContext(UUID contextUUID) public Map<UUID,JsonNode> 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); logger.debug("Going to remove {} with UUID {} from Context with UUID {}", elementType, uuid, contextUUID);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
try { try {

View File

@ -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.ResourceAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException; 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.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;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
@ -309,7 +310,7 @@ public class ResourceManagement extends EntityManagement<Resource> {
} }
@Override @Override
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException { public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
/* /*
* Actually this function only check the Resource constraint, i.e., resource has at least a Facet * Actually this function only check the Resource constraint, i.e., resource has at least a Facet
* in any context. * in any context.

View File

@ -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.ConsistsOfAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAvailableInAnotherContextException; 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.consistsOf.ConsistsOfNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
/** /**
@ -59,7 +60,7 @@ public class ConsistsOfManagement extends RelationManagement<FacetManagement> {
} }
@Override @Override
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException { public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }

View File

@ -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.IsRelatedToAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isrelatedto.IsRelatedToAvailableInAnotherContextException; 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.relation.isrelatedto.IsRelatedToNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
/** /**
@ -59,7 +60,7 @@ public class IsRelatedToManagement extends RelationManagement<ResourceManagement
} }
@Override @Override
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws ResourceRegistryException { public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; 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.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; 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.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.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath; import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation; 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. * 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 * e.g
* PATCH /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=ADD * POST /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=ADD&dryRun=true
* PATCH /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=REMOVE * POST /resource-registry/contexts/67062c11-9c3a-4906-870d-7df6a43408b0?operation=REMOVE
* *
* where * where
* 67062c11-9c3a-4906-870d-7df6a43408b0/ is the Context UUID * 67062c11-9c3a-4906-870d-7df6a43408b0/ is the Context UUID
@ -82,9 +84,9 @@ public class SharingManager {
public String addRemoveNoPropagationConstraint( public String addRemoveNoPropagationConstraint(
@PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId, @PathParam(AccessPath.CONTEXT_UUID_PATH_PARAM) String contextId,
@QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation, @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) String body)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
try { try {
StringBuffer calledMethod = new StringBuffer(); 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 * 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 * e.g
* POST /resource-registry/sharing/contexts/67062c11-9c3a-4906-870d-7df6a43408b0/HostingNode/16032d09-3823-444e-a1ff-a67de4f350a8?operation=ADD&dryRun=true * 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.TYPE_PATH_PARAM) String type,
@PathParam(AccessPath.UUID_PATH_PARAM) String instanceId, @PathParam(AccessPath.UUID_PATH_PARAM) String instanceId,
@QueryParam(SharingPath.OPERATION_QUERY_PARAMETER) SharingOperation operation, @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)
throws ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, ResourceNotFoundException, ContextNotFoundException, ResourceRegistryException {
StringBuffer calledMethod = new StringBuffer(); StringBuffer calledMethod = new StringBuffer();
if(dryRun==null) { if(dryRun==null) {