From 647e77282783dafc0d8589053b869e43da70cfc3 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 2 Mar 2021 10:59:44 +0100 Subject: [PATCH] Removed old commented code of sanityCheck --- .../model/entities/ResourceManagement.java | 130 +----------------- 1 file changed, 1 insertion(+), 129 deletions(-) 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 cc83df3..3f63d14 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 @@ -440,133 +440,5 @@ public class ResourceManagement extends EntityManagement } } - - /* - - 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 expectedInstances) throws SchemaViolationException, ResourceRegistryException { - - } - */ - - /* - public void sanityCheck(Map expectedInstances) throws SchemaViolationException, ResourceRegistryException { - JsonNode resourceInstance = createCompleteJsonNode(); - - 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); - - 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(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); - 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()); - } - } - */ + }