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 8fb3b52..693db2f 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 @@ -173,7 +173,7 @@ public abstract class ElementManagement { checkJsonNode(); } - public void setoDatabaseDocument(ODatabaseDocument oDatabaseDocument) { + public void setODatabaseDocument(ODatabaseDocument oDatabaseDocument) { this.oDatabaseDocument = oDatabaseDocument; } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java index 1e00105..08a1edc 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java @@ -151,7 +151,7 @@ public class ElementManagementUtility { Utility.SHOULD_NOT_OCCUR_ERROR_MESSAGE); throw new ResourceRegistryException(error); } - entityManagement.setoDatabaseDocument(oDatabaseDocument); + entityManagement.setODatabaseDocument(oDatabaseDocument); entityManagement.setWorkingContext(workingContext); entityManagement.setElement(vertex); return entityManagement; @@ -185,7 +185,7 @@ public class ElementManagementUtility { } - relationManagement.setoDatabaseDocument(oDatabaseDocument); + relationManagement.setODatabaseDocument(oDatabaseDocument); relationManagement.setWorkingContext(workingContext); relationManagement.setElement(edge); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java index 6bccec9..75ba533 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/relations/RelationElementManagement.java @@ -193,7 +193,7 @@ public abstract class RelationElementManagement expectedInstances) throws SchemaViolationException, ResourceRegistryException; + + // public void contextSanityCheck(SecurityContext target, Map expectedInstances) throws SchemaViolationException, ResourceRegistryException; public AvailableInAnotherContextException getSpecificERAvailableInAnotherContextException(String message); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java index 6e44e20..d8a3ec7 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/ERManagementUtility.java @@ -38,35 +38,39 @@ public class ERManagementUtility { SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID); + // Map enforcedInstances = new HashMap<>(); + Map> instancesManagement = new HashMap<>(); - for(UUID uuid : expectedInstances.keySet()) { + Set uuids = expectedInstances.keySet(); + for(UUID uuid : uuids) { String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText(); ElementManagement elementManagement = ElementManagementUtility.getERManagement(type); elementManagement.setWorkingContext(adminSecurityContext); - elementManagement.setoDatabaseDocument(oDatabaseDocument); + elementManagement.setODatabaseDocument(oDatabaseDocument); elementManagement.setUUID(uuid); elementManagement.setElementType(type); ((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false); ((ERManagement) elementManagement).setDryRunContextSharing(dryRun); + // enforcedInstances.putAll(((ERManagement) elementManagement).internalAddToContext(targetSecurityContext)); ((ERManagement) elementManagement).internalAddToContext(targetSecurityContext); instancesManagement.put(uuid, elementManagement); } - for(UUID uuid : expectedInstances.keySet()) { + /* + for(UUID uuid : uuids) { ElementManagement elementManagement = instancesManagement.get(uuid); - // TODO - elementManagement.sanityCheck(); + ((ERManagement) elementManagement).contextSanityCheck(targetSecurityContext, expectedInstances); } + */ /* - Map expectedAdditionaInstances = new HashMap<>(); SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.ADD); - - if(operationValidator.isValidOperation(affectedInstances)) { + if(operationValidator.isValidOperation(enforcedInstances)) { oDatabaseDocument.commit(); } */ + oDatabaseDocument.activateOnCurrentThread(); oDatabaseDocument.commit(); staticLogger.info("{} successfully added to Context with UUID {} not following Propagation Constraints", instances, contextUUID); @@ -113,15 +117,18 @@ public class ERManagementUtility { SecurityContext targetSecurityContext = ContextUtility.getInstance().getSecurityContextByUUID(contextUUID); + //Map enforcedInstances = new HashMap<>(); + Map> instancesManagement = new HashMap<>(); for(UUID uuid : expectedInstances.keySet()) { String type = expectedInstances.get(uuid).get(Element.CLASS_PROPERTY).asText(); ElementManagement elementManagement = ElementManagementUtility.getERManagement(type); elementManagement.setWorkingContext(adminSecurityContext); - elementManagement.setoDatabaseDocument(oDatabaseDocument); + elementManagement.setODatabaseDocument(oDatabaseDocument); elementManagement.setUUID(uuid); ((ERManagement) elementManagement).setHonourPropagationConstraintsInContextSharing(false); ((ERManagement) elementManagement).setDryRunContextSharing(dryRun); + //enforcedInstances.putAll(((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext)); ((ERManagement) elementManagement).internalRemoveFromContext(targetSecurityContext); instancesManagement.put(uuid, elementManagement); } @@ -135,11 +142,12 @@ public class ERManagementUtility { /* SharingOperationValidator operationValidator = new SharingOperationValidator(expectedInstances, SharingOperation.REMOVE); - if(operationValidator.isValidOperation(affectedInstances)) { + if(operationValidator.isValidOperation(enforcedInstances)) { oDatabaseDocument.commit(); } */ + oDatabaseDocument.commit(); staticLogger.info("{} successfully removed from Context with UUID {} not following Propagation Constraints", instances, contextUUID); /* diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java index ea81945..cff239c 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java @@ -438,6 +438,8 @@ public abstract class EntityManagement Map affectedInstances = internalRemoveFromContext(targetSecurityContext); + // check here + oDatabaseDocument.commit(); logger.info("{} with UUID {} successfully removed from Context with UUID {}", typeName, uuid, contextUUID); 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 0b57c35..2619371 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 @@ -146,7 +146,7 @@ public class ResourceManagement extends EntityManagement for(JsonNode consistOfJsonNode : jsonNodeArray) { ConsistsOfManagement com = new ConsistsOfManagement(); com.setWorkingContext(getWorkingContext()); - com.setoDatabaseDocument(oDatabaseDocument); + com.setODatabaseDocument(oDatabaseDocument); com.setJsonNode(consistOfJsonNode); com.setSourceEntityManagement(this); com.internalCreate(); @@ -160,7 +160,7 @@ public class ResourceManagement extends EntityManagement for(JsonNode relationJsonNode : jsonNodeArray) { IsRelatedToManagement irtm = new IsRelatedToManagement(); irtm.setWorkingContext(getWorkingContext()); - irtm.setoDatabaseDocument(oDatabaseDocument); + irtm.setODatabaseDocument(oDatabaseDocument); irtm.setJsonNode(relationJsonNode); irtm.setSourceEntityManagement(this); irtm.internalCreate(); @@ -182,7 +182,7 @@ public class ResourceManagement extends EntityManagement for(JsonNode relationJsonNode : jsonNodeArray) { ConsistsOfManagement com = new ConsistsOfManagement(); com.setWorkingContext(getWorkingContext()); - com.setoDatabaseDocument(oDatabaseDocument); + com.setODatabaseDocument(oDatabaseDocument); com.setJsonNode(relationJsonNode); com.internalCreateOrUdate(); addToRelationManagement(com); @@ -195,7 +195,7 @@ public class ResourceManagement extends EntityManagement for(JsonNode relationJsonNode : jsonNodeArray) { IsRelatedToManagement irtm = new IsRelatedToManagement(); irtm.setWorkingContext(getWorkingContext()); - irtm.setoDatabaseDocument(oDatabaseDocument); + irtm.setODatabaseDocument(oDatabaseDocument); irtm.setJsonNode(relationJsonNode); irtm.internalUpdate(); addToRelationManagement(irtm); @@ -231,7 +231,7 @@ public class ResourceManagement extends EntityManagement } if(relationManagement != null) { relationManagement.setWorkingContext(getWorkingContext()); - relationManagement.setoDatabaseDocument(oDatabaseDocument); + relationManagement.setODatabaseDocument(oDatabaseDocument); relationManagement.setElement(edge); relationManagement.internalDelete(); } @@ -474,8 +474,16 @@ public class ResourceManagement extends EntityManagement 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(); @@ -575,5 +583,4 @@ public class ResourceManagement extends EntityManagement } } */ - } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java index 1c5ffc5..c645f5a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/relations/ConsistsOfManagement.java @@ -51,7 +51,7 @@ public class ConsistsOfManagement extends RelationManagement