From 941805a5962f194e5a698b7f6e792799e56a3e3a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 27 Oct 2022 16:18:54 +0200 Subject: [PATCH] Fixing search facility --- .../client/GeoportalDataViewer.java | 2 +- .../client/GeoportalDataViewerService.java | 2 +- .../GeoportalDataViewerServiceAsync.java | 2 +- .../client/ui/GeonaDataViewMainPanel.java | 2 +- .../client/ui/cms/project/ProjectViewer.java | 2 - .../ui/cms/search/SearchFacilityUI.java | 10 +- .../GeoportalDataViewerServiceImpl.java | 155 ++++-------------- 7 files changed, 41 insertions(+), 134 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 7b88bab..af20a74 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 @@ -137,7 +137,7 @@ public class GeoportalDataViewer implements EntryPoint { RootPanel.get(APP_DIV).add(loaderApp); GeoportalDataViewerServiceAsync.Util.getInstance() - .listOfFieldsForSearching(new AsyncCallback>() { + .getConfigListOfFieldsForSearching(new AsyncCallback>() { @Override public void onFailure(Throwable caught) { 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 52c5a61..23cabaf 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 @@ -145,7 +145,7 @@ public interface GeoportalDataViewerService extends RemoteService { * @return the list * @throws Exception the exception */ - List listOfFieldsForSearching() throws Exception; + List getConfigListOfFieldsForSearching() throws Exception; // /** // * Gets the list concessioni. 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 fb28cf0..51e8515 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 @@ -66,7 +66,7 @@ public interface GeoportalDataViewerServiceAsync { void getListBaseLayers(AsyncCallback> callback); - void listOfFieldsForSearching(AsyncCallback> callback); + void getConfigListOfFieldsForSearching(AsyncCallback> callback); // void getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService, // AsyncCallback callback); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java index dd61c78..5c2af4b 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/client/ui/GeonaDataViewMainPanel.java @@ -204,7 +204,7 @@ public class GeonaDataViewMainPanel extends Composite { this.currentSearchFacility.resetCurrentSearch(); searchFacilityPanel.clear(); - this.currentSearchFacility = new SearchFacilityUI(ucd.getProfileID(), applicationBus, sortByFields, searchByFields, + this.currentSearchFacility = new SearchFacilityUI(ucd.getProfileID(), applicationBus, displayFields, sortByFields, searchByFields, initialSortFilter); searchFacilityPanel.add(currentSearchFacility); currentSearchFacility.setSearchButton(searchFacilityButton); 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 ea8a13c..f253062 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 @@ -10,8 +10,6 @@ import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync; -import org.gcube.portlets.user.geoportaldataviewer.client.OLUtil; -import org.gcube.portlets.user.geoportaldataviewer.client.gis.ExtentWrapped; import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils; import org.gcube.portlets.user.geoportaldataviewer.client.ui.ModalWindow; import org.gcube.portlets.user.geoportaldataviewer.client.ui.dialogs.DialogShareableLink; 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 5029ee1..c5a3dcc 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 @@ -17,7 +17,6 @@ import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync; -import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION; 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; @@ -111,6 +110,8 @@ public class SearchFacilityUI extends Composite { private String profileID; + private List displayByFields; + /** * The Interface SearchFacilityPanelUiBinder. * @@ -130,10 +131,11 @@ public class SearchFacilityUI extends Composite { * @param searchForFields the search for fields * @param initialSortFilter the initial sort filter */ - public SearchFacilityUI(String profileID, HandlerManager appManagerBus, List sortByFields, + public SearchFacilityUI(String profileID, HandlerManager appManagerBus,List displayByFields, List sortByFields, List searchForFields, SearchingFilter initialSortFilter) { initWidget(uiBinder.createAndBindUi(this)); this.profileID = profileID; + this.displayByFields = displayByFields; this.searchForFields = searchForFields; this.currentSortFilter = initialSortFilter; this.sortByFields = sortByFields; @@ -301,7 +303,7 @@ public class SearchFacilityUI extends Composite { ft.getElement().setClassName("table-results"); int i = 0; // Table headers - for (ItemFieldDV itemField : searchForFields) { + for (ItemFieldDV itemField : displayByFields) { if (i > MAX_COLUMNS_RESULTS) { break; @@ -352,7 +354,7 @@ public class SearchFacilityUI extends Composite { ft.setWidget(i, 0, locateOnMap); int j = 0; // Other columns - for (ItemFieldDV itemField : searchForFields) { + for (ItemFieldDV itemField : displayByFields) { if (j > MAX_COLUMNS_RESULTS) { break; 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 bb57e3c..06e2c29 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 @@ -14,7 +14,6 @@ import java.util.Map.Entry; import javax.servlet.ServletConfig; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; import org.bson.Document; import org.gcube.application.geoportal.common.model.configuration.Configuration; @@ -521,107 +520,6 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return listDAO; } -// /** -// * Gets the preview image for concessione from http session. It is the first -// * image retrieved from mongoService for mongoConcessioneId. Caching it into -// * session -// * -// * @param httpServletRequest the http servlet request -// * @param itemType the item type -// * @param mongoConcessioneId the mongo concessione id -// * @return the preview image for concessione -// */ -// private UploadedImageDV sessionloadPreviewImageForConcessione(HttpServletRequest httpServletRequest, -// String itemType, String mongoConcessioneId) { -// LOG.info("sessionloadPreviewImageForConcessione [mongoConcessioneId: " + mongoConcessioneId + ", itemType: " -// + itemType + "] called"); -// -// HttpSession session = httpServletRequest.getSession(); -// Map> mapImages = null; -// List lUI = null; -// try { -// mapImages = (LinkedHashMap) session.getAttribute(CACHE_IMAGE_PREVIEW_FOR_CONCESSIONE); -// -// if (mapImages == null) { -// mapImages = new LinkedHashMap>(); -// } -// -// List imagePreviewForConcessione = mapImages.get(mongoConcessioneId); -// -// if (imagePreviewForConcessione == null || imagePreviewForConcessione.size() == 0) { -// LOG.info("Into " + CACHE_IMAGE_PREVIEW_FOR_CONCESSIONE + " object session the mongoConcessioneId " -// + mongoConcessioneId + " is empty or null, loading from service and filling it"); -// lUI = getUploadedImagesForId(httpServletRequest, itemType, mongoConcessioneId, 1); -// mapImages.put(mongoConcessioneId, lUI); -// } -// -// lUI = mapImages.get(mongoConcessioneId); -// LOG.info("From " + CACHE_IMAGE_PREVIEW_FOR_CONCESSIONE + " object session read image: " + lUI); -// session.setAttribute(CACHE_IMAGE_PREVIEW_FOR_CONCESSIONE, mapImages); -// -// } catch (Exception e) { -// LOG.warn("Error occurred when instancing the " + UrlShortener.class.getSimpleName(), e); -// } -// -// if (lUI == null || lUI.isEmpty()) -// return null; -// -// return lUI.get(0); -// } - - /** - * Gets the uploaded images for id. - * - * @param httpServletRequest the http servlet request - * @param itemType the item type - * @param itemId the item id - * @param maxImages the max images - * @return the uploaded images for id - * @throws Exception the exception - */ - private List getUploadedImagesForId(HttpServletRequest httpServletRequest, String itemType, - String itemId, Integer maxImages) throws Exception { - LOG.info("getUploadedImagesForId [itemId: " + itemId + ", itemType: " + itemType + "] called"); - - throw new Exception("getUploadedImagesForId must be revisited"); - - /* - * 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 listUI = null; - * - * try { - * - * if (itemType.equalsIgnoreCase("concessione")) { - * - * LOG.info("Trying to get concessione for id " + itemId); - * GeoportalServiceIdentityProxy cms = new - * GeoportalServiceIdentityProxy(httpServletRequest); Concessione concessione = - * cms.getItemById(itemId); if (concessione != null) { LOG.info("For id " + - * itemId + ", got concessione " + concessione.getNome() + " from service"); - * List images = concessione.getImmaginiRappresentative(); - * - * if (images != null) { listUI = new ArrayList(); int max = - * maxImages < images.size() ? maxImages : images.size(); for (int i = 0; i < - * max; i++) { UploadedImageDV ui = - * ConvertToDataViewModel.toUploadedImage(images.get(i)); listUI.add(ui); } - * LOG.info("For id " + itemId + ", got " + listUI.size() + " image/s"); } } - * else throw new Exception("Concessione with id '" + itemId + - * "' not available"); } - * - * return listUI; - * - * } catch (Exception e) { String erroMsg = UploadedImage.class.getSimpleName() - * + " not available for " + Concessione.class.getSimpleName() + " with id " + - * itemId; LOG.error(erroMsg, e); throw new Exception(erroMsg); } - */ - - } - /** * Gets the list base layers. * @@ -695,22 +593,22 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme // TODO TO Check index flag should be in configuration or evaluated according to // user credentials - String indexFlag = "public"; //default - + String indexFlag = "public"; // default + GeoportalServiceIdentityProxy gsp = getGeoportalServiceProxy(); - if(gsp.isUser()) { + if (gsp.isUser()) { indexFlag = "internal"; - LOG.info("user logged - using indexFlag: "+indexFlag); - }else if(gsp.isIAMClient()) { + LOG.info("user logged - using indexFlag: " + indexFlag); + } else if (gsp.isIAMClient()) { indexFlag = "public"; - LOG.info("user not logged - using indexFlag: "+indexFlag); + LOG.info("user not logged - using indexFlag: " + indexFlag); } // TODO constant coll.setIndexes(new ArrayList()); - LOG.debug("Checking if " + u.getId() + " is GIS Indexed. Index flag needed is " - + indexFlag); + LOG.debug( + "Checking if " + u.getId() + " is GIS Indexed. Index flag needed is " + indexFlag); for (Index index : ucdConfig.getIndexes()) { try { @@ -749,23 +647,21 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme } /** - * List of fields for searching. + * Gets the config list of fields for searching. * - * @return the list + * @return the config list of fields for searching * @throws Exception the exception */ @Override - public List listOfFieldsForSearching() throws Exception { + public List getConfigListOfFieldsForSearching() throws Exception { LOG.info("listOfFieldsForSearching called"); try { SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); -// GNADataViewerConfigProfile profile = getGNADataVieweConfigProfile(); -// return profile.getListItemFields(); List listIFResponse = new ArrayList(); - List handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_list.getId()); + List handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_basic_data_list.getId()); List listUseCaseDescriptor; try { UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors(); @@ -779,13 +675,11 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme listUseCaseDescriptor = new ArrayList(); } - // List listUCDDV = new - // ArrayList(listUseCaseDescriptor.size()); for (UseCaseDescriptor ucd : listUseCaseDescriptor) { UseCaseDescriptorDV ucdDV = ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null); - // listUCDDV.add(ucdDV); + HandlerDeclarationDV dataListHandler = getHandlerDeclarationFor(ucdDV, - GEOPORTAL_DATA_HANDLER.geoportal_data_list); + GEOPORTAL_DATA_HANDLER.geoportal_basic_data_list); if (dataListHandler != null) { ConfigurationDV config = dataListHandler.getConfiguration(); @@ -794,7 +688,6 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme ItemFieldsResponse ifResponse = new ItemFieldsResponse(); ifResponse.setUseCaseDescriptorDV(ucdDV); List listItemFields = (List) config.getConfiguration(); - // map.put(ucdDV.getProfileID(), listItemFields); ifResponse.setListItemFields(listItemFields); listIFResponse.add(ifResponse); break; @@ -1121,7 +1014,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme * @param maxWFSFeature the max WFS feature * @param zoomLevel the zoom level * @return the data result - * @throws Exception + * @throws Exception the exception */ @Override public List getDataResult(List layerObjects, String mapSrsName, @@ -1207,8 +1100,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme layerObject.getProjectID()); layerObject.setProjectDV(projectDV); } - - if(layerObject.getProjectDV().getSpatialReference()==null) { + + if (layerObject.getProjectDV().getSpatialReference() == null) { GeoJSON geoJson = spatialReference(layerObject.getProfileID(), layerObject.getProjectID()); layerObject.getProjectDV().setSpatialReference(geoJson); } @@ -1253,6 +1146,13 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return listDAO; } + /** + * Minimal project DV. + * + * @param profileID the profile ID + * @param projectID the project ID + * @return the project DV + */ private ProjectDV minimalProjectDV(String profileID, String projectID) { LOG.trace("minimalProjectDV for profileID: " + profileID + ", projectID: " + projectID + "called"); @@ -1281,6 +1181,13 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme return projectDV; } + /** + * Spatial reference. + * + * @param profileID the profile ID + * @param projectID the project ID + * @return the geo JSON + */ private GeoJSON spatialReference(String profileID, String projectID) { LOG.trace("spatialReference for profileID: " + profileID + ", projectID: " + projectID + "called"); try {