2087: Geo improvements: moving geo-utility dependecy from geo-explorer to gisviewer

Task-Url: https://support.d4science.org/issues/2087

GisViewer integrated with geo-utility

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gis-viewer@122604 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-01-28 15:28:49 +00:00
parent 7bc46f05e1
commit f2a71a9c94
10 changed files with 838 additions and 81 deletions

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
@ -18,10 +23,5 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -4,6 +4,8 @@
<Change>[Feature: #2034] Added method to get gcube token for WPS
service
</Change>
<Change>[Feature: #2087] Integrated with geo-utility
</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.GISViewer.3-9-0"
date="2016-01-04">

View File

@ -118,6 +118,12 @@
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>geo-utility</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>

View File

@ -12,6 +12,7 @@ import org.gcube.portlets.user.gisviewer.client.commons.beans.DataResult;
import org.gcube.portlets.user.gisviewer.client.commons.beans.ExportFormat;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GeoserverItem;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerBaseLayerInterface;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerWmsValidParameters;
import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItem;
import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItemsResult;
import org.gcube.portlets.user.gisviewer.client.commons.beans.MapViewInfo;
@ -44,6 +45,7 @@ import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
@ -101,7 +103,7 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 28, 2015
*/
public enum LayerType {RASTER, FEATURETYPE};
public enum LayerType {RASTER_BASELAYER, FEATURE_TYPE};
//SHOW INTRO
private boolean first = true;
public static Resources resources = GWT.create(Resources.class);
@ -403,7 +405,9 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
* @param isBase the is base
* @param displayInLayerSwitcher the display in layer switcher
* @param UUID the uuid
* {@link #addLayerByWmsRequest(LayerType, String, String, String, boolean, boolean, String, boolean)}
*/
@Deprecated
public void addLayerByWms(String layerTitle, String layerName, String wmsRequest, boolean isBase, boolean displayInLayerSwitcher, String UUID) {
if(wmsRequest.contains("?")){ //IS FULL REQUEST
@ -414,7 +418,8 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
wmsUrlValidator.parseWmsRequest(false, true);
HashMap<String, String> mapWmsNotStandard = new HashMap<String, String>(wmsUrlValidator.getMapWmsNotStandardParams().size());
mapWmsNotStandard.putAll(wmsUrlValidator.getMapWmsNotStandardParams());
addLayerByWms(LayerType.FEATURETYPE, layerTitle, layerName, wmsUrlValidator.getBaseWmsServiceUrl(), true, false, false, (ArrayList<String>) wmsUrlValidator.getStylesAsList(), wmsRequest, false, mapWmsNotStandard, mapWmsNotStandard.size()>0, UUID);
LayerType featureType = isBase?LayerType.RASTER_BASELAYER:LayerType.FEATURE_TYPE;
addLayerByWms(featureType, layerTitle, layerName, wmsUrlValidator.getBaseWmsServiceUrl(), true, isBase, displayInLayerSwitcher, (ArrayList<String>) wmsUrlValidator.getStylesAsList(), wmsRequest, false, mapWmsNotStandard, mapWmsNotStandard.size()>0, UUID);
} catch (Exception e) {
e.printStackTrace();
Window.alert("Sorry an error occurred during layer parsing, check your wms request");
@ -422,10 +427,45 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
}else{ //IS ONLY GEOSERVER REQUEST
GWT.log("WmsRequest string has not '?', no parameter available");
addLayerByWms(LayerType.FEATURETYPE, layerTitle, layerName, wmsRequest, true, false, false, null, "", false, null, false, UUID);
addLayerByWms(LayerType.FEATURE_TYPE, layerTitle, layerName, wmsRequest, true, false, false, null, "", false, null, false, UUID);
}
}
/**
* Adds the layer by wms request.
*
* @param layerTitle the layer title
* @param layerName the layer name
* @param wmsRequest the wms request
* @param isBase the is base
* @param displayInLayerSwitcher the display in layer switcher
* @param UUID the uuid
* @param onTop the on top
*/
public void addLayerByWmsRequest(final String layerTitle, final String layerName, final String wmsRequest, final boolean isBase,final boolean displayInLayerSwitcher, final String UUID, final boolean onTop) {
final LayerType featureType = isBase?LayerType.RASTER_BASELAYER:LayerType.FEATURE_TYPE;
layersPanel.mask("Adding..."+layerName, "x-mask-loading");
// Info.display("Adding Layer", layerName);
GisViewer.service.parseWmsRequest(wmsRequest, layerName, new AsyncCallback<GisViewerWmsValidParameters>() {
@Override
public void onFailure(Throwable caught) {
layersPanel.unmask();
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(GisViewerWmsValidParameters result) {
layersPanel.unmask();
addLayerByWms(featureType, layerTitle, layerName, result.getBaseWmsServiceHost(), true, isBase, displayInLayerSwitcher, (ArrayList<String>) result.getStyles(), result.getWmsRequest(), false, result.getMapWMSNoStandard(), result.isNcWMS(), UUID);
}
});
}
/**
* Adds the layers on map.
*
@ -1025,32 +1065,6 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
List<GeoserverItem> geoserverItems = new ArrayList<GeoserverItem>();
boolean found;
/* //COMMENTED BY FRANCESCO M. 17/09/2014
for (LayerItem layerItem : layerItems) {
// FIXME: now the "fifao_*" layers were not considerated beacause they belong to fao datastore
if (forData && (layerItem.isExternal() || layerItem.getName().substring(0, 6).equals(Constants.FAO_DATA_STORE_PREFIX)))
; // do nothing, the layer is skipped
else {
found = false;
for (GeoserverItem geoserverItem : geoserverItems)
if (layerItem.getGeoserverWmsUrl().equals(geoserverItem.getUrl())) {
geoserverItem.addLayerItem(layerItem);
found = true;
break;
}
if (!found) {
GeoserverItem geoserverItem = (forData ?
new GeoserverItem(layerItem.getGeoserverUrl()) :
new GeoserverItem(layerItem.getGeoserverWmsUrl())
);
geoserverItem.addLayerItem(layerItem);
geoserverItems.add(geoserverItem);
}
}
}*/
//CHANGED BY FRANCESCO M. 17/09/2014
for (LayerItem layerItem : layerItems) {
found = false;
@ -1193,7 +1207,7 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
* @param isNcWms the is nc wms
* @param UUID the uuid
*/
public void addLayerByWms(LayerType layerType, String layerTitle, String layerName, String wmsServiceBaseUrl, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, ArrayList<String> styles, String serverWmsRequest, boolean onTop, HashMap<String, String> wmsNotStandardParams, boolean isNcWms, String UUID) {
private void addLayerByWms(LayerType layerType, String layerTitle, String layerName, String wmsServiceBaseUrl, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, ArrayList<String> styles, String serverWmsRequest, boolean onTop, HashMap<String, String> wmsNotStandardParams, boolean isNcWms, String UUID) {
// GWT.log("Add addLayerByWms 1");
LayerItem l = new LayerItem();
@ -1215,7 +1229,7 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
switch (layerType) {
//TODO IMPLEMENT THIS CASE
case RASTER:
case RASTER_BASELAYER:
// l.setHasLegend(false);
l.setBaseLayer(true);
@ -1223,7 +1237,7 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
l.setClickData(false);
break;
case FEATURETYPE:
case FEATURE_TYPE:
//CASE FEATURE TYPE
l.setBaseLayer(false);
@ -1256,46 +1270,6 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
layersPanel.updateLayersOrder();
}
/**
* by Francesco M.
*
* @param layers the layers
*/
/*public void addLayerItemsByWms(LayerType layerType, List<LayerItem> listLayerItem, boolean onTop) {
GWT.log("Add addLayerByWms 2");
for (LayerItem l : listLayerItem) {
switch (layerType) {
//TODO IMPLEMENT THIS CASE
case RASTER:
l.setHasLegend(false);
l.setBaseLayer(true);
l.setTrasparent(false);
l.setClickData(false);
break;
case FEATURETYPE:
//CASE FEATURE TYPE
l.setBaseLayer(false);
l.setClickData(true);
l.setTrasparent(true);
break;
}
openLayersMap.addLayerItemByWms(l, false);
}
layersPanel.addLayerItems(listLayerItem, onTop);
layersPanel.updateLayersOrder();
}*/
/**
* by Francesco M.
*

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.gcube.portlets.user.gisviewer.client.commons.beans.DataResult;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerBaseLayerInterface;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerWmsValidParameters;
import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItem;
import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItemsResult;
import org.gcube.portlets.user.gisviewer.client.commons.beans.Property;
@ -116,4 +117,15 @@ public interface GisViewerService extends RemoteService {
*/
String getGcubeSecurityToken() throws Exception;
/**
* Parses the wms request.
*
* @param wmsRequest the wms request
* @param layerName the layer name
* @return the gis viewer wms valid parameters
* @throws Exception the exception
*/
GisViewerWmsValidParameters parseWmsRequest(String wmsRequest, String layerName) throws Exception;
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.gcube.portlets.user.gisviewer.client.commons.beans.DataResult;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerBaseLayerInterface;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerWmsValidParameters;
import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItem;
import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItemsResult;
import org.gcube.portlets.user.gisviewer.client.commons.beans.Property;
@ -116,6 +117,17 @@ public interface GisViewerServiceAsync {
*/
void parseWmsRequest(WmsRequest request, AsyncCallback<String> callback);
/**
* Parses the wms request.
*
* @param wmsRequest the wms request
* @param layerName the layer name
* @param callback the callback
*/
void parseWmsRequest(String wmsRequest, String layerName,
AsyncCallback<GisViewerWmsValidParameters> callback);
/**
* Gets the gcube security token.
*
@ -123,4 +135,9 @@ public interface GisViewerServiceAsync {
* @return the gcube security token
*/
void getGcubeSecurityToken(AsyncCallback<String> callback);
}

View File

@ -0,0 +1,236 @@
/**
*
*/
package org.gcube.portlets.user.gisviewer.client.commons.beans;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
/**
* The Class GisViewerWmsValidParameters.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 28, 2016
*/
public class GisViewerWmsValidParameters implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8871057872297550295L;
private String baseWmsServiceHost;
private String wmsRequest;
private String layerName;
private String versionWMS;
private String crs;
private HashMap<String, String> mapWMSNoStandard;
private List<String> styles;
private boolean isNcWMS;
/**
* Instantiates a new gis viewer wms valid parameters.
*/
public GisViewerWmsValidParameters() {
// TODO Auto-generated constructor stub
}
/**
* Instantiates a new gis viewer wms valid parameters.
*
* @param baseWmsServiceHost the base wms service host
* @param wmsRequest the wms request
* @param layerName the layer name
* @param versionWms the version wms
* @param crs the crs
* @param mapWmsNotStandard the map wms not standard
* @param styles the styles
* @param isNcWms the is nc wms
*/
public GisViewerWmsValidParameters(String baseWmsServiceHost, String wmsRequest, String layerName, String versionWms, String crs, HashMap<String, String> mapWmsNotStandard, List<String> styles, boolean isNcWms) {
this.baseWmsServiceHost = baseWmsServiceHost;
this.wmsRequest = wmsRequest;
this.layerName = layerName;
this.versionWMS = versionWms;
this.crs = crs;
this.mapWMSNoStandard = mapWmsNotStandard;
this.styles = styles;
this.isNcWMS = isNcWms;
}
/**
* Gets the base wms service host.
*
* @return the baseWmsServiceHost
*/
public String getBaseWmsServiceHost() {
return baseWmsServiceHost;
}
/**
* @return the wmsRequest
*/
public String getWmsRequest() {
return wmsRequest;
}
/**
* @return the layerName
*/
public String getLayerName() {
return layerName;
}
/**
* @return the versionWMS
*/
public String getVersionWMS() {
return versionWMS;
}
/**
* @return the crs
*/
public String getCrs() {
return crs;
}
/**
* @return the mapWMSNoStandard
*/
public HashMap<String, String> getMapWMSNoStandard() {
return mapWMSNoStandard;
}
/**
* @return the styles
*/
public List<String> getStyles() {
return styles;
}
/**
* @return the isNcWMS
*/
public boolean isNcWMS() {
return isNcWMS;
}
/**
* @param baseWmsServiceHost the baseWmsServiceHost to set
*/
public void setBaseWmsServiceHost(String baseWmsServiceHost) {
this.baseWmsServiceHost = baseWmsServiceHost;
}
/**
* @param wmsRequest the wmsRequest to set
*/
public void setWmsRequest(String wmsRequest) {
this.wmsRequest = wmsRequest;
}
/**
* @param layerName the layerName to set
*/
public void setLayerName(String layerName) {
this.layerName = layerName;
}
/**
* @param versionWMS the versionWMS to set
*/
public void setVersionWMS(String versionWMS) {
this.versionWMS = versionWMS;
}
/**
* @param crs the crs to set
*/
public void setCrs(String crs) {
this.crs = crs;
}
/**
* @param mapWMSNoStandard the mapWMSNoStandard to set
*/
public void setMapWMSNoStandard(HashMap<String, String> mapWMSNoStandard) {
this.mapWMSNoStandard = mapWMSNoStandard;
}
/**
* @param styles the styles to set
*/
public void setStyles(List<String> styles) {
this.styles = styles;
}
/**
* @param isNcWMS the isNcWMS to set
*/
public void setNcWMS(boolean isNcWMS) {
this.isNcWMS = isNcWMS;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GisViewerWmsValidParameters [baseWmsServiceHost=");
builder.append(baseWmsServiceHost);
builder.append(", wmsRequest=");
builder.append(wmsRequest);
builder.append(", layerName=");
builder.append(layerName);
builder.append(", versionWMS=");
builder.append(versionWMS);
builder.append(", crs=");
builder.append(crs);
builder.append(", mapWMSNoStandard=");
builder.append(mapWMSNoStandard);
builder.append(", styles=");
builder.append(styles);
builder.append(", isNcWMS=");
builder.append(isNcWMS);
builder.append("]");
return builder.toString();
}
}

View File

@ -20,6 +20,7 @@ import org.gcube.portlets.user.gisviewer.client.Constants;
import org.gcube.portlets.user.gisviewer.client.GisViewerService;
import org.gcube.portlets.user.gisviewer.client.commons.beans.DataResult;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerBaseLayerInterface;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerWmsValidParameters;
import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItem;
import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItemsResult;
import org.gcube.portlets.user.gisviewer.client.commons.beans.Property;
@ -30,6 +31,8 @@ import org.gcube.portlets.user.gisviewer.client.commons.utils.URLMakers;
import org.gcube.portlets.user.gisviewer.server.datafeature.ClickDataParser;
import org.gcube.portlets.user.gisviewer.server.datafeature.FeatureParser;
import org.gcube.portlets.user.gisviewer.server.datafeature.FeatureTypeParser;
import org.gcube.spatial.data.geoutility.GeoGetStylesUtility;
import org.gcube.spatial.data.geoutility.bean.WmsParameters;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@ -117,6 +120,38 @@ public abstract class GisViewerServiceImpl extends RemoteServiceServlet implemen
return result;
}
@Override
public GisViewerWmsValidParameters parseWmsRequest(String wmsRequest, String layerName) throws Exception{
try {
GisViewerWMSUrlValidator validator = new GisViewerWMSUrlValidator(wmsRequest, layerName);
String wmsServiceHost = validator.getWmsServiceHost();
String validWMSRequest = validator.parseWMSRequest(true, true);
layerName = validator.getLayerName();
String versionWms = validator.getValueOfParsedWMSParameter(WmsParameters.VERSION);
String crs = validator.getValueOfParsedWMSParameter(WmsParameters.CRS);
//
HashMap<String, String> mapWmsNotStandard = new HashMap<String, String>();
if(validator.getMapWmsNoStandardParams()!=null){
mapWmsNotStandard.putAll(validator.getMapWmsNoStandardParams());
}
//
GeoGetStylesUtility geoGS = new GeoGetStylesUtility(validWMSRequest, validator.getUrlValidator());
mapWmsNotStandard.putAll(geoGS.getMapNcWmsStyles());
List<String> styles = geoGS.getGeoStyles();
boolean isNcWms = geoGS.isNcWms();
return new GisViewerWmsValidParameters(wmsServiceHost, validWMSRequest, layerName, versionWms, crs, mapWmsNotStandard, styles, isNcWms);
}
catch (Exception e) {
String msg = "An error occurred during wms request validation for layer: "+layerName;
logger.error(msg,e);
throw new Exception(msg);
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.gisviewer.client.GisViewerService#getGroupsInfo(java.lang.String)
*/
@ -142,10 +177,9 @@ public abstract class GisViewerServiceImpl extends RemoteServiceServlet implemen
return getLayersInfo(groupRest.getLayers());
} catch (Exception e) {
System.out.println("gisViewer EXCEPTION: Error in getGroupInfo. Message=\""+e.getMessage()+"\"");
System.out.println("geoserver_url="+gsUrl);
System.out.println("Stacktrace: "+e.getStackTrace());
e.printStackTrace();
logger.error("gisViewer EXCEPTION: Error in getGroupInfo. Message=\""+e.getMessage()+"\"");
logger.error("geoserver_url="+gsUrl);
logger.error("Stacktrace: ",e);
return null;
}
}

View File

@ -0,0 +1,388 @@
package org.gcube.portlets.user.gisviewer.server;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.gcube.spatial.data.geoutility.GeoWmsServiceUtility;
import org.gcube.spatial.data.geoutility.bean.WmsParameters;
import org.gcube.spatial.data.geoutility.util.HttpRequestUtil;
import org.gcube.spatial.data.geoutility.wms.WmsUrlValidator;
/**
* The Class GisViewerWMSUrlValidator.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 28, 2016
*/
public class GisViewerWMSUrlValidator {
public static final String GEOSERVER = "/geoserver";
private static final String WMS = "wms";
private static final String OWS = "ows";
private HashMap<String, String> parametersValue = new HashMap<String, String>();
private String wmsRequestURI;
private String wmsServiceHost;
private String layerName;
private String wmsNoStandardParameters = "";
private Map<String, String> mapWmsNoStandardParams;
private WmsUrlValidator urlValidator;
public static Logger logger = Logger.getLogger(GisViewerWMSUrlValidator.class);
/**
* Instantiates a new gis viewer wms url validator.
*
* @param wmsRequest the full url
* @param layerName the layer name
* @throws Exception the exception
*/
public GisViewerWMSUrlValidator(String wmsRequest, String layerName) throws Exception{
if(wmsRequest==null || wmsRequest.isEmpty())
throw new Exception("WMS request is null or empty");
this.wmsRequestURI = wmsRequest.trim();
boolean isOwsService = GeoWmsServiceUtility.isOWSSerice(this.wmsRequestURI);
WebMapServerHost webMapServerHost;
//IS WMS?
if(GeoWmsServiceUtility.isWMSService(wmsRequestURI)){
logger.trace("found "+GeoWmsServiceUtility.SERVICE_WMS+" in wms request: "+wmsRequestURI);
webMapServerHost = getWebMapServerHost(wmsRequestURI);
}else
throw new Exception("WMS service not found for layer: "+layerName);
//VALIDATION WMS
String baseWmsService = webMapServerHost.getHost();
//IS OWS OR WMS?
this.wmsServiceHost = appendWmsServiceToBaseUrl(wmsRequest.substring(0, wmsRequest.indexOf("?")),isOwsService);
this.layerName = layerName;
try {
//VALIDATE WMS SERVICE FOR WEB MAP SERVER
if(!HttpRequestUtil.urlExists(this.wmsServiceHost, true)){
logger.info("baseWmsServiceUrl: "+wmsServiceHost +" is not a geoserver, setting as input base wms server: "+baseWmsService);
this.wmsServiceHost = baseWmsService;
}
} catch (Exception e) {
logger.error("error on validating geoserver wms service: "+e);
logger.info("setting baseWmsService as input base wms server: "+baseWmsService);
this.wmsServiceHost = baseWmsService;
}
//VALIDATION FOR THREDDS - FIND LAYER NAME INTO WMS PATH
if(this.layerName==null || this.layerName.isEmpty()){
this.layerName = WmsUrlValidator.getValueOfParameter(WmsParameters.LAYERS, wmsRequest);
if(this.layerName==null || layerName.isEmpty())
throw new Exception("Layer name is null or empty");
}
parametersValue.put(WmsParameters.LAYERS.getParameter(), this.layerName);
}
/**
* Append wms service to base url.
*
* @param url the url
* @param isOwsServer the is ows server
* @return the string
*/
public String appendWmsServiceToBaseUrl(String url, boolean isOwsServer){
if(url.contains("/"+WMS) || url.contains("/"+OWS))
return url;
if(url.lastIndexOf("/") != url.length()){
url+="/";
}
if(isOwsServer)
return url+=OWS;
else
return url+=WMS;
}
/**
* Method: getFullWmsUrlRequest
* Create a correct wms url request
* Returns:
* {String}.
*
* @param returnEmptyParameter if true the wms url returned contains also wms parameter with empty value, none otherwise.
* and mandatory wms parameters that does not found are filled with empty values
* @param fillEmptyParameterAsDefault the fill empty parameter as default
* @return a correct wms url request in formatted string like this:
* "wmsserver?key1=value1&key2=value2&key3=value3"
*/
public String parseWMSRequest(boolean returnEmptyParameter, boolean fillEmptyParameterAsDefault){
urlValidator = new org.gcube.spatial.data.geoutility.wms.WmsUrlValidator(wmsRequestURI);
String fullWmsUrlBuilded;
try {
fullWmsUrlBuilded = urlValidator.parseWmsRequest(returnEmptyParameter, fillEmptyParameterAsDefault);
parametersValue.putAll(urlValidator.getMapWmsParameters());
String ln = parametersValue.get(WmsParameters.LAYERS);
logger.trace("Compare layers name from Wms request: "+ln +", with OnLineResource layerName: "+this.layerName);
if(ln==null || ln.isEmpty() || ln.compareTo(this.layerName)!=0){
logger.info("Layers name into wms request is different to saved layers name, adding layers name: "+this.layerName);
parametersValue.put(WmsParameters.LAYERS.getParameter(), this.layerName);
urlValidator.getMapWmsParameters().put(org.gcube.spatial.data.geoutility.bean.WmsParameters.LAYERS.getParameter(), this.layerName);
fullWmsUrlBuilded = org.gcube.spatial.data.geoutility.wms.WmsUrlValidator.setValueOfParameter(org.gcube.spatial.data.geoutility.bean.WmsParameters.LAYERS, fullWmsUrlBuilded, this.layerName, true);
}
// logger.trace("parametersValue: "+parametersValue);
mapWmsNoStandardParams = new HashMap<String, String>(urlValidator.getMapWmsNoStandardParams().size());
mapWmsNoStandardParams.putAll(urlValidator.getMapWmsNoStandardParams());
wmsNoStandardParameters = urlValidator.getWmsNoStandardParameters();
}
catch (Exception e) {
logger.error("An error occurred during wms uri build, returning uri: "+wmsRequestURI, e);
fullWmsUrlBuilded = wmsRequestURI;
}
logger.trace("returning full wms url: "+fullWmsUrlBuilded);
return fullWmsUrlBuilded;
}
/**
* Gets the web map server host.
*
* @param wmsRequest the wms request
* @return the web map server host, (geoserver URI or the wmsRequest substring from start to index of '?' char (if exists))
*/
public WebMapServerHost getWebMapServerHost(String wmsRequest){
WebMapServerHost geoserverBaseUri = new WebMapServerHost();
if(wmsRequest==null)
return geoserverBaseUri; //uri is empty
int end = wmsRequest.toLowerCase().lastIndexOf("?");
if(end==-1){
logger.trace("char ? not found in geoserver uri, return: "+wmsRequest);
return geoserverBaseUri; //uri is empty
}
String geoserverUrl = wmsRequest.substring(0, wmsRequest.toLowerCase().lastIndexOf("?"));
int index = geoserverUrl.lastIndexOf(GEOSERVER);
if(index>-1){ //FOUND the string GEOSERVER into URL
logger.trace("found geoserver string: "+GEOSERVER+" in "+geoserverUrl);
//THERE IS SCOPE?
int lastSlash = geoserverUrl.lastIndexOf("/");
int includeGeoserverString = index+GEOSERVER.length();
int endUrl = lastSlash>includeGeoserverString?lastSlash:includeGeoserverString;
logger.trace("indexs - lastSlash: ["+lastSlash+"], includeGeoserverString: ["+includeGeoserverString+"], endUrl: ["+endUrl+"]");
int startScope = includeGeoserverString+1<endUrl?includeGeoserverString+1:endUrl; //INCLUDE SLASH
String scope = geoserverUrl.substring(startScope, endUrl);
logger.trace("geoserver url include scope: "+geoserverUrl.substring(includeGeoserverString, endUrl));
geoserverBaseUri.setHost(geoserverUrl.substring(0, endUrl));
geoserverBaseUri.setScope(scope);
return geoserverBaseUri;
}else{
logger.trace("the string 'geoserver' not found in "+geoserverUrl);
// GET LAST INDEX OF '/' AND CONCATENATE GEOSERVER
String urlConn = geoserverUrl.substring(0, geoserverUrl.lastIndexOf("/"))+GEOSERVER;
logger.trace("tentative concatenating string 'geoserver' at http url "+urlConn);
try {
if(HttpRequestUtil.urlExists(urlConn, false)){
logger.trace("url: "+urlConn+" - open a connection, return "+urlConn);
geoserverBaseUri.setHost(urlConn);
return geoserverBaseUri;
}
else
logger.trace("url: "+urlConn+" - not open a connection");
} catch (Exception e) {
logger.error("url connection is wrong at :"+urlConn);
}
String uriWithoutParameters = wmsRequest.substring(0, end);
logger.trace("url connection, returned: "+uriWithoutParameters);
geoserverBaseUri.setHost(uriWithoutParameters);
return geoserverBaseUri;
}
}
/**
* Gets the wms service host.
*
* @return the wms service host
*/
public String getWmsServiceHost() {
return wmsServiceHost;
}
/**
* Gets the url validator.
*
* @return the urlValidator
*/
public org.gcube.spatial.data.geoutility.wms.WmsUrlValidator getUrlValidator() {
return urlValidator;
}
/**
* Gets the wms no standard parameters.
*
* @return the wms no standard parameters
*/
public String getWmsNoStandardParameters() {
return wmsNoStandardParameters;
}
/**
* Gets the value of parsed wms parameter.
*
* @param parameter the parameter
* @return the value of parsed wms parameter parsed from wms request.
*/
public String getValueOfParsedWMSParameter(WmsParameters parameter){
return parametersValue.get(parameter.getParameter());
}
/**
* Gets the value of parameter.
*
* @param wmsParam the wms param
* @param wmsUrlParameters the wms url parameters
* @return the value of parameter
*/
public static String getValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters){
return WmsUrlValidator.getValueOfParameter(wmsParam, wmsUrlParameters);
}
/**
* Sets the value of parameter.
*
* @param wmsParam the wms param
* @param wmsUrlParameters the wms url parameters
* @param newValue the new value
* @param addIfNotExists the add if not exists
* @return the string
*/
public static String setValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters, String newValue, boolean addIfNotExists){
return WmsUrlValidator.setValueOfParameter(wmsParam, wmsUrlParameters, newValue, addIfNotExists);
}
/**
* Gets the layer name.
*
* @return the layer name
*/
public String getLayerName() {
return layerName;
}
/**
* Gets the styles as list.
*
* @return the styles as list
*/
public List<String> getStylesAsList() {
List<String> listStyles = new ArrayList<String>();
String styles = getValueOfParsedWMSParameter(WmsParameters.STYLES);
if(styles!=null && !styles.isEmpty()){
String[] arrayStyle = styles.split(",");
for (String style : arrayStyle) {
if(style!=null && !style.isEmpty())
listStyles.add(style);
}
}
return listStyles;
}
/**
* Gets the map wms no standard params.
*
* @return the map wms no standard params
*/
public Map<String, String> getMapWmsNoStandardParams() {
return mapWmsNoStandardParams;
}
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
// String baseGeoserverUrl = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows";
// String baseGeoserverUrl = "http://www.fao.org/figis/geoserver/species";
// String fullPath = "http://www.fao.org/figis/geoserver/species?SERVICE=WMS&BBOX=-176.0,-90.0,180.0,90&styles=Species_prob, puppa&layers=layerName&FORMAT=image/gif";
// String fullPath = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows?service=wms&version=1.1.0&request=GetMap&layers==IGG:area_temp_1000&width=676&height=330&srs=EPSG:4326&crs=EPSG:4326&format=application/openlayers&bbox=-85.5,-180.0,90.0,180.0";
// String baseGeoserverUrl = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc";
// String fullPath = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&bbox=-85.0,-180.0,85.0,180.0&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto";
// WmsUrlValidator validator = new WmsUrlValidator(baseGeoserverUrl, fullPath , "", false);
// logger.trace("base wms service url: "+validator.getBaseWmsServiceUrl());
// logger.trace("layer name: "+validator.getLayerName());
// logger.trace("full wms url: "+validator.getFullWmsUrlRequest(false, true));
// logger.trace("style: "+validator.getStyles());
// logger.trace("not standard parameter: "+validator.getWmsNotStandardParameters());
// String[] arrayStyle = validator.getStyles().split(",");
//
// if(arrayStyle!=null && arrayStyle.length>0){
//
// for (String style : arrayStyle) {
// if(style!=null && !style.isEmpty())
//
// System.out.println("Style: "+style.trim());
// }
// }
//
// String fullPath = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&bbox=-85.0,-180.0,85.0,180.0&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto";
//
// WmsGeoExplorerUrlValidator validator = new WmsGeoExplorerUrlValidator("http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc", fullPath , "", false);
// validator.getFullWmsUrlRequest(false,true);
//
// System.out.println(validator.getWmsNoStandardParameters());
// System.out.println(validator.getMapWmsNoStandardParams());
// fullPath = WmsUrlValidator.setValueOfParameter(WmsParameters.STYLES, fullPath, "123", true);
//
// MapPreviewGenerator map = new MapPreviewGenerator();
// fullPath = map.buildWmsRequestMapPreview(fullPath, "-85.0,-180.0,85.0,180.0");
// System.out.println(fullPath);
}
}

View File

@ -0,0 +1,88 @@
/**
*
*/
package org.gcube.portlets.user.gisviewer.server;
/**
* The Class GeoserverBaseUri.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 28, 2016
*/
public class WebMapServerHost {
private String host = "";
private String scope = "";
/**
* Instantiates a new geoserver base uri.
*/
public WebMapServerHost() {
}
/**
* Instantiates a new geoserver base uri.
*
* @param host the base url
* @param scope the scope
*/
public WebMapServerHost(String host, String scope) {
this.host = host;
this.scope = scope;
}
/**
* @return the host
*/
public String getHost() {
return host;
}
/**
* @return the scope
*/
public String getScope() {
return scope;
}
/**
* @param host the host to set
*/
public void setHost(String host) {
this.host = host;
}
/**
* @param scope the scope to set
*/
public void setScope(String scope) {
this.scope = scope;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WebMapServerHost [host=");
builder.append(host);
builder.append(", scope=");
builder.append(scope);
builder.append("]");
return builder.toString();
}
}