Integrated with geo-ytility library, see #2054

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gis-viewer-app@122489 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-01-25 12:00:41 +00:00
parent 53fc6df0fd
commit 1cdabfa6d5
7 changed files with 312 additions and 38 deletions

View File

@ -4,13 +4,12 @@
package org.gcube.portlets.user.gisviewerapp.client;
import java.util.ArrayList;
import java.util.HashMap;
import org.gcube.portlets.user.gisviewer.client.GisViewerPanel;
import org.gcube.portlets.user.gisviewer.client.GisViewerPanel.LayerType;
import org.gcube.portlets.user.gisviewerapp.client.rpc.GisViewerAppServiceAsync;
import org.gcube.portlets.user.gisviewerapp.shared.GeoStyles;
import org.gcube.spatial.data.geoutility.bean.WmsParameters;
import org.gcube.spatial.data.geoutility.wms.WmsUrlValidator;
import org.gcube.portlets.user.gisviewerapp.shared.GeoInformation;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -36,8 +35,6 @@ public class WmsRequestConverter {
private boolean onTop = true;
private String wmsRequest;
private WmsUrlValidator urlValidator;
/**
* Instantiates a new wms request converter.
*
@ -67,31 +64,16 @@ public class WmsRequestConverter {
// throw new Exception("Bad server request '?' not found!");
}
urlValidator = new WmsUrlValidator(wmsRequest);
urlValidator.parseWmsRequest(true,false);
String layerName = urlValidator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
if(layerName==null || layerName.isEmpty()){
Window.alert("Bad wms request LAYER parameter not found!");
throw new Exception("Layer name not found!");
}else{
displayLayerName = layerName;
title = layerName;
if(displayName!=null && !displayName.isEmpty()) {
displayLayerName = displayName;
}
}
GisViewerAppServiceAsync.Util.getInstance().getStylesForWmsRequest(wmsRequest, new AsyncCallback<GeoStyles>() {
@Override
public void onSuccess(GeoStyles result) {
addRequestToGisViewer((ArrayList<String>) result.getStyles(), result.isNcWMS());
}
GisViewerAppServiceAsync.Util.getInstance().getParametersForWmsRequest(wmsRequest, displayName, new AsyncCallback<GeoInformation>() {
@Override
public void onFailure(Throwable caught) {
addRequestToGisViewer(new ArrayList<String>(1), false);
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(GeoInformation result) {
addRequestToGisViewer(result);
}
});
@ -110,13 +92,8 @@ public class WmsRequestConverter {
}*/
}
/**
* Adds the request to gis viewer.
* @param listStyles
*/
public void addRequestToGisViewer(ArrayList<String> styles, boolean ncWMS){
gisViewer.addLayerByWms(GisViewerPanel.LayerType.FEATURETYPE, displayLayerName, title, url, isExternal, isBase, displayInLayerSwitcher, styles, wmsRequest, onTop, urlValidator.getParametersMap(), ncWMS, null);
// gisViewer.addLayerByWms(title, displayLayerName, wmsRequest, isBase, displayInLayerSwitcher, null);
private void addRequestToGisViewer(GeoInformation result) {
gisViewer.addLayerByWms(GisViewerPanel.LayerType.FEATURETYPE, result.getTitle(), result.getLayerName(), url, isExternal, isBase, displayInLayerSwitcher, (ArrayList<String>)result.getGeoStyle().getStyles(), wmsRequest, onTop, (HashMap<String, String>) result.getMapWmsNoStandardParams(), result.getGeoStyle().isNcWMS(), null);
}
/**

View File

@ -1,6 +1,7 @@
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;
@ -23,4 +24,13 @@ public interface GisViewerAppService extends RemoteService {
* @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;
}

View File

@ -1,5 +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;
@ -58,4 +59,10 @@ public interface GisViewerAppServiceAsync
*/
void getStylesForWmsRequest(
String wmsRequest, AsyncCallback<GeoStyles> callback);
void getParametersForWmsRequest(
String wmsRequest, String displayName,
AsyncCallback<GeoInformation> callback);
}

View File

@ -1,11 +1,17 @@
package org.gcube.portlets.user.gisviewerapp.server;
import java.util.HashMap;
import org.apache.log4j.Logger;
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.GeoGetStyles;
import org.gcube.spatial.data.geoutility.GeoGetStylesUtility;
import org.gcube.spatial.data.geoutility.bean.WmsParameters;
import org.gcube.spatial.data.geoutility.wms.WmsUrlValidator;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
@ -27,12 +33,12 @@ public class GisViewerAppServiceImpl extends RemoteServiceServlet implements Gis
try {
logger.info("Tentative get styles for wmsRequest: "+wmsRequest);
GeoGetStyles geoGetStyles = new GeoGetStyles(wmsRequest);
GeoGetStylesUtility geoGetStyles = new GeoGetStylesUtility(wmsRequest);
GeoStyles geo = new GeoStyles();
geo.setStyles(geoGetStyles.getGeoStyles());
geo.setNcWMS(geoGetStyles.isNcWms());
geo.setMapNcWmsStyles(geoGetStyles.getMapNcWmsStyles());
return geo;
}
catch (Exception e) {
@ -40,4 +46,55 @@ public class GisViewerAppServiceImpl extends RemoteServiceServlet implements Gis
return new GeoStyles();
}
}
@Override
public GeoInformation getParametersForWmsRequest(String wmsRequest, String displayName) throws Exception {
try {
logger.info("Tentative to get GeoInformation object for wmsRequest: "+wmsRequest);
WmsUrlValidator urlValidator = new WmsUrlValidator(wmsRequest);
String displayLayerName;
String title;
urlValidator.parseWmsRequest(true,false);
String layerName = urlValidator.getValueOfParsedWMSParameter(WmsParameters.LAYERS);
if(layerName==null || layerName.isEmpty()){
Window.alert("Bad wms request LAYER parameter not found!");
throw new LayerNameNotFound("Layer name not found!");
}else{
displayLayerName = layerName;
title = layerName;
if(displayName!=null && !displayName.isEmpty()) {
displayLayerName = displayName;
}
}
GeoInformation geoInfo = new GeoInformation();
geoInfo.setTitle(title);
geoInfo.setDisplayName(displayLayerName);
geoInfo.setLayerName(layerName);
geoInfo.setParametersMap(urlValidator.getParametersMap());
HashMap<String, String> mapWmsNotStandard = new HashMap<String, String>(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);
logger.info("returning: "+geoInfo);
return geoInfo;
}catch (LayerNameNotFound e1){
throw new Exception("Layer name not found!");
}catch (Exception e) {
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");
}
}
}

View File

@ -0,0 +1,24 @@
/**
*
*/
package org.gcube.portlets.user.gisviewerapp.server;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 22, 2016
*/
public class LayerNameNotFound extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param string
*/
public LayerNameNotFound(String string) {
super(string);
}
}

View File

@ -0,0 +1,179 @@
/**
*
*/
package org.gcube.portlets.user.gisviewerapp.shared;
import java.io.Serializable;
import java.util.Map;
/**
* The Class GeoInformation.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 25, 2016
*/
public class GeoInformation implements Serializable {
private static final long serialVersionUID = 9205334969349325638L;
private String title;
private String displayName;
private String layerName;
private Map<String, String> parametersMap;
private GeoStyles geoStyle;
private Map<String, String> mapWmsNoStandardParams;
/**
* Instantiates a new geo information.
*/
public GeoInformation() {
}
/**
* Sets the title.
*
* @param title
* the new title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Sets the display name.
*
* @param displayName
* the new display name
*/
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
/**
* Sets the layer name.
*
* @param layerName
* the new layer name
*/
public void setLayerName(String layerName) {
this.layerName = layerName;
}
/**
* Sets the geo style.
*
* @param geo the new geo style
*/
public void setGeoStyle(GeoStyles geo) {
this.geoStyle = geo;
}
/**
* Gets the geo style.
*
* @return the geoStyle
*/
public GeoStyles getGeoStyle() {
return geoStyle;
}
/**
* Sets the parameters map.
*
* @param parametersMap
* the parameters map
*/
public void setParametersMap(Map<String, String> parametersMap) {
this.parametersMap = parametersMap;
}
/**
* Gets the title.
*
* @return the title
*/
public String getTitle() {
return title;
}
/**
* Gets the display name.
*
* @return the displayName
*/
public String getDisplayName() {
return displayName;
}
/**
* Gets the layer name.
*
* @return the layerName
*/
public String getLayerName() {
return layerName;
}
/**
* Gets the parameters map.
*
* @return the parametersMap
*/
public Map<String, String> getParametersMap() {
return parametersMap;
}
/**
* Sets the no wms parameters.
*
* @param mapWmsNotStandardParams the map wms not standard params
*/
public void setNoWmsParameters(Map<String, String> mapWmsNotStandardParams) {
this.mapWmsNoStandardParams = mapWmsNotStandardParams;
}
/**
* Gets the map wms no standard params.
*
* @return the map wms no standard params
*/
public Map<String, String> getMapWmsNoStandardParams() {
return mapWmsNoStandardParams;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeoInformation [title=");
builder.append(title);
builder.append(", displayName=");
builder.append(displayName);
builder.append(", layerName=");
builder.append(layerName);
builder.append(", parametersMap=");
builder.append(parametersMap);
builder.append(", geoStyle=");
builder.append(geoStyle);
builder.append(", mapWmsNoStandardParams=");
builder.append(mapWmsNoStandardParams);
builder.append("]");
return builder.toString();
}
}

View File

@ -5,7 +5,9 @@
package org.gcube.portlets.user.gisviewerapp.shared;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -22,6 +24,7 @@ public class GeoStyles implements Serializable {
private static final long serialVersionUID = 7307380872802285337L;
List<String> styles;
boolean isNcWMS = false;
private Map<String, String> mapNcWmsStyles;
/**
* Instantiates a new geo styles.
@ -87,6 +90,22 @@ public class GeoStyles implements Serializable {
this.isNcWMS = isNcWMS;
}
/**
* @param mapNcWmsStyles the mapNcWmsStandardStyles to set
*/
public void setMapNcWmsStyles(Map<String, String> mapNcWmsStyles) {
this.mapNcWmsStyles = mapNcWmsStyles;
}
/**
* @return the mapNcWmsStyles
*/
public Map<String, String> getMapNcWmsStyles() {
return mapNcWmsStyles==null?new HashMap<String, String>(1):mapNcWmsStyles;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@ -98,9 +117,10 @@ public class GeoStyles implements Serializable {
builder.append(styles);
builder.append(", isNcWMS=");
builder.append(isNcWMS);
builder.append(", mapNcWmsStyles=");
builder.append(mapNcWmsStyles);
builder.append("]");
return builder.toString();
}
}