From 3644685fe5672173b8fbd8b6b47390898577aa45 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 9 Jun 2023 10:28:46 +0200 Subject: [PATCH] Improved search facility --- .../client/GeoportalDataViewer.java | 9 +++++---- .../client/GeoportalDataViewerConstants.java | 7 +++++-- .../ui/cms/search/SearchFacilityUI.java | 19 ++++++++++--------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewer.java index 40ff90a..d72cfac 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 @@ -853,15 +853,15 @@ public class GeoportalDataViewer implements EntryPoint { String newCqlFilter = null; // default -// setCqlFilter = "INTERSECTS(geom,querySingle('limiti_amministrativi:regioni','the_geom','DEN_REG=''Calabria'''));INCLUDE"; -// GWT.log("HARD-CODED CQL FILTER: "+setCqlFilter); - if (layerName == null) { GWT.log("CQL FILTER skipped, layerName is NULL!!"); return; } - if (result != null && result.size() > 0) { + // Applying CQL filter only if there are results and its number are less or + // equal to SEARCH_LIMIT_RESULTS_TO_MAXIMUM + if (result != null && result.size() > 0 + && result.size() <= GeoportalDataViewerConstants.SEARCH_LIMIT_RESULTS_TO_MAXIMUM) { String cqlFilter = GeoportalDataViewerConstants.PROJECT_ID_KEY_FEATURE + " IN("; for (String projectId : result) { cqlFilter += "'" + projectId + "',"; @@ -883,6 +883,7 @@ public class GeoportalDataViewer implements EntryPoint { GWT.log("New CQL Filter is: " + newCqlFilter); + // Resetting CQL Filter if (layerName != null) layerManager.setCQLForLayerToIndexLayer(layerName, newCqlFilter); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java index 89b4ac6..c1391e4 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/GeoportalDataViewerConstants.java @@ -25,7 +25,9 @@ public class GeoportalDataViewerConstants { public static final String GET_MAX_ZOOM_LEVEL = OpenLayersMapParameters.OL_MAP_PARAM.maxzoomlevel.name(); public static final String GET_ZOOM = OpenLayersMapParameters.OL_MAP_PARAM.zoom.name(); public static final String GET_CENTER_MAP_TO_LONG_LAT = OpenLayersMapParameters.OL_MAP_PARAM.centermap.name(); - + + public static final int SEARCH_LIMIT_RESULTS_TO_MAXIMUM = 50; + public static final DateTimeFormat DATE_TIME_FORMAT = DateTimeFormat.getFormat("dd MMMM yyyy"); public static enum MapEventType { @@ -152,7 +154,8 @@ public class GeoportalDataViewerConstants { var tabCell = tr.insertCell(-1); var theValue = jsonObj[j][col[i]]; //console.log("the value: "+theValue); - if (theValue !== null && Object.prototype.toString.call(theValue) === '[object Array]') { + if (theValue !== null + && Object.prototype.toString.call(theValue) === '[object Array]') { var formattedValueArray = ""; for (var k = 0; k < theValue.length; k++) { var theValueArray = theValue[k]; 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 43d0916..cbdd963 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 @@ -15,6 +15,7 @@ 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.GeoportalDataViewerConstants; 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; @@ -61,8 +62,6 @@ 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; @@ -272,8 +271,9 @@ public class SearchFacilityUI extends Composite { panelResults.clear(); panelResults.add(new HTML("
")); panelResults.add(new LoaderIcon("Searching...")); - GeoportalDataViewerServiceAsync.Util.getInstance().getListProjects(profileID, 0, SEARCHING_LIMIT_RESULTS_TO, - filter, false, new AsyncCallback() { + GeoportalDataViewerServiceAsync.Util.getInstance().getListProjects(profileID, 0, + GeoportalDataViewerConstants.SEARCH_LIMIT_RESULTS_TO_MAXIMUM, filter, false, + new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -313,13 +313,14 @@ public class SearchFacilityUI extends Composite { + "). Please find below the top " + returnedItems + ".
"; } else if (returnedItems > 0) { message = "Found " + returnedItems; - message += returnedItems > 0 ? " items" : " item"; - message += ". "; + message += returnedItems > 0 ? " projects" : " project"; + message += "."; } -// if (returnedItems > 0) { -// message += "On the map you can see all the projects with a centroid matching the query"; -// } + if (returnedItems > 0 + && returnedItems <= GeoportalDataViewerConstants.SEARCH_LIMIT_RESULTS_TO_MAXIMUM) { + message += "On the map you can see all the projects with a centroid matching the query"; + } HTML resultMessage = new HTML(message); resultMessage.getElement().addClassName("search_result_msg");