From 16d9feffe0de59bddf6ca2b4ca722c496a755cbb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 25 May 2023 11:28:25 +0200 Subject: [PATCH] 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; - } - }