diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/ApplicationController.java b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/ApplicationController.java index 15c8a6d..68e1fed 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/ApplicationController.java +++ b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/ApplicationController.java @@ -3,21 +3,29 @@ */ package org.gcube.portlets.user.gisviewerapp.client; +import java.util.Date; + import org.gcube.portlets.user.gisviewer.client.Constants; import org.gcube.portlets.user.gisviewer.client.DataPanelOpenListener; import org.gcube.portlets.user.gisviewer.client.GisViewerPanel; import org.gcube.portlets.user.gisviewer.client.GisViewerParameters; +import org.gcube.portlets.user.gisviewerapp.client.resources.Images; +import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.ComponentEvent; import com.extjs.gxt.ui.client.event.Events; import com.extjs.gxt.ui.client.event.Listener; +import com.extjs.gxt.ui.client.event.SelectionListener; import com.extjs.gxt.ui.client.fx.Resizable; import com.extjs.gxt.ui.client.widget.Component; import com.extjs.gxt.ui.client.widget.ContentPanel; import com.extjs.gxt.ui.client.widget.LayoutContainer; import com.extjs.gxt.ui.client.widget.layout.FitLayout; import com.google.gwt.core.shared.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.Cookies; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.DialogBox; @@ -45,6 +53,9 @@ public class ApplicationController { private final ApplicationController INSTANCE = this; @SuppressWarnings("unused") private RootPanel gwtRootPanel; + private static final String GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_DATA_POINT_QUERY= "GCUBE-Cookie_GeoWPSQuery_DataPoint_Authorization"; + private static final String GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_BOX_QUERY = "GCUBE-Cookie_GeoWPSQuery_Box_Authorization"; + public static final long MILLISECS_PER_DAY = 1000L * 60L * 60L * 24L; /** * */ @@ -121,8 +132,45 @@ public class ApplicationController { String uuid = Window.Location.getParameter(ConstantGisViewerApp.GET_UUID_PARAMETER); GWT.log(ConstantGisViewerApp.GET_WMS_PARAMETER+ " = "+wmsRequest); GWT.log(ConstantGisViewerApp.GET_UUID_PARAMETER+ " = "+uuid); -// String replacement = Window.Location.getParameter(ConstantGisViewerApp.WMS_PARAM_SEPARATOR_REPLACEMENT_KEY); -// ConstantGisViewerApp.logger.log(Level.INFO, ConstantGisViewerApp.WMS_PARAM_SEPARATOR_REPLACEMENT_KEY+ " is "+replacement); + + boolean displayWarning = readCookieWPSQueryAuthorization(GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_DATA_POINT_QUERY); + GWT.log("Display "+GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_DATA_POINT_QUERY+"? "+displayWarning); + + if(displayWarning){ + gisViewerPanel.getToolBarPanel().getClickDataToggle().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(ButtonEvent ce) { + + if(!gisViewerPanel.getToolBarPanel().getClickDataToggle().isPressed()) + return; + + boolean warning = readCookieWPSQueryAuthorization(GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_DATA_POINT_QUERY); + if(warning) + showWarningForWPSService("Warning: gCube authorization required", "You must be authorized to perform the 'Data point query'. Some data could be not available because you are not authorized to contact gCube WPS service", GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_DATA_POINT_QUERY); + } + }); + } + + displayWarning = readCookieWPSQueryAuthorization(GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_BOX_QUERY); + GWT.log("Display "+GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_BOX_QUERY+"? "+displayWarning); + + if(displayWarning){ + gisViewerPanel.getToolBarPanel().getBoxDataToggle().addSelectionListener(new SelectionListener() { + + @Override + public void componentSelected(ButtonEvent ce) { + + if(!gisViewerPanel.getToolBarPanel().getBoxDataToggle().isPressed()) + return; + + boolean warning = readCookieWPSQueryAuthorization(GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_BOX_QUERY); + if(warning) + showWarningForWPSService("Warning: gCube authorization required", "You must be authorized to perform the 'Data box query'. Some data could be not available because you are not authorized to contact gCube WPS service", GCUBE_COOKIE_SHOW_WARNING_FOR_WPS_BOX_QUERY); + + } + }); + } if(wmsRequest!=null && !wmsRequest.isEmpty()){ @@ -173,6 +221,66 @@ public class ApplicationController { } + private void showWarningForWPSService(String title, String msg, final String cookieName){ + + final DialogResult dialog = new DialogResult(Images.iconWarning().createImage(), title, msg); + dialog.getElement().getStyle().setZIndex(10000); + + dialog.getCloseButton().addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + if(dialog.getCheckShowAgain().getValue()) + setCookie(cookieName, "false", 30); + } + }); + dialog.center(); + } + + /** + * Read cookie workspace available features. + * + * @return true if exists a cookie with msg as true value (or not exists the cookie), false otherwise + */ + private boolean readCookieWPSQueryAuthorization(String cookieName) { + + //get the cookie with name GCBUEWorkspaceGridViewSetting + String msg = Cookies.getCookie(cookieName); + //if null, there was no cookie + if(msg == null){ + setCookie(cookieName, "true", 30); + return true; + } + + if(msg.compareTo("true")==0) + return true; + + return false; + } + + /** + * Sets the cookie. + * + * @param name the name + * @param value the value + * @param days the days + */ + public static void setCookie(String name, String value, int days) { + + if (value == null) { + Cookies.removeCookie(name); + return; + } + + // Now + Date expiringDate = new Date(); + // Now + days + expiringDate.setTime(expiringDate.getTime() + MILLISECS_PER_DAY * days); + Cookies.setCookie(name, value, expiringDate); + } + + /** * * @param wmsRequest diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/DialogResult.java b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/DialogResult.java new file mode 100644 index 0000000..ac4368f --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/DialogResult.java @@ -0,0 +1,104 @@ +/** + * + */ +package org.gcube.portlets.user.gisviewerapp.client; + +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.CheckBox; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.DockPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasVerticalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + + +/** + * The Class DialogResult. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 19, 2015 + */ +public class DialogResult extends DialogBox implements ClickHandler { + + private DockPanel dock = new DockPanel(); + private Button closeButton; + private CheckBox checkShowAgain; + + /** + * Instantiates a new dialog result. + * + * @param img the img + * @param text the text + */ + public DialogResult(Image img, String title, String text) { + + setText(title); + closeButton = new Button("Close", this); + dock.setSpacing(4); + dock.setWidth("100%"); + + dock.add(closeButton, DockPanel.SOUTH); + if(img!=null) + dock.add(img, DockPanel.WEST); + + VerticalPanel vp = new VerticalPanel(); + HTML txt = new HTML(text); + txt.getElement().getStyle().setPaddingLeft(5, Unit.PX); + vp.add(txt); + + HorizontalPanel hp = new HorizontalPanel(); + hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + checkShowAgain = new CheckBox(); +// checkShowAgain.getElement().getStyle().setVerticalAlign(VerticalAlign.MIDDLE); + hp.add(checkShowAgain); + hp.add(new HTML("Don't show this again")); + hp.getElement().getStyle().setMarginTop(10, Unit.PX); + vp.add(hp); + dock.add(vp, DockPanel.CENTER); + + + dock.setCellHorizontalAlignment(closeButton, DockPanel.ALIGN_RIGHT); + setWidget(dock); + } + + + /** + * @return the checkShowAgain + */ + public CheckBox getCheckShowAgain() { + + return checkShowAgain; + } + + /** + * @return the closeButton + */ + public Button getCloseButton() { + return closeButton; + } + + + /* (non-Javadoc) + * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) + */ + @Override + public void onClick(ClickEvent event) { + hide(); + + } + + /** + * Adds the to center panel. + * + * @param w the w + */ + public void addToCenterPanel(Widget w){ + dock.add(w, DockPanel.CENTER); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/resources/Images.java b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/resources/Images.java new file mode 100644 index 0000000..c921e1c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/resources/Images.java @@ -0,0 +1,25 @@ +package org.gcube.portlets.user.gisviewerapp.client.resources; + + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.AbstractImagePrototype; + +/** + * The Class Images. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 12, 2016 + */ +public class Images { + + public static Resources resources = GWT.create(Resources.class); + + /** + * Icon warning. + * + * @return the abstract image prototype + */ + public static AbstractImagePrototype iconWarning() { + return AbstractImagePrototype.create(resources.iconWarning()); + } +} diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/resources/Resources.java b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/resources/Resources.java new file mode 100644 index 0000000..671a30b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/resources/Resources.java @@ -0,0 +1,21 @@ +package org.gcube.portlets.user.gisviewerapp.client.resources; + +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.ImageResource; + +/** + * The Interface Resources. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 12, 2016 + */ +public interface Resources extends ClientBundle { + + /** + * Icon warning. + * + * @return the image resource + */ + @Source("warning.png") + ImageResource iconWarning(); +} diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/resources/warning.png b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/resources/warning.png new file mode 100644 index 0000000..9dc9c42 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/resources/warning.png differ diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/rpc/GisViewerAppService.java b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/rpc/GisViewerAppService.java index 6527d74..670632e 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/rpc/GisViewerAppService.java +++ b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/rpc/GisViewerAppService.java @@ -1,9 +1,6 @@ package org.gcube.portlets.user.gisviewerapp.client.rpc; -import org.gcube.portlets.user.gisviewerapp.shared.GeoInformation; -import org.gcube.portlets.user.gisviewerapp.shared.GeoStyles; - import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -17,20 +14,20 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; public interface GisViewerAppService extends RemoteService { - /** - * Gets the styles for wms request. - * - * @param wmsRequest the wms request - * @return the styles for wms request - */ - GeoStyles getStylesForWmsRequest(String wmsRequest); - - /** - * @param wmsRequest - * @param displayName - * @return - * @throws Exception - */ - GeoInformation getParametersForWmsRequest( - String wmsRequest, String displayName) throws Exception; +// /** +// * Gets the styles for wms request. +// * +// * @param wmsRequest the wms request +// * @return the styles for wms request +// */ +// GeoStyles getStylesForWmsRequest(String wmsRequest); +// +// /** +// * @param wmsRequest +// * @param displayName +// * @return +// * @throws Exception +// */ +// GeoInformation getParametersForWmsRequest( +// String wmsRequest, String displayName) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/rpc/GisViewerAppServiceAsync.java b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/rpc/GisViewerAppServiceAsync.java index 7d77b7d..3221e65 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewerapp/client/rpc/GisViewerAppServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/gisviewerapp/client/rpc/GisViewerAppServiceAsync.java @@ -1,10 +1,6 @@ package org.gcube.portlets.user.gisviewerapp.client.rpc; -import org.gcube.portlets.user.gisviewerapp.shared.GeoInformation; -import org.gcube.portlets.user.gisviewerapp.shared.GeoStyles; - import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; /** * The Interface GisViewerAppServiceAsync. @@ -50,19 +46,19 @@ public interface GisViewerAppServiceAsync - /** - * Gets the styles for wms request. - * - * @param wmsRequest the wms request - * @param callback the callback - * @return the styles for wms request - */ - void getStylesForWmsRequest( - String wmsRequest, AsyncCallback callback); - - - - void getParametersForWmsRequest( - String wmsRequest, String displayName, - AsyncCallback callback); +// /** +// * Gets the styles for wms request. +// * +// * @param wmsRequest the wms request +// * @param callback the callback +// * @return the styles for wms request +// */ +// void getStylesForWmsRequest( +// String wmsRequest, AsyncCallback callback); +// +// +// +// void getParametersForWmsRequest( +// String wmsRequest, String displayName, +// AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/server/GisViewerAppServiceImpl.java b/src/main/java/org/gcube/portlets/user/gisviewerapp/server/GisViewerAppServiceImpl.java index b89ee65..5537483 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewerapp/server/GisViewerAppServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/gisviewerapp/server/GisViewerAppServiceImpl.java @@ -1,13 +1,13 @@ package org.gcube.portlets.user.gisviewerapp.server; -import java.util.HashMap; - import org.apache.log4j.Logger; +import org.gcube.portlets.user.gisviewer.client.commons.beans.GeoInformationForWMSRequest; +import org.gcube.portlets.user.gisviewer.server.DefaultGisViewerServiceImpl; import org.gcube.portlets.user.gisviewerapp.client.rpc.GisViewerAppService; import org.gcube.portlets.user.gisviewerapp.shared.GeoInformation; import org.gcube.portlets.user.gisviewerapp.shared.GeoStyles; -import org.gcube.spatial.data.geoutility.GeoGetStylesUtility; +import org.gcube.spatial.data.geoutility.GeoNcWMSMetadataUtility; import org.gcube.spatial.data.geoutility.bean.WmsParameters; import org.gcube.spatial.data.geoutility.wms.WmsUrlValidator; @@ -28,18 +28,18 @@ public class GisViewerAppServiceImpl extends RemoteServiceServlet implements Gis /* (non-Javadoc) * @see org.gcube.portlets.user.gisviewerapp.client.rpc.GisViewerAppService#getStylesForWmsRequest(java.lang.String) */ - @Override + @Deprecated public GeoStyles getStylesForWmsRequest(String wmsRequest) { try { logger.info("Tentative get styles for wmsRequest: "+wmsRequest); - GeoGetStylesUtility geoGetStyles = new GeoGetStylesUtility(wmsRequest); + GeoNcWMSMetadataUtility geoGetStyles = new GeoNcWMSMetadataUtility(wmsRequest); - GeoStyles geo = new GeoStyles(); - geo.setStyles(geoGetStyles.getGeoStyles()); - geo.setNcWMS(geoGetStyles.isNcWms()); - geo.setMapNcWmsStyles(geoGetStyles.getMapNcWmsStyles()); - return geo; +// GeoStyles geo = new GeoStyles(); +// geo.setStyles(geoGetStyles.getGeoStyles()); +// geo.setNcWMS(geoGetStyles.isNcWms()); +// geo.setMapNcWmsStyles(geoGetStyles.getMapNcWmsStyles()); + return null; } catch (Exception e) { logger.error("An error occurred during get styles, returning an empty GeoStyles: ",e); @@ -47,7 +47,7 @@ public class GisViewerAppServiceImpl extends RemoteServiceServlet implements Gis } } - @Override + @Deprecated public GeoInformation getParametersForWmsRequest(String wmsRequest, String displayName) throws Exception { try { @@ -70,24 +70,36 @@ public class GisViewerAppServiceImpl extends RemoteServiceServlet implements Gis } } + GeoInformationForWMSRequest geoInformation = DefaultGisViewerServiceImpl.loadGeoInfoForWmsRequest(wmsRequest, layerName); + GeoInformation geoInfo = new GeoInformation(); geoInfo.setTitle(title); geoInfo.setDisplayName(displayLayerName); geoInfo.setLayerName(layerName); geoInfo.setParametersMap(urlValidator.getMapWmsParameters()); - HashMap mapWmsNotStandard = new HashMap(urlValidator.getMapWmsNoStandardParams().size()); + /*HashMap mapWmsNotStandard = new HashMap(urlValidator.getMapWmsNoStandardParams().size()); mapWmsNotStandard.putAll(urlValidator.getMapWmsNoStandardParams()); logger.trace("wms no standard params: "+mapWmsNotStandard); + */ - GeoStyles geo = getStylesForWmsRequest(wmsRequest); - logger.trace("overriding wms no standard styles: "+geo.getMapNcWmsStyles()); - mapWmsNotStandard.putAll(geo.getMapNcWmsStyles()); - logger.trace("final wms no standard params: "+geo.getMapNcWmsStyles()); - geoInfo.setGeoStyle(geo); - geoInfo.setNoWmsParameters(mapWmsNotStandard); +// GeoStyles geo = getStylesForWmsRequest(wmsRequest); +// logger.trace("overriding wms no standard styles: "+geo.getMapNcWmsStyles()); + + GeoStyles geoStyles = new GeoStyles(); + geoStyles.setStyles(geoInformation.getStyles().getGeoStyles()); + geoStyles.setNcWMS(geoInformation.isNcWMS()); + geoStyles.setMapNcWmsStyles(geoInformation.getStyles().getMapNcWmsStyles()); +// mapWmsNotStandard.putAll(geoInformation.getMapWMSNoStandard()); +// logger.trace("final wms no standard params: "+mapWmsNotStandard); +// geoInfo.setGeoStyle(geoInformation.getStyles()); + geoInfo.setNoWmsParameters(geoInformation.getMapWMSNoStandard()); logger.info("returning: "+geoInfo); +// RequestDispatcher dispatcher=getServletContext().getRequestDispatcher(DefaultGisViewerServiceImpl.class.getSimpleName()); +// dispatcher.forward( request, response ); + + return geoInfo; }catch (LayerNameNotFound e1){ throw new Exception("Layer name not found!"); @@ -95,6 +107,5 @@ public class GisViewerAppServiceImpl extends RemoteServiceServlet implements Gis logger.error("An error occurred during GetInformation build, returning an empty GetInformation: ",e); throw new Exception("An error occurred during wms service request, try again later"); } - } } diff --git a/src/main/java/org/gcube/portlets/user/gisviewerapp/shared/GeoStyles.java b/src/main/java/org/gcube/portlets/user/gisviewerapp/shared/GeoStyles.java index 8149dff..259fe0c 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewerapp/shared/GeoStyles.java +++ b/src/main/java/org/gcube/portlets/user/gisviewerapp/shared/GeoStyles.java @@ -22,7 +22,7 @@ public class GeoStyles implements Serializable { * */ private static final long serialVersionUID = 7307380872802285337L; - List styles; + private List styles; boolean isNcWMS = false; private Map mapNcWmsStyles;