From a3c10d1b18a92202eb9347857e7d49cc2a01b516 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 18 Oct 2022 14:17:41 +0200 Subject: [PATCH] Ported getLayersForId --- .../client/GeoportalDataViewer.java | 62 ------ .../client/GeoportalDataViewerService.java | 49 ++--- .../GeoportalDataViewerServiceAsync.java | 4 +- .../client/LayerManager.java | 104 +++++---- .../ui/cms/layers/LayersSectionViewer.java | 2 +- .../GeoportalDataViewerServiceImpl.java | 206 +++++++++--------- .../server/Geoportal_JSON_Mapper.java | 139 +++++++----- .../GeoportalServiceIdentityProxy.java | 75 +++---- .../server/util/ContextRequest.java | 4 +- .../GeoportalViewer_Tests.java | 40 +++- 10 files changed, 352 insertions(+), 333 deletions(-) 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 44c95c1..4b31835 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 @@ -259,68 +259,6 @@ public class GeoportalDataViewer implements EntryPoint { 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. 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 0bf3eb1..975d8b8 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 @@ -6,10 +6,10 @@ import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; 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.ItemFieldsResponse; @@ -94,7 +94,7 @@ public interface GeoportalDataViewerService extends RemoteService { * @param itemId the item id * @param maxImages the max images * @return the uploaded images for id - * @throws Exception + * @throws Exception the exception */ List getUploadedImagesForId(String itemType, String itemId, Integer maxImages) throws Exception; @@ -110,12 +110,12 @@ public interface GeoportalDataViewerService extends RemoteService { /** * Gets the layers for id. * - * @param itemType the item type - * @param itemId the item id + * @param theProfileID the the profile ID + * @param theProductID the the product ID * @return the layers for id * @throws Exception the exception */ - List getLayersForId(String itemType, String itemId) throws Exception; + List getLayersForId(String theProfileID, String theProductID) throws Exception; /** * Gets the WFS features. @@ -130,13 +130,18 @@ public interface GeoportalDataViewerService extends RemoteService { List getWFSFeatures(List layerObjects, String mapSrsName, BoundsMap selectBBOX, int maxWFSFeature, double zoomLevel); + /** + * Gets the list base layers. + * + * @return the list base layers + */ List getListBaseLayers(); /** * List of fields for searching. * * @return the list - * @throws Exception + * @throws Exception the exception */ List listOfFieldsForSearching() throws Exception; @@ -178,34 +183,10 @@ public interface GeoportalDataViewerService extends RemoteService { boolean reloadFromService) throws Exception; /** - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * NEW CODE HERE - * - * - * - * - * - * - * - * - * - * - * - * - * + * NEW CODE HERE. + * + * @return the initial configuration + * @throws Exception the exception */ 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 d0a1092..85450e3 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 @@ -6,10 +6,10 @@ import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; 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.ItemFieldsResponse; @@ -58,7 +58,7 @@ public interface GeoportalDataViewerServiceAsync { void getPublicLinksFor(GeoNaItemRef item, AsyncCallback asyncCallback); - void getLayersForId(String itemType, String itemId, AsyncCallback> asyncCallback); + void getLayersForId(String theProfileID, String theProductID, AsyncCallback> asyncCallback); void getWFSFeatures(List layerObjects, String mapSrsName, BoundsMap selectBBOX, int maxWFSFeature, double zoomLevel, 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 848b01a..f15cfd2 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 @@ -9,12 +9,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; 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; @@ -191,14 +193,12 @@ 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; @@ -307,16 +307,18 @@ public class LayerManager { if (olMap.getCurrentZoomLevel() > OLMapManager.QUERY_MIN_ZOOM_LEVEL) { GWT.log("Current zoom level is less than QUERY_MIN_ZOOM_LEVEL, Loading all layers of any product"); - for (String theProductId : listUniqueProducts.keySet()) { - GWT.log("Loading layers of theProductId: " + theProductId); + for (final String theProductID : listUniqueProducts.keySet()) { + GWT.log("Loading layers of theProductId: " + theProductID); // retrieving and showing WMS layers of a concessione if the ZOOM // level // is > // QUERY_MIN_ZOOM_LEVEL + final String theProfileID = "?????"; + GeoportalDataViewerServiceAsync.Util.getInstance().getLayersForId( - "concessione", theProductId, - new AsyncCallback>() { + theProfileID, theProductID, + new AsyncCallback>() { @Override public void onFailure(Throwable caught) { @@ -325,22 +327,51 @@ public class LayerManager { } @Override - public void onSuccess(List result) { + public void onSuccess( + List result) { - for (LayerConcessioneDV layer : result) { - GWT.log("Adding layer: " - + layer.getLayerName()); - addLayer("concessione", layer.getLayerName(), + for (GCubeSDIViewerLayerDV layer : result) { + GWT.log("Adding layer: " + layer.getLayerName()); + addLayer(LayerObjectType.PROJECT_LAYER, layer.getLayerName(), - layer.getWmsLink(), false, false, - layer.getLayerUUID(), true, + layer.getLayerName(), + layer.getWMSLink(), false, false, null, + true, OLMapManager.LAYER_DETAIL_MIN_RESOLUTION, OLMapManager.LAYER_DETAIL_MAX_RESOLUTION, - layer.getRefersTo()); + theProfileID, theProductID); } } }); + +// GeoportalDataViewerServiceAsync.Util.getInstance().getLayersForId( +// "concessione", theProductID, +// new AsyncCallback>() { +// +// @Override +// public void onFailure(Throwable caught) { +// // TODO Auto-generated method stub +// +// } +// +// @Override +// public void onSuccess(List result) { +// +// for (LayerConcessioneDV layer : result) { +// GWT.log("Adding layer: " +// + layer.getLayerName()); +// addLayer("concessione", layer.getLayerName(), +// layer.getLayerName(), +// layer.getWmsLink(), false, false, +// layer.getLayerUUID(), true, +// OLMapManager.LAYER_DETAIL_MIN_RESOLUTION, +// OLMapManager.LAYER_DETAIL_MAX_RESOLUTION, +// layer.getRefersTo()); +// } +// +// } +// }); } } else { // removing all WMS detail layers if the ZOOM level is < @@ -349,9 +380,7 @@ public class LayerManager { } } } - - */ - + } }); } @@ -391,7 +420,7 @@ public class LayerManager { * Parses the geona references. * * @param layerObject the layer object - * @param fRow the f row + * @param fRow the f row * @return the show details event */ private ShowDetailsEvent parseGeonaReferences(LayerObject layerObject, FeatureRow fRow) { @@ -446,27 +475,26 @@ public class LayerManager { } } - /** * 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 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 + * @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, - String profileID, String projectID) { + final boolean asDetailLayer, Double minResolution, Double maxResolution, String profileID, + String projectID) { // final LayoutContainer westPanel = (LayoutContainer) layersPanel.getParent(); // @@ -514,7 +542,7 @@ public class LayerManager { lo.setProjectId(projectID); String key = layerItem.getName(); // should be unique // - //layerObjects.put(key, lo); + // layerObjects.put(key, lo); if (!asDetailLayer) { // is a base layer LayerObject blo = LayerObject blo = mapBaseLayerObjects.get(key); @@ -545,9 +573,9 @@ public class LayerManager { */ public void addIndexLayer(IndexLayerDV layer) { - addLayer(LayerObjectType.INDEX_LAYER, null, null, layer.getLayer().getOgcLinks().get("wms"), false, false, null, false, - null, null, null, null); - + addLayer(LayerObjectType.INDEX_LAYER, null, null, layer.getLayer().getOgcLinks().get("wms"), false, false, null, + false, null, null, null, null); + } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/layers/LayersSectionViewer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/layers/LayersSectionViewer.java index a6186e6..2811fd9 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/layers/LayersSectionViewer.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/layers/LayersSectionViewer.java @@ -62,7 +62,7 @@ public class LayersSectionViewer extends Composite { String wmsLink = null; try { - wmsLink = layer.getOgcLinks().get("wms"); + wmsLink = layer.getWMSLink(); } catch (Exception e) { return; } 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 4091b36..9e4e34a 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 @@ -25,6 +25,7 @@ import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDes 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.ProjectDVBuilder; import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller; import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller; import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller; @@ -37,6 +38,7 @@ import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; @@ -45,7 +47,6 @@ import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescrip import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; 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.application.geoportalcommon.util.URLParserUtil; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerService; @@ -92,12 +93,32 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme private static final String CACHE_IMAGE_PREVIEW_FOR_CONCESSIONE = "MAP_IMAGE_PREVIEW_FOR_CONCESSIONE"; + /** + * The Enum COMMON_IMAGES_FORMAT. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 18, 2022 + */ public static enum COMMON_IMAGES_FORMAT { gif, png, jpeg, jpg, bmp, tif, tiff, svg, avif, webp } + /** + * The Class ImageDetector. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 18, 2022 + */ public static class ImageDetector { + /** + * Gets the names. + * + * @param e the e + * @return the names + */ private static String[] getNames(Class> e) { return Arrays.stream(e.getEnumConstants()).map(Enum::name).toArray(String[]::new); } @@ -111,6 +132,12 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } + /** + * Checks if is image. + * + * @param mimeType the mime type + * @return true, if is image + */ public static boolean isImage(String mimeType) { if (mimeType == null || mimeType.isEmpty()) return false; @@ -663,34 +690,10 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } /** - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * NEW CODE HERE - * - * - * - * - * - * - * - * - * - * - * - * - * + * NEW CODE HERE. + * + * @return the initial configuration + * @throws Exception the exception */ @Override @@ -786,6 +789,12 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme }.execute().getResult(); } + /** + * List of fields for searching. + * + * @return the list + * @throws Exception the exception + */ @Override public List listOfFieldsForSearching() throws Exception { LOG.info("listOfFieldsForSearching called"); @@ -811,10 +820,11 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme listUseCaseDescriptor = new ArrayList(); } - //List listUCDDV = new ArrayList(listUseCaseDescriptor.size()); + // List listUCDDV = new + // ArrayList(listUseCaseDescriptor.size()); for (UseCaseDescriptor ucd : listUseCaseDescriptor) { UseCaseDescriptorDV ucdDV = ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null); - //listUCDDV.add(ucdDV); + // listUCDDV.add(ucdDV); HandlerDeclarationDV dataListHandler = getHandlerDeclarationFor(ucdDV, GEOPORTAL_DATA_HANDLER.geoportal_data_list); @@ -825,7 +835,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme ItemFieldsResponse ifResponse = new ItemFieldsResponse(); ifResponse.setUseCaseDescriptorDV(ucdDV); List listItemFields = (List) config.getConfiguration(); - //map.put(ucdDV.getProfileID(), listItemFields); + // map.put(ucdDV.getProfileID(), listItemFields); ifResponse.setListItemFields(listItemFields); listIFResponse.add(ifResponse); break; @@ -844,6 +854,13 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } } + /** + * Gets the handler declaration for. + * + * @param useCaseDescriptor the use case descriptor + * @param dataHandler the data handler + * @return the handler declaration for + */ public static HandlerDeclarationDV getHandlerDeclarationFor(UseCaseDescriptorDV useCaseDescriptor, GEOPORTAL_DATA_HANDLER dataHandler) { @@ -862,6 +879,12 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } + /** + * Inits the. + * + * @param config the config + * @throws ServletException the servlet exception + */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); @@ -870,10 +893,16 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme new GcubeProfilesPerUCDIdCache(); } + /** + * On before request deserialized. + * + * @param serializedRequest the serialized request + */ @Override protected void onBeforeRequestDeserialized(String serializedRequest) { LOG.info("onBeforeRequestDeserialized called"); String scope = ""; + try { new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); @@ -967,76 +996,52 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme /** * Gets the layers for id. * - * @param itemType the item type - * @param itemId the item id + * @param profileID the profile ID + * @param projectID the project ID * @return the layers for id * @throws Exception the exception */ @Override - public List getLayersForId(String itemType, String itemId) throws Exception { - LOG.info("getLayersForId [itemId: " + itemId + ", itemType: " + itemType + "] called"); + public List getLayersForId(String profileID, String projectID) throws Exception { + LOG.info("getLayersForId [profileID: " + profileID + ", projectID: " + projectID + "] called"); - throw new Exception("getLayersForId must be revisited!!!"); + if (profileID == null) + throw new Exception("Invalid parameter. The profileID is null"); - /* - * if (itemType == null) throw new - * Exception("Invalid parameter. The itemType is null"); - * - * if (itemId == null) throw new - * Exception("Invalid parameter. The itemId is null"); - * - * List listLayers = null; - * - * try { - * - * SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); String - * userName = null; try { userName = - * SessionUtil.getCurrentUser(this.getThreadLocalRequest()).getUsername(); } - * catch (Exception e) { LOG. - * info("User not found in session, the userName for cecking policy will be null" - * ); } - * - * if (itemType.equalsIgnoreCase("concessione")) { - * - * LOG.info("Trying to get concessione for id " + itemId); - * GeoportalServiceIdentityProxy cms = new - * GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); Concessione - * concessione = cms.getItemById(itemId); - * - * BaseConcessioneDV baseConcessione = - * ConvertToDataViewModel.toBaseConcessione(concessione); if (concessione != - * null) { LOG.info("For id " + itemId + ", got concessione " + - * concessione.getNome() + " from service"); listLayers = new - * ArrayList(); if (concessione.getPianteFineScavo() != - * null) { - * - * for (LayerConcessione lc : concessione.getPianteFineScavo()) { if - * (GeoNACheckAccessPolicy.isAccessible(lc.getPolicy().name(), userName)) { - * listLayers.add(ConvertToDataViewModel.toLayerConcessione(lc, - * baseConcessione)); } } - * - * LayerConcessione lcPosizionamento = concessione.getPosizionamentoScavo(); - * - * if (lcPosizionamento != null) { - * - * if (GeoNACheckAccessPolicy.isAccessible(lcPosizionamento.getPolicy().name(), - * userName)) { - * - * LayerConcessioneDV thePosizScavo = ConvertToDataViewModel - * .toLayerConcessione(lcPosizionamento, baseConcessione); if (thePosizScavo != - * null) listLayers.add(thePosizScavo); } } - * - * } - * - * } else throw new Exception("Concessione with id '" + itemId + - * "' not available"); } LOG.info("For id " + itemId + ", returning " + - * listLayers.size() + " layer/s"); return listLayers; - * - * } catch (Exception e) { String erroMsg = "Layers are not available for " + - * Concessione.class.getSimpleName() + " with id " + itemId; LOG.error(erroMsg, - * e); throw new Exception(erroMsg); } - * - */ + if (projectID == null) + throw new Exception("Invalid parameter. The projectID is null"); + + List listLayers = null; + + try { + + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + try { + SessionUtil.getCurrentUser(this.getThreadLocalRequest()).getUsername(); + } catch (Exception e) { + LOG.info("User not found in session, the userName for cecking policy will be null"); + } + + LOG.info("Trying to get project for id " + profileID); + + new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); + Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); + String jsonDocument = theProject.getTheDocument().toJson(); + LOG.trace("JSON Project is: " + jsonDocument); + + String materializationJSONPath = String.format("%s.%s.%s", Geoportal_JSON_Mapper.JSON_$_POINTER, + Geoportal_JSON_Mapper.FILESET, Geoportal_JSON_Mapper._MATERIALIZATIONS); + + listLayers = Geoportal_JSON_Mapper.readGcubeSDILayersForFileset(materializationJSONPath, jsonDocument); + + LOG.info("For projectID " + projectID + ", returning " + listLayers.size() + " layer/s"); + return listLayers; + + } catch (Exception e) { + String erroMsg = "Layers are not available for profileID " + profileID + " with projectID " + projectID; + LOG.error(erroMsg, e); + throw new Exception(erroMsg); + } } @@ -1067,10 +1072,11 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme LOG.info("Trying to get project for id " + profileID); - GeoportalServiceIdentityProxy geoIP = new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); - UseCaseDescriptorDV ucd = geoIP.getUCDByID(profileID); - ProjectDV theProjectDV = geoIP.getProjectByID(profileID, projectID); - + new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); + UseCaseDescriptor ucd = GeoportalClientCaller.useCaseDescriptors().getUCDForId(profileID); + Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); + ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); + ProjectDV theProjectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder); theProjectDV.setProfileName(ucd.getName()); ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(theProjectDV, scope, userName); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java index b8d961b..70b85a1 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java @@ -22,6 +22,7 @@ import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView; import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView; import org.gcube.portlets.user.geoportaldataviewer.server.GeoportalDataViewerServiceImpl.ImageDetector; +import org.gcube.portlets.user.geoportaldataviewer.server.util.URLParserUtil; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; import org.json.JSONArray; @@ -38,6 +39,10 @@ import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider; public class Geoportal_JSON_Mapper { + public static final String _PAYLOADS = "_payloads"; + + public static final String _MATERIALIZATIONS = "_materializations"; + private static final Logger LOG = LoggerFactory.getLogger(Geoportal_JSON_Mapper.class); public static final String FILESET = "fileset"; @@ -50,6 +55,8 @@ public class Geoportal_JSON_Mapper { public static final String JSON_$_POINTER = "$"; + public static final String _THEDOCUMENT = "_theDocument"; + public static ProjectView loadProjectView(ProjectDV theProjectDV, String scope, String username) throws Exception { String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON(); @@ -107,7 +114,7 @@ public class Geoportal_JSON_Mapper { // Reading Fileset _materializations / layers listLayers = readGcubeSDILayersForFileset(filesetJSONPath, wholeSectionDoc); - + subDocumentView.setListLayers(listLayers); sectionView.addSubDocument(subDocumentView); projectView.addSectionView(sectionView); @@ -267,11 +274,11 @@ public class Geoportal_JSON_Mapper { * @param sectionJSONDocument the section JSON document * @return the list */ - private static List readPayloadsForFileset(String filesetJSONPath, String sectionJSONDocument) { + public static List readPayloadsForFileset(String filesetJSONPath, String sectionJSONDocument) { LOG.debug("readPayloadsForFileset called"); List listPayloads = new ArrayList(); - String _payloadsJSONPath = String.format("%s.%s", filesetJSONPath, "_payloads"); + String _payloadsJSONPath = String.format("%s.%s", filesetJSONPath, _PAYLOADS); try { com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() .jsonProvider(new JsonOrgJsonProvider()).build(); @@ -299,64 +306,24 @@ public class Geoportal_JSON_Mapper { } - private static List readGcubeSDILayersForFileset(String materializationJSONPath, + public static List readGcubeSDILayersForFileset(String materializationParentJSONPath, String sectionJSONDocument) { LOG.debug("readGcubeSDILayersForFileset called"); List listSDILayers = new ArrayList(); - String _materializationsJSONPath = String.format("%s.%s", materializationJSONPath, "_materializations"); - + String _materializationsJSONPath = String.format("%s.%s", materializationParentJSONPath, _MATERIALIZATIONS); + try { com.jayway.jsonpath.Configuration configurationJSONSmart = com.jayway.jsonpath.Configuration.builder() .jsonProvider(new JsonOrgJsonProvider()).build(); - LOG.info("Reading sectionPath at {} into section document {}", _materializationsJSONPath, - sectionJSONDocument); + LOG.info("Reading sectionPath {} into section document {}", _materializationsJSONPath, sectionJSONDocument); JsonPath theSectionPolycJsonPath = JsonPath.compile(_materializationsJSONPath); - Object _materializations = theSectionPolycJsonPath.read(sectionJSONDocument, configurationJSONSmart) - .toString(); + Object _materializations = theSectionPolycJsonPath.read(sectionJSONDocument, configurationJSONSmart); - if (_materializations instanceof String) { - String toStringMater = (String) _materializations; - LOG.trace("The _materializations is a String {}", toStringMater); - JSONArray jsonArray = new JSONArray(toStringMater); - for (int i = 0; i < jsonArray.length(); i++) { - // TODO THIS PART SHOULD BE REVISITED/OPTIMIZED + LOG.trace("_materializations.class(): " + _materializations.getClass()); - GCubeSDIViewerLayerDV gsdiLayer = new GCubeSDIViewerLayerDV(); - JSONObject thJsonObject = jsonArray.getJSONObject(i); - try { - gsdiLayer.setType(thJsonObject.getString(_TYPE)); - } catch (Exception e) { - LOG.warn("No " + _TYPE + " found", e); - } - String toSerializeJSONOBJ = jsonArray.getJSONObject(i).toString(); - String jsonPath = null; - try { - jsonPath = String.format("%s.%s", JSON_$_POINTER, _BBOX); - BBOXDV bbox = JsonPath.using(configurationJSONSmart).parse(toSerializeJSONOBJ).read(jsonPath, - BBOXDV.class); - gsdiLayer.setBbox(bbox); - LOG.trace("bbox " + i + " is: " + bbox); - } catch (Exception e) { - LOG.warn(jsonPath + " error: ", e); - } - try { - jsonPath = String.format("%s.%s", JSON_$_POINTER, _OGC_LINKS_WMS); - String jsonString = JsonPath.using(configurationJSONSmart).parse(toSerializeJSONOBJ) - .read(jsonPath).toString(); - Gson gson = new Gson(); - HashMap map = gson.fromJson(jsonString, HashMap.class); - gsdiLayer.setOgcLinks(map); - LOG.trace("ogcLinks " + i + " is: " + map); - } catch (Exception e) { - LOG.warn(jsonPath + " error: ", e); - } - - LOG.trace("gsdiLayer " + i + " is: " + gsdiLayer); - listSDILayers.add(gsdiLayer); - } - } + listSDILayers = recursiveFetchingLayers(configurationJSONSmart, _materializations, listSDILayers); } catch (Exception e) { LOG.warn("Error on reading the JSON Path " + _materializationsJSONPath + " in the doc " @@ -367,6 +334,78 @@ public class Geoportal_JSON_Mapper { } + private static List recursiveFetchingLayers(com.jayway.jsonpath.Configuration config, + Object objectJSON, List listSDILayers) { + + if (objectJSON == null) + return listSDILayers; + + if (objectJSON instanceof JSONArray) { + JSONArray theJsonArray = (JSONArray) objectJSON; + LOG.trace("jsonArray: " + theJsonArray.toString(3)); + + for (int i = 0; i < theJsonArray.length(); i++) { + recursiveFetchingLayers(config, theJsonArray.get(i), listSDILayers); + } + } else if (objectJSON instanceof JSONObject) { + JSONObject theJsonObject = (JSONObject) objectJSON; + LOG.trace("theJSONObject: " + theJsonObject.toString(3)); + GCubeSDIViewerLayerDV gsdiLayer = converLayer(config, theJsonObject); + listSDILayers.add(gsdiLayer); + } + + return listSDILayers; + } + + // TODO THIS PART SHOULD BE REVISITED/OPTIMIZED + private static GCubeSDIViewerLayerDV converLayer(com.jayway.jsonpath.Configuration config, + JSONObject thJsonObject) { + LOG.debug("converLayer called for " + thJsonObject); + + GCubeSDIViewerLayerDV gsdiLayer = new GCubeSDIViewerLayerDV(); + try { + String theType = thJsonObject.getString(_TYPE); + gsdiLayer.setType(theType); + LOG.debug(_TYPE + " is: " + theType); + } catch (Exception e) { + LOG.warn("No " + _TYPE + " found", e); + } + String toSerializeJSONOBJ = thJsonObject.toString(); + String jsonPath = null; + try { + jsonPath = String.format("%s.%s", JSON_$_POINTER, _BBOX); + BBOXDV bbox = JsonPath.using(config).parse(toSerializeJSONOBJ).read(jsonPath, BBOXDV.class); + gsdiLayer.setBbox(bbox); + LOG.debug(_BBOX + " is: " + bbox); + } catch (Exception e) { + LOG.warn(jsonPath + " error: ", e); + } + try { + jsonPath = String.format("%s.%s", JSON_$_POINTER, _OGC_LINKS_WMS); + String jsonString = JsonPath.using(config).parse(toSerializeJSONOBJ).read(jsonPath).toString(); + Gson gson = new Gson(); + HashMap map = gson.fromJson(jsonString, HashMap.class); + gsdiLayer.setOgcLinks(map); + LOG.debug(_OGC_LINKS_WMS + " are: " + map); + } catch (Exception e) { + LOG.warn(jsonPath + " error: ", e); + } + + try { + String wmsLink = gsdiLayer.getWMSLink(); + if(wmsLink!=null) { + String layerName = URLParserUtil.extractValueOfParameterFromURL("layers", wmsLink); + gsdiLayer.setLayerName(layerName); + } + } catch (Exception e) { + LOG.warn(jsonPath + " error: ", e); + } + + + LOG.debug("converLayer returning: " + gsdiLayer); + return gsdiLayer; + } + /** * Checks if is accessible section according to policy. * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/mongoservice/GeoportalServiceIdentityProxy.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/mongoservice/GeoportalServiceIdentityProxy.java index a84dbc3..6d1a85f 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/mongoservice/GeoportalServiceIdentityProxy.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/mongoservice/GeoportalServiceIdentityProxy.java @@ -2,15 +2,6 @@ package org.gcube.portlets.user.geoportaldataviewer.server.mongoservice; import javax.servlet.http.HttpServletRequest; -import org.gcube.application.geoportal.common.model.document.Project; -import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; -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.ucd.UseCaseDescriptorDV; import org.gcube.common.portal.PortalContext; import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.accessidentity.GcubeIdentity; import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.accessidentity.IAMClientIdentity; @@ -61,38 +52,38 @@ public class GeoportalServiceIdentityProxy { gCubeIdentity.setIdentity(request); } - /** - * Gets the project by ID. - * - * @param profileID the profile ID - * @param projectID the project ID - * @return the project by ID - * @throws Exception the exception - */ - public ProjectDV getProjectByID(String profileID, String projectID) throws Exception { - ProjectsCaller clientPrj = GeoportalClientCaller.projects(); - Project theProject = clientPrj.getProjectByID(profileID, projectID); - ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); - return ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder); - /* - * try { // Obtain the client ConcessioniMongoService concessioniManager = new - * ConcessioniMongoService(); // Returning item by Id return - * concessioniManager.getItemById(mongoItemId); }catch(Exception e) { - * LOG.error("Error on reading itemById: "+mongoItemId, e); throw(e); }finally { - * gCubeIdentity.resetIdentity(); } - */ - } +// /** +// * Gets the project by ID. +// * +// * @param profileID the profile ID +// * @param projectID the project ID +// * @return the project by ID +// * @throws Exception the exception +// */ +// public ProjectDV getProjectByID(String profileID, String projectID) throws Exception { +// ProjectsCaller clientPrj = GeoportalClientCaller.projects(); +// Project theProject = clientPrj.getProjectByID(profileID, projectID); +// ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); +// return ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder); +// /* +// * try { // Obtain the client ConcessioniMongoService concessioniManager = new +// * ConcessioniMongoService(); // Returning item by Id return +// * concessioniManager.getItemById(mongoItemId); }catch(Exception e) { +// * LOG.error("Error on reading itemById: "+mongoItemId, e); throw(e); }finally { +// * gCubeIdentity.resetIdentity(); } +// */ +// } - /** - * Gets the UCD by ID. - * - * @param profileID the profile ID - * @return the UCD by ID - * @throws Exception the exception - */ - public UseCaseDescriptorDV getUCDByID(String profileID) throws Exception { - UseCaseDescriptorCaller ucdCaller = GeoportalClientCaller.useCaseDescriptors(); - UseCaseDescriptor ucd = ucdCaller.getUCDForId(profileID); - return ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null); - } +// /** +// * Gets the UCD by ID. +// * +// * @param profileID the profile ID +// * @return the UCD by ID +// * @throws Exception the exception +// */ +// public UseCaseDescriptorDV getUCDByID(String profileID) throws Exception { +// UseCaseDescriptorCaller ucdCaller = GeoportalClientCaller.useCaseDescriptors(); +// UseCaseDescriptor ucd = ucdCaller.getUCDForId(profileID); +// return ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null); +// } } 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 index 55f9dbb..3429ad2 100644 --- 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 @@ -5,6 +5,7 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; +import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy; import org.gcube.portlets.user.geoportaldataviewer.shared.faults.ControlledError; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +34,8 @@ public abstract class ContextRequest { for (Runnable r : preoperations) r.run(); } - + + new GeoportalServiceIdentityProxy(request); LOG.debug("Context is " + SessionUtil.getCurrentContext(request, true)); LOG.debug("Context is " + SessionUtil.getCurrentToken(request, true) == null ? null : "***"); LOG.trace("Executing actual method.."); 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 index 0d52d1d..d700208 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataviewer/GeoportalViewer_Tests.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataviewer/GeoportalViewer_Tests.java @@ -1,17 +1,22 @@ package org.gcube.portlets.user.geoportaldataviewer; +import java.util.List; + 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.materialization.GCubeSDIViewerLayerDV; 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.gcube.portlets.user.geoportaldataviewer.server.Geoportal_JSON_Mapper; +import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy; +import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil; import org.junit.Before; import org.junit.Test; @@ -36,7 +41,7 @@ public class GeoportalViewer_Tests { private static String PROFILE_ID = "profiledConcessioni"; private static String PROJECT_ID = "6311d408900dde90e44d9265"; - + private static String USERNAME = "francesco.mangiacrapa"; /** @@ -53,7 +58,7 @@ public class GeoportalViewer_Tests { clientProjects = GeoportalClientCaller.projects(); } - @Test + //@Test public void getProjectViewForID() { try { @@ -62,7 +67,7 @@ public class GeoportalViewer_Tests { 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); ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(projectDV, CONTEXT, USERNAME); @@ -73,4 +78,33 @@ public class GeoportalViewer_Tests { } } + @Test + public void getLayersForId() { + System.out.println("getLayersForId [profileID: " + PROFILE_ID + ", projectID: " + PROJECT_ID + "] called"); + + List listLayers = null; + + try { + + ScopeProvider.instance.set(CONTEXT); + SecurityTokenProvider.instance.set(TOKEN); + Project project = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID); + String jsonDocument = project.getTheDocument().toJson(); + System.out.println("JSON Project is: " + jsonDocument); + + String materializationParentJSONPath = String.format("%s..%s", Geoportal_JSON_Mapper.JSON_$_POINTER, + Geoportal_JSON_Mapper.FILESET); + + listLayers = Geoportal_JSON_Mapper.readGcubeSDILayersForFileset(materializationParentJSONPath, jsonDocument); + + listLayers.stream().forEach(s -> System.out.println(s)); + + } catch (Exception e) { + String erroMsg = "Layers are not available for profileID " + PROFILE_ID + " with projectID " + PROJECT_ID; + System.out.println(erroMsg); + e.printStackTrace(); + } + + } + }