Updated pom version at 4.4.0. Added base layers as cvs file on

server-side
This commit is contained in:
Francesco Mangiacrapa 2020-04-21 17:05:30 +02:00
parent 91148e5eec
commit fae2a93858
22 changed files with 784 additions and 606 deletions

View File

@ -7,6 +7,7 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/main/test"/> <classpathentry kind="src" path="src/main/test"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>

View File

@ -2,5 +2,6 @@
<wb-module deploy-name="gis-viewer"> <wb-module deploy-name="gis-viewer">
<wb-resource deploy-path="/" source-path="/src/main/java"/> <wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/test"/> <wb-resource deploy-path="/" source-path="/src/main/test"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
</wb-module> </wb-module>
</project-modules> </project-modules>

View File

@ -1,4 +1,9 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset
component="org.gcube.portlets-user.GISViewer.4-4-0" date="2020-04-21">
<Change>[Feature #19111]: init settings configurable via property file and GET parameters
</Change>
</Changeset>
<Changeset <Changeset
component="org.gcube.portlets-user.GISViewer.4-3-0" date="2020-04-08"> component="org.gcube.portlets-user.GISViewer.4-3-0" date="2020-04-08">
<Change>[Task #189812] change the base layer True Marble <Change>[Task #189812] change the base layer True Marble

View File

@ -11,7 +11,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>gis-viewer</artifactId> <artifactId>gis-viewer</artifactId>
<version>4.3.0</version> <version>4.4.0</version>
<name>GIS Viewer Widget</name> <name>GIS Viewer Widget</name>
<description> <description>
GWT Widget application to access GIS Data GWT Widget application to access GIS Data

View File

@ -19,4 +19,7 @@
<stylesheet src="css/treePanelStyle.css" /> <stylesheet src="css/treePanelStyle.css" />
<stylesheet src="theme/default/style.css" /> <stylesheet src="theme/default/style.css" />
<source path='client' />
<source path='shared' />
</module> </module>

View File

@ -0,0 +1,78 @@
/**
*
*/
package org.gcube.portlets.user.gisviewer.client;
// TODO: Auto-generated Javadoc
/**
* The Class GisViewerMapLoadedNotification.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Apr 21, 2020
*/
public class GisViewerMapLoadedNotification {
/**
* The listener interface for receiving gisViewerMapLoadedt events.
* The class that is interested in processing a gisViewerMapLoadedt
* event implements this interface, and the object created
* with that class is registered with a component using the
* component's <code>addGisViewerMapLoadedtListener<code> method. When
* the gisViewerMapLoadedt event occurs, that object's appropriate
* method is invoked.
*
* @see GisViewerMapLoadedtEvent
*/
public interface GisViewerMapLoadedtListener {
/**
* On map loaded. Fired when the OLM has been loaded
*/
void onMapLoaded();
/**
* On failed.
*
* @param throwable the throwable
*/
void onFailed(Throwable throwable);
}
/**
* The listener interface for receiving hasGisViewerMapLoadedNotification events.
* The class that is interested in processing a hasGisViewerMapLoadedNotification
* event implements this interface, and the object created
* with that class is registered with a component using the
* component's <code>addHasGisViewerMapLoadedNotificationListener<code> method. When
* the hasGisViewerMapLoadedNotification event occurs, that object's appropriate
* method is invoked.
*
* @see HasGisViewerMapLoadedNotificationEvent
*/
public interface HasGisViewerMapLoadedListener {
/**
* Adds the map loaded listener.
*
* @param handler the handler
*/
public void addMapLoadedListener(GisViewerMapLoadedtListener handler);
/**
* Removes the map loaded listener.
*
* @param handler the handler
*/
public void removeMapLoadedListener(GisViewerMapLoadedtListener handler);
}
}

View File

@ -7,6 +7,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.gcube.portlets.user.gisviewer.client.GisViewerMapLoadedNotification.GisViewerMapLoadedtListener;
import org.gcube.portlets.user.gisviewer.client.GisViewerMapLoadedNotification.HasGisViewerMapLoadedListener;
import org.gcube.portlets.user.gisviewer.client.commons.beans.DataResult; import org.gcube.portlets.user.gisviewer.client.commons.beans.DataResult;
import org.gcube.portlets.user.gisviewer.client.commons.beans.ExportFormat; import org.gcube.portlets.user.gisviewer.client.commons.beans.ExportFormat;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GeoInformationForWMSRequest; import org.gcube.portlets.user.gisviewer.client.commons.beans.GeoInformationForWMSRequest;
@ -37,6 +39,7 @@ import org.gcube.portlets.user.gisviewer.client.openlayers.ToolbarHandler;
import org.gcube.portlets.user.gisviewer.client.resources.Images; import org.gcube.portlets.user.gisviewer.client.resources.Images;
import org.gcube.portlets.user.gisviewer.client.resources.Resources; import org.gcube.portlets.user.gisviewer.client.resources.Resources;
import org.gcube.portlets.user.gisviewer.client.util.SizedLabel; import org.gcube.portlets.user.gisviewer.client.util.SizedLabel;
import org.gwtopenmaps.openlayers.client.LonLat;
import com.extjs.gxt.ui.client.Style.Scroll; import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.core.XDOM; import com.extjs.gxt.ui.client.core.XDOM;
@ -71,7 +74,7 @@ import com.google.gwt.user.client.ui.Label;
* Sep 26, 2016 * Sep 26, 2016
*/ */
public class GisViewerPanel extends LayoutContainer public class GisViewerPanel extends LayoutContainer
implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandler, OpenLayersHandler { implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandler, OpenLayersHandler, HasGisViewerMapLoadedListener{
private static final String ALERT_HARD_SPATIAL_QUERY = "The spatial query can take long time. Do you want to continue to download it?"; private static final String ALERT_HARD_SPATIAL_QUERY = "The spatial query can take long time. Do you want to continue to download it?";
private GisViewerLayout mainPanel; private GisViewerLayout mainPanel;
@ -85,6 +88,8 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
private CqlFilterPanel cqlFilterPanel = new CqlFilterPanel(this); private CqlFilterPanel cqlFilterPanel = new CqlFilterPanel(this);
private ClickDataInfo lastClickDataInfo = null; private ClickDataInfo lastClickDataInfo = null;
private GisViewerPanel INSTANCE;
protected List<GisViewerMapLoadedNotification.GisViewerMapLoadedtListener> listeners = new ArrayList<GisViewerMapLoadedtListener>();
//ADDED BY FRANCESCO //ADDED BY FRANCESCO
/** /**
@ -150,6 +155,7 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
* Inits the. * Inits the.
*/ */
private void init() { private void init() {
INSTANCE = this;
// create an empty layers panel // create an empty layers panel
layersPanel = new LayersPanel(this); layersPanel = new LayersPanel(this);
createOpenLayersMap(); createOpenLayersMap();
@ -164,7 +170,7 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
protected void onRender(Element parent, int index) { protected void onRender(Element parent, int index) {
super.onRender(parent, index); super.onRender(parent, index);
mainPanel.setLayersPanel(layersPanel); mainPanel.setLayersPanel(layersPanel);
mainPanel.setOpenLayers(openLayersMap); //mainPanel.setOpenLayers(openLayersMap);
} }
}; };
@ -348,12 +354,40 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
* Creates the open layers map. * Creates the open layers map.
*/ */
private void createOpenLayersMap() { // TODO update for pluggable layers private void createOpenLayersMap() { // TODO update for pluggable layers
openLayersMap = new OpenLayersMap(Constants.omWidth + "px",
Constants.omHeight + "px", Constants.numZoomLevels, "GisViewer ver. "+Constants.VERSION, this);
toolBarPanel = new ToolBarPanel(this, openLayersMap); final LonLat centerMapTo = null;
final Integer initZoomTo = null;
GisViewer.service.getBaseLayersToGisViewer(new AsyncCallback<List<? extends GisViewerBaseLayerInterface>>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Error on istancing the Gis-Viewer. Please contact the support!");
}
@Override
public void onSuccess(List<? extends GisViewerBaseLayerInterface> result) {
openLayersMap = new OpenLayersMap(
Constants.omWidth + "px",
Constants.omHeight + "px",
Constants.numZoomLevels,
"GisViewer ver. "+Constants.VERSION,
result,
centerMapTo,
initZoomTo,
INSTANCE);
toolBarPanel = new ToolBarPanel(INSTANCE, openLayersMap);
// toolBarPanel.setStyleName("x-toolbar"); // toolBarPanel.setStyleName("x-toolbar");
openLayersMap.addToolBar(toolBarPanel); openLayersMap.addToolBar(toolBarPanel);
mainPanel.setOpenLayers(openLayersMap);
for (GisViewerMapLoadedtListener listner : listeners) {
listner.onMapLoaded();
}
}
});
} }
/** /**
@ -1162,4 +1196,17 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle
return toolBarPanel; return toolBarPanel;
} }
@Override
public void addMapLoadedListener(GisViewerMapLoadedtListener handler) {
listeners.add(handler);
}
@Override
public void removeMapLoadedListener(GisViewerMapLoadedtListener handler) {
listeners.remove(handler);
}
} }

View File

@ -15,6 +15,7 @@ import org.gcube.portlets.user.gisviewer.client.commons.beans.WmsRequest;
import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
// TODO: Auto-generated Javadoc
/** /**
* The client side stub for the RPC service. * The client side stub for the RPC service.
* *

View File

@ -32,33 +32,6 @@ public interface GisViewerServiceAsync {
*/ */
public void getDataResult(List<String> urls, AsyncCallback<List<DataResult>> callback); public void getDataResult(List<String> urls, AsyncCallback<List<DataResult>> callback);
// /**
// * Gets the groups info.
// *
// * @param groupName the group name
// * @param callback the callback
// * @return the groups info
// */
// public void getGroupsInfo(String groupName, AsyncCallback<LayerItemsResult> callback);
// /**
// * Gets the layers info.
// *
// * @param layersName the layers name
// * @param callback the callback
// * @return the layers info
// */
// public void getLayersInfo(List<String> layersName, AsyncCallback<LayerItemsResult> callback);
//
// /**
// * Gets the layers info by layer items.
// *
// * @param layerItems the layer items
// * @param asyncCallback the async callback
// * @return the layers info by layer items
// */
// public void getLayersInfoByLayerItems(List<LayerItem> layerItems, AsyncCallback<LayerItemsResult> asyncCallback);
/** /**
* Gets the transect parameters. * Gets the transect parameters.
* *
@ -126,4 +99,5 @@ public interface GisViewerServiceAsync {
*/ */
void getGcubeSecurityToken(AsyncCallback<String> callback); void getGcubeSecurityToken(AsyncCallback<String> callback);
} }

View File

@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import org.gcube.portlets.user.gisviewer.client.Constants; import org.gcube.portlets.user.gisviewer.client.Constants;
import org.gcube.portlets.user.gisviewer.client.GisViewerPanel;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerBaseLayerInterface; import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerBaseLayerInterface;
import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItem; import org.gcube.portlets.user.gisviewer.client.commons.beans.LayerItem;
import org.gcube.portlets.user.gisviewer.client.commons.beans.MapViewInfo; import org.gcube.portlets.user.gisviewer.client.commons.beans.MapViewInfo;
@ -153,6 +152,7 @@ public class OpenLayersMap {
} }
} }
// constructor // constructor
/** /**
* Instantiates a new open layers map. * Instantiates a new open layers map.
* *
@ -160,10 +160,18 @@ public class OpenLayersMap {
* @param h the h * @param h the h
* @param numZoomLevels the num zoom levels * @param numZoomLevels the num zoom levels
* @param title the title * @param title the title
* @param baseLayers the base layers
* @param centerMapTo the center map to ex. "To center on Italy" you may pass LonLat(12.45, 42.98);
* @param initZoomTo the init zoom to ex. 6 to set initial level zoom to 6
* @param handler the handler * @param handler the handler
*/ */
public OpenLayersMap(String w, String h, int numZoomLevels, // projection, transectUrl removed public OpenLayersMap(String w, String h,
String title, final OpenLayersHandler handler) { int numZoomLevels,
String title,
List<? extends GisViewerBaseLayerInterface> baseLayers,
final LonLat centerMapTo,
final Integer initZoomTo,
final OpenLayersHandler handler) {
this.handler = handler; this.handler = handler;
this.numZoomLevels = numZoomLevels; this.numZoomLevels = numZoomLevels;
@ -231,29 +239,13 @@ public class OpenLayersMap {
map.addLayer(vectorLayer); map.addLayer(vectorLayer);
vectorLayer.setZIndex(MAX_ZINDEX); vectorLayer.setZIndex(MAX_ZINDEX);
String wmsURI = GisViewerPanel.resources.baseLayer().getText(); //adding base layers
String[] params = wmsURI.split("\\?"); for (GisViewerBaseLayerInterface baseLayer : baseLayers) {
String baseLayerTitle = baseLayer.getTitle();
if(params.length<2){ if(baseLayer.isDisplay())
GWT.log("ERROR: No base layer found!"); addBaseLayerToOpenLayerMap(baseLayerTitle, baseLayer.getName(), baseLayer.getWmsServiceBaseURL());
} }
String baseLayerURI = params[0];
String[] parameter = params[1].split("&");
String baseLayerName = "";
for (String string : parameter) {
if(string.startsWith("layers=")){
baseLayerName = string.substring(7);
break;
}
}
if(baseLayerURI==null || baseLayerURI.isEmpty() || baseLayerName.isEmpty()){
GWT.log("ERROR: No base layer found!");
}
addBaseLayerToOpenLayerMap(baseLayerName, baseLayerName, baseLayerURI);
addControl(mouseDefaults); addControl(mouseDefaults);
addControl(pamZoomBar); addControl(pamZoomBar);
addControl(getMousePosition()); addControl(getMousePosition());
@ -262,14 +254,20 @@ public class OpenLayersMap {
addTransectControl(); addTransectControl();
addBoxControl(); addBoxControl();
if(centerMapTo!=null) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() { Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override @Override
public void execute() { public void execute() {
GWT.log("Centering on Italy"); GWT.log("Centering on Italy");
map.setCenter(new LonLat(12.45, 42.98), 6); //map.setCenter(new LonLat(12.45, 42.98), 6);
if(initZoomTo!=null)
map.setCenter(centerMapTo,initZoomTo);
else
map.setCenter(centerMapTo);
} }
}); });
}
} }
@ -1042,6 +1040,7 @@ public class OpenLayersMap {
* @param geoserverBaseUrl the geoserver base url * @param geoserverBaseUrl the geoserver base url
*/ */
private void addBaseLayerToOpenLayerMap(String title, String layerName, String geoserverBaseUrl) { private void addBaseLayerToOpenLayerMap(String title, String layerName, String geoserverBaseUrl) {
GWT.log("Adding base layer title: "+title +", name: "+layerName +", url: "+geoserverBaseUrl);
if (geoserverBaseUrl==null || geoserverBaseUrl.equals("") || layerName==null || layerName.equals("")) if (geoserverBaseUrl==null || geoserverBaseUrl.equals("") || layerName==null || layerName.equals(""))
return; return;
LayerItem l = new LayerItem(true); LayerItem l = new LayerItem(true);

View File

@ -122,6 +122,6 @@ public interface Resources extends ClientBundle {
ImageResource gisViewerIcon(); ImageResource gisViewerIcon();
@Source("baselayer.txt") // @Source("baselayer.txt")
TextResource baseLayer(); // TextResource baseLayer();
} }

View File

@ -3,7 +3,7 @@
*/ */
package org.gcube.portlets.user.gisviewer.server; package org.gcube.portlets.user.gisviewer.server;
import java.util.ArrayList; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -61,19 +61,16 @@ public class DefaultGisViewerServiceImpl extends GisViewerServiceImpl {
protected List<? extends GisViewerBaseLayerInterface> getBaseLayersToAddGisViewer() throws Exception { protected List<? extends GisViewerBaseLayerInterface> getBaseLayersToAddGisViewer() throws Exception {
BaseLayerPropertyReader bl = null; BaseLayerPropertyReader bl = null;
List<? extends GisViewerBaseLayerInterface> baseLayers = null;
try{ try{
logger.info("Instancing BaseLayerPropertyReader"); logger.info("Instancing BaseLayerPropertyReader");
bl = new BaseLayerPropertyReader(); bl = new BaseLayerPropertyReader();
baseLayers = BaseLayerPropertyReader.readBaseLayers();
logger.info("Read base layer: "+bl); logger.info("Read base layer: "+bl);
}catch(Exception e){ }catch(Exception e){
logger.error("Error on reading BaseLayerPropertyReader! Returning hardcode wms base layer"); logger.error("Error on reading base layers trough "+BaseLayerPropertyReader.class.getName()+". Returning hardcoded wms base layer");
bl = null;
} }
final String layerName = bl!=null && bl.getLayerName()!=null?bl.getLayerName():"aquamaps:TrueMarble.16km.2700x1350";
final String layerTitle = bl!=null && bl.getLayerTitle()!=null?bl.getLayerTitle():"True Marble";
final String layerWmsUrl = bl!=null && bl.getLayerWmsUrl()!=null?bl.getLayerWmsUrl():"http://geoserver1.d4science.org/geoserver/aquamaps/wms";
GisViewerBaseLayerInterface trueMarble = new GisViewerBaseLayerInterface() { GisViewerBaseLayerInterface trueMarble = new GisViewerBaseLayerInterface() {
@Override @Override
@ -83,25 +80,24 @@ public class DefaultGisViewerServiceImpl extends GisViewerServiceImpl {
@Override @Override
public String getWmsServiceBaseURL() { public String getWmsServiceBaseURL() {
return layerWmsUrl; return "http://geoserver1.d4science.org/geoserver/aquamaps/wms";
} }
@Override @Override
public String getTitle() { public String getTitle() {
return layerTitle; return "True Marble";
} }
@Override @Override
public String getName() { public String getName() {
// TODO Auto-generated method stub return "aquamaps:TrueMarble.16km.2700x1350";
return layerName;
} }
}; };
List<GisViewerBaseLayerInterface> baseLayer = new ArrayList<GisViewerBaseLayerInterface>(1); if(baseLayers==null) {
baseLayer.add(trueMarble); baseLayers = Arrays.asList(trueMarble);
}
return baseLayer; return baseLayers;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -111,5 +107,4 @@ public class DefaultGisViewerServiceImpl extends GisViewerServiceImpl {
public String getGcubeSecurityToken() { public String getGcubeSecurityToken() {
return null; return null;
} }
} }

View File

@ -64,39 +64,6 @@ public abstract class GisViewerServiceImpl extends RemoteServiceServlet implemen
*/ */
public abstract String getGcubeSecurityToken(); public abstract String getGcubeSecurityToken();
// /**
// * Gets the geo caller.
// *
// * @return the geo caller
// * @throws Exception the exception
// */
// protected GeoCaller getGeoCaller() throws Exception {
// GisViewerServiceParameters parameters = getParameters();
// String geoserverUrl = parameters.getGeoServerUrl();
// String geonetworkUrl = parameters.getGeoNetworkUrl();
// String gnUser = parameters.getGeoNetworkUser();
// String gnPwd = parameters.getGeoNetworkPwd();
// String gsUser = parameters.getGeoServerUser();
// String gsPwd = parameters.getGeoServerPwd();
//
// GeoCaller geoCaller = geoCallersMap.get(geonetworkUrl);
//
// if (geoCaller!=null) {
// logger.debug("-----------GEOCALLER FOUND IN MAP");
// return geoCaller;
// } else {
// logger.debug("-----------GEOCALLER NOT FOUND IN MAP, ADDED...");
// try {
// geoCaller = new GeoCaller(geonetworkUrl, gnUser, gnPwd, geoserverUrl, gsUser, gsPwd, researchMethod);
// geoCallersMap.put(geonetworkUrl, geoCaller);
// return geoCaller;
// } catch (Exception e) {
// throw new Exception("Error initializing the GeoCaller", e);
// }
// }
//
// }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.gcube.portlets.user.gisviewer.client.GisViewerService#getDataResult(java.util.List) * @see org.gcube.portlets.user.gisviewer.client.GisViewerService#getDataResult(java.util.List)
*/ */
@ -164,154 +131,6 @@ public abstract class GisViewerServiceImpl extends RemoteServiceServlet implemen
} }
} }
// /* (non-Javadoc)
// * @see org.gcube.portlets.user.gisviewer.client.GisViewerService#getGroupsInfo(java.lang.String)
// */
// @Override
// public LayerItemsResult getGroupsInfo(String groupName) {
// // search of geoserver that contains the group
// String gsUrl=null;
// try {
// GeoCaller geoCaller = getGeoCaller();
// gsUrl = geoCaller.getGeoServerForGroup(groupName);
// if (gsUrl==null)
// return null;
//
// //FIXME manage the exception
// GisViewerServiceParameters parameters = getParameters();
// String gsUser = parameters.getGeoServerUser();
// String gsPwd = parameters.getGeoServerPwd();
//
// // connecting to the geoserver found
// GeoserverCaller geoserverCaller = new GeoserverCaller(gsUrl, gsUser, gsPwd);
// GroupRest groupRest = geoserverCaller.getLayerGroup(groupName);
//
// return getLayersInfo(groupRest.getLayers());
//
// } catch (Exception e) {
// logger.error("gisViewer EXCEPTION: Error in getGroupInfo. Message=\""+e.getMessage()+"\"");
// logger.error("geoserver_url="+gsUrl);
// logger.error("Stacktrace: ",e);
// return null;
// }
// }
// /* (non-Javadoc)
// * @see org.gcube.portlets.user.gisviewer.client.GisViewerService#getLayersInfo(java.util.List)
// */
// @Override
// public LayerItemsResult getLayersInfo(List<String> layersName) {
// LayerItemsResult layerItemsResult = new LayerItemsResult();
//
// Map<String, GeoserverCaller> geoserverCallers = new HashMap<String, GeoserverCaller>();
// int countVisible=0, n=layersName.size();
//
// for (String layerName: layersName) {
// try {
// GeoCaller geoCaller = getGeoCaller();
//
// CswLayersResult cswLayerResult = geoCaller.getLayersFromCsw(null, 1, 10, false, true, FILTER_TYPE.ANY_TEXT, layerName);
// if (cswLayerResult.getLayers().size()==0)
// layerItemsResult.addStatusMessage("- Layer \""+layerName+"\" not found.");
// else {
// LayerCsw layerCsw = null;
// for (LayerCsw l: cswLayerResult.getLayers()) {
// String[] split = l.getName().split(":");
// if (l.getName().contentEquals(layerName) || split.length>1 && layerName.contentEquals(split[1])) {
// layerCsw = l;
// break;
// }
// }
// if (layerCsw==null)
// layerCsw = cswLayerResult.getLayers().get(0);
// String gsUrl = URLMakers.getGeoserverUrlFromWmsUrl(layerCsw.getGeoserverUrl());
//// String gsGwcUrl = URLMakers.getGeoserverGwcUrl(gsUrl);
// String gsWmsUrl = URLMakers.getGeoserverWmsUrl(gsUrl);
//
// GeoserverCaller geoserverCaller;
// if ((geoserverCaller = geoserverCallers.get(gsUrl))==null) {
// GisViewerServiceParameters parameters = getParameters();
// String gsUser = parameters.getGeoServerUser();
// String gsPwd = parameters.getGeoServerPwd();
// geoserverCaller = new GeoserverCaller(gsUrl, gsUser, gsPwd);
// geoserverCallers.put(gsUrl, geoserverCaller);
// }
//
// LayerItem layerItem = new LayerItem();
// layerItem.setName(layerName);
// layerItem.setTitle(layerCsw.getTitle());
// layerItem.setLayer(layerCsw.getName());
// layerItem.setVisible(countVisible++>n-3);
// layerItem.setUrl(gsWmsUrl);
// layerItem.setGeoserverUrl(gsUrl);
// layerItem.setGeoserverWmsUrl(gsWmsUrl);
//
// LayerRest layerRest = geoserverCaller.getLayer(layerName);
// // set the dataStore
// layerItem.setDataStore(layerRest.getDatastore());
// layerItem.setDefaultStyle(layerRest.getDefaultStyle());
// layerItem.setStyle(layerRest.getDefaultStyle());
//
// layerItem.setBuffer(2);
// if (layerRest.getType().contentEquals("RASTER")) {
//
// CoverageTypeRest coverageTypeRest = geoserverCaller.getCoverageType(
// layerRest.getWorkspace(),
// layerRest.getCoveragestore(),
// layerName);
//
// layerItem.setMaxExtent(coverageTypeRest.getLatLonBoundingBox().getMinx(),
// coverageTypeRest.getLatLonBoundingBox().getMiny(),
// coverageTypeRest.getLatLonBoundingBox().getMaxx(),
// coverageTypeRest.getLatLonBoundingBox().getMaxy(),
// coverageTypeRest.getLatLonBoundingBox().getCrs());
// layerItem.setHasLegend(false);
// layerItem.setBaseLayer(BASE_LAYER);
// layerItem.setTrasparent(false);
// layerItem.setClickData(false);
// } else {
// FeatureTypeRest featureTypeRest = geoserverCaller.getFeatureType(layerRest.getWorkspace(),
// layerRest.getDatastore(),
// layerName);
//
// layerItem.setMaxExtent(featureTypeRest.getLatLonBoundingBox().getMinx(),
// featureTypeRest.getLatLonBoundingBox().getMiny(),
// featureTypeRest.getLatLonBoundingBox().getMaxx(),
// featureTypeRest.getLatLonBoundingBox().getMaxy(),
// featureTypeRest.getLatLonBoundingBox().getCrs());
//
// layerItem.setBaseLayer(false);
// layerItem.setClickData(true);
// layerItem.setStyles(layerRest.getStyles());
// layerItem.setHasLegend(true);
// layerItem.setTrasparent(true);
// }
//
// // set layer properties info
// List<Property> properties = FeatureTypeParser.getProperties(gsUrl, layerItem.getLayer());
// layerItem.setProperties(properties);
// // set opacity
// setDefaultOpacity(layerItem);
// layerItemsResult.addLayerItem(layerItem);
//
// }
// } catch (Exception e) {
// e.printStackTrace();
// layerItemsResult.addStatusMessage("- Layer \""+layerName+"\" not found.");
// }
// }
//
// boolean isBaseLayer = false;
// for (LayerItem l: layerItemsResult.getLayerItems()) {
// if (!isBaseLayer) isBaseLayer = l.isBaseLayer();
// }
// if (!isBaseLayer && layerItemsResult.getLayerItemsSize() > 0) {
// layerItemsResult.getLayerItems().get(0).setBaseLayer(BASE_LAYER);
// }
//
// return layerItemsResult;
// }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.gcube.portlets.user.gisviewer.client.GisViewerService#getBaseLayersToGisViewer() * @see org.gcube.portlets.user.gisviewer.client.GisViewerService#getBaseLayersToGisViewer()
*/ */
@ -327,199 +146,6 @@ public abstract class GisViewerServiceImpl extends RemoteServiceServlet implemen
} }
} }
// /* (non-Javadoc)
// * @see org.gcube.portlets.user.gisviewer.client.GisViewerService#getLayersInfoByLayerItems(java.util.List)
// */
// @Override
// public LayerItemsResult getLayersInfoByLayerItems(List<LayerItem> layerItems) {
// LayerItemsResult layerItemsResult = new LayerItemsResult();
//
// int countVisible=0;
// for (LayerItem layerItem: layerItems) {
// try {
// putLayerInfoInLayerItem(layerItem);
// layerItem.setVisible(countVisible++<2);
// layerItemsResult.addLayerItem(layerItem);
// setDefaultOpacity(layerItem);
// } catch (Exception e) {
// e.printStackTrace();
// layerItemsResult.addStatusMessage("- Layer \""+layerItem.getName()+"\" not found.");
// }
// }
//
// // set eventually base layer
// boolean isBaseLayer = false;
// for (LayerItem l: layerItemsResult.getLayerItems())
// if (!isBaseLayer) isBaseLayer = l.isBaseLayer();
//
// if (!isBaseLayer && layerItemsResult.getLayerItemsSize() > 0) {
// layerItemsResult.getLayerItems().get(0).setBaseLayer(BASE_LAYER);
// }
//
// return layerItemsResult;
// }
// /**
// * Put layer info in layer item.
// *
// * @param layerItem the layer item
// * @throws Exception the exception
// */
// private void putLayerInfoInLayerItem(LayerItem layerItem) throws Exception {
// String gsUrl = layerItem.getGeoserverUrl();
// String layerName = layerItem.getName();
//
// if (gsUrl==null)
// throw new Exception();
//
// GeoserverCaller geoserverCaller;
// GisViewerServiceParameters parameters = getParameters();
// String gsUser = parameters.getGeoServerUser();
// String gsPwd = parameters.getGeoServerPwd();
// geoserverCaller = new GeoserverCaller(gsUrl, gsUser, gsPwd);
//// String gsGwcUrl = URLMakers.getGeoserverGwcUrl(gsUrl);
// String gsWmsUrl = URLMakers.getGeoserverWmsUrl(gsUrl);
//// layerItem.setUrl(gsGwcUrl);
// layerItem.setUrl(gsWmsUrl);
// layerItem.setGeoserverWmsUrl(gsWmsUrl);
//
// LayerRest layerRest = geoserverCaller.getLayer(layerName);
// // set the dataStore
// layerItem.setDataStore(layerRest.getDatastore());
// layerItem.setDefaultStyle(layerRest.getDefaultStyle());
// layerItem.setStyle(layerRest.getDefaultStyle());
// layerItem.setBuffer(2);
//
//// layerItem.setLayer(ServerGeoExtCostants.workSpace+":" + layerName);
// if (layerRest.getType().contentEquals("RASTER")) {
// CoverageTypeRest coverageTypeRest = geoserverCaller.getCoverageType(
// layerRest.getWorkspace(),
// layerRest.getCoveragestore(),
// layerName);
//
// layerItem.setMaxExtent(coverageTypeRest.getLatLonBoundingBox().getMinx(),
// coverageTypeRest.getLatLonBoundingBox().getMiny(),
// coverageTypeRest.getLatLonBoundingBox().getMaxx(),
// coverageTypeRest.getLatLonBoundingBox().getMaxy(),
// coverageTypeRest.getLatLonBoundingBox().getCrs());
// layerItem.setHasLegend(false);
// layerItem.setBaseLayer(BASE_LAYER);
// layerItem.setTrasparent(false);
// layerItem.setClickData(false);
// } else {
// FeatureTypeRest featureTypeRest = geoserverCaller.getFeatureType(layerRest.getWorkspace(),
// layerRest.getDatastore(),
// layerName);
//
// layerItem.setMaxExtent(featureTypeRest.getLatLonBoundingBox().getMinx(),
// featureTypeRest.getLatLonBoundingBox().getMiny(),
// featureTypeRest.getLatLonBoundingBox().getMaxx(),
// featureTypeRest.getLatLonBoundingBox().getMaxy(),
// featureTypeRest.getLatLonBoundingBox().getCrs());
//
// layerItem.setBaseLayer(false);
// layerItem.setClickData(true);
// layerItem.setStyles(layerRest.getStyles());
// layerItem.setHasLegend(true);
//
// layerItem.setTrasparent(true);
// }
//
// // set layer properties info
// List<Property> properties = FeatureTypeParser.getProperties(gsUrl, layerItem.getLayer());
// layerItem.setProperties(properties);
// }
// /**
// * Gets the layer info by layer name.
// *
// * @param layerName the layer name
// * @param geoserverCallers the geoserver callers
// * @return the layer info by layer name
// * @throws Exception the exception
// */
// private LayerItem getLayerInfoByLayerName(String layerName, Map<String, GeoserverCaller> geoserverCallers) throws Exception {
// GeoCaller geoCaller = getGeoCaller();
//
// CswLayersResult cswLayerResult = geoCaller.getLayersFromCsw(null, 1, 1, false, true, FILTER_TYPE.ANY_TEXT, layerName);
// if (cswLayerResult.getLayers().size()==0)
// throw new Exception("CswLayerResult is empty.");
// else {
// LayerCsw layerCsw = cswLayerResult.getLayers().get(0);
// String gsUrl = URLMakers.getGeoserverUrlFromWmsUrl(layerCsw.getGeoserverUrl());
//// String gsGwcUrl = URLMakers.getGeoserverGwcUrl(gsUrl);
// String gsWmsUrl = URLMakers.getGeoserverWmsUrl(gsUrl);
//
// GeoserverCaller geoserverCaller;
// if ((geoserverCaller = geoserverCallers.get(gsUrl))==null) {
// GisViewerServiceParameters parameters = getParameters();
// String gsUser = parameters.getGeoServerUser();
// String gsPwd = parameters.getGeoServerPwd();
// geoserverCaller = new GeoserverCaller(gsUrl, gsUser, gsPwd);
// geoserverCallers.put(gsUrl, geoserverCaller);
// }
//
// LayerItem layerItem = new LayerItem();
// layerItem.setName(layerName);
// layerItem.setTitle(layerCsw.getTitle());
// layerItem.setLayer(layerCsw.getName());
//// layerItem.setUrl(gsGwcUrl);
// layerItem.setUrl(gsWmsUrl);
// layerItem.setGeoserverUrl(gsUrl);
// layerItem.setGeoserverWmsUrl(gsWmsUrl);
//
// LayerRest layerRest = geoserverCaller.getLayer(layerName);
// // set the dataStore
// layerItem.setDataStore(layerRest.getDatastore());
// layerItem.setDefaultStyle(layerRest.getDefaultStyle());
// layerItem.setStyle(layerRest.getDefaultStyle());
// layerItem.setBuffer(2);
//
// if (layerRest.getType().contentEquals("RASTER")) {
//
// CoverageTypeRest coverageTypeRest = geoserverCaller.getCoverageType(
// layerRest.getWorkspace(),
// layerRest.getCoveragestore(),
// layerName);
//
// layerItem.setMaxExtent(coverageTypeRest.getLatLonBoundingBox().getMinx(),
// coverageTypeRest.getLatLonBoundingBox().getMiny(),
// coverageTypeRest.getLatLonBoundingBox().getMaxx(),
// coverageTypeRest.getLatLonBoundingBox().getMaxy(),
// coverageTypeRest.getLatLonBoundingBox().getCrs());
// layerItem.setHasLegend(false);
// layerItem.setBaseLayer(BASE_LAYER);
// layerItem.setTrasparent(false);
// layerItem.setClickData(false);
// } else {
// FeatureTypeRest featureTypeRest = geoserverCaller.getFeatureType(layerRest.getWorkspace(),
// layerRest.getDatastore(),
// layerName);
//
// layerItem.setMaxExtent(featureTypeRest.getLatLonBoundingBox().getMinx(),
// featureTypeRest.getLatLonBoundingBox().getMiny(),
// featureTypeRest.getLatLonBoundingBox().getMaxx(),
// featureTypeRest.getLatLonBoundingBox().getMaxy(),
// featureTypeRest.getLatLonBoundingBox().getCrs());
//
// layerItem.setBaseLayer(false);
// layerItem.setClickData(true);
// layerItem.setStyles(layerRest.getStyles());
// layerItem.setHasLegend(true);
//
// layerItem.setTrasparent(true);
// }
//
// // set layer properties info
// List<Property> properties = FeatureTypeParser.getProperties(gsUrl, layerItem.getLayer());
// layerItem.setProperties(properties);
// setDefaultOpacity(layerItem);
//
// return layerItem;
// }
// }
/** /**
* Sets the default opacity. * Sets the default opacity.
* *
@ -590,4 +216,5 @@ public abstract class GisViewerServiceImpl extends RemoteServiceServlet implemen
throw new Exception("Sorry, an error occurred when creating wms request, try again later"); throw new Exception("Sorry, an error occurred when creating wms request, try again later");
} }
} }
} }

View File

@ -1,176 +1,84 @@
package org.gcube.portlets.user.gisviewer.server.baselayer; package org.gcube.portlets.user.gisviewer.server.baselayer;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.portlets.user.gisviewer.server.exception.PropertyFileNotFoundException; import org.gcube.portlets.user.gisviewer.server.exception.PropertyFileNotFoundException;
import org.gcube.portlets.user.gisviewer.server.util.CSVReader;
import org.gcube.portlets.user.gisviewer.server.util.FileUtil;
import org.gcube.portlets.user.gisviewer.shared.CSVFile;
import org.gcube.portlets.user.gisviewer.shared.CSVRow;
import org.gcube.portlets.user.gisviewer.shared.GisViewerBaseLayer;
// TODO: Auto-generated Javadoc
/** /**
* The Class BaseLayerPropertyReader. * The Class BaseLayerPropertyReader.
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Sep 28, 2015 * Apr 21, 2020
*/ */
public class BaseLayerPropertyReader { public class BaseLayerPropertyReader {
protected static final String BASE_LAYER_FILE = "baselayer.properties"; protected static final String BASE_LAYER_FILE = "baselayers.csv";
protected static final String BASELAYER_WMS_SERVER = "BASELAYER_WMS_SERVER";
protected static final String BASELAYER_LAYERS = "BASELAYER_LAYERS";
protected static final String BASELAYER_TITLE = "BASELAYER_TITLE";
private String layerName;
private String layerTitle;
private String layerWmsUrl;
public static Logger logger = Logger public static Logger logger = Logger
.getLogger(BaseLayerPropertyReader.class); .getLogger(BaseLayerPropertyReader.class);
/** /**
* Instantiates a new base layer property reader. * Read base layers.
* *
* @return the list<? extends gis viewer base layer>
* @throws PropertyFileNotFoundException the property file not found exception * @throws PropertyFileNotFoundException the property file not found exception
*/ */
public BaseLayerPropertyReader() throws PropertyFileNotFoundException { public static List<? extends GisViewerBaseLayer> readBaseLayers() throws PropertyFileNotFoundException {
Properties prop = new Properties();
try { try {
InputStream in = (InputStream) BaseLayerPropertyReader.class.getResourceAsStream(BASE_LAYER_FILE); InputStream in = (InputStream) BaseLayerPropertyReader.class.getResourceAsStream(BASE_LAYER_FILE);
File baseLayersFile = FileUtil.inputStreamToFile(in);
CSVReader reader = new CSVReader(baseLayersFile);
CSVFile csvFile = reader.getCsvFile();
List<GisViewerBaseLayer> listBaseLayers = new ArrayList<GisViewerBaseLayer>(csvFile.getValueRows().size());
// load a properties file for (CSVRow row : csvFile.getValueRows()) {
prop.load(in); GisViewerBaseLayer baseLayer = new GisViewerBaseLayer();
List<String> headerKeys = csvFile.getHeaderRow().getListValues();
Map<String,String> mapProperties = new HashMap<String, String>(row.getListValues().size());
int i = 0;
//to map properties
List<String> rowValues = row.getListValues();
for (String value : rowValues) {
mapProperties.put(headerKeys.get(i), value);
i++;
}
baseLayer.setMapProperties(mapProperties);
//adding data to interface
try {
baseLayer.setTitle(rowValues.get(0));
baseLayer.setName(rowValues.get(1));
baseLayer.setWmsServiceBaseURL(rowValues.get(2));
baseLayer.setDisplay(Boolean.parseBoolean(rowValues.get(3)));
}catch (Exception e) {
logger.error("Has the property file " + BASE_LAYER_FILE + " been changed?", e);
}
this.layerWmsUrl = prop.getProperty(BASELAYER_WMS_SERVER); listBaseLayers.add(baseLayer);
this.layerTitle = prop.getProperty(BASELAYER_TITLE); }
this.layerName = prop.getProperty(BASELAYER_LAYERS);
return listBaseLayers;
} catch (IOException e) { } catch (IOException e) {
logger.error("An error occurred on read property file " + e, e); logger.error("An error occurred on reading the property file " + BASE_LAYER_FILE, e);
throw new PropertyFileNotFoundException( throw new PropertyFileNotFoundException(
"An error occurred on read property file " + e); "Error on reading the base layers. Is the file '"+BASE_LAYER_FILE+ "' in the application path?");
} }
} }
/**
* Gets the base layer file.
*
* @return the base layer file
*/
public static String getBaseLayerFile() {
return BASE_LAYER_FILE;
}
/**
* Gets the baselayer wms server.
*
* @return the baselayer wms server
*/
public static String getBaselayerWmsServer() {
return BASELAYER_WMS_SERVER;
}
/**
* Gets the baselayer layers.
*
* @return the baselayer layers
*/
public static String getBaselayerLayers() {
return BASELAYER_LAYERS;
}
/**
* Gets the baselayer title.
*
* @return the baselayer title
*/
public static String getBaselayerTitle() {
return BASELAYER_TITLE;
}
/**
* Gets the layer name.
*
* @return the layer name
*/
public String getLayerName() {
return layerName;
}
/**
* Gets the layer title.
*
* @return the layer title
*/
public String getLayerTitle() {
return layerTitle;
}
/**
* Gets the layer wms url.
*
* @return the layer wms url
*/
public String getLayerWmsUrl() {
return layerWmsUrl;
}
/**
* Sets the layer name.
*
* @param layerName the new layer name
*/
public void setLayerName(String layerName) {
this.layerName = layerName;
}
/**
* Sets the layer title.
*
* @param layerTitle the new layer title
*/
public void setLayerTitle(String layerTitle) {
this.layerTitle = layerTitle;
}
/**
* Sets the layer wms url.
*
* @param layerWmsUrl the new layer wms url
*/
public void setLayerWmsUrl(String layerWmsUrl) {
this.layerWmsUrl = layerWmsUrl;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("BaseLayerPropertyReader [layerName=");
builder.append(layerName);
builder.append(", layerTitle=");
builder.append(layerTitle);
builder.append(", layerWmsUrl=");
builder.append(layerWmsUrl);
builder.append("]");
return builder.toString();
}
/*
public static void main(String[] args) {
BaseLayerPropertyReader gr;
try {
gr = new BaseLayerPropertyReader();
System.out.println(gr);
} catch (PropertyFileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}*/
} }

View File

@ -1,3 +0,0 @@
BASELAYER_WMS_SERVER = http://geoserver1.d4science.org/geoserver/aquamaps/wms
BASELAYER_LAYERS = aquamaps:TrueMarble.16km.2700x1350
BASELAYER_TITLE = True Marble

View File

@ -0,0 +1,3 @@
"Layer Title","Layer Name", "WMS Service URL", "Display into GisViewer"
"OpenStreetMap-WMS","OSM-WMS","https://ows.terrestris.de/osm/service","true"
"True Marble","aquamaps:TrueMarble.16km.2700x1350","http://geoserver1.d4science.org/geoserver/aquamaps/wms","true"
1 Layer Title Layer Name WMS Service URL Display into GisViewer
2 OpenStreetMap-WMS OSM-WMS https://ows.terrestris.de/osm/service true
3 True Marble aquamaps:TrueMarble.16km.2700x1350 http://geoserver1.d4science.org/geoserver/aquamaps/wms true

View File

@ -0,0 +1,192 @@
/**
*
*/
package org.gcube.portlets.user.gisviewer.server.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import org.gcube.portlets.user.gisviewer.shared.CSVFile;
import org.gcube.portlets.user.gisviewer.shared.CSVRow;
/**
* The Class CSVReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jan 29, 2019
*/
public class CSVReader {
private static final char DEFAULT_SEPARATOR = ',';
private static final char DEFAULT_QUOTE = '"';
private File file;
private CSVFile csvFile;
/**
* Instantiates a new CSV reader.
*
* @param file the file
* @throws FileNotFoundException the file not found exception
*/
public CSVReader(File file) throws FileNotFoundException {
this.file = file;
this.csvFile = new CSVFile();
readCSV(file);
}
/**
* Read csv.
*
* @param file the file
* @throws FileNotFoundException the file not found exception
*/
private void readCSV(File file) throws FileNotFoundException {
Scanner scanner = new Scanner(file);
int i = 0;
while (scanner.hasNext()) {
CSVRow csvRow = new CSVRow();
List<String> line = parseLine(scanner.nextLine());
csvRow.setListValues(line);
if(i==0){
csvFile.setHeaderRow(csvRow);
}else{
csvFile.addRow(csvRow);
}
i++;
}
scanner.close();
}
/**
* Parses the line.
*
* @param cvsLine the cvs line
* @return the list
*/
public static List<String> parseLine(String cvsLine) {
return parseLine(cvsLine, DEFAULT_SEPARATOR, DEFAULT_QUOTE);
}
/**
* Parses the line.
*
* @param cvsLine the cvs line
* @param separators the separators
* @return the list
*/
public static List<String> parseLine(String cvsLine, char separators) {
return parseLine(cvsLine, separators, DEFAULT_QUOTE);
}
/**
* Parses the line.
*
* @param cvsLine the cvs line
* @param separators the separators
* @param customQuote the custom quote
* @return the list
*/
private static List<String> parseLine(String cvsLine, char separators, char customQuote) {
List<String> result = new ArrayList<>();
// if empty, return!
if (cvsLine == null || cvsLine.isEmpty()) {
return result;
}
if (customQuote == ' ') {
customQuote = DEFAULT_QUOTE;
}
if (separators == ' ') {
separators = DEFAULT_SEPARATOR;
}
StringBuffer curVal = new StringBuffer();
boolean inQuotes = false;
boolean startCollectChar = false;
boolean doubleQuotesInColumn = false;
char[] chars = cvsLine.toCharArray();
for (char ch : chars) {
if (inQuotes) {
startCollectChar = true;
if (ch == customQuote) {
inQuotes = false;
doubleQuotesInColumn = false;
}
else {
// Fixed : allow "" in custom quote enclosed
if (ch == '\"') {
if (!doubleQuotesInColumn) {
curVal.append(ch);
doubleQuotesInColumn = true;
}
}
else {
curVal.append(ch);
}
}
}
else {
if (ch == customQuote) {
inQuotes = true;
// Fixed : allow "" in empty quote enclosed
if (chars[0] != '"' && customQuote == '\"') {
curVal.append('"');
}
// double quotes in column will hit this!
if (startCollectChar) {
curVal.append('"');
}
}
else if (ch == separators) {
result.add(curVal.toString());
curVal = new StringBuffer();
startCollectChar = false;
}
else if (ch == '\r') {
// ignore LF characters
continue;
}
else if (ch == '\n') {
// the end, break!
break;
}
else {
curVal.append(ch);
}
}
}
result.add(curVal.toString());
return result;
}
/**
* Gets the csv file.
*
* @return the csvFile
*/
public CSVFile getCsvFile() {
return csvFile;
}
/**
* Gets the file.
*
* @return the file
*/
public File getFile() {
return file;
}
}

View File

@ -0,0 +1,48 @@
package org.gcube.portlets.user.gisviewer.server.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
// TODO: Auto-generated Javadoc
/**
* The Class FileUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
* Apr 21, 2020
*/
public class FileUtil {
/**
* Input stream to file.
*
* @param inputStream the input stream
* @return the file
* @throws IOException Signals that an I/O exception has occurred.
*/
// InputStream -> File
public static File inputStreamToFile(InputStream inputStream)
throws IOException {
File tempFile = File.createTempFile("baselayers", ".tmp");
//File tempFile = File.createTempFile("MyAppName-", ".tmp");
try (FileOutputStream outputStream = new FileOutputStream(tempFile)) {
int read;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
return tempFile;
}finally {
tempFile.deleteOnExit();
}
}
}

View File

@ -0,0 +1,133 @@
/**
*
*/
package org.gcube.portlets.user.gisviewer.shared;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* The Class CSVFile.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jan 29, 2019
*/
public class CSVFile implements Serializable{
/**
*
*/
private static final long serialVersionUID = 6408321963787244600L;
private CSVRow headerRow;
private List<CSVRow> valueRows;
private String fileName;
/**
* Instantiates a new CSV file.
*/
public CSVFile(){
}
/**
* Instantiates a new csv file.
*
* @param headerRow the header row
* @param valueRows the value rows
*/
public CSVFile(String fileName, CSVRow headerRow, List<CSVRow> valueRows) {
this.fileName = fileName;
this.headerRow = headerRow;
this.valueRows = valueRows;
}
/**
* Gets the header row.
*
* @return the headerRow
*/
public CSVRow getHeaderRow() {
return headerRow;
}
/**
* Gets the value rows.
*
* @return the valueRows
*/
public List<CSVRow> getValueRows() {
return valueRows;
}
/**
* Sets the header row.
*
* @param headerRow the headerRow to set
*/
public void setHeaderRow(CSVRow headerRow) {
this.headerRow = headerRow;
}
/**
* Adds the row.
*
* @param csvRow the csv row
*/
public void addRow(CSVRow csvRow) {
if(this.valueRows==null)
this.valueRows = new ArrayList<CSVRow>();
this.valueRows.add(csvRow);
}
/**
* @return the fileName
*/
public String getFileName() {
return fileName;
}
/**
* @param fileName the fileName to set
*/
public void setFileName(String fileName) {
this.fileName = fileName;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("CSVFile [headerRow=");
builder.append(headerRow);
builder.append(", valueRows=");
builder.append(valueRows);
builder.append(", fileName=");
builder.append(fileName);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,67 @@
/**
*
*/
package org.gcube.portlets.user.gisviewer.shared;
import java.io.Serializable;
import java.util.List;
/**
* The Class CSVRow.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jan 29, 2019
*/
public class CSVRow implements Serializable{
/**
*
*/
private static final long serialVersionUID = 6254861811998867626L;
private List<String> listValues;
/**
* Instantiates a new CSV row.
*/
public CSVRow(){
}
/**
* Gets the list values.
*
* @return the listValues
*/
public List<String> getListValues() {
return listValues;
}
/**
* @param listValues the listValues to set
*/
public void setListValues(List<String> listValues) {
this.listValues = listValues;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("CSVRow [listValues=");
builder.append(listValues);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,80 @@
package org.gcube.portlets.user.gisviewer.shared;
import java.io.Serializable;
import java.util.Map;
import org.gcube.portlets.user.gisviewer.client.commons.beans.GisViewerBaseLayerInterface;
// TODO: Auto-generated Javadoc
/**
* The Class GisViewerBaseLayer.
*
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) Apr 21, 2020
*/
public class GisViewerBaseLayer implements GisViewerBaseLayerInterface, Serializable {
/**
*
*/
private static final long serialVersionUID = 3202101184874861425L;
private Map<String, String> mapProperties;
private String title;
private String name;
private String wmsServiceBaseURL;
private boolean display;
public GisViewerBaseLayer() {
}
public GisViewerBaseLayer(Map<String, String> mapProperties) {
this.mapProperties = mapProperties;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWmsServiceBaseURL() {
return wmsServiceBaseURL;
}
public void setWmsServiceBaseURL(String wmsServiceBaseURL) {
this.wmsServiceBaseURL = wmsServiceBaseURL;
}
public boolean isDisplay() {
return display;
}
public void setDisplay(boolean display) {
this.display = display;
}
public void setMapProperties(Map<String, String> mapProperties) {
this.mapProperties = mapProperties;
}
public Map<String, String> getMapProperties() {
return mapProperties;
}
@Override
public String toString() {
return "GisViewerBaseLayer [mapProperties=" + mapProperties + ", title=" + title + ", name=" + name
+ ", wmsServiceBaseURL=" + wmsServiceBaseURL + ", display=" + display + "]";
}
}

View File

@ -0,0 +1,19 @@
package org.gcube.portlets.user.gisviewer.test.client;
import java.util.List;
import org.gcube.portlets.user.gisviewer.server.baselayer.BaseLayerPropertyReader;
import org.gcube.portlets.user.gisviewer.server.exception.PropertyFileNotFoundException;
import org.gcube.portlets.user.gisviewer.shared.GisViewerBaseLayer;
public class PropertyFiles {
public static void main(String[] args) throws PropertyFileNotFoundException {
List<? extends GisViewerBaseLayer> layers = BaseLayerPropertyReader.readBaseLayers();
for (GisViewerBaseLayer gisViewerBaseLayer : layers) {
System.err.println(gisViewerBaseLayer);
}
}
}