From 1c3184fd0b438d74f26efbc0730c4465a2c91480 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 30 Jul 2021 15:57:25 +0200 Subject: [PATCH] added a method --- .../client/GeoportalDataViewerService.java | 11 +++ .../GeoportalDataViewerServiceAsync.java | 4 + .../client/LayerManager.java | 40 +++++++++- .../GeoportalDataViewerServiceImpl.java | 80 ++++++++++++++++++- 4 files changed, 128 insertions(+), 7 deletions(-) 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 9b11de7..365edd1 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 @@ -9,6 +9,7 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV; +import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.LayerConcessioneDV; import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV; import com.google.gwt.user.client.rpc.RemoteService; @@ -100,4 +101,14 @@ public interface GeoportalDataViewerService extends RemoteService { */ GeoNaItemRef getPublicLinksFor(GeoNaItemRef item) throws Exception; + /** + * Gets the layers for id. + * + * @param itemType the item type + * @param itemId the item id + * @return the layers for id + * @throws Exception the exception + */ + List getLayersForId(String itemType, String itemId) 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 fb9b817..3ae9425 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 @@ -9,6 +9,7 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest; import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV; +import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.LayerConcessioneDV; import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV; import com.google.gwt.core.client.GWT; @@ -50,4 +51,7 @@ public interface GeoportalDataViewerServiceAsync { void getPublicLinksFor(GeoNaItemRef item, AsyncCallback asyncCallback); + void getLayersForId(String itemType, String itemId, + AsyncCallback> asyncCallback); + } 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 89bd471..449ae55 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 @@ -168,20 +168,20 @@ public class LayerManager { flex.getElement().addClassName("popup-table"); boolean featureFound = false; FeatureRow feature = null; - + // TODO SWTCH FOR EARCH ITEM TYPE for (GeoNaSpatialQueryResult geoNaDataObject : listGeonaDataObjects) { List features = geoNaDataObject.getFeatures(); // USING ONLY THE FIRST FEATURE IN THE LIST if (features != null && features.size() > 0) { - + String theProductId = null; // I need to show exaclty the feature with produc_id == recordId if (mongoItemId != null) { for (FeatureRow fRow : features) { List productIdLst = fRow.getMapProperties() .get("product_id"); - String theProductId = productIdLst.get(0); + theProductId = productIdLst.get(0); try { //long productId = Long.parseLong(thePID); if (theProductId == mongoItemId) { @@ -196,9 +196,12 @@ public class LayerManager { } } - // If recordId not passed, I'm using the first feature returned + // If mongoItemId not passed, I'm using the first feature returned if (mongoItemId == null) { feature = features.get(0); + List productIdLst = feature.getMapProperties() + .get("product_id"); + theProductId = productIdLst.get(0); } else { // the recordId to show has been passed but not found into list of // FeatureRow @@ -206,6 +209,35 @@ public class LayerManager { return; } } + + GWT.log("the product id is: "+theProductId); + + /*if(olMap.getCurrentZoomLevel()>10) { + 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) { + GWT.log("Adding layers: "+result); + for (LayerConcessioneDV layer : result) { + addLayer("concessione", layer.getLayerName(), layer.getLayerName(), layer.getWmsLink(), false, false, layer.getLayerUUID(), true); +// LayerItem li = new LayerItem(); +// li.setBaseLayer(false); +// li.setWmsLink(layer.getWmsLink()); +// li.setTitle(layer.getLayerName()); +// olMap.addWMSLayer(li); + } + + } + }); + return; + }*/ + Map> entries = feature.getMapProperties(); 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 9894c98..e3191b3 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 @@ -10,15 +10,13 @@ import java.util.Map; import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI; import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.model.legacy.LayerConcessione; import org.gcube.application.geoportal.common.model.legacy.UploadedImage; import org.gcube.application.geoportalcommon.GeoNaDataViewerProfileReader; import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.LayerItem; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.portal.PortalContext; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerService; import org.gcube.portlets.user.geoportaldataviewer.server.gis.FeatureParser; import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator; @@ -32,6 +30,7 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformation import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.Styles; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis; import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV; +import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.LayerConcessioneDV; import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV; import org.gcube.spatial.data.geoutility.GeoNcWMSMetadataUtility; import org.gcube.spatial.data.geoutility.bean.LayerStyles; @@ -227,6 +226,68 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } + /** + * Gets the layers for id. + * + * @param itemType the item type + * @param itemId the item 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"); + + 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); + + if (itemType.equalsIgnoreCase("concessione")) { + + LOG.info("Trying to get concessione for id " + itemId); + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + SessionUtil.getCurrentToken(this.getThreadLocalRequest(), true); + ConcessioniManagerI concessioniManager = statefulMongoConcessioni().build(); + Concessione concessione = concessioniManager.getById(itemId); + 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()) { + listLayers.add(ConvertToDataViewModel.toLayerConcessione(lc)); + } + } + + if (concessione.getPosizionamentoScavo() != null) { + LayerConcessioneDV thePosizScavo = ConvertToDataViewModel + .toLayerConcessione(concessione.getPosizionamentoScavo()); + 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); + } + + } + /** * Gets the concessione for id. * @@ -364,6 +425,13 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return profile; } + /** + * Gets the public links for. + * + * @param item the item + * @return the public links for + * @throws Exception the exception + */ @Override public GeoNaItemRef getPublicLinksFor(GeoNaItemRef item) throws Exception { LOG.info("getPublicLinksFor called for: " + item); @@ -390,6 +458,12 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } } + /** + * Checks if is session expired. + * + * @return true, if is session expired + * @throws Exception the exception + */ public boolean isSessionExpired() throws Exception { return SessionUtil.isSessionExpired(this.getThreadLocalRequest()); }