From 084e22366972bb8f39795bc43eb42796f37b5e48 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Fri, 10 Nov 2023 14:37:43 +0100 Subject: [PATCH] Trying to fix Server Context Cache --- .../contexts/ServerContextCache.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ServerContextCache.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ServerContextCache.java index 150f0ba..9edfc1a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ServerContextCache.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ServerContextCache.java @@ -6,6 +6,8 @@ import java.util.Calendar; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.UUID; import org.gcube.com.fasterxml.jackson.core.JsonProcessingException; @@ -35,12 +37,12 @@ public class ServerContextCache extends ContextCache { private static Logger logger = LoggerFactory.getLogger(ServerContextCache.class); - protected List contextsNoMeta; - protected Map uuidToContextNoMeta; - protected List contextsMetaPrivacy; protected Map uuidToContextMetaPrivacy; + protected List contextsNoMeta; + protected Map uuidToContextNoMeta; + protected boolean includeMeta; protected static ServerContextCache singleton; @@ -60,10 +62,11 @@ public class ServerContextCache extends ContextCache { @Override protected void cleanCache(Calendar now) { super.cleanCache(now); - contextsNoMeta = null; - uuidToContextNoMeta = new LinkedHashMap<>(); contextsMetaPrivacy = null; - uuidToContextMetaPrivacy = new LinkedHashMap<>(); + uuidToContextMetaPrivacy = null; + contextsNoMeta = null; + uuidToContextNoMeta = null; + } public ServerContextCache() { @@ -148,8 +151,14 @@ public class ServerContextCache extends ContextCache { @Override public void setContexts(List contexts) { this.contexts = new ArrayList<>(); - this.contextsNoMeta = new ArrayList<>(); + this.uuidToContext = new LinkedHashMap<>(); + this.contextsMetaPrivacy = new ArrayList<>(); + this.uuidToContextMetaPrivacy = new LinkedHashMap<>(); + + this.contextsNoMeta = new ArrayList<>(); + this.uuidToContextNoMeta = new LinkedHashMap<>(); + ObjectMapper objectMapper = ElementMapper.getObjectMapper(); @@ -223,5 +232,12 @@ public class ServerContextCache extends ContextCache { this.contextFullNameToUUID.put(fullName, uuid); } + SortedSet contextFullNames = new TreeSet(contextFullNameToUUID.keySet()); + for(String contextFullName : contextFullNames) { + UUID uuid = contextFullNameToUUID.get(contextFullName); + Context context = uuidToContext.get(uuid); + contextsTree.addNode(context); + } + } }