Changed sanityCheck strategy

This commit is contained in:
Luca Frosini 2021-03-04 10:24:21 +01:00
parent 88baf3cb90
commit 005d9a2427
2 changed files with 22 additions and 13 deletions

View File

@ -132,7 +132,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
this.operation = operation; this.operation = operation;
} }
public void cleanCachedSerialization() { protected void cleanCachedSerialization() {
this.self = null; this.self = null;
this.complete = null; this.complete = null;
} }
@ -182,7 +182,6 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
try { try {
this.jsonNode = mapper.readTree(json); this.jsonNode = mapper.readTree(json);
cleanCachedSerialization();
} catch(IOException e) { } catch(IOException e) {
throw new ResourceRegistryException(e); throw new ResourceRegistryException(e);
} }
@ -1169,8 +1168,6 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
// mandatory and notnull constraints due to technical problem // mandatory and notnull constraints due to technical problem
// https://www.orientdb.com/docs/last/java/Graph-Schema-Property.html#using-constraints // https://www.orientdb.com/docs/last/java/Graph-Schema-Property.html#using-constraints
// Going to validate them here // Going to validate them here
cleanCachedSerialization();
JsonNode instances = createCompleteJsonNode();
Set<PropertyDefinition> definedProperties = getAllProperties(); Set<PropertyDefinition> definedProperties = getAllProperties();
@ -1179,11 +1176,13 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
return; return;
} }
Set<String> elementPropertyNames = getElement().getPropertyNames();
for(PropertyDefinition propertyDefinition : definedProperties) { for(PropertyDefinition propertyDefinition : definedProperties) {
String fieldName = propertyDefinition.getName(); String fieldName = propertyDefinition.getName();
if(propertyDefinition.isMandatory() && !instances.has(fieldName)) { if(propertyDefinition.isMandatory() && !elementPropertyNames.contains(fieldName)) {
if(propertyDefinition.isNotnull()) { if(propertyDefinition.isNotnull()) {
// If the field is mandatory but null value is accepted I add the // If the field is mandatory but null value is accepted I add the
// field as null value // field as null value

View File

@ -9,15 +9,12 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode; 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.AccessType;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; 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.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;
@ -393,19 +390,32 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
*/ */
@Override @Override
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException { public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
/*
cleanCachedSerialization(); cleanCachedSerialization();
JsonNode resourceInstance = createCompleteJsonNode(); JsonNode resourceInstance = createCompleteJsonNode();
*/
TypesCache typesCache = TypesCache.getInstance(); TypesCache typesCache = TypesCache.getInstance();
Set<LinkedEntity> consistsOfFacetConstraints = getResourceTypeConstraint(); Set<LinkedEntity> consistsOfFacetConstraints = getResourceTypeConstraint();
Map<LinkedEntity, Integer> satisfiedConsistsOfFacet = new HashMap<>(); Map<LinkedEntity, Integer> satisfiedConsistsOfFacet = new HashMap<>();
ArrayNode consistsOfArrayNode = (ArrayNode) resourceInstance.get(Resource.CONSISTS_OF_PROPERTY);
for(JsonNode consistsOfJsonNode : consistsOfArrayNode) { Iterable<OEdge> edges = getElement().getEdges(ODirection.OUT);
String consistsOfType = consistsOfJsonNode.get(Element.CLASS_PROPERTY).asText();
JsonNode facetJsonNode = consistsOfJsonNode.get(Relation.TARGET_PROPERTY); //ArrayNode consistsOfArrayNode = (ArrayNode) resourceInstance.get(Resource.CONSISTS_OF_PROPERTY);
String facetType = facetJsonNode.get(Element.CLASS_PROPERTY).asText(); //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) { for(LinkedEntity constraint : consistsOfFacetConstraints) {
if(constraintSatisfied(typesCache, constraint, consistsOfType, facetType)) { if(constraintSatisfied(typesCache, constraint, consistsOfType, facetType)) {