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
This commit is contained in:
Luca Frosini 2017-05-04 15:43:36 +00:00
parent e559991510
commit ed6f906c7e
2 changed files with 17 additions and 8 deletions

View File

@ -191,8 +191,6 @@ public class ContextManagementImpl implements ContextManagement {
logger.info("Trying to rename {} with UUID {} to {}", Context.NAME, logger.info("Trying to rename {} with UUID {} to {}", Context.NAME,
contextUUID, newName); contextUUID, newName);
ContextUtility.invalidCurrentContextUUIDCache();
orientGraph = SecurityContextMapper.getSecurityContextFactory( orientGraph = SecurityContextMapper.getSecurityContextFactory(
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
PermissionMode.WRITER).getTx(); PermissionMode.WRITER).getTx();
@ -221,6 +219,8 @@ public class ContextManagementImpl implements ContextManagement {
context.setProperty(Context.NAME_PROPERTY, newName); context.setProperty(Context.NAME_PROPERTY, newName);
orientGraph.commit(); orientGraph.commit();
ContextUtility.invalidContextUUIDCache(contextUUID);
String contextJsonString = Utility.toJsonString(context, true); String contextJsonString = Utility.toJsonString(context, true);
logger.info("Context renamed {}", contextJsonString); logger.info("Context renamed {}", contextJsonString);
@ -253,8 +253,6 @@ public class ContextManagementImpl implements ContextManagement {
"Trying to move {} with UUID {} as child of {} with UUID {}", "Trying to move {} with UUID {} as child of {} with UUID {}",
Context.NAME, contextToMoveUUID, Context.NAME, newParentUUID); Context.NAME, contextToMoveUUID, Context.NAME, newParentUUID);
ContextUtility.invalidCurrentContextUUIDCache();
orientGraph = SecurityContextMapper.getSecurityContextFactory( orientGraph = SecurityContextMapper.getSecurityContextFactory(
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
PermissionMode.WRITER).getTx(); PermissionMode.WRITER).getTx();
@ -288,6 +286,9 @@ public class ContextManagementImpl implements ContextManagement {
orientGraph.commit(); orientGraph.commit();
ContextUtility.invalidContextUUIDCache(contextToMoveUUID);
context = getContext(orientGraph, contextToMoveUUID); context = getContext(orientGraph, contextToMoveUUID);
String contextJsonString = Utility.toJsonString(context, true); String contextJsonString = Utility.toJsonString(context, true);
logger.info("Context moved {}", contextJsonString); logger.info("Context moved {}", contextJsonString);
@ -320,7 +321,7 @@ public class ContextManagementImpl implements ContextManagement {
try { try {
logger.info("Trying to remove {} with UUID {}", Context.NAME, uuid); logger.info("Trying to remove {} with UUID {}", Context.NAME, uuid);
ContextUtility.invalidCurrentContextUUIDCache();
orientGraph = SecurityContextMapper.getSecurityContextFactory( orientGraph = SecurityContextMapper.getSecurityContextFactory(
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID, SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
@ -342,6 +343,8 @@ public class ContextManagementImpl implements ContextManagement {
context.remove(); context.remove();
orientGraph.commit(); orientGraph.commit();
ContextUtility.invalidContextUUIDCache(uuid);
logger.info("{} with UUID {} successfully removed", Context.NAME, logger.info("{} with UUID {} successfully removed", Context.NAME,
uuid); uuid);
return true; return true;

View File

@ -51,9 +51,15 @@ public class ContextUtility {
contextUUIDCache = new HashMap<>(); contextUUIDCache = new HashMap<>();
} }
protected static void invalidCurrentContextUUIDCache(){ protected static void invalidContextUUIDCache(UUID uuid){
String scope = getCurrentContext(); for(String scope : contextUUIDCache.keySet()){
contextUUIDCache.remove(scope); UUID gotUUID = contextUUIDCache.get(scope);
if(gotUUID.compareTo(uuid)==0){
contextUUIDCache.remove(scope);
return;
}
}
} }
public static UUID addToActualContext(OrientGraph orientGraph, Element element) public static UUID addToActualContext(OrientGraph orientGraph, Element element)