diff --git a/CHANGELOG.md b/CHANGELOG.md index 80bdd03..86746c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v4.1.0-SNAPSHOT] -- Prepared Query has been fixed to properly consider polymorphic parameter and provided constraint [#20298] -- Added type update but the API is not exposed via REST [#20316] -- Generalised the definition of the type of a property [#20516] -- Add/Remove to/from Context return the list of affected instances and not just success or failure code [#20555] -- Added the possibility to have a dry run Add/Remove to/from Context [#20530] +- Relation source-target instace types are validated against Relation schema [#7355] +- The instances are validated with the defined schema [#18216] +- Added Types Cache [#18496] +- Superclasses in instances are ordered and does not include internal basic types [#20517] - Redesigned Sharing REST collection [#20530][#20555] - +- Added the possibility to have a dry run Add/Remove to/from Context [#20530] +- Add/Remove to/from Context return the list of affected instances and not just success or failure code [#20555] +- Generalised the definition of the type of a property [#20516] +- Added type update but the API is not exposed via REST [#20316] +- Prepared Query has been fixed to properly consider polymorphic parameter and provided constraint [#20298] ## [v4.0.0] diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java index b6ee292..277a6fd 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/relations/IsParentOfManagement.java @@ -5,6 +5,7 @@ import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.model.reference.relations.Relation; +import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfAlreadyPresentException; @@ -114,4 +115,10 @@ public class IsParentOfManagement extends RelationElementManagement { return stringBuffer.toString(); } + protected boolean typeSatified(TypesCache typesCache, String requiredType, String effectiveType) throws SchemaException, ResourceRegistryException { + if(requiredType.compareTo(effectiveType)==0) { + return true; + } + + @SuppressWarnings("unchecked") + CachedType cachedType = (CachedType) typesCache.getCachedType(requiredType); + if(cachedType.getSubTypes().contains(effectiveType)) { + return true; + } + + return false; + } + /* * Get not only the properties defined in the type but also the properties * defined in the super types diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java index 75ba533..66ef2f8 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java @@ -7,9 +7,12 @@ import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.base.reference.entities.EntityElement; import org.gcube.informationsystem.model.reference.relations.Relation; +import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement; @@ -117,6 +120,8 @@ public abstract class RelationElementManagement {}", typeName, source.toString(), target.toString()); 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 2619371..553d7d1 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 @@ -366,20 +366,6 @@ public class ResourceManagement extends EntityManagement return stringBuffer.toString(); } - protected boolean typeSatified(TypesCache typesCache, String requiredType, String effectiveType) throws SchemaException, ResourceRegistryException { - if(requiredType.compareTo(effectiveType)==0) { - return true; - } - - @SuppressWarnings("unchecked") - CachedType cachedType = (CachedType) typesCache.getCachedType(requiredType); - if(cachedType.getSubTypes().contains(effectiveType)) { - return true; - } - - return false; - } - protected boolean constraintSatisfied(TypesCache typesCache, LinkedEntity constraint, String consistsOfType, String facetType) throws SchemaException, ResourceRegistryException { String requiredSourceResourceType = constraint.getSource(); if(!typeSatified(typesCache, requiredSourceResourceType, typeName)) { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java index 74cae79..e916bfc 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/RelationManagement.java @@ -11,6 +11,7 @@ import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.informationsystem.base.reference.AccessType; +import org.gcube.informationsystem.base.reference.relations.RelationElement; import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.model.reference.entities.Entity; import org.gcube.informationsystem.model.reference.entities.Resource; @@ -23,6 +24,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException; +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; @@ -33,11 +35,13 @@ import org.gcube.informationsystem.resourceregistry.instances.model.ERManagement import org.gcube.informationsystem.resourceregistry.instances.model.entities.EntityManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; +import org.gcube.informationsystem.resourceregistry.types.TypesCache; import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility; import org.gcube.informationsystem.resourceregistry.utils.PropagationConstraintOrient; import org.gcube.informationsystem.resourceregistry.utils.Utility; import org.gcube.informationsystem.types.reference.entities.EntityType; import org.gcube.informationsystem.types.reference.entities.ResourceType; +import org.gcube.informationsystem.types.reference.relations.RelationType; import org.gcube.informationsystem.utils.ElementMapper; import com.orientechnologies.orient.core.db.document.ODatabaseDocument; @@ -165,12 +169,10 @@ public abstract class RelationManagement relationType = getCachedType().getType(); + + ResourceType resourceType = relationType.getSource(); + TET tet = relationType.getTarget(); + + String requiredSourceType = resourceType.getName(); + String requiredTargetType = tet.getName(); + + TypesCache typesCache = TypesCache.getInstance(); + + if(!typeSatified(typesCache, requiredSourceType, sourceType)) { + String message = getEntityTypeNotValidErrroMessage(RelationElement.SOURCE_PROPERTY, requiredSourceType, sourceType); + throw new SchemaViolationException(message); + } + + if(!typeSatified(typesCache, requiredTargetType, targetType)) { + String message = getEntityTypeNotValidErrroMessage(RelationElement.TARGET_PROPERTY, requiredTargetType, targetType); + throw new SchemaViolationException(message); + } + } + @Override protected OEdge reallyUpdate() throws ResourceRegistryException { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/relations/RelationTypeDefinitionManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/relations/RelationTypeDefinitionManagement.java index 76df687..27e3517 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/relations/RelationTypeDefinitionManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/relations/RelationTypeDefinitionManagement.java @@ -5,11 +5,13 @@ import java.util.HashMap; import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; +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.dbinitialization.DatabaseEnvironment; @@ -208,5 +210,11 @@ public abstract class RelationTypeDefinitionManagement