diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java index e8fac87..c510bed 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/entities/ContextManagement.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.UUID; import org.gcube.com.fasterxml.jackson.core.JsonProcessingException; @@ -26,6 +27,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.relations.IsParentOfManagement; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; @@ -445,4 +447,10 @@ public class ContextManagement extends EntityElementManagement { return readFromServer(); } } + + @Override + public void sanityCheck(Map expectedInstances) + throws SchemaViolationException, ResourceRegistryException { + // Nothing to do + } } 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 94bdb81..c5e193c 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 @@ -1,5 +1,8 @@ package org.gcube.informationsystem.resourceregistry.contexts.relations; +import java.util.Map; +import java.util.UUID; + import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.informationsystem.base.reference.AccessType; @@ -9,6 +12,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.isparentof.IsParentOfNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; @@ -103,5 +107,11 @@ public class IsParentOfManagement extends RelationElementManagement expectedInstances) + throws SchemaViolationException, ResourceRegistryException { + // Nothing to do + } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java index 20863f4..863a767 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java @@ -34,6 +34,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.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.AdminSecurityContext; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; @@ -447,6 +448,8 @@ public abstract class ElementManagement { public abstract String reallyGetAll(boolean polymorphic) throws ResourceRegistryException; + public abstract void sanityCheck(Map expectedInstances) throws SchemaViolationException, ResourceRegistryException; + public String all(boolean polymorphic) throws ResourceRegistryException { ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal(); try { @@ -516,6 +519,8 @@ public abstract class ElementManagement { setReload(true); } + sanityCheck(null); + // TODO Notify to subscriptionNotification return serializeAsJsonNode().toString(); @@ -553,6 +558,8 @@ public abstract class ElementManagement { oDatabaseDocument.commit(); + sanityCheck(null); + // TODO Notify to subscriptionNotification return serializeAsJsonNode().toString(); @@ -618,6 +625,8 @@ public abstract class ElementManagement { setReload(true); + sanityCheck(null); + // TODO Notify to subscriptionNotification return serializeAsJsonNode().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 f52e5b7..3c36a7e 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 @@ -1,10 +1,11 @@ package org.gcube.informationsystem.resourceregistry.instances.model.entities; -import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import org.gcube.com.fasterxml.jackson.databind.JsonNode; @@ -25,6 +26,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.SchemaException; 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; @@ -32,9 +34,9 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ElementManage import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.RelationManagement; -import org.gcube.informationsystem.resourceregistry.types.entities.ResourceTypeDefinitionManagement; +import org.gcube.informationsystem.resourceregistry.types.CachedType; +import org.gcube.informationsystem.resourceregistry.types.TypesCache; import org.gcube.informationsystem.resourceregistry.utils.Utility; -import org.gcube.informationsystem.types.TypeMapper; import org.gcube.informationsystem.types.reference.entities.ResourceType; import org.gcube.informationsystem.types.reference.properties.LinkedEntity; @@ -309,76 +311,194 @@ public class ResourceManagement extends EntityManagement { } } - @Override - 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. - * - * We need to load the Resource definition and validate it. - * This task is not very easy because we cannot check just the type but - * me must take in account that a specialisation instance is valid. - * - */ - read(); + private String facetMustBePresentErrorMessage(String consistsOfType, UUID consistsOfUUID, String facetType, UUID facetUUID) { + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("To avoid to have an incosistent graph, add to context no follows cannot add a "); + stringBuffer.append(ConsistsOf.NAME); + stringBuffer.append(" relation (i.e. "); + stringBuffer.append(consistsOfType); + stringBuffer.append(" with UUID "); + stringBuffer.append(consistsOfUUID.toString()); + stringBuffer.append(") without indicating the target "); + stringBuffer.append(Facet.NAME); + stringBuffer.append(" (i.e. "); + stringBuffer.append(facetType); + stringBuffer.append(" with UUID "); + stringBuffer.append(facetUUID.toString()); + stringBuffer.append(")."); + return stringBuffer.toString(); + } + + + protected Set getResourceTypeConstraint() throws SchemaException, ResourceRegistryException{ + Set constraints = new HashSet<>(); + TypesCache typesCache = TypesCache.getInstance(); + CachedType cachedType = typesCache.getType(typeName); + ResourceType resourceType = (ResourceType) cachedType.getType(); - ResourceTypeDefinitionManagement resourceTypeDefinitionManagement = new ResourceTypeDefinitionManagement(); - resourceTypeDefinitionManagement.setName(typeName); - String stringType = resourceTypeDefinitionManagement.read().toString(); - ResourceType resourceType = null; - try { - resourceType = (ResourceType) TypeMapper.deserializeTypeDefinition(stringType); - }catch (Exception e) { - throw new ResourceRegistryException(e); - } - - // TODO Create something like SchemaDefinitionNotRespected o ConstaintNotRespected Exception - - List constraint = new ArrayList<>(); List linkedEntities = resourceType.getFacets(); for(LinkedEntity linkedEntity : linkedEntities) { if(linkedEntity.getMin()>0 || linkedEntity.getMax()>0) { - constraint.add(linkedEntity); + constraints.add(linkedEntity); } } - boolean found = false; - ArrayNode consistsOfArrayNode = (ArrayNode) jsonNode.get(Resource.CONSISTS_OF_PROPERTY); + Set cachedSuperTypes = new HashSet<>(); + List superTypes = cachedType.getSuperTypes(); + for(String superType : superTypes) { + CachedType cachedSuperType = typesCache.getType(superType); + cachedSuperTypes.add(cachedSuperType); + + ResourceType resourceSuperType = (ResourceType) cachedSuperType.getType(); + List linkedEnt = resourceSuperType.getFacets(); + for(LinkedEntity linkedEntity : linkedEnt) { + if(linkedEntity.getMin()>0 || linkedEntity.getMax()>0) { + constraints.add(linkedEntity); + } + } + } + + return constraints; + } + + private String constraintNotSatisfiedErrorMessage(LinkedEntity linkedEntity, Integer occurrence) { + StringBuffer stringBuffer = new StringBuffer(); + stringBuffer.append("A "); + stringBuffer.append(typeName); + stringBuffer.append(" must be described by "); + stringBuffer.append(linkedEntity.getRelation()); + stringBuffer.append(" -> "); + stringBuffer.append(linkedEntity.getTarget()); + stringBuffer.append(" with the following constraint: max:"); + stringBuffer.append(linkedEntity.getMax()); + stringBuffer.append(", min:"); + stringBuffer.append(linkedEntity.getMin()); + stringBuffer.append(". Found "); + stringBuffer.append(occurrence); + stringBuffer.append(" instances"); + return stringBuffer.toString(); + } + + protected boolean typeSatified(TypesCache typesCache, String requiredType, String effectiveType) { + if(requiredType.compareTo(effectiveType)==0) { + return true; + } + + CachedType cachedType = typesCache.getType(requiredType); + if(cachedType.getSpecilisationTypes().contains(effectiveType)) { + return true; + } + + return false; + } + + protected boolean constraintSatisfied(TypesCache typesCache, LinkedEntity constraint, String consistsOfType, String facetType) { + String requiredSourceResourceType = constraint.getSource(); + if(!typeSatified(typesCache, requiredSourceResourceType, typeName)) { + return false; + } + + String requiredConsistsOfType = constraint.getRelation(); + if(!typeSatified(typesCache, requiredConsistsOfType, consistsOfType)) { + return false; + } + + + String requiredTargetFacetType = constraint.getTarget(); + if(!typeSatified(typesCache, requiredTargetFacetType, facetType)) { + return false; + } + + return true; + } + + @Override + public void sanityCheck(Map expectedInstances) throws SchemaViolationException, ResourceRegistryException { + JsonNode resourceInstance = serializeAsJsonNode().deepCopy(); + + TypesCache typesCache = TypesCache.getInstance(); + + Set consistsOfFacetConstraints = getResourceTypeConstraint(); + Map satisfiedConsistsOfFacet = new HashMap<>(); + + boolean oneFacetAvailable = false; + + ArrayNode consistsOfArrayNode = (ArrayNode) resourceInstance.get(Resource.CONSISTS_OF_PROPERTY); for(JsonNode consistsOfJsonNode : consistsOfArrayNode) { + + String consistsOfType = consistsOfJsonNode.get(Element.CLASS_PROPERTY).asText(); String consistsOfUUIDString = consistsOfJsonNode.get(IdentifiableElement.HEADER_PROPERTY).get(Header.UUID_PROPERTY).asText(); UUID consistsOfUUID = UUID.fromString(consistsOfUUIDString); - if(expectedInstances.containsKey(consistsOfUUID)) { - // we need to check that also the facets is present - JsonNode facetJsonNode = consistsOfJsonNode.get(Relation.TARGET_PROPERTY); - String facetUUIDString = facetJsonNode.get(IdentifiableElement.HEADER_PROPERTY).get(Header.UUID_PROPERTY).asText(); - UUID facetUUID = UUID.fromString(facetUUIDString); - if(!expectedInstances.containsKey(facetUUID)) { - StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append("To avoid to have an incosistent graph, add to context no follows cannot add a "); - stringBuffer.append(ConsistsOf.NAME); - stringBuffer.append(" relation (i.e. "); - stringBuffer.append(consistsOfJsonNode.get(Element.CLASS_PROPERTY).asText()); - stringBuffer.append(" with UUID "); - stringBuffer.append(consistsOfUUIDString); - stringBuffer.append(") without indicating the target "); - stringBuffer.append(Facet.NAME); - stringBuffer.append(" (i.e. "); - stringBuffer.append(facetJsonNode.get(Element.CLASS_PROPERTY).asText()); - stringBuffer.append(" with UUID "); - stringBuffer.append(facetUUIDString); - stringBuffer.append(")."); - logger.debug(stringBuffer.toString()); - throw new ResourceRegistryException(stringBuffer.toString()); + + JsonNode facetJsonNode = consistsOfJsonNode.get(Relation.TARGET_PROPERTY); + String facetType = facetJsonNode.get(Element.CLASS_PROPERTY).asText(); + String facetUUIDString = facetJsonNode.get(IdentifiableElement.HEADER_PROPERTY).get(Header.UUID_PROPERTY).asText(); + UUID facetUUID = UUID.fromString(facetUUIDString); + + if(expectedInstances!=null) { + // Integrity check for add/remove to/from Context + // If the ConsistsOf relation is present also the target facet + // must be in the expected instances. + + if(expectedInstances.containsKey(consistsOfUUID)) { + // we need to check that also the facets is present + + if(!expectedInstances.containsKey(facetUUID)) { + String error = facetMustBePresentErrorMessage(consistsOfType, consistsOfUUID, facetType, facetUUID); + logger.debug(error); + throw new SchemaViolationException(error); + } + + oneFacetAvailable = true; } - found = true; - break; } + + for(LinkedEntity constraint : consistsOfFacetConstraints) { + // Check min and max + + if(constraintSatisfied(typesCache, constraint, consistsOfType, facetType)) { + Integer integer = satisfiedConsistsOfFacet.get(constraint); + if(integer==null) { + satisfiedConsistsOfFacet.put(constraint, 1); + }else { + satisfiedConsistsOfFacet.put(constraint, ++integer); + } + } + + } + + } - // TODO check Resource definition for mandatory ConsistsOf/Facet - if(!found) { + consistsOfFacetConstraints.removeAll(satisfiedConsistsOfFacet.keySet()); + + if(!consistsOfFacetConstraints.isEmpty()) { + String message = constraintNotSatisfiedErrorMessage(consistsOfFacetConstraints.iterator().next(), 0); + throw new SchemaViolationException(message); + } + + + for(LinkedEntity linkedEntity : satisfiedConsistsOfFacet.keySet()) { + + Integer satisfiedTimes = satisfiedConsistsOfFacet.get(linkedEntity); + + if(satisfiedTimes0 && satisfiedTimes>max) { + String message = constraintNotSatisfiedErrorMessage(linkedEntity, satisfiedTimes); + throw new SchemaViolationException(message); + } + + } + + + if(expectedInstances!=null && !oneFacetAvailable) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("To avoid to have an incosistent graph, add to context no follows cannot add a "); stringBuffer.append(Resource.NAME); @@ -389,7 +509,7 @@ public class ResourceManagement extends EntityManagement { stringBuffer.append(") without adding at least a "); stringBuffer.append(Facet.NAME); logger.debug(stringBuffer.toString()); - throw new ResourceRegistryException(stringBuffer.toString()); + throw new SchemaViolationException(stringBuffer.toString()); } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/CachedType.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/CachedType.java index 3f52636..9ad3dcc 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/CachedType.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/CachedType.java @@ -1,5 +1,9 @@ package org.gcube.informationsystem.resourceregistry.types; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; import java.util.Set; import org.gcube.informationsystem.base.reference.AccessType; @@ -9,7 +13,9 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.Schema import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.security.AdminSecurityContext; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; +import org.gcube.informationsystem.resourceregistry.dbinitialization.DatabaseEnvironment; import org.gcube.informationsystem.types.reference.Type; +import org.gcube.informationsystem.types.reference.properties.LinkedEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,6 +23,7 @@ import com.orientechnologies.orient.core.db.document.ODatabaseDocument; import com.orientechnologies.orient.core.metadata.OMetadata; import com.orientechnologies.orient.core.metadata.schema.OClass; import com.orientechnologies.orient.core.metadata.schema.OSchema; +import com.tinkerpop.blueprints.util.StringFactory; /** * @author Luca Frosini (ISTI - CNR) @@ -25,6 +32,16 @@ public class CachedType { private static Logger logger = LoggerFactory.getLogger(CachedType.class); + private static final Set superClassesToBeExcluded; + + static { + superClassesToBeExcluded = AccessType.names(); + superClassesToBeExcluded.remove(AccessType.RESOURCE.getName()); + superClassesToBeExcluded.remove(AccessType.FACET.getName()); + superClassesToBeExcluded.remove(AccessType.CONSISTS_OF.getName()); + superClassesToBeExcluded.remove(AccessType.IS_RELATED_TO.getName()); + } + protected final String typeName; protected OClass oClass; @@ -32,9 +49,12 @@ public class CachedType { protected AccessType accessType; protected Type type; - protected Set superTypes; + protected List superTypes; protected Set specilisationTypes; + /* Valid only for resource types */ + protected Set constraints; + public CachedType(String typeName) { this.typeName = typeName; @@ -77,13 +97,23 @@ public class CachedType { } - public synchronized OClass getOClass() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + private OClass internalGetOClass() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { if(oClass==null) { oClass = retrieveOClass(); } return oClass; } + private synchronized void setOClass(OClass oClass) throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + if(this.oClass==null) { + this.oClass = oClass; + } + } + + public synchronized OClass getOClass() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + return internalGetOClass(); + } + private AccessType getAccessTypeFromOClass(OClass oClass) throws ResourceRegistryException { AccessType[] accessTypes = AccessType.values(); for(int i=accessTypes.length-1; i>=0; i--) { @@ -95,28 +125,84 @@ public class CachedType { throw new ResourceRegistryException(typeName + " is not a base type"); } - public synchronized AccessType getAccessType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + public AccessType internalGetAccessType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { if(accessType==null) { if(type!=null) { accessType = type.getAccessType(); }else { - accessType = getAccessTypeFromOClass(getOClass()); + accessType = getAccessTypeFromOClass(internalGetOClass()); } } return accessType; } - public Type getType() { + public synchronized AccessType getAccessType() throws SchemaNotFoundException, SchemaException, ResourceRegistryException { + return internalGetAccessType(); + } + + protected List getSuperclasses(Collection superClassesToBeExcluded) throws SchemaException, ResourceRegistryException { + TypesCache typesCache = TypesCache.getInstance(); + + List superClasses = new ArrayList<>(); + List allSuperClasses = internalGetOClass().getSuperClasses(); + while(allSuperClasses.size()>0) { + List toBeAnalysed = new ArrayList<>(allSuperClasses); + allSuperClasses = new ArrayList<>(); + for(OClass oSuperClass : toBeAnalysed) { + String name = oSuperClass.getName(); + CachedType cachedType = typesCache.getType(name); + cachedType.setOClass(oSuperClass); + if(name.compareTo(StringFactory.V.toUpperCase()) == 0 || name.compareTo(StringFactory.E.toUpperCase()) == 0 + || name.compareTo(DatabaseEnvironment.O_RESTRICTED_CLASS) == 0) { + continue; + } + + if(superClassesToBeExcluded.contains(name)) { + continue; + } + superClasses.add(superClasses.size(), name); + allSuperClasses.addAll(oSuperClass.getSuperClasses()); + } + } + return superClasses; + } + + public synchronized Type getType() { + if(type==null) { + + } return type; } - public synchronized Set getSuperTypes() { + public synchronized List getSuperTypes() throws SchemaException, ResourceRegistryException { + if(superTypes==null) { + superTypes = getSuperclasses(superClassesToBeExcluded); + } return superTypes; } public synchronized Set getSpecilisationTypes() { + if(specilisationTypes==null) { + + } return specilisationTypes; } + @Override + public int hashCode() { + return Objects.hash(typeName); + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CachedType other = (CachedType) obj; + return Objects.equals(typeName, other.typeName); + } + } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/EntityTypeDefinitionManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/EntityTypeDefinitionManagement.java index 8406f63..98ae3c7 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/EntityTypeDefinitionManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/EntityTypeDefinitionManagement.java @@ -1,6 +1,8 @@ package org.gcube.informationsystem.resourceregistry.types.entities; import java.util.HashMap; +import java.util.Map; +import java.util.UUID; import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.informationsystem.base.reference.AccessType; @@ -10,6 +12,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.EntityAlreadyPresentException; 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; @@ -190,4 +193,10 @@ public abstract class EntityTypeDefinitionManagement exten return new SchemaAlreadyPresentException(message); } + @Override + public void sanityCheck(Map expectedInstances) + throws SchemaViolationException, ResourceRegistryException { + // Nothing to do + } + } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/ResourceTypeDefinitionManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/ResourceTypeDefinitionManagement.java index 89bbf99..36589d4 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/ResourceTypeDefinitionManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/entities/ResourceTypeDefinitionManagement.java @@ -1,5 +1,11 @@ package org.gcube.informationsystem.resourceregistry.types.entities; +import java.util.Map; +import java.util.UUID; + +import org.gcube.com.fasterxml.jackson.databind.JsonNode; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.types.reference.entities.ResourceType; /** @@ -11,4 +17,11 @@ public class ResourceTypeDefinitionManagement extends EntityTypeDefinitionManage super(ResourceType.class); } + @Override + public void sanityCheck(Map expectedInstances) + throws SchemaViolationException, ResourceRegistryException { + // TODO + // We should check that a constraint defined here is not in contrast with the constraint of supertypes + } + } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java index d133076..0455bb1 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/types/properties/PropertyTypeDefinitionManagement.java @@ -1,6 +1,8 @@ package org.gcube.informationsystem.resourceregistry.types.properties; import java.util.HashMap; +import java.util.Map; +import java.util.UUID; import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.informationsystem.base.reference.AccessType; @@ -9,6 +11,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundExcep import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; 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; @@ -191,4 +194,9 @@ public class PropertyTypeDefinitionManagement extends ElementManagement expectedInstances) + throws SchemaViolationException, ResourceRegistryException { + // Nothing to do + } } 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 4c60621..51d9175 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 @@ -1,7 +1,10 @@ package org.gcube.informationsystem.resourceregistry.types.relations; import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.informationsystem.base.reference.AccessType; import org.gcube.informationsystem.model.reference.relations.Relation; import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException; @@ -10,6 +13,7 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis 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; @@ -209,4 +213,10 @@ public abstract class RelationTypeDefinitionManagement expectedInstances) + throws SchemaViolationException, ResourceRegistryException { + // Nothing to do + } + }