diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs index ff5aa39..d16c112 100644 --- a/.settings/com.gwtplugins.gdt.eclipse.core.prefs +++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs @@ -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 diff --git a/pom.xml b/pom.xml index a77f1b6..9f6c200 100644 --- a/pom.xml +++ b/pom.xml @@ -48,29 +48,29 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -114,7 +114,18 @@ [2.4.1,3.0.0-SNAPSHOT) provided - + + org.gcube.application + geoportal-logic + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + compile + + + javax.servlet + servlet-api + + + com.liferay.portal portal-service diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java index ea02b17..3e7bb51 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java @@ -49,6 +49,8 @@ public class GeoportalDataViewer implements EntryPoint { /** The layer manager. */ private LayerManager layerManager = new LayerManager(); + + //https://data.d4science.org/gis-viewer-app/?wmsrequest=https%3A%2F%2Fgeona-proto.d4science.org%2Fgeoserver%2Fconcessioni_conf%2Fwms%3Fservice%3DWMS%26version%3D1.1.0%26request%3DGetMap%26layers%3Dconcessioni_conf%3Acentroids_concessioni%26styles%3D%26bbox%3D8.476%2C39.179%2C17.391%2C45.772%26width%3D768%26height%3D567%26srs%3DEPSG%3A4326%26format%3Dapplication%2Fopenlayers&zoom=6¢ermap=12.45%2C42.98 /** * This is the entry point method. @@ -63,7 +65,7 @@ public class GeoportalDataViewer implements EntryPoint { @Override public void execute() { - olMap = new OpenLayerOSM(mainPanel.getMapPanel().getElement().getId()); + olMap = new OpenLayerOSM(mainPanel.getMapPanel().getElement().getId(),layerManager.getEventBus()); layerManager.setOlMap(olMap); mainPanel.setMap(olMap); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java index b98b221..dbc3cb6 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java @@ -17,5 +17,7 @@ public class GeoportalDataViewerConstants { public static final String GET_CENTER_MAP_TO_LONG_LAT = OpenLayersMapParameters.OL_MAP_PARAM.centermap.name(); public enum LayerType {RASTER_BASELAYER, FEATURE_TYPE}; + + public static final int MAX_WFS_FEATURES = 5; // zero for no limit } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java index 371c925..7614141 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java @@ -1,6 +1,11 @@ package org.gcube.portlets.user.geoportaldataviewer.client; +import java.util.List; + +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.GeoInformationForWMSRequest; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -13,4 +18,7 @@ public interface GeoportalDataViewerService extends RemoteService { GeoInformationForWMSRequest parseWmsRequest(String wmsRequest, String layerName) throws Exception; + List getDataResult(List layerItems, String mapSrsName, BoundsMap mapBBOX, + int maxWFSFeature, double zoomLevel); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java index 3fd7240..e0a1dd7 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java @@ -1,6 +1,11 @@ package org.gcube.portlets.user.geoportaldataviewer.client; +import java.util.List; + +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.GeoInformationForWMSRequest; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -25,4 +30,7 @@ public interface GeoportalDataViewerServiceAsync { } void parseWmsRequest(String wmsRequest, String layerName, AsyncCallback callback); + + void getDataResult(List layerItems, String mapSrsName, BoundsMap mapBBOX, int maxWFSFeature, double zoomLevel, + AsyncCallback> callback); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java index 0e3e7f4..3c5796a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java @@ -5,17 +5,23 @@ import java.util.HashMap; import java.util.List; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.LayerType; +import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM; import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; +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.GeoInformationForWMSRequest; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.ZAxis; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; -// TODO: Auto-generated Javadoc + /** * The Class LayerManager. * @@ -30,14 +36,56 @@ public class LayerManager { /** The layer items. */ private List layerItems = new ArrayList(); + + private HandlerManager eventBus = new HandlerManager(""); /** * Instantiates a new layer manager. */ public LayerManager() { + bindEvents(); } + private void bindEvents() { + + eventBus.addHandler(QueryDataEvent.TYPE, new QueryDataEventHandler() { + + @Override + public void onQueryInteraction(QueryDataEvent queryEvent) { + + if(queryEvent.getGeoQuery()!=null) { + GeoQuery selectDataInfo = queryEvent.getGeoQuery(); + GWT.log("("+selectDataInfo.getX1()+","+selectDataInfo.getY1()+")("+selectDataInfo.getX2()+","+selectDataInfo.getY2()+")"); + + for (LayerItem layerItem : layerItems){ + //TODO + isLayerVisible(layerItem); + + } + BoundsMap mapBBOX = new BoundsMap(); + mapBBOX.setCrs(olMap.getProjectionCode()); + mapBBOX.setLowerLeftX(olMap.getExtent().getLowerLeftX()); + mapBBOX.setLowerLeftY(olMap.getExtent().getLowerLeftY()); + mapBBOX.setUpperRightX(olMap.getExtent().getUpperRightX()); + mapBBOX.setUpperRightY(olMap.getExtent().getUpperRightY()); + + GeoportalDataViewerServiceAsync.Util.getInstance().getDataResult(layerItems, olMap.getProjectionCode(), mapBBOX, GeoportalDataViewerConstants.MAX_WFS_FEATURES, olMap.getCurrentZoomLevel(), new AsyncCallback>() { + + @Override + public void onFailure(Throwable caught) { + } + + @Override + public void onSuccess(List result) { + } + }); + } + } + }); + } + + /** * Adds the layer by wms. * @@ -119,20 +167,20 @@ public class LayerManager { private void addLayerByWms(LayerType layerType, String layerTitle, String layerName, String layerURL, String mapServerHost, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, ArrayList styles, String serverWmsRequest, boolean onTop, HashMap wmsNotStandardParams, boolean isNcWms, String UUID, ZAxis zAxis) { // GWT.log("Add addLayerByWms 1"); - LayerItem l = new LayerItem(); - l.setBaseLayer(isBase); - l.setTitle(layerTitle); - l.setName(layerName); - l.setUrl(layerURL); - l.setMapServerHost(mapServerHost); + LayerItem layerItem = new LayerItem(); + layerItem.setBaseLayer(isBase); + layerItem.setTitle(layerTitle); + layerItem.setName(layerName); + layerItem.setUrl(layerURL); + layerItem.setMapServerHost(mapServerHost); //l.setExternal(isExternal); - l.setOpacity(1d); - l.setBuffer(2); - l.setServerWmsRequest(serverWmsRequest); - l.setWmsNotStandardParams(wmsNotStandardParams); - l.setNcWms(isNcWms); - l.setUUID(UUID); - l.setZAxis(zAxis); + layerItem.setOpacity(1d); + layerItem.setBuffer(2); + layerItem.setServerWmsRequest(serverWmsRequest); + layerItem.setWmsNotStandardParams(wmsNotStandardParams); + layerItem.setNcWms(isNcWms); + layerItem.setUUID(UUID); + layerItem.setZAxis(zAxis); switch (layerType) { @@ -140,17 +188,17 @@ public class LayerManager { case RASTER_BASELAYER: // l.setHasLegend(false); - l.setBaseLayer(true); - l.setTrasparent(false); - l.setClickData(false); + layerItem.setBaseLayer(true); + layerItem.setTrasparent(false); + layerItem.setClickData(false); break; case FEATURE_TYPE: //CASE FEATURE TYPE - l.setBaseLayer(false); - l.setClickData(true); - l.setTrasparent(true); + layerItem.setBaseLayer(false); + layerItem.setClickData(true); + layerItem.setTrasparent(true); break; } @@ -158,20 +206,20 @@ public class LayerManager { GWT.log("styles "+styles); if(styles!=null && styles.size()>0){ - l.setHasLegend(true); - l.setDefaultStyle(styles.get(0)); - l.setStyle(styles.get(0)); - l.setStyles(styles); + layerItem.setHasLegend(true); + layerItem.setDefaultStyle(styles.get(0)); + layerItem.setStyle(styles.get(0)); + layerItem.setStyles(styles); }else{ String style = URLUtil.getValueOfParameter("styles", serverWmsRequest); if(style!=null){ //CASE OF STYLE =""; //TENTATIVE TO GET LEGEND - l.setHasLegend(true); + layerItem.setHasLegend(true); } } - GWT.log("Built layer: "+l); - layerItems.add(l); - olMap.addWMSLayer(l.getMapServerHost(), layerName); + GWT.log("Built layer: "+layerItem); + layerItems.add(layerItem); + olMap.addWMSLayer(layerItem.getMapServerHost(), layerName); // openLayersMap.addLayerItemByWms(l, displayInLayerSwitcher); // layersPanel.addLayerItems(layerItems, onTop); @@ -179,6 +227,17 @@ public class LayerManager { } + /** + * Checks if is layer visible. + * + * @param layerItem the layer item + * @return true, if is layer visible + */ + public boolean isLayerVisible(LayerItem layerItem){ + return olMap.isLayerVisible(layerItem.getName()); + } + + /** * Sets the ol map. * @@ -187,6 +246,11 @@ public class LayerManager { public void setOlMap(OpenLayerOSM olMap) { this.olMap = olMap; } + + public HandlerManager getEventBus() { + return eventBus; + } + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/QueryDataEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/QueryDataEvent.java new file mode 100644 index 0000000..eb205b1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/QueryDataEvent.java @@ -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 { + public static Type TYPE = new Type(); + 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 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; + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/QueryDataEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/QueryDataEventHandler.java new file mode 100644 index 0000000..4fe3fd3 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/QueryDataEventHandler.java @@ -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); +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/DemoUtils.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/DemoUtils.java index 7f04fda..cfda852 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/DemoUtils.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/DemoUtils.java @@ -18,7 +18,6 @@ import ol.control.ControlOptions; import ol.control.FullScreen; import ol.control.MousePosition; import ol.control.ZoomSlider; -import ol.control.ZoomToExtent; import ol.geom.Polygon; import ol.layer.Base; import ol.layer.LayerOptions; @@ -49,7 +48,7 @@ public final class DemoUtils { MousePosition mousePosition = new MousePosition(); mousePosition.setCoordinateFormat(Coordinate.createStringXY(5)); controls.push(mousePosition); - controls.push(new ZoomToExtent()); + //controls.push(new ZoomToExtent()); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java index cd72f53..7e80634 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerOSM.java @@ -1,10 +1,12 @@ package org.gcube.portlets.user.geoportaldataviewer.client.gis; -import java.net.MalformedURLException; - import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants; +import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery.TYPE; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; @@ -21,7 +23,6 @@ import ol.View; import ol.ViewOptions; import ol.control.Attribution; import ol.event.EventListener; -import ol.geom.Point; import ol.interaction.Draw; import ol.interaction.DrawOptions; import ol.interaction.Extent; @@ -29,6 +30,7 @@ import ol.interaction.ExtentOptions; import ol.interaction.Interaction; import ol.interaction.KeyboardPan; import ol.interaction.KeyboardZoom; +import ol.layer.Base; import ol.layer.Image; import ol.layer.LayerOptions; import ol.layer.Tile; @@ -72,15 +74,24 @@ public class OpenLayerOSM { /** The popup overlay. */ private Overlay popupOverlay; + private HandlerManager eventBus; + + private boolean isQueryBoxActive; + + private boolean isQueryPointActive; + + /** * Instantiates a new open layer OSM. * * @param divTargetId the div target id + * @param eventBus the event bus */ /* (non-Javadoc) * @see de.desjardins.ol3.demo.client.example.Example#show() */ - public OpenLayerOSM(String divTargetId) { + public OpenLayerOSM(String divTargetId, HandlerManager eventBus) { + this.eventBus = eventBus; // create a OSM-layer XyzOptions osmSourceOptions = OLFactory.createOptions(); @@ -132,7 +143,7 @@ public class OpenLayerOSM { public void onEvent(MapBrowserEvent event) { // TODO Auto-generated method stub Coordinate coordinate = event.getCoordinate(); - if(queryPoint!=null && queryPoint.getActive()) { + if(isQueryPointActive) { double lon = coordinate.getX(); double lat = coordinate.getY(); @@ -149,22 +160,19 @@ public class OpenLayerOSM { double x2 = Math.max(lon+geoWidth, lon-geoWidth); double y1 = Math.min(lat+geoWidth, lat-geoWidth); double y2 = Math.max(lat+geoWidth, lat-geoWidth); - GWT.log("("+x1+","+y1+")("+x2+","+y2+")"); + //GWT.log("("+x1+","+y1+")("+x2+","+y2+")"); - Point pt = new Point(coordinate); - ol.Extent extent = pt.getExtent(); - selectBox(x1, y1, x2, y2); +// Point pt = new Point(coordinate); +// ol.Extent extent = pt.getExtent(); +// //new ClickDataInfo(x1, y1, x2, y2) +// SelectDataInfo selectDataInfo + //selectBox(new GeoQuery(x1, y1, x2, y2, GeoQuery.TYPE.POINT)); + GeoQuery select = new GeoQuery(x1, y1, x2, y2, TYPE.POINT); + eventBus.fireEvent(new QueryDataEvent(select,coordinate)); } - if(popupOverlay==null) { - Element elPopup = DOM.getElementById("popup"); - popupOverlay = addOverlay(elPopup); - addPopupCloserHandelr(popupOverlay); - } - Element popContent = DOM.getElementById("popup-content"); - popContent.setInnerHTML("

You clicked here:

" + coordinate + "");; - popupOverlay.setPosition(coordinate); + } }); @@ -176,13 +184,15 @@ public class OpenLayerOSM { } - /** - * Gets the extent. - * - * @return the extent - */ - public ol.Extent getExtent() { - return this.map.getView().calculateExtent(map.getSize()); + public void showPopup(String html, Coordinate coordinate) { + if(popupOverlay==null) { + Element elPopup = DOM.getElementById("popup"); + popupOverlay = addOverlay(elPopup); + addPopupCloserHandelr(popupOverlay); + } + Element popContent = DOM.getElementById("popup-content"); + popContent.setInnerHTML(html); + popupOverlay.setPosition(coordinate); } /** @@ -224,7 +234,9 @@ public class OpenLayerOSM { /** * Adds the WMS layer. - * @throws MalformedURLException + * + * @param mapServerHost the map server host + * @param layerName the layer name */ public void addWMSLayer(String mapServerHost, String layerName) { @@ -242,7 +254,9 @@ public class OpenLayerOSM { layerOptions.setSource(imageWMSSource); Image wmsLayer = new Image(layerOptions); - + + //visibleLayerItems + map.addLayer(wmsLayer); } @@ -257,6 +271,7 @@ public class OpenLayerOSM { initPointInteraction(); map.addInteraction(queryPoint); + isQueryPointActive = true; return queryPoint; } @@ -300,10 +315,8 @@ public class OpenLayerOSM { if(interactions!=null) { map.removeInteraction(queryBox); map.removeInteraction(queryPoint); - //for (int i = 0; i < inters.length; i++) { -// Interaction inter = inters[i]; -// map.removeInteraction(inter); - //} + isQueryBoxActive = false; + isQueryPointActive = false; } } @@ -321,6 +334,7 @@ public class OpenLayerOSM { //extentOptions.setBoxStyle(new ol.style.Style(styleOptions)); queryBox = new Extent(extentOptions); map.addInteraction(queryBox); + isQueryBoxActive = true; return queryBox; } @@ -342,16 +356,71 @@ public class OpenLayerOSM { map.addOverlay(overlay); return overlay; } + + /** + * Checks if is layer visible. + * + * @param layerName the layer name + * @return true, if is layer visible + */ + public boolean isLayerVisible(String layerName) { + + Collection layers = map.getLayers(); + + if(layers!=null) { + Base[] layersArr = layers.getArray(); + for (int i = 0; i < layersArr.length; i++) { + Base layer = layersArr[i]; + String theLayerName = (String) layer.get("name"); + GWT.log("The Layer name is: "+layerName); + if(theLayerName!=null && theLayerName.equals(layerName)) + return true; + } + } + + return false; + } - public void selectBox(double x1, double y1, double x2, double y2) { - //ClickDataInfo cdi = new ClickDataInfo(x1, y1, x2, y2); - GWT.log("("+x1+","+y1+")("+x2+","+y2+")"); + /** + * Gets the projection code. + * + * @return the projection code + */ + public String getProjectionCode() { + return map.getView().getProjection().getCode(); + } + + /** + * Gets the current zoom level. + * + * @return the current zoom level + */ + public double getCurrentZoomLevel() { + return map.getView().getZoom(); } + /** + * Gets the bbox. + * + * @return the bbox + */ + public ol.Extent getBBOX() { + return getExtent(); + } + + /** + * Gets the extent. + * + * @return the extent + */ + public ol.Extent getExtent() { + return this.map.getView().calculateExtent(map.getSize()); + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/URLMakers.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/URLMakers.java deleted file mode 100644 index 9e44e70..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/URLMakers.java +++ /dev/null @@ -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 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 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 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; - } -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/URLUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/URLUtil.java index 385a160..adb64bd 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/URLUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/URLUtil.java @@ -1,5 +1,12 @@ package org.gcube.portlets.user.geoportaldataviewer.client.util; +/** + * The Class URLUtil. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Oct 29, 2020 + */ public class URLUtil { /** @@ -26,5 +33,56 @@ public class URLUtil { // 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; + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java index cfc4e59..90aa703 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java @@ -1,11 +1,16 @@ package org.gcube.portlets.user.geoportaldataviewer.server; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerService; +import org.gcube.portlets.user.geoportaldataviewer.server.gis.FeatureParser; import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator; +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.GeoInformationForWMSRequest; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.Styles; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.ZAxis; import org.gcube.spatial.data.geoutility.GeoNcWMSMetadataUtility; @@ -74,4 +79,15 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme throw new Exception(msg); } } + + /* (non-Javadoc) + * @see org.gcube.portlets.user.gisviewer.client.GisViewerService#getDataResult(java.util.List, java.lang.String, int) + */ + @Override + public List getDataResult(List layerItems, String mapSrsName, BoundsMap mapBBOX, int maxWFSFeature, double zoomLevel) { + LOG.info("getDataResult called"); + List result = FeatureParser.getDataResults(layerItems, mapSrsName, mapBBOX, maxWFSFeature); + return result; + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/FeatureParser.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/FeatureParser.java new file mode 100644 index 0000000..4eded49 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/FeatureParser.java @@ -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 getDataResults(List 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 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 getWFSFeatureProperties(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxWFSFeature) { + + LOG.info("getTableFromJson -> Creating WfsTable to layerItem: "+layerItem.getName()); + InputStream is = null; + List listFeaturesRow = new ArrayList(); + 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> mapProperties = new HashMap>(); + @SuppressWarnings("unchecked") + Iterator ii = properties.keys(); + while (ii.hasNext()) { + String key = ii.next(); + String value = properties.optString(key,""); + + List 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; + } +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/GisMakers.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/GisMakers.java new file mode 100644 index 0000000..4493061 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/GisMakers.java @@ -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; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/MapServerRecognize.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/MapServerRecognize.java similarity index 59% rename from src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/MapServerRecognize.java rename to src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/MapServerRecognize.java index 5ec0a33..d315462 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/MapServerRecognize.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/MapServerRecognize.java @@ -1,23 +1,38 @@ /** * */ -package org.gcube.portlets.user.geoportaldataviewer.client.util; +package org.gcube.portlets.user.geoportaldataviewer.server.gis; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import com.google.gwt.core.shared.GWT; /** + * The Class MapServerRecognize. + * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @Aug 29, 2014 * - *THIS CLASS DISCRIMINATES BETWEEN GEOSERVER AND MAPSERVER - *ACCORDING TO THE VALUE OF LAYER URL + * THIS CLASS DISCRIMINATES BETWEEN GEOSERVER AND MAPSERVER + * ACCORDING TO THE VALUE OF LAYER URL */ public class MapServerRecognize { + /** + * The Enum SERVERTYPE. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Oct 29, 2020 + */ public static enum SERVERTYPE{GEOSEVER, MAPSERVER}; + /** + * Recongnize. + * + * @param l the l + * @return the servertype + */ public static SERVERTYPE recongnize(LayerItem l){ if(l==null) @@ -26,13 +41,19 @@ public class MapServerRecognize { return recongnize(l.getUrl()); } + /** + * Recongnize. + * + * @param baseServerUrl the base server url + * @return the servertype + */ public static SERVERTYPE recongnize(String baseServerUrl){ if(baseServerUrl==null || baseServerUrl.isEmpty()) return null; //CASE MAP SERVER - if(baseServerUrl.contains(URLMakers.WXS)){ + if(baseServerUrl.contains(GisMakers.WXS)){ GWT.log("wms url contains 'wxs' returning "+SERVERTYPE.MAPSERVER); return SERVERTYPE.MAPSERVER; }else{ @@ -43,10 +64,11 @@ public class MapServerRecognize { } /** - * - * @param serverType - * @param output - * @return + * Output format recognize. + * + * @param serverType the server type + * @param output the output + * @return the string */ public static String outputFormatRecognize(SERVERTYPE serverType, String output){ @@ -59,17 +81,17 @@ public class MapServerRecognize { switch (serverType) { case GEOSEVER: - if(output.contains(URLMakers.JSON)) + if(output.contains(GisMakers.JSON)) return "json"; - else if(output.contains(URLMakers.CSV)) + else if(output.contains(GisMakers.CSV)) return "csv"; break; case MAPSERVER: - if(output.contains(URLMakers.JSON)) + if(output.contains(GisMakers.JSON)) return "application/json;%20subtype=geojson"; - else if(output.contains(URLMakers.CSV)) + else if(output.contains(GisMakers.CSV)) return "csv"; break; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WFSGetFeature.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WFSGetFeature.java new file mode 100644 index 0000000..079b716 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WFSGetFeature.java @@ -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; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/URLParserUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/URLParserUtil.java new file mode 100644 index 0000000..4721ed1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/URLParserUtil.java @@ -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; + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/FeatureRow.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/FeatureRow.java new file mode 100644 index 0000000..55ac712 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/FeatureRow.java @@ -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> mapProperties; + + + + public Map> getMapProperties() { + return mapProperties; + } + + + + public void setMapProperties(Map> 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(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaDataObject.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaDataObject.java new file mode 100644 index 0000000..c62e364 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaDataObject.java @@ -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> 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> getDataEntryFields() { + return dataEntryFields; + } + + /** + * Sets the data entry fields. + * + * @param dataEntryFields the data entry fields + */ + public void setDataEntryFields(Map> 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(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/BoundsMap.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/BoundsMap.java index 7e0b5ff..ddc284a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/BoundsMap.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/BoundsMap.java @@ -10,7 +10,8 @@ import java.io.Serializable; * Oct 27, 2020 */ public class BoundsMap implements Serializable{ - + + /** * */ @@ -31,6 +32,8 @@ public class BoundsMap implements Serializable{ /** The crs. */ private String crs = ""; + + /** * Instantiates a new bounds map. */ @@ -145,11 +148,22 @@ public class BoundsMap implements Serializable{ public void setCrs(String crs) { this.crs = crs; } - + @Override public String toString() { - return "BoundsMap [lowerLeftX=" + lowerLeftX + ", lowerLeftY=" + lowerLeftY + ", upperRightX=" + upperRightX - + ", upperRightY=" + upperRightY + ", crs=" + crs + "]"; + StringBuilder builder = new StringBuilder(); + builder.append("BoundsMap [lowerLeftX="); + builder.append(lowerLeftX); + builder.append(", lowerLeftY="); + builder.append(lowerLeftY); + builder.append(", upperRightX="); + builder.append(upperRightX); + builder.append(", upperRightY="); + builder.append(upperRightY); + builder.append(", crs="); + builder.append(crs); + builder.append("]"); + return builder.toString(); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/ClickDataInfo.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/GeoQuery.java similarity index 55% rename from src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/ClickDataInfo.java rename to src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/GeoQuery.java index 2793d88..1bf6d7d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/ClickDataInfo.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/GeoQuery.java @@ -1,27 +1,34 @@ package org.gcube.portlets.user.geoportaldataviewer.shared.gis; +import java.io.Serializable; + -// TODO: Auto-generated Javadoc /** - * The Class ClickDataInfo. + * The Class GeoQuery. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * - * Oct 27, 2020 + * Oct 29, 2020 */ -public class ClickDataInfo { +public class GeoQuery implements Serializable{ + /** + * + */ + private static final long serialVersionUID = 7500455699960112209L; + + /** + * The Enum TYPE. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Oct 29, 2020 + */ public static enum TYPE { POINT, BOX } - - /** The Constant THRESHOLD_AREA. */ - private static final double THRESHOLD_AREA = 300; - - /** The h. */ - private int x, y, w, h; /** The bbox. */ private String bbox; @@ -45,26 +52,6 @@ public class ClickDataInfo { //ADDED BY FRANCESCO M. private int limit = Integer.MAX_VALUE; - /** - * Instantiates a new click data info. - * - * @param x the x - * @param y the y - * @param w the w - * @param h the h - * @param bbox the bbox - */ - public ClickDataInfo(int x, int y, int w, int h, String bbox) { - super(); - this.x = x; - this.y = y; - this.w = w; - this.h = h; - this.bbox = bbox; - this.type = TYPE.POINT; -// System.out.println("POINT SELECTED: x="+x+", y="+y+", w="+w+", h="+h+", bbox="+bbox); - } - /** * Instantiates a new click data info. * @@ -72,8 +59,9 @@ public class ClickDataInfo { * @param y1 the y 1 * @param x2 the x 2 * @param y2 the y 2 + * @param theType the the type */ - public ClickDataInfo(double x1, double y1, double x2, double y2) { + public GeoQuery(double x1, double y1, double x2, double y2, TYPE theType) { this.x1 = x1; this.y1 = y1; this.x2 = x2; @@ -81,83 +69,11 @@ public class ClickDataInfo { // note: the bounding box is left,lower,right,upper this.bbox = y1 +","+ x1 +","+ y2 +","+ x2; - this.type = TYPE.BOX; + this.type = theType; double area = (x2-x1) * (y2-y1); // System.out.println("BOX SELECTED: BBOX="+bbox + ", AREA="+area); } - /** - * Gets the x. - * - * @return the x - */ - public int getX() { - return x; - } - - /** - * Sets the x. - * - * @param x the new x - */ - public void setX(int x) { - this.x = x; - } - - /** - * Gets the y. - * - * @return the y - */ - public int getY() { - return y; - } - - /** - * Sets the y. - * - * @param y the new y - */ - public void setY(int y) { - this.y = y; - } - - /** - * Gets the w. - * - * @return the w - */ - public int getW() { - return w; - } - - /** - * Sets the w. - * - * @param w the new w - */ - public void setW(int w) { - this.w = w; - } - - /** - * Gets the h. - * - * @return the h - */ - public int getH() { - return h; - } - - /** - * Sets the h. - * - * @param h the new h - */ - public void setH(int h) { - this.h = h; - } - /** * Gets the bbox. * @@ -194,19 +110,6 @@ public class ClickDataInfo { return this.type==TYPE.BOX; } - /** - * Checks if is hard query. - * - * @return true, if is hard query - */ - public boolean isHardQuery() { - if (this.isPoint()) - return false; - else { - double area = (x2-x1) * (y2-y1); - return (area > THRESHOLD_AREA); - } - } /** * Gets the x1. diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore index 3197e17..42efabb 100644 --- a/src/test/resources/.gitignore +++ b/src/test/resources/.gitignore @@ -4,3 +4,6 @@ /log4j.properties /pred4s.gcubekey /preprod.gcubekey +/d4science.research-infrastructures.eu.gcubekey +/devVRE.gcubekey +/gCubeApps.gcubekey