Added Context UUID cache
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@148297 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b8d082399c
commit
e559991510
|
@ -191,6 +191,8 @@ 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();
|
||||||
|
@ -206,7 +208,7 @@ public class ContextManagementImpl implements ContextManagement {
|
||||||
Edge edge = iteratorEdge.next();
|
Edge edge = iteratorEdge.next();
|
||||||
|
|
||||||
if (iteratorEdge.hasNext()) {
|
if (iteratorEdge.hasNext()) {
|
||||||
throw new ContextException("");
|
throw new ContextException("Seems that the Context has more than one Parent. THIS IS REALLY STRANGE AND SHOULD NOT OCCUR. PLEASE CONTACT THE ADMINISTRATOR");
|
||||||
}
|
}
|
||||||
|
|
||||||
Vertex parent = edge.getVertex(Direction.OUT);
|
Vertex parent = edge.getVertex(Direction.OUT);
|
||||||
|
@ -251,6 +253,8 @@ 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();
|
||||||
|
@ -316,6 +320,8 @@ 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,
|
||||||
PermissionMode.WRITER).getTx();
|
PermissionMode.WRITER).getTx();
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.informationsystem.resourceregistry.context;
|
package org.gcube.informationsystem.resourceregistry.context;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.common.authorization.client.Constants;
|
import org.gcube.common.authorization.client.Constants;
|
||||||
|
@ -38,6 +40,22 @@ public class ContextUtility {
|
||||||
private static final Logger logger = LoggerFactory
|
private static final Logger logger = LoggerFactory
|
||||||
.getLogger(ContextUtility.class);
|
.getLogger(ContextUtility.class);
|
||||||
|
|
||||||
|
private static Map<String, UUID> contextUUIDCache;
|
||||||
|
|
||||||
|
static {
|
||||||
|
contextUUIDCache = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static void invalidContextUUIDCache(){
|
||||||
|
contextUUIDCache = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void invalidCurrentContextUUIDCache(){
|
||||||
|
String scope = getCurrentContext();
|
||||||
|
contextUUIDCache.remove(scope);
|
||||||
|
}
|
||||||
|
|
||||||
public static UUID addToActualContext(OrientGraph orientGraph, Element element)
|
public static UUID addToActualContext(OrientGraph orientGraph, Element element)
|
||||||
throws ContextException {
|
throws ContextException {
|
||||||
UUID contextUUID = ContextUtility.getActualContextUUID();
|
UUID contextUUID = ContextUtility.getActualContextUUID();
|
||||||
|
@ -77,6 +95,8 @@ public class ContextUtility {
|
||||||
return authorizationEntry.getContext();
|
return authorizationEntry.getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static UUID getActualContextUUID() throws ContextException {
|
public static UUID getActualContextUUID() throws ContextException {
|
||||||
OrientGraphFactory factory = null;
|
OrientGraphFactory factory = null;
|
||||||
OrientGraph orientGraph = null;
|
OrientGraph orientGraph = null;
|
||||||
|
@ -87,14 +107,24 @@ public class ContextUtility {
|
||||||
throw new ContextException("Null Token and Scope. Please set your token first.");
|
throw new ContextException("Null Token and Scope. Please set your token first.");
|
||||||
}
|
}
|
||||||
logger.trace("Trying to get context UUID for scope {}", scope);
|
logger.trace("Trying to get context UUID for scope {}", scope);
|
||||||
factory = SecurityContextMapper
|
|
||||||
.getSecurityContextFactory(
|
UUID uuid = contextUUIDCache.get(scope);
|
||||||
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
|
||||||
PermissionMode.READER);
|
if(uuid == null){
|
||||||
orientGraph = factory.getTx();
|
logger.trace("UUID for scope {} is not in cache. Going to query it", scope);
|
||||||
Vertex context = ContextUtility.getContextVertexByFullName(
|
factory = SecurityContextMapper
|
||||||
orientGraph, scope);
|
.getSecurityContextFactory(
|
||||||
return Utility.getUUID(context);
|
SecurityContextMapper.ADMIN_SECURITY_CONTEXT_UUID,
|
||||||
|
PermissionMode.READER);
|
||||||
|
orientGraph = factory.getTx();
|
||||||
|
Vertex context = ContextUtility.getContextVertexByFullName(
|
||||||
|
orientGraph, scope);
|
||||||
|
uuid = Utility.getUUID(context);
|
||||||
|
contextUUIDCache.put(scope, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return uuid;
|
||||||
|
|
||||||
} catch (ContextException e) {
|
} catch (ContextException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue