Added layer title to uri built by GisResolver in order to display it in GisViewer App

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@148783 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-05-17 13:27:01 +00:00
parent e6dfb6c1bd
commit a2cfc02f48
3 changed files with 66 additions and 13 deletions

View File

@ -21,6 +21,7 @@ import org.apache.commons.io.IOUtils;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
import org.gcube.datatransfer.resolver.gis.GeonetworkAccessParameter.GeonetworkLoginLevel;
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.gis.property.ApplicationProfileGenericResourcePropertyReader;
@ -304,16 +305,25 @@ public class GisResolver extends HttpServlet{
//ScopeProvider.instance.set(scope);
//ServerParameters geonetworkParams = getCachedServerParameters(scope);
String wmsRequest = getLayerWmsRequest(scope, gisUUID);
logger.info("wms url is: " + wmsRequest);
wmsRequest = URLEncoder.encode(wmsRequest, UTF_8);
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);
String layerTitle = null;
if(gisLayerItem.getCitationTitle()!=null && !gisLayerItem.getCitationTitle().isEmpty())
layerTitle = URLEncoder.encode(gisLayerItem.getCitationTitle(), UTF_8);
logger.info("layer Title encoded is: " + layerTitle);
String gisViewerPortletUrl = getGisViewerApplicationURL(scope);
logger.info("Gis Viewer Application url is: " + gisViewerPortletUrl);
gisViewerPortletUrl+="?rid="+new Random().nextLong()
+"&wmsrequest="+wmsRequest
+"&uuid="+URLEncoder.encode(gisUUID, "UTF-8");
+"&uuid="+URLEncoder.encode(gisUUID, UTF_8);
if(layerTitle!=null)
gisViewerPortletUrl+="&layertitle="+layerTitle;
/*resp.setContentType(TEXT_PLAIN);
resp.setCharacterEncoding(UTF_8);
@ -321,6 +331,7 @@ public class GisResolver extends HttpServlet{
out.println(gisPortletUrl);
logger.info("returning link: " + gisPortletUrl);
out.close();*/
logger.info("Redirecting to: "+gisViewerPortletUrl);
urlRedirect(req, resp, gisViewerPortletUrl);
}
@ -329,7 +340,7 @@ public class GisResolver extends HttpServlet{
String geoExplorerPortletUrl = getGeoExplorerApplicationURL(scope);
logger.info("GeoExplorer Application url is: " + geoExplorerPortletUrl);
geoExplorerPortletUrl+="?rid="+new Random().nextLong()
+"&luuid="+URLEncoder.encode(geoExplorerUUID, "UTF-8");
+"&luuid="+URLEncoder.encode(geoExplorerUUID, UTF_8);
urlRedirect(req, resp, geoExplorerPortletUrl);
}
@ -387,18 +398,20 @@ public class GisResolver extends HttpServlet{
/**
* Gets the layer wms request.
* Gets the gis layer for layer uuid.
*
* @param scope the scope
* @param gisUUID the gis uuid
* @return the layer wms request
* @return the gis layer for layer uuid
* @throws Exception the exception
*/
protected String getLayerWmsRequest(String scope, String gisUUID) throws Exception{
protected GisLayerItem getGisLayerForLayerUUID(String scope, String gisUUID) throws Exception{
try {
GeonetworkInstance gi = getCachedGeonetworkInstance(scope);
return MetadataConverter.getWMSOnLineResource(gi, gisUUID);
GisLayerItem gisLayerItem = MetadataConverter.getWMSOnLineResource(gi, gisUUID);
return gisLayerItem;
//TODO CREATE A BEAN ADDING WMS REQUEST AND LAYER TITLE MetadataConverter.
}catch (GeonetworkInstanceException e){
logger.error("An error occurred when instancing geonetowrk gis layer with UUID "+gisUUID, e);
throw new IllegalArgumentException("Sorry, An error occurred when instancing geonetwork with UUID: "+gisUUID);

View File

@ -3,10 +3,13 @@ package org.gcube.datatransfer.resolver.gis;
import java.util.Collection;
import org.gcube.datatransfer.resolver.gis.entity.GeoserverBaseUri;
import org.gcube.datatransfer.resolver.gis.entity.GisLayerItem;
import org.gcube.datatransfer.resolver.gis.util.HttpRequestUtil;
import org.opengis.metadata.Metadata;
import org.opengis.metadata.citation.Citation;
import org.opengis.metadata.citation.OnlineResource;
import org.opengis.metadata.distribution.DigitalTransferOptions;
import org.opengis.metadata.identification.Identification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -108,13 +111,15 @@ public class MetadataConverter {
* @return the WMS on line resource
* @throws Exception the exception
*/
public static String getWMSOnLineResource(GeonetworkInstance geonetowrkInstance, String uuid) throws Exception{
public static GisLayerItem getWMSOnLineResource(GeonetworkInstance geonetowrkInstance, String uuid) throws Exception{
String fullWmsPath = "";
boolean foundGeoserverUrl = false;
String layerName = "";
//IT IS LAYER TITLE
String citationTitle = null;
try{
logger.trace("geonetowrkInstance is null? "+(geonetowrkInstance==null));
Metadata meta = geonetowrkInstance.getGeonetworkPublisher().getById(uuid);
@ -160,12 +165,29 @@ public class MetadataConverter {
}
}
}
if(meta.getIdentificationInfo()!=null){
// logger.trace("found Identification Info size: "+meta.getIdentificationInfo().size());
for (Identification info : meta.getIdentificationInfo()) {
if(info!=null){
Citation citation = info.getCitation();
if(citation!=null){
citationTitle = citation.getTitle() != null? citation.getTitle().toString():"";
// logger.trace("found citation Title: "+citationTitle);
}else
logger.info("Title is null for: "+uuid);
}
}
}
}catch(Exception e){
logger.error("getWMSOnLineResource with UUID "+uuid + " has thrown exception: ",e);
throw new Exception("An error occurred when converting layer with UUID "+uuid);
}
logger.trace("returning: "+fullWmsPath);
return fullWmsPath;
GisLayerItem gisLI = new GisLayerItem(uuid, citationTitle, layerName, "", fullWmsPath);
logger.debug("returning: "+gisLI);
return gisLI;
}
/*

View File

@ -30,6 +30,24 @@ public class GisLayerItem {
private String versionWMS;
private String setCrsWMS;
/**
* Instantiates a new gis layer item.
*
* @param uuid the uuid
* @param citationTitle the citation title
* @param layerName the layer name
* @param baseWmsServiceUrl the base wms service url
* @param fullWmsUrlRequest the full wms url request
*/
public GisLayerItem(String uuid, String citationTitle, String layerName, String baseWmsServiceUrl, String fullWmsUrlRequest) {
this.uuid = uuid;
this.citationTitle = citationTitle;
this.layerName = layerName;
this.baseWmsServiceUrl = baseWmsServiceUrl;
this.fullWmsUrlRequest = fullWmsUrlRequest;
}
/**
* Instantiates a new gis layer item.
*