From ed6f906c7e4727d516359fae86879099a3ae3efd Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Thu, 4 May 2017 15:43:36 +0000 Subject: [PATCH] Added Context UUID cache git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@148299 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../context/ContextManagementImpl.java | 13 ++++++++----- .../resourceregistry/context/ContextUtility.java | 12 +++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementImpl.java index 5b73900..f0196fc 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementImpl.java @@ -191,8 +191,6 @@ public class ContextManagementImpl implements ContextManagement { logger.info("Trying to rename {} with UUID {} to {}", Context.NAME, contextUUID, newName); - ContextUtility.invalidCurrentContextUUIDCache(); - orientGraph = SecurityContextMapper.getSecurityContextFactory( SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.WRITER).getTx(); @@ -221,6 +219,8 @@ public class ContextManagementImpl implements ContextManagement { context.setProperty(Context.NAME_PROPERTY, newName); orientGraph.commit(); + + ContextUtility.invalidContextUUIDCache(contextUUID); String contextJsonString = Utility.toJsonString(context, true); logger.info("Context renamed {}", contextJsonString); @@ -253,8 +253,6 @@ public class ContextManagementImpl implements ContextManagement { "Trying to move {} with UUID {} as child of {} with UUID {}", Context.NAME, contextToMoveUUID, Context.NAME, newParentUUID); - ContextUtility.invalidCurrentContextUUIDCache(); - orientGraph = SecurityContextMapper.getSecurityContextFactory( SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, PermissionMode.WRITER).getTx(); @@ -288,6 +286,9 @@ public class ContextManagementImpl implements ContextManagement { orientGraph.commit(); + ContextUtility.invalidContextUUIDCache(contextToMoveUUID); + + context = getContext(orientGraph, contextToMoveUUID); String contextJsonString = Utility.toJsonString(context, true); logger.info("Context moved {}", contextJsonString); @@ -320,7 +321,7 @@ public class ContextManagementImpl implements ContextManagement { try { logger.info("Trying to remove {} with UUID {}", Context.NAME, uuid); - ContextUtility.invalidCurrentContextUUIDCache(); + orientGraph = SecurityContextMapper.getSecurityContextFactory( SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, @@ -342,6 +343,8 @@ public class ContextManagementImpl implements ContextManagement { context.remove(); orientGraph.commit(); + ContextUtility.invalidContextUUIDCache(uuid); + logger.info("{} with UUID {} successfully removed", Context.NAME, uuid); return true; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextUtility.java index 70a853b..637ac26 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/context/ContextUtility.java @@ -51,9 +51,15 @@ public class ContextUtility { contextUUIDCache = new HashMap<>(); } - protected static void invalidCurrentContextUUIDCache(){ - String scope = getCurrentContext(); - contextUUIDCache.remove(scope); + protected static void invalidContextUUIDCache(UUID uuid){ + for(String scope : contextUUIDCache.keySet()){ + UUID gotUUID = contextUUIDCache.get(scope); + if(gotUUID.compareTo(uuid)==0){ + contextUUIDCache.remove(scope); + return; + } + } + } public static UUID addToActualContext(OrientGraph orientGraph, Element element)