fixed GisResolver with caching

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173969 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-11-06 10:45:56 +00:00
parent fabf08829f
commit ff223b3b16
1 changed files with 15 additions and 85 deletions

View File

@ -22,7 +22,6 @@ import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
import org.gcube.datatransfer.resolver.gis.MetadataConverter;
import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem;
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
import org.gcube.datatransfer.resolver.gis.exception.IllegalArgumentException;
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -99,6 +98,7 @@ public class GisResolver {
//ServerParameters geonetworkParams = getCachedServerParameters(scope);
GisLayerItem gisLayerItem = getGisLayerForLayerUUID(scope, gisUUID);
logger.info("wms url is: " + gisLayerItem.getFullWmsUrlRequest());
String wmsRequest = URLEncoder.encode(gisLayerItem.getFullWmsUrlRequest(), UTF_8);
logger.info("encoded WMS url is: " + wmsRequest);
@ -108,8 +108,11 @@ public class GisResolver {
layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8);
logger.info("layer Title encoded is: " + layerTitle);
String gisViewerPortletUrl = LoadingGisViewerApplicationURLCache.getCache().get(scope);
//CHECKING IF THE GisViewer Portlet URL is valid
if(gisViewerPortletUrl==null || gisViewerPortletUrl.isEmpty())
ExceptionManager.throwNotFoundException(req, "GisViewer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help);
String gisViewerPortletUrl = getGisViewerApplicationURL(scope);
logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl);
gisViewerPortletUrl+="?rid="+new Random().nextLong()
+"&wmsrequest="+wmsRequest
@ -124,7 +127,12 @@ public class GisResolver {
if(isGeoExplorerLink){
ScopeProvider.instance.set(scope);
String geoExplorerPortletUrl = getGeoExplorerApplicationURL(scope);
String geoExplorerPortletUrl = LoadingGeoExplorerApplicationURLCache.getCache().get(scope);
//CHECKING IF THE GeoExplorer Portlet URL is valid
if(geoExplorerPortletUrl==null || geoExplorerPortletUrl.isEmpty())
ExceptionManager.throwNotFoundException(req, "GeoExplorer Portlet URL not found in the scope: "+scope +". Please contact the support", this.getClass(), help);
logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl);
geoExplorerPortletUrl+="?rid="+new Random().nextLong()
+"&luuid="+URLEncoder.encode(geoExplorerUUID, UTF_8);
@ -144,32 +152,6 @@ public class GisResolver {
}
/**
* Gets the gis viewer application url.
*
* @param scope the scope
* @return the gis viewer application url
* @throws Exception the exception
*/
protected String getGisViewerApplicationURL(String scope) throws Exception{
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;
throw new Exception("GisViewer Application not found in the scope: "+scope);
}else
logger.info("Cache for GisViewerApplication end point is not null using it");
return gisViewerAppHostname;
}
/**
* Gets the gis layer for layer uuid.
*
@ -181,7 +163,10 @@ public class GisResolver {
protected GisLayerItem getGisLayerForLayerUUID(String scope, String gisUUID) throws Exception{
try {
GeonetworkInstance gi = getCachedGeonetworkInstance(scope);
GeonetworkInstance gi = LoadingGeonetworkInstanceCache.getCache().get(scope);
if(gi==null)
throw new Exception("GeonetworkInstance not instanciable in the scope: "+scope);
GisLayerItem gisLayerItem = MetadataConverter.getWMSOnLineResource(gi, gisUUID);
return gisLayerItem;
//TODO CREATE A BEAN ADDING WMS REQUEST AND LAYER TITLE MetadataConverter.
@ -194,60 +179,5 @@ public class GisResolver {
}
}
/**
* Gets the cached geonetwork instance.
*
* @param scope the scope
* @return the cached geonetwork instance
* @throws Exception the exception
*/
protected GeonetworkInstance getCachedGeonetworkInstance(String scope) throws Exception{
logger.info("Attempt to get the GeonetworkInstance from cache by scope: "+scope);
GeonetworkInstance geonInstance = LoadingGeonetworkInstanceCache.getCache().get(scope);
if(geonInstance==null){
logger.info("GeonetworkInstance is null in cache, reading from library...");
try {
geonInstance = LoadingGeonetworkInstanceCache.loadGeonetworkInstance(scope);
LoadingGeonetworkInstanceCache.getCache().put(scope, geonInstance);
logger.info("Updated GeonetworkInstance cache! Scope "+scope+" linking "+geonInstance);
} catch (Exception e) {
logger.error("An error occurred on getting GeonetworkInstance for scope: "+scope, e);
throw new Exception("Sorry, An error occurred on getting GeonetworkInstance for scope: "+scope);
}
}else
logger.info("GeonetworkInstance is not null using it");
logger.info("returning GeonetworkInstance: "+geonInstance);
return geonInstance;
}
/**
* Gets the geo explorer application url.
*
* @param scope the scope
* @return the geo explorer application url
* @throws Exception the exception
*/
protected String getGeoExplorerApplicationURL(String scope) throws Exception{
logger.info("Tentative of recovering geo explorer application hostname from cache for scope: "+scope);
String geoExplorerApplicationHostname = LoadingGeoExplorerApplicationURLCache.getCache().get(scope);
if(geoExplorerApplicationHostname==null){
logger.info("GeoExplorer application hostname is null, reading from application profile..");
String url = LoadingGeoExplorerApplicationURLCache.loadGeoExplorerApplicationURL(scope);
LoadingGeoExplorerApplicationURLCache.getCache().put(scope, url);
logger.info("Updated GeoExplorerApplication cache! Scope "+scope+" linking "+url);
return url;
}else
logger.info("Cache for GeoExplorerApplication end point is not null using it");
return geoExplorerApplicationHostname;
}
}