diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index cfa6374..21f61b8 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -4,6 +4,9 @@
+
+ uses
+
diff --git a/distro/changelog.xml b/distro/changelog.xml
index b89028e..850a2c8 100644
--- a/distro/changelog.xml
+++ b/distro/changelog.xml
@@ -146,5 +146,7 @@
[Task #16471] Tested Catalogue Resolver backward compatibility
+ [Incident #16671] Fixing Catalogue Resolver in case of working with INFRASTRUCTURE and VO scope
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5626931..ba7c5ce 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,5 @@
-
4.0.0
@@ -92,6 +93,13 @@
compile
+
+
org.gcube.core
common-encryption
@@ -128,11 +136,11 @@
compile
-
-
-
-
-
+
+
+
+
+
diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfScopeCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfScopeCache.java
new file mode 100644
index 0000000..13b50c9
--- /dev/null
+++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingMapOfScopeCache.java
@@ -0,0 +1,147 @@
+/**
+ *
+ */
+package org.gcube.datatransfer.resolver.caches;
+
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.common.scope.impl.ScopeBean;
+import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
+import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
+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 LoadingMapOfScopeCache.
+ *
+ * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
+ *
+ * May 13, 2019
+ */
+public class LoadingMapOfScopeCache {
+
+ private static Logger logger = LoggerFactory.getLogger(LoadingMapOfScopeCache.class);
+ private static LoadingCache scopeNamesToFullScopes;
+
+ static{
+
+ CacheLoader loader = new CacheLoader(){
+
+ @Override
+ public ScopeBean load(String scopeName)
+ throws Exception {
+
+ logger.info("Loading the cache for scope: {}",scopeName);
+ ScopeBean fullScope = loadFullScopeforScopeName(scopeName);
+ logger.info("Returning {} for the Scope name: {}",ScopeBean.class.getSimpleName(), scopeName);
+ return fullScope;
+ }
+
+ };
+
+ RemovalListener removalListener = new RemovalListener() {
+
+ @Override
+ public void onRemoval(RemovalNotification arg0) {
+
+ logger.info("cache expired");
+ //prePopulateCache();
+
+ }
+ };
+
+ scopeNamesToFullScopes = CacheBuilder.newBuilder().maximumSize(300).expireAfterWrite(
+ 1, TimeUnit.DAYS).removalListener(removalListener).
+ build(loader);
+
+
+ //Populating the cache at init stage
+ populateTheCache();
+ logger.info("Pre-Loaded VRE to Scope cache with: "+scopeNamesToFullScopes.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 cache with mapping (Scope Name, Full Scope)");
+ ScopeProvider.instance.set(UriResolverSmartGearManagerInit.getRootContextScope());
+ Map map = GetAllInfrastructureScopes.loadMapOfScopeNameToFullScope(UriResolverSmartGearManagerInit.getRootContextScope());
+
+ for (String scopeName : map.keySet()) {
+ scopeNamesToFullScopes.asMap().put(scopeName, new ScopeBean(map.get(scopeName)));
+ }
+
+ logger.info("Cache populated with: "+scopeNamesToFullScopes.asMap().toString());
+ //logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
+
+// if(UriResolverSmartGearManagerInit.getRootContextScope().compareTo("/gcube")==0){
+// logger.warn("HARD-CABLING PARTHENOS_Registry scope to resolve PARTHENOS_REGISTRY Links in dev environment");
+// scopeNamesToFullScopes.asMap().put("PARTHENOS_Registry", "/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry");
+// }
+
+
+ }catch(Exception e){
+ //SILENT
+ }finally{
+
+ }
+ }
+
+
+ /**
+ * Gets the.
+ *
+ * @param scopeName the scope name
+ * @return the scope bean
+ * @throws ExecutionException the execution exception
+ */
+ public static ScopeBean get(String scopeName) throws ExecutionException{
+
+ return scopeNamesToFullScopes.get(scopeName);
+ }
+
+
+ /**
+ * Load full scopefor scope name.
+ *
+ * @param scopeName the scope name
+ * @return the scope bean
+ */
+ protected static ScopeBean loadFullScopeforScopeName(String scopeName){
+
+ //THIS CHECK SHOULD BE NOT NEEDED
+ ScopeBean fullScope = scopeNamesToFullScopes.getIfPresent(scopeName);
+
+ if(fullScope==null){
+ populateTheCache();
+ fullScope = scopeNamesToFullScopes.getIfPresent(scopeName);
+ }
+
+ return fullScope;
+ }
+
+
+ /**
+ * Gets the cache.
+ *
+ * @return the cache
+ */
+ public LoadingCache getCache(){
+ return scopeNamesToFullScopes;
+ }
+
+}
diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingVREsScopeCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingVREsScopeCache.java
deleted file mode 100644
index 500c763..0000000
--- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingVREsScopeCache.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/**
- *
- */
-package org.gcube.datatransfer.resolver.caches;
-
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-
-import org.gcube.common.scope.api.ScopeProvider;
-import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureVREs;
-import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
-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 LoadingVREsScopeCache.
- *
- * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
- * Nov 8, 2018
- */
-public class LoadingVREsScopeCache {
-
- private static Logger logger = LoggerFactory.getLogger(LoadingVREsScopeCache.class);
- private static LoadingCache vresNameToScope;
-
- static{
-
- CacheLoader loader = new CacheLoader(){
-
- @Override
- public String load(String vreName)
- throws Exception {
-
- logger.info("Loading the cache for vreName: "+vreName);
- String fullScope = loadFullScopeforVreName(vreName);
- logger.info("Returning fullScope: "+fullScope+ " for the VRE name: "+vreName);
- return fullScope;
- }
-
- };
-
- RemovalListener removalListener = new RemovalListener() {
-
- @Override
- public void onRemoval(RemovalNotification arg0) {
-
- logger.info("cache expired");
- //prePopulateCache();
-
- }
- };
-
- vresNameToScope = CacheBuilder.newBuilder().maximumSize(300).expireAfterWrite(
- 1, TimeUnit.DAYS).removalListener(removalListener).
- build(loader);
-
-
- //Populating the cache at init stage
- populateTheCache();
- logger.info("Pre-Loaded VRE to Scope cache with: "+vresNameToScope.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 cache with mapping (VRE Name, VRE Full Scope)");
- ScopeProvider.instance.set(UriResolverSmartGearManagerInit.getRootContextScope());
- Map map = GetAllInfrastructureVREs.loadMapOFVreNameToScope(UriResolverSmartGearManagerInit.getRootContextScope());
- vresNameToScope.asMap().putAll(map);
- logger.info("Cache populated with: "+vresNameToScope.asMap().toString());
- //logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString());
-
- if(UriResolverSmartGearManagerInit.getRootContextScope().compareTo("/gcube")==0){
- logger.warn("HARD-CABLING PARTHENOS_Registry scope to resolve PARTHENOS_REGISTRY Links in dev environment");
- vresNameToScope.asMap().put("PARTHENOS_Registry", "/d4science.research-infrastructures.eu/ParthenosVO/PARTHENOS_Registry");
- }
-
- }catch(Exception e){
-
- }finally{
-
- }
- }
-
-
- /**
- * Gets the.
- *
- * @param vreName the vre name
- * @return the string
- * @throws ExecutionException
- */
- public static String get(String vreName) throws ExecutionException{
-
- return vresNameToScope.get(vreName);
- }
-
-
- /**
- * Load application profiles.
- *
- * @param vreName the vre name
- * @return the string
- */
- protected static String loadFullScopeforVreName(String vreName){
-
- //THIS CHECK SHOULD BE NOT NEEDED
- String fullScope = vresNameToScope.getIfPresent(vreName);
-
- if(fullScope==null){
- populateTheCache();
- fullScope = vresNameToScope.getIfPresent(vreName);
- }
-
- return fullScope;
- }
-
-}
diff --git a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GetAllInfrastructureVREs.java b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GetAllInfrastructureScopes.java
similarity index 81%
rename from src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GetAllInfrastructureVREs.java
rename to src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GetAllInfrastructureScopes.java
index 9b0c76d..f46bc60 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GetAllInfrastructureVREs.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/catalogue/resource/GetAllInfrastructureScopes.java
@@ -12,6 +12,8 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.common.scope.impl.ScopeBean;
+import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
@@ -23,54 +25,60 @@ import org.xml.sax.InputSource;
/**
- * The Class GetAllInfrastructureVREs.
+ * The Class GetAllInfrastructureScopes.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
- * Nov 8, 2018
+ *
+ * May 16, 2019
*/
-/**
- *
- * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
- * Nov 8, 2018
- */
-public class GetAllInfrastructureVREs {
+public class GetAllInfrastructureScopes {
- public static Logger logger = LoggerFactory.getLogger(GetAllInfrastructureVREs.class);
+ public static Logger logger = LoggerFactory.getLogger(GetAllInfrastructureScopes.class);
protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()";
+
/**
- * Load map of vre name to scope.
+ * Load map of scope name to full scope.
*
* @param rootScope the root scope
* @return the map of binding between (VRE_NAME, FULL_SCOPE_OF_VRE_NAME)
- * @throws Exception
+ * @throws Exception the exception
*/
- public static Map loadMapOFVreNameToScope(String rootScope) throws Exception{
+ public static Map loadMapOfScopeNameToFullScope(String rootScope) throws Exception{
String originalScope = ScopeProvider.instance.get();
try{
-
+ ScopeBean scopeBean = null;
+ Map scopeNameToFullScopeMap = new HashMap();
ScopeProvider.instance.set(rootScope);
- String secondaryType = "INFRASTRUCTURE";
+ String secondaryType = Type.INFRASTRUCTURE.name();
+ scopeBean = new ScopeBean(rootScope);
+ logger.info("Added the couple ({},{}) as {} (NAME, FULL SCOPE) into map", scopeBean.name(), rootScope, secondaryType);
+ scopeNameToFullScopeMap.put(scopeBean.name(), rootScope);
List listVOScopes = getListOfVOScopes(secondaryType);
- Map vreNameFullScope = new HashMap();
- logger.info("Searching for secondaryType="+secondaryType +" scope/s found is/are: " +listVOScopes);
-
- secondaryType = "VRE";
+ logger.info("Searching for secondaryType={} the scope/s found is/are: " +secondaryType, listVOScopes);
+
//int noVOTypeCount = 0;
for (String voScope : listVOScopes) {
- int count = voScope.length() - voScope.replace("/", "").length();
+ //int count = voScope.length() - voScope.replace("/", "").length();
+ scopeBean = new ScopeBean(voScope);
//IS A VO
- if(count==2){
- logger.info(voScope +" is a VO...");
+ //if(count==2){
+ if(scopeBean.is(Type.VO)){
+ secondaryType = Type.VO.name();
+ logger.info("{} is a {}...",voScope,secondaryType);
ScopeProvider.instance.set(voScope);
+ scopeBean = new ScopeBean(voScope);
+ logger.info("Added the couple ({},{}) as {} (NAME, FULL SCOPE) into map", scopeBean.name(), voScope, secondaryType);
+ scopeNameToFullScopeMap.put(scopeBean.name(), voScope);
+ secondaryType = Type.VRE.name();
List listVREs = getListOfResourcesForSecondaryType(secondaryType);
logger.debug("VREs found for VO "+voScope+ " is/are "+listVREs.size()+ ": "+listVREs);
for (String vreName : listVREs) {
String vreScope = String.format("%s/%s", voScope,vreName);
- vreNameFullScope.put(vreName, vreScope);
+ scopeNameToFullScopeMap.put(vreName, vreScope);
}
}else{
@@ -84,8 +92,8 @@ public class GetAllInfrastructureVREs {
System.out.println("VRE Name: "+vreName + " has scope: "+vreNameFullScope.get(vreName));
}*/
- logger.info("Total VRE is: "+vreNameFullScope.size());
- return vreNameFullScope;
+ logger.info("Total VRE is: "+scopeNameToFullScopeMap.size());
+ return scopeNameToFullScopeMap;
}catch(Exception e ){
throw new Exception("Error on loading the map of VRE nameto scope: ", e);
diff --git a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java
index 76a64b8..ef36cca 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/init/UriResolverSmartGearManagerInit.java
@@ -17,7 +17,7 @@ import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache;
import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache;
-import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
+import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
import org.gcube.datatransfer.resolver.gis.property.ApplicationProfilePropertyReader;
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
import org.gcube.smartgears.ApplicationManager;
@@ -93,7 +93,7 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
//init the caches
new LoadingGeonetworkInstanceCache();
new LoadingGisViewerApplicationURLCache();
- new LoadingVREsScopeCache();
+ new LoadingMapOfScopeCache();
}
}
catch (Exception e) {
@@ -225,4 +225,8 @@ public class UriResolverSmartGearManagerInit implements ApplicationManager {
return rootContextScope;
}
+
+ public static void setRootContextScope(String rootContextScope) {
+ UriResolverSmartGearManagerInit.rootContextScope = rootContextScope;
+ }
}
diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsGetResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsGetResolver.java
index abe473d..26090ed 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsGetResolver.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/services/AnalyticsGetResolver.java
@@ -14,8 +14,9 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
+import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
-import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
+import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,18 +63,18 @@ public class AnalyticsGetResolver {
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
}
- String fullScope = "";
+ ScopeBean fullScopeBean = null;
//CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
try{
- fullScope = LoadingVREsScopeCache.get(vreName);
+ fullScopeBean = LoadingMapOfScopeCache.get(vreName);
}catch(ExecutionException | InvalidCacheLoadException e){
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
}
ApplicationProfileReader reader = null;
try{
- reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
+ reader = new ApplicationProfileReader(fullScopeBean.toString(), APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
}catch(Exception e){
logger.error("Error on reading the "+APPLICATION_PROFILE+" with APPID: "+ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, e);
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "+ANALYTICS_EXECUTOR_PORTLET_NAME+". Please contact the support", this.getClass(), helpURI);
diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/CR7Huevos.java b/src/main/java/org/gcube/datatransfer/resolver/services/CR7Huevos.java
deleted file mode 100644
index 9442421..0000000
--- a/src/main/java/org/gcube/datatransfer/resolver/services/CR7Huevos.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.gcube.datatransfer.resolver.services;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-
-import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * TODO
- * EASTER EGG - TO BE REMOVED
- * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
- *
- */
-@Path("cr7huevos")
-public class CR7Huevos {
-
- private static Logger logger = LoggerFactory.getLogger(UriResolverIndex.class);
-
- @GET
- @Produces({MediaType.TEXT_HTML})
- @Path("")
- public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{
-
- String indexFile = "/WEB-INF/jsp/cr7huevos.jsp";
-
- try{
- logger.info("Easter EGG called :-) - TO BE REMOVE");
- String realPath = req.getServletContext().getRealPath(indexFile);
- return new FileInputStream(new File(realPath));
- }catch (Exception e) {
-
- if(!(e instanceof WebApplicationException)){
- //UNEXPECTED EXCEPTION managing it as WebApplicationException
- String error = "Index.jsp not found. Please, contact the support!";
- throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
- }
- //ALREADY MANAGED AS WebApplicationException
- logger.error("Exception:", e);
- throw (WebApplicationException) e;
- }
- }
-
-}
diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java
index 6847401..a970d93 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/services/CatalogueResolver.java
@@ -16,13 +16,15 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.gcube.common.scope.api.ScopeProvider;
-import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
+import org.gcube.common.scope.impl.ScopeBean;
+import org.gcube.common.scope.impl.ScopeBean.Type;
+import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
import org.gcube.datatransfer.resolver.catalogue.CatalogueRequest;
import org.gcube.datatransfer.resolver.catalogue.ItemCatalogueURLs;
import org.gcube.datatransfer.resolver.catalogue.ResourceCatalogueCodes;
import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
-import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureVREs;
+import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.gcube.datatransfer.resolver.util.Util;
import org.gcube.smartgears.utils.InnerMethodName;
@@ -122,11 +124,11 @@ public class CatalogueResolver {
String serverUrl = Util.getServerURL(req);
final String vreName = scope.substring(scope.lastIndexOf("/")+1, scope.length());
- String fullScope = null;
+ ScopeBean fullScope = null;
//CHECK IF THE vreName has a valid scope, so it is a valid VRE
try {
- fullScope = LoadingVREsScopeCache.get(vreName);
+ fullScope = LoadingMapOfScopeCache.get(vreName);
}catch(ExecutionException e){
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
@@ -158,29 +160,37 @@ public class CatalogueResolver {
}
}
-
/**
- * Gets the item catalogue url.
+ * Gets the item catalogue UR ls.
*
* @param req the req
- * @param vreName the vre name
+ * @param scopeName the scope name
* @param entityContext the entity context
* @param entityName the entity name
- * @return the item catalogue url
+ * @return the item catalogue UR ls
* @throws Exception the exception
*/
- protected static ItemCatalogueURLs getItemCatalogueURLs(HttpServletRequest req, String vreName, String entityContext, String entityName) throws Exception{
+ protected static ItemCatalogueURLs getItemCatalogueURLs(HttpServletRequest req, String scopeName, String entityContext, String entityName) throws Exception{
try {
String entityContextValue = ResourceCatalogueCodes.valueOfCodeId(entityContext).getValue();
- String fullScope = "";
+ ScopeBean scopeBean = null;
try{
- fullScope = LoadingVREsScopeCache.get(vreName);
+ scopeBean = LoadingMapOfScopeCache.get(scopeName);
}catch(ExecutionException | InvalidCacheLoadException e){
- logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
- throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name '"+vreName+"'. Is it registered as VRE in the D4Science Infrastructure System?", CatalogueResolver.class, helpURI);
+ logger.error("Error on getting the fullscope from cache for scopeName "+scopeName, e);
+ throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the scope name '"+scopeName+"'. Is it registered as a valid Scope in the D4Science Infrastructure System?", CatalogueResolver.class, helpURI);
+ }
+
+ String fullScope = scopeBean.toString();
+ logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName());
+
+ if(scopeBean.is(Type.VO)) {
+ logger.info("It is a {} scope", Type.VO);
+ logger.warn("The Catalogue can't work at {} level, I'm overriding the scope to {} level", Type.VO, Type.INFRASTRUCTURE);
+ fullScope = fullScope.substring(0, fullScope.indexOf("/"));
+ logger.info("Overriden the input scope {} with {} type: {}", fullScope, Type.INFRASTRUCTURE, fullScope);
}
- logger.info("Read fullScope: "+fullScope + " for VRE_NAME: "+vreName +" from cache created by: "+GetAllInfrastructureVREs.class.getSimpleName());
ScopeProvider.instance.set(fullScope);
GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/KnimeGetResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/KnimeGetResolver.java
index 0cf42f8..0367d22 100644
--- a/src/main/java/org/gcube/datatransfer/resolver/services/KnimeGetResolver.java
+++ b/src/main/java/org/gcube/datatransfer/resolver/services/KnimeGetResolver.java
@@ -14,8 +14,9 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
+import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
-import org.gcube.datatransfer.resolver.caches.LoadingVREsScopeCache;
+import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -61,14 +62,15 @@ public class KnimeGetResolver {
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
}
- String fullScope = "";
+ ScopeBean scopeBean = null;
try{
- fullScope = LoadingVREsScopeCache.get(vreName);
+ scopeBean = LoadingMapOfScopeCache.get(vreName);
}catch(ExecutionException | InvalidCacheLoadException e){
logger.error("Error on getting the fullscope from cache for vreName "+vreName, e);
throw ExceptionManager.wrongParameterException(req, "Error on getting full scope for the VRE name "+vreName+". Is it registered as VRE in the D4Science Infrastructure System?", this.getClass(), helpURI);
}
ApplicationProfileReader reader = null;
+ String fullScope = scopeBean.toString();
try{
reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false);
}catch(Exception e){
diff --git a/src/test/java/CatalogueResolverTest.java b/src/test/java/CatalogueResolverTest.java
index 9ad5027..06bd337 100644
--- a/src/test/java/CatalogueResolverTest.java
+++ b/src/test/java/CatalogueResolverTest.java
@@ -1,11 +1,14 @@
+import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.datatransfer.resolver.catalogue.resource.CkanCatalogueConfigurationsReader;
+import org.gcube.datatransfer.resolver.catalogue.resource.GatewayCKANCatalogueReference;
+
/**
+ * The Class CatalogueResolverTest.
*
- */
-/**
- *
- * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
- * Dec 7, 2016
+ * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
+ *
+ * May 13, 2019
*/
public class CatalogueResolverTest {
@@ -17,20 +20,15 @@ public class CatalogueResolverTest {
* the arguments
*/
public static void main(String[] args) {
-
- // jsonRequest = "{" +
- // "\"gcube_scope\" : \"/gcube\"," +
- // "\"entity_context\" : \"dataset\"," +
- // "\"entity_name\" : \"sarda-sarda\"" +
- // "}";
- // //String test = "{" +
- // // "\"gcube_scope\" : \"/gcube\"," +
- // // "\"entity_context\" : \"dataset\"," +
- // // "\"entity_name\" : \"sarda-sarda\"," +
- // // "\"query\" : {\"key1\" : \"value1\", \"key2\":\"value2\"}" +
- //
- //
- // // "}";
-
+
+ try {
+
+ ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
+ //ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
+ GatewayCKANCatalogueReference ckanCatalogueReference = CkanCatalogueConfigurationsReader.loadCatalogueEndPoints();
+ System.out.println(ckanCatalogueReference.toString());
+ }catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/src/test/java/GetAllInfrastructureVREs.java b/src/test/java/GetAllInfrastructureScopesFromIS.java
similarity index 65%
rename from src/test/java/GetAllInfrastructureVREs.java
rename to src/test/java/GetAllInfrastructureScopesFromIS.java
index 96f800f..5e83ab8 100644
--- a/src/test/java/GetAllInfrastructureVREs.java
+++ b/src/test/java/GetAllInfrastructureScopesFromIS.java
@@ -5,12 +5,18 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.common.scope.impl.ScopeBean;
+import org.gcube.common.scope.impl.ScopeBean.Type;
+import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
+import org.gcube.datatransfer.resolver.catalogue.resource.GetAllInfrastructureScopes;
+import org.gcube.datatransfer.resolver.init.UriResolverSmartGearManagerInit;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.Query;
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
@@ -32,9 +38,9 @@ import org.xml.sax.InputSource;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 8, 2018
*/
-public class GetAllInfrastructureVREs {
+public class GetAllInfrastructureScopesFromIS {
- public static Logger logger = LoggerFactory.getLogger(GetAllInfrastructureVREs.class);
+ public static Logger logger = LoggerFactory.getLogger(GetAllInfrastructureScopesFromIS.class);
protected static final String RESOURCE_PROFILE_NAME_TEXT = "/Resource/Profile/Name/text()";
@@ -44,48 +50,82 @@ public class GetAllInfrastructureVREs {
* @param args the arguments
*/
public static void main(String[] args) {
+
+ try {
- //TODO TOKEN TO ROOT SCOPE
+// //TODO TOKEN TO ROOT SCOPE
+// String rootScope = "/gcube";
+// //String rootScope = "/d4science.research-infrastructures.eu";
+// ScopeProvider.instance.set(rootScope);
+//
+// String secondaryType = "INFRASTRUCTURE";
+// List listVOScopes = getListOfVOScopes("INFRASTRUCTURE");
+//
+// System.out.println("Searching for secondaryType="+secondaryType +" scope/s found is/are: " +listVOScopes);
+//
+// Map vreNameFullScope = new HashMap();
+//
+// secondaryType = "VRE";
+// int noVOTypeCount = 0;
+// for (String voScope : listVOScopes) {
+// int count = voScope.length() - voScope.replace("/", "").length();
+// //IS A VO
+// if(count==2){
+// logger.info(voScope +" is a VO...");
+// ScopeProvider.instance.set(voScope);
+// List listVREs = getListOfResourcesForSecondaryType(secondaryType);
+// System.out.println("VREs found for VO "+voScope+ " is/are "+listVREs.size()+ ": "+listVREs);
+// for (String vreName : listVREs) {
+// String vreScope = String.format("%s/%s", voScope,vreName);
+// vreNameFullScope.put(vreName, vreScope);
+// }
+//
+// }else{
+// noVOTypeCount++;
+// System.out.println(voScope +" is not a VO, skipping it");
+// }
+// }
+//
+//
+// System.out.println("Total VO is: "+(listVOScopes.size()+noVOTypeCount));
+// for (String vreName : vreNameFullScope.keySet()) {
+// System.out.println("VRE Name: "+vreName + " has scope: "+vreNameFullScope.get(vreName));
+// }
+//
+// System.out.println("Total VRE is: "+vreNameFullScope.size());
+
+
String rootScope = "/gcube";
//String rootScope = "/d4science.research-infrastructures.eu";
ScopeProvider.instance.set(rootScope);
-
- String secondaryType = "INFRASTRUCTURE";
- List listVOScopes = getListOfVOScopes("INFRASTRUCTURE");
-
- System.out.println("Searching for secondaryType="+secondaryType +" scope/s found is/are: " +listVOScopes);
-
- Map vreNameFullScope = new HashMap();
-
- secondaryType = "VRE";
- int noVOTypeCount = 0;
- for (String voScope : listVOScopes) {
- int count = voScope.length() - voScope.replace("/", "").length();
- //IS A VO
- if(count==2){
- logger.info(voScope +" is a VO...");
- ScopeProvider.instance.set(voScope);
- List listVREs = getListOfResourcesForSecondaryType(secondaryType);
- System.out.println("VREs found for VO "+voScope+ " is/are "+listVREs.size()+ ": "+listVREs);
- for (String vreName : listVREs) {
- String vreScope = String.format("%s/%s", voScope,vreName);
- vreNameFullScope.put(vreName, vreScope);
- }
-
- }else{
- noVOTypeCount++;
- System.out.println(voScope +" is not a VO, skipping it");
+ UriResolverSmartGearManagerInit.setRootContextScope(rootScope);
+ LoadingMapOfScopeCache cache = new LoadingMapOfScopeCache();
+
+ int i = 0;
+ for (String string : cache.getCache().asMap().keySet()) {
+ try {
+ System.out.println(++i+") Scope Name: "+string + " to full scope: "+LoadingMapOfScopeCache.get(string));
+ } catch (ExecutionException e) {
+ e.printStackTrace();
}
}
-
-
- System.out.println("Total VO is: "+(listVOScopes.size()+noVOTypeCount));
- for (String vreName : vreNameFullScope.keySet()) {
- System.out.println("VRE Name: "+vreName + " has scope: "+vreNameFullScope.get(vreName));
+
+ String scopeName = "devsec";
+ ScopeBean scopeBean = LoadingMapOfScopeCache.get(scopeName);
+ String fullScope = scopeBean.toString();
+ logger.info("Read fullScope: "+fullScope + " for SCOPE name: "+scopeName +" from cache created by: "+GetAllInfrastructureScopes.class.getSimpleName());
+
+ if(scopeBean.is(Type.VO)) {
+ logger.info("It is a {} scope", Type.VO);
+ logger.warn("The Catalogue can't work at {} level, I'm overriding the scope to {} level", Type.VO, Type.INFRASTRUCTURE);
+ fullScope = fullScope.substring(0, fullScope.indexOf("/"));
+ logger.info("Overriden the input scope {} with {} type: {}", fullScope, Type.INFRASTRUCTURE, fullScope);
+ }
+
+ }catch (Exception e) {
+ e.printStackTrace();
}
-
- System.out.println("Total VRE is: "+vreNameFullScope.size());
}