in progress on WFS interaction
parent
eb0b78da87
commit
8e7071bf6f
@ -1,4 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
lastWarOutDir=/home/francesco/git/geoportal-data-viewer-app/target/geoportal-data-viewer-app-1.0.0-SNAPSHOT
|
||||
lastWarOutDir=/home/francesco-mangiacrapa/git/geoportal-data-viewer-app/target/geoportal-data-viewer-app-1.0.0-SNAPSHOT
|
||||
warSrcDir=src/main/webapp
|
||||
warSrcDirIsOutput=false
|
||||
|
@ -0,0 +1,59 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.client.events;
|
||||
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
import ol.Coordinate;
|
||||
|
||||
/**
|
||||
* The Class QueryDataEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 29, 2020
|
||||
*/
|
||||
public class QueryDataEvent extends GwtEvent<QueryDataEventHandler> {
|
||||
public static Type<QueryDataEventHandler> TYPE = new Type<QueryDataEventHandler>();
|
||||
private GeoQuery select;
|
||||
private Coordinate oLCoordinate;
|
||||
|
||||
/**
|
||||
* Instantiates a new table row selected event.
|
||||
* @param coordinate
|
||||
*/
|
||||
public QueryDataEvent(GeoQuery select, Coordinate coordinate) {
|
||||
this.select = select;
|
||||
this.oLCoordinate = coordinate;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the associated type.
|
||||
*
|
||||
* @return the associated type
|
||||
*/
|
||||
@Override
|
||||
public Type<QueryDataEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(QueryDataEventHandler handler) {
|
||||
handler.onQueryInteraction(this);
|
||||
|
||||
}
|
||||
|
||||
public GeoQuery getGeoQuery() {
|
||||
return select;
|
||||
}
|
||||
|
||||
public Coordinate getoLCoordinate() {
|
||||
return oLCoordinate;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.client.events;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
|
||||
/**
|
||||
* The Interface QueryDataEventHandler.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 29, 2020
|
||||
*/
|
||||
public interface QueryDataEventHandler extends EventHandler {
|
||||
|
||||
/**
|
||||
* On query interaction.
|
||||
*
|
||||
* @param query the query
|
||||
*/
|
||||
void onQueryInteraction(QueryDataEvent query);
|
||||
}
|
@ -1,273 +0,0 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.client.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.util.MapServerRecognize.SERVERTYPE;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.ClickDataInfo;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
||||
|
||||
import com.google.gwt.core.shared.GWT;
|
||||
|
||||
/**
|
||||
* The Class URLMakers.
|
||||
*
|
||||
* @author Ceras. Updated by Francesco Mangiacrapa
|
||||
* francesco.mangiacrapa@isti.cnr.it Jan 28, 2016
|
||||
*/
|
||||
public class URLMakers {
|
||||
|
||||
public static final String CQL_FILTER_PARAMETER = "CQL_FILTER";
|
||||
|
||||
// MAP SERVER PIVOT
|
||||
public static final String WXS = "wxs";
|
||||
// GEOSERVER PIVOT
|
||||
public static final String WMS = "/wms";
|
||||
|
||||
// OUTPUT FORMAT
|
||||
public static final String CSV = "csv";
|
||||
|
||||
public static final String JSON = "json";
|
||||
|
||||
private static String[][] a = { { "\\?", "%3F" }, { "&", "%26" }, };
|
||||
|
||||
// /**
|
||||
// * Encoding layer.
|
||||
// *
|
||||
// * @param l the l
|
||||
// * @return the string
|
||||
// */
|
||||
// private static String encodingLayer(String l) {
|
||||
// String result = l.replace(":", "%3A");
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the url.
|
||||
// *
|
||||
// * @param projection the projection
|
||||
// * @param width the width
|
||||
// * @param height the height
|
||||
// * @param x the x
|
||||
// * @param y the y
|
||||
// * @param bbox the bbox
|
||||
// * @param layers the layers
|
||||
// * @return the url
|
||||
// */
|
||||
// public static String getURL(String projection, String width, String height, int x, int y, String bbox,
|
||||
// Vector<String> layers) {
|
||||
//
|
||||
// String layer = "";
|
||||
// boolean first = true;
|
||||
// for (String s : layers) {
|
||||
// if (!first) {
|
||||
// layer = layer + "%2C" + encodingLayer(s);
|
||||
// }
|
||||
// if (first) {
|
||||
// layer = encodingLayer(s);
|
||||
// }
|
||||
// first = false;
|
||||
// }
|
||||
//
|
||||
// String[] _bbox = bbox.split(",");
|
||||
//
|
||||
// projection = encodingLayer(projection);
|
||||
// String result = "?REQUEST=GetFeatureInfo&EXCEPTIONS=application%2Fvnd.ogc.se_xml&BBOX=" + _bbox[0] + "%2C"
|
||||
// + _bbox[1] + "%2C" + _bbox[2] + "%2C" + _bbox[3] + "&X=" + x + "&Y=" + y
|
||||
// + "&INFO_FORMAT=text%2Fhtml&QUERY_LAYERS=" + layer + "&FEATURE_COUNT=50&Layers=" + layer
|
||||
// + "&Styles=&Srs=" + projection + "&WIDTH=" + width + "&HEIGHT=" + height + "&format=image%2Fpng";
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the url.
|
||||
// *
|
||||
// * @param projection the projection
|
||||
// * @param width the width
|
||||
// * @param height the height
|
||||
// * @param x the x
|
||||
// * @param y the y
|
||||
// * @param bbox the bbox
|
||||
// * @param layerItems the layer items
|
||||
// * @return the url
|
||||
// */
|
||||
// public static String getURL(String projection, int width, int height, int x, int y, String bbox,
|
||||
// List<LayerItem> layerItems) {
|
||||
// String strListLayers = "";
|
||||
// boolean first = true;
|
||||
// for (LayerItem layerItem : layerItems) {
|
||||
// if (layerItem.isClickData()) {
|
||||
// String strLayer = encodingLayer(layerItem.getName());
|
||||
// strListLayers = first ? strLayer : strListLayers + "%2C" + strLayer;
|
||||
// first = false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// String[] _bbox = bbox.split(",");
|
||||
//
|
||||
// projection = encodingLayer(projection);
|
||||
// String result = "?REQUEST=GetFeatureInfo&EXCEPTIONS=application%2Fvnd.ogc.se_xml&BBOX=" + _bbox[0] + "%2C"
|
||||
// + _bbox[1] + "%2C" + _bbox[2] + "%2C" + _bbox[3] + "&X=" + x + "&Y=" + y
|
||||
// + "&INFO_FORMAT=text%2Fhtml&QUERY_LAYERS=" + strListLayers + "&FEATURE_COUNT=50&Layers=" + strListLayers
|
||||
// + "&Styles=&Srs=" + projection + "&WIDTH=" + width + "&HEIGHT=" + height + "&format=image%2Fpng";
|
||||
//
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
//// public static String getURLFeatureInfo(ClickDataInfo clickDataInfo, String projection, String bbox) {
|
||||
//// return getURL(projection, clickDataInfo.getW(), clickDataInfo.getH(), clickDataInfo.getX(), clickDataInfo.getY(), bbox, clickDataInfo.getLayers());
|
||||
//// }
|
||||
|
||||
// /**
|
||||
// * Gets the url.
|
||||
// *
|
||||
// * @param clickDataInfo the click data info
|
||||
// * @param projection the projection
|
||||
// * @param layerItems the layer items
|
||||
// * @return the url
|
||||
// */
|
||||
// public static String getURL(ClickDataInfo clickDataInfo, String projection, List<LayerItem> layerItems) {
|
||||
// return getURL(projection, clickDataInfo.getW(), clickDataInfo.getH(), clickDataInfo.getX(),
|
||||
// clickDataInfo.getY(), clickDataInfo.getBbox(), layerItems);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Gets the wfs feature url.
|
||||
*
|
||||
* @param l the l
|
||||
* @param bbox the bbox
|
||||
* @param limit the limit
|
||||
* @param format the format
|
||||
* @return the wfs feature url
|
||||
*/
|
||||
public static String getWfsFeatureUrl(LayerItem l, String srsName, String bbox, int limit, String format) {
|
||||
|
||||
String link = l.getUrl();
|
||||
GWT.log("Layer URL: " + link);
|
||||
GWT.log("CQL filter is: " + l.getCqlFilter());
|
||||
|
||||
String outputformat = null;
|
||||
String boundingBox = bbox;
|
||||
|
||||
// CASE MAP SERVER
|
||||
SERVERTYPE mapserverType = MapServerRecognize.recongnize(l);
|
||||
GWT.log("Recongnized SERVERTYPE: " + mapserverType);
|
||||
|
||||
if (mapserverType != null) {
|
||||
if (mapserverType.equals(SERVERTYPE.MAPSERVER)) {
|
||||
GWT.log("wms url contains wxs is a map server? no appending /wfs ");
|
||||
outputformat = MapServerRecognize.outputFormatRecognize(SERVERTYPE.MAPSERVER, format);
|
||||
srsName = "EPSG:4326";
|
||||
boundingBox = reverseCoordinate(bbox, ","); // USE AXIS XY
|
||||
// TODO DEBUG
|
||||
GWT.log("SERVERTYPE.MAPSERVER outputformat: " + outputformat);
|
||||
GWT.log("SERVERTYPE.MAPSERVER srsName: " + srsName);
|
||||
GWT.log("SERVERTYPE.MAPSERVER boundingBox: " + boundingBox);
|
||||
} else {
|
||||
GWT.log("is geoserver appending suffix /wfs if is not present");
|
||||
link += link.endsWith("wfs") ? "" : "/wfs";
|
||||
outputformat = MapServerRecognize.outputFormatRecognize(SERVERTYPE.GEOSEVER, format);
|
||||
srsName = "urn:x-ogc:def:crs:"+srsName; // USE AXIS YX
|
||||
// TODO DEBUG
|
||||
GWT.log("SERVERTYPE.GEOSEVER outputformat: " + outputformat);
|
||||
GWT.log("SERVERTYPE.GEOSEVER srsName: " + srsName);
|
||||
}
|
||||
}
|
||||
|
||||
link += "?service=wfs&version=1.1.0" + "&REQUEST=GetFeature" + "&srsName=" + srsName + "&TYPENAME="
|
||||
+ l.getName() + (limit == 0 ? "" : "&MAXFEATURES=" + limit)
|
||||
+ (outputformat == null ? "" : "&OUTPUTFORMAT=" + outputformat);
|
||||
|
||||
if (l.getCqlFilter() != null && !l.getCqlFilter().isEmpty()) {
|
||||
if (l.getCqlFilter().contains("BBOX(the_geom")) {
|
||||
// THE BBOX IS ALREADY USED INTO CQL FILTERING, SO USING IT DIRECTLY
|
||||
link += "&" + CQL_FILTER_PARAMETER + "=" + l.getCqlFilter();
|
||||
} else {
|
||||
// I NEED TO ENCODE THE BBOX INTO CQL FILTERING,
|
||||
String cqlFilterValue = "BBOX(the_geom," + boundingBox + ")" + " AND " + l.getCqlFilter();
|
||||
|
||||
link += "&" + CQL_FILTER_PARAMETER + "=" + cqlFilterValue;
|
||||
}
|
||||
|
||||
} else {
|
||||
// NO CQL FILTERING APPLIED
|
||||
link += (boundingBox == null ? "" : "&BBOX=" + boundingBox);
|
||||
}
|
||||
|
||||
GWT.log("WFS: " + link);
|
||||
return link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse coordinate.
|
||||
*
|
||||
* @param BBOX the bbox
|
||||
* @param split eg. ,
|
||||
* @return a BBOX with reverse x and y coordinate
|
||||
*/
|
||||
public static String reverseCoordinate(String BBOX, String split) {
|
||||
|
||||
if (BBOX == null || BBOX.isEmpty()) {
|
||||
return BBOX;
|
||||
}
|
||||
|
||||
String[] splitted = BBOX.split(split);
|
||||
|
||||
for (String string : splitted) {
|
||||
System.out.println(string);
|
||||
}
|
||||
|
||||
if (splitted.length == 4) {
|
||||
return splitted[1] + split + splitted[0] + split + splitted[3] + split + splitted[2];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode url.
|
||||
*
|
||||
* @param url the url
|
||||
* @return the string
|
||||
*/
|
||||
public static String encodeUrl(String url) {
|
||||
String urlNew = url;
|
||||
for (String[] s : a) {
|
||||
urlNew = urlNew.replaceAll(s[0], s[1]);
|
||||
}
|
||||
return urlNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode url.
|
||||
*
|
||||
* @param url the url
|
||||
* @return the string
|
||||
*/
|
||||
public static String decodeUrl(String url) {
|
||||
String urlNew = url;
|
||||
for (String[] s : a) {
|
||||
urlNew = urlNew.replaceAll(s[1], s[0]);
|
||||
}
|
||||
return urlNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the last char.
|
||||
*
|
||||
* @param string the string
|
||||
* @return the string
|
||||
*/
|
||||
public static String removeLastChar(String string) {
|
||||
|
||||
if (string == null)
|
||||
return null;
|
||||
|
||||
if (string.length() > 0)
|
||||
return string.substring(0, string.length() - 1);
|
||||
|
||||
return string;
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.geoportaldataviewer.server.gis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.server.util.URLParserUtil;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.FeatureRow;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataObject;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class FeatureParser.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 29, 2020
|
||||
*/
|
||||
public class FeatureParser {
|
||||
|
||||
private static Logger LOG = LoggerFactory.getLogger(FeatureParser.class);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the data results.
|
||||
*
|
||||
* @param layerItems the layer items
|
||||
* @param mapSrsName the map srs name
|
||||
* @param mapBBOX the map BBOX
|
||||
* @param maxWFSFeature the max WFS feature
|
||||
* @return the data results
|
||||
*/
|
||||
public static List<GeoNaDataObject> getDataResults(List<LayerItem> layerItems, String mapSrsName, BoundsMap mapBBOX, int maxWFSFeature) {
|
||||
|
||||
if(maxWFSFeature<0) {
|
||||
maxWFSFeature = GeoportalDataViewerConstants.MAX_WFS_FEATURES;
|
||||
}
|
||||
|
||||
//IF WFS IS AVAILABLE USE WFS REQUEST OTHERWHISE TRY TO USE WPS SERVICE
|
||||
for (LayerItem layerItem : layerItems){
|
||||
List<FeatureRow> rows = getWFSFeatureProperties(layerItem, mapSrsName, mapBBOX, maxWFSFeature);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the WFS feature properties.
|
||||
*
|
||||
* @param layerItem the layer item
|
||||
* @param mapSrsName the map srs name
|
||||
* @param mapBBOX the map BBOX
|
||||
* @param maxWFSFeature the max WFS feature
|
||||
* @return the WFS feature properties
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<FeatureRow> getWFSFeatureProperties(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxWFSFeature) {
|
||||
|
||||
LOG.info("getTableFromJson -> Creating WfsTable to layerItem: "+layerItem.getName());
|
||||
InputStream is = null;
|
||||
List<FeatureRow> listFeaturesRow = new ArrayList<FeatureRow>();
|
||||
try {
|
||||
String url = GisMakers.buildWFSFeatureQuery(layerItem, mapSrsName, mapBBOX, maxWFSFeature, GisMakers.JSON);
|
||||
String cqlFilterValue = URLParserUtil.extractValueOfParameterFromURL(GisMakers.CQL_FILTER_PARAMETER, url);
|
||||
LOG.info("Found CQL filter value into query string: "+cqlFilterValue);
|
||||
|
||||
if(cqlFilterValue!=null) {
|
||||
String notEncodedCQLFilter = String.format("%s=%s",GisMakers.CQL_FILTER_PARAMETER,cqlFilterValue);
|
||||
//log.info("Found CQL filter: "+notEncodedCQLFilter);
|
||||
String toEncodeCQLFilter = String.format("%s=%s",GisMakers.CQL_FILTER_PARAMETER,URLEncoder.encode(cqlFilterValue,"UTF-8"));
|
||||
LOG.debug("Encoded CQL filter: "+toEncodeCQLFilter);
|
||||
url = url.replace(notEncodedCQLFilter, toEncodeCQLFilter);
|
||||
}
|
||||
|
||||
LOG.info("getTableFromJson -> WFS URL: "+url);
|
||||
is = new URL(url).openStream();
|
||||
String jsonTxt = IOUtils.toString(is);
|
||||
|
||||
if(jsonTxt==null || jsonTxt.isEmpty()){
|
||||
jsonTxt = "{\"type\":\"FeatureCollection\",\"features\":[]}";
|
||||
}
|
||||
|
||||
// get json object
|
||||
JSONObject json = new JSONObject(jsonTxt);
|
||||
// iterate features
|
||||
JSONArray features = json.getJSONArray("features");
|
||||
if(features.length()==0) {
|
||||
LOG.info("No features detected in the response, returning empty list");
|
||||
return listFeaturesRow;
|
||||
}
|
||||
|
||||
for (int i=0; i<features.length(); i++) {
|
||||
final FeatureRow row = new FeatureRow();
|
||||
JSONObject theFeature = ((JSONObject)features.get(i));
|
||||
LOG.debug("Building at index: "+i);
|
||||
// // iterate properties
|
||||
JSONObject properties = theFeature.getJSONObject("properties");
|
||||
Map<String,List<String>> mapProperties = new HashMap<String,List<String>>();
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<String> ii = properties.keys();
|
||||
while (ii.hasNext()) {
|
||||
String key = ii.next();
|
||||
String value = properties.optString(key,"");
|
||||
|
||||
List<String> theValues = mapProperties.get(key);
|
||||
if(theValues==null)
|
||||
mapProperties.put(key, Arrays.asList(value));
|
||||
else {
|
||||
theValues.add(value);
|
||||
mapProperties.put(key, theValues);
|
||||
}
|
||||
}
|
||||
|
||||
row.setMapProperties(mapProperties);
|
||||
listFeaturesRow.add(row);
|
||||
|
||||
LOG.info("Added row "+row+" to exported properties");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error for layerItem name: "+layerItem.getName(), e);
|
||||
} catch (JSONException e) {
|
||||
LOG.error("Error for layerItem name: "+layerItem.getName(), e);
|
||||
}finally{
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
|
||||
return listFeaturesRow;
|
||||
}
|
||||
}
|
@ -0,0 +1,213 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.server.gis;
|
||||
|
||||
import org.gcube.portlets.user.geoportaldataviewer.server.gis.MapServerRecognize.SERVERTYPE;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.server.util.URLParserUtil;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
||||
|
||||
import com.google.gwt.core.shared.GWT;
|
||||
|
||||
|
||||
/**
|
||||
* The Class URLMakers.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 29, 2020
|
||||
*/
|
||||
public class GisMakers {
|
||||
|
||||
public static final String CQL_FILTER_PARAMETER = "CQL_FILTER";
|
||||
|
||||
// MAP SERVER PIVOT
|
||||
public static final String WXS = "wxs";
|
||||
// GEOSERVER PIVOT
|
||||
public static final String WMS = "/wms";
|
||||
|
||||
// OUTPUT FORMAT
|
||||
public static final String CSV = "csv";
|
||||
|
||||
public static final String JSON = "json";
|
||||
|
||||
private static String[][] a = { { "\\?", "%3F" }, { "&", "%26" }, };
|
||||
|
||||
/**
|
||||
* The Enum COORDINATE_FORMAT.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 29, 2020
|
||||
*/
|
||||
public static enum COORDINATE_FORMAT {
|
||||
XY, YX
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Builds the WFS feature query.
|
||||
*
|
||||
* @param layerItem the layer item
|
||||
* @param mapSrsName the map srs name
|
||||
* @param mapBBOX the map BBOX
|
||||
* @param maxFeatures the max features
|
||||
* @param outputFormat the output format
|
||||
* @return the string
|
||||
*/
|
||||
public static String buildWFSFeatureQuery(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures, String outputFormat) {
|
||||
|
||||
String link = layerItem.getMapServerHost();
|
||||
GWT.log("Map server host URL: " + link);
|
||||
GWT.log("CQL filter is: " + layerItem.getCqlFilter());
|
||||
|
||||
String outputformat = null;
|
||||
String boundingBox = "";
|
||||
|
||||
// CASE MAP SERVER
|
||||
SERVERTYPE mapserverType = MapServerRecognize.recongnize(layerItem);
|
||||
GWT.log("Recongnized SERVERTYPE: " + mapserverType);
|
||||
|
||||
if (mapserverType != null) {
|
||||
if (mapserverType.equals(SERVERTYPE.MAPSERVER)) {
|
||||
GWT.log("wms url contains wxs is a map server? no appending /wfs ");
|
||||
outputformat = MapServerRecognize.outputFormatRecognize(SERVERTYPE.MAPSERVER, outputFormat);
|
||||
mapSrsName = "EPSG:4326";
|
||||
boundingBox = BBOX_FORMAT(COORDINATE_FORMAT.XY, ",",mapBBOX.getLowerLeftX(),mapBBOX.getLowerLeftY(),mapBBOX.getUpperRightX(),mapBBOX.getUpperRightY()); // USE AXIS XY
|
||||
// TODO DEBUG
|
||||
GWT.log("SERVERTYPE.MAPSERVER outputformat: " + outputformat);
|
||||
GWT.log("SERVERTYPE.MAPSERVER srsName: " + mapSrsName);
|
||||
GWT.log("SERVERTYPE.MAPSERVER boundingBox: " + boundingBox);
|
||||
} else {
|
||||
GWT.log("is geoserver appending suffix /wfs if is not present");
|
||||
link += link.endsWith("wfs") ? "" : "/wfs";
|
||||
outputformat = MapServerRecognize.outputFormatRecognize(SERVERTYPE.GEOSEVER, outputFormat);
|
||||
mapSrsName = "urn:x-ogc:def:crs:"+mapSrsName; // USE AXIS YX
|
||||
boundingBox = BBOX_FORMAT(COORDINATE_FORMAT.YX, ",",mapBBOX.getLowerLeftX(),mapBBOX.getLowerLeftY(),mapBBOX.getUpperRightX(),mapBBOX.getUpperRightY()); // USE AXIS XY
|
||||
// TODO DEBUG
|
||||
GWT.log("SERVERTYPE.GEOSEVER outputformat: " + outputformat);
|
||||
GWT.log("SERVERTYPE.GEOSEVER srsName: " + mapSrsName);
|
||||
}
|
||||
}
|
||||
//
|
||||
// link += "?service=wfs&version=1.1.0" + "&REQUEST=GetFeature" + "&srsName=" + srsName + "&TYPENAME="
|
||||
// + layerItem.getName() + (limit == 0 ? "" : "&MAXFEATURES=" + limit)
|
||||
// + (outputformat == null ? "" : "&OUTPUTFORMAT=" + outputformat);
|
||||
//
|
||||
|
||||
link += "?"+
|
||||
URLParserUtil.addParameterToQueryString(WFSGetFeature.SERVICE.getParameter(), WFSGetFeature.SERVICE.getValue(), false, true)+
|
||||
URLParserUtil.addParameterToQueryString(WFSGetFeature.VERSION.getParameter(), WFSGetFeature.VERSION.getValue(), false, true)+
|
||||
URLParserUtil.addParameterToQueryString(WFSGetFeature.REQUEST.getParameter(), WFSGetFeature.REQUEST.getValue(), false, true)+
|
||||
URLParserUtil.addParameterToQueryString(WFSGetFeature.SRSNAME.getParameter(), mapSrsName, false, true)+
|
||||
URLParserUtil.addParameterToQueryString(WFSGetFeature.TYPENAME.getParameter(), layerItem.getName(), false, true)+
|
||||
(maxFeatures == 0 ? "" : URLParserUtil.addParameterToQueryString(WFSGetFeature.MAXFEATURES.getParameter(), maxFeatures+"", false, true))+
|
||||
(outputformat == null ? "" : URLParserUtil.addParameterToQueryString(WFSGetFeature.OUTPUTFORMAT.getParameter(), outputformat, false, false));
|
||||
|
||||
|
||||
if (layerItem.getCqlFilter() != null && !layerItem.getCqlFilter().isEmpty()) {
|
||||
if (layerItem.getCqlFilter().contains("BBOX(the_geom")) {
|
||||
// THE BBOX IS ALREADY USED INTO CQL FILTERING, SO USING IT DIRECTLY
|
||||
link += "&" + CQL_FILTER_PARAMETER + "=" + layerItem.getCqlFilter();
|
||||
} else {
|
||||
// I NEED TO ENCODE THE BBOX INTO CQL FILTERING,
|
||||
String cqlFilterValue = "BBOX(the_geom," + boundingBox + ")" + " AND " + layerItem.getCqlFilter();
|
||||
|
||||
link += "&" + CQL_FILTER_PARAMETER + "=" + cqlFilterValue;
|
||||
}
|
||||
|
||||
} else {
|
||||
// NO CQL FILTERING APPLIED
|
||||
link += (boundingBox == null ? "" : "&BBOX=" + boundingBox);
|
||||
}
|
||||
|
||||
GWT.log("WFS: " + link);
|
||||
return link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode url.
|
||||
*
|
||||
* @param url the url
|
||||
* @return the string
|
||||
*/
|
||||
public static String encodeUrl(String url) {
|
||||
String urlNew = url;
|
||||
for (String[] s : a) {
|
||||
urlNew = urlNew.replaceAll(s[0], s[1]);
|
||||
}
|
||||
return urlNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode url.
|
||||
*
|
||||
* @param url the url
|
||||
* @return the string
|
||||
*/
|
||||
public static String decodeUrl(String url) {
|
||||
String urlNew = url;
|
||||
for (String[] s : a) {
|
||||
urlNew = urlNew.replaceAll(s[1], s[0]);
|
||||
}
|
||||
return urlNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the last char.
|
||||
*
|
||||
* @param string the string
|
||||
* @return the string
|
||||
*/
|
||||
public static String removeLastChar(String string) {
|
||||
|
||||
if (string == null)
|
||||
return null;
|
||||
|
||||
if (string.length() > 0)
|
||||
return string.substring(0, string.length() - 1);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format.
|
||||
*
|
||||
* @param format the format
|
||||
* @param separator the separator
|
||||
* @return the string
|
||||
*/
|
||||
public static String BBOX_FORMAT(COORDINATE_FORMAT format, String separator, double lowerLeftX, double lowerLeftY, double upperRightX, double upperRightY) {
|
||||
|
||||
if(format==null)
|
||||
format = COORDINATE_FORMAT.XY;
|
||||
|
||||
if(separator==null)
|
||||
separator = ",";
|
||||
|
||||
switch (format) {
|
||||
case XY:
|
||||
return String.format("%s%s%s%s%s%s%s",
|
||||
String.valueOf(lowerLeftX),
|
||||
separator,
|
||||
String.valueOf(lowerLeftY),
|
||||
separator,
|
||||
String.valueOf(upperRightX),
|
||||
separator,
|
||||
String.valueOf(upperRightY)
|
||||
);
|
||||
case YX:
|
||||
return String.format("%s%s%s%s%s%s%s",
|
||||
String.valueOf(lowerLeftY),
|
||||
separator,
|
||||
String.valueOf(lowerLeftX),
|
||||
separator,
|
||||
String.valueOf(upperRightY),
|
||||
separator,
|
||||
String.valueOf(upperRightX)
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.server.gis;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Enum WfsParameters.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 29, 2020
|
||||
*/
|
||||
public enum WFSGetFeature {
|
||||
|
||||
SERVICE("SERVICE", "WFS"),
|
||||
VERSION("VERSION", "1.1.0"),
|
||||
REQUEST("REQUEST", "GetFeature"),
|
||||
TYPENAME("TYPENAME", ""),
|
||||
STYLES("STYLES",""),
|
||||
BBOX("BBOX","-180,-90,180,90"),
|
||||
WIDTH("WIDTH","676"),
|
||||
HEIGHT("HEIGHT","230"),
|
||||
SRSNAME("srsName","EPSG:4326"),
|
||||
// CRS("CRS","EPSG:4326"), //WMS 1.3.0 COMPLIANT
|
||||
OUTPUTFORMAT("OUTPUTFORMAT","json"),
|
||||
MAXFEATURES("MAXFEATURES","");
|
||||
|
||||
private String parameter;
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* Instantiates a new wfs parameters.
|
||||
*
|
||||
* @param parameter the parameter
|
||||
* @param value the value
|
||||
*/
|
||||
WFSGetFeature(String parameter, String value){
|
||||
this.parameter = parameter;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameter.
|
||||
*
|
||||
* @return the parameter
|
||||
*/
|
||||
public String getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameter.
|
||||
*
|
||||
* @param parameter the new parameter
|
||||
*/
|
||||
public void setParameter(String parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.server.util;
|
||||
|
||||
/**
|
||||
* The Class URLUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 29, 2020
|
||||
*/
|
||||
public class URLParserUtil {
|
||||
|
||||
/**
|
||||
* Gets the value of parameter.
|
||||
*
|
||||
* @param paramName the param name
|
||||
* @param url the url
|
||||
* @return the value of parameter
|
||||
*/
|
||||
public static String getValueOfParameter(String paramName, String url) {
|
||||
// logger.trace("finding: "+wmsParam +" into "+url);
|
||||
int index = url.toLowerCase().indexOf(paramName.toLowerCase()+"="); //ADDING CHAR "=" IN TAIL TO BE SECURE IT IS A PARAMETER
|
||||
// logger.trace("start index of "+wmsParam+ " is: "+index);
|
||||
String value = "";
|
||||
if(index > -1){
|
||||
int start = index + paramName.length()+1; //add +1 for char '='
|
||||
String sub = url.substring(start, url.length());
|
||||
int indexOfSeparator = sub.indexOf("&");
|
||||
int end = indexOfSeparator!=-1?indexOfSeparator:sub.length();
|
||||
value = sub.substring(0, end);
|
||||
}else
|
||||
return null;
|
||||
|
||||
// logger.trace("return value: "+value);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the parameter to query string.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
* @param prefixAmpersand the prefix ampersand
|
||||
* @param suffixAmpersand the suffix ampersand
|
||||
* @return the string
|
||||
*/
|
||||
public static String addParameterToQueryString(String key, String value, boolean prefixAmpersand, boolean suffixAmpersand) {
|
||||
|
||||
String queryParameter = "";
|
||||
|
||||
if(prefixAmpersand)
|
||||
queryParameter+="&";
|
||||
|
||||
queryParameter+=key+"="+value;
|
||||
|
||||
if(suffixAmpersand)
|
||||
queryParameter+="&";
|
||||
|
||||
return queryParameter;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract value of parameter from URL.
|
||||
*
|
||||
* @param paramName the param name
|
||||
* @param url the url
|
||||
* @return the string
|
||||
*/
|
||||
public static String extractValueOfParameterFromURL(String paramName, String url) {
|
||||
int index = url.toLowerCase().indexOf(paramName.toLowerCase() + "="); // ADDING CHAR "=" IN TAIL TO BE SURE THAT IT
|
||||
// IS A PARAMETER
|
||||
String value = "";
|
||||
if (index > -1) {
|
||||
|
||||
int start = index + paramName.length() + 1; // add +1 for char '='
|
||||
String sub = url.substring(start, url.length());
|
||||
int indexOfSeparator = sub.indexOf("&");
|
||||
int end = indexOfSeparator != -1 ? indexOfSeparator : sub.length();
|
||||
value = sub.substring(0, end);
|
||||
} else
|
||||
return null;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.geoportaldataviewer.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* The Class FeatureRow.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 29, 2020
|
||||
*/
|
||||
public class FeatureRow implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6254861811998867626L;
|
||||
|
||||
private Map<String, List<String>> mapProperties;
|
||||
|
||||
|
||||
|
||||
public Map<String, List<String>> getMapProperties() {
|
||||
return mapProperties;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setMapProperties(Map<String, List<String>> mapProperties) {
|
||||
this.mapProperties = mapProperties;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("FeatureRow [mapValues=");
|
||||
builder.append(mapProperties);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package org.gcube.portlets.user.geoportaldataviewer.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* The Class GeoNaDataObject.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 29, 2020
|
||||
*/
|
||||
public class GeoNaDataObject implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 5566069859060851625L;
|
||||
/** The form data entry fields. */
|
||||
private Map<String, List<String>> dataEntryFields;
|
||||
private String geonaDataType;
|
||||
|
||||
/**
|
||||
* Instantiates a new geo na data object.
|
||||
*/
|
||||
public GeoNaDataObject(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data entry fields.
|
||||
*
|
||||
* @return the data entry fields
|
||||
*/
|
||||
public Map<String, List<String>> getDataEntryFields() {
|
||||
return dataEntryFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data entry fields.
|
||||
*
|
||||
* @param dataEntryFields the data entry fields
|
||||
*/
|
||||
public void setDataEntryFields(Map<String, List<String>> dataEntryFields) {
|
||||
this.dataEntryFields = dataEntryFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the geona data type.
|
||||
*
|
||||
* @return the geona data type
|
||||
*/
|
||||
public String getGeonaDataType() {
|
||||
return geonaDataType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the geona data type.
|
||||
*
|
||||
* @param geonaDataType the new geona data type
|
||||
*/
|
||||
public void setGeonaDataType(String geonaDataType) {
|
||||
this.geonaDataType = geonaDataType;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("GeoNaFormDataObject [dataEntryFields=");
|
||||
builder.append(dataEntryFields);
|
||||
builder.append(", geonaDataType=");
|
||||
builder.append(geonaDataType);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue