diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java index 8b42713..441c68a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagement.java @@ -190,30 +190,39 @@ public class ContextManagement extends EntityManagement { @Override protected Vertex reallyCreate() throws ERAlreadyPresentException, ResourceRegistryException { - JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY); - - if (isParentOfJsonNode!=null && !(isParentOfJsonNode instanceof NullNode)) { + try { + JsonNode isParentOfJsonNode = jsonNode.get(Context.PARENT_PROPERTY); - JsonNode parentJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY); - ContextManagement parentContext = new ContextManagement(orientGraph); - parentContext.setJSON(parentJsonNode); + if (isParentOfJsonNode!=null && !(isParentOfJsonNode instanceof NullNode)) { + + JsonNode parentJsonNode = isParentOfJsonNode.get(Relation.SOURCE_PROPERTY); + ContextManagement parentContext = new ContextManagement(orientGraph); + parentContext.setJSON(parentJsonNode); + + checkContext(parentContext); + createVertex(); + + SecurityContext.createSecurityContext(orientGraph, uuid); + + IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph); + isParentOfManagement.setJSON(isParentOfJsonNode); + isParentOfManagement.setSourceEntityManagement(parentContext); + isParentOfManagement.setTargetEntityManagement(this); + + isParentOfManagement.internalCreate(); + + }else { + checkContext(null); + createVertex(); + } - checkContext(parentContext); - createVertex(); - - IsParentOfManagement isParentOfManagement = new IsParentOfManagement(orientGraph); - isParentOfManagement.setJSON(isParentOfJsonNode); - isParentOfManagement.setSourceEntityManagement(parentContext); - isParentOfManagement.setTargetEntityManagement(this); - - isParentOfManagement.internalCreate(); - - }else { - checkContext(null); - createVertex(); + return getElement(); + }catch (Exception e) { + if(uuid!=null) { + SecurityContext.deleteSecurityContext(orientGraph, uuid); + } + throw e; } - - return getElement(); } @Override @@ -291,6 +300,8 @@ public class ContextManagement extends EntityManagement { element = (Vertex) ERManagement.updateProperties(oClass, getElement(), jsonNode, ignoreKeys, ignoreStartWithKeys); + ContextUtility.invalidContextUUIDCache(uuid); + return element; } @@ -337,6 +348,9 @@ public class ContextManagement extends EntityManagement { element.remove(); + ContextUtility.invalidContextUUIDCache(uuid); + SecurityContext.deleteSecurityContext(orientGraph, uuid); + return true; } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/SecurityContext.java b/src/main/java/org/gcube/informationsystem/resourceregistry/context/SecurityContext.java index 6d85da3..f68d1af 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/SecurityContext.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/context/SecurityContext.java @@ -150,7 +150,6 @@ public class SecurityContext { readerUser.save(); logger.trace("{} created", readerUser); - oDatabaseDocumentTx.commit(); logger.trace( "Security Context (roles and users) with UUID {} successfully created", @@ -158,7 +157,7 @@ public class SecurityContext { } public static void deleteSecurityContext(OrientGraph orientGraph, - UUID context, boolean commit) { + UUID context) { logger.trace( "Going to remove Security Context (roles and users) with UUID {}", @@ -206,10 +205,6 @@ public class SecurityContext { logger.error("{} was not dropped successfully", role); } - if(commit){ - oDatabaseDocumentTx.commit(); - } - logger.trace( "Security Context (roles and users) with UUID {} successfully removed", context.toString());