diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 3bca87b..639f519 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,9 @@ - + + + + + @@ -34,7 +38,11 @@ - + + + + + @@ -69,7 +77,11 @@ - + + + + + @@ -104,7 +116,11 @@ - + + + + + @@ -139,7 +155,11 @@ - + + + + + @@ -174,7 +194,11 @@ - + + + + + @@ -209,7 +233,14 @@ - + + uses + + + + + + @@ -244,7 +275,11 @@ - + + + + + @@ -279,7 +314,11 @@ - + + + + + @@ -314,7 +353,11 @@ - + + + + + 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 6b067a2..fe5948a 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 @@ -6,7 +6,6 @@ import java.util.Set; 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.geojson.GeoJSON; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.RelationshipDV; @@ -71,12 +70,13 @@ import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import ol.Coordinate; -import ol.layer.Image; /** * Entry point classes define onModuleLoad(). @@ -163,8 +163,9 @@ public class GeoportalDataViewer implements EntryPoint { @Override public void onFailure(Throwable caught) { - // TODO Auto-generated method stub - + RootPanel.get(APP_DIV).remove(loaderApp); + Window.alert(caught.getMessage()); + RootPanel.get(APP_DIV).add(getGeneralErrorPanel()); } @Override @@ -193,7 +194,9 @@ public class GeoportalDataViewer implements EntryPoint { @Override public void onFailure(Throwable caught) { + RootPanel.get(APP_DIV).remove(loaderApp); Window.alert(caught.getMessage()); + RootPanel.get(APP_DIV).add(getGeneralErrorPanel()); } @Override @@ -615,7 +618,7 @@ public class GeoportalDataViewer implements EntryPoint { public void onShowPopup(ShowPopupOnCentroiEvent showPopupOnCentroiEvent) { if (showPopupOnCentroiEvent.getProfileID() != null && showPopupOnCentroiEvent.getProjectID() != null) { - GWT.log("ShowPopupOnCentroiEvent: "+showPopupOnCentroiEvent); + GWT.log("ShowPopupOnCentroiEvent: " + showPopupOnCentroiEvent); Coordinate transfCoord = MapUtils .geoJSONTToBBoxCenter(showPopupOnCentroiEvent.getSpatialReference(), null, null); @@ -633,14 +636,14 @@ public class GeoportalDataViewer implements EntryPoint { if (searchPerformedEvent != null) { - LinkedHashMap wmsMap = olMapMng.getOLMap().getWmsLayerMap(); + LinkedHashMap wmsMap = olMapMng.getOLMap().getWmsLayerMap(); String firstWMSKey = wmsMap.keySet().iterator().next(); - List result = searchPerformedEvent.getData(); + List result = searchPerformedEvent.getListProjectIDs(); if (result != null && result.size() > 0) { String cqlFilter = GeoportalDataViewerConstants.PROJECT_ID_KEY_FEATURE + " IN("; - for (DocumentDV documentDV : result) { - cqlFilter += "'" + documentDV.getProjectID() + "',"; + for (String projectId : result) { + cqlFilter += "'" + projectId + "',"; } cqlFilter = cqlFilter.substring(0, cqlFilter.length() - 1) + ")"; @@ -722,4 +725,16 @@ public class GeoportalDataViewer implements EntryPoint { timer.schedule(3000); } + private FlowPanel getGeneralErrorPanel() { + Image geoportalError = new Image(GNAImages.ICONS.geoportaServiceError()); + FlowPanel errorPanelMsg = new FlowPanel(); + errorPanelMsg.getElement().addClassName("general_error"); + errorPanelMsg.add(geoportalError); + errorPanelMsg.add(new HTML("D4S GeoPortal")); + HTML erroMessage = new HTML( + "Oops something went wrong, please refresh and try again. Feel free to contact us if the problem persists"); + errorPanelMsg.add(erroMessage); + return errorPanelMsg; + } + } 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 15e0752..7c1e751 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 @@ -5,7 +5,6 @@ import java.util.List; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; -import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; @@ -13,6 +12,7 @@ import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult; import org.gcube.portlets.user.geoportaldataviewer.shared.ItemFieldsResponse; +import org.gcube.portlets.user.geoportaldataviewer.shared.ResultSetPaginatedDataIDs; 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; @@ -138,7 +138,7 @@ public interface GeoportalDataViewerService extends RemoteService { * @return the list projects * @throws Exception the exception */ - ResultSetPaginatedData getListProjects(String theProfileID, Integer start, Integer limit, SearchingFilter filter, + ResultSetPaginatedDataIDs getListProjects(String theProfileID, Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService) 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 080e2ef..5e31f69 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 @@ -5,7 +5,6 @@ import java.util.List; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; -import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; @@ -13,6 +12,7 @@ import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportalcommon.shared.gis.BoundsMap; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult; import org.gcube.portlets.user.geoportaldataviewer.shared.ItemFieldsResponse; +import org.gcube.portlets.user.geoportaldataviewer.shared.ResultSetPaginatedDataIDs; 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; @@ -64,7 +64,7 @@ public interface GeoportalDataViewerServiceAsync { void getProjectViewForId(String profileID, String projectID, AsyncCallback callback); void getListProjects(String theProfileID, Integer start, Integer limit, SearchingFilter filter, - boolean reloadFromService, AsyncCallback callback); + boolean reloadFromService, AsyncCallback callback); void getInitialConfiguration(AsyncCallback callback); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/SearchPerformedEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/SearchPerformedEvent.java index 15b1eff..3010480 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/SearchPerformedEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/events/SearchPerformedEvent.java @@ -2,8 +2,6 @@ package org.gcube.portlets.user.geoportaldataviewer.client.events; import java.util.List; -import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; - import com.google.gwt.event.shared.GwtEvent; /** @@ -15,17 +13,17 @@ import com.google.gwt.event.shared.GwtEvent; */ public class SearchPerformedEvent extends GwtEvent { public static Type TYPE = new Type(); - private List data; + private List listProjectIDs; private boolean searchReset; /** * Instantiates a new search performed event. * - * @param data the data - * @param searchReset the search reset + * @param listProjectIds the list project ids + * @param searchReset the search reset */ - public SearchPerformedEvent(List data, boolean searchReset) { - this.data = data; + public SearchPerformedEvent(List listProjectIds, boolean searchReset) { + this.listProjectIDs = listProjectIds; this.searchReset = searchReset; } @@ -51,12 +49,12 @@ public class SearchPerformedEvent extends GwtEvent } /** - * Gets the data. + * Gets the list project Ids. * - * @return the data + * @return the list project Ids */ - public List getData() { - return data; + public List getListProjectIDs() { + return listProjectIDs; } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/GNAImages.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/GNAImages.java index 30bbdaa..961ab67 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/GNAImages.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/GNAImages.java @@ -52,5 +52,8 @@ public interface GNAImages extends ClientBundle { @Source("spinner_clock.gif") ImageResource spinnerClock(); + + @Source("geoporta_error.png") + ImageResource geoportaServiceError(); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/geoporta_error.png b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/geoporta_error.png new file mode 100644 index 0000000..1ee4353 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/resources/geoporta_error.png differ 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 dca2ec5..fe073dd 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 @@ -16,11 +16,13 @@ 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.ClosedViewDetailsEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.SearchPerformedEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent; import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowPopupOnCentroiEvent; import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon; import org.gcube.portlets.user.geoportaldataviewer.client.util.StringUtil; +import org.gcube.portlets.user.geoportaldataviewer.shared.ResultSetPaginatedDataIDs; import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Button; @@ -59,6 +61,8 @@ import com.google.gwt.user.client.ui.Widget; */ public class SearchFacilityUI extends Composite { + private static final int SEARCHING_LIMIT_RESULTS_TO = 50; + private static SearchFacilityPanelUiBinder uiBinder = GWT.create(SearchFacilityPanelUiBinder.class); protected static final int MIN_LENGHT_SERCHING_STRING = 3; @@ -140,7 +144,7 @@ public class SearchFacilityUI extends Composite { resetSearch.setType(ButtonType.LINK); listBoxSortBy.setWidth("180px"); - listBoxSearchFor.setWidth("140px"); + // listBoxSearchFor.setWidth("140px"); bindEvents(); } @@ -264,8 +268,8 @@ public class SearchFacilityUI extends Composite { panelResults.clear(); panelResults.add(new HTML("
")); panelResults.add(new LoaderIcon("Searching...")); - GeoportalDataViewerServiceAsync.Util.getInstance().getListProjects(profileID, 0, 30, filter, false, - new AsyncCallback() { + GeoportalDataViewerServiceAsync.Util.getInstance().getListProjects(profileID, 0, SEARCHING_LIMIT_RESULTS_TO, + filter, false, new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -280,9 +284,9 @@ public class SearchFacilityUI extends Composite { } @Override - public void onSuccess(ResultSetPaginatedData result) { + public void onSuccess(ResultSetPaginatedDataIDs result) { - appManagerBus.fireEvent(new SearchPerformedEvent(result.getData(), false)); + appManagerBus.fireEvent(new SearchPerformedEvent(result.getResultSetProjectIDs(), false)); setSearchEnabled(true); latestResult = result; @@ -295,6 +299,23 @@ public class SearchFacilityUI extends Composite { return; } + int allItems = result.getResultSetProjectIDs().size(); + int returnedItems = result.getData().size(); + + String message = ""; + if (allItems > returnedItems) { + message = "Too many results found. Below are " + returnedItems + " out of " + allItems + + " results. Projects (with a centroid) matching your search are shown on the Map"; + } else { + message = "Found " + returnedItems; + message += returnedItems > 0 ? " items" : " item"; + } + + HTML resultMessage = new HTML(message); + resultMessage.getElement().addClassName("search_result_msg"); + + panelResults.add(resultMessage); + FlexTable ft = new FlexTable(); ft.getElement().setClassName("table-results"); int i = 0; @@ -327,9 +348,11 @@ public class SearchFacilityUI extends Composite { public void onClick(ClickEvent event) { GeoportalItemReferences gir = new GeoportalItemReferences(resultDoc.getProjectID(), profileID); + //here + appManagerBus.fireEvent(new ClosedViewDetailsEvent()); appManagerBus.fireEvent(new ShowDetailsEvent(gir, null, true)); - appManagerBus - .fireEvent(new ShowPopupOnCentroiEvent(profileID, resultDoc.getProjectID(), resultDoc.getSpatialReference())); + appManagerBus.fireEvent(new ShowPopupOnCentroiEvent(profileID, + resultDoc.getProjectID(), resultDoc.getSpatialReference())); } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.ui.xml index c69f3ab..af66366 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/cms/search/SearchFacilityUI.ui.xml @@ -20,6 +20,10 @@ margin-right: 23px; } + .listBoxSearchForStyle { + margin-right: 5px; + } + .margin-top-5 { margin-top: 5px; } @@ -35,7 +39,7 @@ Search for: + addStyleNames="{style.listBoxSearchForStyle}"> 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 ea86346..4590bd0 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 @@ -12,6 +12,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -34,7 +37,6 @@ import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller; import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences; -import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; @@ -64,6 +66,7 @@ import org.gcube.portlets.user.geoportaldataviewer.server.util.TemporalComparato import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection; import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult; import org.gcube.portlets.user.geoportaldataviewer.shared.ItemFieldsResponse; +import org.gcube.portlets.user.geoportaldataviewer.shared.ResultSetPaginatedDataIDs; 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; @@ -516,7 +519,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme listUseCaseDescriptor = client.getListForHandlerIds(handlersIds); } catch (Exception e) { LOG.error("Error on reading handlerIds: " + handlersIds + ", in the UCDs", e); - return null; + throw e; } if (listUseCaseDescriptor == null) { @@ -627,7 +630,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme * @throws Exception the exception */ @Override - public ResultSetPaginatedData getListProjects(String theProfileID, Integer start, Integer limit, + public ResultSetPaginatedDataIDs getListProjects(String theProfileID, Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService) throws Exception { LOG.info("getListProjects called with profileID: " + theProfileID + ", start: " + start + ", limit: " + limit + ", filter: " + filter); @@ -637,6 +640,16 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme ProjectsCaller client = GeoportalClientCaller.projects(); SessionUtil.getCurrentContext(getThreadLocalRequest(), true); + // Saving client PROJECTION + LinkedHashMap originalProjection = filter.getProjection(); + + // Setting PROJECTION ONLY FOR PROEJCT ID + LinkedHashMap projectionForIDs = new LinkedHashMap(); + projectionForIDs.put(Project.ID, 1); + filter.setProjection(projectionForIDs); + + ResultSetPaginatedDataIDs searchedDataIDs = new ResultSetPaginatedDataIDs(); + Integer totalProjectForProfile = SessionUtil.getTotalDocumentForProfileID(getThreadLocalRequest(), theProfileID); @@ -645,45 +658,65 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme SessionUtil.setTotalDocumentForProfileID(getThreadLocalRequest(), theProfileID, totalProjectForProfile); } + searchedDataIDs.setTotalItems(totalProjectForProfile); LOG.info("Total Docs read from config: " + totalProjectForProfile); - Iterator projects = client.queryOnMongo(theProfileID, totalProjectForProfile, start, limit, + // FIRST QUERY TO RETRIEVE IDs + // LIMIT IS NULL MEANS THAT IT IS EQUAL TO NUMBER TOTAL OF DOCUMENTS + final Iterator projectsIDs = client.queryOnMongo(theProfileID, totalProjectForProfile, start, null, filter); - ResultSetPaginatedData searchedData = new ResultSetPaginatedData(start, limit, false); - searchedData.setTotalItems(totalProjectForProfile); + //Getting the Project IDs from the Iterable + Iterable itP = () -> projectsIDs; + Stream targetStream = StreamSupport.stream(itP.spliterator(), false); + List listProjectIDs = targetStream.map(Project::getId).collect(Collectors.toList()); + searchedDataIDs.setResultSetProjectIDs(listProjectIDs); + //Total number of Projects are exactly listProjectIDs.size() + int totalItems = listProjectIDs.size(); + searchedDataIDs.setTotalItems(totalItems); + + //NOW PERFORMING THE (REAL) SECOND QUERY FROM CLIENT + // SETTING ORIGINAL PROJECTION FROM CLIENT + filter.setProjection(originalProjection); + // LIMIT IS FROM CLIENT + Iterator projects = client.queryOnMongo(theProfileID, totalItems, start, limit, + filter); + + searchedDataIDs.setClientStartIndex(start); + searchedDataIDs.setLimit(limit); + searchedDataIDs.setServerSearchFinished(false); List toReturnList = ConvertToDataValueObjectModel.toListResultDocument(projects); - - searchedData.setData(toReturnList); + searchedDataIDs.setData(toReturnList); // TODO BUGGY WORKAROUND. BLOCKED BY #22487 IT MUST BE REMOVE AFTER THE QUERY // COUNT // AND LIST.SIZE BY QUERY WILL BE AVAILABLE IN THE SERVICE - if (filter.getConditions() != null) { - searchedData.setTotalItems(toReturnList.size()); - int totalItems = toReturnList.size(); - searchedData.setTotalItems(totalItems); - } +// if (filter.getConditions() != null) { +// searchedDataIDs.setTotalItems(toReturnList.size()); +// int totalItems = searchedDataIDs.getResultSetProjectIDs().size(); +// searchedDataIDs.setTotalItems(totalItems); +// } if (totalProjectForProfile == limit || totalProjectForProfile == 0) { LOG.debug("Page completed returning " + totalProjectForProfile + " projects"); int newOffset = start + limit; - searchedData.setServerSearchFinished(newOffset > totalProjectForProfile || totalProjectForProfile == 0); - LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); + searchedDataIDs + .setServerSearchFinished(newOffset > totalProjectForProfile || totalProjectForProfile == 0); + LOG.debug("is Search finished: " + searchedDataIDs.isServerSearchFinished()); } if (LOG.isDebugEnabled()) { - LOG.debug("returning {}", searchedData.getData()); + LOG.debug("returning {}", searchedDataIDs.getData()); } - List data = searchedData.getData(); + List data = searchedDataIDs.getData(); if (data != null) { LOG.info("returning {} project/s", data.size()); } - return searchedData; + return searchedDataIDs; } catch (Exception e) { LOG.error("Error on loading paginated and filtered list of projects for id: ", e); 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 5c7f10c..b283dc9 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 @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.function.Function; import org.bson.Document; import org.gcube.application.geoportal.client.utils.Serialization; @@ -67,7 +68,7 @@ public class Geoportal_JSON_Mapper { public static final String JSON_$_POINTER = "$"; public static final String _THEDOCUMENT = "_theDocument"; - + public static ProjectEdit loadProjectEdit(ProjectDV theProjectDV, String scope, String username) throws Exception { String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON(); @@ -112,14 +113,18 @@ public class Geoportal_JSON_Mapper { com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() .jsonProvider(new JsonOrgJsonProvider()).build(); - List listProfileBeansExt = new ArrayList(); + //LinkedHashMap mapOfProfilesBeanExt = new LinkedHashMap(); + + ArrayList listOfProfilesBeanExt = new ArrayList(); // 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()); +// SectionView sectionView = new SectionView(); +// sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle()); + + System.out.println("\n\n##### Sto creando la sezione: "+gcubeProfileDV.getSectionTitle()); LOG.debug("\n\nThe profile is: " + gcubeProfileDV); // Building JSON/section full PATH and section name String sectionJSONPath = ""; @@ -174,17 +179,31 @@ public class Geoportal_JSON_Mapper { List theProfileBeans = gcubeProfileMetaForUCD.getListMetadataProfileBean(); MetaDataProfileBean theProfileBean = theProfileBeans.get(0); - //Creating the corresponding MetaDataProfileBeanExt - MetaDataProfileBeanExt theProfileBeanExt = new MetaDataProfileBeanExt(); - theProfileBeanExt.setCategories(theProfileBean.getCategories()); - theProfileBeanExt.setTitle(theProfileBean.getTitle()); - theProfileBeanExt.setType(theProfileBean.getType()); // For each bson.Document filling the MetaDataProfileBean and its file for (int i = 0; i < listBSONDocument.size(); i++) { + + System.out.println("DOCUMENT number "+i+ " of the section: "+theProfileBean.getTitle()); + MetaDataProfileBeanExt theProfileBeanExt = new MetaDataProfileBeanExt(); + theProfileBeanExt.setCategories(theProfileBean.getCategories()); + theProfileBeanExt.setTitle(theProfileBean.getTitle()); + theProfileBeanExt.setType(theProfileBean.getType()); + +// System.out.println("\nPRINTING PROJECT VIEW ON START: "); +// for (int j = 0; j < listOfProfilesBeanExt.size(); j++) { +// MetaDataProfileBeanExt metaDataProfileBeanExt = listOfProfilesBeanExt.get(j); +// System.out.println("MetaDataProfileBeanExt index: " + j + " "+metaDataProfileBeanExt.getType() +" "+metaDataProfileBeanExt.hashCode()); +// int z = 0; +// for (MetadataFieldWrapper mfw : metaDataProfileBeanExt.getMetadataFields()) { +// System.out.println("\t MetadataFieldWrapper index: " + z++ + " " + mfw); +// } +// } + + Document fromSectionDoc = listBSONDocument.get(i); - - + LOG.debug("\n\nNew section DOC for index " + i + " is: " + new JSONObject(fromSectionDoc.toJson()).toString(2)); + //Creating the corresponding MetaDataProfileBeanExt for each section + //Reading policy and license statically //eg. "_access":{"_policy":"OPEN","_license":"CC0-1.0"}} Document docAccess = null; @@ -202,12 +221,12 @@ public class Geoportal_JSON_Mapper { e.printStackTrace(); } - -// SubDocumentView subDocumentView = new SubDocumentView(); -// Document toSectionDoc = new Document(); - // Filling the MetadataFieldWrapper metadata with the - // metadataField.getFieldName() as currentValue - for (MetadataFieldWrapper metadataField : theProfileBean.getMetadataFields()) { + //List copyOfMetadataFields = new ArrayList(theProfileBean.getMetadataFields()); + //int forIndex = 0; + + List cloneListOfMFW = cloneList(theProfileBean.getMetadataFields()); + + for (MetadataFieldWrapper metadataField : cloneListOfMFW) { String theFieldName = metadataField.getFieldId() != null ? metadataField.getFieldId() : metadataField.getFieldName(); @@ -222,13 +241,17 @@ public class Geoportal_JSON_Mapper { metadataField.setCurrentValue(access.getLicense()); } } - + //copyOfMetadataFields.set(forIndex++, metadataField); } - theProfileBeanExt.setMetadataFields(theProfileBean.getMetadataFields()); + LOG.debug("Before assigning it Metadata fields are: "+cloneListOfMFW); + + theProfileBeanExt.setMetadataFields(new ArrayList(cloneListOfMFW)); + LOG.debug("Metadata fields are: "+theProfileBeanExt.getMetadataFields()); // Reading filePaths List filePaths = gcubeProfileDV.getFilePaths(); + List listLayers = new ArrayList(); // READING fileset* field ACCORDING TO filePaths OF THE 'gcubeProfiles' CONFIG if (filePaths != null) { @@ -249,24 +272,73 @@ public class Geoportal_JSON_Mapper { } // Reading Fileset _materializations - // listLayers = readGcubeSDILayersForFileset(filesetJSONPath, - // fromSectionDocJSON); + //listLayers = readGcubeSDILayersForFileset(filesetJSONPath, fromSectionDocJSON); + //theProfileBeanExt.set } theProfileBeanExt.setListFileset(listFiles); } - - listProfileBeansExt.add(theProfileBeanExt); + + System.out.println("\nputting theProfileBeanExt: "+theProfileBeanExt); + listOfProfilesBeanExt.add(theProfileBeanExt); + +// System.out.println("\nPRINTING PROJECT VIEW ON END: "); +// for (int j = 0; j < listOfProfilesBeanExt.size(); j++) { +// MetaDataProfileBeanExt metaDataProfileBeanExt = listOfProfilesBeanExt.get(j); +// System.out.println("MetaDataProfileBeanExt index: " + j + " "+metaDataProfileBeanExt.getType() +" "+metaDataProfileBeanExt.hashCode()); +// int z = 0; +// for (MetadataFieldWrapper mfw : metaDataProfileBeanExt.getMetadataFields()) { +// System.out.println("\t MetadataFieldWrapper index: " + z++ + " " + mfw); +// } +// } +// +// System.out.println(listProfileBeansExt.get(listProfileBeansExt.size()-1)); + //Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView); } } - projectView.setTheProfileBeans(listProfileBeansExt); + projectView.setTheProfileBeans(listOfProfilesBeanExt); + //Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView); + return projectView; } + public static List cloneList(List list) { + List listCloned = new ArrayList(list.size()); + + Function cloneWrapper = (mfw) -> { + + MetadataFieldWrapper newMfw = new MetadataFieldWrapper(); + newMfw.setAsGroup(mfw.getAsGroup()); + newMfw.setAsTag(mfw.getAsTag()); + newMfw.setCurrentValue(mfw.getCurrentValue()); + newMfw.setDefaultValue(mfw.getDefaultValue()); + newMfw.setFieldId(mfw.getFieldId()); + newMfw.setFieldName(mfw.getFieldName()); + newMfw.setFieldNameFromCategory(mfw.getFieldNameFromCategory()); + newMfw.setMandatory(mfw.getMandatory()); + newMfw.setMaxOccurs(mfw.getMaxOccurs()); + newMfw.setMultiSelection(mfw.isMultiSelection()); + newMfw.setNote(mfw.getNote()); + newMfw.setOwnerCategory(mfw.getOwnerCategory()); + newMfw.setType(mfw.getType()); + newMfw.setValidator(mfw.getValidator()); + newMfw.setVocabulary(mfw.getVocabulary()); + + return newMfw; + + }; + + for (MetadataFieldWrapper item : list) { + MetadataFieldWrapper cloned = cloneWrapper.apply(item); + listCloned.add(cloned); + } + return listCloned; + } + /** * Load project view. * @@ -879,11 +951,12 @@ public class Geoportal_JSON_Mapper { for (MetaDataProfileBeanExt mpb : projectEdit.getTheProfileBeans()) { System.out.println("\n\n###### Title: " + mpb.getTitle() + " - Type: " + mpb.getType() + " ######"); int i = 1; - for (MetadataFieldWrapper mfw : mpb.getMetadataFields()) { + for (MetadataFieldWrapper fieldWrapper : mpb.getMetadataFields()) { System.out.println("## " + MetadataFieldWrapper.class.getSimpleName() + " n." + i); System.out.println("***** Metadata"); - //System.out.println(mfw); - System.out.println("\tfieldId: " + mfw.getFieldId() +", fieldName: "+mfw.getFieldName() +", CurrentValue: "+mfw.getCurrentValue()); + // System.out.println(mfw); + System.out.println("\tfieldId: " + fieldWrapper.getFieldId() + ", fieldName: " + + fieldWrapper.getFieldName() + ", CurrentValue: " + fieldWrapper.getCurrentValue()); i++; } i = 1; @@ -891,6 +964,7 @@ public class Geoportal_JSON_Mapper { for (FilesetDV fileSet : mpb.getListFileset()) { System.out.println("## " + FilesetDV.class.getSimpleName() + " n." + i); System.out.println(fileSet); + i++; } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/MetaDataProfileBeanExt.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/MetaDataProfileBeanExt.java index a73cac9..abe93b4 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/MetaDataProfileBeanExt.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/MetaDataProfileBeanExt.java @@ -4,42 +4,126 @@ import java.util.ArrayList; import java.util.List; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.FilesetDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.CategoryWrapper; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; -public class MetaDataProfileBeanExt extends MetaDataProfileBean { +/** + * The Class MetaDataProfileBeanExt. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 23, 2022 + */ +public class MetaDataProfileBeanExt extends MetaDataProfileBean implements Cloneable { - private List listFileset = null; /** * */ - private static final long serialVersionUID = -7201955007623188104L; + private static final long serialVersionUID = 2518128223147908835L; + private List listFileset = null; + /** + * Instantiates a new meta data profile bean ext. + */ public MetaDataProfileBeanExt() { super(); } + /** + * Instantiates a new meta data profile bean ext. + * + * @param type the type + * @param title the title + * @param metadataFields the metadata fields + * @param categories the categories + */ public MetaDataProfileBeanExt(String type, String title, List metadataFields, List categories) { super(type, title, metadataFields, categories); } + /** + * Gets the list fileset. + * + * @return the list fileset + */ public List getListFileset() { - if(listFileset==null) + if (listFileset == null) listFileset = new ArrayList(); return listFileset; } - + + /** + * Sets the list fileset. + * + * @param listFileset the new list fileset + */ public void setListFileset(List listFileset) { this.listFileset = listFileset; } + @Override + protected MetaDataProfileBeanExt clone() throws CloneNotSupportedException { + + MetaDataProfileBeanExt clonedMDPBE = new MetaDataProfileBeanExt(); + clonedMDPBE.setTitle(this.getTitle()); + clonedMDPBE.setType(this.getType()); + ArrayList newListFileset = new ArrayList(); + for (FilesetDV filesetDV : this.getListFileset()) { + FilesetDV newFileset = new FilesetDV(); + for (PayloadDV payloadDV : filesetDV.getListPayload()) { + PayloadDV newPayloadDV = new PayloadDV(); + newPayloadDV.setLink(payloadDV.getLink()); + newPayloadDV.setMimetype(payloadDV.getMimetype()); + newPayloadDV.setName(payloadDV.getName()); + newPayloadDV.setStorageID(payloadDV.getStorageID()); + newFileset.addPayloadDV(newPayloadDV); + } + + newListFileset.add(newFileset); + } + clonedMDPBE.setListFileset(newListFileset); + + ArrayList newListMetadataFieldWrapper = new ArrayList(); + + for (MetadataFieldWrapper mfw : this.getMetadataFields()) { + MetadataFieldWrapper newMfw = new MetadataFieldWrapper(); + newMfw.setAsGroup(mfw.getAsGroup()); + newMfw.setAsTag(mfw.getAsTag()); + newMfw.setCurrentValue(mfw.getCurrentValue()); + newMfw.setDefaultValue(mfw.getDefaultValue()); + newMfw.setFieldId(mfw.getFieldId()); + newMfw.setFieldName(mfw.getFieldName()); + newMfw.setFieldNameFromCategory(mfw.getFieldNameFromCategory()); + newMfw.setMandatory(mfw.getMandatory()); + newMfw.setMaxOccurs(mfw.getMaxOccurs()); + newMfw.setMultiSelection(mfw.isMultiSelection()); + newMfw.setNote(mfw.getNote()); + newMfw.setOwnerCategory(mfw.getOwnerCategory()); + newMfw.setType(mfw.getType()); + newMfw.setValidator(mfw.getValidator()); + newMfw.setVocabulary(mfw.getVocabulary()); + + newListMetadataFieldWrapper.add(newMfw); + + } + + clonedMDPBE.setMetadataFields(newListMetadataFieldWrapper); + + return clonedMDPBE; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("MetaDataProfileBeanExt [listFileset="); - builder.append(listFileset); + builder.append("MetaDataProfileBeanExt [getType()="); + builder.append(getType()); + builder.append(", getTitle()="); + builder.append(getTitle()); + builder.append(", getMetadataFields()="); + builder.append(getMetadataFields()); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ResultSetPaginatedDataIDs.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ResultSetPaginatedDataIDs.java new file mode 100644 index 0000000..b4a5ff1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/shared/ResultSetPaginatedDataIDs.java @@ -0,0 +1,67 @@ +package org.gcube.portlets.user.geoportaldataviewer.shared; + +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; + + +/** + * The Class ResultSetPaginatedDataIDs. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 25, 2022 + */ +public class ResultSetPaginatedDataIDs extends ResultSetPaginatedData { + + /** + * + */ + private static final long serialVersionUID = -4847290903890912325L; + + private List resultSetProjectIDs; + + /** + * Instantiates a new result set paginated data I ds. + */ + public ResultSetPaginatedDataIDs() { + + } + + public ResultSetPaginatedDataIDs(int offset, int limit, boolean isServerSearchFinished) { + super(offset,limit,isServerSearchFinished); + } + + /** + * Gets the result set project I ds. + * + * @return the result set project I ds + */ + public List getResultSetProjectIDs() { + return resultSetProjectIDs; + } + + /** + * Sets the result set project I ds. + * + * @param resultSetProjectIDs the new result set project I ds + */ + public void setResultSetProjectIDs(List resultSetProjectIDs) { + this.resultSetProjectIDs = resultSetProjectIDs; + } + + /** + * To string. + * + * @return the string + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ResultSetPaginatedDataIDs [resultSetProjectIDs="); + builder.append(resultSetProjectIDs); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/webapp/GeoportalDataViewer.css b/src/main/webapp/GeoportalDataViewer.css index 1addef1..078f00a 100644 --- a/src/main/webapp/GeoportalDataViewer.css +++ b/src/main/webapp/GeoportalDataViewer.css @@ -550,6 +550,12 @@ body { text-align: justify; } +.search_result_msg { + font-size: 12px; + color: gray; + font-style: italic; +} + /** VIS TIMELINE CSS @@ -690,6 +696,22 @@ Table Of Contents (TOC) visibility: hidden; } +.general_error { + height: auto; + text-align: center; + font-size: 20px; + margin: 0; + position: absolute; + top: 50%; + width: 100%; + -ms-transform: translateY(-50%); + transform: translateY(-50%); +} + +.general_error div { + padding: 20px; +} + /****************************** RESPONSIVE 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 e08db2f..ee29a71 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 @@ -2,7 +2,15 @@ package org.gcube.portlets.user.geoportaldataviewer; import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; import org.bson.Document; import org.gcube.application.geoportal.common.model.document.Project; @@ -15,6 +23,10 @@ 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.geoportal.util.GisUtil; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.WhereClause; +import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; +import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.Crs; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV; @@ -43,14 +55,14 @@ public class GeoportalViewer_Tests { private ProjectsCaller clientProjects; - // private static String CONTEXT = "/pred4s/preprod/preVRE"; - // private static String TOKEN = ""; //preVRE + private static String CONTEXT = "/pred4s/preprod/preVRE"; + private static String TOKEN = "5c3c7551-870d-4259-bd77-a7e603fe4949-980114272"; //preVRE - private static String CONTEXT = "/gcube/devsec/devVRE"; - private static String TOKEN = ""; // devVRE + //private static String CONTEXT = "/gcube/devsec/devVRE"; + //private static String TOKEN = ""; // devVRE private static String PROFILE_ID = "profiledConcessioni"; - private static String PROJECT_ID = "6372470aa7b910781daaa8bc"; + private static String PROJECT_ID = "637ceb4d21dd0d6fb9f24706"; private static String USERNAME = "francesco.mangiacrapa"; @@ -59,7 +71,7 @@ public class GeoportalViewer_Tests { * * @return the client */ - //@Before + @Before public void getClient() { // assumeTrue(GCubeTest.isTestInfrastructureEnabled()); ScopeProvider.instance.set(CONTEXT); @@ -207,7 +219,7 @@ public class GeoportalViewer_Tests { } } - // @Test + @Test public void testReadProjectEdit() { try { @@ -217,13 +229,15 @@ public class GeoportalViewer_Tests { ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); projectBuilder.relationships(true); ProjectDV theProjectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder); + Geoportal_JSON_Mapper geojsonM = new Geoportal_JSON_Mapper(); ProjectEdit projectEdit = Geoportal_JSON_Mapper.loadProjectEdit(theProjectDV, CONTEXT, USERNAME); Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectEdit); // ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(theProjectDV, CONTEXT, USERNAME); // Geoportal_JSON_Mapper.prettyPrintProjectView(projectView); - + System.out.println("testReadProjectEdit terminated"); } catch (Exception e) { + System.err.println("Error"); e.printStackTrace(); } } @@ -258,5 +272,83 @@ public class GeoportalViewer_Tests { e.printStackTrace(); } } + + + @Test + public void getResultsWithSize() throws Exception { + // List listOfProjects = client.getListForProfileID(PROFILE_ID); + + long start = System.currentTimeMillis(); + System.out.println("start at: "+start); + SearchingFilter filter = new SearchingFilter(); + + // Where Clause + List conditions = new ArrayList(); + Map searchInto = new HashMap(); + searchInto.put("_theDocument.dataInizioProgetto", "2021"); + WhereClause whereClause = new WhereClause(LOGICAL_OP.OR, searchInto); + + conditions.add(whereClause); + filter.setConditions(conditions); + + //NEED TO GET projections + + //SETTING PROJECTION ONLY FOR PROEJCT ID + LinkedHashMap projectionForIDs = new LinkedHashMap(); + projectionForIDs.put(Project.ID, 1); + filter.setProjection(projectionForIDs); + + //LIMIT IS NULL MEANS THAT IT IS EQUAL TO NUMBER TOTAL OF DOCUMENTS + Integer totalDocs = clientProjects.getTotalDocument(PROFILE_ID); + Iterator projects = clientProjects.queryOnMongo(PROFILE_ID, totalDocs, 0, null, filter); + + //CALCULATING SIZE OF THE ITERATOR OF PROJECT IDs + Iterable itP = () -> projects; + Stream targetStream = StreamSupport.stream(itP.spliterator(), false); + List listProjectIDs = targetStream.map(Project::getId).collect(Collectors.toList()); + + System.out.println("Total Ids are: "+listProjectIDs.size()); + //listProjectIDs.stream().forEach(p -> System.out.println(p)); + + long end = System.currentTimeMillis(); + System.out.println("IDS returned in ms: "+(end-start)); + + //RESETTIG FILTER AND PROJECT TO CLIENT QUERY + LinkedHashMap projection = new LinkedHashMap(); + // default + //PROJECTION + projection.put(Project.ID, 1); + projection.put("_theDocument.nome", 1); + projection.put("_profileID", 1); + projection.put("_profileVersion", 1); + projection.put("_version", 1); + projection.put("_theDocument", 1); + + projection.put("_theDocument.paroleChiaveLibere", 1); + projection.put("_theDocument.editore", 1); + projection.put("_theDocument.paroleChiaveICCD", 1); + projection.put("_theDocument.responsabile", 1); + + projection.put("_theDocument.introduzione", 1); + projection.put("_theDocument.authors", 1); + projection.put("_theDocument.dataInizioProgetto", 1); + filter.setProjection(projection); + + + //Integer totalDocs = client.getTotalDocument(PROFILE_ID); + Iterator itProjects = clientProjects.queryOnMongo(PROFILE_ID, totalDocs, 0, 50, filter); + + List results = ConvertToDataValueObjectModel.toListResultDocument(itProjects); + int i = 0; + for (ResultDocumentDV projectDV : results) { + System.out.println(++i + ") " + projectDV.getId() + " dataInizioProgetto: "+projectDV.getDocumentAsMap().get("dataInizioProgetto")); + } + + System.out.println("Result listed has size: "+results.size()); + + end = System.currentTimeMillis(); + System.out.println("Result listed in ms: "+(end-start)); + + } }