From 7dc1343f1bf8d66648462cbb710dc131f7e51be7 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 15 May 2023 16:19:40 +0200 Subject: [PATCH 01/18] Supported the grouped custom layers [#25110] --- .settings/org.eclipse.wst.common.component | 33 +- CHANGELOG.md | 5 + pom.xml | 4 +- .../client/GeoportalDataViewer.java | 47 ++- .../events/OverlayCustomLayerToMapEvent.java | 92 ++++++ .../OverlayCustomLayerToMapEventHandler.java | 20 ++ .../client/gis/LayerOrder.java | 7 +- .../client/gis/OpenLayerMap.java | 75 ++++- .../client/ui/GeonaDataViewMainPanel.java | 68 ++++- .../client/ui/GeonaDataViewMainPanel.ui.xml | 11 +- .../OverlayCustomLayerPanel.java | 284 ++++++++++++++++++ .../OverlayCustomLayerPanel.ui.xml | 29 ++ .../layercollection/LayerCollectionPanel.java | 3 +- .../client/util/URLUtil.java | 14 + .../GeoportalDataViewerServiceImpl.java | 46 ++- .../shared/ViewerConfiguration.java | 13 + .../shared/gis/DisplayCategory.java | 16 + .../shared/gis/OverlayWMSLayer.java | 13 + 18 files changed, 738 insertions(+), 42 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/OverlayCustomLayerToMapEvent.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/OverlayCustomLayerToMapEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.ui.xml create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/DisplayCategory.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/OverlayWMSLayer.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 7653269..9957ee3 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -79,7 +80,8 @@ - + + @@ -159,7 +161,8 @@ - + + @@ -239,7 +242,8 @@ - + + @@ -319,7 +323,8 @@ - + + @@ -399,7 +404,8 @@ - + + @@ -479,7 +485,11 @@ - + + uses + + + @@ -559,7 +569,8 @@ - + + @@ -639,7 +650,8 @@ - + + @@ -719,7 +731,8 @@ - + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f482f2..11ba5b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v3.5.0-SNAPSHOT] + +- Supported the cross-filtering [#25074] +- Supported the grouped custom layers [#25110] + ## [v3.4.0] - 2023-05-11 - Integrated the geoportal-data-mapper component [#24978] diff --git a/pom.xml b/pom.xml index e918346..1f79fa4 100644 --- a/pom.xml +++ b/pom.xml @@ -14,13 +14,13 @@ org.gcube.portlets.user geoportal-data-viewer-app war - 3.4.0 + 3.5.0-SNAPSHOT GeoPortal Data Viewer App The GeoPortal Data Viewer App is an application to access, discovery and navigate the Geoportal projects/documents by a Web-Map Interface - 2.9.0 + 2.10.0 PRETTY 2.6.2 ${project.build.directory}/${project.build.finalName} 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 795b99b..3b6ec72 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 @@ -30,6 +30,8 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetai import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEventHandler; +import org.gcube.portlets.user.geoportaldataviewer.client.events.OverlayCustomLayerToMapEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.OverlayCustomLayerToMapEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEventHandler; @@ -282,6 +284,11 @@ public class GeoportalDataViewer implements EntryPoint { mainPanel.openCollectionMenu(); + GWT.log("LIST CUSTOM LAYERS: " + result.getListCustomLayers()); + if (result.getListCustomLayers() != null && result.getListCustomLayers().size() > 0) { + mainPanel.setCustomLayers(result.getListCustomLayers()); + } + GWT.log("DONE INIT LOAD"); } @@ -672,6 +679,24 @@ public class GeoportalDataViewer implements EntryPoint { } }); + applicationBus.addHandler(OverlayCustomLayerToMapEvent.TYPE, new OverlayCustomLayerToMapEventHandler() { + + @Override + public void onCustomOverlayLayerAction(OverlayCustomLayerToMapEvent customOverLayerToMapEvent) { + + if(customOverLayerToMapEvent.getLayerItem()==null) + return; + + if (customOverLayerToMapEvent.getActionType() + .equals(OverlayCustomLayerToMapEvent.ACTION_TYPE.VISIBILITY)) { + OpenLayerMap olMap = olMapMng.getOLMap(); + olMap.setWMSGroupedCustomLayerVisible(customOverLayerToMapEvent.getLayerItem(), + customOverLayerToMapEvent.isEnabled()); + } + + } + }); + applicationBus.addHandler(ChangeMapLayerEvent.TYPE, new ChangeMapLayerEventHandler() { @Override @@ -911,18 +936,16 @@ public class GeoportalDataViewer implements EntryPoint { GWT.log("features: " + features); olMapMng.getOLMap().addLayerFeaturesAsHighlight(layerItem, features, true); - /* Fit to extent calculating the features extent - if (projectDV != null) { - GeoJSON spatialReference = projectDV.getSpatialReference(); - - GWT.log("spatialReference is: " + spatialReference); - Coordinate transfCoord = MapUtils.geoJSONTToBBoxCenter(spatialReference, MAP_PROJECTION.EPSG_4326.getName(), - MAP_PROJECTION.EPSG_3857.getName()); - GWT.log("transfCoord is: " + transfCoord); - if (transfCoord != null) - olMapMng.getOLMap().setCenter(transfCoord); - } - */ + /* + * Fit to extent calculating the features extent if (projectDV != null) { + * GeoJSON spatialReference = projectDV.getSpatialReference(); + * + * GWT.log("spatialReference is: " + spatialReference); Coordinate transfCoord = + * MapUtils.geoJSONTToBBoxCenter(spatialReference, + * MAP_PROJECTION.EPSG_4326.getName(), MAP_PROJECTION.EPSG_3857.getName()); + * GWT.log("transfCoord is: " + transfCoord); if (transfCoord != null) + * olMapMng.getOLMap().setCenter(transfCoord); } + */ } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/OverlayCustomLayerToMapEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/OverlayCustomLayerToMapEvent.java new file mode 100644 index 0000000..0923d28 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/OverlayCustomLayerToMapEvent.java @@ -0,0 +1,92 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events; + +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class OverlayCustomLayerToMapEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 15, 2023 + */ +public class OverlayCustomLayerToMapEvent extends GwtEvent { + public static Type TYPE = new Type(); + private LayerItem layerItem; + private ACTION_TYPE actionType; + private boolean enabled; + + /** + * The Enum ACTION_TYPE. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 15, 2023 + */ + public enum ACTION_TYPE { + VISIBILITY + } + + /** + * Instantiates a new overlay custom layer to map event. + * + * @param layerItem the layer item + * @param actionType the action type + * @param enabled the enabled + */ + public OverlayCustomLayerToMapEvent(LayerItem layerItem, ACTION_TYPE actionType, boolean enabled) { + this.layerItem = layerItem; + this.actionType = actionType; + this.enabled = enabled; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + @Override + protected void dispatch(OverlayCustomLayerToMapEventHandler handler) { + handler.onCustomOverlayLayerAction(this); + + } + + /** + * Gets the layer item. + * + * @return the layer item + */ + public LayerItem getLayerItem() { + return layerItem; + } + + /** + * Gets the action type. + * + * @return the action type + */ + public ACTION_TYPE getActionType() { + return actionType; + } + + /** + * Checks if is enabled. + * + * @return true, if is enabled + */ + public boolean isEnabled() { + return enabled; + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/OverlayCustomLayerToMapEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/OverlayCustomLayerToMapEventHandler.java new file mode 100644 index 0000000..6e027b5 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/OverlayCustomLayerToMapEventHandler.java @@ -0,0 +1,20 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events; + +import com.google.gwt.event.shared.EventHandler; + +/** + * The Interface OverlayCustomLayerToMapEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 15, 2023 + */ +public interface OverlayCustomLayerToMapEventHandler extends EventHandler { + + /** + * On custom overlay layer action. + * + * @param customOverLayerToMapEvent the custom over layer to map event + */ + void onCustomOverlayLayerAction(OverlayCustomLayerToMapEvent customOverLayerToMapEvent); +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java index 940f016..e5f9bc6 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java @@ -19,7 +19,7 @@ public class LayerOrder { * Nov 12, 2021 */ public static enum LAYER_TYPE { - BASE_MAP, BASE_WMS, WMS_DETAIL, VECTOR + BASE_MAP, BASE_WMS, WMS_DETAIL, CUSTOM_WMS_DETAIL, VECTOR } public static final HashMap LAYER_OFFSET = new HashMap(5); @@ -28,8 +28,9 @@ public class LayerOrder { LAYER_OFFSET.put(LAYER_TYPE.BASE_MAP, 0); LAYER_OFFSET.put(LAYER_TYPE.BASE_WMS, 70); - LAYER_OFFSET.put(LAYER_TYPE.WMS_DETAIL, 140); - LAYER_OFFSET.put(LAYER_TYPE.VECTOR, 210); + LAYER_OFFSET.put(LAYER_TYPE.CUSTOM_WMS_DETAIL, 140); + LAYER_OFFSET.put(LAYER_TYPE.WMS_DETAIL, 210); + LAYER_OFFSET.put(LAYER_TYPE.VECTOR, 320); } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java index 2e4a755..28c580e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java @@ -149,6 +149,8 @@ public abstract class OpenLayerMap { private LinkedHashMap wmsDetailsLayerMap; + private LinkedHashMap wmsGroupedCustomLayerMap; + private LinkedHashMap wmsLayerMap; private LinkedHashMap vectorLayersHighlighted = new LinkedHashMap(); @@ -537,6 +539,57 @@ public abstract class OpenLayerMap { } + /** + * Adds the custom WMS detail layer. + * + * @param layerItem the layer item + */ + public void addGroupedCustomWMSLayer(LayerItem layerItem) { + + if (wmsGroupedCustomLayerMap == null) + wmsGroupedCustomLayerMap = new LinkedHashMap(); + + String key = layerItem.getName(); + + Image layer = wmsGroupedCustomLayerMap.get(key); + + if (layer == null) { + GWT.log("The grouped custom layer with key: " + key + " does not exist, creating and adding it to map"); + ImageWmsParams imageWMSParams = OLFactory.createOptions(); + imageWMSParams.setLayers(layerItem.getName()); + + ImageWmsOptions imageWMSOptions = OLFactory.createOptions(); + imageWMSOptions.setUrl(layerItem.getMapServerHost()); + imageWMSOptions.setParams(imageWMSParams); + // imageWMSOptions.setRatio(1.5f); + + ImageWms imageWMSSource = new ImageWms(imageWMSOptions); + LayerOptions layerOptions = OLFactory.createOptions(); + layerOptions.setSource(imageWMSSource); + + // Settings MIN and MAX Resolution + if (layerItem.getMinResolution() != null) { + layerOptions.setMinResolution(layerItem.getMinResolution()); + } + if (layerItem.getMaxResolution() != null) { + layerOptions.setMaxResolution(layerItem.getMaxResolution()); + } + + Image wmsLayer = new Image(layerOptions); + int zIndex = layerOrder.getOffset(LayerOrder.LAYER_TYPE.CUSTOM_WMS_DETAIL) + wmsGroupedCustomLayerMap.size() + + 1; + wmsLayer.setZIndex(zIndex); + map.addLayer(wmsLayer); + wmsGroupedCustomLayerMap.put(key, wmsLayer); + + GWT.log("Added GroupedCustomWMSLayer for layer name: " + layerItem.getName()); + eventBus.fireEvent(new AddedLayerToMapEvent(layerItem, LAYER_TYPE.OVERLAY)); + } else { + GWT.log("The WMS detail layer with key: " + key + " already exists, skipping"); + } + + } + /** * Removes the all detail layers. * @@ -633,8 +686,8 @@ public abstract class OpenLayerMap { /** * Adds the vector. * - * @param layerItem the layer item - * @param features the features + * @param layerItem the layer item + * @param features the features * @param fitMapToFeaturesExtent the fit map to features extent */ public void addLayerFeaturesAsHighlight(LayerItem layerItem, Feature[] features, boolean fitMapToFeaturesExtent) { @@ -656,7 +709,7 @@ public abstract class OpenLayerMap { @Override public void onEvent(ol.events.Event event) { ol.Extent theExtent = vectorSource.getExtent(); - //GWT.log(theExtent.toString()); + // GWT.log(theExtent.toString()); map.getView().fit(theExtent); } @@ -1050,7 +1103,21 @@ public abstract class OpenLayerMap { public void setWMSDetailLayerOpacity(LayerItem layerItem, double opacity) { String key = layerItem.getName(); Image layer = wmsDetailsLayerMap.get(key); - layer.setOpacity(opacity); + if (layer != null) + layer.setOpacity(opacity); + } + + /** + * Sets the WMS detail layer visible. + * + * @param layerItem the layer item + * @param visible the visible + */ + public void setWMSGroupedCustomLayerVisible(LayerItem layerItem, boolean visible) { + String key = layerItem.getName(); + Image layer = wmsGroupedCustomLayerMap.get(key); + if (layer != null) + layer.setVisible(visible); } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index ed89854..0022a81 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -9,6 +9,8 @@ import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.CustomLayerDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GroupedCustomLayersDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants; @@ -20,12 +22,15 @@ import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap; import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAIcons; import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAImages; import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.search.SearchFacilityUI; +import org.gcube.portlets.user.geoportaldataviewer.client.ui.customoverlays.OverlayCustomLayerPanel; import org.gcube.portlets.user.geoportaldataviewer.client.ui.layercollection.LayerCollectionPanel; import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil; import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.Location; +import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection; import org.gcube.portlets.user.geoportaldataviewer.shared.ItemFieldsResponse; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.CheckBox; @@ -34,6 +39,7 @@ import com.github.gwtbootstrap.client.ui.ListBox; import com.github.gwtbootstrap.client.ui.NavLink; import com.github.gwtbootstrap.client.ui.Paragraph; import com.github.gwtbootstrap.client.ui.constants.IconType; +import com.github.gwtbootstrap.client.ui.constants.LabelType; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; @@ -111,6 +117,12 @@ public class GeonaDataViewMainPanel extends Composite { @UiField DropdownButton openCollectionDropDown; + @UiField + DropdownButton linkCustomOverlayLayers; + + @UiField + HTMLPanel panelCustomOverlayLayers; + @UiField HTMLPanel openCollectionPanel; @@ -173,7 +185,7 @@ public class GeonaDataViewMainPanel extends Composite { extentToEarth.getElement().appendChild(worldImg.getElement()); extentToEarth.setWidth("140px"); - linkMap.setCustomIconStyle(GNAIcons.CustomIconType.MAP.get()); + // linkMap.setCustomIconStyle(GNAIcons.CustomIconType.MAP.get()); linkPresetLocation.setCustomIconStyle(GNAIcons.CustomIconType.PRESET_LOCATION.get()); linkLayers.setCustomIconStyle(GNAIcons.CustomIconType.LAYERS.get()); @@ -185,9 +197,9 @@ public class GeonaDataViewMainPanel extends Composite { initialSortFilter.setOrder(ORDER.ASC); navListSearch.addItem(PLACEHOLDER_SELECT_SEARCH_IN, PLACEHOLDER_SELECT_SEARCH_IN); - + navListSearch.getElement().getFirstChildElement().setAttribute("disabled", "disabled"); - + // List listUCDs = new ArrayList(); // // for (ItemFieldsResponse itemFieldsResponse : itemFieldsReponse) { @@ -216,9 +228,9 @@ public class GeonaDataViewMainPanel extends Composite { String ucdProfileID = navListSearch.getValue(navListSearch.getSelectedIndex()); GWT.log("UCD ProfileID selected: " + ucdProfileID); - + if (ucdProfileID.compareTo(PLACEHOLDER_SELECT_SEARCH_IN) != 0) { - + searchFacilityPanel.clear(); ItemFieldsResponse itemFieldResp = mapItemFieldsForUCD.get(ucdProfileID); @@ -310,6 +322,16 @@ public class GeonaDataViewMainPanel extends Composite { } }, ClickEvent.getType()); + + linkCustomOverlayLayers.addDomHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + // event.preventDefault(); + event.stopPropagation(); + + } + }, ClickEvent.getType()); } /** @@ -608,4 +630,40 @@ public class GeonaDataViewMainPanel extends Composite { } + public void setCustomLayers(List listCustomLayers) { + + if (listCustomLayers == null) + return; + + for (GroupedCustomLayersDV gCustomLayerDV : listCustomLayers) { + if (gCustomLayerDV.getListCustomLayers() != null) { + com.github.gwtbootstrap.client.ui.Label labelGroup = new com.github.gwtbootstrap.client.ui.Label(gCustomLayerDV.getName()); + labelGroup.setType(LabelType.WARNING); + String descr = gCustomLayerDV.getDescription() != null + && !gCustomLayerDV.getDescription().isEmpty() ? gCustomLayerDV.getDescription() + : gCustomLayerDV.getName(); + labelGroup.setTitle(descr); + panelCustomOverlayLayers.add(labelGroup); + for (CustomLayerDV customLayer : gCustomLayerDV.getListCustomLayers()) { + + if(customLayer.isDisplay()) { + LayerItem layerItem = new LayerItem(); + final String mapServerHost = URLUtil.getPathURL(customLayer.getWms_url()); + GWT.log("mapServerHost: " + mapServerHost); + layerItem.setMapServerHost(mapServerHost); + layerItem.setBaseLayer(false); + layerItem.setName(customLayer.getName()); + layerItem.setTitle(customLayer.getTitle()); + layerItem.setWmsLink(customLayer.getWms_url()); + panelCustomOverlayLayers.add(new OverlayCustomLayerPanel(layerItem, applicationBus)); + map.addGroupedCustomWMSLayer(layerItem); + } + } + } + } + + linkCustomOverlayLayers.setVisible(listCustomLayers.size() > 0); + + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml index 24aa44d..24a6e0c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml @@ -49,17 +49,22 @@ - + + title="Select the Map" text="Map" ui:field="linkMap" icon="GLOBE"> + + + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.java new file mode 100644 index 0000000..5da70d8 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.java @@ -0,0 +1,284 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.ui.customoverlays; + +import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync; +import org.gcube.portlets.user.geoportaldataviewer.client.events.OverlayCustomLayerToMapEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; + +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.CheckBox; +import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.constants.ButtonType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Style.FontWeight; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.ErrorEvent; +import com.google.gwt.event.dom.client.ErrorHandler; +import com.google.gwt.event.dom.client.LoadEvent; +import com.google.gwt.event.dom.client.LoadHandler; +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlexTable; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.ScrollPanel; +import com.google.gwt.user.client.ui.Widget; + +/** + * The Class OverlayCustomLayerPanel. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 15, 2023 + */ +public class OverlayCustomLayerPanel extends Composite { + + public static String COLORSCALERANGE = "COLORSCALERANGE"; + + @UiField + HTMLPanel basePanel; + + @UiField + HTMLPanel stylePanel; + + @UiField + HTMLPanel styleListPanel; + + @UiField + Button buttonLegend; + + @UiField + ScrollPanel legendPanel; + + private CheckBox checkbox; + + private GeoInformationForWMSRequest geoInformation; + + private static OverlayCustomLayerPanelUiBinder uiBinder = GWT.create(OverlayCustomLayerPanelUiBinder.class); + + private ListBox listBoxStyles = new ListBox(); + + private HandlerManager applicationBus; + + private LayerItem layerItem; + + /** + * The Interface LayerCollectionPanelUiBinder. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jan 16, 2023 + */ + interface OverlayCustomLayerPanelUiBinder extends UiBinder { + } + + /** + * Instantiates a new overlay custom layer panel. + * + * @param layerItem the layer item + * @param applicationBus the application bus + */ + public OverlayCustomLayerPanel(LayerItem layerItem, HandlerManager applicationBus) { + initWidget(uiBinder.createAndBindUi(this)); + this.applicationBus = applicationBus; + this.layerItem = layerItem; + + buttonLegend.setType(ButtonType.LINK); + legendPanel.setVisible(false); + + GWT.log("Found available layerItem " + layerItem); + String label = layerItem.getTitle(); + final String layerName = layerItem.getName(); + + checkbox = new CheckBox(label); + checkbox.setId("gcubeCustomLayerSelector_" + layerName); + checkbox.getElement().getStyle().setFontWeight(FontWeight.BOLD); + checkbox.setChecked(true); + + checkbox.addValueChangeHandler(new ValueChangeHandler() { + + @Override + public void onValueChange(ValueChangeEvent event) { + GWT.log("CustomLayer selector flag changed to value : " + event.toDebugString()); + +// String collectionID = ((CheckBox) event.getSource()).getId().replace("gcubeCollectionSelector_", +// ""); + + // GWT.log("Collection ID is : " + collectionID + ", event value: " + + // event.getValue()); + if (event.getValue()) { + // OPEN COLLECTION + applicationBus.fireEvent(new OverlayCustomLayerToMapEvent(layerItem, OverlayCustomLayerToMapEvent.ACTION_TYPE.VISIBILITY, true)); + } else { + // CLOSE COLLECTION + legendPanel.clear(); + legendPanel.setVisible(false); + applicationBus.fireEvent(new OverlayCustomLayerToMapEvent(layerItem, OverlayCustomLayerToMapEvent.ACTION_TYPE.VISIBILITY, false)); + } + } + }); + + basePanel.add(checkbox); + + final String wmsLink = layerItem.getWmsLink(); + GeoportalDataViewerServiceAsync.Util.getInstance().parseWmsRequest(wmsLink, layerName, + new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + + Window.alert(caught.getMessage()); + } + + @Override + public void onSuccess(GeoInformationForWMSRequest geoInfoWMS) { + geoInformation = geoInfoWMS; + GWT.log("Parsed WMS Request returned: " + geoInfoWMS); + + if (geoInfoWMS.getStyles() != null && geoInfoWMS.getStyles().getGeoStyles() != null) { + if (geoInfoWMS.getStyles().getGeoStyles().size() > 0) { + stylePanel.setVisible(true); + listBoxStyles.clear(); + for (String styleName : geoInfoWMS.getStyles().getGeoStyles()) { + listBoxStyles.addItem(styleName, styleName); + } + + styleListPanel.add(listBoxStyles); + } + } + + listBoxStyles.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + legendPanel.clear(); + legendPanel.setVisible(false); + } + }); + + + buttonLegend.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + GWT.log("is isToggle: " + buttonLegend.isToggle()); + GWT.log("is isToggled: " + buttonLegend.isToggled()); + if (legendPanel.isVisible()) { + legendPanel.clear(); + legendPanel.setVisible(false); + + } else { + legendPanel.setVisible(true); + loadLegend(wmsLink); + } + + } + }); + + } + }); + + } + + /** + * Gets the checkbox. + * + * @return the checkbox + */ + public CheckBox getCheckbox() { + return checkbox; + } + + /** + * Load legend. + * + * @param wmsLink the wms link + */ + private void loadLegend(String wmsLink) { + + legendPanel.clear(); + String theLayerName = geoInformation.getLayerName(); + final FlexTable flexTable = new FlexTable(); + legendPanel.add(flexTable); + + // Case no style found + if (listBoxStyles.getSelectedValue() == null) { + flexTable.setWidget(0, 0, new HTML("No style found")); + return; + } + + FlowPanel flow = new FlowPanel(); + flow.add(new HTMLPanel("Legend for: " + theLayerName)); + final HorizontalPanel hpLegend = new HorizontalPanel(); + + String url = geoInformation.getBaseWmsServiceHost() + "?service=WMS&" + "version=" + + URLUtil.getValueOfParameter("version", wmsLink) + "&" + "request=GetLegendGraphic&" + "layer=" + + theLayerName; + + String styleName = null; + try { + styleName = listBoxStyles.getSelectedValue(); + } catch (Exception e) { + } + + styleName = styleName != null && !styleName.isEmpty() ? styleName : ""; + + if (!geoInformation.isNcWMS()) { + + url += "&format=image/png" + "&STYLE=" + styleName + + "&LEGEND_OPTIONS=forceRule:True;dx:0.2;dy:0.2;mx:0.2;my:0.2;fontStyle:bold;" + + "borderColor:000000;border:true;fontColor:000000;fontSize:14"; + } else { + + int isNcWmsStyle = styleName.indexOf("/"); + if (isNcWmsStyle != -1) { + styleName = styleName.substring(isNcWmsStyle + 1, styleName.length()); + } + url += "&palette=" + styleName; + if (geoInformation.getMapWMSNoStandard() != null) { + for (String key : geoInformation.getMapWMSNoStandard().keySet()) { // ADDING COLORSCALERANGE? + if (key.compareToIgnoreCase(COLORSCALERANGE) == 0) { + url += "&" + key + "=" + geoInformation.getMapWMSNoStandard().get(key); + break; + } + } + } + } + + GWT.log(url); + flexTable.setStyleName("layer-style-panel-table-legend"); + flexTable.setWidget(0, 0, new Label("Legend")); + final Image legendImage = new Image(url); + legendImage.addLoadHandler(new LoadHandler() { + @Override + public void onLoad(LoadEvent event) { + } + }); + + legendImage.addErrorHandler(new ErrorHandler() { + @Override + public void onError(ErrorEvent event) { + GWT.log("ErrorEvent "); + flexTable.setWidget(0, 1, new HTML("Error on loading the style")); + } + }); + + hpLegend.add(legendImage); + flexTable.setWidget(0, 1, hpLegend); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.ui.xml new file mode 100644 index 0000000..bcfa94c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.ui.xml @@ -0,0 +1,29 @@ + + + + .important { + font-weight: bold; + } + + .margin-left-10 { + margin-left: 10px; + } + + + + + + Layer Style + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/layercollection/LayerCollectionPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/layercollection/LayerCollectionPanel.java index 15dcd9d..b8a74ce 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/layercollection/LayerCollectionPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/layercollection/LayerCollectionPanel.java @@ -42,12 +42,13 @@ import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.Widget; + /** * The Class LayerCollectionPanel. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Jan 16, 2023 + * May 15, 2023 */ public class LayerCollectionPanel extends Composite { 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 d79b001..c245173 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 @@ -35,6 +35,20 @@ public class URLUtil { return value; } + /** + * Gets the path URL. + * + * @param url the url + * @return the path URL + */ + public static String getPathURL(String url) { + int index = url.toLowerCase().indexOf("?"); + if (index > -1) { + return url.substring(0, index); + } else + return null; + } + /** * Adds the parameter to query string. * 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 95855fc..07af62d 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 @@ -31,6 +31,7 @@ import org.gcube.application.geoportal.common.model.document.identification.Iden import org.gcube.application.geoportal.common.model.document.relationships.Relationship; import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject; import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.gcube.application.geoportal.common.rest.Projects; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; @@ -50,11 +51,13 @@ import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GroupedCustomLayersDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.IdentificationReferencesTYPE; import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.TemporalReferenceDV; +import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; @@ -470,10 +473,23 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme Projects p = projects(u.getId()).build(); - UseCaseDescriptorDV ucd = ConvertToDataValueObjectModel.toUseCaseDescriptorDV(u, null); + UseCaseDescriptorDV ucdDV = ConvertToDataValueObjectModel.toUseCaseDescriptorDV(u, null); Configuration ucdConfig = p.getConfiguration(); GCubeCollection coll = new GCubeCollection(); - coll.setUcd(ucd); + coll.setUcd(ucdDV); + + // Loading geoportal_grouped_custom_layers if exists + GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_grouped_custom_layers; + List handlers = u.getHandlersByType(theHandler.getType()); + + if (handlers != null && handlers.size() > 0) { + // Loading Handler gcube_profiles + HandlerDeclaration handler = handlers.get(0); + List listCustomLayers = getGroupedCustomLayers(u, handler, + GEOPORTAL_DATA_HANDLER.geoportal_grouped_custom_layers); + config.setGroupCustomLayers(listCustomLayers); + } else + LOG.warn("No handler " + theHandler + "found into UCD " + u.getId() + ", continue..."); // TODO TO Check index flag should be in configuration or evaluated according to // user credentials @@ -552,6 +568,32 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return null; } + private List getGroupedCustomLayers(UseCaseDescriptor ucd, HandlerDeclaration handler, + GEOPORTAL_DATA_HANDLER geoportalGroupedCustomLayers) { + + List listGroupedCustomLayers = null; + try { + + HandlerDeclarationDV handlerDV = ConvertToDataValueObjectModel.toHandlerDeclarationDV(handler, ucd, + GEOPORTAL_CONFIGURATION_TYPE.grouped_custom_layers); + + if (handler != null) { + ConfigurationDV config = handlerDV.getConfiguration(); + switch (config.getConfigurationType()) { + case grouped_custom_layers: + listGroupedCustomLayers = (List) config.getConfiguration(); + break; + default: + break; + } + + } + } catch (Exception e) { + LOG.error("Error on loading {} config for ucd Id {}. Returning null", geoportalGroupedCustomLayers, ucd.getId()); + } + return listGroupedCustomLayers; + } + /** * Gets the config list of fields for searching. * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java index 30f8430..5fd43e1 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java @@ -4,6 +4,7 @@ import java.io.Serializable; import java.util.List; import java.util.Map; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GroupedCustomLayersDV; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; public class ViewerConfiguration implements Serializable { @@ -22,6 +23,8 @@ public class ViewerConfiguration implements Serializable { public Map availableCollections; + private List listCustomLayers; + public List getBaseLayers() { return baseLayers; } @@ -37,4 +40,14 @@ public class ViewerConfiguration implements Serializable { public void setAvailableCollections(Map availableCollections) { this.availableCollections = availableCollections; } + + public void setGroupCustomLayers(List listCustomLayers) { + this.listCustomLayers = listCustomLayers; + + } + + public List getListCustomLayers() { + return listCustomLayers; + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/DisplayCategory.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/DisplayCategory.java new file mode 100644 index 0000000..030ab3f --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/DisplayCategory.java @@ -0,0 +1,16 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared.gis; + +import java.io.Serializable; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Data +public class DisplayCategory implements Serializable { + + + String title; + String description; + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/OverlayWMSLayer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/OverlayWMSLayer.java new file mode 100644 index 0000000..6707121 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/OverlayWMSLayer.java @@ -0,0 +1,13 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared.gis; + +import java.util.Map; + +public class OverlayWMSLayer { + + private String title; + private String name; + private String wmsServiceBaseURL; + private boolean display; + private Map mapProperties; + +} From f86988f8c75e6f2906a00962ca84b0cb8cfa34c3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 15 May 2023 17:11:37 +0200 Subject: [PATCH 02/18] Improved Overlay Custom Layer Panel and CSS --- .../client/ui/GeonaDataViewMainPanel.java | 7 ++++++ .../client/ui/GeonaDataViewMainPanel.ui.xml | 4 ++-- src/main/webapp/GeoportalDataViewer.css | 24 ++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index 0022a81..4d57628 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -56,6 +56,7 @@ import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Label; @@ -644,6 +645,12 @@ public class GeonaDataViewMainPanel extends Composite { : gCustomLayerDV.getName(); labelGroup.setTitle(descr); panelCustomOverlayLayers.add(labelGroup); + if(descr.compareTo(gCustomLayerDV.getName())!=0) { + HTML overlayGroupDescr = new HTML(); + overlayGroupDescr.getElement().setClassName("overlay-panel-style-description"); + overlayGroupDescr.setHTML(descr); + panelCustomOverlayLayers.add(overlayGroupDescr); + } for (CustomLayerDV customLayer : gCustomLayerDV.getListCustomLayers()) { if(customLayer.isDisplay()) { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml index 24a6e0c..4545cd4 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml @@ -61,8 +61,8 @@ - + title="Custom overlay layers.." text="Overlay" ui:field="linkCustomOverlayLayers" icon="REORDER"> + div { + border: 1px solid #ccc; + border-radius: 5px; + padding: 10px; + margin-bottom: 10px; + margin-top: 5px; +} + + From b3dd9126b94f052c480c7ae4b309953542c03364 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 19 May 2023 14:59:55 +0200 Subject: [PATCH 03/18] Fixing layer order --- .../user/geoportaldataviewer/client/gis/LayerOrder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java index e5f9bc6..f20da8a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java @@ -19,7 +19,7 @@ public class LayerOrder { * Nov 12, 2021 */ public static enum LAYER_TYPE { - BASE_MAP, BASE_WMS, WMS_DETAIL, CUSTOM_WMS_DETAIL, VECTOR + BASE_MAP, CUSTOM_WMS_DETAIL, BASE_WMS, WMS_DETAIL, VECTOR } public static final HashMap LAYER_OFFSET = new HashMap(5); @@ -27,8 +27,8 @@ public class LayerOrder { static { LAYER_OFFSET.put(LAYER_TYPE.BASE_MAP, 0); - LAYER_OFFSET.put(LAYER_TYPE.BASE_WMS, 70); - LAYER_OFFSET.put(LAYER_TYPE.CUSTOM_WMS_DETAIL, 140); + LAYER_OFFSET.put(LAYER_TYPE.CUSTOM_WMS_DETAIL, 70); + LAYER_OFFSET.put(LAYER_TYPE.BASE_WMS, 140); LAYER_OFFSET.put(LAYER_TYPE.WMS_DETAIL, 210); LAYER_OFFSET.put(LAYER_TYPE.VECTOR, 320); } From d1ec08c70f6324fa1d526795c45c4ff80c48d6c4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 19 May 2023 15:12:46 +0200 Subject: [PATCH 04/18] added comments --- .../geoportaldataviewer/client/gis/LayerOrder.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java index f20da8a..472aaf5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java @@ -26,11 +26,11 @@ public class LayerOrder { static { - LAYER_OFFSET.put(LAYER_TYPE.BASE_MAP, 0); - LAYER_OFFSET.put(LAYER_TYPE.CUSTOM_WMS_DETAIL, 70); - LAYER_OFFSET.put(LAYER_TYPE.BASE_WMS, 140); - LAYER_OFFSET.put(LAYER_TYPE.WMS_DETAIL, 210); - LAYER_OFFSET.put(LAYER_TYPE.VECTOR, 320); + LAYER_OFFSET.put(LAYER_TYPE.BASE_MAP, 0); //Base OL or MapBox + LAYER_OFFSET.put(LAYER_TYPE.CUSTOM_WMS_DETAIL, 70); //WMS custom Overlay. Es. Layer "Limiti Amministrativi" + LAYER_OFFSET.put(LAYER_TYPE.BASE_WMS, 140); // Index layers (i.e. centroids for UCD) + LAYER_OFFSET.put(LAYER_TYPE.WMS_DETAIL, 210); //Layer/s belonging to a Project (materialized layers. Ex. "Posizionamento Scavo") + LAYER_OFFSET.put(LAYER_TYPE.VECTOR, 320); //Vector layer to show other info. Ex. Pointer with coordinates (x,y) in the Light OL Map. } /** From 16d9feffe0de59bddf6ca2b4ca722c496a755cbb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 25 May 2023 11:28:25 +0200 Subject: [PATCH 05/18] Implement generic method to load grouped configured layers for Overlay and Cross-Filtering facilities --- .../client/GeoportalDataViewer.java | 82 ++++++- .../client/GeoportalDataViewerService.java | 21 +- .../GeoportalDataViewerServiceAsync.java | 7 + .../client/ui/GeonaDataViewMainPanel.java | 50 ++-- .../GeoportalDataViewerServiceImpl.java | 222 ++++++++++++++++-- .../server/util/SessionUtil.java | 50 ++-- .../shared/ViewerConfiguration.java | 13 - 7 files changed, 346 insertions(+), 99 deletions(-) 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 3b6ec72..cffe69c 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 @@ -5,13 +5,17 @@ import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; +import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.RelationshipDV; +import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MapEventType; @@ -156,6 +160,8 @@ public class GeoportalDataViewer implements EntryPoint { // A cache (Layer_ID, GeoJSON) of layer features loaded via GetFeature Request private HashMap layerFeaturesCache = new HashMap(); + private ViewerConfiguration viewerConfiguration; + /** * This is the entry point method. */ @@ -230,6 +236,7 @@ public class GeoportalDataViewer implements EntryPoint { @Override public void onSuccess(ViewerConfiguration result) { super.onSuccess(result); + viewerConfiguration = result; GWT.log("Received init config : " + result); GWT.log("Loading base layers, count : " + result.getBaseLayers().size()); @@ -283,11 +290,13 @@ public class GeoportalDataViewer implements EntryPoint { } mainPanel.openCollectionMenu(); - - GWT.log("LIST CUSTOM LAYERS: " + result.getListCustomLayers()); - if (result.getListCustomLayers() != null && result.getListCustomLayers().size() > 0) { - mainPanel.setCustomLayers(result.getListCustomLayers()); - } +// +// GWT.log("LIST CUSTOM LAYERS: " + result.getListCustomLayers()); +// if (result.getListCustomLayers() != null && result.getListCustomLayers().size() > 0) { +// mainPanel.setCustomLayers(result.getListCustomLayers()); +// } + + loadConfigureduGroupedLayersForUCD(); GWT.log("DONE INIT LOAD"); @@ -309,6 +318,45 @@ public class GeoportalDataViewer implements EntryPoint { RootPanel.get(APP_DIV).add(attributionDiv); } + + /** + * Load Overlay Layers and Cross-Filtering layers for UCD + * + * Load configuredu grouped layers for UCD. + */ + public void loadConfigureduGroupedLayersForUCD() { + + GeoportalDataViewerServiceAsync.Util.getInstance().getAvaiableCustomGroupedLayersForUCD( + GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers, + new AsyncCallback>>>() { + + @Override + public void onFailure(Throwable caught) { + Window.alert("error: "+caught.getMessage()); + + } + + @Override + public void onSuccess(Map>> result) { + GWT.log("GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers returned: "); + if (result != null && result.size() > 0) { + + Map collections = viewerConfiguration.getAvailableCollections(); + + for (String profileId : result.keySet()) { + List> list = result.get(profileId); + if (list != null && list.size() > 0) { + GCubeCollection collection = collections.get(profileId); + mainPanel.addOverlayLayers(collection, list); + + } + } + + } + } + }); + } + /** * Gets the status. * @@ -684,9 +732,9 @@ public class GeoportalDataViewer implements EntryPoint { @Override public void onCustomOverlayLayerAction(OverlayCustomLayerToMapEvent customOverLayerToMapEvent) { - if(customOverLayerToMapEvent.getLayerItem()==null) + if (customOverLayerToMapEvent.getLayerItem() == null) return; - + if (customOverLayerToMapEvent.getActionType() .equals(OverlayCustomLayerToMapEvent.ACTION_TYPE.VISIBILITY)) { OpenLayerMap olMap = olMapMng.getOLMap(); @@ -750,7 +798,7 @@ public class GeoportalDataViewer implements EntryPoint { if (searchPerformedEvent != null) { LinkedHashMap wmsMap = olMapMng.getOLMap().getWmsLayerMap(); - String firstWMSKey = wmsMap.keySet().iterator().next(); + // String firstWMSKey = wmsMap.keySet().iterator().next(); List result = searchPerformedEvent.getListProjectIDs(); ViewerConfiguration viewerConfig = GeoportalDataViewer.getStatus().getViewerConfig(); @@ -777,6 +825,14 @@ public class GeoportalDataViewer implements EntryPoint { String setCqlFilter = null; // default +// setCqlFilter = "INTERSECTS(geom,querySingle('limiti_amministrativi:regioni','the_geom','DEN_REG=''Calabria'''));INCLUDE"; +// GWT.log("HARD-CODED CQL FILTER: "+setCqlFilter); + + if (layerName == null) { + GWT.log("CQL FILTER skipped, layerName is NULL!!"); + return; + } + if (result != null && result.size() > 0) { String cqlFilter = GeoportalDataViewerConstants.PROJECT_ID_KEY_FEATURE + " IN("; for (String projectId : result) { @@ -784,15 +840,19 @@ public class GeoportalDataViewer implements EntryPoint { } cqlFilter = cqlFilter.substring(0, cqlFilter.length() - 1) + ")"; setCqlFilter = cqlFilter; - olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, cqlFilter); + + setCqlFilter = "INTERSECTS(geom,querySingle('limiti_amministrativi:regioni','the_geom','DEN_REG=''Calabria'''));INCLUDE"; + GWT.log("HARD-CODED CQL FILTER: " + setCqlFilter); + + olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, setCqlFilter); } else { - olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null); + olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, null); setCqlFilter = null; // is already null } if (searchPerformedEvent.isSearchReset()) { - olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null); + olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, null); setCqlFilter = null; // is already null } 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 b1b4847..9b9840b 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 @@ -2,12 +2,16 @@ package org.gcube.portlets.user.geoportaldataviewer.client; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; +import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult; @@ -183,10 +187,10 @@ public interface GeoportalDataViewerService extends RemoteService { /** * Gets the WFS request. * - * @param layerItem the layer item - * @param mapSrsName the map srs name - * @param mapBBOX the map BBOX - * @param maxFeatures the max features. If 0 means all feature + * @param layerItem the layer item + * @param mapSrsName the map srs name + * @param mapBBOX the map BBOX + * @param maxFeatures the max features. If 0 means all feature * @param outputFormat the output format * @return the WFS request */ @@ -206,4 +210,13 @@ public interface GeoportalDataViewerService extends RemoteService { String getWFSResponse(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures, String outputFormat); + /** + * Gets the avaiable custom grouped layers for UCD. + * + * @param theHandler the the handler + * @return the avaiable custom grouped layers for UCD + */ + Map>> getAvaiableCustomGroupedLayersForUCD( + GEOPORTAL_DATA_HANDLER theHandler); + } 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 3f3f7bb..ada1daf 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 @@ -2,12 +2,16 @@ package org.gcube.portlets.user.geoportaldataviewer.client; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; +import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult; @@ -82,4 +86,7 @@ public interface GeoportalDataViewerServiceAsync { void getWFSResponse(LayerItem layerItem, String mapSrsName, BoundsMap mapBBOX, int maxFeatures, String outputFormat, AsyncCallback callback); + void getAvaiableCustomGroupedLayersForUCD(GEOPORTAL_DATA_HANDLER theHandler, + AsyncCallback>>> callback); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index 4d57628..b8ccb33 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -8,9 +8,10 @@ import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; +import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; -import org.gcube.application.geoportalcommon.shared.geoportal.materialization.CustomLayerDV; -import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GroupedCustomLayersDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.ConfiguredLayerDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants; @@ -631,45 +632,50 @@ public class GeonaDataViewMainPanel extends Composite { } - public void setCustomLayers(List listCustomLayers) { + public void addOverlayLayers(GCubeCollection collection, + List> listGroupedLayers) { - if (listCustomLayers == null) + if (listGroupedLayers == null) return; - for (GroupedCustomLayersDV gCustomLayerDV : listCustomLayers) { + for (GroupedLayersDV gCustomLayerDV : listGroupedLayers) { if (gCustomLayerDV.getListCustomLayers() != null) { - com.github.gwtbootstrap.client.ui.Label labelGroup = new com.github.gwtbootstrap.client.ui.Label(gCustomLayerDV.getName()); + com.github.gwtbootstrap.client.ui.Label labelGroup = new com.github.gwtbootstrap.client.ui.Label( + gCustomLayerDV.getName()); labelGroup.setType(LabelType.WARNING); - String descr = gCustomLayerDV.getDescription() != null - && !gCustomLayerDV.getDescription().isEmpty() ? gCustomLayerDV.getDescription() - : gCustomLayerDV.getName(); + String descr = gCustomLayerDV.getDescription() != null && !gCustomLayerDV.getDescription().isEmpty() + ? gCustomLayerDV.getDescription() + : gCustomLayerDV.getName(); labelGroup.setTitle(descr); panelCustomOverlayLayers.add(labelGroup); - if(descr.compareTo(gCustomLayerDV.getName())!=0) { + if (descr.compareTo(gCustomLayerDV.getName()) != 0) { HTML overlayGroupDescr = new HTML(); overlayGroupDescr.getElement().setClassName("overlay-panel-style-description"); overlayGroupDescr.setHTML(descr); panelCustomOverlayLayers.add(overlayGroupDescr); } - for (CustomLayerDV customLayer : gCustomLayerDV.getListCustomLayers()) { + List list = gCustomLayerDV.getListCustomLayers(); + for (ConfiguredLayerDV customLayer : list) { - if(customLayer.isDisplay()) { + if (customLayer.isDisplay()) { LayerItem layerItem = new LayerItem(); - final String mapServerHost = URLUtil.getPathURL(customLayer.getWms_url()); - GWT.log("mapServerHost: " + mapServerHost); - layerItem.setMapServerHost(mapServerHost); - layerItem.setBaseLayer(false); - layerItem.setName(customLayer.getName()); - layerItem.setTitle(customLayer.getTitle()); - layerItem.setWmsLink(customLayer.getWms_url()); - panelCustomOverlayLayers.add(new OverlayCustomLayerPanel(layerItem, applicationBus)); - map.addGroupedCustomWMSLayer(layerItem); + if (customLayer.getWMS_URL() != null) { + final String mapServerHost = URLUtil.getPathURL(customLayer.getWMS_URL()); + GWT.log("mapServerHost: " + mapServerHost); + layerItem.setMapServerHost(mapServerHost); + layerItem.setBaseLayer(false); + layerItem.setName(customLayer.getName()); + layerItem.setTitle(customLayer.getTitle()); + layerItem.setWmsLink(customLayer.getWMS_URL()); + panelCustomOverlayLayers.add(new OverlayCustomLayerPanel(layerItem, applicationBus)); + map.addGroupedCustomWMSLayer(layerItem); + } } } } } - linkCustomOverlayLayers.setVisible(listCustomLayers.size() > 0); + linkCustomOverlayLayers.setVisible(listGroupedLayers.size() > 0); } 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 07af62d..92721da 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 @@ -22,6 +22,7 @@ import java.util.stream.StreamSupport; import javax.servlet.ServletConfig; import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; import org.bson.Document; import org.gcube.application.geoportal.common.model.configuration.Configuration; @@ -48,10 +49,16 @@ import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.GeoportalConfigurationID; +import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.ConfiguredLayerDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.CrossFilteringLayerDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDILayer; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; -import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GroupedCustomLayersDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GeoServerPlatformInfoDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.IdentificationReferencesTYPE; @@ -123,19 +130,41 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme gif, png, jpeg, jpg, bmp, tif, tiff, svg, avif, webp } + /** + * The Enum CENTROID_LAYER_INDEX_FLAG. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 25, 2023 + */ public static enum CENTROID_LAYER_INDEX_FLAG { PUBLIC("public"), PRIVATE("internal"); String id; + /** + * Instantiates a new centroid layer index flag. + * + * @param id the id + */ CENTROID_LAYER_INDEX_FLAG(String id) { this.id = id; } + /** + * Gets the id. + * + * @return the id + */ public String getId() { return id; } + /** + * To string. + * + * @return the string + */ @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -471,6 +500,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme try { LOG.debug("Checking configuration for collection " + u.getId()); + SessionUtil.addCollectionToSession(getThreadLocalRequest(), u); + Projects p = projects(u.getId()).build(); UseCaseDescriptorDV ucdDV = ConvertToDataValueObjectModel.toUseCaseDescriptorDV(u, null); @@ -478,18 +509,18 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme GCubeCollection coll = new GCubeCollection(); coll.setUcd(ucdDV); - // Loading geoportal_grouped_custom_layers if exists - GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_grouped_custom_layers; - List handlers = u.getHandlersByType(theHandler.getType()); - - if (handlers != null && handlers.size() > 0) { - // Loading Handler gcube_profiles - HandlerDeclaration handler = handlers.get(0); - List listCustomLayers = getGroupedCustomLayers(u, handler, - GEOPORTAL_DATA_HANDLER.geoportal_grouped_custom_layers); - config.setGroupCustomLayers(listCustomLayers); - } else - LOG.warn("No handler " + theHandler + "found into UCD " + u.getId() + ", continue..."); +// // Loading geoportal_grouped_overlay_layers if exists +// GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers; +// List handlers = u.getHandlersByType(theHandler.getType()); +// +// if (handlers != null && handlers.size() > 0) { +// // Loading Handler gcube_profiles +// HandlerDeclaration handler = handlers.get(0); +// List listCustomLayers = getGroupedOverlayLayers(u, handler, +// GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers); +// config.setGroupCustomLayers(listCustomLayers); +// } else +// LOG.warn("No handler " + theHandler + "found into UCD " + u.getId() + ", continue..."); // TODO TO Check index flag should be in configuration or evaluated according to // user credentials @@ -548,11 +579,123 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme }.execute().getResult(); } + /** + * Gets the avaiable custom grouped layers for UCD. + * + * @param theHandler the the handler + * @return the avaiable custom grouped layers for UCD + */ + @Override + public Map>> getAvaiableCustomGroupedLayersForUCD( + GEOPORTAL_DATA_HANDLER theHandler) { + LOG.debug("getAvaiableCustomGroupedLayersForUCD called"); + + Map>> mapProfileIDCustomGroupedLayers = new LinkedHashMap<>(); + + // Reading UCDs Collections from the session + Map ucdCollections = SessionUtil.getAvailableCollections(getThreadLocalRequest()); + LOG.debug("ucdCollections in session are: " + ucdCollections.size()); + + for (String profileId : ucdCollections.keySet()) { + + UseCaseDescriptor u = ucdCollections.get(profileId); + + // Loading geoportal_grouped_overlay_layers if exists + List handlers = u.getHandlersByType(theHandler.getType()); + + GEOPORTAL_CONFIGURATION_TYPE configurationType = null; + switch (theHandler) { + case geoportal_grouped_overlay_layers: + configurationType = GEOPORTAL_CONFIGURATION_TYPE.grouped_overlay_layers; + break; + case geoportal_grouped_cross_filtering: + configurationType = GEOPORTAL_CONFIGURATION_TYPE.grouped_cross_filtering_layers; + default: + break; + } + + if (configurationType != null && handlers != null && handlers.size() > 0) { + // Loading Handler gcube_profiles + HandlerDeclaration handler = handlers.get(0); + List> listGroupedCustomLayers = (List>) getGroupedLayers( + u, handler, configurationType); + LOG.debug("listGroupedCustomLayers for type '{}' are: {}", configurationType, listGroupedCustomLayers); + mapProfileIDCustomGroupedLayers.put(profileId, listGroupedCustomLayers); + } else { + LOG.info("No handler '{}' found into UCD {}, continue...",theHandler, u.getId()); + mapProfileIDCustomGroupedLayers.put(profileId, null); + } + } + + LOG.debug("mapProfileIDCustomGroupedLayers returned: " + mapProfileIDCustomGroupedLayers); + LOG.info("mapProfileIDCustomGroupedLayers returned are: " + mapProfileIDCustomGroupedLayers.size()); + return mapProfileIDCustomGroupedLayers; + + } + +// public Map> getAvaiableCrossFilteringLayers() { +// +// Map> mapProfileIDOvelayLayers = new LinkedHashMap<>(); +// +// // Reading UCDs Collections from the session +// Map ucdCollections = SessionUtil.getAvailableCollections(getThreadLocalRequest()); +// +// for (String profileId : ucdCollections.keySet()) { +// +// UseCaseDescriptor u = ucdCollections.get(profileId); +// +// // Loading geoportal_grouped_overlay_layers if exists +// GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_grouped_cross_filtering; +// List handlers = u.getHandlersByType(theHandler.getType()); +// +// if (handlers != null && handlers.size() > 0) { +// // Loading Handler gcube_profiles +// HandlerDeclaration handler = handlers.get(0); +// List listGroupedCustomLayers = null; +// try { +// +// HandlerDeclarationDV handlerDV = ConvertToDataValueObjectModel.toHandlerDeclarationDV(handler, u, +// GEOPORTAL_CONFIGURATION_TYPE.grouped_overlay_layers); +// +// if (handler != null) { +// ConfigurationDV config = handlerDV.getConfiguration(); +// switch (config.getConfigurationType()) { +// case grouped_overlay_layers: +// listGroupedCustomLayers = (List) config.getConfiguration(); +// break; +// default: +// break; +// } +// } +// } catch (Exception e) { +// LOG.error("Error on loading {} config for ucd Id {}. Returning null", +// GEOPORTAL_CONFIGURATION_TYPE.grouped_overlay_layers, u.getId()); +// } +// +// mapProfileIDOvelayLayers.put(profileId, listGroupedCustomLayers); +// } else { +// LOG.warn("No handler " + theHandler + "found into UCD " + u.getId() + ", continue..."); +// mapProfileIDOvelayLayers.put(profileId, null); +// } +// } +// +// return mapProfileIDOvelayLayers; +// +// } + + /** + * Gets the layer index. + * + * @param ucdConfig the ucd config + * @param flag the flag + * @return the layer index + */ private IndexLayerDV getLayerIndex(Configuration ucdConfig, CENTROID_LAYER_INDEX_FLAG flag) { for (Index index : ucdConfig.getIndexes()) { try { IndexLayerDV toAdd = ConvertToDataValueObjectModel.convert(index); + toAdd = removeGSWorkspaceFromWMSPathOfOGCLinks(toAdd); LOG.trace("Discovered index: " + toAdd); if (toAdd.getFlag().compareToIgnoreCase(flag.getId()) == 0) { LOG.debug("Layer index found for flag: " + flag + ", returning"); @@ -568,28 +711,65 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return null; } - private List getGroupedCustomLayers(UseCaseDescriptor ucd, HandlerDeclaration handler, - GEOPORTAL_DATA_HANDLER geoportalGroupedCustomLayers) { + /** + * Removes the GS workspace from WMS path of OGC links. + * + * @param index the index + * @return the index layer DV + */ + private IndexLayerDV removeGSWorkspaceFromWMSPathOfOGCLinks(IndexLayerDV index) { + LOG.info("removeGSWorkspaceFromWMSPathOfOGCLinks called"); + GCubeSDILayer indexLayer = index.getLayer(); + HashMap ogcLinks = indexLayer.getOgcLinks(); + String wmsLink = ogcLinks.get("wms"); + LOG.info("wms link is {}", wmsLink); + int lastCharOfthePath = wmsLink.indexOf("?"); + String wmsPath = wmsLink.substring(0, lastCharOfthePath); + for (GeoServerPlatformInfoDV geoserver : indexLayer.getPlatformInfos()) { + // removing "workspace/" from the wms path + if (wmsPath.contains(geoserver.getWorkspace())) { + wmsPath = wmsPath.replace(geoserver.getWorkspace() + "/", ""); + LOG.debug("purged wmsPath from the 'workspace' is {}", wmsPath); + wmsLink = wmsPath + wmsLink.substring(lastCharOfthePath, wmsLink.length()); + ogcLinks.put("wms", wmsLink); + LOG.info("wms link without {} is {}", geoserver.getWorkspace(), wmsLink); + } + } + return index; - List listGroupedCustomLayers = null; + } + + /** + * Gets the grouped layers. + * + * @param ucd the ucd + * @param handler the handler + * @param type the type + * @return the grouped layers + */ + private List getGroupedLayers(UseCaseDescriptor ucd, HandlerDeclaration handler, + GEOPORTAL_CONFIGURATION_TYPE type) { + + List listGroupedCustomLayers = null; try { - HandlerDeclarationDV handlerDV = ConvertToDataValueObjectModel.toHandlerDeclarationDV(handler, ucd, - GEOPORTAL_CONFIGURATION_TYPE.grouped_custom_layers); + HandlerDeclarationDV handlerDV = ConvertToDataValueObjectModel.toHandlerDeclarationDV(handler, ucd, type); if (handler != null) { ConfigurationDV config = handlerDV.getConfiguration(); switch (config.getConfigurationType()) { - case grouped_custom_layers: - listGroupedCustomLayers = (List) config.getConfiguration(); + case grouped_overlay_layers: + listGroupedCustomLayers = (List>) config.getConfiguration(); break; + case grouped_cross_filtering_layers: + listGroupedCustomLayers = (List>) config.getConfiguration(); default: break; } } } catch (Exception e) { - LOG.error("Error on loading {} config for ucd Id {}. Returning null", geoportalGroupedCustomLayers, ucd.getId()); + LOG.error("Error on loading {} config for ucd Id {}. Returning null", type, ucd.getId()); } return listGroupedCustomLayers; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java index 5cb8986..3993314 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java @@ -3,7 +3,9 @@ */ package org.gcube.portlets.user.geoportaldataviewer.server.util; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @@ -26,6 +28,7 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import com.liferay.portal.service.UserLocalServiceUtil; /** @@ -51,6 +54,8 @@ public class SessionUtil { private static final String COUNT_DOCS_FOR_PROFILE_ID = "GNA_DATAVIEWER_COUNT_DOCS_FOR_PROFILE_ID"; + private static final String UCD_COLLECTIONS_SESSION = "THE_UCD_COLLECTIONS"; + /** * Checks if is into portal. * @@ -136,7 +141,7 @@ public class SessionUtil { if (token != null) { LOG.debug("Returning token " + token.substring(1, 10) + "_MASKED_TOKEN_"); - if(setInThread) + if (setInThread) SecurityTokenProvider.instance.set(token); } @@ -273,33 +278,6 @@ public class SessionUtil { HttpSession session = httpServletRequest.getSession(); List listOfConcessioni = (List) session.getAttribute(LIST_OF_CONCESSIONI); throw new Exception("getListConcessioni must be revisited!!!!"); - /* - * // setting null to force reloading from service if (reloadFromService) - * listOfConcessioni = null; - * - * if (listOfConcessioni == null) { listOfConcessioni = new - * ArrayList(); - * LOG.info("Loading list of concessione from client mongo"); - * SessionUtil.getCurrentContext(httpServletRequest, true); MongoServiceCommon - * serviceUtil = new MongoServiceCommon(); MongoConcessioni clientMongo = - * serviceUtil.getInstanceMongoConcessioni(); - * - * Iterator concessioni = clientMongo.getList(); if (concessioni != - * null) { while (concessioni.hasNext()) { Concessione concessione = - * (Concessione) concessioni.next(); listOfConcessioni.add(concessione); - * - * } } // LOG.debug("Got list of concessioni from client mongo: " + - * listOfConcessioni); session.setAttribute(LIST_OF_CONCESSIONI, - * listOfConcessioni); - * LOG.info("Saved in session list of concessioni from client mongo with size: " - * + listOfConcessioni.size()); - * - * } else LOG.info("list of concessioni presents in session, using it"); - * - * LOG.info("read list of concessioni with size: " + listOfConcessioni.size()); - * return listOfConcessioni; - * - */ } /** @@ -352,4 +330,20 @@ public class SessionUtil { } + public static void addCollectionToSession(HttpServletRequest httpServletRequest, UseCaseDescriptor u) { + HttpSession session = httpServletRequest.getSession(); + Map ucds = (Map) session + .getAttribute(UCD_COLLECTIONS_SESSION); + if (ucds == null) { + ucds = new HashMap(); + } + ucds.put(u.getId(), u); + session.setAttribute(UCD_COLLECTIONS_SESSION, ucds); + } + + public static Map getAvailableCollections(HttpServletRequest httpServletRequest) { + HttpSession session = httpServletRequest.getSession(); + return (Map) session.getAttribute(UCD_COLLECTIONS_SESSION); + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java index 5fd43e1..30f8430 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java @@ -4,7 +4,6 @@ import java.io.Serializable; import java.util.List; import java.util.Map; -import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GroupedCustomLayersDV; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; public class ViewerConfiguration implements Serializable { @@ -23,8 +22,6 @@ public class ViewerConfiguration implements Serializable { public Map availableCollections; - private List listCustomLayers; - public List getBaseLayers() { return baseLayers; } @@ -40,14 +37,4 @@ public class ViewerConfiguration implements Serializable { public void setAvailableCollections(Map availableCollections) { this.availableCollections = availableCollections; } - - public void setGroupCustomLayers(List listCustomLayers) { - this.listCustomLayers = listCustomLayers; - - } - - public List getListCustomLayers() { - return listCustomLayers; - } - } From a208b377917f057641f1a82d3660f657ead8d937 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 May 2023 14:45:47 +0200 Subject: [PATCH 06/18] in progress cross-filtering --- .classpath | 6 +- .../com.gwtplugins.gdt.eclipse.core.prefs | 2 +- .settings/org.eclipse.wst.common.component | 42 ++- .../client/GeoportalDataViewer.java | 60 ++-- .../client/ui/GeonaDataViewMainPanel.java | 70 +++- .../client/ui/GeonaDataViewMainPanel.ui.xml | 5 + .../CrossFilteringLayerPanel.java | 320 ++++++++++++++++++ .../CrossFilteringLayerPanel.ui.xml | 22 ++ .../client/ui/util/OLGeoJSONUtil.java | 55 +++ .../GeoportalDataViewerServiceImpl.java | 1 - .../server/util/SessionUtil.java | 1 - src/main/webapp/GeoportalDataViewer.css | 23 ++ 12 files changed, 564 insertions(+), 43 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java diff --git a/.classpath b/.classpath index 61bb68c..1e9c243 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -35,5 +35,5 @@ - + diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs index 3f0dc49..2377aa7 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/francescomangiacrapa/git/geoportal-data-viewer-app/target/geoportal-data-viewer-app-3.4.0-SNAPSHOT +lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-viewer-app/target/geoportal-data-viewer-app-3.5.0-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 9957ee3..f13f375 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,5 @@ - + @@ -79,8 +79,12 @@ - - + + + + + + @@ -161,7 +165,9 @@ - + + + @@ -242,7 +248,9 @@ - + + + @@ -323,7 +331,9 @@ - + + + @@ -404,7 +414,9 @@ - + + + @@ -488,7 +500,9 @@ uses - + + + @@ -569,7 +583,9 @@ - + + + @@ -650,7 +666,9 @@ - + + + @@ -731,7 +749,9 @@ - + + + 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 cffe69c..98547e5 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 @@ -59,6 +59,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap; import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAImages; import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel; import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation.TimelineManagerStatus; +import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil; import org.gcube.portlets.user.geoportaldataviewer.client.util.ControlledCallBack; import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon; import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; @@ -91,12 +92,6 @@ import com.google.gwt.user.client.ui.Widget; import ol.Coordinate; import ol.Feature; -import ol.OLFactory; -import ol.format.GeoJson; -import ol.format.GeoJsonFeatureOptions; -import ol.format.GeoJsonOptions; -import ol.proj.Projection; -import ol.proj.ProjectionOptions; /** * Entry point classes define onModuleLoad(). @@ -295,7 +290,7 @@ public class GeoportalDataViewer implements EntryPoint { // if (result.getListCustomLayers() != null && result.getListCustomLayers().size() > 0) { // mainPanel.setCustomLayers(result.getListCustomLayers()); // } - + loadConfigureduGroupedLayersForUCD(); GWT.log("DONE INIT LOAD"); @@ -318,7 +313,6 @@ public class GeoportalDataViewer implements EntryPoint { RootPanel.get(APP_DIV).add(attributionDiv); } - /** * Load Overlay Layers and Cross-Filtering layers for UCD * @@ -332,13 +326,14 @@ public class GeoportalDataViewer implements EntryPoint { @Override public void onFailure(Throwable caught) { - Window.alert("error: "+caught.getMessage()); + GWT.log("loadConfigureduGroupedLayersForUCD error for " + + GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers + ": " + caught.getMessage()); } @Override public void onSuccess(Map>> result) { - GWT.log("GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers returned: "); + GWT.log(GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers +" returned: "+result); if (result != null && result.size() > 0) { Map collections = viewerConfiguration.getAvailableCollections(); @@ -355,6 +350,38 @@ public class GeoportalDataViewer implements EntryPoint { } } }); + + GeoportalDataViewerServiceAsync.Util.getInstance().getAvaiableCustomGroupedLayersForUCD( + GEOPORTAL_DATA_HANDLER.geoportal_grouped_cross_filtering, + new AsyncCallback>>>() { + + @Override + public void onFailure(Throwable caught) { + GWT.log("loadConfigureduGroupedLayersForUCD error for " + + GEOPORTAL_DATA_HANDLER.geoportal_grouped_cross_filtering + ": " + + caught.getMessage()); + + } + + @Override + public void onSuccess(Map>> result) { + GWT.log(GEOPORTAL_DATA_HANDLER.geoportal_grouped_cross_filtering+" returned: "+result); + if (result != null && result.size() > 0) { + + Map collections = viewerConfiguration.getAvailableCollections(); + + for (String profileId : result.keySet()) { + List> list = result.get(profileId); + if (list != null && list.size() > 0) { + GCubeCollection collection = collections.get(profileId); + mainPanel.addCrossFilteringLayers(collection, list); + + } + } + + } + } + }); } /** @@ -980,18 +1007,7 @@ public class GeoportalDataViewer implements EntryPoint { */ private void showLayerFeatures(LayerItem layerItem, String geoJSONFeatures, ProjectDV projectDV) { - GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions(); - ProjectionOptions projectionOptions = new ProjectionOptions(); - projectionOptions.setCode(MAP_PROJECTION.EPSG_4326.getName()); - Projection fp = new Projection(projectionOptions); - fo.setFeatureProjection(fp); - fo.setDataProjection(fp); - GeoJsonOptions geoJsonOpt = new GeoJsonOptions(); - geoJsonOpt.setDefaultDataProjection(fp); - geoJsonOpt.setFeatureProjection(fp); - GeoJson geoJson = OLFactory.createGeoJSON(geoJsonOpt); - - Feature[] features = geoJson.readFeatures(geoJSONFeatures); + Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, geoJSONFeatures); GWT.log("features: " + features); olMapMng.getOLMap().addLayerFeaturesAsHighlight(layerItem, features, true); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index b8ccb33..23301f5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -23,6 +23,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap; import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAIcons; import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAImages; import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.search.SearchFacilityUI; +import org.gcube.portlets.user.geoportaldataviewer.client.ui.crossfiltering.CrossFilteringLayerPanel; import org.gcube.portlets.user.geoportaldataviewer.client.ui.customoverlays.OverlayCustomLayerPanel; import org.gcube.portlets.user.geoportaldataviewer.client.ui.layercollection.LayerCollectionPanel; import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil; @@ -61,6 +62,7 @@ import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.LayoutPanel; import com.google.gwt.user.client.ui.RadioButton; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.SimplePanel; @@ -122,9 +124,15 @@ public class GeonaDataViewMainPanel extends Composite { @UiField DropdownButton linkCustomOverlayLayers; + @UiField + DropdownButton linkCrossFilteringLayers; + @UiField HTMLPanel panelCustomOverlayLayers; + @UiField + HTMLPanel panelCrossFilteringLayers; + @UiField HTMLPanel openCollectionPanel; @@ -638,21 +646,30 @@ public class GeonaDataViewMainPanel extends Composite { if (listGroupedLayers == null) return; + com.github.gwtbootstrap.client.ui.Label collectionGroup = new com.github.gwtbootstrap.client.ui.Label( + collection.getUcd().getName()); + collectionGroup.setType(LabelType.WARNING); + LayoutPanel lc = new LayoutPanel(); + lc.add(collectionGroup); + panelCustomOverlayLayers.add(lc); + for (GroupedLayersDV gCustomLayerDV : listGroupedLayers) { if (gCustomLayerDV.getListCustomLayers() != null) { + FlowPanel lcInner = new FlowPanel(); + lcInner.getElement().getStyle().setMarginLeft(5.0, Unit.PX); com.github.gwtbootstrap.client.ui.Label labelGroup = new com.github.gwtbootstrap.client.ui.Label( gCustomLayerDV.getName()); - labelGroup.setType(LabelType.WARNING); + labelGroup.setType(LabelType.INFO); String descr = gCustomLayerDV.getDescription() != null && !gCustomLayerDV.getDescription().isEmpty() ? gCustomLayerDV.getDescription() : gCustomLayerDV.getName(); labelGroup.setTitle(descr); - panelCustomOverlayLayers.add(labelGroup); + lcInner.add(labelGroup); if (descr.compareTo(gCustomLayerDV.getName()) != 0) { HTML overlayGroupDescr = new HTML(); overlayGroupDescr.getElement().setClassName("overlay-panel-style-description"); overlayGroupDescr.setHTML(descr); - panelCustomOverlayLayers.add(overlayGroupDescr); + lcInner.add(overlayGroupDescr); } List list = gCustomLayerDV.getListCustomLayers(); for (ConfiguredLayerDV customLayer : list) { @@ -667,16 +684,61 @@ public class GeonaDataViewMainPanel extends Composite { layerItem.setName(customLayer.getName()); layerItem.setTitle(customLayer.getTitle()); layerItem.setWmsLink(customLayer.getWMS_URL()); - panelCustomOverlayLayers.add(new OverlayCustomLayerPanel(layerItem, applicationBus)); + // panelCustomOverlayLayers.add(new CrossFilteringLayerPanel(layerItem, + // applicationBus)); + lcInner.add(new OverlayCustomLayerPanel(layerItem, applicationBus)); map.addGroupedCustomWMSLayer(layerItem); } } } + panelCustomOverlayLayers.add(lcInner); } + } linkCustomOverlayLayers.setVisible(listGroupedLayers.size() > 0); } + public void addCrossFilteringLayers(GCubeCollection collection, + List> listGroupedLayers) { + + if (listGroupedLayers == null) + return; + + com.github.gwtbootstrap.client.ui.Label collectionGroup = new com.github.gwtbootstrap.client.ui.Label( + collection.getUcd().getName()); + collectionGroup.setType(LabelType.WARNING); + LayoutPanel lc = new LayoutPanel(); + lc.add(collectionGroup); + panelCrossFilteringLayers.add(lc); + for (GroupedLayersDV groupedLayerDV : listGroupedLayers) { + FlowPanel lcInner = new FlowPanel(); + lcInner.getElement().getStyle().setMarginLeft(5.0, Unit.PX); + com.github.gwtbootstrap.client.ui.Label labelGroup = new com.github.gwtbootstrap.client.ui.Label( + groupedLayerDV.getName()); + labelGroup.setType(LabelType.INFO); + String descr = groupedLayerDV.getDescription() != null && !groupedLayerDV.getDescription().isEmpty() + ? groupedLayerDV.getDescription() + : groupedLayerDV.getName(); + labelGroup.setTitle(descr); + lcInner.add(labelGroup); + // panelCustomOverlayLayers.add(labelGroup); + if (descr.compareTo(groupedLayerDV.getName()) != 0) { + HTML overlayGroupDescr = new HTML(); + overlayGroupDescr.getElement().setClassName("filter-panel-style-description"); + overlayGroupDescr.setHTML(descr); + lcInner.add(overlayGroupDescr); + // panelCustomOverlayLayers.add(overlayGroupDescr); + } + lcInner.add(new CrossFilteringLayerPanel(groupedLayerDV, applicationBus)); + panelCrossFilteringLayers.add(lcInner); + } + + //panelCrossFilteringLayers.add(new CrossFilteringLayerPanel(groupedLayerDV, applicationBus)); + + linkCrossFilteringLayers.setVisible(listGroupedLayers.size() > 0); + + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml index 4545cd4..2a7d6e9 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml @@ -65,6 +65,11 @@ + + + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java new file mode 100644 index 0000000..e1e4307 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -0,0 +1,320 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.ui.crossfiltering; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.CrossFilteringLayerDV; +import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; +import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; +import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; + +import com.github.gwtbootstrap.client.ui.CheckBox; +import com.github.gwtbootstrap.client.ui.ControlGroup; +import com.github.gwtbootstrap.client.ui.ControlLabel; +import com.github.gwtbootstrap.client.ui.Controls; +import com.github.gwtbootstrap.client.ui.Fieldset; +import com.github.gwtbootstrap.client.ui.ListBox; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.http.client.Request; +import com.google.gwt.http.client.RequestBuilder; +import com.google.gwt.http.client.RequestCallback; +import com.google.gwt.http.client.RequestException; +import com.google.gwt.http.client.Response; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.json.client.JSONValue; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.Widget; + +import ol.Feature; + +/** + * The Class CrossFilteringLayerPanel. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 15, 2023 + */ +public class CrossFilteringLayerPanel extends Composite { + + public static String COLORSCALERANGE = "COLORSCALERANGE"; + + //@UiField + //WellForm panelContainer; + + @UiField + Fieldset fieldSet; + + private CheckBox checkbox; + + private GeoInformationForWMSRequest geoInformation; + + private static CrossFilteringLayerPanelUiBinder uiBinder = GWT.create(CrossFilteringLayerPanelUiBinder.class); + + private HandlerManager applicationBus; + + private LayerItem layerItem; + + private LinkedHashMap> mapInnestedFeatures = new LinkedHashMap>(); + + private LinkedHashMap> mapInnestedFiltering = new LinkedHashMap>(); + + private LinkedHashMap> mapInnestedListBoxes = new LinkedHashMap>(); + + private GroupedLayersDV groupedLayersDV; + + /** + * The Interface LayerCollectionPanelUiBinder. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jan 16, 2023 + */ + interface CrossFilteringLayerPanelUiBinder extends UiBinder { + } + + public class SelectableItem { + String key; + String parentKey; + String itemField; + + String provenance; // layerName + + SelectableItem() { + + } + + public SelectableItem(String key, String parentKey, String itemField, String provenance) { + super(); + this.key = key; + this.parentKey = parentKey; + this.itemField = itemField; + this.provenance = provenance; + } + + public String getKey() { + return key; + } + + public String getParentKey() { + return parentKey; + } + + public String getItemField() { + return itemField; + } + + public String getProvenance() { + return provenance; + } + + public void setKey(String key) { + this.key = key; + } + + public void setParentKey(String parentKey) { + this.parentKey = parentKey; + } + + public void setItemField(String itemField) { + this.itemField = itemField; + } + + public void setProvenance(String provenance) { + this.provenance = provenance; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SelectableItem [key="); + builder.append(key); + builder.append(", parentKey="); + builder.append(parentKey); + builder.append(", itemField="); + builder.append(itemField); + builder.append(", provenance="); + builder.append(provenance); + builder.append("]"); + return builder.toString(); + } + + } + + private void recursivelyBuildSelectableLevels(int level, List layersIDV) { + + if (layersIDV == null) + return; + + mapInnestedFiltering.put(level, layersIDV); + + for (LayerIDV layerIDV : layersIDV) { + if (layerIDV instanceof CrossFilteringLayerDV) { + CrossFilteringLayerDV crossFilteringLayer = (CrossFilteringLayerDV) layerIDV; + + if (crossFilteringLayer.getRelated_to() != null) { + recursivelyBuildSelectableLevels(++level, crossFilteringLayer.getRelated_to()); + } + } + } + } + + /** + * Instantiates a new overlay custom layer panel. + * + * @param listGroupedLayers the layer item + * @param applicationBus the application bus + */ + public CrossFilteringLayerPanel(GroupedLayersDV groupedLayersDV, + HandlerManager applicationBus) { + initWidget(uiBinder.createAndBindUi(this)); + this.applicationBus = applicationBus; + this.groupedLayersDV = groupedLayersDV; + GWT.log("Building cross-filtering for: " + groupedLayersDV); + + int level = 0; + // Building mapInnestedFiltering + recursivelyBuildSelectableLevels(level, groupedLayersDV.getListCustomLayers()); + + GWT.log("cross-filtering mapInnestedFiltering: " + mapInnestedFiltering); + + for (Integer theLevel : mapInnestedFiltering.keySet()) { + addListBoxesLevelToPanel(theLevel, mapInnestedFiltering.get(theLevel)); + } + + // filleSelectableLevel(level, mapInnestedFiltering.get(level), + // mapInnestedListBoxes.get(level)); + + } + + private void filleSelectableLevel(int level, List layersIDV, List listBoxes) { + + if (layersIDV == null) + return; + + HashMap mapSelectableFeatures = mapInnestedFeatures.get(level); + + if (mapSelectableFeatures == null) { + mapSelectableFeatures = new HashMap(); + HashMap mapFeatures = new HashMap(); + + for (LayerIDV layerIDV : layersIDV) { + if (layerIDV instanceof CrossFilteringLayerDV) { + CrossFilteringLayerDV crossFilteringLayer = (CrossFilteringLayerDV) layerIDV; + String wfsURL = crossFilteringLayer.getWFS_URL(); + RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsURL); + + try { + + Request response = builder.sendRequest(null, new RequestCallback() { + public void onError(Request request, Throwable exception) { + // Code omitted for clarity + } + + public void onResponseReceived(Request request, Response response) { + JSONString json = new JSONString(response.getText()); + JSONValue parser = JSONParser.parse(response.getText()); + Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, + response.getText()); + for (Feature feature : features) { + String key = feature.get(crossFilteringLayer.getTable_key_field()); + String parentKey = feature.get(crossFilteringLayer.getTable_parent_key_field()); + String itemField = feature.get(crossFilteringLayer.getTable_show_field()); + + parentKey = parentKey == null ? "" : parentKey; + + SelectableItem selectableItem = new SelectableItem(key, parentKey, itemField, + crossFilteringLayer.getName()); + + String mapKey = "root_" + parentKey + key; + mapFeatures.put(mapKey, selectableItem); + + } + } + }); + + } catch (RequestException e) { + // Code omitted for clarity + } + } + } + mapSelectableFeatures.putAll(mapFeatures); + } + + fillListBoxLevel(level, mapSelectableFeatures, listBoxes); + // mapInnestedFeatures.put(level, mapSelectableFeatures); + + } + + private void addListBoxesLevelToPanel(int level, List layersIDV) { + + if (layersIDV == null) + return; + + List listBoxes = new ArrayList(layersIDV.size()); + + for (LayerIDV layerIDV : layersIDV) { + ControlGroup cg = new ControlGroup(); + ControlLabel cl = new ControlLabel(layerIDV.getTitle()); + Controls controls = new Controls(); + ListBox listBox = new ListBox(); + listBox.addItem("Select " + layerIDV.getTitle() + " ..."); + listBoxes.add(listBox); + + controls.add(listBox); + cg.add(cl); + cg.add(controls); + + fieldSet.add(cg); + } + + mapInnestedListBoxes.put(level, listBoxes); + } + + private void fillListBoxLevel(int level, HashMap mapSelectableFeatures, + List listBoxes) { + + if (mapSelectableFeatures == null) + return; + + ListBox listBox = listBoxes.get(0); // Expected one + + for (String key : mapSelectableFeatures.keySet()) { + SelectableItem selItem = mapSelectableFeatures.get(key); + listBox.addItem(selItem.getItemField(), key); + } + + listBox.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + loadInnerLevel(level); + } + }); + } + + private void loadInnerLevel(int level) { + // TODO Auto-generated method stub + + } + +// public void resetCurrentSearch() { +// searchField.setText(""); +// resetSearch.setVisible(false); +// panelResults.clear(); +// latestResult = null; +// appManagerBus.fireEvent(new SearchPerformedEvent(profileID, null, true)); +// setSearchEnabled(false); +// } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml new file mode 100644 index 0000000..2a5a31a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml @@ -0,0 +1,22 @@ + + + + .important { + font-weight: bold; + } + + .margin-left-10 { + margin-left: 10px; + } + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java new file mode 100644 index 0000000..aa766f4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java @@ -0,0 +1,55 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.ui.util; + +import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; + +import ol.Feature; +import ol.OLFactory; +import ol.format.GeoJson; +import ol.format.GeoJsonFeatureOptions; +import ol.format.GeoJsonOptions; +import ol.proj.Projection; +import ol.proj.ProjectionOptions; + +/** + * The Class OLGeoJSONUtil. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 25, 2023 + */ +public class OLGeoJSONUtil { + + /** + * Builds the geo JSON. + * + * @param projection the projection + * @param geoJSONString the geo JSON string + * @return the geo json + */ + public static GeoJson buildGeoJSON(MAP_PROJECTION projection, String geoJSONString) { + GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions(); + ProjectionOptions projectionOptions = new ProjectionOptions(); + projectionOptions.setCode(projection.getName()); + Projection fp = new Projection(projectionOptions); + fo.setFeatureProjection(fp); + fo.setDataProjection(fp); + GeoJsonOptions geoJsonOpt = new GeoJsonOptions(); + geoJsonOpt.setDefaultDataProjection(fp); + geoJsonOpt.setFeatureProjection(fp); + return OLFactory.createGeoJSON(geoJsonOpt); + + } + + /** + * Read geo json features. + * + * @param projection the projection + * @param geoJSONString the geo JSON string + * @return the feature[] + */ + public static Feature[] readGeoJsonFeatures(MAP_PROJECTION projection, String geoJSONString) { + GeoJson geoJson = buildGeoJSON(projection, geoJSONString); + return geoJson.readFeatures(geoJSONString); + } + +} 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 92721da..6efdbd4 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 @@ -22,7 +22,6 @@ import java.util.stream.StreamSupport; import javax.servlet.ServletConfig; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; import org.bson.Document; import org.gcube.application.geoportal.common.model.configuration.Configuration; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java index 3993314..6c0fb18 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java @@ -28,7 +28,6 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import com.liferay.portal.service.UserLocalServiceUtil; /** diff --git a/src/main/webapp/GeoportalDataViewer.css b/src/main/webapp/GeoportalDataViewer.css index ac79473..749dea3 100644 --- a/src/main/webapp/GeoportalDataViewer.css +++ b/src/main/webapp/GeoportalDataViewer.css @@ -836,6 +836,7 @@ RESPONSIVE .overlay-panel-style-description { border: none !important; white-space: pre-line; + padding: 5px 0px; } .overlay-panel-style > div { @@ -847,3 +848,25 @@ RESPONSIVE } +/* FILTER PANEL UI */ +.filter-panel-style { + padding-left: 10px; + padding-right: 10px; + max-width: 350px; +} + +.filter-panel-style-description { + border: none !important; + white-space: pre-line; + padding: 5px 0px; +} + +.filter-panel-style > div { + border: 1px solid #ccc; + border-radius: 5px; + padding: 10px; + margin-bottom: 10px; + margin-top: 5px; +} + + From 9d48e78fac5f0f69054b518397dd6a6903b797d3 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 May 2023 17:49:59 +0200 Subject: [PATCH 07/18] in progress cross filtering --- .../client/GeoportalDataViewer.java | 9 +- .../client/ui/GeonaDataViewMainPanel.java | 10 + .../CrossFilteringLayerPanel.java | 181 ++++++++++++------ .../OverlayCustomLayerPanel.java | 6 - .../client/ui/util/OLGeoJSONUtil.java | 4 +- .../GeoportalDataViewerServiceImpl.java | 13 -- 6 files changed, 140 insertions(+), 83 deletions(-) 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 98547e5..7f9d4d9 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 @@ -285,11 +285,6 @@ public class GeoportalDataViewer implements EntryPoint { } mainPanel.openCollectionMenu(); -// -// GWT.log("LIST CUSTOM LAYERS: " + result.getListCustomLayers()); -// if (result.getListCustomLayers() != null && result.getListCustomLayers().size() > 0) { -// mainPanel.setCustomLayers(result.getListCustomLayers()); -// } loadConfigureduGroupedLayersForUCD(); @@ -333,7 +328,7 @@ public class GeoportalDataViewer implements EntryPoint { @Override public void onSuccess(Map>> result) { - GWT.log(GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers +" returned: "+result); + GWT.log(GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers + " returned: " + result); if (result != null && result.size() > 0) { Map collections = viewerConfiguration.getAvailableCollections(); @@ -365,7 +360,7 @@ public class GeoportalDataViewer implements EntryPoint { @Override public void onSuccess(Map>> result) { - GWT.log(GEOPORTAL_DATA_HANDLER.geoportal_grouped_cross_filtering+" returned: "+result); + GWT.log(GEOPORTAL_DATA_HANDLER.geoportal_grouped_cross_filtering + " returned: " + result); if (result != null && result.size() > 0) { Map collections = viewerConfiguration.getAvailableCollections(); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index 23301f5..4eecdae 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -342,6 +342,16 @@ public class GeonaDataViewMainPanel extends Composite { } }, ClickEvent.getType()); + + linkCrossFilteringLayers.addDomHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + // event.preventDefault(); + event.stopPropagation(); + + } + }, ClickEvent.getType()); } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index e1e4307..4bb44bc 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -28,14 +28,13 @@ import com.google.gwt.http.client.RequestBuilder; import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.Response; -import com.google.gwt.json.client.JSONParser; -import com.google.gwt.json.client.JSONString; -import com.google.gwt.json.client.JSONValue; +import com.google.gwt.http.client.URL; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Widget; +import jsinterop.base.JsPropertyMap; import ol.Feature; /** @@ -49,8 +48,8 @@ public class CrossFilteringLayerPanel extends Composite { public static String COLORSCALERANGE = "COLORSCALERANGE"; - //@UiField - //WellForm panelContainer; + // @UiField + // WellForm panelContainer; @UiField Fieldset fieldSet; @@ -65,10 +64,10 @@ public class CrossFilteringLayerPanel extends Composite { private LayerItem layerItem; - private LinkedHashMap> mapInnestedFeatures = new LinkedHashMap>(); - private LinkedHashMap> mapInnestedFiltering = new LinkedHashMap>(); + private LinkedHashMap> mapInnestedFeatures = new LinkedHashMap>(); + private LinkedHashMap> mapInnestedListBoxes = new LinkedHashMap>(); private GroupedLayersDV groupedLayersDV; @@ -192,70 +191,101 @@ public class CrossFilteringLayerPanel extends Composite { addListBoxesLevelToPanel(theLevel, mapInnestedFiltering.get(theLevel)); } - // filleSelectableLevel(level, mapInnestedFiltering.get(level), - // mapInnestedListBoxes.get(level)); + filleSelectableLevel(level, null); } - private void filleSelectableLevel(int level, List layersIDV, List listBoxes) { + private void filleSelectableLevel(int level, SelectableItem selectedItem) { + + //HashMap mapOfFeatureAtLevel = mapInnestedFeatures.get(level); + List layersIDV = mapInnestedFiltering.get(level); + List listBoxes = mapInnestedListBoxes.get(level); if (layersIDV == null) return; - HashMap mapSelectableFeatures = mapInnestedFeatures.get(level); +// final HashMap mapSelectableFeatures = mapOfFeatureAtLevel == null +// ? new HashMap() +// : mapOfFeatureAtLevel; + + final HashMap mapSelectableFeatures = new HashMap(); - if (mapSelectableFeatures == null) { - mapSelectableFeatures = new HashMap(); - HashMap mapFeatures = new HashMap(); + // if (mapSelectableFeatures.isEmpty()) { - for (LayerIDV layerIDV : layersIDV) { - if (layerIDV instanceof CrossFilteringLayerDV) { - CrossFilteringLayerDV crossFilteringLayer = (CrossFilteringLayerDV) layerIDV; - String wfsURL = crossFilteringLayer.getWFS_URL(); - RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsURL); + LayerIDV layerIDV = layersIDV.get(0); // Expected one - try { + if (layerIDV instanceof CrossFilteringLayerDV) { + CrossFilteringLayerDV crossFilteringLayer = (CrossFilteringLayerDV) layerIDV; + String wfsURL = crossFilteringLayer.getWFS_URL(); - Request response = builder.sendRequest(null, new RequestCallback() { - public void onError(Request request, Throwable exception) { - // Code omitted for clarity - } + if (selectedItem != null) { - public void onResponseReceived(Request request, Response response) { - JSONString json = new JSONString(response.getText()); - JSONValue parser = JSONParser.parse(response.getText()); - Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, - response.getText()); - for (Feature feature : features) { - String key = feature.get(crossFilteringLayer.getTable_key_field()); - String parentKey = feature.get(crossFilteringLayer.getTable_parent_key_field()); - String itemField = feature.get(crossFilteringLayer.getTable_show_field()); + String cqlFilterValue = crossFilteringLayer.getTable_parent_key_field() + "=" + selectedItem.getKey(); + wfsURL += "&CQL_FILTER=" + URL.encode(cqlFilterValue); - parentKey = parentKey == null ? "" : parentKey; + } + GWT.log("wfsURL request: " + wfsURL); + RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsURL); - SelectableItem selectableItem = new SelectableItem(key, parentKey, itemField, - crossFilteringLayer.getName()); + try { - String mapKey = "root_" + parentKey + key; - mapFeatures.put(mapKey, selectableItem); - - } - } - }); - - } catch (RequestException e) { + Request response = builder.sendRequest(null, new RequestCallback() { + public void onError(Request request, Throwable exception) { // Code omitted for clarity } - } + + public void onResponseReceived(Request request, Response response) { + GWT.log("wfsURL response: " + response.getText()); + Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, + response.getText()); + + for (Feature feature : features) { + JsPropertyMap properties = feature.getProperties(); + Object key = properties.get(crossFilteringLayer.getTable_key_field()); + Object itemField = properties.get(crossFilteringLayer.getTable_show_field()); + + Object parentKey = null; + if (crossFilteringLayer.getTable_parent_key_field() != null + && !crossFilteringLayer.getTable_parent_key_field().isEmpty()) + parentKey = properties.get(crossFilteringLayer.getTable_parent_key_field()); + + parentKey = parentKey == null ? "" : parentKey; + + SelectableItem selectableItem = new SelectableItem(key + "", parentKey + "", itemField + "", + crossFilteringLayer.getName()); + GWT.log("select item: " + selectableItem); + + String pathFeatureKey = pathFeatureKey(selectableItem); + mapSelectableFeatures.put(pathFeatureKey, selectableItem); + + } + mapInnestedFeatures.put(level, mapSelectableFeatures); + String placholder = placeholderLayer(layersIDV.get(0)); // Expected one + fillListBoxLevel(level, mapSelectableFeatures, listBoxes, placholder); + } + }); + + } catch (RequestException e) { + // Code omitted for clarity } - mapSelectableFeatures.putAll(mapFeatures); } - fillListBoxLevel(level, mapSelectableFeatures, listBoxes); - // mapInnestedFeatures.put(level, mapSelectableFeatures); +// } else { +// +// String placholder = placeholderLayer(layersIDV.get(0)); // Expected one +// fillListBoxLevel(level, mapInnestedFeatures.get(level), listBoxes, placholder); +// } } + private String pathFeatureKey(SelectableItem selectableItem) { + return "root_" + selectableItem.getParentKey() + "_"+selectableItem.getKey(); + } + + private String placeholderLayer(LayerIDV layersIDV) { + return "Select " + layersIDV.getTitle() + "..."; + } + private void addListBoxesLevelToPanel(int level, List layersIDV) { if (layersIDV == null) @@ -268,26 +298,50 @@ public class CrossFilteringLayerPanel extends Composite { ControlLabel cl = new ControlLabel(layerIDV.getTitle()); Controls controls = new Controls(); ListBox listBox = new ListBox(); - listBox.addItem("Select " + layerIDV.getTitle() + " ..."); + String placeholder = placeholderLayer(layerIDV); + listBox.addItem(placeholder); + setEnabledBox(listBox, false); listBoxes.add(listBox); - controls.add(listBox); cg.add(cl); cg.add(controls); - + fieldSet.add(cg); } mapInnestedListBoxes.put(level, listBoxes); } + public void setEnabledBox(ListBox listBox, boolean bool) { + listBox.setEnabled(bool); + } + + public void clearListBox(ListBox listBox, boolean bool) { + listBox.setEnabled(bool); + } + + private void resetListBoxLevel(int level) { + + List listBoxes = mapInnestedListBoxes.get(level); + if(listBoxes!=null) { + for (ListBox listBox : listBoxes) { + listBox.clear(); + setEnabledBox(listBox, false); + } + } + } + private void fillListBoxLevel(int level, HashMap mapSelectableFeatures, - List listBoxes) { + List listBoxes, String placeholder) { + GWT.log("fillBox level: " + level + " map: " + mapSelectableFeatures); if (mapSelectableFeatures == null) return; ListBox listBox = listBoxes.get(0); // Expected one + listBox.clear(); + listBox.addItem(placeholder); + listBox.getElement().getFirstChildElement().setAttribute("disabled", "disabled"); for (String key : mapSelectableFeatures.keySet()) { SelectableItem selItem = mapSelectableFeatures.get(key); @@ -298,13 +352,30 @@ public class CrossFilteringLayerPanel extends Composite { @Override public void onChange(ChangeEvent event) { - loadInnerLevel(level); + loadInnerLevel(level, listBox.getSelectedValue()); } }); + + setEnabledBox(listBox, true); } - private void loadInnerLevel(int level) { - // TODO Auto-generated method stub + private void loadInnerLevel(int level, String selectableItemValue) { + GWT.log("selected level " + level + " selectableItemValue " + selectableItemValue); + HashMap mapSelectableItem = mapInnestedFeatures.get(level); + SelectableItem selectedItem = mapSelectableItem.get(selectableItemValue); + + GWT.log("selected selectableItem " + selectedItem); + int innerLevel = level + 1; + List selectedLayers = mapInnestedFiltering.get(innerLevel); + + //if layer filtering exists at this level + if (selectedLayers != null) { + + List selectedListBoxes = mapInnestedListBoxes.get(innerLevel); + GWT.log("loading inner layers " + selectedLayers); + GWT.log("loading selectedListBoxes " + selectedListBoxes); + filleSelectableLevel(innerLevel, selectedItem); + } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.java index 5da70d8..55e3e17 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/customoverlays/OverlayCustomLayerPanel.java @@ -114,12 +114,6 @@ public class OverlayCustomLayerPanel extends Composite { @Override public void onValueChange(ValueChangeEvent event) { GWT.log("CustomLayer selector flag changed to value : " + event.toDebugString()); - -// String collectionID = ((CheckBox) event.getSource()).getId().replace("gcubeCollectionSelector_", -// ""); - - // GWT.log("Collection ID is : " + collectionID + ", event value: " + - // event.getValue()); if (event.getValue()) { // OPEN COLLECTION applicationBus.fireEvent(new OverlayCustomLayerToMapEvent(layerItem, OverlayCustomLayerToMapEvent.ACTION_TYPE.VISIBILITY, true)); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java index aa766f4..80e2aa2 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java @@ -26,7 +26,7 @@ public class OLGeoJSONUtil { * @param geoJSONString the geo JSON string * @return the geo json */ - public static GeoJson buildGeoJSON(MAP_PROJECTION projection, String geoJSONString) { + public static GeoJson buildGeoJSON(MAP_PROJECTION projection) { GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions(); ProjectionOptions projectionOptions = new ProjectionOptions(); projectionOptions.setCode(projection.getName()); @@ -48,7 +48,7 @@ public class OLGeoJSONUtil { * @return the feature[] */ public static Feature[] readGeoJsonFeatures(MAP_PROJECTION projection, String geoJSONString) { - GeoJson geoJson = buildGeoJSON(projection, geoJSONString); + GeoJson geoJson = buildGeoJSON(projection); return geoJson.readFeatures(geoJSONString); } 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 6efdbd4..ee64f81 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 @@ -508,19 +508,6 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme GCubeCollection coll = new GCubeCollection(); coll.setUcd(ucdDV); -// // Loading geoportal_grouped_overlay_layers if exists -// GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers; -// List handlers = u.getHandlersByType(theHandler.getType()); -// -// if (handlers != null && handlers.size() > 0) { -// // Loading Handler gcube_profiles -// HandlerDeclaration handler = handlers.get(0); -// List listCustomLayers = getGroupedOverlayLayers(u, handler, -// GEOPORTAL_DATA_HANDLER.geoportal_grouped_overlay_layers); -// config.setGroupCustomLayers(listCustomLayers); -// } else -// LOG.warn("No handler " + theHandler + "found into UCD " + u.getId() + ", continue..."); - // TODO TO Check index flag should be in configuration or evaluated according to // user credentials From 33d6dbc89fa461b2d45e571b7b5b1b971f1038e4 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 31 May 2023 17:02:03 +0200 Subject: [PATCH 08/18] Applied CQL_Filter for cross filtering --- .settings/org.eclipse.wst.common.component | 30 +- .../client/GeoportalDataViewer.java | 48 ++- .../events/ApplyCQLToLayerMapEvent.java | 72 ++++ .../ApplyCQLToLayerMapEventHandler.java | 20 + .../client/ui/GeonaDataViewMainPanel.java | 8 +- .../ui/cms/search/SearchFacilityUI.java | 7 +- .../CrossFilteringLayerPanel.java | 378 ++++++++++++------ .../CrossFilteringLayerPanel.ui.xml | 12 +- src/main/webapp/GeoportalDataViewer.css | 17 +- 9 files changed, 448 insertions(+), 144 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEvent.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEventHandler.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index f13f375..9a321a3 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -82,7 +83,8 @@ - + + @@ -165,7 +167,8 @@ - + + @@ -248,7 +251,8 @@ - + + @@ -331,7 +335,8 @@ - + + @@ -414,7 +419,8 @@ - + + @@ -500,7 +506,8 @@ uses - + + @@ -583,7 +590,8 @@ - + + @@ -666,7 +674,8 @@ - + + @@ -749,7 +758,8 @@ - + + 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 7f9d4d9..4b3bb32 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 @@ -12,6 +12,7 @@ import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDILayer; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.RelationshipDV; @@ -24,6 +25,8 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.AddLayerToMapEv import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent.LAYER_TYPE; import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEventHandler; +import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.ChangeMapLayerEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.ChangeMapLayerEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEvent; @@ -863,9 +866,6 @@ public class GeoportalDataViewer implements EntryPoint { cqlFilter = cqlFilter.substring(0, cqlFilter.length() - 1) + ")"; setCqlFilter = cqlFilter; - setCqlFilter = "INTERSECTS(geom,querySingle('limiti_amministrativi:regioni','the_geom','DEN_REG=''Calabria'''));INCLUDE"; - GWT.log("HARD-CODED CQL FILTER: " + setCqlFilter); - olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, setCqlFilter); } else { @@ -886,6 +886,48 @@ public class GeoportalDataViewer implements EntryPoint { } }); + applicationBus.addHandler(ApplyCQLToLayerMapEvent.TYPE, new ApplyCQLToLayerMapEventHandler() { + + @Override + public void onApplyCQL(ApplyCQLToLayerMapEvent applyCQLToLayerMapEvent) { + GWT.log("Fired: " + applyCQLToLayerMapEvent); + + if (applyCQLToLayerMapEvent != null) { + + String layerName = null; + + GCubeSDILayer layer = applyCQLToLayerMapEvent.getTheIndeLayer().getLayer(); + + try { + String wmsLink = layer.getOgcLinks().get("wms"); + layerName = URLUtil.extractValueOfParameterFromURL("layers", wmsLink); + } catch (Exception e) { + // TODO: handle exception + } + + String setCqlFilter = null; + + if (layerName != null) { + + GWT.log("ApplyCQLToLayerMapEvent: " + layerName + ", filter : " + + applyCQLToLayerMapEvent.getCqlFilterValue()); + + + if (applyCQLToLayerMapEvent.getCqlFilterValue() == null) { + olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, null); + setCqlFilter = null; // is already null + } else { + setCqlFilter = applyCQLToLayerMapEvent.getCqlFilterValue(); + olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, setCqlFilter); + } + + layerManager.setCQLForLayerToIndexLayer(layerName, setCqlFilter); + } + } + + } + }); + } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEvent.java new file mode 100644 index 0000000..0b38f07 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEvent.java @@ -0,0 +1,72 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events; + +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class AddedLayerToMapEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Nov 18, 2020 + */ +public class ApplyCQLToLayerMapEvent extends GwtEvent { + public static Type TYPE = new Type(); + private IndexLayerDV theIndeLayer; + private String cqlFilterValue; + + /** + * Instantiates a new apply CQL to layer map event. + * + * @param theIndeLayer the the inde layer + * @param cqlFilter the cql filter + */ + public ApplyCQLToLayerMapEvent(IndexLayerDV theIndeLayer, String cqlFilterValue) { + this.theIndeLayer = theIndeLayer; + this.cqlFilterValue = cqlFilterValue; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + @Override + protected void dispatch(ApplyCQLToLayerMapEventHandler handler) { + handler.onApplyCQL(this); + + } + + public IndexLayerDV getTheIndeLayer() { + return theIndeLayer; + } + + public String getCqlFilterValue() { + return cqlFilterValue; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ApplyCQLToLayerMapEvent [theIndeLayer="); + builder.append(theIndeLayer); + builder.append(", cqlFilterValue="); + builder.append(cqlFilterValue); + builder.append("]"); + return builder.toString(); + } + + + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEventHandler.java new file mode 100644 index 0000000..8557944 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEventHandler.java @@ -0,0 +1,20 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events; + +import com.google.gwt.event.shared.EventHandler; + +/** + * The Interface ApplyCQLToLayerMapEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 31, 2023 + */ +public interface ApplyCQLToLayerMapEventHandler extends EventHandler { + + /** + * On apply CQL. + * + * @param applyCQLToLayerMapEvent the apply CQL to layer map event + */ + void onApplyCQL(ApplyCQLToLayerMapEvent applyCQLToLayerMapEvent); +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index 4eecdae..4cbc711 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -342,7 +342,7 @@ public class GeonaDataViewMainPanel extends Composite { } }, ClickEvent.getType()); - + linkCrossFilteringLayers.addDomHandler(new ClickHandler() { @Override @@ -741,11 +741,11 @@ public class GeonaDataViewMainPanel extends Composite { lcInner.add(overlayGroupDescr); // panelCustomOverlayLayers.add(overlayGroupDescr); } - lcInner.add(new CrossFilteringLayerPanel(groupedLayerDV, applicationBus)); + CrossFilteringLayerPanel cfp = new CrossFilteringLayerPanel(collection, groupedLayerDV, applicationBus); + cfp.setFilterButton(linkCrossFilteringLayers); + lcInner.add(cfp); panelCrossFilteringLayers.add(lcInner); } - - //panelCrossFilteringLayers.add(new CrossFilteringLayerPanel(groupedLayerDV, applicationBus)); linkCrossFilteringLayers.setVisible(listGroupedLayers.size() > 0); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java index 621090d..43d0916 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java @@ -127,6 +127,7 @@ public class SearchFacilityUI extends Composite { * * @param profileID the profile ID * @param appManagerBus the app manager bus + * @param displayByFields the display by fields * @param sortByFields the sort by fields * @param searchForFields the search for fields * @param initialSortFilter the initial sort filter @@ -237,6 +238,9 @@ public class SearchFacilityUI extends Composite { } + /** + * Reset current search. + */ public void resetCurrentSearch() { searchField.setText(""); resetSearch.setVisible(false); @@ -356,7 +360,8 @@ public class SearchFacilityUI extends Composite { profileID); // here appManagerBus.fireEvent(new ClosedViewDetailsEvent()); - appManagerBus.fireEvent(new ShowDetailsEvent(gir, null, true, true, EVENT_SOURCE.LOCATE_SEARCHED)); + appManagerBus.fireEvent( + new ShowDetailsEvent(gir, null, true, true, EVENT_SOURCE.LOCATE_SEARCHED)); // appManagerBus.fireEvent(new ShowPopupOnCentroidEvent(profileID, // resultDoc.getProjectID(), resultDoc.getSpatialReference())); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index 4bb44bc..bcab8cf 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -9,19 +9,26 @@ import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLaye import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.CrossFilteringLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; +import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEvent; import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil; +import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; +import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.CheckBox; import com.github.gwtbootstrap.client.ui.ControlGroup; import com.github.gwtbootstrap.client.ui.ControlLabel; import com.github.gwtbootstrap.client.ui.Controls; +import com.github.gwtbootstrap.client.ui.DropdownButton; import com.github.gwtbootstrap.client.ui.Fieldset; import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.http.client.Request; import com.google.gwt.http.client.RequestBuilder; @@ -54,6 +61,9 @@ public class CrossFilteringLayerPanel extends Composite { @UiField Fieldset fieldSet; + @UiField + Button buttonReset; + private CheckBox checkbox; private GeoInformationForWMSRequest geoInformation; @@ -72,6 +82,10 @@ public class CrossFilteringLayerPanel extends Composite { private GroupedLayersDV groupedLayersDV; + private GCubeCollection gCubeCollection; + + private DropdownButton filterButton; + /** * The Interface LayerCollectionPanelUiBinder. * @@ -82,74 +96,68 @@ public class CrossFilteringLayerPanel extends Composite { interface CrossFilteringLayerPanelUiBinder extends UiBinder { } - public class SelectableItem { - String key; - String parentKey; - String itemField; + /** + * Instantiates a new overlay custom layer panel. + * + * @param gCubeCollection the g cube collection + * @param groupedLayersDV the grouped layers DV + * @param applicationBus the application bus + */ + public CrossFilteringLayerPanel(GCubeCollection gCubeCollection, + GroupedLayersDV groupedLayersDV, HandlerManager applicationBus) { + initWidget(uiBinder.createAndBindUi(this)); + this.applicationBus = applicationBus; + this.groupedLayersDV = groupedLayersDV; + this.gCubeCollection = gCubeCollection; + GWT.log("Building cross-filtering for: " + groupedLayersDV); - String provenance; // layerName + buttonReset.setType(ButtonType.LINK); - SelectableItem() { + int level = 0; + // Building mapInnestedFiltering + recursivelyBuildSelectableLevels(level, groupedLayersDV.getListCustomLayers()); + GWT.log("cross-filtering mapInnestedFiltering: " + mapInnestedFiltering); + + for (Integer theLevel : mapInnestedFiltering.keySet()) { + addListBoxesLevelToPanel(theLevel, mapInnestedFiltering.get(theLevel)); } - public SelectableItem(String key, String parentKey, String itemField, String provenance) { - super(); - this.key = key; - this.parentKey = parentKey; - this.itemField = itemField; - this.provenance = provenance; - } + fillSelectableLevel(level, null); - public String getKey() { - return key; - } - - public String getParentKey() { - return parentKey; - } - - public String getItemField() { - return itemField; - } - - public String getProvenance() { - return provenance; - } - - public void setKey(String key) { - this.key = key; - } - - public void setParentKey(String parentKey) { - this.parentKey = parentKey; - } - - public void setItemField(String itemField) { - this.itemField = itemField; - } - - public void setProvenance(String provenance) { - this.provenance = provenance; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("SelectableItem [key="); - builder.append(key); - builder.append(", parentKey="); - builder.append(parentKey); - builder.append(", itemField="); - builder.append(itemField); - builder.append(", provenance="); - builder.append(provenance); - builder.append("]"); - return builder.toString(); - } + bindEvents(); } + /** + * Bind events. + */ + private void bindEvents() { + + buttonReset.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + for (int i = 1; i < mapInnestedListBoxes.size(); i++) { + resetListBoxLevel(i); + } + // Selecting the placeholder of the fist list box + List listBox = mapInnestedListBoxes.get(0); + listBox.get(0).setSelectedIndex(0); + // Resetting CQL filtering + applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(gCubeCollection.getIndexes().get(0), null)); + setFilterHighLighted(false); + } + }); + + } + + /** + * Recursively build selectable levels. + * + * @param level the level + * @param layersIDV the layers IDV + */ private void recursivelyBuildSelectableLevels(int level, List layersIDV) { if (layersIDV == null) @@ -169,49 +177,21 @@ public class CrossFilteringLayerPanel extends Composite { } /** - * Instantiates a new overlay custom layer panel. + * Fill selectable level. * - * @param listGroupedLayers the layer item - * @param applicationBus the application bus + * @param level the level + * @param selectedItem the selected item */ - public CrossFilteringLayerPanel(GroupedLayersDV groupedLayersDV, - HandlerManager applicationBus) { - initWidget(uiBinder.createAndBindUi(this)); - this.applicationBus = applicationBus; - this.groupedLayersDV = groupedLayersDV; - GWT.log("Building cross-filtering for: " + groupedLayersDV); + private void fillSelectableLevel(int level, SelectableItem selectedItem) { - int level = 0; - // Building mapInnestedFiltering - recursivelyBuildSelectableLevels(level, groupedLayersDV.getListCustomLayers()); - - GWT.log("cross-filtering mapInnestedFiltering: " + mapInnestedFiltering); - - for (Integer theLevel : mapInnestedFiltering.keySet()) { - addListBoxesLevelToPanel(theLevel, mapInnestedFiltering.get(theLevel)); - } - - filleSelectableLevel(level, null); - - } - - private void filleSelectableLevel(int level, SelectableItem selectedItem) { - - //HashMap mapOfFeatureAtLevel = mapInnestedFeatures.get(level); List layersIDV = mapInnestedFiltering.get(level); List listBoxes = mapInnestedListBoxes.get(level); if (layersIDV == null) return; -// final HashMap mapSelectableFeatures = mapOfFeatureAtLevel == null -// ? new HashMap() -// : mapOfFeatureAtLevel; - final HashMap mapSelectableFeatures = new HashMap(); - // if (mapSelectableFeatures.isEmpty()) { - LayerIDV layerIDV = layersIDV.get(0); // Expected one if (layerIDV instanceof CrossFilteringLayerDV) { @@ -220,7 +200,7 @@ public class CrossFilteringLayerPanel extends Composite { if (selectedItem != null) { - String cqlFilterValue = crossFilteringLayer.getTable_parent_key_field() + "=" + selectedItem.getKey(); + String cqlFilterValue = crossFilteringLayer.getTable_parent_key_field() + "=" + selectedItem.keyValue; wfsURL += "&CQL_FILTER=" + URL.encode(cqlFilterValue); } @@ -241,7 +221,7 @@ public class CrossFilteringLayerPanel extends Composite { for (Feature feature : features) { JsPropertyMap properties = feature.getProperties(); - Object key = properties.get(crossFilteringLayer.getTable_key_field()); + Object keyValue = properties.get(crossFilteringLayer.getTable_key_field()); Object itemField = properties.get(crossFilteringLayer.getTable_show_field()); Object parentKey = null; @@ -251,14 +231,17 @@ public class CrossFilteringLayerPanel extends Composite { parentKey = parentKey == null ? "" : parentKey; - SelectableItem selectableItem = new SelectableItem(key + "", parentKey + "", itemField + "", - crossFilteringLayer.getName()); - GWT.log("select item: " + selectableItem); + SelectableItem selectableItem = new SelectableItem( + crossFilteringLayer.getTable_key_field() + "", keyValue + "", + crossFilteringLayer.getTable_parent_key_field(), itemField + "", + crossFilteringLayer.getName(), crossFilteringLayer.getTable_geometry_name()); + GWT.log("selectableItem: " + selectableItem); String pathFeatureKey = pathFeatureKey(selectableItem); mapSelectableFeatures.put(pathFeatureKey, selectableItem); } + GWT.log("mapSelectableFeatures: " + mapSelectableFeatures); mapInnestedFeatures.put(level, mapSelectableFeatures); String placholder = placeholderLayer(layersIDV.get(0)); // Expected one fillListBoxLevel(level, mapSelectableFeatures, listBoxes, placholder); @@ -269,23 +252,39 @@ public class CrossFilteringLayerPanel extends Composite { // Code omitted for clarity } } - -// } else { -// -// String placholder = placeholderLayer(layersIDV.get(0)); // Expected one -// fillListBoxLevel(level, mapInnestedFeatures.get(level), listBoxes, placholder); -// } - } + /** + * Path feature key. + * + * @param selectableItem the selectable item + * @return the string + */ private String pathFeatureKey(SelectableItem selectableItem) { - return "root_" + selectableItem.getParentKey() + "_"+selectableItem.getKey(); + return "root_" + selectableItem.parentKeyField + "_" + selectableItem.keyField + "_" + selectableItem.keyValue; } + /** + * Placeholder layer. + * + * @param layersIDV the layers IDV + * @return the string + */ private String placeholderLayer(LayerIDV layersIDV) { - return "Select " + layersIDV.getTitle() + "..."; + String placeholder = "Select"; + if (layersIDV != null) + placeholder += " " + layersIDV.getTitle() + "..."; + + placeholder += " ..."; + return placeholder; } + /** + * Adds the list boxes level to panel. + * + * @param level the level + * @param layersIDV the layers IDV + */ private void addListBoxesLevelToPanel(int level, List layersIDV) { if (layersIDV == null) @@ -312,18 +311,35 @@ public class CrossFilteringLayerPanel extends Composite { mapInnestedListBoxes.put(level, listBoxes); } + /** + * Sets the enabled box. + * + * @param listBox the list box + * @param bool the bool + */ public void setEnabledBox(ListBox listBox, boolean bool) { listBox.setEnabled(bool); } - + + /** + * Clear list box. + * + * @param listBox the list box + * @param bool the bool + */ public void clearListBox(ListBox listBox, boolean bool) { listBox.setEnabled(bool); } - + + /** + * Reset list box level. + * + * @param level the level + */ private void resetListBoxLevel(int level) { - + List listBoxes = mapInnestedListBoxes.get(level); - if(listBoxes!=null) { + if (listBoxes != null) { for (ListBox listBox : listBoxes) { listBox.clear(); setEnabledBox(listBox, false); @@ -331,6 +347,14 @@ public class CrossFilteringLayerPanel extends Composite { } } + /** + * Fill list box level. + * + * @param level the level + * @param mapSelectableFeatures the map selectable features + * @param listBoxes the list boxes + * @param placeholder the placeholder + */ private void fillListBoxLevel(int level, HashMap mapSelectableFeatures, List listBoxes, String placeholder) { GWT.log("fillBox level: " + level + " map: " + mapSelectableFeatures); @@ -345,7 +369,7 @@ public class CrossFilteringLayerPanel extends Composite { for (String key : mapSelectableFeatures.keySet()) { SelectableItem selItem = mapSelectableFeatures.get(key); - listBox.addItem(selItem.getItemField(), key); + listBox.addItem(selItem.itemValue, key); } listBox.addChangeHandler(new ChangeHandler() { @@ -353,12 +377,44 @@ public class CrossFilteringLayerPanel extends Composite { @Override public void onChange(ChangeEvent event) { loadInnerLevel(level, listBox.getSelectedValue()); + + for (int i = level + 1; i < mapInnestedListBoxes.size(); i++) { + resetListBoxLevel(i); + } + + String key = listBox.getSelectedValue(); + SelectableItem selectableItem = mapSelectableFeatures.get(key); + buildCrossFilteringCQLAndFireEvent(selectableItem); + setFilterHighLighted(true); } + }); setEnabledBox(listBox, true); } + /** + * Builds the cross filtering CQL and fire event. + * + * @param selectableItem the selectable item + */ + private void buildCrossFilteringCQLAndFireEvent(SelectableItem selectableItem) { + String setCqlFilter = "INTERSECTS(geom,querySingle('" + selectableItem.layername + "','" + + selectableItem.theGeometryName + "','" + selectableItem.keyField + "=''" + selectableItem.keyValue + + "'''));INCLUDE"; + GWT.log("CQL FILTER built: " + setCqlFilter); + + // olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, setCqlFilter); + + applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(gCubeCollection.getIndexes().get(0), setCqlFilter)); + } + + /** + * Load inner level. + * + * @param level the level + * @param selectableItemValue the selectable item value + */ private void loadInnerLevel(int level, String selectableItemValue) { GWT.log("selected level " + level + " selectableItemValue " + selectableItemValue); HashMap mapSelectableItem = mapInnestedFeatures.get(level); @@ -368,24 +424,106 @@ public class CrossFilteringLayerPanel extends Composite { int innerLevel = level + 1; List selectedLayers = mapInnestedFiltering.get(innerLevel); - //if layer filtering exists at this level + // if layer filtering exists at this level if (selectedLayers != null) { List selectedListBoxes = mapInnestedListBoxes.get(innerLevel); GWT.log("loading inner layers " + selectedLayers); GWT.log("loading selectedListBoxes " + selectedListBoxes); - filleSelectableLevel(innerLevel, selectedItem); + fillSelectableLevel(innerLevel, selectedItem); } } -// public void resetCurrentSearch() { -// searchField.setText(""); -// resetSearch.setVisible(false); -// panelResults.clear(); -// latestResult = null; -// appManagerBus.fireEvent(new SearchPerformedEvent(profileID, null, true)); -// setSearchEnabled(false); -// } + /** + * Sets the filter high lighted. + * + * @param bool the new filter high lighted + */ + private void setFilterHighLighted(boolean bool) { + if (bool) { + filterButton.getElement().addClassName("highlight-button"); + } else { + filterButton.getElement().removeClassName("highlight-button"); + } + } + /** + * Sets the search button. + * + * @param searchFacilityButton the new search button + */ + public void setFilterButton(DropdownButton searchFacilityButton) { + this.filterButton = searchFacilityButton; + + } + + /** + * The Class SelectableItem. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 31, 2023 + */ + public class SelectableItem { + protected String keyField; + protected String keyValue; + protected String parentKeyField; + protected String itemValue; + protected String layername; + protected String theGeometryName; + + /** + * Instantiates a new selectable item. + */ + SelectableItem() { + + } + + /** + * Instantiates a new selectable item. + * + * @param keyField the key field + * @param keyValue the key value + * @param parentKeyField the parent key field + * @param itemValue the item value + * @param layername the layername + * @param theGeometryName the the geometry name + */ + public SelectableItem(String keyField, String keyValue, String parentKeyField, String itemValue, + String layername, String theGeometryName) { + super(); + this.keyField = keyField; + this.keyValue = keyValue; + this.parentKeyField = parentKeyField; + this.itemValue = itemValue; + this.layername = layername; + this.theGeometryName = theGeometryName; + } + + /** + * To string. + * + * @return the string + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("SelectableItem [keyField="); + builder.append(keyField); + builder.append(", keyValue="); + builder.append(keyValue); + builder.append(", parentKeyField="); + builder.append(parentKeyField); + builder.append(", itemValue="); + builder.append(itemValue); + builder.append(", layername="); + builder.append(layername); + builder.append(", theGeometryName="); + builder.append(theGeometryName); + builder.append("]"); + return builder.toString(); + } + + } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml index 2a5a31a..9f5d9a9 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml @@ -13,10 +13,14 @@ - - - - + + + + + + Reset + \ No newline at end of file diff --git a/src/main/webapp/GeoportalDataViewer.css b/src/main/webapp/GeoportalDataViewer.css index 749dea3..e43201d 100644 --- a/src/main/webapp/GeoportalDataViewer.css +++ b/src/main/webapp/GeoportalDataViewer.css @@ -836,7 +836,8 @@ RESPONSIVE .overlay-panel-style-description { border: none !important; white-space: pre-line; - padding: 5px 0px; + padding: 10px 0px; + font-style: italic; } .overlay-panel-style > div { @@ -855,10 +856,15 @@ RESPONSIVE max-width: 350px; } +.filter-panel-style select { + min-width: 310px; +} + .filter-panel-style-description { border: none !important; white-space: pre-line; - padding: 5px 0px; + padding: 10px 0px; + font-style: italic; } .filter-panel-style > div { @@ -869,4 +875,11 @@ RESPONSIVE margin-top: 5px; } +.filter-panel-style a { + float: right; +} + +.filter-panel-style label { + font-weight: bold; +} From dcca1afba1a5dba209be5554dd82b534a7573f4c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 31 May 2023 17:15:04 +0200 Subject: [PATCH 09/18] fixed cross filtering select --- .../client/ui/crossfiltering/CrossFilteringLayerPanel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index bcab8cf..f6c9e9c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -273,7 +273,7 @@ public class CrossFilteringLayerPanel extends Composite { private String placeholderLayer(LayerIDV layersIDV) { String placeholder = "Select"; if (layersIDV != null) - placeholder += " " + layersIDV.getTitle() + "..."; + placeholder += " " + layersIDV.getTitle(); placeholder += " ..."; return placeholder; @@ -357,7 +357,7 @@ public class CrossFilteringLayerPanel extends Composite { */ private void fillListBoxLevel(int level, HashMap mapSelectableFeatures, List listBoxes, String placeholder) { - GWT.log("fillBox level: " + level + " map: " + mapSelectableFeatures); + //GWT.log("fillBox level: " + level + " map: " + mapSelectableFeatures); if (mapSelectableFeatures == null) return; From 36bfcd2b9ee79a2bb96fc37d7817ef621d4df9ff Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 1 Jun 2023 16:26:34 +0200 Subject: [PATCH 10/18] Added WFS cross filtering results --- .../client/gis/OpenLayerMap.java | 11 +- .../CrossFilteringLayerPanel.java | 103 +++++++- .../CrossFilteringLayerPanel.ui.xml | 2 + .../client/util/WFSMakerUtil.java | 49 ++++ .../server/gis/GisMakers.java | 1 + .../server/gis/WMSUrlValidator.java | 245 +++++++----------- .../gis => shared/gis/wfs}/WFSGetFeature.java | 5 +- .../WMSUrlValidatorTest.java | 84 ++++++ 8 files changed, 330 insertions(+), 170 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/WFSMakerUtil.java rename src/main/java/org/gcube/portlets/user/geoportaldataviewer/{server/gis => shared/gis/wfs}/WFSGetFeature.java (92%) create mode 100644 src/test/java/org/gcube/portlets/user/geoportaldataviewer/WMSUrlValidatorTest.java diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java index 28c580e..8ec7179 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java @@ -8,6 +8,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerCon import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent.LAYER_TYPE; import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.SwapLayer; +import org.gcube.portlets.user.geoportaldataviewer.client.util.WFSMakerUtil; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; @@ -78,6 +79,8 @@ import ol.style.Style; */ public abstract class OpenLayerMap { + public static final String CQL_FILTER_PARAMETER = WFSMakerUtil.CQL_FILTER_PARAMETER; + private static final int MAX_LENGHT_CQL_FOR_GET_REQUEST = 1600; // 1600 characters public static final int SET_CENTER_ANIMATED_DURATION = 500; @@ -419,9 +422,7 @@ public abstract class OpenLayerMap { if (layer == null) { ImageWmsParams imageWMSParams = OLFactory.createOptions(); imageWMSParams.setLayers(layerItem.getName()); - // imageWMSParams.set("CQL_FILTER", "product_id - // IN('6165b07202ad3d60e1d26f42','6166ff8002ad3d60e1d26fb7')"); - + ImageWmsOptions imageWMSOptions = OLFactory.createOptions(); imageWMSOptions.setUrl(layerItem.getMapServerHost()); @@ -478,9 +479,9 @@ public abstract class OpenLayerMap { ImageWmsParams imageWMSParams = imageWMSSource.getParams(); if (cqlFilterExpression == null || cqlFilterExpression.length() > MAX_LENGHT_CQL_FOR_GET_REQUEST) { - imageWMSParams.delete("CQL_FILTER"); + imageWMSParams.delete(CQL_FILTER_PARAMETER); } else { - imageWMSParams.set("CQL_FILTER", cqlFilterExpression); + imageWMSParams.set(CQL_FILTER_PARAMETER, cqlFilterExpression); } imageWMSSource.updateParams(imageWMSParams); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index f6c9e9c..cd162d7 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -8,13 +8,19 @@ import java.util.List; import org.gcube.application.geoportalcommon.shared.geoportal.config.GroupedLayersDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.CrossFilteringLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDILayer; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEvent; import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil; +import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon; +import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; +import org.gcube.portlets.user.geoportaldataviewer.client.util.WFSMakerUtil; import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; +import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.CheckBox; import com.github.gwtbootstrap.client.ui.ControlGroup; @@ -23,6 +29,7 @@ import com.github.gwtbootstrap.client.ui.Controls; import com.github.gwtbootstrap.client.ui.DropdownButton; import com.github.gwtbootstrap.client.ui.Fieldset; import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ChangeEvent; @@ -39,6 +46,8 @@ import com.google.gwt.http.client.URL; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; import jsinterop.base.JsPropertyMap; @@ -61,6 +70,9 @@ public class CrossFilteringLayerPanel extends Composite { @UiField Fieldset fieldSet; + @UiField + HTMLPanel panelResults; + @UiField Button buttonReset; @@ -138,6 +150,7 @@ public class CrossFilteringLayerPanel extends Composite { @Override public void onClick(ClickEvent event) { + panelResults.clear(); for (int i = 1; i < mapInnestedListBoxes.size(); i++) { resetListBoxLevel(i); } @@ -201,7 +214,7 @@ public class CrossFilteringLayerPanel extends Composite { if (selectedItem != null) { String cqlFilterValue = crossFilteringLayer.getTable_parent_key_field() + "=" + selectedItem.keyValue; - wfsURL += "&CQL_FILTER=" + URL.encode(cqlFilterValue); + wfsURL += "&" + WFSMakerUtil.CQL_FILTER_PARAMETER + "=" + URL.encode(cqlFilterValue); } GWT.log("wfsURL request: " + wfsURL); @@ -357,7 +370,7 @@ public class CrossFilteringLayerPanel extends Composite { */ private void fillListBoxLevel(int level, HashMap mapSelectableFeatures, List listBoxes, String placeholder) { - //GWT.log("fillBox level: " + level + " map: " + mapSelectableFeatures); + // GWT.log("fillBox level: " + level + " map: " + mapSelectableFeatures); if (mapSelectableFeatures == null) return; @@ -401,12 +414,87 @@ public class CrossFilteringLayerPanel extends Composite { private void buildCrossFilteringCQLAndFireEvent(SelectableItem selectableItem) { String setCqlFilter = "INTERSECTS(geom,querySingle('" + selectableItem.layername + "','" + selectableItem.theGeometryName + "','" + selectableItem.keyField + "=''" + selectableItem.keyValue - + "'''));INCLUDE"; + + "'''))"; + // setCqlFilter = URL.encode(setCqlFilter); GWT.log("CQL FILTER built: " + setCqlFilter); - // olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, setCqlFilter); + IndexLayerDV indexLayer = gCubeCollection.getIndexes().get(0); + applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(indexLayer, setCqlFilter)); - applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(gCubeCollection.getIndexes().get(0), setCqlFilter)); + try { + GCubeSDILayer layer = indexLayer.getLayer(); + String wmsLink = layer.getOgcLinks().get("wms"); + String layerName = URLUtil.extractValueOfParameterFromURL("layers", wmsLink); + String serviceURL = URLUtil.getPathURL(wmsLink); + String toLServiceURL = serviceURL.toLowerCase(); + if (toLServiceURL.endsWith("wms")) { + toLServiceURL = toLServiceURL.substring(0, toLServiceURL.length() - 3) + "ows"; + } + String wfsCrossFilteringQuery = WFSMakerUtil.buildWFSRequest(toLServiceURL, layerName, 1000, "geom", + setCqlFilter); + GWT.log("wfsCrossFilteringQuery: " + wfsCrossFilteringQuery); + showCountResultsOfWFSCrossFiltering(wfsCrossFilteringQuery); + } catch (Exception e) { + // TODO: handle exception + } + } + + public void showCountResultsOfWFSCrossFiltering(String wfsQuery) { + + RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsQuery); + panelResults.clear(); + panelResults.add(new HTML("
")); + panelResults.add(new LoaderIcon("Filtering...")); + try { + + Request response = builder.sendRequest(null, new RequestCallback() { + public void onError(Request request, Throwable exception) { +// showLoading(false); +// Window.alert(caught.getMessage()); + panelResults.clear(); + panelResults.add(new HTML("
")); + Alert alert = new Alert("Error on returning number of centroids"); + alert.setType(AlertType.ERROR); + alert.setClose(false); + panelResults.add(alert); + } + + public void onResponseReceived(Request request, Response response) { + + Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, + response.getText()); + + if (features != null) { + int dataCount = features.length; + + panelResults.clear(); + panelResults.add(new HTML("
")); + + if (dataCount == 0) { + panelResults.add(new HTML("No result found")); + return; + } + + String message = ""; + + if (dataCount > 0) { + message = "Found " + dataCount; + message += dataCount > 1 ? " centroids" : " centroid"; + message += ". "; + } + + HTML resultMessage = new HTML(message); + resultMessage.getElement().addClassName("search_result_msg"); + + panelResults.add(resultMessage); + } + + } + }); + + } catch (RequestException e) { + panelResults.clear(); + } } /** @@ -416,11 +504,12 @@ public class CrossFilteringLayerPanel extends Composite { * @param selectableItemValue the selectable item value */ private void loadInnerLevel(int level, String selectableItemValue) { - GWT.log("selected level " + level + " selectableItemValue " + selectableItemValue); + // GWT.log("selected level " + level + " selectableItemValue " + + // selectableItemValue); HashMap mapSelectableItem = mapInnestedFeatures.get(level); SelectableItem selectedItem = mapSelectableItem.get(selectableItemValue); - GWT.log("selected selectableItem " + selectedItem); + // GWT.log("selected selectableItem " + selectedItem); int innerLevel = level + 1; List selectedLayers = mapInnestedFiltering.get(innerLevel); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml index 9f5d9a9..923d6db 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.ui.xml @@ -18,6 +18,8 @@ + + Reset diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/WFSMakerUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/WFSMakerUtil.java new file mode 100644 index 0000000..5307159 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/WFSMakerUtil.java @@ -0,0 +1,49 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.util; + +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.WFSGetFeature; + +import com.google.gwt.http.client.URL; + +public class WFSMakerUtil { + + public static final String CQL_FILTER_PARAMETER = "CQL_FILTER"; + + public static String buildWFSRequest(String webserviceURL, String layerName, int maxFeatures, String propertyName, + String cqlFilter) throws Exception { + + if (layerName == null) + throw new Exception("Bad parameter layerName is null"); + + if (webserviceURL == null) + throw new Exception("Bad parameter webserviceURL is null"); + + StringBuilder builder = new StringBuilder(); + builder.append(webserviceURL); + builder.append("?"); + builder.append(WFSGetFeature.SERVICE.getParameter() + "=" + WFSGetFeature.SERVICE.getValue()); + builder.append("&"); + builder.append(WFSGetFeature.VERSION.getParameter() + "=" + WFSGetFeature.VERSION.getValue()); + builder.append("&"); + builder.append(WFSGetFeature.REQUEST.getParameter() + "=" + WFSGetFeature.REQUEST.getValue()); + builder.append("&"); + builder.append(WFSGetFeature.OUTPUTFORMAT.getParameter() + "=" + URL.encode("application/json")); + builder.append("&"); + builder.append(WFSGetFeature.TYPENAME.getParameter() + "=" + layerName); + builder.append("&"); + + if (maxFeatures > 0) { + builder.append(WFSGetFeature.MAXFEATURES.getParameter() + "=" + maxFeatures); + builder.append("&"); + } + if (propertyName != null) { + builder.append(WFSGetFeature.PROPERTYNAME.getParameter() + "=" + propertyName); + builder.append("&"); + } + if (cqlFilter != null) { + builder.append(CQL_FILTER_PARAMETER + "=" + cqlFilter); + } + + return builder.toString(); + } + +} 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 index 7740acf..3a3c5d5 100644 --- 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 @@ -4,6 +4,7 @@ import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; import org.gcube.application.geoportalcommon.util.URLParserUtil; import org.gcube.portlets.user.geoportaldataviewer.server.gis.MapServerRecognize.SERVERTYPE; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.WFSGetFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WMSUrlValidator.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WMSUrlValidator.java index 2be8861..27b7925 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WMSUrlValidator.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WMSUrlValidator.java @@ -12,12 +12,10 @@ import org.gcube.spatial.data.geoutility.wms.WmsUrlValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * The Class GisViewerWMSUrlValidator. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Jan 28, 2016 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 28, 2016 */ public class WMSUrlValidator { @@ -35,57 +33,56 @@ public class WMSUrlValidator { private static final Logger LOG = LoggerFactory.getLogger(WMSUrlValidator.class); - /** * Instantiates a new WMS url validator. * - * @param wmsRequest the wms request + * @param wmsRequest the wms request * @param inputLayerName the input layer name * @throws Exception the exception */ - public WMSUrlValidator(String wmsRequest, String inputLayerName) throws Exception{ - LOG.debug("WMSURLValidator wmsRequest: "+wmsRequest); - LOG.debug("WMSURLValidator layerName: "+inputLayerName); - + public WMSUrlValidator(String wmsRequest, String inputLayerName) throws Exception { + LOG.debug("WMSURLValidator wmsRequest: " + wmsRequest); + LOG.debug("WMSURLValidator layerName: " + inputLayerName); - if(wmsRequest==null || wmsRequest.isEmpty()) + if (wmsRequest == null || wmsRequest.isEmpty()) throw new Exception("WMS request is null or empty"); this.wmsRequestURI = wmsRequest.trim(); boolean isOwsService = GeoWmsServiceUtility.isOWSSerice(this.wmsRequestURI); WebMapServerHost webMapServerHost; - //IS WMS? - if(GeoWmsServiceUtility.isWMSService(wmsRequestURI)){ - LOG.trace("found "+GeoWmsServiceUtility.SERVICE_WMS+" in wms request: "+wmsRequestURI); + // IS WMS? + if (GeoWmsServiceUtility.isWMSService(wmsRequestURI)) { + LOG.trace("found " + GeoWmsServiceUtility.SERVICE_WMS + " in wms request: " + wmsRequestURI); webMapServerHost = getWebMapServerHost(wmsRequestURI); - }else - throw new Exception("WMS service not found for layer: "+inputLayerName); + } else + throw new Exception("WMS service not found for layer: " + inputLayerName); - //VALIDATION WMS + // VALIDATION WMS String baseWmsService = webMapServerHost.getHost(); - //IS OWS OR WMS? - this.wmsServiceHost = appendWmsServiceToBaseUrl(wmsRequest.substring(0, wmsRequest.indexOf("?")),isOwsService); + // IS OWS OR WMS? + this.wmsServiceHost = appendWmsServiceToBaseUrl(wmsRequest.substring(0, wmsRequest.indexOf("?")), isOwsService); this.layerName = inputLayerName; try { - //VALIDATE WMS SERVICE FOR WEB MAP SERVER - if(!HttpRequestUtil.urlExists(this.wmsServiceHost, true)){ - LOG.info("baseWmsServiceUrl: "+wmsServiceHost +" is not a geoserver, setting as input base wms server: "+baseWmsService); + // VALIDATE WMS SERVICE FOR WEB MAP SERVER + if (!HttpRequestUtil.urlExists(this.wmsServiceHost, true)) { + LOG.info("baseWmsServiceUrl: " + wmsServiceHost + + " is not a geoserver, setting as input base wms server: " + baseWmsService); this.wmsServiceHost = baseWmsService; } } catch (Exception e) { - LOG.error("error on validating geoserver wms service: "+e); - LOG.info("setting baseWmsService as input base wms server: "+baseWmsService); + LOG.error("error on validating geoserver wms service: " + e); + LOG.info("setting baseWmsService as input base wms server: " + baseWmsService); this.wmsServiceHost = baseWmsService; } - //VALIDATION FOR THREDDS - FIND LAYER NAME INTO WMS PATH - if(this.layerName==null || this.layerName.isEmpty()){ + // VALIDATION FOR THREDDS - FIND LAYER NAME INTO WMS PATH + if (this.layerName == null || this.layerName.isEmpty()) { this.layerName = WmsUrlValidator.getValueOfParameter(WmsParameters.LAYERS, wmsRequest); - if(this.layerName==null || this.layerName.isEmpty()) + if (this.layerName == null || this.layerName.isEmpty()) throw new Exception("Layer name is null or empty"); } @@ -93,42 +90,42 @@ public class WMSUrlValidator { parametersValue.put(WmsParameters.LAYERS.getParameter(), this.layerName); } - /** * Append wms service to base url. * - * @param url the url + * @param url the url * @param isOwsServer the is ows server * @return the string */ - public String appendWmsServiceToBaseUrl(String url, boolean isOwsServer){ + public String appendWmsServiceToBaseUrl(String url, boolean isOwsServer) { - if(url.contains("/"+WMS) || url.contains("/"+OWS)) + if (url.contains("/" + WMS) || url.contains("/" + OWS)) return url; - if(url.lastIndexOf("/") != url.length()){ - url+="/"; + if (url.lastIndexOf("/") != url.length()) { + url += "/"; } - if(isOwsServer) - return url+=OWS; + if (isOwsServer) + return url += OWS; else - return url+=WMS; + return url += WMS; } /** - * Method: getFullWmsUrlRequest - * Create a correct wms url request - * Returns: + * Method: getFullWmsUrlRequest Create a correct wms url request Returns: * {String}. * - * @param returnEmptyParameter if true the wms url returned contains also wms parameter with empty value, none otherwise. - * and mandatory wms parameters that does not found are filled with empty values + * @param returnEmptyParameter if true the wms url returned contains also + * wms parameter with empty value, none + * otherwise. and mandatory wms parameters + * that does not found are filled with empty + * values * @param fillEmptyParameterAsDefault the fill empty parameter as default * @return a correct wms url request in formatted string like this: - * "wmsserver?key1=value1&key2=value2&key3=value3" + * "wmsserver?key1=value1&key2=value2&key3=value3" */ - public String parseWMSRequest(boolean returnEmptyParameter, boolean fillEmptyParameterAsDefault){ + public String parseWMSRequest(boolean returnEmptyParameter, boolean fillEmptyParameterAsDefault) { urlValidator = new org.gcube.spatial.data.geoutility.wms.WmsUrlValidator(wmsRequestURI); String fullWmsUrlBuilded; @@ -138,98 +135,100 @@ public class WMSUrlValidator { parametersValue.putAll(urlValidator.getMapWmsParameters()); String ln = parametersValue.get(WmsParameters.LAYERS.name()); - LOG.debug("Comparing layer name from Wms request: "+ln +", with OnLineResource layerName: "+this.layerName); - if(ln==null || ln.isEmpty() || ln.compareTo(this.layerName)!=0){ - LOG.info("Layer name into wms request is different to OnLineResource layers name, replacing layer name: "+this.layerName); + LOG.debug("Comparing layer name from Wms request: " + ln + ", with OnLineResource layerName: " + + this.layerName); + if (ln == null || ln.isEmpty() || ln.compareTo(this.layerName) != 0) { + LOG.info( + "Layer name into wms request is different to OnLineResource layers name, replacing layer name: " + + this.layerName); parametersValue.put(WmsParameters.LAYERS.getParameter(), this.layerName); - urlValidator.getMapWmsParameters().put(org.gcube.spatial.data.geoutility.bean.WmsParameters.LAYERS.getParameter(), this.layerName); - fullWmsUrlBuilded = org.gcube.spatial.data.geoutility.wms.WmsUrlValidator.setValueOfParameter(org.gcube.spatial.data.geoutility.bean.WmsParameters.LAYERS, fullWmsUrlBuilded, this.layerName, true); + urlValidator.getMapWmsParameters().put( + org.gcube.spatial.data.geoutility.bean.WmsParameters.LAYERS.getParameter(), this.layerName); + fullWmsUrlBuilded = org.gcube.spatial.data.geoutility.wms.WmsUrlValidator.setValueOfParameter( + org.gcube.spatial.data.geoutility.bean.WmsParameters.LAYERS, fullWmsUrlBuilded, this.layerName, + true); } // logger.trace("parametersValue: "+parametersValue); mapWmsNoStandardParams = new HashMap(urlValidator.getMapWmsNoStandardParams().size()); mapWmsNoStandardParams.putAll(urlValidator.getMapWmsNoStandardParams()); wmsNoStandardParameters = urlValidator.getWmsNoStandardParameters(); - } - catch (Exception e) { - LOG.error("An error occurred during wms uri build, returning uri: "+wmsRequestURI, e); + } catch (Exception e) { + LOG.error("An error occurred during wms uri build, returning uri: " + wmsRequestURI, e); fullWmsUrlBuilded = wmsRequestURI; } - LOG.trace("GisViewerWMSUrlValidator parseWMSRequest returning full wms url: "+fullWmsUrlBuilded); + LOG.trace("GisViewerWMSUrlValidator parseWMSRequest returning full wms url: " + fullWmsUrlBuilded); return fullWmsUrlBuilded; } - - /** * Gets the web map server host. * * @param wmsRequest the wms request - * @return the web map server host, (geoserver URI or the wmsRequest substring from start to index of '?' char (if exists)) + * @return the web map server host, (geoserver URI or the wmsRequest substring + * from start to index of '?' char (if exists)) */ - public WebMapServerHost getWebMapServerHost(String wmsRequest){ + public WebMapServerHost getWebMapServerHost(String wmsRequest) { WebMapServerHost webMapServerHost = new WebMapServerHost(); - if(wmsRequest==null) - return webMapServerHost; //uri is empty - + if (wmsRequest == null) + return webMapServerHost; // uri is empty int end = wmsRequest.toLowerCase().lastIndexOf("?"); - if(end==-1){ - LOG.trace("char ? not found in geoserver uri, return: "+wmsRequest); - return webMapServerHost; //uri is empty + if (end == -1) { + LOG.trace("char ? not found in geoserver uri, return: " + wmsRequest); + return webMapServerHost; // uri is empty } String webMapServerBaseURL = wmsRequest.substring(0, wmsRequest.toLowerCase().lastIndexOf("?")); int index = webMapServerBaseURL.lastIndexOf(GEOSERVER); - if(index>-1){ //FOUND the string GEOSERVER into URL - LOG.trace("found geoserver string: "+GEOSERVER+" in "+webMapServerBaseURL); + if (index > -1) { // FOUND the string GEOSERVER into URL + LOG.trace("found geoserver string: " + GEOSERVER + " in " + webMapServerBaseURL); - //THERE IS SCOPE? + // THERE IS SCOPE? int lastSlash = webMapServerBaseURL.lastIndexOf("/"); - int includeGeoserverString = index+GEOSERVER.length(); - int endUrl = lastSlash>includeGeoserverString?lastSlash:includeGeoserverString; - LOG.trace("indexs - lastSlash: ["+lastSlash+"], includeGeoserverString: ["+includeGeoserverString+"], endUrl: ["+endUrl+"]"); - int startScope = includeGeoserverString+1 includeGeoserverString ? lastSlash : includeGeoserverString; + LOG.trace("indexs - lastSlash: [" + lastSlash + "], includeGeoserverString: [" + includeGeoserverString + + "], endUrl: [" + endUrl + "]"); + int startScope = includeGeoserverString + 1 < endUrl ? includeGeoserverString + 1 : endUrl; // INCLUDE SLASH String scope = webMapServerBaseURL.substring(startScope, endUrl); - LOG.trace("geoserver url include scope: "+webMapServerBaseURL.substring(includeGeoserverString, endUrl)); + LOG.trace("geoserver url include scope: " + webMapServerBaseURL.substring(includeGeoserverString, endUrl)); webMapServerHost.setHost(webMapServerBaseURL.substring(0, endUrl)); webMapServerHost.setScope(scope); return webMapServerHost; - }else{ - LOG.trace("the string 'geoserver' not found in "+webMapServerBaseURL); + } else { + LOG.trace("the string 'geoserver' not found in " + webMapServerBaseURL); // GET LAST INDEX OF '/' AND CONCATENATE GEOSERVER - String urlConn = webMapServerBaseURL.substring(0, webMapServerBaseURL.lastIndexOf("/"))+GEOSERVER; - LOG.trace("tentative concatenating string 'geoserver' at http url "+urlConn); + String urlConn = webMapServerBaseURL.substring(0, webMapServerBaseURL.lastIndexOf("/")) + GEOSERVER; + LOG.trace("tentative concatenating string 'geoserver' at http url " + urlConn); try { - if(HttpRequestUtil.urlExists(urlConn, false)){ - LOG.trace("url: "+urlConn+" - open a connection, return "+urlConn); + if (HttpRequestUtil.urlExists(urlConn, false)) { + LOG.trace("url: " + urlConn + " - open a connection, return " + urlConn); webMapServerHost.setHost(urlConn); return webMapServerHost; - } - else - LOG.trace("url: "+urlConn+" - not open a connection"); + } else + LOG.trace("url: " + urlConn + " - not open a connection"); } catch (Exception e) { - LOG.error("url connection is wrong at :"+urlConn); + LOG.error("url connection is wrong at :" + urlConn); } String uriWithoutParameters = wmsRequest.substring(0, end); - LOG.trace("url connection, returned: "+uriWithoutParameters); + LOG.trace("url connection, returned: " + uriWithoutParameters); webMapServerHost.setHost(uriWithoutParameters); return webMapServerHost; } } - /** * Gets the wms service host. * @@ -260,42 +259,40 @@ public class WMSUrlValidator { return wmsNoStandardParameters; } - /** * Gets the value of parsed wms parameter. * * @param parameter the parameter * @return the value of parsed wms parameter parsed from wms request. */ - public String getValueOfParsedWMSParameter(WmsParameters parameter){ + public String getValueOfParsedWMSParameter(WmsParameters parameter) { return parametersValue.get(parameter.getParameter()); } - /** * Gets the value of parameter. * - * @param wmsParam the wms param + * @param wmsParam the wms param * @param wmsUrlParameters the wms url parameters * @return the value of parameter */ - public static String getValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters){ + public static String getValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters) { return WmsUrlValidator.getValueOfParameter(wmsParam, wmsUrlParameters); } - /** * Sets the value of parameter. * - * @param wmsParam the wms param + * @param wmsParam the wms param * @param wmsUrlParameters the wms url parameters - * @param newValue the new value - * @param addIfNotExists the add if not exists + * @param newValue the new value + * @param addIfNotExists the add if not exists * @return the string */ - public static String setValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters, String newValue, boolean addIfNotExists){ + public static String setValueOfParameter(WmsParameters wmsParam, String wmsUrlParameters, String newValue, + boolean addIfNotExists) { return WmsUrlValidator.setValueOfParameter(wmsParam, wmsUrlParameters, newValue, addIfNotExists); } @@ -309,8 +306,6 @@ public class WMSUrlValidator { return layerName; } - - /** * Gets the styles as list. * @@ -321,18 +316,17 @@ public class WMSUrlValidator { List listStyles = new ArrayList(); String styles = getValueOfParsedWMSParameter(WmsParameters.STYLES); - if(styles!=null && !styles.isEmpty()){ + if (styles != null && !styles.isEmpty()) { String[] arrayStyle = styles.split(","); for (String style : arrayStyle) { - if(style!=null && !style.isEmpty()) + if (style != null && !style.isEmpty()) listStyles.add(style); } } return listStyles; } - /** * Gets the map wms no standard params. * @@ -342,63 +336,4 @@ public class WMSUrlValidator { return mapWmsNoStandardParams; } - /** - * The main method. - * - * @param args the arguments - */ - public static void main(String[] args) { - -// String baseGeoserverUrl = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows"; -// String baseGeoserverUrl = "http://www.fao.org/figis/geoserver/species"; -// String fullPath = "http://www.fao.org/figis/geoserver/species?SERVICE=WMS&BBOX=-176.0,-90.0,180.0,90&styles=Species_prob, puppa&layers=layerName&FORMAT=image/gif"; -// String fullPath = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows?service=wms&version=1.1.0&request=GetMap&layers==IGG:area_temp_1000&width=676&height=330&srs=EPSG:4326&crs=EPSG:4326&format=application/openlayers&bbox=-85.5,-180.0,90.0,180.0"; -// String baseGeoserverUrl = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc"; -// String fullPath = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&bbox=-85.0,-180.0,85.0,180.0&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto"; -// WmsUrlValidator validator = new WmsUrlValidator(baseGeoserverUrl, fullPath , "", false); -// logger.trace("base wms service url: "+validator.getBaseWmsServiceUrl()); -// logger.trace("layer name: "+validator.getLayerName()); -// logger.trace("full wms url: "+validator.getFullWmsUrlRequest(false, true)); -// logger.trace("style: "+validator.getStyles()); -// logger.trace("not standard parameter: "+validator.getWmsNotStandardParameters()); -// String[] arrayStyle = validator.getStyles().split(","); -// -// if(arrayStyle!=null && arrayStyle.length>0){ -// -// for (String style : arrayStyle) { -// if(style!=null && !style.isEmpty()) -// -// System.out.println("Style: "+style.trim()); -// } -// } -// -// String fullPath = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&bbox=-85.0,-180.0,85.0,180.0&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto"; -// -// WmsGeoExplorerUrlValidator validator = new WmsGeoExplorerUrlValidator("http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc", fullPath , "", false); -// validator.getFullWmsUrlRequest(false,true); -// -// System.out.println(validator.getWmsNoStandardParameters()); -// System.out.println(validator.getMapWmsNoStandardParams()); - -// fullPath = WmsUrlValidator.setValueOfParameter(WmsParameters.STYLES, fullPath, "123", true); -// - -// MapPreviewGenerator map = new MapPreviewGenerator(); -// fullPath = map.buildWmsRequestMapPreview(fullPath, "-85.0,-180.0,85.0,180.0"); -// System.out.println(fullPath); - - String wmsRequest = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver/wms?CRS=EPSG:4326&BBOX=-85.5,-180.0,90.0,180.0&VERSION=1.1.0&FORMAT=application/openlayers&SERVICE=wms&HEIGHT=330&LAYERS=aquamaps:lsoleasolea20130716162322254cest&REQUEST=GetMap&STYLES=Species_prob&SRS=EPSG:4326&WIDTH=676"; -// String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0"; - WmsUrlValidator wms; - try { - wms = new WmsUrlValidator(wmsRequest); - System.out.println("Returned wms: "+wms.toString()); - } - catch (Exception e) { - e.printStackTrace(); - } - - - } - } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WFSGetFeature.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/wfs/WFSGetFeature.java similarity index 92% rename from src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WFSGetFeature.java rename to src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/wfs/WFSGetFeature.java index 079b716..5ce76b1 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/gis/WFSGetFeature.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/wfs/WFSGetFeature.java @@ -1,6 +1,4 @@ -package org.gcube.portlets.user.geoportaldataviewer.server.gis; - - +package org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs; /** * The Enum WfsParameters. @@ -20,6 +18,7 @@ public enum WFSGetFeature { WIDTH("WIDTH","676"), HEIGHT("HEIGHT","230"), SRSNAME("srsName","EPSG:4326"), + PROPERTYNAME("propertyName", ""), // CRS("CRS","EPSG:4326"), //WMS 1.3.0 COMPLIANT OUTPUTFORMAT("OUTPUTFORMAT","json"), MAXFEATURES("MAXFEATURES",""); diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataviewer/WMSUrlValidatorTest.java b/src/test/java/org/gcube/portlets/user/geoportaldataviewer/WMSUrlValidatorTest.java new file mode 100644 index 0000000..fc1f55c --- /dev/null +++ b/src/test/java/org/gcube/portlets/user/geoportaldataviewer/WMSUrlValidatorTest.java @@ -0,0 +1,84 @@ +package org.gcube.portlets.user.geoportaldataviewer; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.spatial.data.geoutility.GeoWmsServiceUtility; +import org.gcube.spatial.data.geoutility.bean.WmsParameters; +import org.gcube.spatial.data.geoutility.util.HttpRequestUtil; +import org.gcube.spatial.data.geoutility.wms.WmsUrlValidator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * The Class WMSUrlValidatorTest. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 1, 2023 + */ +public class WMSUrlValidatorTest { + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + +// String baseGeoserverUrl = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows"; +// String baseGeoserverUrl = "http://www.fao.org/figis/geoserver/species"; +// String fullPath = "http://www.fao.org/figis/geoserver/species?SERVICE=WMS&BBOX=-176.0,-90.0,180.0,90&styles=Species_prob, puppa&layers=layerName&FORMAT=image/gif"; +// String fullPath = "http://repoigg.services.iit.cnr.it:8080/geoserver/IGG/ows?service=wms&version=1.1.0&request=GetMap&layers==IGG:area_temp_1000&width=676&height=330&srs=EPSG:4326&crs=EPSG:4326&format=application/openlayers&bbox=-85.5,-180.0,90.0,180.0"; +// String baseGeoserverUrl = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc"; +// String fullPath = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&bbox=-85.0,-180.0,85.0,180.0&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto"; +// WmsUrlValidator validator = new WmsUrlValidator(baseGeoserverUrl, fullPath , "", false); +// logger.trace("base wms service url: "+validator.getBaseWmsServiceUrl()); +// logger.trace("layer name: "+validator.getLayerName()); +// logger.trace("full wms url: "+validator.getFullWmsUrlRequest(false, true)); +// logger.trace("style: "+validator.getStyles()); +// logger.trace("not standard parameter: "+validator.getWmsNotStandardParameters()); +// String[] arrayStyle = validator.getStyles().split(","); +// +// if(arrayStyle!=null && arrayStyle.length>0){ +// +// for (String style : arrayStyle) { +// if(style!=null && !style.isEmpty()) +// +// System.out.println("Style: "+style.trim()); +// } +// } +// +// String fullPath = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&bbox=-85.0,-180.0,85.0,180.0&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto"; +// +// WmsGeoExplorerUrlValidator validator = new WmsGeoExplorerUrlValidator("http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc", fullPath , "", false); +// validator.getFullWmsUrlRequest(false,true); +// +// System.out.println(validator.getWmsNoStandardParameters()); +// System.out.println(validator.getMapWmsNoStandardParams()); + +// fullPath = WmsUrlValidator.setValueOfParameter(WmsParameters.STYLES, fullPath, "123", true); +// + +// MapPreviewGenerator map = new MapPreviewGenerator(); +// fullPath = map.buildWmsRequestMapPreview(fullPath, "-85.0,-180.0,85.0,180.0"); +// System.out.println(fullPath); + + String wmsRequest = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geoserver/wms?CRS=EPSG:4326&BBOX=-85.5,-180.0,90.0,180.0&VERSION=1.1.0&FORMAT=application/openlayers&SERVICE=wms&HEIGHT=330&LAYERS=aquamaps:lsoleasolea20130716162322254cest&REQUEST=GetMap&STYLES=Species_prob&SRS=EPSG:4326&WIDTH=676"; +// String wmsRequest = "http://thredds-d-d4s.d4science.org/thredds/wms/public/netcdf/test20.nc?service=wms&version=1.3.0&request=GetMap&layers=analyzed_field&styles=&width=640&height=480&srs=EPSG:4326&CRS=EPSG:4326&format=image/png&COLORSCALERANGE=auto&bbox=-85.0,-180.0,85.0,180.0"; + WmsUrlValidator wms; + try { + wms = new WmsUrlValidator(wmsRequest); + System.out.println("Returned wms: "+wms.toString()); + } + catch (Exception e) { + e.printStackTrace(); + } + + + } + +} From a28d2433a019e0d01c8c83bfe72549117dae0acb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 5 Jun 2023 16:54:40 +0200 Subject: [PATCH 11/18] Passing WFS requests from the servlet due to CORS issue, see #25074?#note-7 --- .settings/org.eclipse.wst.common.component | 32 ++-- .../client/GeoportalDataViewerService.java | 8 + .../GeoportalDataViewerServiceAsync.java | 2 + .../CrossFilteringLayerPanel.java | 163 ++++++++---------- .../client/ui/util/OLGeoJSONUtil.java | 30 ++-- .../client/util/URLUtil.java | 2 +- .../GeoportalDataViewerServiceImpl.java | 57 ++---- .../server/util/HTTPRequestUtil.java | 69 ++++++++ .../server/util/URLParserUtil.java | 2 +- 9 files changed, 214 insertions(+), 151 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/HTTPRequestUtil.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 9a321a3..5714c34 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -83,7 +84,8 @@ - + + @@ -167,7 +169,8 @@ - + + @@ -251,7 +254,8 @@ - + + @@ -335,7 +339,8 @@ - + + @@ -419,7 +424,8 @@ - + + @@ -503,10 +509,11 @@ - + uses - + + @@ -590,7 +597,8 @@ - + + @@ -674,7 +682,8 @@ - + + @@ -758,7 +767,8 @@ - + + 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 9b9840b..3c9d549 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 @@ -219,4 +219,12 @@ public interface GeoportalDataViewerService extends RemoteService { Map>> getAvaiableCustomGroupedLayersForUCD( GEOPORTAL_DATA_HANDLER theHandler); + /** + * Gets the HTTP response for URL. + * + * @param url the url + * @return the HTTP response for URL + */ + String getHTTPResponseForURL(String url); + } 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 ada1daf..a9b335b 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 @@ -89,4 +89,6 @@ public interface GeoportalDataViewerServiceAsync { void getAvaiableCustomGroupedLayersForUCD(GEOPORTAL_DATA_HANDLER theHandler, AsyncCallback>>> callback); + void getHTTPResponseForURL(String url, AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index cd162d7..c93fbd1 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -11,6 +11,7 @@ import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.Laye import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDILayer; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; +import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync; import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEvent; import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil; import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon; @@ -37,14 +38,10 @@ import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; import com.google.gwt.http.client.URL; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTMLPanel; @@ -64,9 +61,6 @@ public class CrossFilteringLayerPanel extends Composite { public static String COLORSCALERANGE = "COLORSCALERANGE"; - // @UiField - // WellForm panelContainer; - @UiField Fieldset fieldSet; @@ -218,52 +212,55 @@ public class CrossFilteringLayerPanel extends Composite { } GWT.log("wfsURL request: " + wfsURL); - RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsURL); - try { + GeoportalDataViewerServiceAsync.Util.getInstance().getHTTPResponseForURL(wfsURL, + new AsyncCallback() { - Request response = builder.sendRequest(null, new RequestCallback() { - public void onError(Request request, Throwable exception) { - // Code omitted for clarity - } + @Override + public void onSuccess(String response) { + GWT.log("wfsURL response: " + response); + Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, response); - public void onResponseReceived(Request request, Response response) { - GWT.log("wfsURL response: " + response.getText()); - Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, - response.getText()); + for (Feature feature : features) { + JsPropertyMap properties = feature.getProperties(); + Object keyValue = properties.get(crossFilteringLayer.getTable_key_field()); + Object itemField = properties.get(crossFilteringLayer.getTable_show_field()); - for (Feature feature : features) { - JsPropertyMap properties = feature.getProperties(); - Object keyValue = properties.get(crossFilteringLayer.getTable_key_field()); - Object itemField = properties.get(crossFilteringLayer.getTable_show_field()); + Object parentKey = null; + if (crossFilteringLayer.getTable_parent_key_field() != null + && !crossFilteringLayer.getTable_parent_key_field().isEmpty()) + parentKey = properties.get(crossFilteringLayer.getTable_parent_key_field()); - Object parentKey = null; - if (crossFilteringLayer.getTable_parent_key_field() != null - && !crossFilteringLayer.getTable_parent_key_field().isEmpty()) - parentKey = properties.get(crossFilteringLayer.getTable_parent_key_field()); + parentKey = parentKey == null ? "" : parentKey; - parentKey = parentKey == null ? "" : parentKey; + SelectableItem selectableItem = new SelectableItem( + crossFilteringLayer.getTable_key_field() + "", keyValue + "", + crossFilteringLayer.getTable_parent_key_field(), itemField + "", + crossFilteringLayer.getName(), crossFilteringLayer.getTable_geometry_name()); + GWT.log("selectableItem: " + selectableItem); - SelectableItem selectableItem = new SelectableItem( - crossFilteringLayer.getTable_key_field() + "", keyValue + "", - crossFilteringLayer.getTable_parent_key_field(), itemField + "", - crossFilteringLayer.getName(), crossFilteringLayer.getTable_geometry_name()); - GWT.log("selectableItem: " + selectableItem); + String pathFeatureKey = pathFeatureKey(selectableItem); + mapSelectableFeatures.put(pathFeatureKey, selectableItem); - String pathFeatureKey = pathFeatureKey(selectableItem); - mapSelectableFeatures.put(pathFeatureKey, selectableItem); + } + GWT.log("mapSelectableFeatures: " + mapSelectableFeatures); + mapInnestedFeatures.put(level, mapSelectableFeatures); + String placholder = placeholderLayer(layersIDV.get(0)); // Expected one + fillListBoxLevel(level, mapSelectableFeatures, listBoxes, placholder); } - GWT.log("mapSelectableFeatures: " + mapSelectableFeatures); - mapInnestedFeatures.put(level, mapSelectableFeatures); - String placholder = placeholderLayer(layersIDV.get(0)); // Expected one - fillListBoxLevel(level, mapSelectableFeatures, listBoxes, placholder); - } - }); - } catch (RequestException e) { - // Code omitted for clarity - } + @Override + public void onFailure(Throwable caught) { + panelResults.clear(); + HTML error = new HTML( + "Sorry, an issue is occurred on loading data for cross-filtering facility. Error is: " + + caught.getMessage()); + panelResults.add(error); + + } + }); + } } @@ -419,7 +416,6 @@ public class CrossFilteringLayerPanel extends Composite { GWT.log("CQL FILTER built: " + setCqlFilter); IndexLayerDV indexLayer = gCubeCollection.getIndexes().get(0); - applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(indexLayer, setCqlFilter)); try { GCubeSDILayer layer = indexLayer.getLayer(); @@ -437,64 +433,57 @@ public class CrossFilteringLayerPanel extends Composite { } catch (Exception e) { // TODO: handle exception } + + applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(indexLayer, setCqlFilter)); } public void showCountResultsOfWFSCrossFiltering(String wfsQuery) { - RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsQuery); panelResults.clear(); panelResults.add(new HTML("
")); - panelResults.add(new LoaderIcon("Filtering...")); - try { + panelResults.add(new LoaderIcon("Applying spatial filter...")); + + GeoportalDataViewerServiceAsync.Util.getInstance().getHTTPResponseForURL(wfsQuery, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + panelResults.clear(); + panelResults.add(new HTML("
")); + Alert alert = new Alert("Error on returning number of items"); + alert.setType(AlertType.ERROR); + alert.setClose(false); + panelResults.add(alert); + + } + + @Override + public void onSuccess(String response) { + Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, response); + + if (features != null) { + int dataCount = features.length; - Request response = builder.sendRequest(null, new RequestCallback() { - public void onError(Request request, Throwable exception) { -// showLoading(false); -// Window.alert(caught.getMessage()); panelResults.clear(); panelResults.add(new HTML("
")); - Alert alert = new Alert("Error on returning number of centroids"); - alert.setType(AlertType.ERROR); - alert.setClose(false); - panelResults.add(alert); - } - public void onResponseReceived(Request request, Response response) { + String message = ""; - Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, - response.getText()); + if (dataCount <= 0) { + message = "No item found"; + } else { - if (features != null) { - int dataCount = features.length; - - panelResults.clear(); - panelResults.add(new HTML("
")); - - if (dataCount == 0) { - panelResults.add(new HTML("No result found")); - return; - } - - String message = ""; - - if (dataCount > 0) { - message = "Found " + dataCount; - message += dataCount > 1 ? " centroids" : " centroid"; - message += ". "; - } - - HTML resultMessage = new HTML(message); - resultMessage.getElement().addClassName("search_result_msg"); - - panelResults.add(resultMessage); + message = "Found " + dataCount; + message += dataCount > 1 ? " items" : " item"; + message += ". "; } - + HTML resultMessage = new HTML(); + resultMessage.getElement().addClassName("search_result_msg"); + resultMessage.setHTML(message); + panelResults.add(resultMessage); } - }); - } catch (RequestException e) { - panelResults.clear(); - } + } + }); } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java index 80e2aa2..4d1a038 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/util/OLGeoJSONUtil.java @@ -15,7 +15,7 @@ import ol.proj.ProjectionOptions; * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * May 25, 2023 + * May 25, 2023 */ public class OLGeoJSONUtil { @@ -23,27 +23,31 @@ public class OLGeoJSONUtil { * Builds the geo JSON. * * @param projection the projection - * @param geoJSONString the geo JSON string * @return the geo json */ public static GeoJson buildGeoJSON(MAP_PROJECTION projection) { - GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions(); - ProjectionOptions projectionOptions = new ProjectionOptions(); - projectionOptions.setCode(projection.getName()); - Projection fp = new Projection(projectionOptions); - fo.setFeatureProjection(fp); - fo.setDataProjection(fp); - GeoJsonOptions geoJsonOpt = new GeoJsonOptions(); - geoJsonOpt.setDefaultDataProjection(fp); - geoJsonOpt.setFeatureProjection(fp); - return OLFactory.createGeoJSON(geoJsonOpt); + try { + GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions(); + ProjectionOptions projectionOptions = new ProjectionOptions(); + projectionOptions.setCode(projection.getName()); + Projection fp = new Projection(projectionOptions); + fo.setFeatureProjection(fp); + fo.setDataProjection(fp); + GeoJsonOptions geoJsonOpt = new GeoJsonOptions(); + geoJsonOpt.setDefaultDataProjection(fp); + geoJsonOpt.setFeatureProjection(fp); + return OLFactory.createGeoJSON(geoJsonOpt); + } catch (Exception e) { + // silent + return OLFactory.createGeoJSON(); + } } /** * Read geo json features. * - * @param projection the projection + * @param projection the projection * @param geoJSONString the geo JSON string * @return the feature[] */ 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 c245173..cdc727c 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,7 +1,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client.util; /** - * The Class URLUtil. + * The Class HTTPRequestUtil. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * 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 ee64f81..ae212eb 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 @@ -3,10 +3,6 @@ package org.gcube.portlets.user.geoportaldataviewer.server; import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects; import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -79,6 +75,7 @@ import org.gcube.portlets.user.geoportaldataviewer.server.gis.GisMakers; import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator; import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy; import org.gcube.portlets.user.geoportaldataviewer.server.util.ContextRequest; +import org.gcube.portlets.user.geoportaldataviewer.server.util.HTTPRequestUtil; import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil; import org.gcube.portlets.user.geoportaldataviewer.server.util.TemporalComparatorUtil; import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection; @@ -608,7 +605,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme LOG.debug("listGroupedCustomLayers for type '{}' are: {}", configurationType, listGroupedCustomLayers); mapProfileIDCustomGroupedLayers.put(profileId, listGroupedCustomLayers); } else { - LOG.info("No handler '{}' found into UCD {}, continue...",theHandler, u.getId()); + LOG.info("No handler '{}' found into UCD {}, continue...", theHandler, u.getId()); mapProfileIDCustomGroupedLayers.put(profileId, null); } } @@ -1825,6 +1822,22 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return url; } + /** + * Gets the HTTP response for URL. + * + * @param url the url + * @return the HTTP response for URL + */ + @Override + public String getHTTPResponseForURL(String url) { + LOG.info("getHTTPResponseForURL called"); + + if (LOG.isDebugEnabled()) { + LOG.debug("getHTTPResponseForURL for URL {} ", url); + } + return HTTPRequestUtil.getResponse(url); + } + /** * Gets the WFS response. * @@ -1846,39 +1859,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } String url = getWFSRequest(layerItem, mapSrsName, mapBBOX, maxFeatures, outputFormat); - StringBuffer response = new StringBuffer(); - String theResponseString = ""; - HttpURLConnection con = null; - LOG.debug("Built URL: " + url); - try { - URL obj = new URL(url); - con = (HttpURLConnection) obj.openConnection(); - con.setRequestMethod("GET"); - int responseCode = con.getResponseCode(); - LOG.debug("GET Response Code: " + responseCode); - if (responseCode == HttpURLConnection.HTTP_OK) { // success - BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); - String inputLine; - while ((inputLine = in.readLine()) != null) { - response.append(inputLine); - } - in.close(); - } else { - LOG.info("GET request did not work."); - } - - theResponseString = response.toString(); - // LOG.trace(theResponseString); - - if (LOG.isDebugEnabled()) { - LOG.debug("getWFSResponse is empty? " + theResponseString.isEmpty()); - } - } catch (Exception e) { - LOG.error("Error on performing the request to URL: " + url, e); - } finally { - - } - return theResponseString; + return HTTPRequestUtil.getResponse(url); } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/HTTPRequestUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/HTTPRequestUtil.java new file mode 100644 index 0000000..b601f8f --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/HTTPRequestUtil.java @@ -0,0 +1,69 @@ +package org.gcube.portlets.user.geoportaldataviewer.server.util; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.gcube.portlets.user.geoportaldataviewer.server.GeoportalDataViewerServiceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class HTTPRequestUtil. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 5, 2023 + */ +public class HTTPRequestUtil { + + private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerServiceImpl.class); + + /** + * Gets the response. + * + * @param url the url + * @return the response + */ + public static String getResponse(String url) { + if (url == null || url.isEmpty()) + return null; + + StringBuffer response = new StringBuffer(); + String theResponseString = ""; + HttpURLConnection con = null; + LOG.debug("Calling URL: " + url); + try { + URL obj = new URL(url); + con = (HttpURLConnection) obj.openConnection(); + con.setRequestMethod("GET"); + int responseCode = con.getResponseCode(); + LOG.debug("GET Response Code: " + responseCode); + if (responseCode == HttpURLConnection.HTTP_OK) { // success + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + } else { + LOG.info("GET request did not work."); + } + + theResponseString = response.toString(); + // LOG.trace(theResponseString); + + if (LOG.isDebugEnabled()) { + LOG.debug("getResponse is empty? " + theResponseString.isEmpty()); + } + } catch (Exception e) { + LOG.error("Error on performing the request to URL: " + url, e); + } finally { + + } + LOG.debug("returning response with size: " + theResponseString.length()); + return theResponseString; + } + +} 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 index 01c8e62..58589cb 100644 --- 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 @@ -9,7 +9,7 @@ import java.util.List; import java.util.Map; /** - * The Class URLUtil. + * The Class URLParserUtil. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * From e73c3a0202a4e64c02455e74f04895a3a2511b4c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 6 Jun 2023 11:49:31 +0200 Subject: [PATCH 12/18] Improved CQL filtering. Now is working in combination with SEARCH and CROSS_Filtering --- .../client/GeoportalDataViewer.java | 40 ++++++++------ .../client/LayerManager.java | 2 - ...nt.java => ApplyCQLToLayerOnMapEvent.java} | 12 ++-- ... => ApplyCQLToLayerOnMapEventHandler.java} | 6 +- .../client/gis/OpenLayerMap.java | 55 ++++++++++++++----- .../client/ui/GeonaDataViewMainPanel.ui.xml | 8 +-- .../CrossFilteringLayerPanel.java | 6 +- .../shared/gis/LayerItem.java | 30 ++-------- src/main/webapp/GeoportalDataViewer.css | 8 ++- 9 files changed, 89 insertions(+), 78 deletions(-) rename src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/{ApplyCQLToLayerMapEvent.java => ApplyCQLToLayerOnMapEvent.java} (72%) rename src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/{ApplyCQLToLayerMapEventHandler.java => ApplyCQLToLayerOnMapEventHandler.java} (63%) 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 4b3bb32..ba0a812 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 @@ -25,8 +25,8 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.AddLayerToMapEv import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent.LAYER_TYPE; import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEventHandler; -import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEvent; -import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEventHandler; +import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerOnMapEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerOnMapEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.ChangeMapLayerEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.ChangeMapLayerEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEvent; @@ -59,6 +59,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.Ope import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped; import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils; import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap; +import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap.CQL_FACILITY_ORIGIN; import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAImages; import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel; import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation.TimelineManagerStatus; @@ -848,7 +849,7 @@ public class GeoportalDataViewer implements EntryPoint { // TODO: handle exception } - String setCqlFilter = null; // default + String newCqlFilter = null; // default // setCqlFilter = "INTERSECTS(geom,querySingle('limiti_amministrativi:regioni','the_geom','DEN_REG=''Calabria'''));INCLUDE"; // GWT.log("HARD-CODED CQL FILTER: "+setCqlFilter); @@ -864,32 +865,34 @@ public class GeoportalDataViewer implements EntryPoint { cqlFilter += "'" + projectId + "',"; } cqlFilter = cqlFilter.substring(0, cqlFilter.length() - 1) + ")"; - setCqlFilter = cqlFilter; - olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, setCqlFilter); + newCqlFilter = olMapMng.getOLMap().setCQLFilterToWMSLayer(CQL_FACILITY_ORIGIN.SEARCH, layerName, + cqlFilter); } else { - olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, null); - setCqlFilter = null; // is already null + newCqlFilter = olMapMng.getOLMap().setCQLFilterToWMSLayer(CQL_FACILITY_ORIGIN.SEARCH, layerName, + null); } if (searchPerformedEvent.isSearchReset()) { - olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, null); - setCqlFilter = null; // is already null + newCqlFilter = olMapMng.getOLMap().setCQLFilterToWMSLayer(CQL_FACILITY_ORIGIN.SEARCH, layerName, + null); } + + GWT.log("New CQL Filter is: "+newCqlFilter); if (layerName != null) - layerManager.setCQLForLayerToIndexLayer(layerName, setCqlFilter); + layerManager.setCQLForLayerToIndexLayer(layerName, newCqlFilter); } } }); - applicationBus.addHandler(ApplyCQLToLayerMapEvent.TYPE, new ApplyCQLToLayerMapEventHandler() { + applicationBus.addHandler(ApplyCQLToLayerOnMapEvent.TYPE, new ApplyCQLToLayerOnMapEventHandler() { @Override - public void onApplyCQL(ApplyCQLToLayerMapEvent applyCQLToLayerMapEvent) { + public void onApplyCQL(ApplyCQLToLayerOnMapEvent applyCQLToLayerMapEvent) { GWT.log("Fired: " + applyCQLToLayerMapEvent); if (applyCQLToLayerMapEvent != null) { @@ -904,21 +907,22 @@ public class GeoportalDataViewer implements EntryPoint { } catch (Exception e) { // TODO: handle exception } - + String setCqlFilter = null; - + if (layerName != null) { - GWT.log("ApplyCQLToLayerMapEvent: " + layerName + ", filter : " + GWT.log("ApplyCQLToLayerOnMapEvent: " + layerName + ", filter : " + applyCQLToLayerMapEvent.getCqlFilterValue()); - if (applyCQLToLayerMapEvent.getCqlFilterValue() == null) { - olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, null); + olMapMng.getOLMap().setCQLFilterToWMSLayer(CQL_FACILITY_ORIGIN.CROSS_FILTERING, layerName, + null); setCqlFilter = null; // is already null } else { setCqlFilter = applyCQLToLayerMapEvent.getCqlFilterValue(); - olMapMng.getOLMap().setCQLFilterToWMSLayer(layerName, setCqlFilter); + olMapMng.getOLMap().setCQLFilterToWMSLayer(CQL_FACILITY_ORIGIN.CROSS_FILTERING, layerName, + setCqlFilter); } layerManager.setCQLForLayerToIndexLayer(layerName, setCqlFilter); 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 458fa56..ef77a8a 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 @@ -582,9 +582,7 @@ public class LayerManager { public void setCQLForLayerToIndexLayer(String layerName, String cqlFilter) { LayerObject theLo = mapIndexLayerObjects.get(layerName); if (theLo != null) { - boolean isCQLFilter = cqlFilter != null; theLo.getLayerItem().setCqlFilter(cqlFilter); - theLo.getLayerItem().setCqlFilterAvailable(isCQLFilter); } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerOnMapEvent.java similarity index 72% rename from src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEvent.java rename to src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerOnMapEvent.java index 0b38f07..fdd2c97 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerMapEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ApplyCQLToLayerOnMapEvent.java @@ -11,8 +11,8 @@ import com.google.gwt.event.shared.GwtEvent; * * Nov 18, 2020 */ -public class ApplyCQLToLayerMapEvent extends GwtEvent { - public static Type TYPE = new Type(); +public class ApplyCQLToLayerOnMapEvent extends GwtEvent { + public static Type TYPE = new Type(); private IndexLayerDV theIndeLayer; private String cqlFilterValue; @@ -22,7 +22,7 @@ public class ApplyCQLToLayerMapEvent extends GwtEvent getAssociatedType() { + public Type getAssociatedType() { return TYPE; } @@ -43,7 +43,7 @@ public class ApplyCQLToLayerMapEvent extends GwtEvent MAX_LENGHT_CQL_FOR_GET_REQUEST) { - imageWMSParams.delete(CQL_FILTER_PARAMETER); - } else { - imageWMSParams.set(CQL_FILTER_PARAMETER, cqlFilterExpression); + // Setting new CQL filter for Origin + cqlFilterMap.put(origin, newCQLFilterExpression); + + String setCQLFilter = ""; + + // Building new CQL filter + for (CQL_FACILITY_ORIGIN originKey : cqlFilterMap.keySet()) { + + String originCQLFilter = cqlFilterMap.get(originKey); + if (originCQLFilter != null) { + if (setCQLFilter.isEmpty()) { + setCQLFilter = originCQLFilter; + } else { + setCQLFilter += " AND " + originCQLFilter; + } + } } + if (setCQLFilter.isEmpty()) + imageWMSParams.delete(CQL_FILTER_PARAMETER); + else + imageWMSParams.set(CQL_FILTER_PARAMETER, setCQLFilter); + imageWMSSource.updateParams(imageWMSParams); wmsLayer.setSource(imageWMSSource); wmsLayer.changed(); + + GWT.log("returning " + CQL_FILTER_PARAMETER + ": " + setCQLFilter); + return setCQLFilter; } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml index 2a7d6e9..d18b74d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml @@ -56,17 +56,17 @@ + title="Select the base Map" text="Map" ui:field="linkMap" icon="GLOBE"> + title="Add overlay layers.." text="Overlay" ui:field="linkCustomOverlayLayers" icon="REORDER"> + title="Apply spatial filtering.." text="Filter" ui:field="linkCrossFilteringLayers" icon="FILTER"> @@ -85,7 +85,7 @@ + ui:field="linkPresetLocation" addStyleNames="preset-location"> diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index c93fbd1..db86a25 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -12,7 +12,7 @@ import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GC import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync; -import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerOnMapEvent; import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil; import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon; import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; @@ -152,7 +152,7 @@ public class CrossFilteringLayerPanel extends Composite { List listBox = mapInnestedListBoxes.get(0); listBox.get(0).setSelectedIndex(0); // Resetting CQL filtering - applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(gCubeCollection.getIndexes().get(0), null)); + applicationBus.fireEvent(new ApplyCQLToLayerOnMapEvent(gCubeCollection.getIndexes().get(0), null)); setFilterHighLighted(false); } }); @@ -434,7 +434,7 @@ public class CrossFilteringLayerPanel extends Composite { // TODO: handle exception } - applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(indexLayer, setCqlFilter)); + applicationBus.fireEvent(new ApplyCQLToLayerOnMapEvent(indexLayer, setCqlFilter)); } public void showCountResultsOfWFSCrossFiltering(String wfsQuery) { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerItem.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerItem.java index 10c3f9c..37c2e1d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerItem.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerItem.java @@ -23,7 +23,6 @@ import com.google.gwt.core.client.GWT; */ public class LayerItem implements Serializable, Cloneable { - /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1664082688635256899L; @@ -102,9 +101,6 @@ public class LayerItem implements Serializable, Cloneable { /** The server wms request. */ public String wmsLink; - /** The cql filter available. */ - private boolean cqlFilterAvailable = false; - /** The uuid. */ private String UUID; @@ -722,7 +718,7 @@ public class LayerItem implements Serializable, Cloneable { public String getCqlFilter() { return cqlFilter; } - + /** * Sets the cql filter. * @@ -756,16 +752,7 @@ public class LayerItem implements Serializable, Cloneable { * @return true, if is cql filter available */ public boolean isCqlFilterAvailable() { - return cqlFilterAvailable; - } - - /** - * Sets the cql filter available. - * - * @param cqlFilterAvailable the new cql filter available - */ - public void setCqlFilterAvailable(boolean cqlFilterAvailable) { - this.cqlFilterAvailable = cqlFilterAvailable; + return (cqlFilter != null) && (!cqlFilter.isEmpty()); } /** @@ -894,11 +881,6 @@ public class LayerItem implements Serializable, Cloneable { return maxResolution; } - /** - * To string. - * - * @return the string - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -952,8 +934,6 @@ public class LayerItem implements Serializable, Cloneable { builder.append(isNcWms); builder.append(", wmsLink="); builder.append(wmsLink); - builder.append(", cqlFilterAvailable="); - builder.append(cqlFilterAvailable); builder.append(", UUID="); builder.append(UUID); builder.append(", zAxis="); @@ -968,7 +948,6 @@ public class LayerItem implements Serializable, Cloneable { return builder.toString(); } - /** * To layer item. * @@ -991,9 +970,8 @@ public class LayerItem implements Serializable, Cloneable { * @param maxResolution the max resolution * @return the layer item */ - - - // TODO Constructor from IndexLayerDV, GCUBESDILAeryDV or direct info + + // TODO Constructor from IndexLayerDV, GCUBESDILAeryDV or direct info private LayerItem toLayerItem(LayerType layerType, String layerTitle, String layerName, String layerURL, String mapServerHost, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, ArrayList styles, String wmsLink, boolean onTop, HashMap wmsNotStandardParams, diff --git a/src/main/webapp/GeoportalDataViewer.css b/src/main/webapp/GeoportalDataViewer.css index e43201d..53d5764 100644 --- a/src/main/webapp/GeoportalDataViewer.css +++ b/src/main/webapp/GeoportalDataViewer.css @@ -158,6 +158,11 @@ body { padding-top: 1px; } +.preset-location ul a { + margin: 5px !important; +} + + .my-control-group .controls { margin-left: 70px !important; } @@ -211,7 +216,7 @@ body { } .inner-toolbar .btn-group { - margin-left: 0px !important; + margin-left: 2px !important; } .inner-toolbar .btn-link { @@ -426,6 +431,7 @@ body { .map-layers-radio label { margin-left: 5px; padding-top: 5px; + font-weight: bold; } From e76448d10a0ba75d2d98ddcd57ad80abcb40fa47 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 6 Jun 2023 12:04:25 +0200 Subject: [PATCH 13/18] Updated border radius --- .../client/ui/crossfiltering/CrossFilteringLayerPanel.java | 4 ++-- src/main/webapp/GeoportalDataViewer.css | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index db86a25..540b31b 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -282,8 +282,8 @@ public class CrossFilteringLayerPanel extends Composite { */ private String placeholderLayer(LayerIDV layersIDV) { String placeholder = "Select"; - if (layersIDV != null) - placeholder += " " + layersIDV.getTitle(); +// if (layersIDV != null) +// placeholder += " " + layersIDV.getTitle(); placeholder += " ..."; return placeholder; diff --git a/src/main/webapp/GeoportalDataViewer.css b/src/main/webapp/GeoportalDataViewer.css index 53d5764..7ba6fd8 100644 --- a/src/main/webapp/GeoportalDataViewer.css +++ b/src/main/webapp/GeoportalDataViewer.css @@ -26,7 +26,7 @@ body { background-color: white; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2); padding: 10px; - border-radius: 2px; + border-radius: 10px; border: 1px solid #cccccc; bottom: 12px; left: -50px; From f3e3ca5eb9eae9079426c73eacbefbba7a9f85fe Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 6 Jun 2023 14:38:30 +0200 Subject: [PATCH 14/18] Updated label and css --- .../client/ui/crossfiltering/CrossFilteringLayerPanel.java | 5 +++-- src/main/webapp/GeoportalDataViewer.css | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index 540b31b..b183a3d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -59,6 +59,8 @@ import ol.Feature; */ public class CrossFilteringLayerPanel extends Composite { + private static final String ITEM_LABEL = "centroid"; + public static String COLORSCALERANGE = "COLORSCALERANGE"; @UiField @@ -473,8 +475,7 @@ public class CrossFilteringLayerPanel extends Composite { } else { message = "Found " + dataCount; - message += dataCount > 1 ? " items" : " item"; - message += ". "; + message += dataCount > 1 ? " " + ITEM_LABEL + "s" : " " + ITEM_LABEL; } HTML resultMessage = new HTML(); resultMessage.getElement().addClassName("search_result_msg"); diff --git a/src/main/webapp/GeoportalDataViewer.css b/src/main/webapp/GeoportalDataViewer.css index 7ba6fd8..d4a1751 100644 --- a/src/main/webapp/GeoportalDataViewer.css +++ b/src/main/webapp/GeoportalDataViewer.css @@ -862,6 +862,10 @@ RESPONSIVE max-width: 350px; } +.filter-panel-style .control-group { + margin-bottom: 5px !important; +} + .filter-panel-style select { min-width: 310px; } From 1002111ca855eb6cba114c931d43f52b7dbf772c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 6 Jun 2023 14:50:06 +0200 Subject: [PATCH 15/18] Fixing label --- .../client/ui/crossfiltering/CrossFilteringLayerPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index b183a3d..f567816 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -471,7 +471,7 @@ public class CrossFilteringLayerPanel extends Composite { String message = ""; if (dataCount <= 0) { - message = "No item found"; + message = "No "+ITEM_LABEL+" found"; } else { message = "Found " + dataCount; From a7680ffb46a2a570b749a89b435b92633c0567ee Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 7 Jun 2023 14:26:57 +0200 Subject: [PATCH 16/18] Added "Fit map to Extent" facility --- .../client/GeoportalDataViewer.java | 33 ++++---- .../client/events/FitMapToExtentEvent.java | 52 ++++++++++++ .../events/FitMapToExtentEventHandler.java | 20 +++++ .../client/gis/MapUtils.java | 17 +++- .../client/gis/OpenLayerMap.java | 21 +++++ .../client/ui/cms/project/ProjectViewer.java | 2 +- .../CrossFilteringLayerPanel.java | 79 ++++++++++++++++++- 7 files changed, 204 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/FitMapToExtentEvent.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/FitMapToExtentEventHandler.java 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 ba0a812..40ff90a 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 @@ -35,6 +35,8 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetai import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.DO_LAYER_ACTION; import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.SwapLayer; import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEventHandler; +import org.gcube.portlets.user.geoportaldataviewer.client.events.FitMapToExtentEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.FitMapToExtentEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.OverlayCustomLayerToMapEvent; @@ -802,8 +804,8 @@ public class GeoportalDataViewer implements EntryPoint { // Showing popup after clicking on map if (showPopupOnCentroiEvent.getProfileID() != null && showPopupOnCentroiEvent.getProjectID() != null) { - Coordinate transfCoord = MapUtils - .geoJSONTToBBoxCenter(showPopupOnCentroiEvent.getSpatialReference(), null, null); + Coordinate transfCoord = MapUtils.geoJSONToBBOXCenter(showPopupOnCentroiEvent.getSpatialReference(), + null, null); performWFSQueryOnCentroid(showPopupOnCentroiEvent.getProjectID(), transfCoord.getX(), transfCoord.getY()); @@ -878,8 +880,8 @@ public class GeoportalDataViewer implements EntryPoint { newCqlFilter = olMapMng.getOLMap().setCQLFilterToWMSLayer(CQL_FACILITY_ORIGIN.SEARCH, layerName, null); } - - GWT.log("New CQL Filter is: "+newCqlFilter); + + GWT.log("New CQL Filter is: " + newCqlFilter); if (layerName != null) layerManager.setCQLForLayerToIndexLayer(layerName, newCqlFilter); @@ -932,6 +934,18 @@ public class GeoportalDataViewer implements EntryPoint { } }); + applicationBus.addHandler(FitMapToExtentEvent.TYPE, new FitMapToExtentEventHandler() { + + @Override + public void onFitToMap(FitMapToExtentEvent fitMapToExtentEvent) { + + if (fitMapToExtentEvent.getExtent() != null) { + olMapMng.getOLMap().fitToExtent(fitMapToExtentEvent.getExtent()); + } + + } + }); + } /** @@ -1052,17 +1066,6 @@ public class GeoportalDataViewer implements EntryPoint { GWT.log("features: " + features); olMapMng.getOLMap().addLayerFeaturesAsHighlight(layerItem, features, true); - - /* - * Fit to extent calculating the features extent if (projectDV != null) { - * GeoJSON spatialReference = projectDV.getSpatialReference(); - * - * GWT.log("spatialReference is: " + spatialReference); Coordinate transfCoord = - * MapUtils.geoJSONTToBBoxCenter(spatialReference, - * MAP_PROJECTION.EPSG_4326.getName(), MAP_PROJECTION.EPSG_3857.getName()); - * GWT.log("transfCoord is: " + transfCoord); if (transfCoord != null) - * olMapMng.getOLMap().setCenter(transfCoord); } - */ } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/FitMapToExtentEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/FitMapToExtentEvent.java new file mode 100644 index 0000000..ea4a128 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/FitMapToExtentEvent.java @@ -0,0 +1,52 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events; + +import com.google.gwt.event.shared.GwtEvent; + +import ol.Extent; + +/** + * The Class FitMapToExtentEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 6, 2023 + */ +public class FitMapToExtentEvent extends GwtEvent { + public static Type TYPE = new Type(); + private Extent extent; + + /** + * Instantiates a new fit map to extent event. + * + * @param extent the extent + */ + public FitMapToExtentEvent(Extent extent) { + this.extent = extent; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + @Override + protected void dispatch(FitMapToExtentEventHandler handler) { + handler.onFitToMap(this); + + } + + public Extent getExtent() { + return extent; + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/FitMapToExtentEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/FitMapToExtentEventHandler.java new file mode 100644 index 0000000..a816212 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/FitMapToExtentEventHandler.java @@ -0,0 +1,20 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events; + +import com.google.gwt.event.shared.EventHandler; + +/** + * The Interface FitMapToExtentEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 6, 2023 + */ +public interface FitMapToExtentEventHandler extends EventHandler { + + /** + * On fit to map. + * + * @param fitMapToExtentEvent the fit map to extent event + */ + void onFitToMap(FitMapToExtentEvent fitMapToExtentEvent); +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/MapUtils.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/MapUtils.java index 4940ed0..7862e60 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/MapUtils.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/MapUtils.java @@ -6,6 +6,7 @@ import com.google.gwt.core.client.GWT; import ol.Collection; import ol.Coordinate; +import ol.Extent; import ol.control.Attribution; import ol.control.Control; import ol.control.FullScreen; @@ -55,6 +56,18 @@ public final class MapUtils { return Projection.transform(centerCoordinate, source, target); } + /** + * Transform extent. + * + * @param extent the extent + * @param source the source + * @param target the target + * @return the extent + */ + public static Extent transformExtent(Extent extent, String source, String target) { + return Projection.transformExtent(extent, source, target); + } + /** * Distance between centroid. * @@ -95,14 +108,14 @@ public final class MapUtils { } /** - * Geo JSONT to B box center. + * Geo JSON to B box center. * * @param spatialReference the spatial reference * @param transforFrom the transfor from * @param transformTo the transform to * @return the coordinate */ - public static Coordinate geoJSONTToBBoxCenter(GeoJSON spatialReference, String transforFrom, String transformTo) { + public static Coordinate geoJSONToBBOXCenter(GeoJSON spatialReference, String transforFrom, String transformTo) { try { if (spatialReference != null) { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java index 3486357..ef64d80 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java @@ -37,6 +37,7 @@ import ol.Overlay; import ol.OverlayOptions; import ol.Size; import ol.View; +import ol.ViewFitOptions; import ol.ViewOptions; import ol.animation.AnimationOptions; import ol.color.Color; @@ -90,6 +91,13 @@ public abstract class OpenLayerMap { public static final int MAX_ZOOM = 21; + /** + * The Enum CQL_FACILITY_ORIGIN. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Jun 6, 2023 + */ public static enum CQL_FACILITY_ORIGIN { SEARCH, CROSS_FILTERING } @@ -1183,4 +1191,17 @@ public abstract class OpenLayerMap { return map.get((map.keySet().toArray())[index]); } + /** + * Fit to extent. + * + * @param extent the extent + */ + public void fitToExtent(ol.Extent extent) { + ViewFitOptions opt = new ViewFitOptions(); + opt.setMaxZoom(16); + opt.setDuration(SET_CENTER_ANIMATED_DURATION*4); + map.getView().fit(extent, opt); + + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.java index bdda6f9..50041e7 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.java @@ -304,7 +304,7 @@ public class ProjectViewer extends Composite { GeoJSON spatialReference = theProjectView.getTheProjectDV().getSpatialReference(); - Coordinate transfCoord = MapUtils.geoJSONTToBBoxCenter(spatialReference, MAP_PROJECTION.EPSG_4326.getName(), + Coordinate transfCoord = MapUtils.geoJSONToBBOXCenter(spatialReference, MAP_PROJECTION.EPSG_4326.getName(), MAP_PROJECTION.EPSG_3857.getName()); if (transfCoord != null) { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index f567816..8ae6a78 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -10,9 +10,13 @@ import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.Cros import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.LayerIDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDILayer; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.BBOXDV; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync; import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerOnMapEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.FitMapToExtentEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped; +import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils; import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil; import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon; import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; @@ -39,16 +43,24 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.http.client.URL; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONValue; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; import jsinterop.base.JsPropertyMap; +import ol.Coordinate; +import ol.Extent; import ol.Feature; +import ol.OLFactory; /** * The Class CrossFilteringLayerPanel. @@ -461,12 +473,14 @@ public class CrossFilteringLayerPanel extends Composite { @Override public void onSuccess(String response) { Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, response); - + if (features != null) { int dataCount = features.length; panelResults.clear(); panelResults.add(new HTML("
")); + + FlexTable flexTable = new FlexTable(); String message = ""; @@ -480,12 +494,73 @@ public class CrossFilteringLayerPanel extends Composite { HTML resultMessage = new HTML(); resultMessage.getElement().addClassName("search_result_msg"); resultMessage.setHTML(message); - panelResults.add(resultMessage); + flexTable.setWidget(0, 0, resultMessage.asWidget()); + panelResults.add(flexTable); + + try { + JSONObject jObject = (JSONObject) JSONParser.parseStrict(response); + JSONArray bbox = (JSONArray) jObject.get("bbox"); + double[] coords = new double[bbox.size()]; + for (int i = 0; i < bbox.size(); i++) { + JSONValue coord = bbox.get(i); + coords[i] = Double.parseDouble(coord.toString()); + } + + //Inverting coordinate to lat/long for EPSG:3857 Pseudo-Mercator + Coordinate lower = OLFactory.createCoordinate(coords[1], coords[0]); + Coordinate lowerCoord = MapUtils.transformCoordiante(lower, MAP_PROJECTION.EPSG_4326.getName(), + MAP_PROJECTION.EPSG_3857.getName()); + + Coordinate upper = OLFactory.createCoordinate(coords[3], coords[2]); + Coordinate upperCoord = MapUtils.transformCoordiante(upper, MAP_PROJECTION.EPSG_4326.getName(), + MAP_PROJECTION.EPSG_3857.getName()); + + final Extent transfExtent = new ExtentWrapped(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY()); + GWT.log("Zoom to selected - transf extent: "+transfExtent); + + + Button selectTo = new Button("Zoom to selected"); + selectTo.setType(ButtonType.DEFAULT); + selectTo.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + applicationBus.fireEvent(new FitMapToExtentEvent(transfExtent)); + + } + }); + flexTable.setWidget(1,0,selectTo); + //panelResults.add(selectTo); + + }catch (Exception e) { + // TODO: handle exception + } } + + } }); } + + public static final BBOXDV fromGeoJSON(double[] coords) { + BBOXDV toReturn = new BBOXDV(); + toReturn.setMaxX(coords[0]); + toReturn.setMinY(coords[1]); + + if (coords.length == 6) { + // 3D + toReturn.setMinZ(coords[2]); + toReturn.setMinX(coords[3]); + toReturn.setMaxY(coords[4]); + toReturn.setMaxZ(coords[5]); + } else { + toReturn.setMinX(coords[2]); + toReturn.setMaxY(coords[3]); + } + return toReturn; + } + /** * Load inner level. From 6361c1c0b93e7fdcbf543184cfe7f8ebbd2972d0 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 8 Jun 2023 17:03:42 +0200 Subject: [PATCH 17/18] #25074 cross-filtering completed --- .../client/gis/LayerOrder.java | 4 +- .../client/gis/OpenLayerMap.java | 2 +- .../client/ui/GeonaDataViewMainPanel.java | 12 +- .../CrossFilteringLayerPanel.java | 87 +- .../server/Geoportal_JSON_Mapper.java | 1032 ----------------- src/main/webapp/GeoportalDataViewer.css | 4 + 6 files changed, 48 insertions(+), 1093 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java index 472aaf5..5b325c0 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LayerOrder.java @@ -28,8 +28,8 @@ public class LayerOrder { LAYER_OFFSET.put(LAYER_TYPE.BASE_MAP, 0); //Base OL or MapBox LAYER_OFFSET.put(LAYER_TYPE.CUSTOM_WMS_DETAIL, 70); //WMS custom Overlay. Es. Layer "Limiti Amministrativi" - LAYER_OFFSET.put(LAYER_TYPE.BASE_WMS, 140); // Index layers (i.e. centroids for UCD) - LAYER_OFFSET.put(LAYER_TYPE.WMS_DETAIL, 210); //Layer/s belonging to a Project (materialized layers. Ex. "Posizionamento Scavo") + LAYER_OFFSET.put(LAYER_TYPE.BASE_WMS, 210); // Index layers (i.e. centroids for UCD) + LAYER_OFFSET.put(LAYER_TYPE.WMS_DETAIL, 140); //Layer/s belonging to a Project (materialized layers. Ex. "Posizionamento Scavo") LAYER_OFFSET.put(LAYER_TYPE.VECTOR, 320); //Vector layer to show other info. Ex. Pointer with coordinates (x,y) in the Light OL Map. } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java index ef64d80..95fcbae 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/OpenLayerMap.java @@ -1199,7 +1199,7 @@ public abstract class OpenLayerMap { public void fitToExtent(ol.Extent extent) { ViewFitOptions opt = new ViewFitOptions(); opt.setMaxZoom(16); - opt.setDuration(SET_CENTER_ANIMATED_DURATION*4); + opt.setDuration(SET_CENTER_ANIMATED_DURATION*5); map.getView().fit(extent, opt); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index 4cbc711..05efc6a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -210,14 +210,6 @@ public class GeonaDataViewMainPanel extends Composite { navListSearch.getElement().getFirstChildElement().setAttribute("disabled", "disabled"); -// List listUCDs = new ArrayList(); -// -// for (ItemFieldsResponse itemFieldsResponse : itemFieldsReponse) { -// listUCDs.add(itemFieldsResponse.getUseCaseDescriptorDV()); -// } -// -// Collections.sort(listUCDs); - for (final ItemFieldsResponse itemFieldResp : itemFieldsReponse) { UseCaseDescriptorDV ucd = itemFieldResp.getUseCaseDescriptorDV(); @@ -282,7 +274,9 @@ public class GeonaDataViewMainPanel extends Composite { @Override public void execute() { - searchFacilityPanel.getElement().getParentElement().getStyle().setOpacity(0.9); + searchFacilityPanel.getElement().getParentElement().addClassName("opacity-09"); + panelCustomOverlayLayers.getElement().getParentElement().addClassName("opacity-09"); + panelCrossFilteringLayers.getElement().getParentElement().addClassName("opacity-09"); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java index 8ae6a78..5f3a8b2 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/crossfiltering/CrossFilteringLayerPanel.java @@ -43,10 +43,6 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.http.client.URL; -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONParser; -import com.google.gwt.json.client.JSONValue; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -57,10 +53,9 @@ import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; import jsinterop.base.JsPropertyMap; -import ol.Coordinate; import ol.Extent; import ol.Feature; -import ol.OLFactory; +import ol.source.Vector; /** * The Class CrossFilteringLayerPanel. @@ -71,6 +66,8 @@ import ol.OLFactory; */ public class CrossFilteringLayerPanel extends Composite { + private static final double BBOX_OFFESET_ON_FEATURES = 18000.0; + private static final String ITEM_LABEL = "centroid"; public static String COLORSCALERANGE = "COLORSCALERANGE"; @@ -473,19 +470,19 @@ public class CrossFilteringLayerPanel extends Composite { @Override public void onSuccess(String response) { Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, response); - + if (features != null) { int dataCount = features.length; panelResults.clear(); panelResults.add(new HTML("
")); - + FlexTable flexTable = new FlexTable(); String message = ""; if (dataCount <= 0) { - message = "No "+ITEM_LABEL+" found"; + message = "No " + ITEM_LABEL + " found"; } else { message = "Found " + dataCount; @@ -496,53 +493,46 @@ public class CrossFilteringLayerPanel extends Composite { resultMessage.setHTML(message); flexTable.setWidget(0, 0, resultMessage.asWidget()); panelResults.add(flexTable); - + try { - JSONObject jObject = (JSONObject) JSONParser.parseStrict(response); - JSONArray bbox = (JSONArray) jObject.get("bbox"); - double[] coords = new double[bbox.size()]; - for (int i = 0; i < bbox.size(); i++) { - JSONValue coord = bbox.get(i); - coords[i] = Double.parseDouble(coord.toString()); - } - - //Inverting coordinate to lat/long for EPSG:3857 Pseudo-Mercator - Coordinate lower = OLFactory.createCoordinate(coords[1], coords[0]); - Coordinate lowerCoord = MapUtils.transformCoordiante(lower, MAP_PROJECTION.EPSG_4326.getName(), - MAP_PROJECTION.EPSG_3857.getName()); - - Coordinate upper = OLFactory.createCoordinate(coords[3], coords[2]); - Coordinate upperCoord = MapUtils.transformCoordiante(upper, MAP_PROJECTION.EPSG_4326.getName(), - MAP_PROJECTION.EPSG_3857.getName()); - - final Extent transfExtent = new ExtentWrapped(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY()); - GWT.log("Zoom to selected - transf extent: "+transfExtent); - - - Button selectTo = new Button("Zoom to selected"); - selectTo.setType(ButtonType.DEFAULT); - selectTo.addClickHandler(new ClickHandler() { + if (features.length > 0) { + // Calculating Extend of the selected Features + Vector vector = new Vector(); + vector.addFeatures(features); + Extent theExtent = vector.getExtent(); + GWT.log("Extent from features is: " + theExtent); + theExtent = MapUtils.transformExtent(theExtent, MAP_PROJECTION.EPSG_4326.getName(), + MAP_PROJECTION.EPSG_3857.getName()); - @Override - public void onClick(ClickEvent event) { - applicationBus.fireEvent(new FitMapToExtentEvent(transfExtent)); - - } - }); - flexTable.setWidget(1,0,selectTo); - //panelResults.add(selectTo); - - }catch (Exception e) { + double bboxOffset = features.length>1?BBOX_OFFESET_ON_FEATURES:0; + + final Extent transfExtent = new ExtentWrapped(theExtent.getLowerLeftX() - bboxOffset, + theExtent.getLowerLeftY() - bboxOffset, theExtent.getUpperRightX() + bboxOffset, + theExtent.getUpperRightY() + bboxOffset); + GWT.log("Zoom to selected - transf extent: " + transfExtent); + + Button selectTo = new Button("Zoom to selected"); + selectTo.setTitle("Zoom to select centroids..."); + selectTo.setType(ButtonType.DEFAULT); + selectTo.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + applicationBus.fireEvent(new FitMapToExtentEvent(transfExtent)); + + } + }); + flexTable.setWidget(1, 0, selectTo); + } + + } catch (Exception e) { // TODO: handle exception } } - - - } }); } - + public static final BBOXDV fromGeoJSON(double[] coords) { BBOXDV toReturn = new BBOXDV(); toReturn.setMaxX(coords[0]); @@ -561,7 +551,6 @@ public class CrossFilteringLayerPanel extends Composite { return toReturn; } - /** * Load inner level. * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java deleted file mode 100644 index 70343ad..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java +++ /dev/null @@ -1,1032 +0,0 @@ -//package org.gcube.portlets.user.geoportaldataviewer.server; -// -//import java.util.ArrayList; -//import java.util.HashMap; -//import java.util.LinkedHashMap; -//import java.util.List; -//import java.util.function.Function; -// -//import org.bson.Document; -//import org.gcube.application.geoportal.client.utils.Serialization; -//import org.gcube.application.geoportal.common.model.document.access.Access; -//import org.gcube.application.geoportal.common.model.document.access.AccessPolicy; -//import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; -//import org.gcube.application.geoportalcommon.geoportal.access.GeportalCheckAccessPolicy; -//import org.gcube.application.geoportalcommon.geoportal.serdes.Payload; -//import org.gcube.application.geoportalcommon.shared.geoportal.config.FilePathDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.BBOXDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.FilesetDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE; -//import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; -//import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView; -//import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView; -//import org.gcube.portlets.user.geoportaldataviewer.server.GeoportalDataViewerServiceImpl.ImageDetector; -//import org.gcube.portlets.user.geoportaldataviewer.server.util.URLParserUtil; -//import org.gcube.portlets.user.geoportaldataviewer.shared.MetaDataProfileBeanExt; -//import org.gcube.portlets.user.geoportaldataviewer.shared.ProjectEdit; -//import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; -//import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; -//import org.json.JSONArray; -//import org.json.JSONObject; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -// -//import com.google.gson.Gson; -//import com.google.gson.GsonBuilder; -//import com.google.gson.JsonObject; -//import com.google.gson.JsonParser; -//import com.jayway.jsonpath.JsonPath; -//import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider; -// -///** -// * The Class Geoportal_JSON_Mapper. -// * -// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it -// * -// * Oct 24, 2022 -// */ -//public class Geoportal_JSON_Mapper { -// -// public static final String _PAYLOADS = "_payloads"; -// -// public static final String _MATERIALIZATIONS = "_materializations"; -// -// public static final String _TYPE_GCUBE_SDI_LAYER = "gcube-sdi-layer"; -// -// private static final Logger LOG = LoggerFactory.getLogger(Geoportal_JSON_Mapper.class); -// -// public static final String FILESET = "fileset"; -// -// public static final String _OGC_LINKS = "_ogcLinks"; -// -// public static final String _BBOX = "_bbox"; -// -// public static final String _TYPE = "_type"; -// -// public static final String JSON_$_POINTER = "$"; -// -// public static final String _THEDOCUMENT = "_theDocument"; -// -// public static ProjectEdit loadProjectEdit(ProjectDV theProjectDV, String scope, String username) throws Exception { -// -// String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON(); -// -// LOG.debug("theProjectDV as JSON: " + theWholeProjectAsJSON); -// LOG.debug("theProjectDV as MAP: " + theProjectDV.getTheDocument().getDocumentAsMap()); -// -// ProjectEdit projectView = new ProjectEdit(); -// projectView.setTheProjectDV(theProjectDV); -// -// LinkedHashMap> linkedMap_UCDId_gCubeProfiles = GcubeProfilesPerUCDIdCache -// .get(scope); -// -// // NO UCD defined, applying default -// if (linkedMap_UCDId_gCubeProfiles.size() == 0) { -// LOG.warn("No " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " found in the UCD"); -// LOG.info("Applying default business logic to display the project"); -// SectionView sectionView = new SectionView(); -// sectionView.setSectionTitle("Document"); -// Document sectionDoc = Document.parse(theProjectDV.getTheDocument().getDocumentAsJSON()); -// -// // Creating one Project with one SectionView and SubDocumentView -// String wholeSectionDoc = sectionDoc.toJson(); -// -// List listFiles = new ArrayList(); -// -// // Reading Fileset _payloads -// String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, FILESET); -// List listPayloads = readPayloadsForFileset(filesetJSONPath, wholeSectionDoc); -// FilesetDV filesetDV = new FilesetDV(); -// filesetDV.setGcubeProfileFieldName(FILESET); -// for (Payload payload : listPayloads) { -// PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); -// filesetDV.addPayloadDV(payloadDV); -// listFiles.add(filesetDV); -// } -// } -// -// List listProfilesBean = linkedMap_UCDId_gCubeProfiles -// .get(theProjectDV.getProfileID()); -// -// com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() -// .jsonProvider(new JsonOrgJsonProvider()).build(); -// -// // LinkedHashMap mapOfProfilesBeanExt = new -// // LinkedHashMap(); -// -// ArrayList listOfProfilesBeanExt = new ArrayList(); -// -// // Reading the Project according to list of Profile defined in the UCD -// for (GcubeProfilesMetadataForUCD gcubeProfileMetaForUCD : listProfilesBean) { -// -// GcubeProfileDV gcubeProfileDV = gcubeProfileMetaForUCD.getGcubeProfile(); -//// SectionView sectionView = new SectionView(); -//// sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle()); -// -// System.out.println("\n\n##### Sto creando la sezione: " + gcubeProfileDV.getSectionTitle()); -// LOG.debug("\n\nThe profile is: " + gcubeProfileDV); -// // Building JSON/section full PATH and section name -// String sectionJSONPath = ""; -// String parentPathFromProfile = gcubeProfileDV.getParentName() == null ? "" : gcubeProfileDV.getParentName(); -// String theSectionName = gcubeProfileDV.getSectionName(); -// -// if (theSectionName.compareTo(JSON_$_POINTER) == 0 || theSectionName.compareTo(JSON_$_POINTER + ".") == 0) { -// sectionJSONPath = JSON_$_POINTER; -// theSectionName = ""; -// } else { -// sectionJSONPath = String.format("%s%s", -// parentPathFromProfile.endsWith(".") ? parentPathFromProfile : parentPathFromProfile + ".", -// theSectionName); -// } -// -// LOG.debug("The sectionJSONPath is: " + sectionJSONPath); -// -// JsonPath theSectionJsonPath = null; -// Object data = null; -// try { -// theSectionJsonPath = JsonPath.compile(sectionJSONPath); -// data = theSectionJsonPath.read(theWholeProjectAsJSON, configuration); -// } catch (Exception e) { -// LOG.warn("Error on searching the section " + sectionJSONPath + " in the JSON Project: " -// + theWholeProjectAsJSON); -// continue; -// } -// -// LOG.debug("Data is instace of: " + data.getClass()); -// LOG.debug("data to string: " + data.toString()); -// -// // Splitting the General Document in bson.Document according to list of -// // GcubeProfiles -// List listBSONDocument = new ArrayList(); -// if (data instanceof org.json.JSONObject) { -// String jsonString = data.toString(); -// LOG.debug("the JSON to string: " + jsonString); -// Document sectionDoc = Document.parse(jsonString); -// listBSONDocument.add(sectionDoc); -// -// } else if (data instanceof org.json.JSONArray) { -// org.json.JSONArray dataArray = (org.json.JSONArray) data; -// for (int i = 0; i < dataArray.length(); i++) { -// String jsonString = dataArray.get(i).toString(); -// LOG.debug("the array " + i + " JSON to string: " + jsonString); -// Document sectionDoc = Document.parse(jsonString); -// listBSONDocument.add(sectionDoc); -// } -// } -// -// LOG.debug("Result for " + gcubeProfileDV.getSectionName() + " is: " + listBSONDocument); -// List theProfileBeans = gcubeProfileMetaForUCD.getListMetadataProfileBean(); -// MetaDataProfileBean theProfileBean = theProfileBeans.get(0); -// -// // For each bson.Document filling the MetaDataProfileBean and its file -// for (int i = 0; i < listBSONDocument.size(); i++) { -// -// System.out.println("DOCUMENT number " + i + " of the section: " + theProfileBean.getTitle()); -// MetaDataProfileBeanExt theProfileBeanExt = new MetaDataProfileBeanExt(); -// theProfileBeanExt.setCategories(theProfileBean.getCategories()); -// theProfileBeanExt.setTitle(theProfileBean.getTitle()); -// theProfileBeanExt.setType(theProfileBean.getType()); -// -//// System.out.println("\nPRINTING PROJECT VIEW ON START: "); -//// for (int j = 0; j < listOfProfilesBeanExt.size(); j++) { -//// MetaDataProfileBeanExt metaDataProfileBeanExt = listOfProfilesBeanExt.get(j); -//// System.out.println("MetaDataProfileBeanExt index: " + j + " "+metaDataProfileBeanExt.getType() +" "+metaDataProfileBeanExt.hashCode()); -//// int z = 0; -//// for (MetadataFieldWrapper mfw : metaDataProfileBeanExt.getMetadataFields()) { -//// System.out.println("\t MetadataFieldWrapper index: " + z++ + " " + mfw); -//// } -//// } -// -// Document fromSectionDoc = listBSONDocument.get(i); -// LOG.debug("\n\nNew section DOC for index " + i + " is: " -// + new JSONObject(fromSectionDoc.toJson()).toString(2)); -// // Creating the corresponding MetaDataProfileBeanExt for each section -// -// // Reading policy and license statically -// // eg. "_access":{"_policy":"OPEN","_license":"CC0-1.0"}} -// Document docAccess = null; -// Access access = null; -// try { -// docAccess = fromSectionDoc.get("_access", Document.class); -// System.out.println("docAccess is: " + docAccess); -// access = new Access(); -// access.setPolicy(AccessPolicy.valueOf(docAccess.getString("_policy"))); -// access.setLicense(docAccess.getString("_license")); -// // Access. access.get("_policy"); -// // access.get("_license"); -// System.out.println("access is: " + access); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// // List copyOfMetadataFields = new -// // ArrayList(theProfileBean.getMetadataFields()); -// // int forIndex = 0; -// -// List cloneListOfMFW = cloneList(theProfileBean.getMetadataFields()); -// -// for (MetadataFieldWrapper metadataField : cloneListOfMFW) { -// -// String theFieldName = metadataField.getFieldId() != null ? metadataField.getFieldId() -// : metadataField.getFieldName(); -// LOG.debug("reading theFieldName: " + theFieldName); -// Object theOBJFieldValue = fromSectionDoc.get(theFieldName); -// metadataField.setCurrentValue(theOBJFieldValue + ""); -// -// if (access != null) { -// if (theFieldName.equalsIgnoreCase("policy")) { -// metadataField.setCurrentValue(access.getPolicy().name()); -// } else if (theFieldName.equalsIgnoreCase("licenseID")) { -// metadataField.setCurrentValue(access.getLicense()); -// } -// } -// // copyOfMetadataFields.set(forIndex++, metadataField); -// } -// -// LOG.debug("Before assigning it Metadata fields are: " + cloneListOfMFW); -// -// theProfileBeanExt.setMetadataFields(new ArrayList(cloneListOfMFW)); -// LOG.debug("Metadata fields are: " + theProfileBeanExt.getMetadataFields()); -// -// // Reading filePaths -// List filePaths = gcubeProfileDV.getFilePaths(); -// List listLayers = new ArrayList(); -// -// // READING fileset* field ACCORDING TO filePaths OF THE 'gcubeProfiles' CONFIG -// if (filePaths != null) { -// String fromSectionDocJSON = fromSectionDoc.toJson(); -// List listFiles = new ArrayList(); -//// List listLayers = new ArrayList(); -// for (FilePathDV filePath : filePaths) { -// -// // Reading Fileset _payloads -// String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName()); -// List listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON); -// FilesetDV filesetDV = new FilesetDV(); -// filesetDV.setGcubeProfileFieldName(filePath.getGcubeProfileFieldName()); -// for (Payload payload : listPayloads) { -// PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); -// filesetDV.addPayloadDV(payloadDV); -// -// } -// listFiles.add(filesetDV); -// -// // Reading Fileset _materializations -// // listLayers = readGcubeSDILayersForFileset(filesetJSONPath, -// // fromSectionDocJSON); -// // theProfileBeanExt.set -// -// } -// -// theProfileBeanExt.setListFileset(listFiles); -// } -// -// System.out.println("\nputting theProfileBeanExt: " + theProfileBeanExt); -// listOfProfilesBeanExt.add(theProfileBeanExt); -// -//// System.out.println("\nPRINTING PROJECT VIEW ON END: "); -//// for (int j = 0; j < listOfProfilesBeanExt.size(); j++) { -//// MetaDataProfileBeanExt metaDataProfileBeanExt = listOfProfilesBeanExt.get(j); -//// System.out.println("MetaDataProfileBeanExt index: " + j + " "+metaDataProfileBeanExt.getType() +" "+metaDataProfileBeanExt.hashCode()); -//// int z = 0; -//// for (MetadataFieldWrapper mfw : metaDataProfileBeanExt.getMetadataFields()) { -//// System.out.println("\t MetadataFieldWrapper index: " + z++ + " " + mfw); -//// } -//// } -//// -//// System.out.println(listProfileBeansExt.get(listProfileBeansExt.size()-1)); -// // Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView); -// } -// -// } -// -// projectView.setTheProfileBeans(listOfProfilesBeanExt); -// -// // Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView); -// -// return projectView; -// } -// -// public static List cloneList(List list) { -// List listCloned = new ArrayList(list.size()); -// -// Function cloneWrapper = (mfw) -> { -// -// MetadataFieldWrapper newMfw = new MetadataFieldWrapper(); -// newMfw.setAsGroup(mfw.getAsGroup()); -// newMfw.setAsTag(mfw.getAsTag()); -// newMfw.setCurrentValue(mfw.getCurrentValue()); -// newMfw.setDefaultValue(mfw.getDefaultValue()); -// newMfw.setFieldId(mfw.getFieldId()); -// newMfw.setFieldName(mfw.getFieldName()); -// newMfw.setFieldNameFromCategory(mfw.getFieldNameFromCategory()); -// newMfw.setMandatory(mfw.getMandatory()); -// newMfw.setMaxOccurs(mfw.getMaxOccurs()); -// newMfw.setMultiSelection(mfw.isMultiSelection()); -// newMfw.setNote(mfw.getNote()); -// newMfw.setOwnerCategory(mfw.getOwnerCategory()); -// newMfw.setType(mfw.getType()); -// newMfw.setValidator(mfw.getValidator()); -// newMfw.setVocabulary(mfw.getVocabulary()); -// -// return newMfw; -// -// }; -// -// for (MetadataFieldWrapper item : list) { -// MetadataFieldWrapper cloned = cloneWrapper.apply(item); -// listCloned.add(cloned); -// } -// return listCloned; -// } -// -// /** -// * Load project view. -// * -// * @param theProjectDV the the project DV -// * @param scope the scope -// * @param username the username -// * @return the project view -// * @throws Exception the exception -// */ -// public static ProjectView loadProjectView(ProjectDV theProjectDV, String scope, String username) throws Exception { -// -// String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON(); -// -// LOG.debug("theProjectDV as JSON: " + theWholeProjectAsJSON); -// LOG.debug("theProjectDV as MAP: " + theProjectDV.getTheDocument().getDocumentAsMap()); -// -// ProjectView projectView = new ProjectView(); -// projectView.setTheProjectDV(theProjectDV); -// -// LinkedHashMap> linkedMap_UCDId_gCubeProfiles = GcubeProfilesPerUCDIdCache -// .get(scope); -// -// // NO UCD defined, applying default -// if (linkedMap_UCDId_gCubeProfiles.size() == 0) { -// LOG.warn("No " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " found in the UCD"); -// LOG.info("Applying default business logic to display the project"); -// SectionView sectionView = new SectionView(); -// sectionView.setSectionTitle("Document"); -// SubDocumentView subDocumentView = new SubDocumentView(); -// -// Document sectionDoc = Document.parse(theProjectDV.getTheDocument().getDocumentAsJSON()); -// boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, JSON_$_POINTER, username); -// -// // If is accessible -// if (isAccessibleSection) { -// -// // Creating one Project with one SectionView and SubDocumentView -// String wholeSectionDoc = sectionDoc.toJson(); -// subDocumentView.setMetadataAsJSON(wholeSectionDoc); -// -// List listFiles = new ArrayList(); -// List listImages = new ArrayList(); -// List listLayers = new ArrayList(); -// -// // Reading Fileset _payloads -// String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, FILESET); -// List listPayloads = readPayloadsForFileset(filesetJSONPath, wholeSectionDoc); -// FilesetDV filesetDV = new FilesetDV(); -// filesetDV.setGcubeProfileFieldName(FILESET); -// for (Payload payload : listPayloads) { -// PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); -// filesetDV.addPayloadDV(payloadDV); -// boolean isImage = ImageDetector.isImage(payload.getMimetype()); -// -// if (isImage) { -// listImages.add(filesetDV); -// } else { -// listFiles.add(filesetDV); -// } -// } -// -// subDocumentView.setListImages(listImages); -// subDocumentView.setListFiles(listFiles); -// -// // Reading Fileset _materializations / layers -// listLayers = readGcubeSDILayersForFileset(filesetJSONPath, wholeSectionDoc); -// -// subDocumentView.setListLayers(listLayers); -// sectionView.addSubDocument(subDocumentView); -// projectView.addSectionView(sectionView); -// -// } -// -// } -// -// List listProfilesBean = linkedMap_UCDId_gCubeProfiles -// .get(theProjectDV.getProfileID()); -// -// com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() -// .jsonProvider(new JsonOrgJsonProvider()).build(); -// -// // Reading the Project according to list of Profile defined in the UCD -// for (GcubeProfilesMetadataForUCD gcubeProfileMetaForUCD : listProfilesBean) { -// -// GcubeProfileDV gcubeProfileDV = gcubeProfileMetaForUCD.getGcubeProfile(); -// SectionView sectionView = new SectionView(); -// sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle()); -// LOG.debug("\n\nThe profile is: " + gcubeProfileDV); -// // Building JSON/section full PATH and section name -// String sectionJSONPath = ""; -// String parentPathFromProfile = gcubeProfileDV.getParentName() == null ? "" : gcubeProfileDV.getParentName(); -// String theSectionName = gcubeProfileDV.getSectionName(); -// -// if (theSectionName.compareTo(JSON_$_POINTER) == 0 || theSectionName.compareTo(JSON_$_POINTER + ".") == 0) { -// sectionJSONPath = JSON_$_POINTER; -// theSectionName = ""; -// } else { -// sectionJSONPath = String.format("%s%s", -// parentPathFromProfile.endsWith(".") ? parentPathFromProfile : parentPathFromProfile + ".", -// theSectionName); -// } -// -// LOG.debug("The sectionJSONPath is: " + sectionJSONPath); -// -// JsonPath theSectionJsonPath = null; -// Object data = null; -// try { -// theSectionJsonPath = JsonPath.compile(sectionJSONPath); -// data = theSectionJsonPath.read(theWholeProjectAsJSON, configuration); -// } catch (Exception e) { -// LOG.warn("Error on searching the section " + sectionJSONPath + " in the JSON Project: " -// + theWholeProjectAsJSON); -// continue; -// } -// -// LOG.debug("Data is instace of: " + data.getClass()); -// LOG.debug("data to string: " + data.toString()); -// -// // Splitting the General Document in bson.Document according to list of -// // GcubeProfiles -// List listBSONDocument = new ArrayList(); -// if (data instanceof org.json.JSONObject) { -// String jsonString = data.toString(); -// LOG.debug("the JSON to string: " + jsonString); -// Document sectionDoc = Document.parse(jsonString); -// boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, sectionJSONPath, -// username); -// if (isAccessibleSection) { -// listBSONDocument.add(sectionDoc); -// } -// -// } else if (data instanceof org.json.JSONArray) { -// org.json.JSONArray dataArray = (org.json.JSONArray) data; -// for (int i = 0; i < dataArray.length(); i++) { -// String jsonString = dataArray.get(i).toString(); -// LOG.debug("the array " + i + " JSON to string: " + jsonString); -// Document sectionDoc = Document.parse(jsonString); -// boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, sectionJSONPath, -// username); -// if (isAccessibleSection) { -// listBSONDocument.add(sectionDoc); -// } -// -// } -// } -// -// LOG.debug("Result for " + gcubeProfileDV.getSectionName() + " is: " + listBSONDocument); -// List theProfileBeans = gcubeProfileMetaForUCD.getListMetadataProfileBean(); -// MetaDataProfileBean theProfileBean = theProfileBeans.get(0); -// -// // For each bson.Document creating the SubDocumentView -// for (int i = 0; i < listBSONDocument.size(); i++) { -// Document fromSectionDoc = listBSONDocument.get(i); -// SubDocumentView subDocumentView = new SubDocumentView(); -// Document toSectionDoc = new Document(); -// // Filling the SubDocumentView metadata with the metadataField.getFieldName() -// // read from the Profile -// for (MetadataFieldWrapper metadataField : theProfileBean.getMetadataFields()) { -// -// String theFieldName = metadataField.getFieldId() != null ? metadataField.getFieldId() -// : metadataField.getFieldName(); -// LOG.debug("reading theFieldName: " + theFieldName); -// Object theOBJFieldValue = fromSectionDoc.get(theFieldName); -// -// // NB: Using ALWAYS THE metadataField.getFieldName() as LABEL -// toSectionDoc = sanitizeDocumentValue(toSectionDoc, metadataField.getFieldName(), theOBJFieldValue); -// -// } -// String subToJSON = toSectionDoc.toJson(); -// LOG.debug("theSubSetionDoc is: " + subToJSON); -// subDocumentView.setMetadataAsJSON(toSectionDoc.toJson()); -// -// // Reading filePaths -// List filePaths = gcubeProfileDV.getFilePaths(); -// -// // READING fileset* field ACCORDING TO filePaths OF THE 'gcubeProfiles' CONFIG -// if (filePaths != null) { -// String fromSectionDocJSON = fromSectionDoc.toJson(); -// List listFiles = new ArrayList(); -// List listImages = new ArrayList(); -// List listLayers = new ArrayList(); -// for (FilePathDV filePath : filePaths) { -// -// // Reading Fileset _payloads -// String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName()); -// List listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON); -// if(LOG.isDebugEnabled()) { -// for (Payload payload : listPayloads) { -// LOG.debug("read payload: " + payload); -// } -// } -// -// FilesetDV filesetImages = new FilesetDV(); -// FilesetDV filesetFiles = new FilesetDV(); -// -// for (Payload payload : listPayloads) { -// PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); -// //filesetDV.addPayloadDV(payloadDV); -// boolean isImage = ImageDetector.isImage(payload.getMimetype()); -// -// if (isImage) { -// filesetImages.setGcubeProfileFieldName(filePath.getGcubeProfileFieldName()); -// filesetImages.addPayloadDV(payloadDV); -// } else { -// filesetFiles.addPayloadDV(payloadDV); -// filesetFiles.setGcubeProfileFieldName(filePath.getGcubeProfileFieldName()); -// } -// } -// -// //Setting only if one element exists -// if(filesetImages.getListPayload()!=null && filesetImages.getListPayload().size()>0) { -// listImages.add(filesetImages); -// } -// if(filesetFiles.getListPayload()!=null && filesetFiles.getListPayload().size()>0) { -// listFiles.add(filesetFiles); -// } -// -// // Reading Fileset _materializations -// listLayers = readGcubeSDILayersForFileset(filesetJSONPath, fromSectionDocJSON); -// -// } -// subDocumentView.setListFiles(listFiles); -// subDocumentView.setListImages(listImages); -// subDocumentView.setListLayers(listLayers); -// } -// -// sectionView.addSubDocument(subDocumentView); -// -// } -// -// projectView.addSectionView(sectionView); -// } -// -// LOG.debug("returning the projectView: " + projectView); -// return projectView; -// } -// -// /** -// * Read payloads for fileset. -// * -// * @param filesetJSONPath the fileset JSON path -// * @param sectionJSONDocument the section JSON document -// * @return the list -// */ -// public static List readPayloadsForFileset(String filesetJSONPath, String sectionJSONDocument) { -// LOG.debug("readPayloadsForFileset called"); -// -// List listPayloads = new ArrayList(); -// String _payloadsJSONPath = String.format("%s.%s", filesetJSONPath, _PAYLOADS); -// try { -// com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() -// .jsonProvider(new JsonOrgJsonProvider()).build(); -// -// LOG.debug("Reading sectionPath at {} into section document {}", _payloadsJSONPath, sectionJSONDocument); -// JsonPath theSectionPolycJsonPath = JsonPath.compile(_payloadsJSONPath); -// Object _payloads = theSectionPolycJsonPath.read(sectionJSONDocument, configuration).toString(); -// -// if (_payloads instanceof String) { -// String toStringPayloads = (String) _payloads; -// LOG.trace("The _payloads is a String {}", toStringPayloads); -// JSONArray jsonArray = new JSONArray(toStringPayloads); -// for (int i = 0; i < jsonArray.length(); i++) { -// Payload payloadDV = Serialization.read(jsonArray.getJSONObject(i).toString(), Payload.class); -// listPayloads.add(payloadDV); -// } -// } -// -// LOG.info("returning list of payloads {}", listPayloads); -// } catch (Exception e) { -// LOG.warn("Error on reading the JSON Path " + _payloadsJSONPath + " in the doc " + sectionJSONDocument, e); -// } -// -// return listPayloads; -// -// } -// -// /** -// * Read images for fileset. -// * -// * @param parentJSONPath the parent JSON path -// * @param sectionJSONDocument the section JSON document -// * @param limitToFirstOneFound the limit to first one found -// * @return the list -// */ -// public static List readImagesForFileset(String parentJSONPath, String sectionJSONDocument, -// boolean limitToFirstOneFound) { -// LOG.info("readImagesForFileset called"); -// -// List listImages = new ArrayList(); -// com.jayway.jsonpath.Configuration config = com.jayway.jsonpath.Configuration.builder() -// .jsonProvider(new JsonOrgJsonProvider()).build(); -// // Reading Fileset _payloads -// String filesetJSONPath = String.format("%s.%s", parentJSONPath, _PAYLOADS); -// LOG.debug("Reading sectionPath {} into section document {}", filesetJSONPath, sectionJSONDocument); -// JsonPath theSectionPolycJsonPath = JsonPath.compile(filesetJSONPath); -// Object _filesets = theSectionPolycJsonPath.read(sectionJSONDocument, config); -// -// List payloads = new ArrayList(); -// List listPayloads = recursiveFetchingPayloads(config, _filesets, payloads); -// for (Payload payload : listPayloads) { -// boolean isImage = ImageDetector.isImage(payload.getMimetype()); -// if (isImage) { -// PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); -// listImages.add(payloadDV); -// if (limitToFirstOneFound && listImages.size() == 1) -// return listImages; -// } -// } -// -// LOG.debug("readImagesForFileset returning listOfImages: " + listImages); -// return listImages; -// -// } -// -// /** -// * Read gcube SDI layers for fileset. -// * -// * @param materializationParentJSONPath the materialization parent JSON path -// * @param sectionJSONDocument the section JSON document -// * @return the list -// */ -// public static List readGcubeSDILayersForFileset(String materializationParentJSONPath, -// String sectionJSONDocument) { -// LOG.info("readGcubeSDILayersForFileset called"); -// -// List listSDILayers = new ArrayList(); -// // _materializations AT THE MOMENT ARE ONLY OF TYPE gcube-sdi-layer. I'm adding -// // the filtering "_type": "gcube-sdi-layer" to be sure of reading SDI layer -// String _materializationsJSONPath = String.format("%s.%s[?(@._type=='%s')]", materializationParentJSONPath, -// _MATERIALIZATIONS, _TYPE_GCUBE_SDI_LAYER); -// // [?(@._access._policy=='%s')] -// -// try { -// com.jayway.jsonpath.Configuration configurationJSONSmart = com.jayway.jsonpath.Configuration.builder() -// .jsonProvider(new JsonOrgJsonProvider()).build(); -// -// LOG.debug("GcubeSDILayers Reading sectionPath {} into section document {}", _materializationsJSONPath, -// sectionJSONDocument); -// -// JsonPath theSectionMaterializationJsonPath = JsonPath.compile(_materializationsJSONPath); -// Object _materializations = theSectionMaterializationJsonPath.read(sectionJSONDocument, -// configurationJSONSmart); -// -// LOG.trace("_materializations.class(): " + _materializations.getClass()); -// -// listSDILayers = recursiveFetchingLayers(configurationJSONSmart, _materializations, listSDILayers); -// -// } catch (Exception e) { -// LOG.debug("Error on reading the JSON Path " + _materializationsJSONPath + " in the doc " -// + sectionJSONDocument, e); -// } -// LOG.info("returning list of layers {}", listSDILayers); -// return listSDILayers; -// -// } -// -// /** -// * Recursive fetching layers. -// * -// * @param config the config -// * @param objectJSON the object JSON -// * @param listSDILayers the list SDI layers -// * @return the list -// */ -// private static List recursiveFetchingLayers(com.jayway.jsonpath.Configuration config, -// Object objectJSON, List listSDILayers) { -// -// if (objectJSON == null) -// return listSDILayers; -// -// if (objectJSON instanceof JSONArray) { -// JSONArray theJsonArray = (JSONArray) objectJSON; -// LOG.debug("jsonArray: " + theJsonArray.toString(3)); -// -// for (int i = 0; i < theJsonArray.length(); i++) { -// recursiveFetchingLayers(config, theJsonArray.get(i), listSDILayers); -// } -// } else if (objectJSON instanceof JSONObject) { -// JSONObject theJsonObject = (JSONObject) objectJSON; -// LOG.debug("theJSONObject: " + theJsonObject.toString(3)); -// GCubeSDIViewerLayerDV gsdiLayer = converLayer(config, theJsonObject); -// listSDILayers.add(gsdiLayer); -// } -// -// return listSDILayers; -// } -// -// /** -// * Recursive fetching payloads. -// * -// * @param config the config -// * @param objectJSON the object JSON -// * @param payloads the payloads -// * @return the list -// */ -// public static List recursiveFetchingPayloads(com.jayway.jsonpath.Configuration config, Object objectJSON, -// List payloads) { -// LOG.debug("recursiveFetchingPayloads called"); -// -// if (objectJSON == null) -// return payloads; -// -// if (objectJSON instanceof JSONArray) { -// JSONArray theJsonArray = (JSONArray) objectJSON; -// LOG.trace("jsonArray: " + theJsonArray.toString(3)); -// -// for (int i = 0; i < theJsonArray.length(); i++) { -// payloads = recursiveFetchingPayloads(config, theJsonArray.get(i), payloads); -// } -// } else if (objectJSON instanceof JSONObject) { -// JSONObject toStringPayloads = (JSONObject) objectJSON; -// LOG.trace("The _payloads is a String {}", toStringPayloads.toString(3)); -// Payload payload; -// try { -// payload = Serialization.read(toStringPayloads.toString(), Payload.class); -// payloads.add(payload); -// } catch (Exception e) { -// LOG.warn("Error on converting the JSON Boject " + toStringPayloads + "as " -// + Payload.class.getSimpleName() + e.getMessage()); -// } -// -// } -// -// return payloads; -// -// } -// -// /** -// * Conver layer. -// * -// * @param config the config -// * @param thJsonObject the th json object -// * @return the g cube SDI viewer layer DV -// */ -// // TODO THIS PART SHOULD BE REVISITED/OPTIMIZED -// private static GCubeSDIViewerLayerDV converLayer(com.jayway.jsonpath.Configuration config, -// JSONObject thJsonObject) { -// LOG.debug("converLayer called for " + thJsonObject); -// -// GCubeSDIViewerLayerDV gsdiLayer = new GCubeSDIViewerLayerDV(); -// try { -// String theType = thJsonObject.getString(_TYPE); -// gsdiLayer.setType(theType); -// LOG.debug(_TYPE + " is: " + theType); -// } catch (Exception e) { -// LOG.warn("No " + _TYPE + " found", e); -// } -// String toSerializeJSONOBJ = thJsonObject.toString(); -// String jsonPath = null; -// try { -// jsonPath = String.format("%s.%s", JSON_$_POINTER, _BBOX); -// HashMap bbox = JsonPath.using(config).parse(toSerializeJSONOBJ).read(jsonPath, -// HashMap.class); -// BBOXDV bboxDV = new BBOXDV(bbox); -// gsdiLayer.setBbox(bboxDV); -// LOG.debug(_BBOX + " is: " + bboxDV); -// } catch (Exception e) { -// LOG.warn(jsonPath + " error: ", e); -// } -// try { -// jsonPath = String.format("%s.%s", JSON_$_POINTER, _OGC_LINKS); -// String jsonString = JsonPath.using(config).parse(toSerializeJSONOBJ).read(jsonPath).toString(); -// Gson gson = new Gson(); -// HashMap map = gson.fromJson(jsonString, HashMap.class); -// gsdiLayer.setOgcLinks(map); -// LOG.debug(_OGC_LINKS + " are: " + map); -// } catch (Exception e) { -// LOG.warn(jsonPath + " error: ", e); -// } -// -// try { -// String wmsLink = gsdiLayer.getWMSLink(); -// if (wmsLink != null) { -// String layerName = URLParserUtil.extractValueOfParameterFromURL("layers", wmsLink); -// gsdiLayer.setLayerName(layerName); -// } -// } catch (Exception e) { -// LOG.warn(jsonPath + " error: ", e); -// } -// -// LOG.debug("converLayer returning: " + gsdiLayer); -// return gsdiLayer; -// } -// -// /** -// * Checks if is accessible section according to policy. -// * -// * @param section the section -// * @param sectionJSONPath the section JSON path -// * @param myLogin the my login -// * @return true, if is accessible section according to policy -// */ -// public static boolean isAccessibleSectionAccordingToPolicy(Document section, String sectionJSONPath, -// String myLogin) { -// LOG.debug("isAccessibleSectionAccordingToPolicy called"); -// boolean isAccessible = true; -// -// // Skipping the root, going to check the access_policy of subsections -// if (sectionJSONPath.compareTo(JSON_$_POINTER) != 0) { -// isAccessible = checkAccessPolicy(section.toJson(), myLogin); -// } -// -// return isAccessible; -// } -// -// /** -// * Check access policy. -// * -// * @param sectionDocumentJSON the section document JSON -// * @param myLogin the my login -// * @return true, if successful -// */ -// private static boolean checkAccessPolicy(String sectionDocumentJSON, String myLogin) { -// LOG.info("checkAccessPolicy called"); -// // CHECKING THE POLICY -// // see ticket #24390 -// // First reading the access policy from the fileset -// String accessPolicyPath = JSON_$_POINTER + ".fileset._access._policy"; -// boolean isAccessible = true; -// try { -// com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() -// .jsonProvider(new JsonOrgJsonProvider()).build(); -// -// LOG.debug("Reading access policy at {} into section document {}", accessPolicyPath, sectionDocumentJSON); -// String _policy = null; -// try { -// JsonPath theSectionPolycJsonPath = JsonPath.compile(accessPolicyPath); -// _policy = theSectionPolycJsonPath.read(sectionDocumentJSON, configuration).toString(); -// -// if (_policy == null) -// throw new Exception("Policy is null"); -// -// } catch (Exception e) { -// LOG.debug("Access policy not found in: " + accessPolicyPath); -// } -// -// // If policy does not exist into fileset, reading from the parent section -// if (_policy == null) { -// accessPolicyPath = JSON_$_POINTER + "._access._policy"; -// LOG.debug("Reading access policy at {} into section document {}", accessPolicyPath, -// sectionDocumentJSON); -// try { -// JsonPath theSectionPolycJsonPath = JsonPath.compile(accessPolicyPath); -// _policy = theSectionPolycJsonPath.read(sectionDocumentJSON, configuration).toString(); -// -// if (_policy == null) -// throw new Exception("Policy is null"); -// -// } catch (Exception e) { -// LOG.debug("Access policy not found in: " + accessPolicyPath); -// } -// } -// -// LOG.debug("The section {} has policy {}", accessPolicyPath, _policy); -// isAccessible = GeportalCheckAccessPolicy.isAccessible(_policy, myLogin); -// } catch (Exception e) { -// LOG.error(accessPolicyPath + " not found. Check OK"); -// } -// LOG.info("It is {} accessible the section {} accessible? {}", isAccessible, sectionDocumentJSON); -// return isAccessible; -// } -// -// /** -// * Sanitize document value. -// * -// * @param toDoc the to doc -// * @param fieldLabel the field label -// * @param theObjectFieldValue the the object field value -// * @return the document -// */ -// private static Document sanitizeDocumentValue(Document toDoc, String fieldLabel, Object theObjectFieldValue) { -// -// if (theObjectFieldValue != null) { -// if (theObjectFieldValue instanceof String) { -// String toString = (String) theObjectFieldValue; -// if (toString != null && !toString.isEmpty()) { -// toDoc.append(fieldLabel, toString.trim()); -// } else { -// LOG.debug("Skipping String field " + fieldLabel + " its value is null or empty"); -// } -// -// } else if (theObjectFieldValue instanceof ArrayList) { -// ArrayList toArrayList = (ArrayList) theObjectFieldValue; -// if (toArrayList != null && !toArrayList.isEmpty()) { -// toDoc.append(fieldLabel, theObjectFieldValue); -// } else { -// LOG.debug("Skipping ArrayList field " + fieldLabel + " its value is null or empty"); -// } -// } else { -// toDoc.append(fieldLabel, theObjectFieldValue); -// } -// } else { -// LOG.debug("Skipping field " + fieldLabel + " its value is null or empty"); -// } -// -// return toDoc; -// } -// -// /** -// * Pretty print JSON. -// * -// * @param jsonString the json string -// * @return the string -// */ -// private static String prettyPrintJSON(String jsonString) { -// -// Gson gson = new GsonBuilder().setPrettyPrinting().create(); -// JsonObject jsonObject = new JsonParser().parse(jsonString).getAsJsonObject(); -// return gson.toJson(jsonObject); -// } -// -// /** -// * Pretty print project view. -// * -// * @param projectView the project view -// */ -// public static void prettyPrintProjectView(ProjectView projectView) { -// -// for (SectionView section : projectView.getListSections()) { -// System.out.println("\n\n###### Section Title: " + section.getSectionTitle() + " ######"); -// int i = 1; -// for (SubDocumentView subDocument : section.getListSubDocuments()) { -// System.out.println("## " + SubDocumentView.class.getSimpleName() + " n." + i); -// System.out.println("***** Metadata"); -// System.out.println(prettyPrintJSON(subDocument.getMetadataAsJSON())); -// System.out.println("***** Files"); -// if (subDocument.getListFiles() != null) { -// for (FilesetDV filesetDV : subDocument.getListFiles()) { -// System.out.println("******* File Fileset name: " + filesetDV.getGcubeProfileFieldName()); -// for (PayloadDV payload : filesetDV.getListPayload()) { -// System.out.println("********* Payload: " + payload); -// } -// } -// } -// System.out.println("***** Images"); -// if (subDocument.getListImages() != null) { -// for (FilesetDV filesetDV : subDocument.getListImages()) { -// System.out.println("******* Image Fileset name: " + filesetDV.getGcubeProfileFieldName()); -// for (PayloadDV payload : filesetDV.getListPayload()) { -// System.out.println("********* Payload: " + payload); -// } -// } -// } -// System.out.println("***** Layers"); -// if (subDocument.getListLayers() != null) { -// for (GCubeSDIViewerLayerDV layer : subDocument.getListLayers()) { -// System.out.println("******* Layer type: " + layer.getType()); -// System.out.println("******* Layer: " + layer); -// } -// } -// i++; -// } -// -// } -// } -// -// /** -// * Pretty print project view. -// * -// * @param projectView the project view -// */ -// public static void prettyPrintProjectEdit(ProjectEdit projectEdit) { -// -// for (MetaDataProfileBeanExt mpb : projectEdit.getTheProfileBeans()) { -// System.out.println("\n\n###### Title: " + mpb.getTitle() + " - Type: " + mpb.getType() + " ######"); -// int i = 1; -// for (MetadataFieldWrapper fieldWrapper : mpb.getMetadataFields()) { -// System.out.println("## " + MetadataFieldWrapper.class.getSimpleName() + " n." + i); -// System.out.println("***** Metadata"); -// // System.out.println(mfw); -// System.out.println("\tfieldId: " + fieldWrapper.getFieldId() + ", fieldName: " -// + fieldWrapper.getFieldName() + ", CurrentValue: " + fieldWrapper.getCurrentValue()); -// i++; -// } -// i = 1; -// System.out.println("***** Files"); -// for (FilesetDV fileSet : mpb.getListFileset()) { -// System.out.println("## " + FilesetDV.class.getSimpleName() + " n." + i); -// System.out.println(fileSet); -// i++; -// } -// -// } -// } -// -//} diff --git a/src/main/webapp/GeoportalDataViewer.css b/src/main/webapp/GeoportalDataViewer.css index d4a1751..b6c6545 100644 --- a/src/main/webapp/GeoportalDataViewer.css +++ b/src/main/webapp/GeoportalDataViewer.css @@ -892,4 +892,8 @@ RESPONSIVE .filter-panel-style label { font-weight: bold; } +/* END CUSTOM OVERLAY UI */ +.opacity-09 { + opacity: 0.9; +} From 3644685fe5672173b8fbd8b6b47390898577aa45 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 9 Jun 2023 10:28:46 +0200 Subject: [PATCH 18/18] Improved search facility --- .../client/GeoportalDataViewer.java | 9 +++++---- .../client/GeoportalDataViewerConstants.java | 7 +++++-- .../ui/cms/search/SearchFacilityUI.java | 19 ++++++++++--------- 3 files changed, 20 insertions(+), 15 deletions(-) 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 40ff90a..d72cfac 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 @@ -853,15 +853,15 @@ public class GeoportalDataViewer implements EntryPoint { String newCqlFilter = null; // default -// setCqlFilter = "INTERSECTS(geom,querySingle('limiti_amministrativi:regioni','the_geom','DEN_REG=''Calabria'''));INCLUDE"; -// GWT.log("HARD-CODED CQL FILTER: "+setCqlFilter); - if (layerName == null) { GWT.log("CQL FILTER skipped, layerName is NULL!!"); return; } - if (result != null && result.size() > 0) { + // Applying CQL filter only if there are results and its number are less or + // equal to SEARCH_LIMIT_RESULTS_TO_MAXIMUM + if (result != null && result.size() > 0 + && result.size() <= GeoportalDataViewerConstants.SEARCH_LIMIT_RESULTS_TO_MAXIMUM) { String cqlFilter = GeoportalDataViewerConstants.PROJECT_ID_KEY_FEATURE + " IN("; for (String projectId : result) { cqlFilter += "'" + projectId + "',"; @@ -883,6 +883,7 @@ public class GeoportalDataViewer implements EntryPoint { GWT.log("New CQL Filter is: " + newCqlFilter); + // Resetting CQL Filter if (layerName != null) layerManager.setCQLForLayerToIndexLayer(layerName, newCqlFilter); 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 89b4ac6..c1391e4 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 @@ -25,7 +25,9 @@ public class GeoportalDataViewerConstants { public static final String GET_MAX_ZOOM_LEVEL = OpenLayersMapParameters.OL_MAP_PARAM.maxzoomlevel.name(); public static final String GET_ZOOM = OpenLayersMapParameters.OL_MAP_PARAM.zoom.name(); public static final String GET_CENTER_MAP_TO_LONG_LAT = OpenLayersMapParameters.OL_MAP_PARAM.centermap.name(); - + + public static final int SEARCH_LIMIT_RESULTS_TO_MAXIMUM = 50; + public static final DateTimeFormat DATE_TIME_FORMAT = DateTimeFormat.getFormat("dd MMMM yyyy"); public static enum MapEventType { @@ -152,7 +154,8 @@ public class GeoportalDataViewerConstants { var tabCell = tr.insertCell(-1); var theValue = jsonObj[j][col[i]]; //console.log("the value: "+theValue); - if (theValue !== null && Object.prototype.toString.call(theValue) === '[object Array]') { + if (theValue !== null + && Object.prototype.toString.call(theValue) === '[object Array]') { var formattedValueArray = ""; for (var k = 0; k < theValue.length; k++) { var theValueArray = theValue[k]; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java index 43d0916..cbdd963 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java @@ -15,6 +15,7 @@ import org.gcube.application.geoportalcommon.shared.WhereClause; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; +import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync; import org.gcube.portlets.user.geoportaldataviewer.client.events.ClosedViewDetailsEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEvent; @@ -61,8 +62,6 @@ import com.google.gwt.user.client.ui.Widget; */ public class SearchFacilityUI extends Composite { - private static final int SEARCHING_LIMIT_RESULTS_TO = 50; - private static SearchFacilityPanelUiBinder uiBinder = GWT.create(SearchFacilityPanelUiBinder.class); protected static final int MIN_LENGHT_SERCHING_STRING = 3; @@ -272,8 +271,9 @@ public class SearchFacilityUI extends Composite { panelResults.clear(); panelResults.add(new HTML("
")); panelResults.add(new LoaderIcon("Searching...")); - GeoportalDataViewerServiceAsync.Util.getInstance().getListProjects(profileID, 0, SEARCHING_LIMIT_RESULTS_TO, - filter, false, new AsyncCallback() { + GeoportalDataViewerServiceAsync.Util.getInstance().getListProjects(profileID, 0, + GeoportalDataViewerConstants.SEARCH_LIMIT_RESULTS_TO_MAXIMUM, filter, false, + new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -313,13 +313,14 @@ public class SearchFacilityUI extends Composite { + "). Please find below the top " + returnedItems + ".
"; } else if (returnedItems > 0) { message = "Found " + returnedItems; - message += returnedItems > 0 ? " items" : " item"; - message += ". "; + message += returnedItems > 0 ? " projects" : " project"; + message += "."; } -// if (returnedItems > 0) { -// message += "On the map you can see all the projects with a centroid matching the query"; -// } + if (returnedItems > 0 + && returnedItems <= GeoportalDataViewerConstants.SEARCH_LIMIT_RESULTS_TO_MAXIMUM) { + message += "On the map you can see all the projects with a centroid matching the query"; + } HTML resultMessage = new HTML(message); resultMessage.getElement().addClassName("search_result_msg");