Removed old commented code of sanityCheck

This commit is contained in:
Luca Frosini 2021-03-02 10:59:44 +01:00
parent 94388d9a36
commit 647e772827
1 changed files with 1 additions and 129 deletions

View File

@ -440,133 +440,5 @@ public class ResourceManagement extends EntityManagement<Resource, ResourceType>
}
}
/*
private String facetMustBePresentErrorMessage(String consistsOfType, UUID consistsOfUUID, String facetType, UUID facetUUID) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("To avoid to have an inconsistent 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();
}
*/
/*
@Override
public void contextSanityCheck(SecurityContext targetSecurityContext, Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
}
*/
/*
public void sanityCheck(Map<UUID, JsonNode> expectedInstances) throws SchemaViolationException, ResourceRegistryException {
JsonNode resourceInstance = createCompleteJsonNode();
TypesCache typesCache = TypesCache.getInstance();
Set<LinkedEntity> consistsOfFacetConstraints = getResourceTypeConstraint();
Map<LinkedEntity, Integer> 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);
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;
}
}
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);
}
}
}
}
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(satisfiedTimes<linkedEntity.getMin()) {
String message = constraintNotSatisfiedErrorMessage(linkedEntity, satisfiedTimes);
throw new SchemaViolationException(message);
}
Integer max = linkedEntity.getMax();
if((max!=null && max>0) && 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);
stringBuffer.append(" (i.e. ");
stringBuffer.append(typeName);
stringBuffer.append(" with UUID ");
stringBuffer.append(uuid.toString());
stringBuffer.append(") without adding at least a ");
stringBuffer.append(Facet.NAME);
logger.debug(stringBuffer.toString());
throw new SchemaViolationException(stringBuffer.toString());
}
}
*/
}