From 538f87f1d11b9ce8589984abe79f73710df02d8c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 12 Nov 2020 18:25:24 +0100 Subject: [PATCH] added Application Profile to read available layers --- .../client/GeoportalDataViewer.java | 124 +++++++++--- .../client/GeoportalDataViewerConstants.java | 1 + .../client/GeoportalDataViewerService.java | 12 ++ .../GeoportalDataViewerServiceAsync.java | 5 + .../client/LayerManager.java | 53 ++++- .../client/gis/LightOpenLayerOSM.java | 5 - .../client/ui/map/MapView.java | 6 +- .../ApplicationProfileNotFoundException.java | 20 ++ .../server/GeoNaDataViewerProfileReader.java | 181 ++++++++++++++++++ .../GeoportalDataViewerServiceImpl.java | 96 ++++++++-- .../server/gis/WMSUrlValidator.java | 19 +- .../shared/GeoNaDataViewerProfile.java | 81 ++++++++ .../shared/gis/LayerItem.java | 28 ++- 13 files changed, 553 insertions(+), 78 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/ApplicationProfileNotFoundException.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoNaDataViewerProfileReader.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaDataViewerProfile.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 cd03e2f..0e7ad53 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 @@ -1,5 +1,6 @@ package org.gcube.portlets.user.geoportaldataviewer.client; +import java.util.Iterator; import java.util.List; import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent; @@ -7,8 +8,9 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEven import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils; import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM; import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel; -import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; +import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataViewerProfile; import org.gcube.portlets.user.geoportaldataviewer.shared.ProductType; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow; import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV; @@ -58,6 +60,9 @@ public class GeoportalDataViewer implements EntryPoint { /** The param UUID. */ private String paramUUID; + /** The param UUID. */ + private String layerType; + /** The param layer title. */ private String paramLayerTitle; @@ -104,42 +109,109 @@ public class GeoportalDataViewer implements EntryPoint { // }); paramWmsRequest = Window.Location.getParameter(GeoportalDataViewerConstants.GET_WMS_PARAMETER); + layerType = Window.Location.getParameter(GeoportalDataViewerConstants.GET_DISPLAY_LAYER_TYPE); paramUUID = Window.Location.getParameter(GeoportalDataViewerConstants.GET_UUID_PARAMETER); paramLayerTitle = Window.Location.getParameter(GeoportalDataViewerConstants.GET_LAYER_TITLE); GWT.log(GeoportalDataViewerConstants.GET_WMS_PARAMETER + " = " + paramWmsRequest); + GWT.log(GeoportalDataViewerConstants.GET_DISPLAY_LAYER_TYPE + " = " + layerType); GWT.log(GeoportalDataViewerConstants.GET_UUID_PARAMETER + " = " + paramUUID); GWT.log(GeoportalDataViewerConstants.GET_LAYER_TITLE + " = " + paramLayerTitle); + + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { - if (paramWmsRequest != null && !paramWmsRequest.isEmpty()) { - - try { - //wmsRequestConverter.addRequestToGisViewer(paramWmsRequest, paramLayerTitle, paramUUID); - //FIND BASE URL - int indexStart = paramWmsRequest.indexOf("?"); - String url; - if(indexStart>=0){ - url = paramWmsRequest.substring(0, indexStart); //get only base uri - url = url.trim(); //string trim - }else{ - Window.alert("Bad wms request '?' not found!"); -// throw new Exception("Bad server request '?' not found!"); - } - - String layerName = URLUtil.getValueOfParameter("layers", paramWmsRequest); - String displayName = paramLayerTitle==null || paramLayerTitle.isEmpty()?layerName:paramLayerTitle; - Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + GeoportalDataViewerServiceAsync.Util.getInstance().getGeoNaDataViewProfile(new AsyncCallback() { @Override - public void execute() { - layerManager.addLayerByWmsRequest(displayName, layerName, paramWmsRequest, false, false, paramUUID, true); + public void onFailure(Throwable caught) { + Window.alert(caught.getMessage()); + + } + + @Override + public void onSuccess(GeoNaDataViewerProfile result) { + GWT.log("Profile: "+result); + Iterator it; + if(layerType==null) { + it = result.getMapLayers().keySet().iterator(); + it.hasNext(); + layerType= it.next(); + } + + LayerItem layerItem = result.getMapLayers().get(layerType); + + if(layerItem==null) { + Window.alert("Not detected any layer for "+layerType); + return; + } + GWT.log("The layerItem is: "+layerItem); + layerManager.addLayerByWmsRequest(null, null, layerItem.getWmsLink(), false, false, null, true); } }); - - } catch (Exception e) { - GWT.log("An error occurred on adding wmsrequest :" + paramWmsRequest, e); - e.printStackTrace(); } - } + }); + +// if (paramWmsRequest != null && !paramWmsRequest.isEmpty()) { +// +// try { +// //wmsRequestConverter.addRequestToGisViewer(paramWmsRequest, paramLayerTitle, paramUUID); +// //FIND BASE URL +// /*int indexStart = paramWmsRequest.indexOf("?"); +// String url; +// if(indexStart>=0){ +// url = paramWmsRequest.substring(0, indexStart); //get only base uri +// url = url.trim(); //string trim +// }else{ +// Window.alert("Bad wms request '?' not found!"); +//// throw new Exception("Bad server request '?' not found!"); +// } +// +// String layerName = URLUtil.getValueOfParameter("layers", paramWmsRequest); +// String displayName = paramLayerTitle==null || paramLayerTitle.isEmpty()?layerName:paramLayerTitle; +// Scheduler.get().scheduleDeferred(new ScheduledCommand() { +// +// @Override +// public void execute() { +// layerManager.addLayerByWmsRequest(displayName, layerName, paramWmsRequest, false, false, paramUUID, true); +// +// } +// });*/ +// Scheduler.get().scheduleDeferred(new ScheduledCommand() { +// +// @Override +// public void execute() { +// GWT.log("qui"); +// GeoportalDataViewerServiceAsync.Util.getInstance().getGeoNaDataViewProfile(new AsyncCallback() { +// +// @Override +// public void onFailure(Throwable caught) { +// Window.alert(caught.getMessage()); +// +// } +// +// @Override +// public void onSuccess(GeoNaDataViewerProfile result) { +// GWT.log("Profile: "+result); +// Iterator it; +// if(layerType==null) { +// it = result.getMapLayers().keySet().iterator(); +// it.hasNext(); +// layerType= it.next(); +// } +// layerManager.addLayerByType(layerType); +// } +// }); +// } +// }); +// +// +// } catch (Exception e) { +// GWT.log("An error occurred on adding wmsrequest :" + paramWmsRequest, e); +// e.printStackTrace(); +// } +// } bindEvents(); } 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 7352618..decc1eb 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 @@ -10,6 +10,7 @@ public class GeoportalDataViewerConstants { public static final String MAP_DIV = "map"; public static final String GET_WMS_PARAMETER = "wmsrequest"; + public static final String GET_DISPLAY_LAYER_TYPE = "dlt"; public static final String GET_UUID_PARAMETER = "uuid"; public static final String GET_LAYER_TITLE = "layertitle"; public static final String GET_MAX_ZOOM_LEVEL = OpenLayersMapParameters.OL_MAP_PARAM.maxzoomlevel.name(); 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 ee579d6..147407b 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 @@ -3,6 +3,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client; import java.util.List; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataObject; +import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataViewerProfile; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; @@ -26,4 +27,15 @@ public interface GeoportalDataViewerService extends RemoteService { String getMyLogin(); + /** + * Gets the layer for type. + * + * @param layerType the layer type + * @return the layer for type + * @throws Exception the exception + */ + GeoInformationForWMSRequest getLayerForType(String layerType) throws Exception; + + GeoNaDataViewerProfile getGeoNaDataViewProfile() throws Exception; + } 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 ae8e029..805c51f 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 @@ -3,6 +3,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client; import java.util.List; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataObject; +import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataViewerProfile; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; @@ -38,4 +39,8 @@ public interface GeoportalDataViewerServiceAsync { void getConcessioneForId(Long id, AsyncCallback callback); void getMyLogin(AsyncCallback callback); + + void getLayerForType(String layerType, AsyncCallback callback); + + void getGeoNaDataViewProfile(AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java index 707681e..56d61de 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 @@ -1,3 +1,6 @@ +/* + * + */ package org.gcube.portlets.user.geoportaldataviewer.client; import java.util.ArrayList; @@ -62,7 +65,8 @@ public class LayerManager { /** * Instantiates a new layer manager. - * @param applicationBus + * + * @param applicationBus the application bus */ public LayerManager(HandlerManager applicationBus) { this.applicationBus = applicationBus; @@ -70,6 +74,9 @@ public class LayerManager { } + /** + * Bind events. + */ private void bindEvents() { eventBus.addHandler(QueryDataEvent.TYPE, new QueryDataEventHandler() { @@ -266,14 +273,36 @@ public class LayerManager { @Override public void onSuccess(GeoInformationForWMSRequest result) { - GWT.log("Add Layer By WMS: "+result.getMapWMSNoStandard() + ", and isNCWMS? "+result.isNcWMS()); - addLayerByWms(featureType, layerTitle, layerName, result.getWmsRequest(), result.getBaseWmsServiceHost(), true, isBase, displayInLayerSwitcher, (ArrayList) result.getStyles().getGeoStyles(), result.getWmsRequest(), false, result.getMapWMSNoStandard(), result.isNcWMS(), UUID, result.getZAxis()); + GWT.log("Add Layer By WMS: "+result.getWmsRequest() + ", and isNCWMS? "+result.isNcWMS()); + addLayerByWms(featureType, layerTitle, result.getLayerName(), result.getWmsRequest(), result.getBaseWmsServiceHost(), true, isBase, displayInLayerSwitcher, (ArrayList) result.getStyles().getGeoStyles(), result.getWmsRequest(), false, result.getMapWMSNoStandard(), result.isNcWMS(), UUID, result.getZAxis()); } }); } - +// public void addLayerByType(String layerType) { +// +// final boolean isBase = false; +// final LayerType featureType = isBase?LayerType.RASTER_BASELAYER:LayerType.FEATURE_TYPE; +// boolean displayInLayerSwitcher = false; +// GeoportalDataViewerServiceAsync.Util.getInstance().getLayerForType(layerType, new AsyncCallback() { +// +// @Override +// public void onFailure(Throwable caught) { +// Window.alert(caught.getMessage()); +// +// } +// +// @Override +// public void onSuccess(GeoInformationForWMSRequest result) { +// GWT.log("Add Layer By WMS: "+result.getMapWMSNoStandard() + ", and isNCWMS? "+result.isNcWMS()); +// addLayerByWms(featureType, result.getLayerName(), result.getLayerName(), result.getWmsRequest(), result.getBaseWmsServiceHost(), true, isBase, displayInLayerSwitcher, (ArrayList) result.getStyles().getGeoStyles(), result.getWmsRequest(), false, result.getMapWMSNoStandard(), result.isNcWMS(), null, result.getZAxis()); +// +// } +// }); +// +// } + /** * Adds the layer by wms. * @@ -286,14 +315,14 @@ public class LayerManager { * @param isBase the is base * @param displayInLayerSwitcher the display in layer switcher * @param styles the styles - * @param serverWmsRequest the server wms request + * @param wmsLink the wms link * @param onTop the on top * @param wmsNotStandardParams the wms not standard params * @param isNcWms the is nc wms * @param UUID the uuid * @param zAxis the z axis */ - private void addLayerByWms(LayerType layerType, String layerTitle, String layerName, String layerURL, String mapServerHost, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, ArrayList styles, String serverWmsRequest, boolean onTop, HashMap wmsNotStandardParams, boolean isNcWms, String UUID, ZAxis zAxis) { + private void addLayerByWms(LayerType layerType, String layerTitle, String layerName, String layerURL, String mapServerHost, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, ArrayList styles, String wmsLink, boolean onTop, HashMap wmsNotStandardParams, boolean isNcWms, String UUID, ZAxis zAxis) { // GWT.log("Add addLayerByWms 1"); LayerItem layerItem = new LayerItem(); @@ -305,7 +334,7 @@ public class LayerManager { //l.setExternal(isExternal); layerItem.setOpacity(1d); layerItem.setBuffer(2); - layerItem.setServerWmsRequest(serverWmsRequest); + layerItem.setWmsLink(wmsLink); layerItem.setWmsNotStandardParams(wmsNotStandardParams); layerItem.setNcWms(isNcWms); layerItem.setUUID(UUID); @@ -340,7 +369,7 @@ public class LayerManager { layerItem.setStyle(styles.get(0)); layerItem.setStyles(styles); }else{ - String style = URLUtil.getValueOfParameter("styles", serverWmsRequest); + String style = URLUtil.getValueOfParameter("styles", wmsLink); if(style!=null){ //CASE OF STYLE =""; //TENTATIVE TO GET LEGEND layerItem.setHasLegend(true); @@ -376,9 +405,17 @@ public class LayerManager { this.olMap = olMap; } + /** + * Gets the event bus. + * + * @return the event bus + */ public HandlerManager getEventBus() { return eventBus; } + + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java index ee1d259..209f64e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/gis/LightOpenLayerOSM.java @@ -15,7 +15,6 @@ import ol.MapOptions; import ol.OLFactory; import ol.View; import ol.ViewOptions; -import ol.color.Color; import ol.control.Attribution; import ol.event.EventListener; import ol.geom.Point; @@ -32,12 +31,8 @@ import ol.source.ImageWmsOptions; import ol.source.ImageWmsParams; import ol.source.Osm; import ol.source.XyzOptions; -import ol.style.Fill; -import ol.style.FillOptions; import ol.style.Icon; import ol.style.IconOptions; -import ol.style.Stroke; -import ol.style.StrokeOptions; import ol.style.Style; import ol.style.Text; import ol.style.TextOptions; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java index bd1ddc3..f8184b8 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/map/MapView.java @@ -118,9 +118,9 @@ import ol.OLFactory; ExtentWrapped ew = new ExtentWrapped(lowerCoord.getX(), lowerCoord.getY(), upperCoord.getX(), upperCoord.getY()); - Coordinate center = ew.getCenter(); - GWT.log("center: "+center); - Coordinate invertCoordinate = new Coordinate(center.getY(), center.getX()); + //Coordinate center = ew.getCenter(); + //GWT.log("center: "+center); + //Coordinate invertCoordinate = new Coordinate(center.getY(), center.getX()); // Size size = new Size(300, 300); //olsm.getMap().getView().setCenter(invertCoordinate); olsm.getMap().getView().fit(ew); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/ApplicationProfileNotFoundException.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/ApplicationProfileNotFoundException.java new file mode 100644 index 0000000..436675c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/ApplicationProfileNotFoundException.java @@ -0,0 +1,20 @@ +package org.gcube.portlets.user.geoportaldataviewer.server; + +/** + * The Class ApplicationProfileException. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it + * Sep 6, 2016 + */ +@SuppressWarnings("serial") +public class ApplicationProfileNotFoundException extends Exception { + + /** + * Instantiates a new application profile exception. + * + * @param message the message + */ + public ApplicationProfileNotFoundException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoNaDataViewerProfileReader.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoNaDataViewerProfileReader.java new file mode 100644 index 0000000..1ad011a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoNaDataViewerProfileReader.java @@ -0,0 +1,181 @@ +package org.gcube.portlets.user.geoportaldataviewer.server; + +import static org.gcube.resources.discovery.icclient.ICFactory.client; + +import java.io.StringReader; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import org.gcube.common.resources.gcore.utils.XPathHelper; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataViewerProfile; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.Query; +import org.gcube.resources.discovery.client.queries.impl.QueryBox; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + + + +/** + * The Class GeoNaViewerProfileReader. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Nov 12, 2020 + */ +public class GeoNaDataViewerProfileReader { + + private static final String RESOURCE_PROFILE_BODY_PORTLET_URL = "/Resource/Profile/Body/PortletURL"; + /** + * + */ + public static final String SECONDARY_TYPE = "ApplicationProfile"; + public static final String WORKSPACE_EXPLORER_APP_NAME = "GeoNa-Viewer-Profile"; + + private Logger logger = LoggerFactory.getLogger(GeoNaDataViewerProfileReader.class); + private String secondaryType; + private String scope; + private String appID; + + /** + * Instantiates a new application profile reader. + * + * @param appID the app id + */ + public GeoNaDataViewerProfileReader(String appID) { + + this.appID = appID; + this.secondaryType = SECONDARY_TYPE; + this.scope = ScopeProvider.instance.get(); + } + + /** + * Read profile from infrastrucure. + * + * @return the map + */ + public GeoNaDataViewerProfile readProfileFromInfrastrucure() throws Exception { + + String queryString = getGcubeGenericQueryString(secondaryType, appID); + logger.info("Scope "+scope+", trying to perform query: "+queryString); + + try { + + if (scope == null) + throw new Exception("Scope is null, set scope into ScopeProvider"); + + GeoNaDataViewerProfile profile = new GeoNaDataViewerProfile(); + + logger.info("Trying to fetch ApplicationProfile in the scope: " + scope + ", SecondaryType: " + + secondaryType + ", AppId: " + appID); + Query q = new QueryBox(queryString); + DiscoveryClient client = client(); + List appProfile = client.submit(q); + + if (appProfile == null || appProfile.size() == 0) + throw new ApplicationProfileNotFoundException("ApplicationProfile with SecondaryType: " + secondaryType + + ", AppId: " + appID + " is not registered in the scope: " + scope); + else { + String elem = appProfile.get(0); + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document doc = docBuilder.parse(new InputSource(new StringReader(elem))); + + XPathHelper helper = new XPathHelper(doc.getDocumentElement()); + + List currValue = null; + String portletURL = null; + currValue = helper.evaluate(RESOURCE_PROFILE_BODY_PORTLET_URL+"/text()"); + if (currValue != null && currValue.size() > 0) { + portletURL = currValue.get(0); + }else + throw new Exception("I'm not able to read the path: "+RESOURCE_PROFILE_BODY_PORTLET_URL); + + + XPath xPath = XPathFactory.newInstance().newXPath(); + NodeList nodeList = (NodeList) xPath.compile("/Resource/Profile/Body/AvailableLayers/Layer") + .evaluate(doc, XPathConstants.NODESET); + + Map mapLayers = new HashMap(nodeList.getLength()); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node layerNode = nodeList.item(i); + if (layerNode.getNodeType() == Node.ELEMENT_NODE) { + Element eElement = (Element) layerNode; + String layerType = eElement.getElementsByTagName("Type").item(0).getTextContent(); + String wmsLink = eElement.getElementsByTagName("WMS_LINK").item(0).getTextContent(); + String decodedURL = URLDecoder.decode(wmsLink, "UTF-8"); + LayerItem layer = new LayerItem(); + layer.setWmsLink(decodedURL); + mapLayers.put(layerType.toLowerCase(), layer); + } + } + + profile.setPortletURL(portletURL); + profile.setMapLayers(mapLayers); + logger.info("returning: "+profile); + return profile; + } + + } catch (Exception e) { + logger.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType " + + WORKSPACE_EXPLORER_APP_NAME + " from scope " + scope, e); + return null; + } finally { + + } + + } + + /** + * Gets the gcube generic query string. + * + * @param secondaryType the secondary type + * @param appId the app id + * @return the gcube generic query string + */ + public static String getGcubeGenericQueryString(String secondaryType, String appId) { + + return "for $profile in collection('/db/Profiles/GenericResource')//Resource " + + "where $profile/Profile/SecondaryType/string() eq '" + secondaryType + + "' and $profile/Profile/Body/AppId/string() " + " eq '" + appId + "'" + "return $profile"; + } + + /** + * Gets the secondary type. + * + * @return the secondary type + */ + public String getSecondaryType() { + return secondaryType; + } + + /** + * Gets the scope. + * + * @return the scope + */ + public String getScope() { + return scope; + } + + @Override + public String toString() { + return "GeoNaViewerProfileReader [secondaryType=" + secondaryType + ", scope=" + scope + ", appID=" + appID + + "]"; + } +} 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 a4637f4..0324ada 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 @@ -14,6 +14,7 @@ import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator; import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil; import org.gcube.portlets.user.geoportaldataviewer.server.util.URLParserUtil; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataObject; +import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataViewerProfile; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; @@ -32,6 +33,10 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet; /** * The server side implementation of the RPC service. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Nov 12, 2020 */ @SuppressWarnings("serial") public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet implements @@ -41,21 +46,31 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme /** The Constant LOG. */ private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerServiceImpl.class); + /** + * Parses the wms request. + * + * @param wmsRequest the wms request + * @param layerName the layer name + * @return the geo information for WMS request + * @throws Exception the exception + */ @Override public GeoInformationForWMSRequest parseWmsRequest(String wmsRequest, String layerName) throws Exception { return loadGeoInfoForWmsRequest(wmsRequest, layerName); } - /* Load geo info for wms request. + + /** + * Load geo info for wms request. * - * @param wmsRequest the wms request + * @param wmsLink the wms link * @param layerName the layer name - * @return the gis viewer wms valid parameters + * @return the geo information for WMS request * @throws Exception the exception */ - public static GeoInformationForWMSRequest loadGeoInfoForWmsRequest(String wmsRequest, String layerName) throws Exception{ + public static GeoInformationForWMSRequest loadGeoInfoForWmsRequest(String wmsLink, String layerName) throws Exception{ try { - WMSUrlValidator validator = new WMSUrlValidator(wmsRequest, layerName); + WMSUrlValidator validator = new WMSUrlValidator(wmsLink, layerName); String wmsServiceHost = validator.getWmsServiceHost(); String validWMSRequest = validator.parseWMSRequest(true, true); layerName = validator.getLayerName(); @@ -89,6 +104,16 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } } + /** + * Gets the data result. + * + * @param layerItems the layer items + * @param mapSrsName the map srs name + * @param selectBBOX the select BBOX + * @param maxWFSFeature the max WFS feature + * @param zoomLevel the zoom level + * @return the data result + */ /* * (non-Javadoc) * @@ -104,17 +129,17 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return result; } + /** + * Gets the concessione for id. + * + * @param id the id + * @return the concessione for id + * @throws Exception the exception + */ @Override public ConcessioneDV getConcessioneForId(Long id) throws Exception{ LOG.info("getConcessioneForId "+id+ "called"); -// if(!SessionUtil.isIntoPortal()) { -// LOG.warn("OUT OF PORTAL setting HARD-CODED SCOPE"); -// String scope = "/gcube/devNext/NextNext"; -// LOG.warn("SCOPE is: "+scope); -// ScopeProvider.instance.set(scope); -// } - ConcessioneDV concessionDV = null; if(id==null) @@ -197,5 +222,52 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return null; } } + + /** + * Gets the layer for type. + * + * @param layerType the layer type + * @param fallbackOnError the fallback on error + * @return the layer for type + * @throws Exception the exception + */ + @Override + public GeoInformationForWMSRequest getLayerForType(String layerType) throws Exception{ + LOG.info("Called getLayerForType for:"+layerType); + + if(layerType==null || layerType.isEmpty()) + throw new Exception("The input parameter layerType is null or empty"); + + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + GeoNaDataViewerProfileReader gdvp = new GeoNaDataViewerProfileReader("geoportal-data-viewer-app"); + GeoNaDataViewerProfile profile = gdvp.readProfileFromInfrastrucure(); + LOG.info("Read profile: "+profile); + + String lowerLayerType = layerType.toLowerCase(); + LOG.info("Reading map layers for type:"+lowerLayerType); + LayerItem layer = profile.getMapLayers().get(lowerLayerType); + + if(layer==null || layer.getWmsLink()==null) + throw new Exception("The layer type "+lowerLayerType+" has not been found. Please check your input parameter"); + + if(layer.getWmsLink()==null) + throw new Exception("The layer type "+lowerLayerType+" has not a WMS Link associated. Please check your input parameter"); + + + return parseWmsRequest(layer.getWmsLink(), null); + } + + + @Override + public GeoNaDataViewerProfile getGeoNaDataViewProfile() throws Exception{ + LOG.info("Called getAvailableLayers"); + + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + GeoNaDataViewerProfileReader gdvp = new GeoNaDataViewerProfileReader("geoportal-data-viewer-app"); + GeoNaDataViewerProfile profile = gdvp.readProfileFromInfrastrucure(); + LOG.info("Returning profile: "+profile); + return profile; + } + } 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 4eb3ac2..8e22431 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 @@ -35,15 +35,18 @@ public class WMSUrlValidator { private static final Logger LOG = LoggerFactory.getLogger(WMSUrlValidator.class); - + /** - * Instantiates a new gis viewer wms url validator. + * Instantiates a new WMS url validator. * - * @param wmsRequest the full url - * @param layerName the layer name + * @param wmsRequest the wms request + * @param inputLayerName the input layer name * @throws Exception the exception */ - public WMSUrlValidator(String wmsRequest, String layerName) throws Exception{ + public WMSUrlValidator(String wmsRequest, String inputLayerName) throws Exception{ + LOG.debug("WMSURLValidator wmsRequest: "+wmsRequest); + LOG.debug("WMSURLValidator layerName: "+inputLayerName); + if(wmsRequest==null || wmsRequest.isEmpty()) throw new Exception("WMS request is null or empty"); @@ -57,13 +60,13 @@ public class WMSUrlValidator { LOG.trace("found "+GeoWmsServiceUtility.SERVICE_WMS+" in wms request: "+wmsRequestURI); webMapServerHost = getWebMapServerHost(wmsRequestURI); }else - throw new Exception("WMS service not found for layer: "+layerName); + throw new Exception("WMS service not found for layer: "+inputLayerName); //VALIDATION WMS String baseWmsService = webMapServerHost.getHost(); //IS OWS OR WMS? this.wmsServiceHost = appendWmsServiceToBaseUrl(wmsRequest.substring(0, wmsRequest.indexOf("?")),isOwsService); - this.layerName = layerName; + this.layerName = inputLayerName; try { //VALIDATE WMS SERVICE FOR WEB MAP SERVER @@ -82,7 +85,7 @@ public class WMSUrlValidator { if(this.layerName==null || this.layerName.isEmpty()){ this.layerName = WmsUrlValidator.getValueOfParameter(WmsParameters.LAYERS, wmsRequest); - if(this.layerName==null || layerName.isEmpty()) + if(this.layerName==null || this.layerName.isEmpty()) throw new Exception("Layer name is null or empty"); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaDataViewerProfile.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaDataViewerProfile.java new file mode 100644 index 0000000..e2ba29c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaDataViewerProfile.java @@ -0,0 +1,81 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared; + +import java.io.Serializable; +import java.util.Map; + +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; + +import com.google.gwt.user.client.rpc.IsSerializable; + + +/** + * The Class GeoNaDataViewerProfile. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Nov 12, 2020 + */ +public class GeoNaDataViewerProfile implements IsSerializable, Serializable{ + + /** + * + */ + private static final long serialVersionUID = 8583236018312392009L; + private String portletURL; + //the key is the layer type + private Map mapLayers; + + /** + * Instantiates a new geo na data viewer profile. + */ + public GeoNaDataViewerProfile() { + + } + + /** + * Gets the portlet URL. + * + * @return the portlet URL + */ + public String getPortletURL() { + return portletURL; + } + + /** + * Sets the portlet URL. + * + * @param portletURL the new portlet URL + */ + public void setPortletURL(String portletURL) { + this.portletURL = portletURL; + } + + /** + * Gets the map layers. + * + * @return the map layers + */ + public Map getMapLayers() { + return mapLayers; + } + + /** + * Sets the map layers. + * + * @param mapLayers the map layers + */ + public void setMapLayers(Map mapLayers) { + this.mapLayers = mapLayers; + } + + /** + * To string. + * + * @return the string + */ + @Override + public String toString() { + return "GeoNaDataViewerProfile [portletURL=" + portletURL + ", mapLayers=" + mapLayers + "]"; + } + +} 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 b4df034..c2cbd5e 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 @@ -94,7 +94,7 @@ public class LayerItem implements Serializable, Cloneable { private boolean isNcWms = false; /** The server wms request. */ - public String serverWmsRequest; + public String wmsLink; /** The cql filter available. */ private boolean cqlFilterAvailable = false; @@ -759,21 +759,21 @@ public class LayerItem implements Serializable, Cloneable { } /** - * Gets the server wms request. + * Gets the wms link. * - * @return the server wms request + * @return the wms link */ - public String getServerWmsRequest() { - return serverWmsRequest; + public String getWmsLink() { + return wmsLink; } /** - * Sets the server wms request. + * Sets the wms link. * - * @param serverWmsRequest the new server wms request + * @param wmsLink the new wms link */ - public void setServerWmsRequest(String serverWmsRequest) { - this.serverWmsRequest = serverWmsRequest; + public void setWmsLink(String wmsLink) { + this.wmsLink = wmsLink; } /** @@ -848,11 +848,6 @@ public class LayerItem implements Serializable, Cloneable { this.zAxisSelected = zAxisSelected; } - /** - * To string. - * - * @return the string - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -904,8 +899,8 @@ public class LayerItem implements Serializable, Cloneable { builder.append(wmsNotStandardParams); builder.append(", isNcWms="); builder.append(isNcWms); - builder.append(", serverWmsRequest="); - builder.append(serverWmsRequest); + builder.append(", wmsLink="); + builder.append(wmsLink); builder.append(", cqlFilterAvailable="); builder.append(cqlFilterAvailable); builder.append(", UUID="); @@ -918,4 +913,5 @@ public class LayerItem implements Serializable, Cloneable { return builder.toString(); } + }