From 6899669ccf4a49055e118211dc54efd1ef63d56a Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Thu, 23 Nov 2017 15:37:53 +0000 Subject: [PATCH] Refs #10238: Refactor Context Port Type Task-Url: https://support.d4science.org/issues/10238 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@158789 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../context/ContextManagement.java | 56 ++++++++++++------- .../context/SecurityContext.java | 7 +-- 2 files changed, 36 insertions(+), 27 deletions(-) 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());