diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/api/contexts/ContextCache.java b/src/main/java/org/gcube/informationsystem/resourceregistry/api/contexts/ContextCache.java index a0dcb35..495fd19 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/api/contexts/ContextCache.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/api/contexts/ContextCache.java @@ -3,8 +3,10 @@ package org.gcube.informationsystem.resourceregistry.api.contexts; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -49,11 +51,11 @@ public class ContextCache { cleanCache(Calendar.getInstance()); } - private void cleanCache(Calendar now) { + protected void cleanCache(Calendar now) { this.contexts = null; - this.uuidToContext = new HashMap<>(); - this.uuidToContextFullName = new HashMap<>(); - this.contextFullNameToUUID = new HashMap<>(); + this.uuidToContext = new LinkedHashMap<>(); + this.uuidToContextFullName = new LinkedHashMap<>(); + this.contextFullNameToUUID = new TreeMap<>(); this.creationTime = Calendar.getInstance(); this.creationTime.setTimeInMillis(now.getTimeInMillis()); this.expiringTime = Calendar.getInstance(); @@ -78,6 +80,10 @@ public class ContextCache { cleanCache(now); } + public ContextCacheRenewal getContextCacheRenewal() { + return contextCacheRenewal; + } + public void setContextCacheRenewal(ContextCacheRenewal contextCacheRenewal) { if(this.contextCacheRenewal==null) { this.contextCacheRenewal = contextCacheRenewal; @@ -106,7 +112,7 @@ public class ContextCache { return contexts; } - private void setContexts(List contexts) { + protected void setContexts(List contexts) { this.contexts = new ArrayList<>(); for(Context c : contexts) { @@ -144,7 +150,7 @@ public class ContextCache { } - private String getContextFullName(Context context) { + protected String getContextFullName(Context context) { StringBuilder stringBuilder = new StringBuilder(); IsParentOf ipo = context.getParent(); if(ipo!=null) { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/api/contexts/ContextUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/api/contexts/ContextUtility.java index f06a692..16248e2 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/api/contexts/ContextUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/api/contexts/ContextUtility.java @@ -49,8 +49,7 @@ public class ContextUtility { return uuids; } - public static Set getContextFullNameSet(Collection uuids) throws Exception { - ContextCache contextCache = ContextCache.getInstance(); + public static Set getContextFullNameSet(ContextCache contextCache, Collection uuids) throws Exception { Set contextFullNames = new HashSet<>(); try { Map uuidToContextFullNameAssociation = contextCache.getUUIDToContextFullNameAssociation();