diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 4a60a64..cb4d305 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,7 @@ - + + + @@ -23,7 +25,9 @@ - + + + @@ -47,7 +51,9 @@ - + + + @@ -71,7 +77,9 @@ - + + + @@ -95,7 +103,9 @@ - + + + @@ -119,7 +129,9 @@ - + + + @@ -146,7 +158,9 @@ uses - + + + @@ -170,7 +184,9 @@ - + + + @@ -194,7 +210,9 @@ - + + + @@ -218,7 +236,9 @@ - + + + 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 8543d4e..a02f8d5 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 @@ -8,10 +8,7 @@ import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; 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.view.ProjectView; -import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; -import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; 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; @@ -304,7 +301,7 @@ public class GeoportalDataViewer implements EntryPoint { IndexLayerDV layer = toOpen.getIndexes().get(0); // Open Index Layer - layerManager.addIndexLayer(layer, toOpen.getUcd().getProfileID()); + layerManager.addIndexLayer(layer, toOpen.getUcd().getProfileID(), null); } } }); @@ -406,7 +403,8 @@ public class GeoportalDataViewer implements EntryPoint { if (record != null) { this.cancel(); GWT.log("cancelled timer"); - performWFSQueryOnCentroid(record); + performWFSQueryOnCentroid(record.getTheProjectDV().getId(), + record.getCentroidLong(), record.getCentroidLat()); } if (attempt > MAX_RETRY) { @@ -540,16 +538,17 @@ public class GeoportalDataViewer implements EntryPoint { } }); -// applicationBus.addHandler(ShowPopupOnCentroiEvent.TYPE, new ShowPopupOnCentroiEventHandler() { -// -// @Override -// public void onShowPopup(ShowPopupOnCentroiEvent showPopupOnCentroiEvent) { -// -// if (showPopupOnCentroiEvent.getRecord() != null) -// performWFSQueryOnCentroid(showPopupOnCentroiEvent.getRecord()); -// -// } -// }); + applicationBus.addHandler(ShowPopupOnCentroiEvent.TYPE, new ShowPopupOnCentroiEventHandler() { + + @Override + public void onShowPopup(ShowPopupOnCentroiEvent showPopupOnCentroiEvent) { + + if (showPopupOnCentroiEvent.getDocument() != null) + performWFSQueryOnCentroid(showPopupOnCentroiEvent.getDocument().getProjectID(), + showPopupOnCentroiEvent.getCentroidLong(), showPopupOnCentroiEvent.getCentroidLat()); + + } + }); applicationBus.addHandler(SearchPerformedEvent.TYPE, new SearchPerformedEventHandler() { @@ -602,10 +601,11 @@ public class GeoportalDataViewer implements EntryPoint { // // }-*/; - private void performWFSQueryOnCentroid(ProjectView project) { - if (project != null) { - Double x = project.getCentroidLong(); - Double y = project.getCentroidLat(); + private void performWFSQueryOnCentroid(String projectID, Double centroidLong, Double centroidLat) { + GWT.log("Perform performWFSQueryOnCentroid: "+projectID+ " long: "+centroidLong + ", lat: "+centroidLat); + if (projectID != null) { + Double x = centroidLong; + Double y = centroidLat; GWT.log("X: " + x + ", Y:" + y); if (x != null && y != null) { Coordinate transfCoord = MapUtils.transformCoordiante(new Coordinate(x, y), @@ -615,8 +615,8 @@ public class GeoportalDataViewer implements EntryPoint { // GeoportalDataViewerConstants.print("fireEvent QueryDataEvent"); ExtentWrapped toExt = new ExtentWrapped(transfCoord.getX(), transfCoord.getY(), transfCoord.getX(), transfCoord.getY()); - layerManager.getLayerManagerBus().fireEvent(new QueryDataEvent(select, toExt, - project.getTheProjectDV().getId(), true, MapEventType.ADDED_CENTROID_LAYER_TO_MAP)); + layerManager.getLayerManagerBus().fireEvent( + new QueryDataEvent(select, toExt, projectID, true, 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/client/LayerManager.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/LayerManager.java index cd66c5f..adea0ee 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 @@ -210,7 +210,7 @@ public class LayerManager { MapEventType sourceEvent = queryEvent.getSourceMapEventType(); // TODO SWTCH FOR EARCH ITEM TYPE - for (GeoNaSpatialQueryResult geoNaDataObject : listGeonaDataObjects) { + for (final GeoNaSpatialQueryResult geoNaDataObject : listGeonaDataObjects) { GWT.log("GeoNaDataObject: " + geoNaDataObject); List features = geoNaDataObject.getFeatures(); LayerItem layerItem = geoNaDataObject.getSourceLayerObject().getLayerItem(); @@ -344,7 +344,7 @@ public class LayerManager { true, OLMapManager.LAYER_DETAIL_MIN_RESOLUTION, OLMapManager.LAYER_DETAIL_MAX_RESOLUTION, - theProfileID, theProductID); + theProfileID, theProductID, geoNaDataObject.getSourceLayerObject().getProjectDV()); } } @@ -464,11 +464,12 @@ public class LayerManager { * @param maxResolution the max resolution * @param profileID the profile ID * @param projectID the project ID + * @param projectDV the project DV */ 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, final String profileID, - final String projectID) { + final String projectID, final ProjectDV projectDV) { final LayerType featureType = isBase ? LayerType.RASTER_BASELAYER : LayerType.FEATURE_TYPE; @@ -507,6 +508,7 @@ public class LayerManager { lo.setType(lot); lo.setProjectID(projectID); lo.setProfileID(profileID); + lo.setProjectDV(projectDV); String layerNameKey = layerItem.getName(); @@ -531,6 +533,7 @@ public class LayerManager { mapOtherLayerObjects.put(layerNameKey, theLo); GWT.log("mapOtherLayerObjects is: " + mapIndexLayerObjects); olMap.addWMSDetailLayer(layerItem); + overlayLayerManager.addLayerItem(theLo); } else { GWT.log("Skipping " + lo.getType() + " layer " + theLo.getLayerItem().getName() + " already added to Map"); @@ -565,17 +568,20 @@ public class LayerManager { }); } + /** * Adds the index layer. * * @param layer the layer + * @param profileID the profile ID + * @param projectDV the project DV */ - public void addIndexLayer(IndexLayerDV layer, String profileID) { + public void addIndexLayer(IndexLayerDV layer, String profileID, ProjectDV projectDV) { GWT.log("Adding index layer: " + layer); String wmsLink = layer.getLayer().getOgcLinks().get("wms"); GWT.log("index layer wmsLink: " + wmsLink); addLayer(LayerObjectType.INDEX_LAYER, null, null, wmsLink, false, false, null, false, null, null, profileID, - null); + null, projectDV); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/OverlayLayerManager.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/OverlayLayerManager.java index 436423b..01642da 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/OverlayLayerManager.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/OverlayLayerManager.java @@ -1,17 +1,25 @@ package org.gcube.portlets.user.geoportaldataviewer.client; import java.util.ArrayList; +import java.util.HashMap; import org.gcube.portlets.user.geoportaldataviewer.client.ui.dandd.DragDropLayer; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; +import com.github.gwtbootstrap.client.ui.Label; +import com.github.gwtbootstrap.client.ui.constants.LabelType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.ui.FlowPanel; public class OverlayLayerManager { - private ArrayList layers = new ArrayList(); - private FlowPanel fp = new FlowPanel(); + // private ArrayList layers = new ArrayList(); + // private FlowPanel fp = new FlowPanel(); + private FlowPanel clusterCollectionsMainPanel = new FlowPanel(); + private HashMap> mapCollectionsPerProfileID = new HashMap>(); + private HashMap mapCollectionsContainersPerProfileID = new HashMap(); private HandlerManager applicationBus; public OverlayLayerManager(HandlerManager applicationBus) { @@ -19,18 +27,43 @@ public class OverlayLayerManager { } void addLayerItem(LayerObject lo) { + GWT.log("Adding LayerObject having project: "+lo.getProjectDV()); + + ArrayList listDDLayers = mapCollectionsPerProfileID.get(lo.getProfileID()); + + if (listDDLayers == null) { + + String collectionName = lo.getProjectDV() != null && lo.getProjectDV().getProfileName() != null + ? lo.getProjectDV().getProfileName() + : lo.getProfileID(); + + Label labelCollectionName = new Label(collectionName); + labelCollectionName.setType(LabelType.WARNING); + clusterCollectionsMainPanel.add(labelCollectionName); + listDDLayers = new ArrayList(); + + } + + FlowPanel fp = new FlowPanel(); + fp.getElement().getStyle().setMarginLeft(10, Unit.PX); + DragDropLayer dandd = new DragDropLayer(applicationBus, lo, true, true); - layers.add(lo); + listDDLayers.add(dandd); fp.add(dandd); + + mapCollectionsContainersPerProfileID.put(lo.getProfileID(), fp); + mapCollectionsPerProfileID.put(lo.getProfileID(), listDDLayers); + clusterCollectionsMainPanel.add(fp); } public void resetLayers() { - layers.clear(); - fp.clear(); + clusterCollectionsMainPanel.clear(); + mapCollectionsContainersPerProfileID.clear(); + mapCollectionsPerProfileID.clear(); } public FlowPanel getPanel() { - return fp; + return clusterCollectionsMainPanel; } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ShowPopupOnCentroiEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ShowPopupOnCentroiEvent.java index 1a3fadf..cfc8895 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ShowPopupOnCentroiEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/ShowPopupOnCentroiEvent.java @@ -14,6 +14,8 @@ import com.google.gwt.event.shared.GwtEvent; public class ShowPopupOnCentroiEvent extends GwtEvent { public static Type TYPE = new Type(); private DocumentDV document; + private Double centroidLong; + private Double centroidLat; /** * Instantiates a new show details event. @@ -23,8 +25,10 @@ public class ShowPopupOnCentroiEvent extends GwtEvent diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectUtil.java new file mode 100644 index 0000000..4fc7d0e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectUtil.java @@ -0,0 +1,24 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project; + +import java.util.Map.Entry; + +import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; + +public class ProjectUtil { + + public static String toHMLCode(T document, String projectID) { + String htmlCode = ""; + + Entry firstEntrySet = document.getFirstEntryOfMap(); + if (firstEntrySet != null) { + htmlCode += firstEntrySet.getKey() + ": " + firstEntrySet.getValue() + ""; + } + + if (projectID != null) { + htmlCode += "(id: " + projectID + ")"; + } + + return htmlCode; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.java index 775fbc9..1ced53f 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.java @@ -19,7 +19,6 @@ import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.MapView; import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.CustomFlexTable; import com.github.gwtbootstrap.client.ui.Button; -import com.github.gwtbootstrap.client.ui.PageHeader; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.IconType; import com.google.gwt.core.client.GWT; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.ui.xml index 6cf5218..7c47cc3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/ProjectViewer.ui.xml @@ -21,8 +21,7 @@ .the-title { background-color: rgba(0,60,136,.7); color: white; - font-style: italic; - padding: 5px 10px; + padding: 10px 10px; font-size: 14px; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/RelationshipPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/RelationshipPanel.java new file mode 100644 index 0000000..0e2c91d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/RelationshipPanel.java @@ -0,0 +1,50 @@ +package org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.relation; + +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; +import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.project.ProjectUtil; + +import com.github.gwtbootstrap.client.ui.Column; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + +public class RelationshipPanel extends Composite { + + private static ViewRelationshipPanelUiBinder uiBinder = GWT.create(ViewRelationshipPanelUiBinder.class); + + interface ViewRelationshipPanelUiBinder extends UiBinder { + } + + @UiField + HTMLPanel rootRow; + + @UiField + Column leftChildColumn; + + @UiField + Column rightChildColumn; + + private HandlerManager appManagerBus; + + + public RelationshipPanel(HandlerManager appManagerBus, ProjectDV fromProject, List relationships) { + initWidget(uiBinder.createAndBindUi(this)); + this.appManagerBus = appManagerBus; + + String html = ProjectUtil.toHMLCode(fromProject.getTheDocument(), fromProject.getId()); + rootRow.add(new HTML(html)); + + showRelationsOf(fromProject); + } + + public void showRelationsOf(ProjectDV project) { + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/RelationshipPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/RelationshipPanel.ui.xml new file mode 100644 index 0000000..176545b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/project/relation/RelationshipPanel.ui.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java index 3743c95..da9df0a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.java @@ -13,6 +13,7 @@ import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; import org.gcube.application.geoportalcommon.shared.WhereClause; 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.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync; import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEvent; @@ -38,10 +39,8 @@ import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.KeyPressEvent; import com.google.gwt.event.dom.client.KeyPressHandler; import com.google.gwt.event.shared.HandlerManager; -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.user.cellview.client.TextColumn; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; @@ -308,9 +307,11 @@ public class SearchFacilityUI extends Composite { i = 1; for (DocumentDV documentDV : result.getData()) { + + ResultDocumentDV resultDoc = (ResultDocumentDV) documentDV; NavLink locateOnMap = new NavLink("Show"); - locateOnMap.setTitle("Locate on the Map and show details"); + locateOnMap.setTitle("Open this project and show details"); locateOnMap.setIcon(IconType.MAP_MARKER); locateOnMap.addClickHandler(new ClickHandler() { @@ -320,7 +321,7 @@ public class SearchFacilityUI extends Composite { GeoportalItemReferences gir = new GeoportalItemReferences(documentDV.getProjectID(), profileID); appManagerBus.fireEvent(new ShowDetailsEvent(gir, null, null)); - appManagerBus.fireEvent(new ShowPopupOnCentroiEvent(documentDV)); + appManagerBus.fireEvent(new ShowPopupOnCentroiEvent(documentDV, resultDoc.getCentroidLong(), resultDoc.getCentroidLat())); } }); 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 e80d6eb..c8e5d9f 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 @@ -995,8 +995,10 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } - protected List getImagesForId(String profileID, String projectID) throws Exception { - LOG.info("getImagesForId [profileID: " + profileID + ", projectID: " + projectID + "] called"); + protected List getImagesForId(String profileID, String projectID, boolean limitToFirstOneFound) + throws Exception { + LOG.info("getImagesForId [profileID: " + profileID + ", projectID: " + projectID + ", limitToFirstOneFound: " + + limitToFirstOneFound + "] called"); if (profileID == null) throw new Exception("Invalid parameter. The profileID is null"); @@ -1025,7 +1027,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme String filesetJSONPath = String.format("%s..%s", Geoportal_JSON_Mapper.JSON_$_POINTER, Geoportal_JSON_Mapper.FILESET); - listImages = Geoportal_JSON_Mapper.readImagesForFileset(filesetJSONPath, jsonDocument); + listImages = Geoportal_JSON_Mapper.readImagesForFileset(filesetJSONPath, jsonDocument, + limitToFirstOneFound); LOG.info("For projectID " + projectID + ", returning " + listImages.size() + " image/s"); return listImages; @@ -1068,7 +1071,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); UseCaseDescriptor ucd = GeoportalClientCaller.useCaseDescriptors().getUCDForId(profileID); Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); - + ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); projectBuilder.relationships(true); ProjectDV theProjectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder); @@ -1137,10 +1140,11 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme String projectID = productIDs.get(0); layerObject.setProjectID(projectID); String profileID = layerObject.getProfileID(); + List images; // Loading images for profileID and projectID try { - images = getImagesForId(profileID, projectID); + images = getImagesForId(profileID, projectID, true); Map> mapImages = new LinkedHashMap>(); mapImages.put(projectID, images); @@ -1150,6 +1154,32 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme LOG.warn("Error on loading images for projectID: " + projectID + " profileID: " + profileID); } + + // Sets only profileID and profileName into ProjectDV + if (layerObject.getProjectDV() == null) { + + QueryRequest request = new QueryRequest(); + request.setFilter(Document.parse( + "{\"" + UseCaseDescriptor.ID + "\" : " + "{\"$eq\" : \"" + profileID + "\"}}")); + request.setProjection(Document.parse("{\"" + UseCaseDescriptor.NAME + "\" : " + "1}")); + + try { + useCaseDescriptors().build().query(request).forEachRemaining(u -> { + try { + LOG.debug("UCD for id" + u.getId() + " returend name: " + u.getName()); + ProjectDV projectDV = new ProjectDV(); + projectDV.setId(projectID); + projectDV.setProfileName(u.getName()); + projectDV.setProfileID(u.getId()); + layerObject.setProjectDV(projectDV); + } catch (Exception e) { + LOG.warn("Invalid UCD, UCID : " + u.getId()); + } + }); + } catch (Exception e) { + // silent + } + } } } @@ -1160,35 +1190,56 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme break; } + case PROJECT_LAYER: case GENERIC_LAYER: { - LOG.debug("The LayerObject is a of kind: "+layerObject.getType()); - // Getting the projectid from WFS features, but limiting to the first one - for (FeatureRow fRow : features) { - if (fRow.getMapProperties() != null) { - List productIDs = fRow.getMapProperties().get("projectid"); - if (productIDs != null && productIDs.size() > 0) { - String projectID = productIDs.get(0); - layerObject.setProjectID(projectID); - String profileID = layerObject.getProfileID(); - try { - Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, - projectID); - ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder() - .fullDocumentMap(false); - ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, - projectBuilder); - geoDAO.setProjectDV(projectDV); - layerObject.setProjectDV(projectDV); - // Limiting to 1 feature of Layers - continue; - } catch (Exception e) { - LOG.warn("Error on loading the Project for projectID: " + projectID + " profileID: " - + profileID); - } - } + LOG.debug("The LayerObject is a of kind: " + layerObject.getType()); + // TODO CHECK THIS + // Getting the projectid from WFS features, but limiting to the first one, Do we + // have more than one centroid in the same position?? + + if (layerObject.getProjectDV() == null) { + + Project theProject; + try { + theProject = GeoportalClientCaller.projects().getProjectByID(layerObject.getProfileID(), + layerObject.getProjectID()); + + ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(false); + ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder); + layerObject.setProjectDV(projectDV); + } catch (Exception e) { + String erroMsg = "Error occurred on loading project for profileID "+layerObject.getProfileID()+" and projectID "+layerObject.getProjectID(); + LOG.warn(erroMsg, e); } + } + +// for (FeatureRow fRow : features) { +// if (fRow.getMapProperties() != null) { +// List productIDs = fRow.getMapProperties().get("projectid"); +// if (productIDs != null && productIDs.size() > 0) { +// String projectID = productIDs.get(0); +// layerObject.setProjectID(projectID); +// String profileID = layerObject.getProfileID(); +// try { +// Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, +// projectID); +// ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder() +// .fullDocumentMap(false); +// ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, +// projectBuilder); +// // geoDAO.setProjectDV(projectDV); +// layerObject.setProjectDV(projectDV); +// // Limiting to 1 feature of Layers +// continue; +// } catch (Exception e) { +// LOG.warn("Error on loading the Project for projectID: " + projectID + " profileID: " +// + profileID); +// } +// } +// } +// } geoDAO.setSourceLayerObject(layerObject); LOG.info("For layer name: " + layerObject.getLayerItem().getName() + " got " + features.size() + " feature/s"); 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 b9ed375..a4dd768 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 @@ -37,6 +37,13 @@ import com.google.gson.JsonParser; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider; +/** + * The Class Geoportal_JSON_Mapper. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 24, 2022 + */ public class Geoportal_JSON_Mapper { public static final String _PAYLOADS = "_payloads"; @@ -57,6 +64,15 @@ public class Geoportal_JSON_Mapper { public static final String _THEDOCUMENT = "_theDocument"; + /** + * Load project view. + * + * @param theProjectDV the the project DV + * @param scope the scope + * @param username the username + * @return the project view + * @throws Exception the exception + */ public static ProjectView loadProjectView(ProjectDV theProjectDV, String scope, String username) throws Exception { String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON(); @@ -309,11 +325,13 @@ public class Geoportal_JSON_Mapper { /** * Read images for fileset. * - * @param parentJSONPath the parent JSON path - * @param sectionJSONDocument the section JSON document + * @param parentJSONPath the parent JSON path + * @param sectionJSONDocument the section JSON document + * @param limitToFirstOneFound the limit to first one found * @return the list */ - public static List readImagesForFileset(String parentJSONPath, String sectionJSONDocument) { + public static List readImagesForFileset(String parentJSONPath, String sectionJSONDocument, + boolean limitToFirstOneFound) { LOG.debug("readImagesForFileset called"); List listImages = new ArrayList(); @@ -332,14 +350,23 @@ public class Geoportal_JSON_Mapper { if (isImage) { PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); listImages.add(payloadDV); + if (limitToFirstOneFound && listImages.size() == 1) + return listImages; } } - LOG.debug("readImagesForFileset returning listOfImages: "+listImages); + LOG.debug("readImagesForFileset returning listOfImages: " + listImages); return listImages; } + /** + * Read gcube SDI layers for fileset. + * + * @param materializationParentJSONPath the materialization parent JSON path + * @param sectionJSONDocument the section JSON document + * @return the list + */ public static List readGcubeSDILayersForFileset(String materializationParentJSONPath, String sectionJSONDocument) { LOG.debug("readGcubeSDILayersForFileset called"); @@ -368,6 +395,14 @@ public class Geoportal_JSON_Mapper { } + /** + * Recursive fetching layers. + * + * @param config the config + * @param objectJSON the object JSON + * @param listSDILayers the list SDI layers + * @return the list + */ private static List recursiveFetchingLayers(com.jayway.jsonpath.Configuration config, Object objectJSON, List listSDILayers) { @@ -392,10 +427,11 @@ public class Geoportal_JSON_Mapper { } /** - * Read payloads for fileset. + * Recursive fetching payloads. * - * @param filesetJSONPath the fileset JSON path - * @param sectionJSONDocument the section JSON document + * @param config the config + * @param objectJSON the object JSON + * @param payloads the payloads * @return the list */ public static List recursiveFetchingPayloads(com.jayway.jsonpath.Configuration config, Object objectJSON, @@ -410,7 +446,7 @@ public class Geoportal_JSON_Mapper { LOG.trace("jsonArray: " + theJsonArray.toString(3)); for (int i = 0; i < theJsonArray.length(); i++) { - recursiveFetchingPayloads(config, theJsonArray.get(i), payloads); + payloads = recursiveFetchingPayloads(config, theJsonArray.get(i), payloads); } } else if (objectJSON instanceof JSONObject) { JSONObject toStringPayloads = (JSONObject) objectJSON; @@ -420,8 +456,8 @@ public class Geoportal_JSON_Mapper { payload = Serialization.read(toStringPayloads.toString(), Payload.class); payloads.add(payload); } catch (Exception e) { - LOG.warn("Error on converting the JSON Boject " + toStringPayloads + "as " + Payload.class.getSimpleName() - + e.getMessage()); + LOG.warn("Error on converting the JSON Boject " + toStringPayloads + "as " + + Payload.class.getSimpleName() + e.getMessage()); } } @@ -430,6 +466,13 @@ public class Geoportal_JSON_Mapper { } + /** + * Conver layer. + * + * @param config the config + * @param thJsonObject the th json object + * @return the g cube SDI viewer layer DV + */ // TODO THIS PART SHOULD BE REVISITED/OPTIMIZED private static GCubeSDIViewerLayerDV converLayer(com.jayway.jsonpath.Configuration config, JSONObject thJsonObject) { @@ -576,6 +619,11 @@ public class Geoportal_JSON_Mapper { return gson.toJson(jsonObject); } + /** + * Pretty print project view. + * + * @param projectView the project view + */ public static void prettyPrintProjectView(ProjectView projectView) { for (SectionView section : projectView.getListSections()) { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaSpatialQueryResult.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaSpatialQueryResult.java index 211c8c9..afa2d4c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaSpatialQueryResult.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/GeoNaSpatialQueryResult.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV; -import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject; import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow; @@ -27,7 +26,7 @@ public class GeoNaSpatialQueryResult implements Serializable { // Map with couple (mongoId concessione, list of uploaded GNAImages for the // concessione) private Map> mapImages = null; - private ProjectDV projectDV; +// private ProjectDV projectDV; /** * Instantiates a new geo na data object. @@ -36,14 +35,14 @@ public class GeoNaSpatialQueryResult implements Serializable { } - public void setProjectDV(ProjectDV projectDV) { - this.projectDV = projectDV; - - } - - public ProjectDV getProjectDV() { - return projectDV; - } +// public void setProjectDV(ProjectDV projectDV) { +// this.projectDV = projectDV; +// +// } +// +// public ProjectDV getProjectDV() { +// return projectDV; +// } /** * Gets the features. @@ -108,8 +107,6 @@ public class GeoNaSpatialQueryResult implements Serializable { builder.append(sourceLayerObject); builder.append(", mapImages="); builder.append(mapImages); - builder.append(", projectDV="); - builder.append(projectDV); builder.append("]"); return builder.toString(); } diff --git a/src/main/webapp/GeoportalDataViewer.css b/src/main/webapp/GeoportalDataViewer.css index eec2336..ed8b4d9 100644 --- a/src/main/webapp/GeoportalDataViewer.css +++ b/src/main/webapp/GeoportalDataViewer.css @@ -454,8 +454,9 @@ body { /*******************************************/ .search-facility { - width: 600px; + width: 750px; max-height: 700px; + max-width: 850px; } .search-textbox { 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 ca3e6e6..c9db6ea 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,8 +1,13 @@ package org.gcube.portlets.user.geoportaldataviewer; +import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors; + import java.util.List; +import org.bson.Document; 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.geoportalcommon.ConvertToDataValueObjectModel; import org.gcube.application.geoportalcommon.ProjectDVBuilder; import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller; @@ -120,9 +125,10 @@ public class GeoportalViewer_Tests { Project project = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID); String jsonDocument = project.getTheDocument().toJson(); System.out.println("JSON Project is: " + jsonDocument); - - String filesetJSONPath = String.format("%s..%s", Geoportal_JSON_Mapper.JSON_$_POINTER, Geoportal_JSON_Mapper.FILESET); - listImages = Geoportal_JSON_Mapper.readImagesForFileset(filesetJSONPath, jsonDocument); + + String filesetJSONPath = String.format("%s..%s", Geoportal_JSON_Mapper.JSON_$_POINTER, + Geoportal_JSON_Mapper.FILESET); + listImages = Geoportal_JSON_Mapper.readImagesForFileset(filesetJSONPath, jsonDocument, true); listImages.stream().forEach(s -> System.out.println("Image: " + s)); @@ -133,5 +139,31 @@ public class GeoportalViewer_Tests { } } + + //@Test + public void testUCDQuery() { + QueryRequest request = new QueryRequest(); + request.setFilter( + Document.parse("{\"" + UseCaseDescriptor.ID + "\" : " + "{\"$eq\" : \"" + PROFILE_ID + "\"}}")); + request.setProjection(Document.parse("{\"" + UseCaseDescriptor.NAME + "\" : " + "1}")); + + try { + useCaseDescriptors().build().query(request).forEachRemaining(u -> { + try { + System.out.println("UCD for id" + u.getId() + " returend name: " + u.getName()); + ProjectDV projectDV = new ProjectDV(); + projectDV.setId(PROJECT_ID); + projectDV.setProfileName(u.getName()); + projectDV.setProfileID(u.getId()); + System.out.println(projectDV); + } catch (Exception e) { + System.out.println("Invalid UCD, UCID : " + u.getId()); + e.printStackTrace(); + } + }); + } catch (Exception e) { + // silent + } + } }