diff --git a/pom.xml b/pom.xml index 69ff262..f57913a 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,11 @@ common-smartgears + + org.gcube.core + common-smartgears-app + + org.gcube.common common-authorization diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingCatalogueApplicationProfilesCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingCatalogueApplicationProfilesCache.java index ee5133f..582f919 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingCatalogueApplicationProfilesCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingCatalogueApplicationProfilesCache.java @@ -6,6 +6,7 @@ package org.gcube.datatransfer.resolver.caches; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import org.gcube.common.scope.api.ScopeProvider; import org.gcube.datatransfer.resolver.catalogue.resource.ApplicationProfileReaderForCatalogueResolver; import org.gcube.datatransfer.resolver.listeners.UriResolverStartupListener; import org.slf4j.Logger; @@ -37,8 +38,10 @@ public class LoadingCatalogueApplicationProfilesCache { public String load(String vreName) throws Exception { - logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" loaded"); - return loadApplicationProfiles(vreName); + logger.info("Loading the cache for vreName: "+vreName); + String fullScope = loadFullScopeByApplicationProfile(vreName); + logger.info("Returning fullScope: "+fullScope+ " for the VRE name: "+vreName); + return fullScope; } }; @@ -57,12 +60,20 @@ public class LoadingCatalogueApplicationProfilesCache { 1, TimeUnit.HOURS).removalListener(removalListener). build(loader); - //PRE-POPULATE CACHE - ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true); - catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope()); + try{ + //PRE-POPULATE CACHE + logger.info("Trying to pre-poluate catalogue resolver cache"); + ScopeProvider.instance.set(UriResolverStartupListener.getContextScope()); + ApplicationProfileReaderForCatalogueResolver appPrCatResolver = new ApplicationProfileReaderForCatalogueResolver(UriResolverStartupListener.getContextScope(), true); + catalogueApplicationProfiles.asMap().putAll(appPrCatResolver.getHashVreNameScope()); - logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" instancied "+catalogueApplicationProfiles); - logger.info("Pre-Loaded cache is: "+catalogueApplicationProfiles.toString()); + logger.info(LoadingCatalogueApplicationProfilesCache.class.getSimpleName() +" instancied"); + logger.info("Pre-Loaded CatalogueApplicationProfiles cache is: "+catalogueApplicationProfiles.asMap().toString()); + }catch(Exception e){ + + }finally{ + + } } @@ -83,7 +94,7 @@ public class LoadingCatalogueApplicationProfilesCache { * @param vreName the vre name * @return the string */ - public static String loadApplicationProfiles(String vreName){ + public static String loadFullScopeByApplicationProfile(String vreName){ String fullScope = null; try { diff --git a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java index a42e720..5d27215 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java +++ b/src/main/java/org/gcube/datatransfer/resolver/caches/LoadingGisViewerApplicationURLCache.java @@ -38,7 +38,7 @@ public class LoadingGisViewerApplicationURLCache { @Override public String load(String scope) throws Exception { - logger.info(LoadingGisViewerApplicationURLCache.class.getSimpleName() +" loaded"); + logger.info("Loading the cache for scope: "+scope); return loadGisViewerApplicationURL(scope); } }; @@ -81,6 +81,11 @@ public class LoadingGisViewerApplicationURLCache { logger.warn("Scope is null or ermpty, skipping loadGisViewerApplicationURL"); ApplicationProfileReader reader = new ApplicationProfileReader(scope, UriResolverStartupListener.getGisViewerProfile().getGenericResource(), UriResolverStartupListener.getGisViewerProfile().getAppId(), false); + + if(reader.getApplicationProfile()==null){ + logger.error("NO Appllication Profile "+UriResolverStartupListener.getGisViewerProfile().getAppId()+" found in the scope: "+scope+", returning null!"); + return null; + } String url = reader.getApplicationProfile().getUrl(); logger.info("With scope "+scope+" loaded the GisViewer Application URL "+url); return url; diff --git a/src/main/java/org/gcube/datatransfer/resolver/listeners/UriResolverStartupListener.java b/src/main/java/org/gcube/datatransfer/resolver/listeners/UriResolverStartupListener.java index 2d393f3..47dddc8 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/listeners/UriResolverStartupListener.java +++ b/src/main/java/org/gcube/datatransfer/resolver/listeners/UriResolverStartupListener.java @@ -20,6 +20,8 @@ import org.gcube.datatransfer.resolver.caches.LoadingGeonetworkInstanceCache; import org.gcube.datatransfer.resolver.caches.LoadingGisViewerApplicationURLCache; import org.gcube.datatransfer.resolver.gis.property.ApplicationProfileGenericResourceReader; import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException; +import org.gcube.smartgears.ContextProvider; +import org.gcube.smartgears.context.application.ApplicationContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,25 +62,29 @@ public class UriResolverStartupListener implements ServletContextListener { */ @Override public void contextInitialized(ServletContextEvent event) { - try { + try { contextScope = loadScopeFromEnvironment(); + ApplicationContext ctx = ContextProvider.get(); + String rootScope = ctx.container().configuration().infrastructure(); + logger.info("The ContextProvider returns the root scope: "+rootScope); } - catch (ServletException e) { + catch (Exception e) { // logger.error(e.getMessage(), e); } gisViewerProfile = loadApplicationProfile(event.getServletContext(), GIS_VIEWER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); geoExplorerProfile = loadApplicationProfile(event.getServletContext(), GEO_EXPLORER_GENERIC_RESOURCE_GCUBE_APPS_PROPERTIES); + //init the caches new LoadingGeonetworkInstanceCache(); new LoadingGisViewerApplicationURLCache(); new LoadingCatalogueApplicationProfilesCache(); logger.info("Context initialized with: "); logger.info("Scope: "+contextScope); - logger.info("GisViewerProfile: "+gisViewerProfile.getAppId() + " "+gisViewerProfile.getGenericResource()); - logger.info("GeoExplorerProfile: "+geoExplorerProfile. getAppId() + " "+geoExplorerProfile.getGenericResource()); + logger.info("GisViewerProfile [ID: "+gisViewerProfile.getAppId() + ", Generic Resource Type: "+gisViewerProfile.getGenericResource()+"]"); + logger.info("GeoExplorerProfile [ID: "+geoExplorerProfile. getAppId() + ", Generic Resource Type: "+geoExplorerProfile.getGenericResource()+"]"); } /* (non-Javadoc) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java index 28c8f1b..5cbd30c 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/GisResolver.java @@ -95,7 +95,7 @@ public class GisResolver { try { if(isGisLink){ - //ScopeProvider.instance.set(scope); + ScopeProvider.instance.set(scope); //ServerParameters geonetworkParams = getCachedServerParameters(scope); GisLayerItem gisLayerItem = getGisLayerForLayerUUID(scope, gisUUID); @@ -157,11 +157,12 @@ public class GisResolver { logger.info("Tentative of recovering gis viewer application hostname from cache for scope: "+scope); String gisViewerAppHostname = LoadingGisViewerApplicationURLCache.getCache().get(scope); if(gisViewerAppHostname==null){ - logger.info("Gis viewer application hostname is null, reading from application profile.."); - String url = LoadingGisViewerApplicationURLCache.loadGisViewerApplicationURL(scope); - LoadingGisViewerApplicationURLCache.getCache().put(scope, url); - logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url); - return url; +// logger.info("Gis viewer application hostname is null, reading from application profile.."); +// String url = LoadingGisViewerApplicationURLCache.loadGisViewerApplicationURL(scope); +// LoadingGisViewerApplicationURLCache.getCache().put(scope, url); +// logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url); +// return url; + throw new Exception("GisViewer Application not found in the scope: "+scope); }else logger.info("Cache for GisViewerApplication end point is not null using it");