Added WFS cross filtering results
This commit is contained in:
parent
dcca1afba1
commit
36bfcd2b9e
|
@ -8,6 +8,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerCon
|
|||
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent.LAYER_TYPE;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.SwapLayer;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.util.WFSMakerUtil;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
||||
|
||||
|
@ -78,6 +79,8 @@ import ol.style.Style;
|
|||
*/
|
||||
public abstract class OpenLayerMap {
|
||||
|
||||
public static final String CQL_FILTER_PARAMETER = WFSMakerUtil.CQL_FILTER_PARAMETER;
|
||||
|
||||
private static final int MAX_LENGHT_CQL_FOR_GET_REQUEST = 1600; // 1600 characters
|
||||
|
||||
public static final int SET_CENTER_ANIMATED_DURATION = 500;
|
||||
|
@ -419,9 +422,7 @@ public abstract class OpenLayerMap {
|
|||
if (layer == null) {
|
||||
ImageWmsParams imageWMSParams = OLFactory.createOptions();
|
||||
imageWMSParams.setLayers(layerItem.getName());
|
||||
// imageWMSParams.set("CQL_FILTER", "product_id
|
||||
// IN('6165b07202ad3d60e1d26f42','6166ff8002ad3d60e1d26fb7')");
|
||||
|
||||
|
||||
ImageWmsOptions imageWMSOptions = OLFactory.createOptions();
|
||||
imageWMSOptions.setUrl(layerItem.getMapServerHost());
|
||||
|
||||
|
@ -478,9 +479,9 @@ public abstract class OpenLayerMap {
|
|||
ImageWmsParams imageWMSParams = imageWMSSource.getParams();
|
||||
|
||||
if (cqlFilterExpression == null || cqlFilterExpression.length() > MAX_LENGHT_CQL_FOR_GET_REQUEST) {
|
||||
imageWMSParams.delete("CQL_FILTER");
|
||||
imageWMSParams.delete(CQL_FILTER_PARAMETER);
|
||||
} else {
|
||||
imageWMSParams.set("CQL_FILTER", cqlFilterExpression);
|
||||
imageWMSParams.set(CQL_FILTER_PARAMETER, cqlFilterExpression);
|
||||
}
|
||||
|
||||
imageWMSSource.updateParams(imageWMSParams);
|
||||
|
|
|
@ -8,13 +8,19 @@ import java.util.List;
|
|||
import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.CrossFilteringLayerDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDILayer;
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEvent;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.util.WFSMakerUtil;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Alert;
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
import com.github.gwtbootstrap.client.ui.CheckBox;
|
||||
import com.github.gwtbootstrap.client.ui.ControlGroup;
|
||||
|
@ -23,6 +29,7 @@ import com.github.gwtbootstrap.client.ui.Controls;
|
|||
import com.github.gwtbootstrap.client.ui.DropdownButton;
|
||||
import com.github.gwtbootstrap.client.ui.Fieldset;
|
||||
import com.github.gwtbootstrap.client.ui.ListBox;
|
||||
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
||||
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ChangeEvent;
|
||||
|
@ -39,6 +46,8 @@ import com.google.gwt.http.client.URL;
|
|||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
import jsinterop.base.JsPropertyMap;
|
||||
|
@ -61,6 +70,9 @@ public class CrossFilteringLayerPanel extends Composite {
|
|||
@UiField
|
||||
Fieldset fieldSet;
|
||||
|
||||
@UiField
|
||||
HTMLPanel panelResults;
|
||||
|
||||
@UiField
|
||||
Button buttonReset;
|
||||
|
||||
|
@ -138,6 +150,7 @@ public class CrossFilteringLayerPanel extends Composite {
|
|||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
panelResults.clear();
|
||||
for (int i = 1; i < mapInnestedListBoxes.size(); i++) {
|
||||
resetListBoxLevel(i);
|
||||
}
|
||||
|
@ -201,7 +214,7 @@ public class CrossFilteringLayerPanel extends Composite {
|
|||
if (selectedItem != null) {
|
||||
|
||||
String cqlFilterValue = crossFilteringLayer.getTable_parent_key_field() + "=" + selectedItem.keyValue;
|
||||
wfsURL += "&CQL_FILTER=" + URL.encode(cqlFilterValue);
|
||||
wfsURL += "&" + WFSMakerUtil.CQL_FILTER_PARAMETER + "=" + URL.encode(cqlFilterValue);
|
||||
|
||||
}
|
||||
GWT.log("wfsURL request: " + wfsURL);
|
||||
|
@ -357,7 +370,7 @@ public class CrossFilteringLayerPanel extends Composite {
|
|||
*/
|
||||
private void fillListBoxLevel(int level, HashMap<String, SelectableItem> mapSelectableFeatures,
|
||||
List<ListBox> listBoxes, String placeholder) {
|
||||
//GWT.log("fillBox level: " + level + " map: " + mapSelectableFeatures);
|
||||
// GWT.log("fillBox level: " + level + " map: " + mapSelectableFeatures);
|
||||
|
||||
if (mapSelectableFeatures == null)
|
||||
return;
|
||||
|
@ -401,12 +414,87 @@ public class CrossFilteringLayerPanel extends Composite {
|
|||
private void buildCrossFilteringCQLAndFireEvent(SelectableItem selectableItem) {
|
||||
String setCqlFilter = "INTERSECTS(geom,querySingle('" + selectableItem.layername + "','"
|
||||
+ selectableItem.theGeometryName + "','" + selectableItem.keyField + "=''" + selectableItem.keyValue
|
||||
+ "'''));INCLUDE";
|
||||
+ "'''))";
|
||||
// setCqlFilter = URL.encode(setCqlFilter);
|
||||
GWT.log("CQL FILTER built: " + setCqlFilter);
|
||||
|
||||
// olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, setCqlFilter);
|
||||
IndexLayerDV indexLayer = gCubeCollection.getIndexes().get(0);
|
||||
applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(indexLayer, setCqlFilter));
|
||||
|
||||
applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(gCubeCollection.getIndexes().get(0), setCqlFilter));
|
||||
try {
|
||||
GCubeSDILayer layer = indexLayer.getLayer();
|
||||
String wmsLink = layer.getOgcLinks().get("wms");
|
||||
String layerName = URLUtil.extractValueOfParameterFromURL("layers", wmsLink);
|
||||
String serviceURL = URLUtil.getPathURL(wmsLink);
|
||||
String toLServiceURL = serviceURL.toLowerCase();
|
||||
if (toLServiceURL.endsWith("wms")) {
|
||||
toLServiceURL = toLServiceURL.substring(0, toLServiceURL.length() - 3) + "ows";
|
||||
}
|
||||
String wfsCrossFilteringQuery = WFSMakerUtil.buildWFSRequest(toLServiceURL, layerName, 1000, "geom",
|
||||
setCqlFilter);
|
||||
GWT.log("wfsCrossFilteringQuery: " + wfsCrossFilteringQuery);
|
||||
showCountResultsOfWFSCrossFiltering(wfsCrossFilteringQuery);
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
|
||||
public void showCountResultsOfWFSCrossFiltering(String wfsQuery) {
|
||||
|
||||
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsQuery);
|
||||
panelResults.clear();
|
||||
panelResults.add(new HTML("<hr>"));
|
||||
panelResults.add(new LoaderIcon("Filtering..."));
|
||||
try {
|
||||
|
||||
Request response = builder.sendRequest(null, new RequestCallback() {
|
||||
public void onError(Request request, Throwable exception) {
|
||||
// showLoading(false);
|
||||
// Window.alert(caught.getMessage());
|
||||
panelResults.clear();
|
||||
panelResults.add(new HTML("<hr>"));
|
||||
Alert alert = new Alert("Error on returning number of centroids");
|
||||
alert.setType(AlertType.ERROR);
|
||||
alert.setClose(false);
|
||||
panelResults.add(alert);
|
||||
}
|
||||
|
||||
public void onResponseReceived(Request request, Response response) {
|
||||
|
||||
Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326,
|
||||
response.getText());
|
||||
|
||||
if (features != null) {
|
||||
int dataCount = features.length;
|
||||
|
||||
panelResults.clear();
|
||||
panelResults.add(new HTML("<hr>"));
|
||||
|
||||
if (dataCount == 0) {
|
||||
panelResults.add(new HTML("No result found"));
|
||||
return;
|
||||
}
|
||||
|
||||
String message = "";
|
||||
|
||||
if (dataCount > 0) {
|
||||
message = "Found " + dataCount;
|
||||
message += dataCount > 1 ? " centroids" : " centroid";
|
||||
message += ". ";
|
||||
}
|
||||
|
||||
HTML resultMessage = new HTML(message);
|
||||
resultMessage.getElement().addClassName("search_result_msg");
|
||||
|
||||
panelResults.add(resultMessage);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
} catch (RequestException e) {
|
||||
panelResults.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -416,11 +504,12 @@ public class CrossFilteringLayerPanel extends Composite {
|
|||
* @param selectableItemValue the selectable item value
|
||||
*/
|
||||
private void loadInnerLevel(int level, String selectableItemValue) {
|
||||
GWT.log("selected level " + level + " selectableItemValue " + selectableItemValue);
|
||||
// GWT.log("selected level " + level + " selectableItemValue " +
|
||||
// selectableItemValue);
|
||||
HashMap<String, SelectableItem> mapSelectableItem = mapInnestedFeatures.get(level);
|
||||
SelectableItem selectedItem = mapSelectableItem.get(selectableItemValue);
|
||||
|
||||
GWT.log("selected selectableItem " + selectedItem);
|
||||
// GWT.log("selected selectableItem " + selectedItem);
|
||||
int innerLevel = level + 1;
|
||||
List<? extends LayerIDV> selectedLayers = mapInnestedFiltering.get(innerLevel);
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
<b:Fieldset ui:field="fieldSet">
|
||||
</b:Fieldset>
|
||||
</b:Form>
|
||||
<g:HTMLPanel ui:field="panelResults">
|
||||
</g:HTMLPanel>
|
||||
<b:Button icon="REMOVE_CIRCLE" ui:field="buttonReset"
|
||||
title="Reset the filter">Reset</b:Button>
|
||||
</g:HTMLPanel>
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package org.gcube.portlets.user.geoportaldataviewer.client.util;
|
||||
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.WFSGetFeature;
|
||||
|
||||
import com.google.gwt.http.client.URL;
|
||||
|
||||
public class WFSMakerUtil {
|
||||
|
||||
public static final String CQL_FILTER_PARAMETER = "CQL_FILTER";
|
||||
|
||||
public static String buildWFSRequest(String webserviceURL, String layerName, int maxFeatures, String propertyName,
|
||||
String cqlFilter) throws Exception {
|
||||
|
||||
if (layerName == null)
|
||||
throw new Exception("Bad parameter layerName is null");
|
||||
|
||||
if (webserviceURL == null)
|
||||
throw new Exception("Bad parameter webserviceURL is null");
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(webserviceURL);
|
||||
builder.append("?");
|
||||
builder.append(WFSGetFeature.SERVICE.getParameter() + "=" + WFSGetFeature.SERVICE.getValue());
|
||||
builder.append("&");
|
||||
builder.append(WFSGetFeature.VERSION.getParameter() + "=" + WFSGetFeature.VERSION.getValue());
|
||||
builder.append("&");
|
||||
builder.append(WFSGetFeature.REQUEST.getParameter() + "=" + WFSGetFeature.REQUEST.getValue());
|
||||
builder.append("&");
|
||||
builder.append(WFSGetFeature.OUTPUTFORMAT.getParameter() + "=" + URL.encode("application/json"));
|
||||
builder.append("&");
|
||||
builder.append(WFSGetFeature.TYPENAME.getParameter() + "=" + layerName);
|
||||
builder.append("&");
|
||||
|
||||
if (maxFeatures > 0) {
|
||||
builder.append(WFSGetFeature.MAXFEATURES.getParameter() + "=" + maxFeatures);
|
||||
builder.append("&");
|
||||
}
|
||||
if (propertyName != null) {
|
||||
builder.append(WFSGetFeature.PROPERTYNAME.getParameter() + "=" + propertyName);
|
||||
builder.append("&");
|
||||
}
|
||||
if (cqlFilter != null) {
|
||||
builder.append(CQL_FILTER_PARAMETER + "=" + cqlFilter);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ import org.gcube.application.geoportalcommon.shared.gis.BoundsMap;
|
|||
import org.gcube.application.geoportalcommon.util.URLParserUtil;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.server.gis.MapServerRecognize.SERVERTYPE;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.WFSGetFeature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -12,12 +12,10 @@ import org.gcube.spatial.data.geoutility.wms.WmsUrlValidator;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class GisViewerWMSUrlValidator.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Jan 28, 2016
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 28, 2016
|
||||
*/
|
||||
public class WMSUrlValidator {
|
||||
|
||||
|
@ -35,57 +33,56 @@ public class WMSUrlValidator {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WMSUrlValidator.class);
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new WMS url validator.
|
||||
*
|
||||
* @param wmsRequest the wms request
|
||||
* @param wmsRequest the wms request
|
||||
* @param inputLayerName the input layer name
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public WMSUrlValidator(String wmsRequest, String inputLayerName) throws Exception{
|
||||
LOG.debug("WMSURLValidator wmsRequest: "+wmsRequest);
|
||||
LOG.debug("WMSURLValidator layerName: "+inputLayerName);
|
||||
|
||||
public WMSUrlValidator(String wmsRequest, String inputLayerName) throws Exception {
|
||||
LOG.debug("WMSURLValidator wmsRequest: " + wmsRequest);
|
||||
LOG.debug("WMSURLValidator layerName: " + inputLayerName);
|
||||
|
||||
if(wmsRequest==null || wmsRequest.isEmpty())
|
||||
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)){
|
||||
LOG.trace("found "+GeoWmsServiceUtility.SERVICE_WMS+" in wms request: "+wmsRequestURI);
|
||||
// IS WMS?
|
||||
if (GeoWmsServiceUtility.isWMSService(wmsRequestURI)) {
|
||||
LOG.trace("found " + GeoWmsServiceUtility.SERVICE_WMS + " in wms request: " + wmsRequestURI);
|
||||
webMapServerHost = getWebMapServerHost(wmsRequestURI);
|
||||
}else
|
||||
throw new Exception("WMS service not found for layer: "+inputLayerName);
|
||||
} else
|
||||
throw new Exception("WMS service not found for layer: " + inputLayerName);
|
||||
|
||||
//VALIDATION WMS
|
||||
// VALIDATION WMS
|
||||
String baseWmsService = webMapServerHost.getHost();
|
||||
//IS OWS OR WMS?
|
||||
this.wmsServiceHost = appendWmsServiceToBaseUrl(wmsRequest.substring(0, wmsRequest.indexOf("?")),isOwsService);
|
||||
// IS OWS OR WMS?
|
||||
this.wmsServiceHost = appendWmsServiceToBaseUrl(wmsRequest.substring(0, wmsRequest.indexOf("?")), isOwsService);
|
||||
this.layerName = inputLayerName;
|
||||
|
||||
try {
|
||||
//VALIDATE WMS SERVICE FOR WEB MAP SERVER
|
||||
if(!HttpRequestUtil.urlExists(this.wmsServiceHost, true)){
|
||||
LOG.info("baseWmsServiceUrl: "+wmsServiceHost +" is not a geoserver, setting as input base wms server: "+baseWmsService);
|
||||
// VALIDATE WMS SERVICE FOR WEB MAP SERVER
|
||||
if (!HttpRequestUtil.urlExists(this.wmsServiceHost, true)) {
|
||||
LOG.info("baseWmsServiceUrl: " + wmsServiceHost
|
||||
+ " is not a geoserver, setting as input base wms server: " + baseWmsService);
|
||||
this.wmsServiceHost = baseWmsService;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("error on validating geoserver wms service: "+e);
|
||||
LOG.info("setting baseWmsService as input base wms server: "+baseWmsService);
|
||||
LOG.error("error on validating geoserver wms service: " + e);
|
||||
LOG.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()){
|
||||
// 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 || this.layerName.isEmpty())
|
||||
if (this.layerName == null || this.layerName.isEmpty())
|
||||
throw new Exception("Layer name is null or empty");
|
||||
|
||||
}
|
||||
|
@ -93,42 +90,42 @@ public class WMSUrlValidator {
|
|||
parametersValue.put(WmsParameters.LAYERS.getParameter(), this.layerName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append wms service to base url.
|
||||
*
|
||||
* @param url the url
|
||||
* @param url the url
|
||||
* @param isOwsServer the is ows server
|
||||
* @return the string
|
||||
*/
|
||||
public String appendWmsServiceToBaseUrl(String url, boolean isOwsServer){
|
||||
public String appendWmsServiceToBaseUrl(String url, boolean isOwsServer) {
|
||||
|
||||
if(url.contains("/"+WMS) || url.contains("/"+OWS))
|
||||
if (url.contains("/" + WMS) || url.contains("/" + OWS))
|
||||
return url;
|
||||
|
||||
if(url.lastIndexOf("/") != url.length()){
|
||||
url+="/";
|
||||
if (url.lastIndexOf("/") != url.length()) {
|
||||
url += "/";
|
||||
}
|
||||
|
||||
if(isOwsServer)
|
||||
return url+=OWS;
|
||||
if (isOwsServer)
|
||||
return url += OWS;
|
||||
else
|
||||
return url+=WMS;
|
||||
return url += WMS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method: getFullWmsUrlRequest
|
||||
* Create a correct wms url request
|
||||
* Returns:
|
||||
* 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 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"
|
||||
* "wmsserver?key1=value1&key2=value2&key3=value3"
|
||||
*/
|
||||
public String parseWMSRequest(boolean returnEmptyParameter, boolean fillEmptyParameterAsDefault){
|
||||
public String parseWMSRequest(boolean returnEmptyParameter, boolean fillEmptyParameterAsDefault) {
|
||||
|
||||
urlValidator = new org.gcube.spatial.data.geoutility.wms.WmsUrlValidator(wmsRequestURI);
|
||||
String fullWmsUrlBuilded;
|
||||
|
@ -138,98 +135,100 @@ public class WMSUrlValidator {
|
|||
parametersValue.putAll(urlValidator.getMapWmsParameters());
|
||||
|
||||
String ln = parametersValue.get(WmsParameters.LAYERS.name());
|
||||
LOG.debug("Comparing layer name from Wms request: "+ln +", with OnLineResource layerName: "+this.layerName);
|
||||
if(ln==null || ln.isEmpty() || ln.compareTo(this.layerName)!=0){
|
||||
LOG.info("Layer name into wms request is different to OnLineResource layers name, replacing layer name: "+this.layerName);
|
||||
LOG.debug("Comparing layer name from Wms request: " + ln + ", with OnLineResource layerName: "
|
||||
+ this.layerName);
|
||||
if (ln == null || ln.isEmpty() || ln.compareTo(this.layerName) != 0) {
|
||||
LOG.info(
|
||||
"Layer name into wms request is different to OnLineResource layers name, replacing layer 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);
|
||||
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) {
|
||||
LOG.error("An error occurred during wms uri build, returning uri: "+wmsRequestURI, e);
|
||||
} catch (Exception e) {
|
||||
LOG.error("An error occurred during wms uri build, returning uri: " + wmsRequestURI, e);
|
||||
fullWmsUrlBuilded = wmsRequestURI;
|
||||
}
|
||||
|
||||
LOG.trace("GisViewerWMSUrlValidator parseWMSRequest returning full wms url: "+fullWmsUrlBuilded);
|
||||
LOG.trace("GisViewerWMSUrlValidator parseWMSRequest 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))
|
||||
* @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){
|
||||
public WebMapServerHost getWebMapServerHost(String wmsRequest) {
|
||||
|
||||
WebMapServerHost webMapServerHost = new WebMapServerHost();
|
||||
|
||||
if(wmsRequest==null)
|
||||
return webMapServerHost; //uri is empty
|
||||
|
||||
if (wmsRequest == null)
|
||||
return webMapServerHost; // uri is empty
|
||||
|
||||
int end = wmsRequest.toLowerCase().lastIndexOf("?");
|
||||
|
||||
if(end==-1){
|
||||
LOG.trace("char ? not found in geoserver uri, return: "+wmsRequest);
|
||||
return webMapServerHost; //uri is empty
|
||||
if (end == -1) {
|
||||
LOG.trace("char ? not found in geoserver uri, return: " + wmsRequest);
|
||||
return webMapServerHost; // uri is empty
|
||||
}
|
||||
|
||||
String webMapServerBaseURL = wmsRequest.substring(0, wmsRequest.toLowerCase().lastIndexOf("?"));
|
||||
int index = webMapServerBaseURL.lastIndexOf(GEOSERVER);
|
||||
|
||||
if(index>-1){ //FOUND the string GEOSERVER into URL
|
||||
LOG.trace("found geoserver string: "+GEOSERVER+" in "+webMapServerBaseURL);
|
||||
if (index > -1) { // FOUND the string GEOSERVER into URL
|
||||
LOG.trace("found geoserver string: " + GEOSERVER + " in " + webMapServerBaseURL);
|
||||
|
||||
//THERE IS SCOPE?
|
||||
// THERE IS SCOPE?
|
||||
int lastSlash = webMapServerBaseURL.lastIndexOf("/");
|
||||
int includeGeoserverString = index+GEOSERVER.length();
|
||||
int endUrl = lastSlash>includeGeoserverString?lastSlash:includeGeoserverString;
|
||||
LOG.trace("indexs - lastSlash: ["+lastSlash+"], includeGeoserverString: ["+includeGeoserverString+"], endUrl: ["+endUrl+"]");
|
||||
int startScope = includeGeoserverString+1<endUrl?includeGeoserverString+1:endUrl; //INCLUDE SLASH
|
||||
int includeGeoserverString = index + GEOSERVER.length();
|
||||
int endUrl = lastSlash > includeGeoserverString ? lastSlash : includeGeoserverString;
|
||||
LOG.trace("indexs - lastSlash: [" + lastSlash + "], includeGeoserverString: [" + includeGeoserverString
|
||||
+ "], endUrl: [" + endUrl + "]");
|
||||
int startScope = includeGeoserverString + 1 < endUrl ? includeGeoserverString + 1 : endUrl; // INCLUDE SLASH
|
||||
String scope = webMapServerBaseURL.substring(startScope, endUrl);
|
||||
LOG.trace("geoserver url include scope: "+webMapServerBaseURL.substring(includeGeoserverString, endUrl));
|
||||
LOG.trace("geoserver url include scope: " + webMapServerBaseURL.substring(includeGeoserverString, endUrl));
|
||||
webMapServerHost.setHost(webMapServerBaseURL.substring(0, endUrl));
|
||||
webMapServerHost.setScope(scope);
|
||||
|
||||
return webMapServerHost;
|
||||
|
||||
}else{
|
||||
LOG.trace("the string 'geoserver' not found in "+webMapServerBaseURL);
|
||||
} else {
|
||||
LOG.trace("the string 'geoserver' not found in " + webMapServerBaseURL);
|
||||
// GET LAST INDEX OF '/' AND CONCATENATE GEOSERVER
|
||||
String urlConn = webMapServerBaseURL.substring(0, webMapServerBaseURL.lastIndexOf("/"))+GEOSERVER;
|
||||
LOG.trace("tentative concatenating string 'geoserver' at http url "+urlConn);
|
||||
String urlConn = webMapServerBaseURL.substring(0, webMapServerBaseURL.lastIndexOf("/")) + GEOSERVER;
|
||||
LOG.trace("tentative concatenating string 'geoserver' at http url " + urlConn);
|
||||
|
||||
try {
|
||||
|
||||
if(HttpRequestUtil.urlExists(urlConn, false)){
|
||||
LOG.trace("url: "+urlConn+" - open a connection, return "+urlConn);
|
||||
if (HttpRequestUtil.urlExists(urlConn, false)) {
|
||||
LOG.trace("url: " + urlConn + " - open a connection, return " + urlConn);
|
||||
webMapServerHost.setHost(urlConn);
|
||||
return webMapServerHost;
|
||||
}
|
||||
else
|
||||
LOG.trace("url: "+urlConn+" - not open a connection");
|
||||
} else
|
||||
LOG.trace("url: " + urlConn + " - not open a connection");
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("url connection is wrong at :"+urlConn);
|
||||
LOG.error("url connection is wrong at :" + urlConn);
|
||||
}
|
||||
|
||||
String uriWithoutParameters = wmsRequest.substring(0, end);
|
||||
LOG.trace("url connection, returned: "+uriWithoutParameters);
|
||||
LOG.trace("url connection, returned: " + uriWithoutParameters);
|
||||
webMapServerHost.setHost(uriWithoutParameters);
|
||||
return webMapServerHost;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the wms service host.
|
||||
*
|
||||
|
@ -260,42 +259,40 @@ public class WMSUrlValidator {
|
|||
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){
|
||||
public String getValueOfParsedWMSParameter(WmsParameters parameter) {
|
||||
|
||||
return parametersValue.get(parameter.getParameter());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value of parameter.
|
||||
*
|
||||
* @param wmsParam the wms param
|
||||
* @param wmsParam the wms param
|
||||
* @param wmsUrlParameters the wms url parameters
|
||||
* @return the value of parameter
|
||||
*/
|
||||
public static String getValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters){
|
||||
public static String getValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters) {
|
||||
|
||||
return WmsUrlValidator.getValueOfParameter(wmsParam, wmsUrlParameters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the value of parameter.
|
||||
*
|
||||
* @param wmsParam the wms param
|
||||
* @param wmsParam the wms param
|
||||
* @param wmsUrlParameters the wms url parameters
|
||||
* @param newValue the new value
|
||||
* @param addIfNotExists the add if not exists
|
||||
* @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){
|
||||
public static String setValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters, String newValue,
|
||||
boolean addIfNotExists) {
|
||||
|
||||
return WmsUrlValidator.setValueOfParameter(wmsParam, wmsUrlParameters, newValue, addIfNotExists);
|
||||
}
|
||||
|
@ -309,8 +306,6 @@ public class WMSUrlValidator {
|
|||
return layerName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the styles as list.
|
||||
*
|
||||
|
@ -321,18 +316,17 @@ public class WMSUrlValidator {
|
|||
List<String> listStyles = new ArrayList<String>();
|
||||
String styles = getValueOfParsedWMSParameter(WmsParameters.STYLES);
|
||||
|
||||
if(styles!=null && !styles.isEmpty()){
|
||||
if (styles != null && !styles.isEmpty()) {
|
||||
|
||||
String[] arrayStyle = styles.split(",");
|
||||
for (String style : arrayStyle) {
|
||||
if(style!=null && !style.isEmpty())
|
||||
if (style != null && !style.isEmpty())
|
||||
listStyles.add(style);
|
||||
}
|
||||
}
|
||||
return listStyles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the map wms no standard params.
|
||||
*
|
||||
|
@ -342,63 +336,4 @@ public class WMSUrlValidator {
|
|||
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);
|
||||
|
||||
String wmsRequest = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver/wms?CRS=EPSG:4326&BBOX=-85.5,-180.0,90.0,180.0&VERSION=1.1.0&FORMAT=application/openlayers&SERVICE=wms&HEIGHT=330&LAYERS=aquamaps:lsoleasolea20130716162322254cest&REQUEST=GetMap&STYLES=Species_prob&SRS=EPSG:4326&WIDTH=676";
|
||||
// String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
|
||||
WmsUrlValidator wms;
|
||||
try {
|
||||
wms = new WmsUrlValidator(wmsRequest);
|
||||
System.out.println("Returned wms: "+wms.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
package org.gcube.portlets.user.geoportaldataviewer.server.gis;
|
||||
|
||||
|
||||
package org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs;
|
||||
|
||||
/**
|
||||
* The Enum WfsParameters.
|
||||
|
@ -20,6 +18,7 @@ public enum WFSGetFeature {
|
|||
WIDTH("WIDTH","676"),
|
||||
HEIGHT("HEIGHT","230"),
|
||||
SRSNAME("srsName","EPSG:4326"),
|
||||
PROPERTYNAME("propertyName", ""),
|
||||
// CRS("CRS","EPSG:4326"), //WMS 1.3.0 COMPLIANT
|
||||
OUTPUTFORMAT("OUTPUTFORMAT","json"),
|
||||
MAXFEATURES("MAXFEATURES","");
|
|
@ -0,0 +1,84 @@
|
|||
package org.gcube.portlets.user.geoportaldataviewer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* The Class WMSUrlValidatorTest.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Jun 1, 2023
|
||||
*/
|
||||
public class WMSUrlValidatorTest {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
String wmsRequest = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver/wms?CRS=EPSG:4326&BBOX=-85.5,-180.0,90.0,180.0&VERSION=1.1.0&FORMAT=application/openlayers&SERVICE=wms&HEIGHT=330&LAYERS=aquamaps:lsoleasolea20130716162322254cest&REQUEST=GetMap&STYLES=Species_prob&SRS=EPSG:4326&WIDTH=676";
|
||||
// String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0";
|
||||
WmsUrlValidator wms;
|
||||
try {
|
||||
wms = new WmsUrlValidator(wmsRequest);
|
||||
System.out.println("Returned wms: "+wms.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue