Changed sanityCheck strategy
This commit is contained in:
parent
88baf3cb90
commit
005d9a2427
|
@ -132,7 +132,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
this.operation = operation;
|
||||
}
|
||||
|
||||
public void cleanCachedSerialization() {
|
||||
protected void cleanCachedSerialization() {
|
||||
this.self = null;
|
||||
this.complete = null;
|
||||
}
|
||||
|
@ -182,7 +182,6 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
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<El extends OElement, T extends Type> {
|
|||
// 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<PropertyDefinition> definedProperties = getAllProperties();
|
||||
|
||||
|
@ -1179,11 +1176,13 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
|||
return;
|
||||
}
|
||||
|
||||
Set<String> 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
|
||||
|
|
|
@ -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<Resource, ResourceType>
|
|||
*/
|
||||
@Override
|
||||
public void sanityCheck() throws SchemaViolationException, ResourceRegistryException {
|
||||
/*
|
||||
cleanCachedSerialization();
|
||||
JsonNode resourceInstance = createCompleteJsonNode();
|
||||
*/
|
||||
|
||||
TypesCache typesCache = TypesCache.getInstance();
|
||||
|
||||
Set<LinkedEntity> consistsOfFacetConstraints = getResourceTypeConstraint();
|
||||
Map<LinkedEntity, Integer> 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<OEdge> 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)) {
|
||||
|
|
Loading…
Reference in New Issue