diff --git a/.classpath b/.classpath index 4f9ed35..15480fb 100644 --- a/.classpath +++ b/.classpath @@ -7,6 +7,7 @@ + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 2dcdf31..8ceb790 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -2,5 +2,6 @@ + diff --git a/changelog.xml b/changelog.xml index 8122498..42c2631 100644 --- a/changelog.xml +++ b/changelog.xml @@ -1,4 +1,9 @@ + + [Feature #19111]: init settings configurable via property file and GET parameters + + [Task #189812] change the base layer True Marble diff --git a/pom.xml b/pom.xml index 9ba88d0..cc9751b 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.gcube.portlets.user gis-viewer - 4.3.0 + 4.4.0 GIS Viewer Widget GWT Widget application to access GIS Data diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/GisViewer.gwt.xml b/src/main/java/org/gcube/portlets/user/gisviewer/GisViewer.gwt.xml index 2b7fd01..a9edee4 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/GisViewer.gwt.xml +++ b/src/main/java/org/gcube/portlets/user/gisviewer/GisViewer.gwt.xml @@ -1,7 +1,7 @@ - + @@ -19,4 +19,7 @@ + + + diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerMapLoadedNotification.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerMapLoadedNotification.java new file mode 100644 index 0000000..80c46c4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerMapLoadedNotification.java @@ -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 addGisViewerMapLoadedtListener 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 addHasGisViewerMapLoadedNotificationListener 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); + + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerPanel.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerPanel.java index 74670b4..2b966d2 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerPanel.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerPanel.java @@ -7,6 +7,8 @@ import java.util.HashMap; import java.util.List; 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.ExportFormat; 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.Resources; 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.core.XDOM; @@ -71,7 +74,7 @@ import com.google.gwt.user.client.ui.Label; * Sep 26, 2016 */ 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 GisViewerLayout mainPanel; @@ -85,6 +88,8 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle private CqlFilterPanel cqlFilterPanel = new CqlFilterPanel(this); private ClickDataInfo lastClickDataInfo = null; + private GisViewerPanel INSTANCE; + protected List listeners = new ArrayList(); //ADDED BY FRANCESCO /** @@ -150,6 +155,7 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle * Inits the. */ private void init() { + INSTANCE = this; // create an empty layers panel layersPanel = new LayersPanel(this); createOpenLayersMap(); @@ -164,7 +170,7 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle protected void onRender(Element parent, int index) { super.onRender(parent, index); mainPanel.setLayersPanel(layersPanel); - mainPanel.setOpenLayers(openLayersMap); + //mainPanel.setOpenLayers(openLayersMap); } }; @@ -348,12 +354,40 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle * Creates the open layers map. */ 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); -// toolBarPanel.setStyleName("x-toolbar"); - openLayersMap.addToolBar(toolBarPanel); + final LonLat centerMapTo = null; + final Integer initZoomTo = null; + + GisViewer.service.getBaseLayersToGisViewer(new AsyncCallback>() { + + @Override + public void onFailure(Throwable caught) { + Window.alert("Error on istancing the Gis-Viewer. Please contact the support!"); + } + + @Override + public void onSuccess(List 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"); + openLayersMap.addToolBar(toolBarPanel); + mainPanel.setOpenLayers(openLayersMap); + + for (GisViewerMapLoadedtListener listner : listeners) { + listner.onMapLoaded(); + } + } + }); + } /** @@ -1162,4 +1196,17 @@ implements ToolbarHandler, DataPanelHandler, LayersPanelHandler, CqlFilterHandle return toolBarPanel; } + + + @Override + public void addMapLoadedListener(GisViewerMapLoadedtListener handler) { + listeners.add(handler); + + } + + @Override + public void removeMapLoadedListener(GisViewerMapLoadedtListener handler) { + listeners.remove(handler); + + } } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerService.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerService.java index 8392c81..cbf5afe 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerService.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerService.java @@ -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.RemoteServiceRelativePath; +// TODO: Auto-generated Javadoc /** * The client side stub for the RPC service. * @@ -96,5 +97,5 @@ public interface GisViewerService extends RemoteService { * @throws Exception the exception */ GeoInformationForWMSRequest parseWmsRequest(String wmsRequest, String layerName) throws Exception; - + } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerServiceAsync.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerServiceAsync.java index 9f438f2..e26d6f8 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/GisViewerServiceAsync.java @@ -32,33 +32,6 @@ public interface GisViewerServiceAsync { */ public void getDataResult(List urls, AsyncCallback> callback); -// /** -// * Gets the groups info. -// * -// * @param groupName the group name -// * @param callback the callback -// * @return the groups info -// */ -// public void getGroupsInfo(String groupName, AsyncCallback callback); - -// /** -// * Gets the layers info. -// * -// * @param layersName the layers name -// * @param callback the callback -// * @return the layers info -// */ -// public void getLayersInfo(List layersName, AsyncCallback 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 layerItems, AsyncCallback asyncCallback); - /** * Gets the transect parameters. * @@ -125,5 +98,6 @@ public interface GisViewerServiceAsync { * @return the gcube security token */ void getGcubeSecurityToken(AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/openlayers/OpenLayersMap.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/openlayers/OpenLayersMap.java index f6c0b6a..7b282bb 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/openlayers/OpenLayersMap.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/openlayers/OpenLayersMap.java @@ -5,7 +5,6 @@ import java.util.HashMap; import java.util.List; 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.LayerItem; import org.gcube.portlets.user.gisviewer.client.commons.beans.MapViewInfo; @@ -153,6 +152,7 @@ public class OpenLayersMap { } } // constructor + /** * Instantiates a new open layers map. * @@ -160,10 +160,18 @@ public class OpenLayersMap { * @param h the h * @param numZoomLevels the num zoom levels * @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 */ - public OpenLayersMap(String w, String h, int numZoomLevels, // projection, transectUrl removed - String title, final OpenLayersHandler handler) { + public OpenLayersMap(String w, String h, + int numZoomLevels, + String title, + List baseLayers, + final LonLat centerMapTo, + final Integer initZoomTo, + final OpenLayersHandler handler) { this.handler = handler; this.numZoomLevels = numZoomLevels; @@ -231,29 +239,13 @@ public class OpenLayersMap { map.addLayer(vectorLayer); vectorLayer.setZIndex(MAX_ZINDEX); - String wmsURI = GisViewerPanel.resources.baseLayer().getText(); - String[] params = wmsURI.split("\\?"); - - if(params.length<2){ - GWT.log("ERROR: No base layer found!"); + //adding base layers + for (GisViewerBaseLayerInterface baseLayer : baseLayers) { + String baseLayerTitle = baseLayer.getTitle(); + if(baseLayer.isDisplay()) + 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(pamZoomBar); addControl(getMousePosition()); @@ -262,14 +254,20 @@ public class OpenLayersMap { addTransectControl(); addBoxControl(); - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - - @Override - public void execute() { - GWT.log("Centering on Italy"); - map.setCenter(new LonLat(12.45, 42.98), 6); - } - }); + if(centerMapTo!=null) { + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + + @Override + public void execute() { + GWT.log("Centering on Italy"); + //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 */ 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("")) return; LayerItem l = new LayerItem(true); diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/client/resources/Resources.java b/src/main/java/org/gcube/portlets/user/gisviewer/client/resources/Resources.java index 62445bb..30beaae 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/client/resources/Resources.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/client/resources/Resources.java @@ -122,6 +122,6 @@ public interface Resources extends ClientBundle { ImageResource gisViewerIcon(); - @Source("baselayer.txt") - TextResource baseLayer(); +// @Source("baselayer.txt") +// TextResource baseLayer(); } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/server/DefaultGisViewerServiceImpl.java b/src/main/java/org/gcube/portlets/user/gisviewer/server/DefaultGisViewerServiceImpl.java index 32038a1..f22ebb3 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/server/DefaultGisViewerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/server/DefaultGisViewerServiceImpl.java @@ -3,7 +3,7 @@ */ package org.gcube.portlets.user.gisviewer.server; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.apache.log4j.Logger; @@ -61,19 +61,16 @@ public class DefaultGisViewerServiceImpl extends GisViewerServiceImpl { protected List getBaseLayersToAddGisViewer() throws Exception { BaseLayerPropertyReader bl = null; + List baseLayers = null; try{ logger.info("Instancing BaseLayerPropertyReader"); bl = new BaseLayerPropertyReader(); + baseLayers = BaseLayerPropertyReader.readBaseLayers(); logger.info("Read base layer: "+bl); }catch(Exception e){ - logger.error("Error on reading BaseLayerPropertyReader! Returning hardcode wms base layer"); - bl = null; + logger.error("Error on reading base layers trough "+BaseLayerPropertyReader.class.getName()+". Returning hardcoded wms base layer"); } - 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() { @Override @@ -83,25 +80,24 @@ public class DefaultGisViewerServiceImpl extends GisViewerServiceImpl { @Override public String getWmsServiceBaseURL() { - return layerWmsUrl; + return "http://geoserver1.d4science.org/geoserver/aquamaps/wms"; } @Override public String getTitle() { - return layerTitle; + return "True Marble"; } @Override public String getName() { - // TODO Auto-generated method stub - return layerName; + return "aquamaps:TrueMarble.16km.2700x1350"; } }; - List baseLayer = new ArrayList(1); - baseLayer.add(trueMarble); - - return baseLayer; + if(baseLayers==null) { + baseLayers = Arrays.asList(trueMarble); + } + return baseLayers; } /* (non-Javadoc) @@ -111,5 +107,4 @@ public class DefaultGisViewerServiceImpl extends GisViewerServiceImpl { public String getGcubeSecurityToken() { return null; } - } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/server/GisViewerServiceImpl.java b/src/main/java/org/gcube/portlets/user/gisviewer/server/GisViewerServiceImpl.java index b55b2c3..2dcec71 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/server/GisViewerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/server/GisViewerServiceImpl.java @@ -64,39 +64,6 @@ public abstract class GisViewerServiceImpl extends RemoteServiceServlet implemen */ 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) * @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 layersName) { -// LayerItemsResult layerItemsResult = new LayerItemsResult(); -// -// Map geoserverCallers = new HashMap(); -// 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 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) * @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 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 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 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 properties = FeatureTypeParser.getProperties(gsUrl, layerItem.getLayer()); -// layerItem.setProperties(properties); -// setDefaultOpacity(layerItem); -// -// return layerItem; -// } -// } - /** * 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"); } } + } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/BaseLayerPropertyReader.java b/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/BaseLayerPropertyReader.java index 50ffef6..988eff4 100644 --- a/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/BaseLayerPropertyReader.java +++ b/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/BaseLayerPropertyReader.java @@ -1,176 +1,84 @@ package org.gcube.portlets.user.gisviewer.server.baselayer; +import java.io.File; import java.io.IOException; 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.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. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Sep 28, 2015 + * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) + * Apr 21, 2020 */ public class BaseLayerPropertyReader { - protected static final String BASE_LAYER_FILE = "baselayer.properties"; - 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; + protected static final String BASE_LAYER_FILE = "baselayers.csv"; public static Logger logger = Logger .getLogger(BaseLayerPropertyReader.class); - + /** - * Instantiates a new base layer property reader. + * Read base layers. * + * @return the list * @throws PropertyFileNotFoundException the property file not found exception */ - public BaseLayerPropertyReader() throws PropertyFileNotFoundException { - - Properties prop = new Properties(); + public static List readBaseLayers() throws PropertyFileNotFoundException { try { - + InputStream in = (InputStream) BaseLayerPropertyReader.class.getResourceAsStream(BASE_LAYER_FILE); + File baseLayersFile = FileUtil.inputStreamToFile(in); + CSVReader reader = new CSVReader(baseLayersFile); + CSVFile csvFile = reader.getCsvFile(); + List listBaseLayers = new ArrayList(csvFile.getValueRows().size()); - // load a properties file - prop.load(in); + for (CSVRow row : csvFile.getValueRows()) { + GisViewerBaseLayer baseLayer = new GisViewerBaseLayer(); + List headerKeys = csvFile.getHeaderRow().getListValues(); + Map mapProperties = new HashMap(row.getListValues().size()); + int i = 0; + //to map properties + List 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); + } + + listBaseLayers.add(baseLayer); + } - this.layerWmsUrl = prop.getProperty(BASELAYER_WMS_SERVER); - this.layerTitle = prop.getProperty(BASELAYER_TITLE); - this.layerName = prop.getProperty(BASELAYER_LAYERS); + return listBaseLayers; } 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( - "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(); - } - }*/ - } diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/baselayer.properties b/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/baselayer.properties deleted file mode 100644 index 9d3e47c..0000000 --- a/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/baselayer.properties +++ /dev/null @@ -1,3 +0,0 @@ -BASELAYER_WMS_SERVER = http://geoserver1.d4science.org/geoserver/aquamaps/wms -BASELAYER_LAYERS = aquamaps:TrueMarble.16km.2700x1350 -BASELAYER_TITLE = True Marble \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/baselayers.csv b/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/baselayers.csv new file mode 100644 index 0000000..1ae3e97 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewer/server/baselayer/baselayers.csv @@ -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" \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/server/util/CSVReader.java b/src/main/java/org/gcube/portlets/user/gisviewer/server/util/CSVReader.java new file mode 100644 index 0000000..17e5723 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewer/server/util/CSVReader.java @@ -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 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 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 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 parseLine(String cvsLine, char separators, char customQuote) { + + List 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; + } +} diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/server/util/FileUtil.java b/src/main/java/org/gcube/portlets/user/gisviewer/server/util/FileUtil.java new file mode 100644 index 0000000..6641b7c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewer/server/util/FileUtil.java @@ -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(); + } + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/shared/CSVFile.java b/src/main/java/org/gcube/portlets/user/gisviewer/shared/CSVFile.java new file mode 100644 index 0000000..118c853 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewer/shared/CSVFile.java @@ -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 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 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 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(); + + 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(); + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/shared/CSVRow.java b/src/main/java/org/gcube/portlets/user/gisviewer/shared/CSVRow.java new file mode 100644 index 0000000..c6380de --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewer/shared/CSVRow.java @@ -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 listValues; + + /** + * Instantiates a new CSV row. + */ + public CSVRow(){ + + } + + + /** + * Gets the list values. + * + * @return the listValues + */ + public List getListValues() { + + return listValues; + } + + + + /** + * @param listValues the listValues to set + */ + public void setListValues(List 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(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/gisviewer/shared/GisViewerBaseLayer.java b/src/main/java/org/gcube/portlets/user/gisviewer/shared/GisViewerBaseLayer.java new file mode 100644 index 0000000..3bd7131 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/gisviewer/shared/GisViewerBaseLayer.java @@ -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 mapProperties; + private String title; + private String name; + private String wmsServiceBaseURL; + private boolean display; + + public GisViewerBaseLayer() { + + } + + public GisViewerBaseLayer(Map 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 mapProperties) { + this.mapProperties = mapProperties; + } + + public Map getMapProperties() { + return mapProperties; + } + + @Override + public String toString() { + return "GisViewerBaseLayer [mapProperties=" + mapProperties + ", title=" + title + ", name=" + name + + ", wmsServiceBaseURL=" + wmsServiceBaseURL + ", display=" + display + "]"; + } + +} diff --git a/src/main/test/org/gcube/portlets/user/gisviewer/test/client/PropertyFiles.java b/src/main/test/org/gcube/portlets/user/gisviewer/test/client/PropertyFiles.java new file mode 100644 index 0000000..1167ba9 --- /dev/null +++ b/src/main/test/org/gcube/portlets/user/gisviewer/test/client/PropertyFiles.java @@ -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 layers = BaseLayerPropertyReader.readBaseLayers(); + + for (GisViewerBaseLayer gisViewerBaseLayer : layers) { + System.err.println(gisViewerBaseLayer); + } + } + +}