diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index cfa6374..390c7ae 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -4,6 +4,9 @@
+
+ uses
+
diff --git a/changelog.md b/CHANGELOG.md
similarity index 100%
rename from changelog.md
rename to CHANGELOG.md
diff --git a/pom.xml b/pom.xml
index fea6c8a..cb7c240 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
org.gcube.data.transfer
uri-resolver
- 2.3.2
+ 2.4.0-SNAPSHOT
war
The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications.
@@ -85,6 +85,12 @@
[0.0.1,1.0.0-SNAPSHOT)
+
+ org.gcube.infrastructure.detachedres
+ detachedres-library
+ [1.0.0,2.0.0-SNAPSHOT)
+
+
org.gcube.common
diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java
new file mode 100644
index 0000000..d8ae311
--- /dev/null
+++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfDetachedVRE.java
@@ -0,0 +1,191 @@
+/**
+ *
+ */
+package org.gcube.datatransfer.resolver.caches;
+
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
+import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient;
+import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs;
+import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway;
+import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO;
+import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
+
+/**
+ * The Class LoadingMapOfDetachedVRE.
+ *
+ * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
+ * Jun 8, 2020
+ */
+public class LoadingMapOfDetachedVRE {
+
+ private static Logger logger = LoggerFactory.getLogger(LoadingMapOfDetachedVRE.class);
+ private static LoadingCache vreNameToVRE;
+
+ static{
+
+ CacheLoader loader = new CacheLoader(){
+
+ @Override
+ public VRE load(String vreName)
+ throws Exception {
+
+ logger.info("Loading the cache for VRE name: {}",vreName);
+ VRE theVRE = loadFullScopeforScopeName(vreName);
+ logger.info("Returning {} with scope {} for the VRE name: {}", VRE.class.getSimpleName(), theVRE.getScope(), vreName);
+ return theVRE;
+ }
+
+ };
+
+ RemovalListener removalListener = new RemovalListener() {
+
+ @Override
+ public void onRemoval(RemovalNotification arg0) {
+
+ logger.info("cache expired");
+ //prePopulateCache();
+
+ }
+ };
+
+ vreNameToVRE = CacheBuilder.newBuilder().maximumSize(300).expireAfterWrite(
+ 1, TimeUnit.DAYS).removalListener(removalListener).
+ build(loader);
+
+
+ //Populating the cache at init stage
+ populateTheCache();
+ logger.info("Pre-Loaded detached VRE Name to VRE Obj cache with: "+vreNameToVRE.asMap().size()+" item/s");
+ }
+
+
+ /**
+ * Populate the cache.
+ */
+ private static void populateTheCache(){
+ try{
+ //POPULATE THE CACHE READING THE RESOURCE "CATALOGUE-RESOLVER"
+ logger.info("Trying to pre-populate the detached VREs cache with mapping (VRE Name, VRE Obj)");
+ ScopeProvider.instance.set(UriResolverSmartGearManagerInit.getRootContextScope());
+ DetachedREsClient detachedREsClient = new DetachedREsClient();
+ DetachedREs detachedREs = detachedREsClient.getDetachedREs();
+
+ int totalVREDimissed = 0;
+ for (Gateway gateway : detachedREs.getGateways().values()) {
+ logger.trace("Gateway: " + gateway.getName());
+ int vreDismissedPerGatew = 0;
+ for (VO vo : gateway.getVos().values()) {
+ logger.trace("VO: " + vo.getName());
+ for (VRE vre : vo.getVres().values()) {
+ if(logger.isTraceEnabled()) {
+ logger.trace("VRE name: " + vre.getName() +
+ " scope: "+vre.getScope() +
+ " VRE catalogue url: " + vre.getCatalogUrl() +
+ " VRE catalog Portlet URL: "+vre.getCatalogPortletURL());
+ }
+ try {
+ if(vre.getScope()!=null && !vre.getScope().isEmpty()) {
+ String vreName = vre.getScope().split("/")[3];
+ vreNameToVRE.put(vreName, vre);
+ vreDismissedPerGatew++;
+ }
+ }catch (Exception e) {
+ logger.warn("Error on parsing the scope: "+vre.getScope()+ " skipping it");
+
+ }
+ }
+ }
+
+ logger.debug("\nVREs dismissed loaded and cached per " + gateway.getName() + " are: "+vreDismissedPerGatew);
+ totalVREDimissed+=vreDismissedPerGatew;
+ }
+
+ logger.debug("\nTotal detached VREs are: "+totalVREDimissed);
+
+ logger.info("Cache populated with: ");
+ ConcurrentMap mapOfVreNames = vreNameToVRE.asMap();
+ for (String key : mapOfVreNames.keySet()) {
+ VRE theDetachedVRE = mapOfVreNames.get(key);
+ logger.info("detached VRE with scope {}, catalogueURL {}, cataloguePortletURL {}",
+ theDetachedVRE.getScope(), theDetachedVRE.getCatalogUrl(),
+ theDetachedVRE.getCatalogPortletURL());
+ }
+
+ }catch(Exception e){
+ //SILENT
+ }finally{
+
+ }
+ }
+
+
+ /**
+ * Gets the.
+ *
+ * @param vreName the vre name
+ * @return the vre
+ * @throws ExecutionException the execution exception
+ */
+ public static VRE get(String vreName) throws ExecutionException{
+
+ boolean cacheNotLoaded = true;
+ final int MAX_ATTEMPTS = 3;
+ int retry = 1;
+ while (cacheNotLoaded) {
+ cacheNotLoaded = vreNameToVRE == null;
+ if(retry getCache(){
+ return vreNameToVRE;
+ }
+
+}
diff --git a/src/test/java/CatalogueNameExtractor.java b/src/test/java/CatalogueNameExtractor.java
index e4460ee..5af2460 100644
--- a/src/test/java/CatalogueNameExtractor.java
+++ b/src/test/java/CatalogueNameExtractor.java
@@ -1,5 +1,4 @@
import org.gcube.datatransfer.resolver.catalogue.resource.CatalogueStaticConfigurations;
-import org.junit.Test;
public class CatalogueNameExtractor {
diff --git a/src/test/java/DetachedVREs.java b/src/test/java/DetachedVREs.java
new file mode 100644
index 0000000..becbb03
--- /dev/null
+++ b/src/test/java/DetachedVREs.java
@@ -0,0 +1,33 @@
+import java.util.concurrent.ExecutionException;
+
+import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
+import org.gcube.datatransfer.resolver.caches.LoadingMapOfDetachedVRE;
+import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DetachedVREs {
+
+ public static Logger LOG = LoggerFactory.getLogger(DetachedVREs.class);
+
+ public static String TOKEN = "0e2c7963-8d3e-4ea6-a56d-ffda530dd0fa-98187548";
+
+ /**
+ * Storage hub test.
+ *
+ * @throws Exception the exception
+ */
+ @Test
+ public void testCacheOfDetachedVREs() throws Exception{
+
+ try {
+ SecurityTokenProvider.instance.set(TOKEN);
+ VRE theDetachedVRE = LoadingMapOfDetachedVRE.get("NextNext");
+ LOG.info("Detached VRE found {}", theDetachedVRE);
+ }catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/test/java/GisResolverTest.java b/src/test/java/GisResolverTest.java
index c42100d..2a6d3f4 100644
--- a/src/test/java/GisResolverTest.java
+++ b/src/test/java/GisResolverTest.java
@@ -1,6 +1,5 @@
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem;
-import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
import org.gcube.datatransfer.resolver.services.GisResolver;
/**
@@ -14,7 +13,7 @@ import org.gcube.datatransfer.resolver.services.GisResolver;
public class GisResolverTest {
static String scope = "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab";
- static String gisUUID = "6b99efdf-2202-4b6f-aaa3-7e10e0bf09f4";
+ static String gisUUID = "";
public static void main(String[] args) {
GisResolver gisResolver = new GisResolver();
ScopeProvider.instance.set(scope);