diff --git a/pom.xml b/pom.xml index 89c084c..b7cb944 100644 --- a/pom.xml +++ b/pom.xml @@ -234,6 +234,7 @@ 4.11 test + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java index b3d5446..68dcea9 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java @@ -1,14 +1,13 @@ package org.gcube.portlets.user.geoportaldataviewer.client; -import java.util.ArrayList; -import java.util.Iterator; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; -import org.gcube.application.geoportalcommon.shared.LayerItem; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; @@ -38,14 +37,19 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowPopupOnCent import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowPopupOnCentroiEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.ZoomOutOverMinimumEventHandler; +import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.OpenCollectionEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.OpenCollectionEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped; import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils; import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap; import org.gcube.portlets.user.geoportaldataviewer.client.ui.GeonaDataViewMainPanel; +import org.gcube.portlets.user.geoportaldataviewer.client.util.ControlledCallBack; import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon; -import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; +import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection; +import org.gcube.portlets.user.geoportaldataviewer.shared.ViewerConfiguration; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.IndexLayer; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; @@ -104,16 +108,14 @@ public class GeoportalDataViewer implements EntryPoint { private OLMapManager olMapMng = null; int attempt = 0; - + private LoaderIcon loaderApp = new LoaderIcon("Loading application... please wait"); - + private HTML attributionDiv = new HTML(); - + private static List listBaseMapLayers = null; - - private List displayFields = new ArrayList(); - private List sortByFields = new ArrayList(); - private List searchByFields = new ArrayList(); + + private static ViewerStatus viewerStatus = new ViewerStatus(); /** * This is the entry point method. @@ -122,7 +124,7 @@ public class GeoportalDataViewer implements EntryPoint { loaderApp.getElement().addClassName("loader-gna-app"); RootPanel.get(APP_DIV).add(loaderApp); - + paramWmsRequest = Window.Location.getParameter(GeoportalDataViewerConstants.GET_WMS_PARAMETER); paramGeonaItemType = Window.Location.getParameter(GeoportalDataViewerConstants.GET_GEONA_ITEM_TYPE); paramGeonaItemID = Window.Location.getParameter(GeoportalDataViewerConstants.GET_GEONA_ITEM_ID); @@ -131,162 +133,81 @@ public class GeoportalDataViewer implements EntryPoint { GWT.log(GeoportalDataViewerConstants.GET_GEONA_ITEM_TYPE + " = " + paramGeonaItemType); GWT.log(GeoportalDataViewerConstants.GET_GEONA_ITEM_ID + " = " + paramGeonaItemID); GWT.log(GeoportalDataViewerConstants.GET_LAYER_TITLE + " = " + paramLayerTitle); - + RootPanel.get(APP_DIV).add(loaderApp); - - GeoportalDataViewerServiceAsync.Util.getInstance().listOfFieldsForSearching(new AsyncCallback>>() { - @Override - public void onFailure(Throwable caught) { - Window.alert(caught.getMessage()); - - } - - @Override - public void onSuccess(Map> mapOfSearchingFilterForUCD) { - GWT.log("listOfFieldsForSearching: "+mapOfSearchingFilterForUCD); - -// for (ItemFieldDV itemField : result) { -// if(itemField.isDisplayAsResult()) { -// displayFields.add(itemField); -// } -// -// if(itemField.isSearchable()) { -// searchByFields.add(itemField); -// } -// -// if(itemField.isSortable()) { -// sortByFields.add(itemField); -// } -// } -// -// -// GWT.log("List display fields: "+result); -// SearchingFilter initialSortFilter = new SearchingFilter(); -// initialSortFilter.setOrder(ORDER.ASC); - - //TODO MUST BE REVISITED - //initialSortFilter.setOrderByFields(Arrays.asList(new ItemField("Name", Arrays.asList("name"), true, true, true))); - - mainPanel = new GeonaDataViewMainPanel(applicationBus, getClientHeight(),mapOfSearchingFilterForUCD); - RootPanel.get(APP_DIV).add(mainPanel); - - initApplication(); - } - - - }); - - } - - private void initApplication() { - - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - - @Override - public void execute() { - - //LOADING THE BASE MAP LAYERS - GeoportalDataViewerServiceAsync.Util.getInstance().getListBaseLayers(new AsyncCallback>() { + GeoportalDataViewerServiceAsync.Util.getInstance() + .listOfFieldsForSearching(new AsyncCallback>>() { @Override public void onFailure(Throwable caught) { - RootPanel.get(APP_DIV).remove(loaderApp); - Window.alert("Sorry, an error occurred on instancing the GeoPortale Viewer. Please, contact the support"); + Window.alert(caught.getMessage()); + } @Override - public void onSuccess(List listBaseMapLayers) { - try { - RootPanel.get(APP_DIV).remove(loaderApp); - }catch (Exception e) { - loaderApp.setVisible(false); - } - GeoportalDataViewer.listBaseMapLayers = listBaseMapLayers; - //now the map is loaded and I'm sure that I can load the GeonaDataViewer Profile - loadGeonaDataViewerProfile(); - mainPanel.setBaseLayers(listBaseMapLayers); - - BaseMapLayer firstBaseLayer = listBaseMapLayers.get(0); - //Passing the first base map layer that will be applied as first base layer - olMapMng = new OLMapManager(mainPanel.getMapPanel().getElement().getId(), - layerManager.getLayerManagerBus(), firstBaseLayer); - OpenLayerMap olMap = olMapMng.getOLMap(); - layerManager.setOLMap(olMap); - mainPanel.setMap(olMap); - - updateSize(); - ScriptInjector.fromUrl("//cdnjs.cloudflare.com/ajax/libs/nanogallery2/3.0.5/jquery.nanogallery2.min.js") - .setWindow(ScriptInjector.TOP_WINDOW).inject(); - + public void onSuccess(Map> mapOfSearchingFilterForUCD) { + GWT.log("listOfFieldsForSearching: " + mapOfSearchingFilterForUCD); + + mainPanel = new GeonaDataViewMainPanel(applicationBus, getClientHeight(), + mapOfSearchingFilterForUCD); + RootPanel.get(APP_DIV).add(mainPanel); + + initApplication(); } - }); - - } - }); - Window.addResizeHandler(new ResizeHandler() { - @Override - public void onResize(ResizeEvent event) { - updateSize(); - } - }); + } + + private void initApplication() { - bindEvents(); - - RootPanel.get(APP_DIV).add(attributionDiv); - - } - - public static List getListBaseMapLayers() { - return listBaseMapLayers; - } - - private void loadGeonaDataViewerProfile() { - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override public void execute() { + GeoportalDataViewerServiceAsync.Util.getInstance() - .getGeoNaDataViewProfile(new AsyncCallback() { + .getInitialConfiguration(new ControlledCallBack() { @Override public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); - } @Override - public void onSuccess(GNADataViewerConfigProfile profile) { - geonaDataViewerProfile = profile; - GWT.log("Profile: " + geonaDataViewerProfile); - Iterator it; - - - - String theItemType = null; - if (theItemType == null) { - it = geonaDataViewerProfile.getMapLayers().keySet().iterator(); - it.hasNext(); - theItemType = it.next(); - } + public void after() { + RootPanel.get(APP_DIV).remove(loaderApp); + } - LayerItem layerItem = geonaDataViewerProfile.getMapLayers().get(theItemType); + @Override + public void onSuccess(ViewerConfiguration result) { + super.onSuccess(result); -// if (layerItem == null) { -// Window.alert("Not detected any layer with type: " + theItemType); -// return; -// } + GWT.log("Received init config : " + result); + GWT.log("Loading base layers, count : " + result.getBaseLayers().size()); - GWT.log("ON module load The layerItem is: " + layerItem); - String layerName = URLUtil.getValueOfParameter("layers", layerItem.getWmsLink()); - layerItem.setName(layerName); - layerManager.setBaseLayerFromIsProfile(layerItem); - layerManager.addLayer(theItemType, null, null, layerItem.getWmsLink(), false, false, - null, false, null, null, null); + GeoportalDataViewer.getStatus().setConfig(result); + + listBaseMapLayers = result.getBaseLayers(); + mainPanel.setBaseLayers(result.getBaseLayers()); + + BaseMapLayer firstBaseLayer = result.getBaseLayers().get(0); + // Passing the first base map layer that will be applied as first base layer + olMapMng = new OLMapManager(mainPanel.getMapPanel().getElement().getId(), + layerManager.getLayerManagerBus(), firstBaseLayer); + OpenLayerMap olMap = olMapMng.getOLMap(); + layerManager.setOLMap(olMap); + mainPanel.setMap(olMap); + + updateSize(); + + ScriptInjector.fromUrl( + "//cdnjs.cloudflare.com/ajax/libs/nanogallery2/3.0.5/jquery.nanogallery2.min.js") + .setWindow(ScriptInjector.TOP_WINDOW).inject(); + + GWT.log("Loading collections, count " + result.getAvailableCollections().size()); + + mainPanel.setAvailableCollections(result.getAvailableCollections().values()); if (paramGeonaItemID != null) { if (paramGeonaItemType == null) { @@ -300,13 +221,99 @@ public class GeoportalDataViewer implements EntryPoint { applicationBus.fireEvent(new ShowDetailsEvent(gir, null, null)); } + // TODO LOAD INITIAL LAYERS + + GWT.log("DONE INIT LOAD"); } + }); } }); - + + Window.addResizeHandler(new ResizeHandler() { + @Override + public void onResize(ResizeEvent event) { + updateSize(); + } + }); + + bindEvents(); + + RootPanel.get(APP_DIV).add(attributionDiv); + } + public static ViewerStatus getStatus() { + return viewerStatus; + } + + public static List getListBaseMapLayers() { + return listBaseMapLayers; + } + +// private void loadGeonaDataViewerProfile() { +// +// Scheduler.get().scheduleDeferred(new ScheduledCommand() { +// +// @Override +// public void execute() { +// GeoportalDataViewerServiceAsync.Util.getInstance() +// .getGeoNaDataViewProfile(new AsyncCallback() { +// +// @Override +// public void onFailure(Throwable caught) { +// Window.alert(caught.getMessage()); +// +// } +// +// @Override +// public void onSuccess(GNADataViewerConfigProfile profile) { +// geonaDataViewerProfile = profile; +// GWT.log("Profile: " + geonaDataViewerProfile); +// Iterator it; +// +// String theItemType = null; +// if (theItemType == null) { +// it = geonaDataViewerProfile.getMapLayers().keySet().iterator(); +// it.hasNext(); +// theItemType = it.next(); +// } +// +// GWT.log("getGeoNaDataViewProfile theItemType is: " + theItemType); +// +// LayerItem layerItem = geonaDataViewerProfile.getMapLayers().get(theItemType); +// +//// if (layerItem == null) { +//// Window.alert("Not detected any layer with type: " + theItemType); +//// return; +//// } +// +// GWT.log("ON module load The layerItem is: " + layerItem); +// String layerName = URLUtil.getValueOfParameter("layers", layerItem.getWmsLink()); +// layerItem.setName(layerName); +// layerManager.setBaseLayerFromIsProfile(layerItem); +// layerManager.addLayer(theItemType, null, null, layerItem.getWmsLink(), false, false, +// null, false, null, null, null); +// +// if (paramGeonaItemID != null) { +// if (paramGeonaItemType == null) { +// Window.alert( +// "Missing parameter " + GeoportalDataViewerConstants.GET_GEONA_ITEM_TYPE +// + " (GeoNa Data Type) where to search the item id: " +// + paramGeonaItemID); +// return; +// } +// GeoNaItemRef gir = new GeoNaItemRef(paramGeonaItemID, paramGeonaItemType); +// applicationBus.fireEvent(new ShowDetailsEvent(gir, null, null)); +// } +// +// } +// }); +// } +// }); +// +// } + /** * Update window size. */ @@ -331,14 +338,75 @@ public class GeoportalDataViewer implements EntryPoint { */ private void bindEvents() { + applicationBus.addHandler(OpenCollectionEvent.TYPE, new OpenCollectionEventHandler() { + + @Override + public void onOpenCollection(OpenCollectionEvent openCollectionEvent) { + GWT.log("Fired event: " + openCollectionEvent); + // Check if ID is available + String collId = openCollectionEvent.getCollectionId(); + ViewerConfiguration theConfig = GeoportalDataViewer.getStatus().getViewerConfig(); + + Set ucdIds = theConfig.getAvailableCollections().keySet(); + + if (!ucdIds.contains(collId)) { + GWT.log("!! Collection " + collId + " is not available"); + Window.alert("Collection " + collId + " is not found."); + } else { + GCubeCollection toOpen = theConfig.getAvailableCollections().get(collId); + + // Check if indexes is empty + if (toOpen.getIndexes() == null || toOpen.getIndexes().isEmpty()) { + GWT.log("Unexpected empty indexes in collection " + toOpen); + Window.alert("Cannot open collection index layer for " + toOpen.getUcd().getName() + "."); + } + // TODO Get Default Index Layer + // For now we just take the first - only 1 is expected + IndexLayer layer = toOpen.getIndexes().get(0); + // Open Index Layer + + layerManager.addIndexLayer(layer); + } + } + }); + +// applicationBus.addHandler(OpenCollectionEvent.TYPE, openCollectionEvent -> { +// GWT.log("Fired event: " + openCollectionEvent); +// // Check if ID is available +// String collId = openCollectionEvent.getCollectionId(); +// ViewerConfiguration theConfig = GeoportalDataViewer.getStatus().getViewerConfig(); +// +// Set ucdIds = theConfig.getAvailableCollections().keySet(); +// +// if (!ucdIds.contains(collId)) { +// GWT.log("!! Collection " + collId + " is not available"); +// Window.alert("Collection " + collId + " is not found."); +// } else { +// GCubeCollection toOpen = theConfig.getAvailableCollections().get(collId); +// +// // Check if indexes is empty +// if (toOpen.getIndexes() == null || toOpen.getIndexes().isEmpty()) { +// GWT.log("Unexpected empty indexes in collection " + toOpen); +// Window.alert("Cannot open collection index layer for " + toOpen.getUcd().getName() + "."); +// } +// // TODO Get Default Index Layer +// // For now we just take the first - only 1 is expected +// IndexLayer layer = toOpen.getIndexes().get(0); +// // Open Index Layer +// +// layerManager.addIndexLayer(layer); +// +// } +// }); + applicationBus.addHandler(ShowDetailsEvent.TYPE, new ShowDetailsEventHandler() { @Override public void onShowDetails(ShowDetailsEvent showDetailsEvent) { GWT.log("Fired event: " + showDetailsEvent); - String projectID = showDetailsEvent.getGeonaMongoID(); - String profileID = showDetailsEvent.getGeonaItemType(); + String projectID = showDetailsEvent.getProjectID(); + String profileID = showDetailsEvent.getProfileID(); if (projectID == null) { Window.alert("Item Id not found"); @@ -348,21 +416,21 @@ public class GeoportalDataViewer implements EntryPoint { // TODO boolean found = false; GWT.log("Product with id: " + projectID + " found? " + found); - - - GeoportalDataViewerServiceAsync.Util.getInstance().getProjectViewForId(profileID, projectID, new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - // TODO Auto-generated method stub - - } + GeoportalDataViewerServiceAsync.Util.getInstance().getProjectViewForId(profileID, projectID, + new AsyncCallback() { - @Override - public void onSuccess(ProjectView result) { - mainPanel.showAsDetails(result, showDetailsEvent.getGeonaItemRef()); - } - }); + @Override + public void onFailure(Throwable caught) { + // TODO Auto-generated method stub + + } + + @Override + public void onSuccess(ProjectView result) { + mainPanel.showAsDetails(result, showDetailsEvent.getGeonaItemRef()); + } + }); // if (!found) { // @@ -394,48 +462,40 @@ public class GeoportalDataViewer implements EntryPoint { @Override public void onLayerRendered(AddedLayerToMapEvent addedLayerToMapEvent) { - GWT.log("Fired AddedLayerToMapEvent " + addedLayerToMapEvent.getLayerItem() + "layer type: "+addedLayerToMapEvent.getLayerType()); - + GWT.log("Fired AddedLayerToMapEvent " + addedLayerToMapEvent.getLayerItem() + "layer type: " + + addedLayerToMapEvent.getLayerType()); + try { GWT.log("onLayerRendered Timer PART MUST BE REVISITED"); /* - attempt = 0; - - if (paramGeonaItemID != null) { - // waiting for record retrieved by service before calling the WFS - final int MAX_RETRY = 15; - Timer timer = new com.google.gwt.user.client.Timer() { - @Override - public void run() { - attempt++; - GWT.log("waiting get record: " + attempt); - - - - - RecordDV record = mainPanel.getDisplayedRecord(); - if (record != null) { - this.cancel(); - GWT.log("cancelled timer"); - performWFSQueryOnCentroid(record); - } - - if (attempt > MAX_RETRY) { - GWT.log("MAX_RETRY reached, cancelled timer"); - this.cancel(); - } - - } - }; - timer.scheduleRepeating(1000); - - } - */ + * attempt = 0; + * + * if (paramGeonaItemID != null) { // waiting for record retrieved by service + * before calling the WFS final int MAX_RETRY = 15; Timer timer = new + * com.google.gwt.user.client.Timer() { + * + * @Override public void run() { attempt++; GWT.log("waiting get record: " + + * attempt); + * + * + * + * + * RecordDV record = mainPanel.getDisplayedRecord(); if (record != null) { + * this.cancel(); GWT.log("cancelled timer"); performWFSQueryOnCentroid(record); + * } + * + * if (attempt > MAX_RETRY) { GWT.log("MAX_RETRY reached, cancelled timer"); + * this.cancel(); } + * + * } }; timer.scheduleRepeating(1000); + * + * } + */ } catch (Exception e) { // TODO: handle exception } - + LAYER_TYPE layerType = addedLayerToMapEvent.getLayerType(); if (layerType != null) { @@ -497,29 +557,29 @@ public class GeoportalDataViewer implements EntryPoint { public void onDoActionOnDetailLayers(DoActionOnDetailLayersEvent doLayerActionEvent) { DO_LAYER_ACTION doAction = doLayerActionEvent.getDoAction(); - GWT.log("event: "+doAction); - GWT.log("layer source: "+doLayerActionEvent.getLayerItem().getName()); + GWT.log("event: " + doAction); + GWT.log("layer source: " + doLayerActionEvent.getLayerItem().getName()); OpenLayerMap olMap = olMapMng.getOLMap(); - + switch (doAction) { case OPACITY: - GWT.log("opacity: "+doLayerActionEvent.getOpacity()); - olMap.setWMSDetailLayerOpacity(doLayerActionEvent.getLayerItem(), - doLayerActionEvent.getOpacity()); + GWT.log("opacity: " + doLayerActionEvent.getOpacity()); + olMap.setWMSDetailLayerOpacity(doLayerActionEvent.getLayerItem(), doLayerActionEvent.getOpacity()); break; case SWAP: SwapLayer swLS = doLayerActionEvent.getSourceLayerSwap(); SwapLayer swLT = doLayerActionEvent.getTargetLayerSwap(); - GWT.log("SWAPPING source "+swLS.getLayerItem().getName() +", target: "+swLT.getLayerItem().getName()); + GWT.log("SWAPPING source " + swLS.getLayerItem().getName() + ", target: " + + swLT.getLayerItem().getName()); olMap.swapDetailsLayers(swLS, swLT); break; case VISIBILITY: - GWT.log("visibility: "+doLayerActionEvent.getVisibility()); + GWT.log("visibility: " + doLayerActionEvent.getVisibility()); olMap.setWMSDetailLayerVisible(doLayerActionEvent.getLayerItem(), doLayerActionEvent.getVisibility()); - + break; default: @@ -528,8 +588,7 @@ public class GeoportalDataViewer implements EntryPoint { } }); - - + applicationBus.addHandler(ChangeMapLayerEvent.TYPE, new ChangeMapLayerEventHandler() { @Override @@ -552,48 +611,47 @@ public class GeoportalDataViewer implements EntryPoint { } }); - + applicationBus.addHandler(ShowPopupOnCentroiEvent.TYPE, new ShowPopupOnCentroiEventHandler() { - + @Override public void onShowPopup(ShowPopupOnCentroiEvent showPopupOnCentroiEvent) { - - if(showPopupOnCentroiEvent.getRecord()!=null) + + if (showPopupOnCentroiEvent.getRecord() != null) performWFSQueryOnCentroid(showPopupOnCentroiEvent.getRecord()); - + } }); - + applicationBus.addHandler(SearchPerformedEvent.TYPE, new SearchPerformedEventHandler() { - + @Override public void onSearchDone(SearchPerformedEvent searchPerformedEvent) { - - if(searchPerformedEvent!=null) { - + + if (searchPerformedEvent != null) { + LinkedHashMap wmsMap = olMapMng.getOLMap().getWmsLayerMap(); String firstWMSKey = wmsMap.keySet().iterator().next(); List result = searchPerformedEvent.getData(); - - if(result!=null && result.size()>0) { + + if (result != null && result.size() > 0) { String cqlFilter = "product_id IN("; for (DocumentDV documentDV : result) { - cqlFilter+="'"+documentDV.getProjectID()+"',"; + cqlFilter += "'" + documentDV.getProjectID() + "',"; } - cqlFilter = cqlFilter.substring(0,cqlFilter.length()-1)+")"; - + cqlFilter = cqlFilter.substring(0, cqlFilter.length() - 1) + ")"; + olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, cqlFilter); - }else { + } else { olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null); } - - if(searchPerformedEvent.isSearchReset()) { + + if (searchPerformedEvent.isSearchReset()) { olMapMng.getOLMap().setCQLFilterToWMSLayer(firstWMSKey, null); } } - - + } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java index 53fe79d..9e3893a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerService.java @@ -14,6 +14,7 @@ import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult; +import org.gcube.portlets.user.geoportaldataviewer.shared.ViewerConfiguration; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; @@ -177,4 +178,37 @@ public interface GeoportalDataViewerService extends RemoteService { ResultSetPaginatedData getListProjects(String theProfileID, Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService) throws Exception; + /** + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * NEW CODE HERE + * + * + * + * + * + * + * + * + * + * + * + * + * + */ + + ViewerConfiguration getInitialConfiguration() throws Exception; + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java index 233c047..4226b55 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerServiceAsync.java @@ -14,6 +14,7 @@ import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult; +import org.gcube.portlets.user.geoportaldataviewer.shared.ViewerConfiguration; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; @@ -75,4 +76,6 @@ public interface GeoportalDataViewerServiceAsync { void getListProjects(String theProfileID, Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService, AsyncCallback callback); + void getInitialConfiguration(AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java index 671678c..e331f44 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java @@ -10,13 +10,10 @@ import java.util.List; import java.util.Map; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; -import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; -import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.LayerType; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; -import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MapEventType; import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.AddedLayerToMapEventHandler; import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent; @@ -32,22 +29,20 @@ import org.gcube.portlets.user.geoportaldataviewer.client.util.StringUtil; import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.GeoQuery; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.IndexLayer; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObjectType; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis; import com.github.gwtbootstrap.client.ui.Button; -import com.github.gwtbootstrap.client.ui.Heading; -import com.github.gwtbootstrap.client.ui.Label; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.IconType; -import com.github.gwtbootstrap.client.ui.constants.LabelType; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; @@ -57,7 +52,6 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; -import com.google.gwt.user.client.Random; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.FlexTable; @@ -196,10 +190,14 @@ public class LayerManager { public void onSuccess(List listGeonaDataObjects) { GWT.log("GeoNaDataObject's is/are " + listGeonaDataObjects.size()); + // GWT.log("GeoNaDataObject's: " + listGeonaDataObjects); // GeoportalDataViewerConstants.print("GeoNaDataObject's: // "+listGeonaDataObjects); - + GWT.log("GeoNaDataObject's must be revisited"); + /* + + if (listGeonaDataObjects == null || listGeonaDataObjects.isEmpty()) return; @@ -350,6 +348,9 @@ public class LayerManager { } } } + + */ + } }); } @@ -388,11 +389,11 @@ public class LayerManager { /** * Parses the geona references. * - * @param itemType the item type - * @param fRow the f row + * @param layerObject the layer object + * @param fRow the f row * @return the show details event */ - private ShowDetailsEvent parseGeonaReferences(String itemType, FeatureRow fRow) { + private ShowDetailsEvent parseGeonaReferences(LayerObject layerObject, FeatureRow fRow) { if (fRow == null) return null; @@ -405,31 +406,66 @@ public class LayerManager { itemName = listName.get(0); } - return new ShowDetailsEvent(itemType, productId, itemName, fRow); + LayerObjectType layerObjectType = layerObject.getType(); + return new ShowDetailsEvent(layerObjectType != null ? layerObjectType.name() : null, layerObject.getUcid(), + productId, itemName, fRow); } return null; } + // ******************************** LAYERS Management + /** * Adds the layer. * - * @param geonaItemType the geona item type - * @param layerTitle the layer title - * @param layerName the layer name - * @param wmsLink the wms link - * @param isBase the is base - * @param displayInLayerSwitcher the display in layer switcher - * @param UUID the uuid - * @param asDetailLayer the as detail layer - * @param minResolution the min resolution - * @param maxResolution the max resolution - * @param refersToBaseConcessione the refers to base concessione + * @param object the object */ - public void addLayer(final String geonaItemType, final String layerTitle, final String layerName, + public void addLayer(LayerObject object) { + GWT.log("Layers management : Add layer " + object); + + switch (object.getType()) { + case BASE_LAYER: { + GWT.log("ERROR : cannot add base layers "); + break; + } + case GENERIC_LAYER: { + GWT.log("SUPPORT TO EXTERNAL LAYERS TO BE IMPLEMENTED"); + break; + } + + case PROJECT_LAYER: { + + break; + } + + case INDEX_LAYER: { + break; + } + } + } + + + /** + * Adds the layer. + * + * @param lot the lot + * @param layerTitle the layer title + * @param layerName the layer name + * @param wmsLink the wms link + * @param isBase the is base + * @param displayInLayerSwitcher the display in layer switcher + * @param UUID the uuid + * @param asDetailLayer the as detail layer + * @param minResolution the min resolution + * @param maxResolution the max resolution + * @param profileID the profile ID + * @param projectID the project ID + */ + public void addLayer(final LayerObjectType lot, final String layerTitle, final String layerName, final String wmsLink, final boolean isBase, final boolean displayInLayerSwitcher, final String UUID, final boolean asDetailLayer, Double minResolution, Double maxResolution, - BaseConcessioneDV refersToBaseConcessione) { + String profileID, String projectID) { // final LayoutContainer westPanel = (LayoutContainer) layersPanel.getParent(); // @@ -473,14 +509,13 @@ public class LayerManager { LayerObject lo = new LayerObject(); lo.setLayerItem(layerItem); - lo.setItemType(geonaItemType); - lo.setSourceConcessione(refersToBaseConcessione); + lo.setType(lot); + lo.setProjectId(projectID); - String key = layerItem.getName(); // should be unique - // layerObjects.put(key, lo); + String key = layerItem.getName(); // should be unique // + //layerObjects.put(key, lo); - if (!asDetailLayer) { - // is a base layer + if (!asDetailLayer) { // is a base layer LayerObject blo = LayerObject blo = mapBaseLayerObjects.get(key); if (blo == null) { olMap.addWMSLayer(layerItem); @@ -493,16 +528,30 @@ public class LayerManager { if (dlo == null) { mapDetailLayerObjects.put(key, lo); olMap.addWMSDetailLayer(layerItem); - overlayLayerManager.addLayerItem(lo); - // overlayLayerManager.show(); - } else { + overlayLayerManager.addLayerItem(lo); // overlayLayerManager.show(); } else { GWT.log("Skipping detail layer " + key + " already added to Map"); } } + } }); } + /** + * Adds the index layer. + * + * @param layer the layer + */ + public void addIndexLayer(IndexLayer layer) { + + addLayer(LayerObjectType.INDEX_LAYER, null, null, layer.getLayer().getOgcLinks().get("wms"), false, false, null, false, + null, null, null, null); + + // toLayerItem(null, null, null, null, null, false, false, false, null, null, + // false, null, false, null, null, null, null) + + } + /** * To layer item. * @@ -663,106 +712,82 @@ public class LayerManager { continue; } - String nomeConcessione = lo.getSourceConcessione().getNome(); - if (prevConcessioneName.compareTo(nomeConcessione) != 0) { - String concessioneIntro = nomeConcessione.length() > 100 - ? StringUtil.ellipsize(nomeConcessione, 100) - : nomeConcessione; - Heading heading = new Heading(4, concessioneIntro); - heading.setTitle(nomeConcessione); - heading.getElement().getStyle().setMarginBottom(10, Unit.PX); - flowPanel.add(heading); + GWT.log("showPopupInfoForLayer must be REVISITED"); + /* + * String nomeConcessione = lo.getSourceConcessione().getNome(); if + * (prevConcessioneName.compareTo(nomeConcessione) != 0) { String + * concessioneIntro = nomeConcessione.length() > 100 ? + * StringUtil.ellipsize(nomeConcessione, 100) : nomeConcessione; Heading heading + * = new Heading(4, concessioneIntro); heading.setTitle(nomeConcessione); + * heading.getElement().getStyle().setMarginBottom(10, Unit.PX); + * flowPanel.add(heading); + * + * Button buttOpenProject = new Button("Open Project"); final String buttId = + * "open-details-" + Random.nextInt(); Element bEl = + * buttOpenProject.getElement(); bEl.setId(buttId); + * bEl.getStyle().setPaddingLeft(0, Unit.PX); + * buttOpenProject.setType(ButtonType.LINK); + * + * if (buttOpenProject != null) { flowPanel.add(buttOpenProject); + * buttOpenProject.setType(ButtonType.LINK); + * Scheduler.get().scheduleDeferred(new ScheduledCommand() { + * + * @Override public void execute() { Element buttonElement = + * DOM.getElementById(buttId); Event.sinkEvents(buttonElement, Event.ONCLICK); + * Event.setEventListener(buttonElement, new EventListener() { + * + * @Override public void onBrowserEvent(Event event) { if (Event.ONCLICK == + * event.getTypeInt()) { applicationBus.fireEvent(new + * ShowDetailsEvent("concessione", lo.getSourceConcessione().getItemId(), + * nomeConcessione, null)); + * + * } } }); } }); } listOpenProject.add(buttOpenProject); + * + * HTML subText = new HTML( + * "

Layers and Properties

" + * ); flowPanel.add(subText); } + * + * prevConcessioneName = nomeConcessione; + * + * Label layerLabel = new Label(); layerLabel.setType(LabelType.INFO); + * + * String layerName = StringUtil.fullNameToLayerName(layerSourceName, ":"); + * layerLabel.setText(layerName); layerLabel.setTitle(layerSourceName); + * layerLabel.getElement().getStyle().setMarginTop(10, Unit.PX); + * layerLabel.getElement().getStyle().setMarginBottom(5, Unit.PX); + * flowPanel.add(layerLabel); + * + * GWT.log("Displaying " + features.size() + " features"); FlexTable intFlex = + * new FlexTable(); intFlex.setCellPadding(1); intFlex.setCellSpacing(1); + * intFlex.getElement().addClassName("table-feature"); intFlex.setHTML(0, 0, new + * HTML("Feature Id").toString()); + * + * int i = 0; for (FeatureRow feature : features) { + * + * intFlex.setHTML(i + 1, 0, new HTML(feature.getId()).toString()); + * + * // Showing properties belonging to concessioni layer Map> entries = feature.getMapProperties(); + * + * if (entries.size() == 0) { // Adding this row to show "no property" for + * feature // intFlex.setHTML(i + 1, 1, new + * HTML("No property").toString()); } int j = 0; for (String key : + * entries.keySet()) { List theValues = entries.get(key); String + * valueToDisplay = ""; for (String value : theValues) { valueToDisplay += value + * + ", "; + * + * } valueToDisplay = valueToDisplay.substring(0, valueToDisplay.length() - 2); + * + * // adding the keys only of first feature row. They are equal for all features + * // (beloning to same layer). if (i == 0) intFlex.setHTML(0, j + 1, new + * HTML(key).toString()); + * + * intFlex.setHTML(i + 1, j + 1, new HTML(valueToDisplay).toString()); j++; + * + * } i++; } flowPanel.add(intFlex); + * + */ - Button buttOpenProject = new Button("Open Project"); - final String buttId = "open-details-" + Random.nextInt(); - Element bEl = buttOpenProject.getElement(); - bEl.setId(buttId); - bEl.getStyle().setPaddingLeft(0, Unit.PX); - buttOpenProject.setType(ButtonType.LINK); - - if (buttOpenProject != null) { - flowPanel.add(buttOpenProject); - buttOpenProject.setType(ButtonType.LINK); - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - - @Override - public void execute() { - Element buttonElement = DOM.getElementById(buttId); - Event.sinkEvents(buttonElement, Event.ONCLICK); - Event.setEventListener(buttonElement, new EventListener() { - - @Override - public void onBrowserEvent(Event event) { - if (Event.ONCLICK == event.getTypeInt()) { - applicationBus.fireEvent(new ShowDetailsEvent("concessione", - lo.getSourceConcessione().getItemId(), nomeConcessione, null)); - - } - } - }); - } - }); - } - listOpenProject.add(buttOpenProject); - - HTML subText = new HTML( - "

Layers and Properties

"); - flowPanel.add(subText); - } - - prevConcessioneName = nomeConcessione; - - Label layerLabel = new Label(); - layerLabel.setType(LabelType.INFO); - - String layerName = StringUtil.fullNameToLayerName(layerSourceName, ":"); - layerLabel.setText(layerName); - layerLabel.setTitle(layerSourceName); - layerLabel.getElement().getStyle().setMarginTop(10, Unit.PX); - layerLabel.getElement().getStyle().setMarginBottom(5, Unit.PX); - flowPanel.add(layerLabel); - - GWT.log("Displaying " + features.size() + " features"); - FlexTable intFlex = new FlexTable(); - intFlex.setCellPadding(1); - intFlex.setCellSpacing(1); - intFlex.getElement().addClassName("table-feature"); - intFlex.setHTML(0, 0, new HTML("Feature Id").toString()); - - int i = 0; - for (FeatureRow feature : features) { - - intFlex.setHTML(i + 1, 0, new HTML(feature.getId()).toString()); - - // Showing properties belonging to concessioni layer - Map> entries = feature.getMapProperties(); - - if (entries.size() == 0) { - // Adding this row to show "no property" for feature - // intFlex.setHTML(i + 1, 1, new HTML("No property").toString()); - } - int j = 0; - for (String key : entries.keySet()) { - List theValues = entries.get(key); - String valueToDisplay = ""; - for (String value : theValues) { - valueToDisplay += value + ", "; - - } - valueToDisplay = valueToDisplay.substring(0, valueToDisplay.length() - 2); - - // adding the keys only of first feature row. They are equal for all features - // (beloning to same layer). - if (i == 0) - intFlex.setHTML(0, j + 1, new HTML(key).toString()); - - intFlex.setHTML(i + 1, j + 1, new HTML(valueToDisplay).toString()); - j++; - - } - i++; - } - flowPanel.add(intFlex); } catch (Exception e) { GeoportalDataViewerConstants.printJs("Error: " + e.getMessage()); } @@ -859,8 +884,7 @@ public class LayerManager { @Override public void onClick(ClickEvent event) { - ShowDetailsEvent toEvent = parseGeonaReferences( - geoNaDataObject.getSourceLayerObject().getItemType(), theFeature); + ShowDetailsEvent toEvent = parseGeonaReferences(geoNaDataObject.getSourceLayerObject(), theFeature); applicationBus.fireEvent(toEvent); } @@ -934,8 +958,8 @@ public class LayerManager { @Override public void onBrowserEvent(Event event) { if (Event.ONCLICK == event.getTypeInt()) { - ShowDetailsEvent toEvent = parseGeonaReferences( - geoNaDataObject.getSourceLayerObject().getItemType(), theFeature); + ShowDetailsEvent toEvent = parseGeonaReferences(geoNaDataObject.getSourceLayerObject(), + theFeature); applicationBus.fireEvent(toEvent); } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ViewerStatus.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ViewerStatus.java new file mode 100644 index 0000000..31e90a1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ViewerStatus.java @@ -0,0 +1,18 @@ +package org.gcube.portlets.user.geoportaldataviewer.client; + +import org.gcube.portlets.user.geoportaldataviewer.shared.ViewerConfiguration; + +public class ViewerStatus { + + private ViewerConfiguration viewerConfig; + + public void setConfig(ViewerConfiguration result) { + this.viewerConfig = result; + + } + + public ViewerConfiguration getViewerConfig() { + return viewerConfig; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ShowDetailsEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ShowDetailsEvent.java index 2e61b8e..b13a59d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ShowDetailsEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ShowDetailsEvent.java @@ -5,53 +5,70 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow; import com.google.gwt.event.shared.GwtEvent; - /** * The Class ShowDetailsEvent. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Jul 30, 2021 + * Jul 30, 2021 */ public class ShowDetailsEvent extends GwtEvent { public static Type TYPE = new Type(); - private String geonaItemType; + private String layerObjectType; private FeatureRow featureRow; - private String geonaMongoID; private String itemName; - + private String profileID; + private String projectID; /** * Instantiates a new show details event. * - * @param geonaItemType the geona item type - * @param geonaMongoID the geona mongo ID - * @param itemName the item name - * @param featureRow the feature row + * @param layerObjectType the geona item type + * @param geonaMongoID the geona mongo ID + * @param itemName the item name + * @param featureRow the feature row */ - public ShowDetailsEvent(String geonaItemType, String geonaMongoID, String itemName, FeatureRow featureRow) { - this.geonaItemType = geonaItemType; - this.geonaMongoID = geonaMongoID; + public ShowDetailsEvent(String layerObjectType, String profileID, String projectID, String itemName, + FeatureRow featureRow) { + this.layerObjectType = layerObjectType; + this.profileID = profileID; + this.projectID = projectID; this.itemName = itemName; this.featureRow = featureRow; } - /** * Instantiates a new show details event. * - * @param gir the gir - * @param itemName the item name + * @param gir the gir + * @param itemName the item name * @param featureRow the feature row */ public ShowDetailsEvent(GeoNaItemRef gir, String itemName, FeatureRow featureRow) { - this.geonaItemType = gir.getItemType(); - this.geonaMongoID = gir.getItemId(); + this.layerObjectType = gir.getLayerObjectType(); + this.profileID = gir.getProfileID(); + this.projectID = gir.getProjectID(); this.itemName = itemName; this.featureRow = featureRow; } + public static Type getTYPE() { + return TYPE; + } + + public String getLayerObjectType() { + return layerObjectType; + } + + public String getProfileID() { + return profileID; + } + + public String getProjectID() { + return projectID; + } + /** * Gets the associated type. * @@ -73,15 +90,6 @@ public class ShowDetailsEvent extends GwtEvent { } - /** - * Gets the geona item type. - * - * @return the geona item type - */ - public String getGeonaItemType() { - return geonaItemType; - } - /** * Gets the feature row. * @@ -91,15 +99,6 @@ public class ShowDetailsEvent extends GwtEvent { return featureRow; } - /** - * Gets the geona mongo ID. - * - * @return the geona mongo ID - */ - public String getGeonaMongoID() { - return geonaMongoID; - } - /** * Gets the item name. * @@ -117,18 +116,14 @@ public class ShowDetailsEvent extends GwtEvent { public void setItemName(String itemName) { this.itemName = itemName; } - - + /** * Gets the geona item ref. * * @return the geona item ref */ public GeoNaItemRef getGeonaItemRef() { - return new GeoNaItemRef(geonaMongoID, geonaItemType); + return new GeoNaItemRef(projectID, profileID, layerObjectType); } - - - } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/CloseCollectionEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/CloseCollectionEvent.java new file mode 100644 index 0000000..9a88e50 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/CloseCollectionEvent.java @@ -0,0 +1,30 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events.collections; + + +import com.google.gwt.event.shared.GwtEvent; + +public class CloseCollectionEvent extends GwtEvent { + + + private String collectionId = null; + + public static Type TYPE = new Type(); + + @Override + public Type getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(CloseCollectionEventHandler h) { + + } + + public CloseCollectionEvent(String collectionId) { + this.collectionId=collectionId; + } + public String getCollectionId() { + return collectionId; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/CloseCollectionEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/CloseCollectionEventHandler.java new file mode 100644 index 0000000..44c196d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/CloseCollectionEventHandler.java @@ -0,0 +1,7 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events.collections; + +import com.google.gwt.event.shared.EventHandler; + +public interface CloseCollectionEventHandler extends EventHandler{ + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/OpenCollectionEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/OpenCollectionEvent.java new file mode 100644 index 0000000..72bb428 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/OpenCollectionEvent.java @@ -0,0 +1,40 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events.collections; + +import com.google.gwt.event.shared.GwtEvent; + +public class OpenCollectionEvent extends GwtEvent { + + private String collectionId = null; + + public static Type TYPE = new Type(); + + /** + * Gets the associated type. + * + * @return the associated type + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + @Override + protected void dispatch(OpenCollectionEventHandler handler) { + handler.onOpenCollection(this); + + } + + public OpenCollectionEvent(String collectionId) { + this.collectionId = collectionId; + } + + public String getCollectionId() { + return collectionId; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/OpenCollectionEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/OpenCollectionEventHandler.java new file mode 100644 index 0000000..4a8bebd --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/collections/OpenCollectionEventHandler.java @@ -0,0 +1,10 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.events.collections; + +import com.google.gwt.event.shared.EventHandler; + +public interface OpenCollectionEventHandler extends EventHandler { + + + void onOpenCollection(OpenCollectionEvent event); + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index 4b728f7..49ba81b 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -1,6 +1,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client.ui; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -12,15 +13,19 @@ import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; import org.gcube.portlets.user.geoportaldataviewer.client.events.ChangeMapLayerEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.MapExtentToEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.CloseCollectionEvent; +import org.gcube.portlets.user.geoportaldataviewer.client.events.collections.OpenCollectionEvent; import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerMap; import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAIcons; import org.gcube.portlets.user.geoportaldataviewer.client.resources.GNAImages; import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.search.SearchFacilityUI; import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil; import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil.Location; +import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.CheckBox; import com.github.gwtbootstrap.client.ui.DropdownButton; import com.github.gwtbootstrap.client.ui.NavLink; import com.github.gwtbootstrap.client.ui.NavList; @@ -95,7 +100,13 @@ public class GeonaDataViewMainPanel extends Composite { @UiField Button linkLayers; + + @UiField + DropdownButton openCollectionDropDown; + @UiField + HTMLPanel openCollectionPanel; + @UiField DropdownButton searchFacilityButton; @@ -126,77 +137,6 @@ public class GeonaDataViewMainPanel extends Composite { private HandlerManager applicationBus; -// /** -// * Instantiates a new geona data view main panel. -// * -// * @param applicationBus the application bus -// * @param mapHeight the map height -// * @param sortByFields the sort by fields -// * @param searchForFields the search for fields -// * @param initialSortFilter the initial sort filter -// */ -// public GeonaDataViewMainPanel(HandlerManager applicationBus, int mapHeight, List sortByFields, -// List searchForFields, SearchingFilter initialSortFilter) { -// initWidget(uiBinder.createAndBindUi(this)); -// this.applicationBus = applicationBus; -// mapPanel = new MapPanel(mapHeight + "px"); -// detailsPanel.setHeight(mapHeight + "px"); -// detailsPanel.setApplicationBus(applicationBus); -// mainContainerPanel.add(mapPanel); -// bindHandlers(); -// dataPointSelection.setIcon(IconType.SCREENSHOT); -// dataBoxSelection.setIcon(IconType.BOOKMARK); -// removeQuery.setIcon(IconType.REMOVE); -// -// Image italyImg = new Image(GNAImages.ICONS.italyIcon()); -// italyImg.getElement().getStyle().setPaddingLeft(20, Unit.PX); -// extentToItaly.getElement().appendChild(italyImg.getElement()); -// extentToItaly.setWidth("140px"); -// -// Image worldImg = new Image(GNAImages.ICONS.worldIcon()); -// worldImg.getElement().getStyle().setPaddingLeft(20, Unit.PX); -// extentToEarth.getElement().appendChild(worldImg.getElement()); -// extentToEarth.setWidth("140px"); -// -// linkMap.setCustomIconStyle(GNAIcons.CustomIconType.MAP.get()); -// linkPresetLocation.setCustomIconStyle(GNAIcons.CustomIconType.PRESET_LOCATION.get()); -// linkLayers.setCustomIconStyle(GNAIcons.CustomIconType.LAYERS.get()); -// -// SearchingFilter initialSortFilter = new SearchingFilter(); -// initialSortFilter.setOrder(ORDER.ASC); -// -// for (ItemFieldDV itemField : result) { -// if (itemField.isDisplayAsResult()) { -// displayFields.add(itemField); -// } -// -// if (itemField.isSearchable()) { -// searchByFields.add(itemField); -// } -// -// if (itemField.isSortable()) { -// sortByFields.add(itemField); -// } -// } -// -// searchFacility = new SearchFacilityUI(applicationBus, sortByFields, searchForFields, initialSortFilter); -// searchFacility.setSearchButton(searchFacilityButton); -// searchFacilityButton.setIcon(IconType.SEARCH); -// searchFacilityPanel.add(searchFacility); -// Scheduler.get().scheduleDeferred(new ScheduledCommand() { -// -// @Override -// public void execute() { -// searchFacilityPanel.getElement().getParentElement().getStyle().setOpacity(0.9); -// -// } -// -// }); -// -// // layersDDB.setToggle(true); -// bindEvents(); -// -// } public GeonaDataViewMainPanel(HandlerManager applicationBus, int mapHeight, Map> mapOfSearchingFilterForUCD) { @@ -225,6 +165,8 @@ public class GeonaDataViewMainPanel extends Composite { linkPresetLocation.setCustomIconStyle(GNAIcons.CustomIconType.PRESET_LOCATION.get()); linkLayers.setCustomIconStyle(GNAIcons.CustomIconType.LAYERS.get()); + openCollectionDropDown.setCustomIconStyle(GNAIcons.CustomIconType.MAP.get()); + SearchingFilter initialSortFilter = new SearchingFilter(); initialSortFilter.setOrder(ORDER.ASC); @@ -528,6 +470,48 @@ public class GeonaDataViewMainPanel extends Composite { * * @param listBaseLayers the new base layers */ + + public void setAvailableCollections(Collection collection) { + GWT.log("Init Available collections menu"); + if(collection == null || collection.isEmpty()) + GWT.log("!!! No Available collections"); + + + for(GCubeCollection coll : collection) { + GWT.log("Found available collection "+coll); + String label = coll.getUcd().getName(); + String id=coll.getUcd().getId(); + + CheckBox checkbox = new CheckBox(label); + checkbox.setId("gcubeCollectionSelector_"+id); + + checkbox.addValueChangeHandler(new ValueChangeHandler() { + + @Override + public void onValueChange(ValueChangeEvent event) { + GWT.log("Collection selector flag changed to value : "+event.toDebugString()); + + String collectionID = ((CheckBox)event.getSource()).getId().replace("gcubeCollectionSelector_", ""); + + GWT.log("Collection ID is : "+collectionID + ", event value: "+event.getValue()); + if(event.getValue()) { + // OPEN COLLECTION + applicationBus.fireEvent(new OpenCollectionEvent(collectionID)); + }else { + // CLOSE COLLECTION + applicationBus.fireEvent(new CloseCollectionEvent(collectionID)); + } + } + }); + + openCollectionPanel.add(checkbox); + } + + + } + + + public void setBaseLayers(List listBaseLayers) { if (listBaseLayers == null) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml index 029b77b..d0fea78 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.ui.xml @@ -35,17 +35,22 @@ - - - + + + + + + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/dandd/DragDropLayer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/dandd/DragDropLayer.java index 6c53001..fce172a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/dandd/DragDropLayer.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/dandd/DragDropLayer.java @@ -1,6 +1,5 @@ package org.gcube.portlets.user.geoportaldataviewer.client.ui.dandd; -import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV; import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.DO_LAYER_ACTION; import org.gcube.portlets.user.geoportaldataviewer.client.events.DoActionOnDetailLayersEvent.SwapLayer; @@ -60,10 +59,10 @@ public class DragDropLayer extends FlowPanel { this.labelLayerName.setTitle(layerItem.getName()); this.labelLayerName.setType(LabelType.INFO); - BaseConcessioneDV refConcessione = layerObject.getSourceConcessione(); - String nameConcessione = StringUtil.ellipsize(refConcessione.getNome(), 40); + LayerItem refConcessione = layerObject.getLayerItem(); + String nameConcessione = StringUtil.ellipsize(refConcessione.getName(), 40); com.google.gwt.user.client.ui.Label labelConcessione = new com.google.gwt.user.client.ui.Label(nameConcessione); - labelConcessione.setTitle(refConcessione.getNome()); + labelConcessione.setTitle(refConcessione.getName()); getElement().getStyle().setMarginTop(5, Unit.PX); getElement().getStyle().setMarginBottom(10, Unit.PX); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/ControlledCallBack.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/ControlledCallBack.java new file mode 100644 index 0000000..e3e9a63 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/ControlledCallBack.java @@ -0,0 +1,33 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.util; + +import org.gcube.portlets.user.geoportaldataviewer.shared.faults.ControlledError; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; + +public abstract class ControlledCallBack implements AsyncCallback { + + @Override + public void onFailure(Throwable caught) { + before(); + if(caught instanceof ControlledError) { + GWT.log("Controlled error "+caught); + Window.alert(caught.getMessage()); + }else { + GWT.log("Uncontrolled failure, check server log.", caught); + Window.alert("Sorry, an unexpected error occurred. Please, contact the support"); + } + after(); + } + + public void before() {} + + public void after() {} + + @Override + public void onSuccess(T result) { + before(); + after(); + } +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/OGCUtils.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/OGCUtils.java new file mode 100644 index 0000000..3a499d6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/util/OGCUtils.java @@ -0,0 +1,40 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.util; + +import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; + +import com.google.gwt.core.client.GWT; + +public class OGCUtils { + + public static void performWFSQueryOnCentroid(RecordDV record) { + GWT.log("WFS Query for : "+record); + + if (record != null) { +// GWT.log("record instanceof ConcessioneDV: " + (record instanceof ConcessioneDV) + " with mongo item id: " +// + record.getItemId()); + // GeoportalDataViewerConstants.print("record instanceof ConcessioneDV: " + // +(record instanceof ConcessioneDV)); +// if (record instanceof ConcessioneDV) { +// ConcessioneDV concessioneDV = (ConcessioneDV) record; +// Double x = concessioneDV.getCentroidLong(); +// Double y = concessioneDV.getCentroidLat(); +// GWT.log("X: " + x + ", Y:" + y); +// if (x != null && y != null) { +// Coordinate transfCoord = MapUtils.transformCoordiante(new Coordinate(x, y), +// GeoportalDataViewerConstants.MAP_PROJECTION.EPSG_4326.getName(), GeoportalDataViewerConstants.MAP_PROJECTION.EPSG_3857.getName()); +// GeoQuery select = olMapMng.toDataPointQuery(transfCoord, false); +// GWT.log("GeoQuery: " + select); +// // GeoportalDataViewerConstants.print("fireEvent QueryDataEvent"); +// ExtentWrapped toExt = new ExtentWrapped(transfCoord.getX(), transfCoord.getY(), transfCoord.getX(), +// transfCoord.getY()); +// layerManager.getLayerManagerBus().fireEvent(new QueryDataEvent(select, toExt, record.getItemId(), +// true, GeoportalDataViewerConstants.MapEventType.ADDED_CENTROID_LAYER_TO_MAP)); +// } else { +// GeoportalDataViewerConstants.printJs( +// "I cannot select the point one or both coordiantes are null. X: " + x + ", Y:" + y); +// } +// } + } + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerHttpSessionListener.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerHttpSessionListener.java deleted file mode 100644 index b06f745..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerHttpSessionListener.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.gcube.portlets.user.geoportaldataviewer.server; - -import javax.servlet.annotation.WebListener; -import javax.servlet.http.HttpSessionEvent; -import javax.servlet.http.HttpSessionListener; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@WebListener -public class GeoportalDataViewerHttpSessionListener implements HttpSessionListener { - - private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerHttpSessionListener.class); - - @Override - public void sessionDestroyed(HttpSessionEvent event) { - LOG.info("sessionDestroyed called"); - } - - @Override - public void sessionCreated(HttpSessionEvent arg0) { - LOG.info("sessionCreated called. Session id is: "+arg0.getSession().getId()); - } -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java index d7d1190..7ed742e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java @@ -1,5 +1,8 @@ package org.gcube.portlets.user.geoportaldataviewer.server; +import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects; +import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -15,8 +18,12 @@ import javax.servlet.http.HttpSession; import org.bson.Document; import org.gcube.application.geoportal.client.utils.Serialization; +import org.gcube.application.geoportal.common.model.configuration.Configuration; +import org.gcube.application.geoportal.common.model.configuration.Index; import org.gcube.application.geoportal.common.model.document.Project; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; +import org.gcube.application.geoportal.common.rest.Projects; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller; @@ -51,12 +58,19 @@ import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessi import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; import org.gcube.application.geoportalcommon.util.URLParserUtil; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerService; +import org.gcube.portlets.user.geoportaldataviewer.server.faults.InvalidObjectException; import org.gcube.portlets.user.geoportaldataviewer.server.gis.FeatureParser; import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator; import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy; +import org.gcube.portlets.user.geoportaldataviewer.server.util.ContextRequest; +import org.gcube.portlets.user.geoportaldataviewer.server.util.DVConversion; import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil; +import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult; +import org.gcube.portlets.user.geoportaldataviewer.shared.ViewerConfiguration; +import org.gcube.portlets.user.geoportaldataviewer.shared.faults.ControlledError; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.IndexLayer; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; @@ -493,11 +507,11 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme if (item == null) throw new Exception("Bad request, the item is null"); - if (item.getItemId() == null) - throw new Exception("Bad request, the item id is null"); + if (item.getProjectID() == null) + throw new Exception("Bad request, the projectID is null"); - if (item.getItemType() == null) - throw new Exception("Bad request, the item type is null"); + if (item.getProfileID() == null) + throw new Exception("Bad request, the profileID is null"); SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); GeoportalCommon gc = new GeoportalCommon(); @@ -701,6 +715,97 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme * */ + @Override + public ViewerConfiguration getInitialConfiguration() throws Exception { + LOG.debug("getInitialConfiguration called"); + + return new ContextRequest(this.getThreadLocalRequest()) { + @Override + protected ViewerConfiguration run() throws Exception, ControlledError { + try { + + // ************* LOAD BASE LAYERS + + final ViewerConfiguration config = new ViewerConfiguration(); + LOG.info("Getting initial configuration "); + LOG.debug("Loading base layers.."); + List listBL = SessionUtil.getGNABaseMaps(request); + + LOG.debug("getListBaseLayers returning " + listBL.size() + " base maps"); + config.setBaseLayers(listBL); + + // ************** LOAD AVAILABLE COLLECTIONS + + LOG.debug("Loading available collections.. "); + config.setAvailableCollections(new HashMap()); + + // TODO filter by + // configured ? + // gis indexed + QueryRequest request = new QueryRequest(); + + // TODO Constant + String Id = "org.gcube.portlets.user.geoportaldataviewer"; + request.setFilter(Document.parse("{\"" + UseCaseDescriptor.HANDLERS + "." + + org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration.ID + + "\" : " + "{\"$eq\" : \"" + Id + "\"}}")); + + useCaseDescriptors().build().query(new QueryRequest()).forEachRemaining(u -> { + try { + LOG.debug("Checking configuration for collection " + u.getId()); + + Projects p = projects(u.getId()).build(); + UseCaseDescriptorDV ucd = ConvertToDataValueObjectModel.toUseCaseDescriptorDV(u, null); + Configuration ucdConfig = p.getConfiguration(); + GCubeCollection coll = new GCubeCollection(); + coll.setUcd(ucd); + + // TODO TO Check index flag should be in configuration or evaluated according to + // user credentials + + String toCheckFlag = "internal"; + + // TODO constant + coll.setIndexes(new ArrayList()); + + LOG.debug("Checking if " + u.getId() + " is GIS Indexed. Index flag needed is " + + toCheckFlag); + + for (Index index : ucdConfig.getIndexes()) { + try { + IndexLayer toAdd = DVConversion.convert(index); + if (toAdd.getFlag().equals(toCheckFlag)) + coll.getIndexes().add(toAdd); + } catch (InvalidObjectException e) { + LOG.debug("Skipping invalid index ", e); + } catch (Throwable t) { + LOG.error("Unable to check index ", t); + } + } + + // Return only if gis indexed + if (coll.getIndexes().isEmpty()) + LOG.info("No available GIS Index for collection " + coll.getUcd().getName()); + else + config.getAvailableCollections().put(coll.getUcd().getId(), coll); + + } catch (Throwable t) { + LOG.warn("Invalid UCD, can't translate to DV. UCID : " + u.getId(), t); + } + }); + // TODO load initial layers from query parameters + LOG.debug("Found " + config.getAvailableCollections().size() + " collections"); + + return config; + } catch (Throwable t) { + LOG.error("Unexpected exception while loading initial config", t); + throw new ControlledError("Unable to configure viewer. Please retry in a few minutes."); + } + } + + }.execute().getResult(); + } + @Override public Map> listOfFieldsForSearching() throws Exception { LOG.info("listOfFieldsForSearching called"); @@ -1021,222 +1126,12 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme GeoportalServiceIdentityProxy cms = new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); ProjectDV theProjectDV = cms.getProjectByID(profileID, projectID); - String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON(); + ProjectView projectView = loadProjectView(theProjectDV, scope, userName); - LOG.debug("theProjectDV as JSON: " + theWholeProjectAsJSON); - LOG.debug("theProjectDV as MAP: " + theProjectDV.getTheDocument().getDocumentAsMap()); - - ProjectView projectView = new ProjectView(); - projectView.setTheProjectDV(theProjectDV); - - LinkedHashMap> linkedMap_UCDId_gCubeProfiles = GcubeProfilesPerUCDIdCache - .get(scope); - - // NO UCD defined, applyong default - if (linkedMap_UCDId_gCubeProfiles.size() == 0) { - LOG.warn("No " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " found in the UCD"); - LOG.info("Applying default business logic to display the project"); - SectionView sectionView = new SectionView(); - sectionView.setSectionTitle("Document"); - SubDocumentView subDocumentView = new SubDocumentView(); - - Document sectionDoc = Document.parse(theProjectDV.getTheDocument().getDocumentAsJSON()); - boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, JSON_$_POINTER, - userName); - - // If is accessible - if (isAccessibleSection) { - - // Creating one Project with one SectionView and SubDocumentView - String wholeSectionDoc = sectionDoc.toJson(); - subDocumentView.setMetadataAsJSON(wholeSectionDoc); - - List listFiles = new ArrayList(); - List listImages = new ArrayList(); - String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, "fileset"); - List listPayloads = readPayloadsForFileset(filesetJSONPath, wholeSectionDoc); - FilesetDV filesetDV = new FilesetDV(); - filesetDV.setName("fileset"); - for (Payload payload : listPayloads) { - PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); - filesetDV.addPayloadDV(payloadDV); - boolean isImage = ImageDetector.isImage(payload.getMimetype()); - - if (isImage) { - listImages.add(filesetDV); - } else { - listFiles.add(filesetDV); - } - } - - // TODO LAYERS - subDocumentView.setListImages(listImages); - subDocumentView.setListFiles(listFiles); - sectionView.addSubDocument(subDocumentView); - projectView.addSectionView(sectionView); - - } - - } - - List listProfilesBean = linkedMap_UCDId_gCubeProfiles.get(profileID); - - com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() - .jsonProvider(new JsonOrgJsonProvider()).build(); - - // Reading the Project according to list of Profile defined in the UCD - for (GcubeProfilesMetadataForUCD gcubeProfileMetaForUCD : listProfilesBean) { - - GcubeProfileDV gcubeProfileDV = gcubeProfileMetaForUCD.getGcubeProfile(); - SectionView sectionView = new SectionView(); - sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle()); - LOG.debug("\n\nThe profile is: " + gcubeProfileDV); - // Building JSON/section full PATH and section name - String sectionJSONPath = ""; - String parentPathFromProfile = gcubeProfileDV.getParentName() == null ? "" - : gcubeProfileDV.getParentName(); - String theSectionName = gcubeProfileDV.getSectionName(); - - if (theSectionName.compareTo(JSON_$_POINTER) == 0 - || theSectionName.compareTo(JSON_$_POINTER + ".") == 0) { - sectionJSONPath = JSON_$_POINTER; - theSectionName = ""; - } else { - sectionJSONPath = String.format("%s%s", - parentPathFromProfile.endsWith(".") ? parentPathFromProfile : parentPathFromProfile + ".", - theSectionName); - } - - LOG.debug("The sectionJSONPath is: " + sectionJSONPath); - - JsonPath theSectionJsonPath = JsonPath.compile(sectionJSONPath); - Object data = theSectionJsonPath.read(theWholeProjectAsJSON, configuration); - - LOG.debug("Data is instace of: " + data.getClass()); - LOG.debug("data to string: " + data.toString()); - - // Splitting the General Document in bson.Document according to list of - // GcubeProfiles - List listBSONDocument = new ArrayList(); - if (data instanceof org.json.JSONObject) { - String jsonString = data.toString(); - LOG.debug("the JSON to string: " + jsonString); - Document sectionDoc = Document.parse(jsonString); - boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, sectionJSONPath, - userName); - if (isAccessibleSection) { - listBSONDocument.add(sectionDoc); - } - - } else if (data instanceof org.json.JSONArray) { - org.json.JSONArray dataArray = (org.json.JSONArray) data; - for (int i = 0; i < dataArray.length(); i++) { - String jsonString = dataArray.get(i).toString(); - LOG.debug("the array " + i + " JSON to string: " + jsonString); - Document sectionDoc = Document.parse(jsonString); - boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, sectionJSONPath, - userName); - if (isAccessibleSection) { - listBSONDocument.add(sectionDoc); - } - - } - } - - LOG.debug("Result for " + gcubeProfileDV.getSectionName() + " is: " + listBSONDocument); - List theProfileBeans = gcubeProfileMetaForUCD.getListMetadataProfileBean(); - MetaDataProfileBean theProfileBean = theProfileBeans.get(0); - - // For each bson.Document creating the SubDocumentView - for (int i = 0; i < listBSONDocument.size(); i++) { - Document fromSectionDoc = listBSONDocument.get(i); - SubDocumentView subDocumentView = new SubDocumentView(); - Document toSectionDoc = new Document(); - // Filling the SubDocumentView metadata with the metadataField.getFieldName() - // read from the Profile - for (MetadataFieldWrapper metadataField : theProfileBean.getMetadataFields()) { - - String theFieldName = metadataField.getFieldId() != null ? metadataField.getFieldId() - : metadataField.getFieldName(); - LOG.debug("reading theFieldName: " + theFieldName); - Object theOBJFieldValue = fromSectionDoc.get(theFieldName); - - // NB: Using ALWAYS THE metadataField.getFieldName() as LABEL - toSectionDoc = sanitizeDocumentValue(toSectionDoc, metadataField.getFieldName(), - theOBJFieldValue); - - } - String subToJSON = toSectionDoc.toJson(); - LOG.debug("theSubSetionDoc is: " + subToJSON); - subDocumentView.setMetadataAsJSON(toSectionDoc.toJson()); - - // Reading filePaths - List filePaths = gcubeProfileDV.getFilePaths(); - - // READING fileset* field ACCORDING TO filePaths OF THE 'gcubeProfiles' CONFIG - if (filePaths != null) { - String fromSectionDocJSON = fromSectionDoc.toJson(); - List listFiles = new ArrayList(); - List listImages = new ArrayList(); - for (FilePathDV filePath : filePaths) { - - String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName()); - List listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON); - FilesetDV filesetDV = new FilesetDV(); - filesetDV.setName(filePath.getGcubeProfileFieldName()); - for (Payload payload : listPayloads) { - PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); - filesetDV.addPayloadDV(payloadDV); - boolean isImage = ImageDetector.isImage(payload.getMimetype()); - - if (isImage) { - listImages.add(filesetDV); - } else { - listFiles.add(filesetDV); - } - } - - } - subDocumentView.setListFiles(listFiles); - subDocumentView.setListImages(listImages); - } - - sectionView.addSubDocument(subDocumentView); - - } - - projectView.addSectionView(sectionView); - } - -// for (SectionView section : projectView.getListSections()) { -// System.out.println("\n\n###### Section Title: " + section.getSectionTitle() + " ######"); -// int i = 1; -// for (SubDocumentView subDocument : section.getListSubDocuments()) { -// System.out.println("## " + SubDocumentView.class.getSimpleName() + " n." + i); -// System.out.println("***** Metadata"); -// System.out.println(prettyPrintJSON(subDocument.getMetadataAsJSON())); -// System.out.println("***** Files"); -// if (subDocument.getListFiles() != null) { -// for (FilesetDV filesetDV : subDocument.getListFiles()) { -// System.out.println("******* File Fileset name: " + filesetDV.getName()); -// for (PayloadDV payload : filesetDV.getListPayload()) { -// System.out.println("********* Payload: " + payload); -// } -// } -// } -// System.out.println("***** Images"); -// if (subDocument.getListImages() != null) { -// for (FilesetDV filesetDV : subDocument.getListImages()) { -// System.out.println("******* Image Fileset name: " + filesetDV.getName()); -// for (PayloadDV payload : filesetDV.getListPayload()) { -// System.out.println("********* Payload: " + payload); -// } -// } -// } -// i++; -// } -// -// } + if(LOG.isDebugEnabled()) + prettyPrintProjectView(projectView); + + LOG.info("returning project view for id: " + projectView.getTheProjectDV().getId()); return projectView; } catch (Exception e) { @@ -1247,6 +1142,235 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } + public ProjectView loadProjectView(ProjectDV theProjectDV, String scope, String username) throws Exception { + + String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON(); + + LOG.debug("theProjectDV as JSON: " + theWholeProjectAsJSON); + LOG.debug("theProjectDV as MAP: " + theProjectDV.getTheDocument().getDocumentAsMap()); + + ProjectView projectView = new ProjectView(); + projectView.setTheProjectDV(theProjectDV); + + LinkedHashMap> linkedMap_UCDId_gCubeProfiles = GcubeProfilesPerUCDIdCache + .get(scope); + + // NO UCD defined, applying default + if (linkedMap_UCDId_gCubeProfiles.size() == 0) { + LOG.warn("No " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " found in the UCD"); + LOG.info("Applying default business logic to display the project"); + SectionView sectionView = new SectionView(); + sectionView.setSectionTitle("Document"); + SubDocumentView subDocumentView = new SubDocumentView(); + + Document sectionDoc = Document.parse(theProjectDV.getTheDocument().getDocumentAsJSON()); + boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, JSON_$_POINTER, username); + + // If is accessible + if (isAccessibleSection) { + + // Creating one Project with one SectionView and SubDocumentView + String wholeSectionDoc = sectionDoc.toJson(); + subDocumentView.setMetadataAsJSON(wholeSectionDoc); + + List listFiles = new ArrayList(); + List listImages = new ArrayList(); + String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, "fileset"); + List listPayloads = readPayloadsForFileset(filesetJSONPath, wholeSectionDoc); + FilesetDV filesetDV = new FilesetDV(); + filesetDV.setName("fileset"); + for (Payload payload : listPayloads) { + PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); + filesetDV.addPayloadDV(payloadDV); + boolean isImage = ImageDetector.isImage(payload.getMimetype()); + + if (isImage) { + listImages.add(filesetDV); + } else { + listFiles.add(filesetDV); + } + } + + // TODO LAYERS + subDocumentView.setListImages(listImages); + subDocumentView.setListFiles(listFiles); + sectionView.addSubDocument(subDocumentView); + projectView.addSectionView(sectionView); + + } + + } + + List listProfilesBean = linkedMap_UCDId_gCubeProfiles + .get(theProjectDV.getProfileID()); + + com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() + .jsonProvider(new JsonOrgJsonProvider()).build(); + + // Reading the Project according to list of Profile defined in the UCD + for (GcubeProfilesMetadataForUCD gcubeProfileMetaForUCD : listProfilesBean) { + + GcubeProfileDV gcubeProfileDV = gcubeProfileMetaForUCD.getGcubeProfile(); + SectionView sectionView = new SectionView(); + sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle()); + LOG.debug("\n\nThe profile is: " + gcubeProfileDV); + // Building JSON/section full PATH and section name + String sectionJSONPath = ""; + String parentPathFromProfile = gcubeProfileDV.getParentName() == null ? "" : gcubeProfileDV.getParentName(); + String theSectionName = gcubeProfileDV.getSectionName(); + + if (theSectionName.compareTo(JSON_$_POINTER) == 0 || theSectionName.compareTo(JSON_$_POINTER + ".") == 0) { + sectionJSONPath = JSON_$_POINTER; + theSectionName = ""; + } else { + sectionJSONPath = String.format("%s%s", + parentPathFromProfile.endsWith(".") ? parentPathFromProfile : parentPathFromProfile + ".", + theSectionName); + } + + LOG.debug("The sectionJSONPath is: " + sectionJSONPath); + + JsonPath theSectionJsonPath = null; + Object data = null; + try { + theSectionJsonPath = JsonPath.compile(sectionJSONPath); + data = theSectionJsonPath.read(theWholeProjectAsJSON, configuration); + }catch (Exception e) { + LOG.warn("Error on searching the section " + sectionJSONPath +" in the JSON Project: "+theWholeProjectAsJSON); + continue; + } + + LOG.debug("Data is instace of: " + data.getClass()); + LOG.debug("data to string: " + data.toString()); + + // Splitting the General Document in bson.Document according to list of + // GcubeProfiles + List listBSONDocument = new ArrayList(); + if (data instanceof org.json.JSONObject) { + String jsonString = data.toString(); + LOG.debug("the JSON to string: " + jsonString); + Document sectionDoc = Document.parse(jsonString); + boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, sectionJSONPath, + username); + if (isAccessibleSection) { + listBSONDocument.add(sectionDoc); + } + + } else if (data instanceof org.json.JSONArray) { + org.json.JSONArray dataArray = (org.json.JSONArray) data; + for (int i = 0; i < dataArray.length(); i++) { + String jsonString = dataArray.get(i).toString(); + LOG.debug("the array " + i + " JSON to string: " + jsonString); + Document sectionDoc = Document.parse(jsonString); + boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, sectionJSONPath, + username); + if (isAccessibleSection) { + listBSONDocument.add(sectionDoc); + } + + } + } + + LOG.debug("Result for " + gcubeProfileDV.getSectionName() + " is: " + listBSONDocument); + List theProfileBeans = gcubeProfileMetaForUCD.getListMetadataProfileBean(); + MetaDataProfileBean theProfileBean = theProfileBeans.get(0); + + // For each bson.Document creating the SubDocumentView + for (int i = 0; i < listBSONDocument.size(); i++) { + Document fromSectionDoc = listBSONDocument.get(i); + SubDocumentView subDocumentView = new SubDocumentView(); + Document toSectionDoc = new Document(); + // Filling the SubDocumentView metadata with the metadataField.getFieldName() + // read from the Profile + for (MetadataFieldWrapper metadataField : theProfileBean.getMetadataFields()) { + + String theFieldName = metadataField.getFieldId() != null ? metadataField.getFieldId() + : metadataField.getFieldName(); + LOG.debug("reading theFieldName: " + theFieldName); + Object theOBJFieldValue = fromSectionDoc.get(theFieldName); + + // NB: Using ALWAYS THE metadataField.getFieldName() as LABEL + toSectionDoc = sanitizeDocumentValue(toSectionDoc, metadataField.getFieldName(), theOBJFieldValue); + + } + String subToJSON = toSectionDoc.toJson(); + LOG.debug("theSubSetionDoc is: " + subToJSON); + subDocumentView.setMetadataAsJSON(toSectionDoc.toJson()); + + // Reading filePaths + List filePaths = gcubeProfileDV.getFilePaths(); + + // READING fileset* field ACCORDING TO filePaths OF THE 'gcubeProfiles' CONFIG + if (filePaths != null) { + String fromSectionDocJSON = fromSectionDoc.toJson(); + List listFiles = new ArrayList(); + List listImages = new ArrayList(); + for (FilePathDV filePath : filePaths) { + + String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName()); + List listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON); + FilesetDV filesetDV = new FilesetDV(); + filesetDV.setName(filePath.getGcubeProfileFieldName()); + for (Payload payload : listPayloads) { + PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); + filesetDV.addPayloadDV(payloadDV); + boolean isImage = ImageDetector.isImage(payload.getMimetype()); + + if (isImage) { + listImages.add(filesetDV); + } else { + listFiles.add(filesetDV); + } + } + + } + subDocumentView.setListFiles(listFiles); + subDocumentView.setListImages(listImages); + } + + sectionView.addSubDocument(subDocumentView); + + } + + projectView.addSectionView(sectionView); + } + + return projectView; + } + + public void prettyPrintProjectView(ProjectView projectView) { + + for (SectionView section : projectView.getListSections()) { + System.out.println("\n\n###### Section Title: " + section.getSectionTitle() + " ######"); + int i = 1; + for (SubDocumentView subDocument : section.getListSubDocuments()) { + System.out.println("## " + SubDocumentView.class.getSimpleName() + " n." + i); + System.out.println("***** Metadata"); + System.out.println(prettyPrintJSON(subDocument.getMetadataAsJSON())); + System.out.println("***** Files"); + if (subDocument.getListFiles() != null) { + for (FilesetDV filesetDV : subDocument.getListFiles()) { + System.out.println("******* File Fileset name: " + filesetDV.getName()); + for (PayloadDV payload : filesetDV.getListPayload()) { + System.out.println("********* Payload: " + payload); + } + } + } + System.out.println("***** Images"); + if (subDocument.getListImages() != null) { + for (FilesetDV filesetDV : subDocument.getListImages()) { + System.out.println("******* Image Fileset name: " + filesetDV.getName()); + for (PayloadDV payload : filesetDV.getListPayload()) { + System.out.println("********* Payload: " + payload); + } + } + } + i++; + } + + } + } + /** * Read payloads for fileset. * @@ -1279,8 +1403,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme LOG.info("returning list of payloads {}", listPayloads); } catch (Exception e) { - LOG.error("Error on reading the JSON Path {} in the doc {} ", _payloadsJSONPath, sectionJSONDocument); - e.printStackTrace(); + LOG.warn("Error on reading the JSON Path "+_payloadsJSONPath+" in the doc "+sectionJSONDocument, e); } return listPayloads; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/faults/InvalidObjectException.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/faults/InvalidObjectException.java new file mode 100644 index 0000000..db253e9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/faults/InvalidObjectException.java @@ -0,0 +1,35 @@ +package org.gcube.portlets.user.geoportaldataviewer.server.faults; + +public class InvalidObjectException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 7577708930172470038L; + + public InvalidObjectException() { + // TODO Auto-generated constructor stub + } + + public InvalidObjectException(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + public InvalidObjectException(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + public InvalidObjectException(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + + public InvalidObjectException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/ContextRequest.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/ContextRequest.java new file mode 100644 index 0000000..55f9dbb --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/ContextRequest.java @@ -0,0 +1,56 @@ +package org.gcube.portlets.user.geoportaldataviewer.server.util; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.gcube.portlets.user.geoportaldataviewer.shared.faults.ControlledError; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class ContextRequest { + + private static final Logger LOG = LoggerFactory.getLogger(ContextRequest.class); + + private static List preoperations = new ArrayList<>(); + + public static void addPreoperation(Runnable preoperation) { + preoperations.add(preoperation); + } + + protected HttpServletRequest request; + private T result = null; + + public ContextRequest(HttpServletRequest httpRequest) { + this.request = httpRequest; + } + + public ContextRequest execute() throws Exception, ControlledError { + try { + if (!preoperations.isEmpty()) { + LOG.trace("Running preops (size : {} )", preoperations.size()); + for (Runnable r : preoperations) + r.run(); + } + + LOG.debug("Context is " + SessionUtil.getCurrentContext(request, true)); + LOG.debug("Context is " + SessionUtil.getCurrentToken(request, true) == null ? null : "***"); + LOG.trace("Executing actual method.."); + result = run(); + return this; + } catch (ControlledError e) { + throw e; + } catch (Throwable t) { + LOG.error("Unexpected error ", t); + throw new Exception("Unexpected error contacting the infrastructure", t); + } + + } + + public T getResult() { + return result; + } + + protected abstract T run() throws Exception, ControlledError; +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/DVConversion.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/DVConversion.java new file mode 100644 index 0000000..b64e36b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/DVConversion.java @@ -0,0 +1,68 @@ +package org.gcube.portlets.user.geoportaldataviewer.server.util; + +import org.gcube.application.geoportal.client.utils.Serialization; +import org.gcube.application.geoportal.common.model.configuration.Index; +import org.gcube.portlets.user.geoportaldataviewer.server.faults.InvalidObjectException; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.IndexLayer; + +public class DVConversion { + + + + /** + * + * { + "_type": "GIS-CENTROIDS", + "layer": { + "_type": "gcube-sdi-layer", + "_platformInfo": [ + { + "_type": "Geoserver", + "workspace": "profiledconcessioni_devvre", + "storeName": "profiledconcessioni_devvre_centroids", + "_host": "geoserver-218.dev.d4science.org" + } + ], + "_bbox": { + "_maxX": 180.0, + "_minX": -180.0, + "_maxY": 90.0, + "_minY": -90.0 + }, + "_ogcLinks": { + "wms": { + "wms": "https://geoserver-218.dev.d4science.org/geoserver/profiledconcessioni_devvre/wms?service=WMS&version=1.1.0&request=GetMap&layers=profiledconcessioni_devvre:null&styles=&bbox=-180.000000,-90.000000,180.000000,90.000000&srs=EPSG:4326&format=application/openlayers&width=400&height=400" + } + } + }, + "indexName": "profiledconcessioni_devvre_centroids", + "records": 4, + "crossReferencedLayers": {}, + "flag": "public" + } + * @throws InvalidObjectException + * + */ + + public static IndexLayer convert(Index toConvert) throws InvalidObjectException { + IndexLayer toReturn = null; + + + switch(toConvert.getType()) { + case "GIS-CENTROIDS" : { + toReturn = Serialization.convert(toConvert,IndexLayer.class); + // toReturn.setLayer(Serialization.read(toConvert.get("layer"), GCubeSDILayer.class)); + // toReturn.setFlag(toConvert.getString("flag")); + // toReturn.setIndexName(toConvert.getString()); + break; + + } + default:{ + throw new InvalidObjectException("Unable to convert Index. Unknown type : "+toConvert.getType()); + } + } + + return toReturn; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GCubeCollection.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GCubeCollection.java new file mode 100644 index 0000000..796caaf --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GCubeCollection.java @@ -0,0 +1,47 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared; + + +import java.io.Serializable; +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.IndexLayer; + + +public class GCubeCollection implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3915546050671671465L; + + private UseCaseDescriptorDV ucd; + private List indexes; + + public GCubeCollection() { + } + + public UseCaseDescriptorDV getUcd() { + return ucd; + } + + public List getIndexes() { + return indexes; + } + + + public void setUcd(UseCaseDescriptorDV ucd) { + this.ucd = ucd; + } + + public void setIndexes(List indexes) { + this.indexes = indexes; + } + + @Override + public String toString() { + return "GCubeCollection [ucd=" + ucd + ", indexes=" + indexes + "]"; + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java new file mode 100644 index 0000000..51bdb2b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ViewerConfiguration.java @@ -0,0 +1,47 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer; + +public class ViewerConfiguration implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 7838513808590351819L; + + public ViewerConfiguration() { + + } + + // TODO BaseLayers + public List baseLayers; + + public Map availableCollections; + + public List getBaseLayers() { + return baseLayers; + } + + public void setBaseLayers(List baseLayers) { + this.baseLayers = baseLayers; + } + + public Map getAvailableCollections() { + return availableCollections; + } + + public void setAvailableCollections(Map availableCollections) { + this.availableCollections = availableCollections; + } + + // TODO +// public List displayedCollections; +// +// +// public Map selectedProjects; + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/cl/document/materialization/BBOXDV.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/cl/document/materialization/BBOXDV.java new file mode 100644 index 0000000..08b62b2 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/cl/document/materialization/BBOXDV.java @@ -0,0 +1,109 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared.cl.document.materialization; + +import java.util.HashMap; + +public class BBOXDV extends HashMap{ + + /** + * + */ + private static final long serialVersionUID = -160255589938251081L; + + public BBOXDV() { + + } + + + public final String asGeoJSONBBox(){ + StringBuilder builder = new StringBuilder("["); + builder.append(getMaxX()+","); // W + builder.append(getMinY()+","); // S + if(is3d()) builder.append(getMinZ()+","); // Z + + builder.append(getMinX()+","); // E + builder.append(getMaxY()+","); // N + if(is3d()) builder.append(getMaxZ()+","); // Z + + + builder.deleteCharAt(builder.length()); + builder.append("]"); + return builder.toString(); + } + public double[] asGeoJSONArray(){ + if(is3d()){ + return new double[]{getMaxX(),getMinY(),getMinZ(),getMinX(),getMaxY(),getMaxZ()}; + }else return new double[]{getMaxX(),getMinY(),getMinX(),getMaxY()}; + } + + public static final BBOXDV fromGeoJSON(double[] coords){ + BBOXDV toReturn = new BBOXDV(); + toReturn.setMaxX(coords[0]); + toReturn.setMinY(coords[1]); + + if(coords.length == 6){ + // 3D + toReturn.setMinZ(coords[2]); + toReturn.setMinX(coords[3]); + toReturn.setMaxY(coords[4]); + toReturn.setMaxZ(coords[5]); + }else { + toReturn.setMinX(coords[2]); + toReturn.setMaxY(coords[3]); + } + return toReturn; + } + + public static final BBOXDV WORLD=new BBOXDV(180d,-180d,90d,-90d); + + public static final BBOXDV WORLD_3D=new BBOXDV(180d,-180d,90d,-90d); + + public static final String MAX_X="_maxX"; + public static final String MAX_Y="_maxY"; + public static final String MAX_Z="_maxZ"; + public static final String MIN_X="_minX"; + public static final String MIN_Y="_minY"; + public static final String MIN_Z="_minZ"; + + + public BBOXDV(Double maxX,Double minX,Double maxY,Double minY,Double maxZ,Double minZ){ + this(maxX,minX,maxY,minY); + setMaxZ(maxZ); + setMinZ(minZ); + } + public BBOXDV(Double maxX,Double minX,Double maxY,Double minY){ + setMaxX(maxX); + setMinX(minX); + setMaxY(maxY); + setMinY(minY); + } + + + public BBOXDV setMaxX(Double d){this.put(MAX_X,d);return this;} + + public BBOXDV setMaxY(Double d){this.put(MAX_Y,d);return this;} + + public BBOXDV setMaxZ(Double d){this.put(MAX_Z,d);return this;} + + public BBOXDV setMinX(Double d){this.put(MIN_X,d);return this;} + + public BBOXDV setMinY(Double d){this.put(MIN_Y,d);return this;} + + public BBOXDV setMinZ(Double d){this.put(MIN_Z,d);return this;} + + public Double getMinY(){return (Double) this.getOrDefault(MIN_Y,-90d);} + + public Double getMaxY(){return (Double) this.getOrDefault(MAX_Y,90d);} + + public Double getMinX(){return (Double) this.getOrDefault(MIN_X,-180d);} + + public Double getMaxX(){return (Double) this.getOrDefault(MAX_X,180d);} + + public Double getMinZ(){return (Double) this.getOrDefault(MIN_Z,null);} + + public Double getMaxZ(){return (Double) this.getOrDefault(MAX_Z,null);} + + + public Boolean is3d(){ + return getMinZ()!=null && getMaxZ() !=null; + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/cl/document/materialization/GCubeSDILayerDV.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/cl/document/materialization/GCubeSDILayerDV.java new file mode 100644 index 0000000..ce2d78c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/cl/document/materialization/GCubeSDILayerDV.java @@ -0,0 +1,77 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared.cl.document.materialization; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class GCubeSDILayerDV implements Serializable { + + // TODO manage heterogeneus collection + + /** + * + */ + private static final long serialVersionUID = 5317964084778336268L; + @JsonProperty(value = "_type") + private String type; + @JsonProperty(value = "_platformInfo") + private List platformInfos; + @JsonProperty(value = "_bbox") + private BBOXDV bbox; + @JsonProperty(value = "_ogcLinks") + private HashMap ogcLinks; + + public GCubeSDILayerDV() { + + } + + public String getType() { + return type; + } + + public List getPlatformInfos() { + return platformInfos; + } + + public BBOXDV getBbox() { + return bbox; + } + + public HashMap getOgcLinks() { + return ogcLinks; + } + + public void setType(String type) { + this.type = type; + } + + public void setPlatformInfos(List platformInfos) { + this.platformInfos = platformInfos; + } + + public void setBbox(BBOXDV bbox) { + this.bbox = bbox; + } + + public void setOgcLinks(HashMap ogcLinks) { + this.ogcLinks = ogcLinks; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GCubeSDILayerDV [type="); + builder.append(type); + builder.append(", platformInfos="); + builder.append(platformInfos); + builder.append(", bbox="); + builder.append(bbox); + builder.append(", ogcLinks="); + builder.append(ogcLinks); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/cl/document/materialization/GeoServerPlatformInfoDV.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/cl/document/materialization/GeoServerPlatformInfoDV.java new file mode 100644 index 0000000..3aeaf5f --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/cl/document/materialization/GeoServerPlatformInfoDV.java @@ -0,0 +1,85 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared.cl.document.materialization; + +import java.io.Serializable; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class GeoServerPlatformInfoDV implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -2630467451758269625L; + + @JsonProperty(value = "_type") + private String type; + private String workspace; + private String storeName; + + public GeoServerPlatformInfoDV() { + } + + @JsonProperty(value = "_host") + private String host; + + private Map ogcLinks; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getWorkspace() { + return workspace; + } + + public void setWorkspace(String workspace) { + this.workspace = workspace; + } + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public Map getOgcLinks() { + return ogcLinks; + } + + public void setOgcLinks(Map ogcLinks) { + this.ogcLinks = ogcLinks; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeoServerPlatformInfoDV [type="); + builder.append(type); + builder.append(", workspace="); + builder.append(workspace); + builder.append(", storeName="); + builder.append(storeName); + builder.append(", host="); + builder.append(host); + builder.append(", ogcLinks="); + builder.append(ogcLinks); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/faults/ControlledError.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/faults/ControlledError.java new file mode 100644 index 0000000..cacda13 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/faults/ControlledError.java @@ -0,0 +1,37 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared.faults; + +public class ControlledError extends Exception { + + /** + * + */ + private static final long serialVersionUID = 3471094758439575063L; + + public ControlledError() { + super(); + // TODO Auto-generated constructor stub + } + + public ControlledError(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + // TODO Auto-generated constructor stub + } + + public ControlledError(String message, Throwable cause) { + super(message, cause); + // TODO Auto-generated constructor stub + } + + public ControlledError(String message) { + super(message); + // TODO Auto-generated constructor stub + } + + public ControlledError(Throwable cause) { + super(cause); + // TODO Auto-generated constructor stub + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/IndexLayer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/IndexLayer.java new file mode 100644 index 0000000..437e1bb --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/IndexLayer.java @@ -0,0 +1,85 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared.gis; + +import java.io.Serializable; + +import org.gcube.portlets.user.geoportaldataviewer.shared.cl.document.materialization.GCubeSDILayerDV; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class IndexLayer implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 5352754312327975329L; + + @JsonProperty(value = "_type") + private String type; + private GCubeSDILayerDV layer; + private String indexName; + private int records; + private String flag; + + public IndexLayer() { + + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public GCubeSDILayerDV getLayer() { + return layer; + } + + public void setLayer(GCubeSDILayerDV layer) { + this.layer = layer; + } + + public String getIndexName() { + return indexName; + } + + public void setIndexName(String indexName) { + this.indexName = indexName; + } + + public int getRecords() { + return records; + } + + public void setRecords(int records) { + this.records = records; + } + + public String getFlag() { + return flag; + } + + public void setFlag(String flag) { + this.flag = flag; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("IndexLayer [type="); + builder.append(type); + builder.append(", layer="); + builder.append(layer); + builder.append(", indexName="); + builder.append(indexName); + builder.append(", records="); + builder.append(records); + builder.append(", flag="); + builder.append(flag); + builder.append("]"); + return builder.toString(); + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerItem.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerItem.java index 58f17f1..2b05b81 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerItem.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerItem.java @@ -2,13 +2,18 @@ package org.gcube.portlets.user.geoportaldataviewer.shared.gis; import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; +import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.LayerType; +import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.Property; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis; +import com.google.gwt.core.client.GWT; + /** * The Class LayerItem. * @@ -18,6 +23,7 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis; */ public class LayerItem implements Serializable, Cloneable { + /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1664082688635256899L; @@ -962,4 +968,92 @@ public class LayerItem implements Serializable, Cloneable { return builder.toString(); } + + /** + * To layer item. + * + * @param layerType the layer type + * @param layerTitle the layer title + * @param layerName the layer name + * @param layerURL the layer URL + * @param mapServerHost the map server host + * @param isExternal the is external + * @param isBase the is base + * @param displayInLayerSwitcher the display in layer switcher + * @param styles the styles + * @param wmsLink the wms link + * @param onTop the on top + * @param wmsNotStandardParams the wms not standard params + * @param isNcWms the is nc wms + * @param UUID the uuid + * @param zAxis the z axis + * @param minResolution the min resolution + * @param maxResolution the max resolution + * @return the layer item + */ + + + // TODO Constructor from IndexLayer, GCUBESDILAeryDV or direct info + private LayerItem toLayerItem(LayerType layerType, String layerTitle, String layerName, String layerURL, + String mapServerHost, boolean isExternal, boolean isBase, boolean displayInLayerSwitcher, + ArrayList styles, String wmsLink, boolean onTop, HashMap wmsNotStandardParams, + boolean isNcWms, String UUID, ZAxis zAxis, Double minResolution, Double maxResolution) { + +// GWT.log("Add addLayerByWms 1"); + LayerItem layerItem = new LayerItem(); + layerItem.setBaseLayer(isBase); + layerItem.setTitle(layerTitle); + layerItem.setName(layerName); + layerItem.setUrl(layerURL); + layerItem.setMapServerHost(mapServerHost); + // l.setExternal(isExternal); + layerItem.setOpacity(1d); + layerItem.setBuffer(2); + layerItem.setWmsLink(wmsLink); + layerItem.setWmsNotStandardParams(wmsNotStandardParams); + layerItem.setNcWms(isNcWms); + layerItem.setUUID(UUID); + layerItem.setZAxis(zAxis); + layerItem.setMinResolution(minResolution); + layerItem.setMaxResolution(maxResolution); + + switch (layerType) { + + // TODO IMPLEMENT THIS CASE + case RASTER_BASELAYER: + +// l.setHasLegend(false); + layerItem.setBaseLayer(true); + layerItem.setTrasparent(false); + layerItem.setClickData(false); + break; + + case FEATURE_TYPE: + + // CASE FEATURE TYPE + layerItem.setBaseLayer(false); + layerItem.setClickData(true); + layerItem.setTrasparent(true); + break; + + } + + GWT.log("styles " + styles); + + if (styles != null && styles.size() > 0) { + layerItem.setHasLegend(true); + layerItem.setDefaultStyle(styles.get(0)); + layerItem.setStyle(styles.get(0)); + layerItem.setStyles(styles); + } else { + String style = URLUtil.getValueOfParameter("styles", wmsLink); + if (style != null) { // CASE OF STYLE =""; + // TENTATIVE TO GET LEGEND + layerItem.setHasLegend(true); + } + } + GWT.log("Built layer: " + layerItem); + return layerItem; + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerObject.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerObject.java index f0c2a3c..d058a04 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerObject.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerObject.java @@ -2,15 +2,14 @@ package org.gcube.portlets.user.geoportaldataviewer.shared.gis; import java.io.Serializable; -import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV; +import org.gcube.portlets.user.geoportaldataviewer.shared.cl.document.materialization.GCubeSDILayerDV; /** - * The Class LayerObject. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * Represents a layer, + * holds the layer item and the related Collection info if existing + * * - * Sep 9, 2021 */ public class LayerObject implements Serializable { @@ -18,101 +17,107 @@ public class LayerObject implements Serializable { * */ private static final long serialVersionUID = -2282478701630148774L; - /* This is the layer/product type. E.g. Concessione */ - private String itemType; + + + private LayerObjectType type; + + private IndexLayer indexLayer; // expected for INDEX_LAYER type + private String ucid; // expected for collection layers + private GCubeSDILayerDV projectLayer; // expected for PROJECT_LAYER + private String projectId; // expected for PROJECT_LAYER + private LayerItem layerItem; - private BaseConcessioneDV sourceConcessione; - /** - * Instantiates a new layer object. - */ public LayerObject() { - } - - /** - * Instantiates a new layer object. - * - * @param itemType the item type - * @param layerItem the layer item - * @param sourceConcessione the source concessione - */ - public LayerObject(String itemType, LayerItem layerItem, BaseConcessioneDV sourceConcessione) { super(); - this.itemType = itemType; - this.layerItem = layerItem; - this.sourceConcessione = sourceConcessione; } - /** - * Gets the item type. - * - * @return the item type - */ - public String getItemType() { - return itemType; + public LayerObject(LayerObjectType type,LayerItem item) { + this.setType(type); + this.setLayerItem(item); + } + + + public LayerObject(String ucid, IndexLayer indexLayer, LayerItem item) { + this(LayerObjectType.INDEX_LAYER,item); + this.ucid=ucid; + this.indexLayer=indexLayer; + } + + public LayerObject(String ucid, String projectId, GCubeSDILayerDV projectLayer, LayerItem item) { + this(LayerObjectType.PROJECT_LAYER,item); + this.ucid=ucid; + this.projectId=projectId; + this.projectLayer = projectLayer; } - /** - * Gets the layer item. - * - * @return the layer item - */ + + public LayerObjectType getType() { + return type; + } + + + public void setType(LayerObjectType type) { + this.type = type; + } + + + public IndexLayer getIndexLayer() { + return indexLayer; + } + + + public void setIndexLayer(IndexLayer indexLayer) { + this.indexLayer = indexLayer; + } + + + public String getUcid() { + return ucid; + } + + + public void setUcid(String ucid) { + this.ucid = ucid; + } + + + public GCubeSDILayerDV getProjectLayer() { + return projectLayer; + } + + + public void setProjectLayer(GCubeSDILayerDV projectLayer) { + this.projectLayer = projectLayer; + } + + + public String getProjectId() { + return projectId; + } + + + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + public LayerItem getLayerItem() { return layerItem; } - /** - * Gets the source concessione. - * - * @return the source concessione - */ - public BaseConcessioneDV getSourceConcessione() { - return sourceConcessione; - } - /** - * Sets the item type. - * - * @param itemType the new item type - */ - public void setItemType(String itemType) { - this.itemType = itemType; - } - - /** - * Sets the layer item. - * - * @param layerItem the new layer item - */ public void setLayerItem(LayerItem layerItem) { this.layerItem = layerItem; } - /** - * Sets the source concessione. - * - * @param sourceConcessione the new source concessione - */ - public void setSourceConcessione(BaseConcessioneDV sourceConcessione) { - this.sourceConcessione = sourceConcessione; - } - /** - * To string. - * - * @return the string - */ - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("LayerObject [itemType="); - builder.append(itemType); - builder.append(", layerItem="); - builder.append(layerItem); - builder.append(", sourceConcessione="); - builder.append(sourceConcessione); - builder.append("]"); - return builder.toString(); + public static long getSerialversionuid() { + return serialVersionUID; } + + + + } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerObjectType.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerObjectType.java new file mode 100644 index 0000000..0155a88 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/gis/LayerObjectType.java @@ -0,0 +1,5 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared.gis; + +public enum LayerObjectType { + BASE_LAYER, PROJECT_LAYER, INDEX_LAYER, GENERIC_LAYER +} \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index d239f5b..f72daa1 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -32,9 +32,4 @@ /GeoportalDataViewer/geoportaldataviewerservice - - - org.gcube.portlets.user.geoportaldataviewer.server.GeoportalDataViewerHttpSessionListener - - diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataviewer/GeoportalViewer_Tests.java b/src/test/java/org/gcube/portlets/user/geoportaldataviewer/GeoportalViewer_Tests.java new file mode 100644 index 0000000..3e00966 --- /dev/null +++ b/src/test/java/org/gcube/portlets/user/geoportaldataviewer/GeoportalViewer_Tests.java @@ -0,0 +1,77 @@ +package org.gcube.portlets.user.geoportaldataviewer; + +import org.gcube.application.geoportal.common.model.document.Project; +import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; +import org.gcube.application.geoportalcommon.ProjectDVBuilder; +import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller; +import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller; +import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller; +import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; +import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.portlets.user.geoportaldataviewer.server.GeoportalDataViewerServiceImpl; +import org.junit.Before; +import org.junit.Test; + +/** + * The Class GeoportalViewer_Tests. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Sep 9, 2022 + */ +public class GeoportalViewer_Tests { + + private UseCaseDescriptorCaller clientUCD; + + private ProjectsCaller clientProjects; + + // private static String CONTEXT = "/pred4s/preprod/preVRE"; + // private static String TOKEN = ""; //preVRE + + private static String CONTEXT = "/gcube/devsec/devVRE"; + private static String TOKEN = "c41a00c0-7897-48d2-a67a-05190d6ce5e6-98187548"; // devVRE + + private static String PROFILE_ID = "profiledConcessioni"; + private static String PROJECT_ID = "6311d408900dde90e44d9265"; + + private static String USERNAME = "francesco.mangiacrapa"; + + /** + * Gets the client. + * + * @return the client + */ + @Before + public void getClient() { + // assumeTrue(GCubeTest.isTestInfrastructureEnabled()); + ScopeProvider.instance.set(CONTEXT); + SecurityTokenProvider.instance.set(TOKEN); + clientUCD = GeoportalClientCaller.useCaseDescriptors(); + clientProjects = GeoportalClientCaller.projects(); + } + + @Test + public void getPreviewObjectForID() { + + try { + ScopeProvider.instance.set(CONTEXT); + SecurityTokenProvider.instance.set(TOKEN); + Project project = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID); + ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); + ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder); + + ScopeProvider.instance.set(CONTEXT); + SecurityTokenProvider.instance.set(TOKEN); + GeoportalDataViewerServiceImpl gdvsi = new GeoportalDataViewerServiceImpl(); + + ProjectView projectView = gdvsi.loadProjectView(projectDV, CONTEXT, USERNAME); + System.out.println(projectView); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +}