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 07f8bb6..d1dcf1b 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 @@ -132,7 +132,7 @@ public abstract class ElementManagement { this.operation = operation; } - public void cleanCachedSerialization() { + protected void cleanCachedSerialization() { this.self = null; this.complete = null; } @@ -182,7 +182,6 @@ public abstract class ElementManagement { ObjectMapper mapper = new ObjectMapper(); try { this.jsonNode = mapper.readTree(json); - cleanCachedSerialization(); } catch(IOException e) { throw new ResourceRegistryException(e); } @@ -1169,8 +1168,6 @@ public abstract class ElementManagement { // mandatory and notnull constraints due to technical problem // https://www.orientdb.com/docs/last/java/Graph-Schema-Property.html#using-constraints // Going to validate them here - cleanCachedSerialization(); - JsonNode instances = createCompleteJsonNode(); Set definedProperties = getAllProperties(); @@ -1179,11 +1176,13 @@ public abstract class ElementManagement { return; } + Set elementPropertyNames = getElement().getPropertyNames(); + for(PropertyDefinition propertyDefinition : definedProperties) { String fieldName = propertyDefinition.getName(); - if(propertyDefinition.isMandatory() && !instances.has(fieldName)) { + if(propertyDefinition.isMandatory() && !elementPropertyNames.contains(fieldName)) { if(propertyDefinition.isNotnull()) { // If the field is mandatory but null value is accepted I add the // field as null value 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 101a05b..26a0921 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 @@ -9,15 +9,12 @@ import java.util.Set; import java.util.UUID; import org.gcube.com.fasterxml.jackson.databind.JsonNode; -import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; import org.gcube.informationsystem.base.reference.AccessType; -import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; -import org.gcube.informationsystem.model.reference.relations.Relation; 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; @@ -393,19 +390,32 @@ public class ResourceManagement extends EntityManagement */ @Override public void sanityCheck() throws SchemaViolationException, ResourceRegistryException { + /* cleanCachedSerialization(); JsonNode resourceInstance = createCompleteJsonNode(); + */ TypesCache typesCache = TypesCache.getInstance(); Set consistsOfFacetConstraints = getResourceTypeConstraint(); Map satisfiedConsistsOfFacet = new HashMap<>(); - ArrayNode consistsOfArrayNode = (ArrayNode) resourceInstance.get(Resource.CONSISTS_OF_PROPERTY); - for(JsonNode consistsOfJsonNode : consistsOfArrayNode) { - String consistsOfType = consistsOfJsonNode.get(Element.CLASS_PROPERTY).asText(); - JsonNode facetJsonNode = consistsOfJsonNode.get(Relation.TARGET_PROPERTY); - String facetType = facetJsonNode.get(Element.CLASS_PROPERTY).asText(); + + Iterable edges = getElement().getEdges(ODirection.OUT); + + //ArrayNode consistsOfArrayNode = (ArrayNode) resourceInstance.get(Resource.CONSISTS_OF_PROPERTY); + //for(JsonNode consistsOfJsonNode : consistsOfArrayNode) { + for(OEdge edge : edges) { + RelationManagement relationManagement = getRelationManagement(edge); + if(!(relationManagement instanceof ConsistsOfManagement)) { + continue; + } + String consistsOfType = relationManagement.getTypeName(); + String facetType = relationManagement.getTargetEntityManagement().getTypeName(); + + // String consistsOfType = consistsOfJsonNode.get(Element.CLASS_PROPERTY).asText(); + // JsonNode facetJsonNode = consistsOfJsonNode.get(Relation.TARGET_PROPERTY); + // String facetType = facetJsonNode.get(Element.CLASS_PROPERTY).asText(); for(LinkedEntity constraint : consistsOfFacetConstraints) { if(constraintSatisfied(typesCache, constraint, consistsOfType, facetType)) {