From 93c3d1d07da4fbf39cf09e1cdb4f2418ae36655d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 Nov 2021 16:05:05 +0100 Subject: [PATCH 01/16] #22455, integrated with roles: (Data-Member as default), Data-Manager, Data-Editor --- .classpath | 6 +- .../com.gwtplugins.gdt.eclipse.core.prefs | 2 +- .settings/org.eclipse.wst.common.component | 38 ++- CHANGELOG.md | 7 + pom.xml | 2 +- .../ConstantsGeoPortalDataEntryApp.java | 20 +- .../client/GeoPortalDataEntryApp.java | 269 +++++++++++++++--- .../client/GeoportalDataEntryService.java | 18 +- .../GeoportalDataEntryServiceAsync.java | 4 + .../client/events/ActionOnItemEvent.java | 2 +- .../events/ActionPerformedOnItemEvent.java | 84 ++++++ .../ActionPerformedOnItemEventHandler.java | 24 ++ .../client/resource/Images.java | 3 + .../client/resource/access_denied.png | Bin 0 -> 962 bytes .../client/ui/GeonaMainTabPanel.java | 42 ++- .../client/ui/ModalWindow.java | 58 ++++ .../client/ui/edit/EditModeRecord.java | 50 ++-- .../client/ui/edit/UpdateFileset.java | 6 +- .../client/ui/table/ItemsTable.java | 6 +- .../server/GeoportalDataEntryServiceImpl.java | 119 +++++++- .../.~lock.GNA_UserRights_Configurations.csv# | 1 + .../server/config/CSVFile.java | 152 ++++++++++ .../server/config/CSVReader.java | 192 +++++++++++++ .../server/config/CSVRow.java | 81 ++++++ .../server/config/FileUtil.java | 68 +++++ .../config/GNARoleRitghtsConfigReader.java | 166 +++++++++++ .../config/GNA_RoleRights_Configurations.csv | 5 + .../shared/ACTION_ON_ITEM.java | 29 ++ .../shared/ActionOnItemType.java | 5 + .../GNAUserRightsConfigNotFoundException.java | 8 + .../shared/GcubeUserRole.java | 55 ++++ .../geoportaldataentry/shared/RoleRights.java | 100 +++++++ .../geoportaldataentry/shared/UserRights.java | 63 ++++ .../geoportaldataentry/client/TestClass.java | 58 ++-- 34 files changed, 1604 insertions(+), 139 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEvent.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/access_denied.png create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/.~lock.GNA_UserRights_Configurations.csv# create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVFile.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVReader.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVRow.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNA_RoleRights_Configurations.csv create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ACTION_ON_ITEM.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ActionOnItemType.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigNotFoundException.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GcubeUserRole.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/RoleRights.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java diff --git a/.classpath b/.classpath index e619cfc..7edc167 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -35,5 +35,5 @@ - + diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs index 384836d..876328d 100644 --- a/.settings/com.gwtplugins.gdt.eclipse.core.prefs +++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 jarsExcludedFromWebInfLib= -lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-2.0.1-SNAPSHOT +lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-2.1.0-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index b922d7e..4c4808d 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,5 @@ - + @@ -17,8 +17,12 @@ - - + + + + + + @@ -37,7 +41,9 @@ - + + + @@ -56,7 +62,9 @@ - + + + @@ -75,7 +83,9 @@ - + + + @@ -94,7 +104,9 @@ - + + + @@ -113,7 +125,9 @@ - + + + @@ -132,7 +146,9 @@ - + + + @@ -151,7 +167,9 @@ - + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index f94c8f7..fede67f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v2.1.0-SNAPSHOT] - 2021-11-24 + +#### Enhancements + +- [#22455] Integrated with roles: (Data-Member as default), Data-Manager, Data-Editor + + ## [v2.0.1] - 2021-11-17 - [#22369] Just to include the bug fix for Policy and LicenseID in the geoportal-common diff --git a/pom.xml b/pom.xml index a2c34bf..6196c99 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.gcube.portlets.user geoportal-data-entry-app war - 2.0.1 + 2.1.0-SNAPSHOT GeoPortal Data Entry App The GeoPortal Data Entry App is an application to build the web forms for data entries needed to GeoNa project diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index dea88f1..95d5323 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -17,8 +17,6 @@ public class ConstantsGeoPortalDataEntryApp { public static final String HOURS_MINUTES_SEPARATOR = ConstantsMPFormBuilder.HOURS_MINUTES_SEPARATOR; - public static final String ERROR_ON_INIZIALITAION_STAGE_PLEASE_CONTACT_THE_SUPPORT = "Error on inizialization stage, please contact the support!"; - /** * The Enum RECORD_TYPE. * @@ -31,14 +29,14 @@ public class ConstantsGeoPortalDataEntryApp { } /** - * The Enum ACTION_ON_ITEM. + * The Enum ACTION_PERFORMED_ON_ITEM. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Aug 6, 2021 + * Nov 25, 2021 */ - public enum ACTION_ON_ITEM { - SHOW_ON_MAP, SHOW_METADATA, SHOW_REPORT, SHOW_EDIT_MODE, DELETE_RECORD, UPDATED_RECORD + public enum ACTION_PERFORMED_ON_ITEM { + UPDATED_PROJECT } /** @@ -67,10 +65,20 @@ public class ConstantsGeoPortalDataEntryApp { this.displayName = displayName; } + /** + * Gets the json field name. + * + * @return the json field name + */ public String getJsonFieldName() { return jsonFieldName; } + /** + * Gets the display name. + * + * @return the display name + */ public String getDisplayName() { return displayName; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index d4430bd..8ca2bd1 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -11,19 +11,23 @@ import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_ON_ITEM; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEventHandler; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEvent; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsHandler; +import org.gcube.portlets.user.geoportaldataentry.client.resource.Images; import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaMainTabPanel; import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaRecordsPaginatedView; +import org.gcube.portlets.user.geoportaldataentry.client.ui.ModalWindow; import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel; import org.gcube.portlets.user.geoportaldataentry.client.ui.edit.EditModeRecord; import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm; @@ -34,11 +38,16 @@ import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil.HTML_TAG; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.NewBrowserWindow; +import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.ORDER; +import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync; import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; @@ -58,6 +67,7 @@ import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.VerticalPanel; @@ -82,7 +92,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { private LinkedHashMap mapForms = new LinkedHashMap(); - private GeonaDataEntryMainForm geoNaMainForm; + private GeonaDataEntryMainForm geoNaMainForm = null; private Collection orderedCards; @@ -94,6 +104,10 @@ public class GeoPortalDataEntryApp implements EntryPoint { private GeonaRecordsPaginatedView grpw = null; + private UserRights myRights = null; + + private LoaderIcon loader = new LoaderIcon("Loading Application..."); + /** * This is the entry point method. */ @@ -104,34 +118,82 @@ public class GeoPortalDataEntryApp implements EntryPoint { SortFilter initialSortFilter = new SortFilter(RECORD_FIELD.NAME, ORDER.ASC); + RootPanel.get(DIV_PORTLET_ID).add(loader); + mainTabPanel = new GeonaMainTabPanel(appManagerBus, sortByOptions, initialSortFilter); mainTabPanel.setLoaderVisible("Loading...", true); geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus); + mainTabPanel.addFormPanel(geoNaMainForm); - GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback() { + GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback() { @Override public void onFailure(Throwable caught) { - Window.alert(ConstantsGeoPortalDataEntryApp.ERROR_ON_INIZIALITAION_STAGE_PLEASE_CONTACT_THE_SUPPORT); + String errorMsg = "Sorry, an error occurrend on istancing the application. Please, contact the support"; + Alert alert = new Alert(errorMsg, AlertType.ERROR); + alert.setClose(false); + try { + RootPanel.get(DIV_PORTLET_ID).remove(loader); + } catch (Exception e) { + + } + RootPanel.get(DIV_PORTLET_ID).add(alert); + Window.alert(errorMsg); + } @Override - public void onSuccess(GeonaISConfig result) { + public void onSuccess(UserRights result) { + try { + RootPanel.get(DIV_PORTLET_ID).remove(loader); + } catch (Exception e) { - if (result != null && result.getgRSecondaryType() != null && result.getScope() != null) { - callGetMetadataProfiles(result.getScope(), result.getgRSecondaryType()); - } else - Window.alert( - ConstantsGeoPortalDataEntryApp.ERROR_ON_INIZIALITAION_STAGE_PLEASE_CONTACT_THE_SUPPORT); + } + + initGUI(); + myRights = result; + + RoleRights roleRights = myRights.getRoleRights(); + boolean canCreateNewItem = roleRights.getListPermessions().keySet().contains(ACTION_ON_ITEM.CREATE_NEW_PROJECT); + + if (!canCreateNewItem) { + // removing Tab "Create New Project" + mainTabPanel.removeTab(0); + // activating Tab "List of Project" + mainTabPanel.setTabActive(0); + mainTabPanel.instanceAndShowListOfConcessioni(); + return; + } + + GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + Window.alert( + "Sorry, an error occurrend when loading configurations. Please, contact the support"); + } + + @Override + public void onSuccess(GeonaISConfig result) { + + if (result != null && result.getgRSecondaryType() != null + && result.getScope() != null) { + callGetMetadataProfiles(result.getScope(), result.getgRSecondaryType()); + } else + Window.alert( + "Sorry, no configuration found in the context. Please, contact the support"); + + } + }); } }); + } + private void initGUI() { bindEvents(); - mainTabPanel.addFormPanel(geoNaMainForm); RootPanel.get(DIV_PORTLET_ID).add(mainTabPanel); - Window.addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { @@ -143,21 +205,29 @@ public class GeoPortalDataEntryApp implements EntryPoint { updateSize(); } + private static native void click(Element element)/*-{ + element.click(); + }-*/; + /** * Update window size */ public void updateSize() { - RootPanel workspace = RootPanel.get(DIV_PORTLET_ID); - int topBorder = workspace.getAbsoluteTop(); - int footer = 85; // footer is bottombar + sponsor - int headerSize = 90; - // int headerSize = 30; - int rootHeight = Window.getClientHeight() - topBorder - headerSize - footer;// - ((footer == - // null)?0:(footer.getOffsetHeight()-15)); + try { + RootPanel workspace = RootPanel.get(DIV_PORTLET_ID); + int topBorder = workspace.getAbsoluteTop(); + int footer = 85; // footer is bottombar + sponsor + int headerSize = 90; + // int headerSize = 30; + int rootHeight = Window.getClientHeight() - topBorder - headerSize - footer;// - ((footer == + // null)?0:(footer.getOffsetHeight()-15)); - GWT.log("New workspace dimension Height: " + rootHeight); - mainTabPanel.setInternalHeight(rootHeight); + GWT.log("New workspace dimension Height: " + rootHeight); + mainTabPanel.setInternalHeight(rootHeight); + } catch (Exception e) { + // TODO: handle exception + } // appController.getMainPanel().setHeight(rootHeight); // appController.getMainPanel().setWidth(rootWidth); @@ -430,14 +500,54 @@ public class GeoPortalDataEntryApp implements EntryPoint { public void onGetList(GetListOfRecordsEvent getListOfRecordsEvent) { SortFilter sortFilter = getListOfRecordsEvent.getSortFilter(); - if(sortFilter==null){ + if (sortFilter == null) { sortFilter = mainTabPanel.getCurrentSortFilter(); } - grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, - sortFilter); + grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, sortFilter); mainTabPanel.showListOfConcessioniView(grpw); } }); + + appManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() { + + @Override + public void onDoActionPerformedFired( + ActionPerformedOnItemEvent actionPerformedOnItemEvent) { + if (actionPerformedOnItemEvent != null) { + + ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction(); + List items = actionPerformedOnItemEvent.getSelectItems(); + + if (items == null) { + if (grpw != null) { + items = (List) grpw.getSelectItems(); + } + } + + if (items == null || items.size() == 0) { + Window.alert("No item selected"); + return; + } + + T item = items.get(0); + + if (item == null) + return; + + if (item instanceof ConcessioneDV) { + final ConcessioneDV concessione = (ConcessioneDV) item; + GWT.log("onDoActionPerformedFired item: " + concessione); + switch (action) { + case UPDATED_PROJECT: + appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, + mainTabPanel.getCurrentSortFilter())); + break; + } + } + } + + } + }); appManagerBus.addHandler(ActionOnItemEvent.TYPE, new ActionOnItemEventHandler() { @@ -470,10 +580,41 @@ public class GeoPortalDataEntryApp implements EntryPoint { if (item instanceof ConcessioneDV) { final ConcessioneDV concessione = (ConcessioneDV) item; - GWT.log("ActionOnItemEvente item: " + concessione); + GWT.log("onDoActionFired item: " + concessione); + + // Checking if the user is NOT authorized to perform this action in two ways: + // 1. the map of actions allowed for the user does not contain the action; + RoleRights roleRights = myRights.getRoleRights(); + OPERATION_TYPE operationType = roleRights.getListPermessions().get(action); + boolean allowedOperationForUser = operationType != null? true:false; + if (!allowedOperationForUser) { + + String msg = "You are not authorized to perform the action: "+ action.getLabel(); + ModalWindow modalW = new ModalWindow(new Image(Images.ICONS.accessDenied()), "Forbidden: "+action, msg, AlertType.WARNING); + modalW.show(); + return; + } + // 2. the user cannot access to action (e.g. the user cannot write an item of another user) + // if so an error is shown + GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); + boolean allowedWriteActionOnItem = checkAccessToOperationType(userRole, operationType, concessione); + if (!allowedWriteActionOnItem) { + String title = "Forbidden: missing write access"; + String msg = "You do not have write access to item: "+ concessione.getNome(); + if(!userRole.isWriteOwn()) { + msg = "You do not have write access to item: "+ concessione.getNome(); + }else if (!userRole.isWriteAny()){ + title = "Forbidden: missing ownership"; + msg = "You are not the creator of: "+ concessione.getNome() +". You cannot access to it"; + } + ModalWindow modalW = new ModalWindow(new Image(Images.ICONS.accessDenied()), title, msg, AlertType.WARNING); + modalW.show(); + return; + } + switch (action) { - case SHOW_ON_MAP: + case VIEW_ON_MAP: final Modal modal = new Modal(true, true); modal.setCloseVisible(true); final HorizontalPanel hpGetLink = new HorizontalPanel(); @@ -508,10 +649,12 @@ public class GeoPortalDataEntryApp implements EntryPoint { break; - case SHOW_REPORT: + case VIEW_REPORT: + final Modal modal2 = new Modal(true, true); - modal2.setTitle("Report: " + concessione.getNome() - + ""); + modal2.setTitle( + "Report: " + + concessione.getNome() + ""); modal2.setWidth(800); modal2.setCloseVisible(true); if (concessione.getValidationReport() == null) { @@ -525,10 +668,11 @@ public class GeoPortalDataEntryApp implements EntryPoint { break; - case SHOW_EDIT_MODE: + case EDIT_PROJECT: final Modal modal3 = new Modal(true, true); - modal3.setTitle("Edit: " + concessione.getNome() - + ""); + modal3.setTitle( + "Edit: " + + concessione.getNome() + ""); modal3.setWidth(950); modal3.setHeight("700px"); modal3.setCloseVisible(true); @@ -540,12 +684,11 @@ public class GeoPortalDataEntryApp implements EntryPoint { modal3.show(); break; - case UPDATED_RECORD: - appManagerBus.fireEvent( - new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, - mainTabPanel.getCurrentSortFilter())); - break; - case DELETE_RECORD: +// case UPDATED_PROJECT: +// appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, +// mainTabPanel.getCurrentSortFilter())); +// break; + case DELETE_PROJECT: String htmlMsg = "Going to delete the project with:"; htmlMsg += "
    "; @@ -614,6 +757,56 @@ public class GeoPortalDataEntryApp implements EntryPoint { }); } + + private boolean checkAccessToOperationType(GcubeUserRole userRole, OPERATION_TYPE allowedAction, ConcessioneDV concessione) { + + boolean writeAnyAPassed = false; + boolean writeOwnPassed = false; + + // Case ADMIN + if (userRole.isWriteAny()) { + writeAnyAPassed = true; + } + + // Case EDITOR + // Going to check if the user can RW the record is owner of. + if (userRole.isWriteOwn()) { + String ownerUser = concessione.getCreationUser(); + if (ownerUser == null || ownerUser.isEmpty()) { + writeOwnPassed = false; + }else if (ownerUser.compareTo(myRights.getMyUsername()) == 0) { + // if my username is equal the owner of the concessione + writeOwnPassed = true; + } + } + + boolean operationAllowed = false; + switch (allowedAction) { + case READ: + //Access to READ operation is allowed to everyone + operationAllowed = true; + GWT.log(OPERATION_TYPE.READ+ " ALLOWED? "+operationAllowed); + break; + case READ_WRITE: + //Access to READ_WRITE operation + operationAllowed = writeAnyAPassed || writeOwnPassed; + GWT.log(OPERATION_TYPE.READ_WRITE+ " ALLOWED? "+operationAllowed); + break; + case WRITE: + //Access to WRITE operation + operationAllowed = writeAnyAPassed || writeOwnPassed; + GWT.log(OPERATION_TYPE.WRITE+ " ALLOWED? "+operationAllowed); + break; + case UNKNOWN: + operationAllowed = false; + GWT.log(OPERATION_TYPE.UNKNOWN+ " ALLOWED? "+operationAllowed); + break; + default: + break; + } + + return operationAllowed; + } private void purgeFileUploaded() { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java index e85bd00..d596c09 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java @@ -12,6 +12,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; +import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import com.google.gwt.user.client.rpc.RemoteService; @@ -118,13 +119,24 @@ public interface GeoportalDataEntryService extends RemoteService { /** * Update record. * - * @param itemId the item id - * @param jsonUpdate the json update - * @param recordType the record type + * @param itemId the item id + * @param recordType the record type + * @param section the section + * @param pathIndex the path index + * @param keepCurrentContent the keep current content + * @param gDBean the g D bean * @return the updated JSON string representing the itemId * @throws Exception the exception */ ConcessioneDV updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, List keepCurrentContent, GenericDatasetBean gDBean) throws Exception; + /** + * Gets the my rights in the context. + * + * @return the my rights in the context + * @throws Exception + */ + UserRights getMyRightsInTheContext() throws Exception; + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java index 0dc4486..acc75a4 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java @@ -12,6 +12,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; +import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import com.google.gwt.core.client.GWT; @@ -74,4 +75,7 @@ public interface GeoportalDataEntryServiceAsync void updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, List keepCurrentContent, GenericDatasetBean gDBean, AsyncCallback callback); + + + void getMyRightsInTheContext(AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java index 11386db..11f03b3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java @@ -3,7 +3,7 @@ package org.gcube.portlets.user.geoportaldataentry.client.events; import java.util.List; import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_ON_ITEM; +import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import com.google.gwt.event.shared.GwtEvent; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEvent.java new file mode 100644 index 0000000..54857af --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEvent.java @@ -0,0 +1,84 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import java.util.List; + +import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class ActionOnItemEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Sep 15, 2021 + * @param the generic type + */ +public class ActionPerformedOnItemEvent extends GwtEvent { + public static Type TYPE = new Type(); + private List selectItems; + private ACTION_PERFORMED_ON_ITEM action; + + /** + * Instantiates a new action performed on item event. + * + * @param selectItems the select items + * @param doAction the do action + */ + public ActionPerformedOnItemEvent(List selectItems, ACTION_PERFORMED_ON_ITEM doAction) { + this.selectItems = selectItems; + this.action = doAction; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + /* + * (non-Javadoc) + * + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + /** + * Dispatch. + * + * @param handler the handler + */ + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared. + * EventHandler) + */ + @Override + protected void dispatch(ActionPerformedOnItemEventHandler handler) { + handler.onDoActionPerformedFired(this); + } + + /** + * Gets the select items. + * + * @return the select items + */ + public List getSelectItems() { + return selectItems; + } + + /** + * Gets the action. + * + * @return the action + */ + public ACTION_PERFORMED_ON_ITEM getAction() { + return action; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEventHandler.java new file mode 100644 index 0000000..0d6ec7b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionPerformedOnItemEventHandler.java @@ -0,0 +1,24 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; + +import com.google.gwt.event.shared.EventHandler; + + +/** + * The Interface ActionPerformedOnItemEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 25, 2021 + */ +public interface ActionPerformedOnItemEventHandler extends EventHandler { + + /** + * On do action performed fired. + * @param + * + * @param actionPerformedOnItemEvent the action performed on item event + */ + void onDoActionPerformedFired(ActionPerformedOnItemEvent actionPerformedOnItemEvent); +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/Images.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/Images.java index d7dddd6..087bf8d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/Images.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/Images.java @@ -10,4 +10,7 @@ public interface Images extends ClientBundle { @Source("loading.gif") ImageResource loading(); + + @Source("access_denied.png") + ImageResource accessDenied(); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/access_denied.png b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/resource/access_denied.png new file mode 100644 index 0000000000000000000000000000000000000000..ae76b5f3dd6d6db6d8177ea25ffb82aad6b5fcc1 GIT binary patch literal 962 zcmV;z13mnSP) zsFj_dSlDPGK|3o8L6is@;)(b}Dg_auHVP616~P2ez(fPKCh_v~TI>cVm)*T&fA02v zUYO=)znS;BncbcFX2Fo4P0%A45o81^(voo)dIWpPmcSBR5zHmPY}92=&@He`;HwER z7I*0edt}>yL7-~M(3h6xfqhlLIZ7WEY{oN|U=-MzhYr63FM%(>m}8(3*adU~+w$OH z1jYX}ek5qmG3u{2{5llzvG3wXRH48pR)tChzf$LGV2N2~5{}HTrX}?NvSMWyA z>{8$C)ZLNGdO%Pom`vi7zUT3WZa1zOH=!NaaihM;qm8~K0w4F8MW*3#L5ovN*gl{5 zQ%MAF@iCkdq_dz+*t8(!6W@|V;MHD+9n;l?3~-%Bm+xuK0@G2QTvMnct+3_0qjx5kSC8T<1sBb z9Rl{O{y*r70(hZ3&pfr3uG0Gb7c zf#2Ah{mt09=~ekMkZ<6Es~nD47O4VU>Pi8(3T>jIilUPx=*4~)mV<+fbXO9&1Np3C0h6xw9iG9`E> zIAk)q=AUH$-awAylN@RV`UA!u0X~K3dlHziSh_KCJ=1Y6{1u`@1a%?8$1M03rhhM$ z-CDW=T(listConcessioni, ACTION_ON_ITEM.SHOW_ON_MAP)); + .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.VIEW_ON_MAP)); } }); @@ -223,7 +225,7 @@ public class GeonaMainTabPanel extends Composite { listConcessioni = grpw.getSelectItems(); } appManagerBus - .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.SHOW_REPORT)); + .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.VIEW_REPORT)); } }); @@ -236,8 +238,8 @@ public class GeonaMainTabPanel extends Composite { if (grpw != null && grpw.getSelectItems() != null) { listConcessioni = grpw.getSelectItems(); } - appManagerBus - .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.SHOW_EDIT_MODE)); + appManagerBus.fireEvent( + new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.EDIT_PROJECT)); } }); @@ -250,7 +252,7 @@ public class GeonaMainTabPanel extends Composite { listConcessioni = grpw.getSelectItems(); } appManagerBus - .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.DELETE_RECORD)); + .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.DELETE_PROJECT)); } }); @@ -335,4 +337,22 @@ public class GeonaMainTabPanel extends Composite { return currentSortFilter; } + public void removeTab(int index) { + tabPanel.remove(index); + } + + public void setTabActive(int index) { + tabPanel.selectTab(index); + } + + /** + * Dirty solution. + * I created this one because I had problem on firing click event for Tab element + * + */ + public void instanceAndShowListOfConcessioni(){ + grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, currentSortFilter); + showListOfConcessioniView(grpw); + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java new file mode 100644 index 0000000..c18f8df --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java @@ -0,0 +1,58 @@ +package org.gcube.portlets.user.geoportaldataentry.client.ui; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.Modal; +import com.github.gwtbootstrap.client.ui.ModalFooter; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; + +public class ModalWindow { + + private HorizontalPanel hp = new HorizontalPanel(); + private Modal modal; + + public ModalWindow(Image icon, String title, String msg, AlertType alertType) { + + modal = new Modal(false); + modal.hide(false); + modal.setTitle(title); + modal.setCloseVisible(true); + + + Alert alert = new Alert(); + alert.setType(alertType); + alert.setClose(false); + alert.setText(msg); + alert.getElement().getStyle().setMarginLeft(10, Unit.PX); + + + if (icon != null) + hp.add(icon); + hp.add(alert); + + ModalFooter modalFooter = new ModalFooter(); + final Button buttClose = new Button("Close"); + modalFooter.add(buttClose); + + buttClose.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + modal.hide(); + } + }); + + modal.add(hp); + modal.add(modalFooter); + } + + public void show() { + modal.show(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java index f7a0330..79ca301 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java @@ -7,11 +7,11 @@ import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_ON_ITEM; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp; -import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEvent; -import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEventHandler; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEvent; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.ui.edit.jseditor.JSONEditorWrapper; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; @@ -66,7 +66,7 @@ public class EditModeRecord extends Composite { private JSONEditorWrapper jsEditor; private HandlerManager appManagerBus; - + private final HandlerManager editorManagerBus = new HandlerManager(null); /** @@ -159,7 +159,7 @@ public class EditModeRecord extends Composite { * Bind events. */ private void bindEvents() { - + buttonJSONUpdate.addClickHandler(new ClickHandler() { @Override @@ -181,8 +181,8 @@ public class EditModeRecord extends Composite { // TODO: handle exception } - editorManagerBus.fireEvent( - new ActionOnItemEvent(null, ACTION_ON_ITEM.UPDATED_RECORD)); + editorManagerBus.fireEvent(new ActionPerformedOnItemEvent(null, + ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); } @@ -195,38 +195,38 @@ public class EditModeRecord extends Composite { } catch (Exception e) { // TODO: handle exception } - - DialogInform di = new DialogInform(null, "Project updated!", "Project '" + result.getNome() + "' updated correctly"); + + DialogInform di = new DialogInform(null, "Project updated!", + "Project '" + result.getNome() + "' updated correctly"); di.setZIndex(100000); di.center(); - editorManagerBus.fireEvent( - new ActionOnItemEvent(Arrays.asList(result), ACTION_ON_ITEM.UPDATED_RECORD)); + editorManagerBus.fireEvent(new ActionPerformedOnItemEvent( + Arrays.asList(result), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); } }); } }); - - editorManagerBus.addHandler(ActionOnItemEvent.TYPE, new ActionOnItemEventHandler() { + + editorManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() { @Override - public void onDoActionFired(ActionOnItemEvent showItemEvent) { - - ACTION_ON_ITEM action = showItemEvent.getAction(); - List items = showItemEvent.getSelectItems(); - - if(items!=null) { + public void onDoActionPerformedFired( + ActionPerformedOnItemEvent actionPerformedOnItemEvent) { + ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction(); + List items = actionPerformedOnItemEvent.getSelectItems(); + + if (items != null) { selectedConcessione = (BaseConcessioneDV) items.get(0); instanceJSONEditor(); - - if(action.equals(ACTION_ON_ITEM.UPDATED_RECORD)) { - appManagerBus.fireEvent( - new ActionOnItemEvent((List) items, ACTION_ON_ITEM.UPDATED_RECORD)); + + if (action.equals(ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)) { + appManagerBus.fireEvent(new ActionPerformedOnItemEvent( + (List) items, ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); } } - + } }); - } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java index 51036f8..ddfbaf5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java @@ -14,11 +14,11 @@ import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelaz import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScavoDV; import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_ON_ITEM; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryServiceAsync; -import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEvent; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEvent; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogConfirm; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.StringUtil; @@ -262,7 +262,7 @@ public class UpdateFileset extends Composite { buttonUpdate.setEnabled(true); showUploadFileGUI(); editorManagerBus.fireEvent( - new ActionOnItemEvent(Arrays.asList(fullConcessione), ACTION_ON_ITEM.UPDATED_RECORD)); + new ActionPerformedOnItemEvent(Arrays.asList(fullConcessione), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java index f801244..f7b0ca0 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java @@ -351,7 +351,7 @@ public class ItemsTable extends AbstractItemsCellTable< // @Override // public void update(int index, T object, String value) { // GWT.log("clicked show"); -// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.SHOW_ON_MAP)); +// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.VIEW_ON_MAP)); // } // }); // sortedCellTable.addColumn(showOnMapColumn); @@ -370,7 +370,7 @@ public class ItemsTable extends AbstractItemsCellTable< // @Override // public void update(int index, T object, String value) { // -// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.SHOW_REPORT)); +// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.VIEW_REPORT)); // } // }); // sortedCellTable.addColumn(showReportRecordColumn); @@ -389,7 +389,7 @@ public class ItemsTable extends AbstractItemsCellTable< // @Override // public void update(int index, T object, String value) { // -// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.DELETE_RECORD)); +// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.DELETE_PROJECT)); // } // }); // sortedCellTable.addColumn(deleteRecordColumn); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index aae3fa7..db01754 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -25,19 +25,32 @@ import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV; import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; +import org.gcube.common.portal.PortalContext; import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; import org.gcube.portlets.user.geoportaldataentry.server.MongoServiceUtil.ConcessioneValidationReportStatusComparator; +import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader; +import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigNotFoundException; +import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.ORDER; +import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; +import org.gcube.vomanagement.usermanagement.RoleManager; +import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; +import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; +import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; +import org.gcube.vomanagement.usermanagement.model.GCubeRole; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -760,19 +773,19 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen String toEditPath = null; AddSectionToConcessioneRequest request = null; List files = new ArrayList(); - + // Managing files already present as current content and kept by user List keepFiles = serviceUtil.toTemFilesFromWSC(keepCurrentContent); if (keepFiles != null) { files.addAll(keepFiles); - LOG.debug(keepFiles.size() +" current corrent file/s has/have been added to list of files"); + LOG.debug(keepFiles.size() + " current corrent file/s has/have been added to list of files"); } // Managing new files uploaded by user List newFiles = serviceUtil.toTemFiles(gDBean.getFilesUploaded()); if (newFiles != null) { files.addAll(newFiles); - LOG.debug(newFiles.size() +" new file/s has/have been added to list of files"); + LOG.debug(newFiles.size() + " new file/s has/have been added to list of files"); } // if (files == null || files.isEmpty()) @@ -808,21 +821,21 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen Concessione concessione = clientMongo.cleanFileSet(itemId, toEditPath); LOG.debug("Sending new Fileset .."); - if(files.size()>0) { + if (files.size() > 0) { // StorageUtils storage=new StorageUtils(); // Building TempFile SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); - LOG.info("Registering FileSet into recordId " + itemId + " with request path: " + toEditPath + " and: " - + files.size() + " file/s"); + LOG.info("Registering FileSet into recordId " + itemId + " with request path: " + toEditPath + + " and: " + files.size() + " file/s"); concessione = clientMongo.registerFileSet(itemId, request); - }else { + } else { LOG.info("Fileset is empty, skipping registerFileSet"); } - - LOG.info("Publishings itemId: "+itemId); + + LOG.info("Publishings itemId: " + itemId); concessione = clientMongo.publish(itemId); - - LOG.debug("returning concessione: "+concessione); + + LOG.debug("returning concessione: " + concessione); return ConvertToDataViewModel.toConcessione(concessione); } @@ -835,4 +848,88 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } } + @Override + public UserRights getMyRightsInTheContext() throws Exception { + LOG.info("getMyRightsInTheContext called"); + + GCubeUser user = null; + + try { + PortalContext pContext = PortalContext.getConfiguration(); + user = pContext.getCurrentUser(this.getThreadLocalRequest()); + + List listUserRightsForRole = GNARoleRitghtsConfigReader.readRoleRightsConfig(); + // DEV MODE + if (!SessionUtil.isIntoPortal()) { + LOG.warn("OUT OF PORTAL - DEV MODE detected"); + GcubeUserRole myRole = GcubeUserRole.DATA_MEMBER; + + for (RoleRights roleRight : listUserRightsForRole) { + if (roleRight.getUserRole().equals(myRole)) { + UserRights userRights = new UserRights(user.getUsername(), roleRight); + LOG.warn("DEV MODE returning: " + userRights); + return userRights; + } + } + } + + String scope = pContext.getCurrentScope(this.getThreadLocalRequest()); + long groupId = pContext.getCurrentGroupId(this.getThreadLocalRequest()); + + if (user == null || scope == null) { + LOG.warn("called getMyRightsInTheContext with invalid parameter user: " + user + ", in the scope: " + + scope, ", returning null"); + return null; + } + + LOG.info("reading GcubeUserRole for user: " + user.getUsername() + ", in the scope: " + scope); + // The following snippet should pass in the service-side + RoleManager roleManager = new LiferayRoleManager(); + List roles = roleManager.listRolesByUserAndGroup(user.getUserId(), groupId); + List listMyRoles = new ArrayList(); + for (GCubeRole gCubeRole : roles) { + if (gCubeRole.getRoleName().equalsIgnoreCase(GcubeUserRole.DATA_EDITOR.getName())) { + listMyRoles.add(GcubeUserRole.DATA_EDITOR); + } + if (gCubeRole.getRoleName().equalsIgnoreCase(GcubeUserRole.DATA_MANAGER.getName())) { + listMyRoles.add(GcubeUserRole.DATA_MANAGER); + } + } + + // Mapping to roles "known" + LOG.info( + "For user: " + user.getUsername() + " in the scope: " + scope + " read the role/s: " + listMyRoles); + + GcubeUserRole myRole = null; + if (listMyRoles.contains(GcubeUserRole.DATA_MANAGER)) + myRole = GcubeUserRole.DATA_MANAGER; + else if (listMyRoles.contains(GcubeUserRole.DATA_EDITOR)) + myRole = GcubeUserRole.DATA_EDITOR; + else + myRole = GcubeUserRole.DATA_MEMBER; + + LOG.info("using highest role: " + myRole); + + RoleRights toRoleRight = null; + for (RoleRights roleRight : listUserRightsForRole) { + if (roleRight.getUserRole().equals(myRole)) { + toRoleRight = roleRight; + break; + } + } + UserRights userRights = new UserRights(scope, toRoleRight); + LOG.info("returning: " + userRights); + return userRights; + } catch (UserRetrievalFault | GroupRetrievalFault | GNAUserRightsConfigNotFoundException e) { + LOG.error("An error occurred during getMyRightsInTheContext: " + user, e); + + Map permissions = new HashMap(); + RoleRights roleRights = new RoleRights(permissions, GcubeUserRole.DATA_MEMBER); + UserRights ur = new UserRights(user.getUsername(), roleRights); + LOG.warn("Returning default user rights: " + ur); + return ur; + } + + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/.~lock.GNA_UserRights_Configurations.csv# b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/.~lock.GNA_UserRights_Configurations.csv# new file mode 100644 index 0000000..23f831e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/.~lock.GNA_UserRights_Configurations.csv# @@ -0,0 +1 @@ +,francescomangiacrapa,francesco-xps,26.11.2021 11:54,file:///home/francescomangiacrapa/.config/libreoffice/4; \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVFile.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVFile.java new file mode 100644 index 0000000..52385eb --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVFile.java @@ -0,0 +1,152 @@ +/** + * + */ +package org.gcube.portlets.user.geoportaldataentry.server.config; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * The Class CSVFile. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jan 29, 2019 + */ +public class CSVFile implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 6408321963787244600L; + private CSVRow headerRow; + private List valueRows; + private String fileName; + + /** + * Instantiates a new CSV file. + */ + public CSVFile(){ + + } + + + /** + * Instantiates a new csv file. + * + * @param fileName the file name + * @param headerRow the header row + * @param valueRows the value rows + */ + public CSVFile(String fileName, CSVRow headerRow, List valueRows) { + this.fileName = fileName; + this.headerRow = headerRow; + this.valueRows = valueRows; + } + + + /** + * Gets the header row. + * + * @return the headerRow + */ + public CSVRow getHeaderRow() { + + return headerRow; + } + + /** + * Adds the value row. + * + * @param row the row + */ + public void addValueRow(CSVRow row) { + if(valueRows==null) + valueRows = new ArrayList(); + + valueRows.add(row); + } + + + /** + * Sets the value rows. + * + * @param valueRows the new value rows + */ + public void setValueRows(List valueRows) { + this.valueRows = valueRows; + } + + + /** + * Gets the value rows. + * + * @return the valueRows + */ + public List getValueRows() { + + return valueRows; + } + + + /** + * Sets the header row. + * + * @param headerRow the headerRow to set + */ + public void setHeaderRow(CSVRow headerRow) { + + this.headerRow = headerRow; + } + + + + + /** + * Gets the file name. + * + * @return the fileName + */ + public String getFileName() { + + return fileName; + } + + + + /** + * Sets the file name. + * + * @param fileName the fileName to set + */ + public void setFileName(String fileName) { + + this.fileName = fileName; + } + + + /** + * To string. + * + * @return the string + */ + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("CSVFile [headerRow="); + builder.append(headerRow); + builder.append(", valueRows="); + builder.append(valueRows); + builder.append(", fileName="); + builder.append(fileName); + builder.append("]"); + return builder.toString(); + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVReader.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVReader.java new file mode 100644 index 0000000..51eb5b9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVReader.java @@ -0,0 +1,192 @@ +/** + * + */ + +package org.gcube.portlets.user.geoportaldataentry.server.config; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * The Class CSVReader. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jan 29, 2019 + */ +public class CSVReader { + + public static final char DEFAULT_SEPARATOR = ','; + public static final char DEFAULT_QUOTE = '"'; + private File file; + private CSVFile csvFile; + + /** + * Instantiates a new CSV reader. + * + * @param file the file + * @throws FileNotFoundException the file not found exception + */ + public CSVReader(File file) throws FileNotFoundException { + + this.file = file; + this.csvFile = new CSVFile(); + readCSV(file); + } + + /** + * Read csv. + * + * @param file the file + * @throws FileNotFoundException the file not found exception + */ + private void readCSV(File file) throws FileNotFoundException { + + Scanner scanner = new Scanner(file); + csvFile.setFileName(file.getName()); + int i = 0; + while (scanner.hasNext()) { + CSVRow csvRow = new CSVRow(); + List line = parseLine(scanner.nextLine()); + csvRow.setListValues(line); + + if(i==0){ + csvFile.setHeaderRow(csvRow); + }else{ + csvFile.addValueRow(csvRow); + } + i++; + + } + scanner.close(); + } + + /** + * Parses the line. + * + * @param cvsLine the cvs line + * @return the list + */ + public static List parseLine(String cvsLine) { + + return parseLine(cvsLine, DEFAULT_SEPARATOR, DEFAULT_QUOTE); + } + + /** + * Parses the line. + * + * @param cvsLine the cvs line + * @param separators the separators + * @return the list + */ + public static List parseLine(String cvsLine, char separators) { + + return parseLine(cvsLine, separators, DEFAULT_QUOTE); + } + + /** + * Parses the line. + * + * @param cvsLine the cvs line + * @param separators the separators + * @param customQuote the custom quote + * @return the list + */ + private static List parseLine(String cvsLine, char separators, char customQuote) { + + List result = new ArrayList<>(); + // if empty, return! + if (cvsLine == null || cvsLine.isEmpty()) { + return result; + } + if (customQuote == ' ') { + customQuote = DEFAULT_QUOTE; + } + if (separators == ' ') { + separators = DEFAULT_SEPARATOR; + } + StringBuffer curVal = new StringBuffer(); + boolean inQuotes = false; + boolean startCollectChar = false; + boolean doubleQuotesInColumn = false; + char[] chars = cvsLine.toCharArray(); + for (char ch : chars) { + if (inQuotes) { + startCollectChar = true; + if (ch == customQuote) { + inQuotes = false; + doubleQuotesInColumn = false; + } + else { + // Fixed : allow "" in custom quote enclosed + if (ch == '\"') { + if (!doubleQuotesInColumn) { + curVal.append(ch); + doubleQuotesInColumn = true; + } + } + else { + curVal.append(ch); + } + } + } + else { + if (ch == customQuote) { + inQuotes = true; + // Fixed : allow "" in empty quote enclosed + if (chars[0] != '"' && customQuote == '\"') { + curVal.append('"'); + } + // double quotes in column will hit this! + if (startCollectChar) { + curVal.append('"'); + } + } + else if (ch == separators) { + result.add(curVal.toString()); + curVal = new StringBuffer(); + startCollectChar = false; + } + else if (ch == '\r') { + // ignore LF characters + continue; + } + else if (ch == '\n') { + // the end, break! + break; + } + else { + curVal.append(ch); + } + } + } + result.add(curVal.toString()); + return result; + } + + + /** + * Gets the csv file. + * + * @return the csvFile + */ + public CSVFile getCsvFile() { + + return csvFile; + } + + + /** + * Gets the file. + * + * @return the file + */ + public File getFile() { + + return file; + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVRow.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVRow.java new file mode 100644 index 0000000..7b565e8 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVRow.java @@ -0,0 +1,81 @@ +/** + * + */ +package org.gcube.portlets.user.geoportaldataentry.server.config; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + + +/** + * The Class CSVRow. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jan 29, 2019 + */ +public class CSVRow implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 6254861811998867626L; + + private List listValues; + + /** + * Instantiates a new CSV row. + */ + public CSVRow(){ + + } + + + /** + * Gets the list values. + * + * @return the listValues + */ + public List getListValues() { + + return listValues; + } + + + + /** + * @param listValues the listValues to set + */ + public void setListValues(List listValues) { + + this.listValues = listValues; + } + + + /** + * Adds the value. + * + * @param value the value + */ + public void addValue(String value) { + if(listValues==null) + listValues = new ArrayList(); + + listValues.add(value); + } + + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("CSVRow [listValues="); + builder.append(listValues); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java new file mode 100644 index 0000000..0902cac --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java @@ -0,0 +1,68 @@ +package org.gcube.portlets.user.geoportaldataentry.server.config; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +// TODO: Auto-generated Javadoc +/** + * The Class FileUtil. + * + * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) + * Apr 21, 2020 + */ +public class FileUtil { + + + /** + * Input stream to temp file. + * + * @param inputStream the input stream + * @param fileName the file name + * @return the file + * @throws IOException Signals that an I/O exception has occurred. + */ + // InputStream -> Temp File + public static File inputStreamToTempFile(InputStream inputStream, String fileName) + throws IOException { + + File tempFile = File.createTempFile(fileName, ".tmp"); + //File tempFile = File.createTempFile("MyAppName-", ".tmp"); + try (FileOutputStream outputStream = new FileOutputStream(tempFile)) { + + int read; + byte[] bytes = new byte[1024]; + + while ((read = inputStream.read(bytes)) != -1) { + outputStream.write(bytes, 0, read); + } + + return tempFile; + + }finally { + tempFile.deleteOnExit(); + } + + } + + + /** + * Copy input stream to file. + * + * @param is the is + * @param to the to + * @return the file + * @throws IOException Signals that an I/O exception has occurred. + */ + public static File copyInputStreamToFile(InputStream is, String to) throws IOException { + Path dest = Paths.get(to); + Files.copy(is, dest); + return new File(to); + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java new file mode 100644 index 0000000..6a97d8b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java @@ -0,0 +1,166 @@ +package org.gcube.portlets.user.geoportaldataentry.server.config; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; +import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigNotFoundException; +import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.allen_sauer.gwt.log.client.Log; + +/** + * The Class GNARoleRitghtsConfigReader. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 25, 2021 + */ +public class GNARoleRitghtsConfigReader { + + private static final String USER_RIGHTS_CONFIG_FILENAME = "GNA_RoleRights_Configurations.csv"; + private static Logger LOG = LoggerFactory.getLogger(GNARoleRitghtsConfigReader.class); + + public static final String WRITE_OWN_CONFIG = "WRITE_OWN"; + public static final String WRITE_ANY_CONFIG = "WRITE_ANY"; + + /** + * Read user rights config. + * + * @return the list + * @throws GNAUserRightsConfigNotFoundException the GNA user rights config not + * found exception + */ + public static List readRoleRightsConfig() throws GNAUserRightsConfigNotFoundException { + + File configurationFile = null; + + try { + + InputStream in = (InputStream) GNARoleRitghtsConfigReader.class.getResourceAsStream(USER_RIGHTS_CONFIG_FILENAME); + configurationFile = FileUtil.inputStreamToTempFile(in, USER_RIGHTS_CONFIG_FILENAME); + CSVReader reader = new CSVReader(configurationFile); + CSVFile csvFile = reader.getCsvFile(); + List listUserRights = new ArrayList(); + + List headerKeys = csvFile.getHeaderRow().getListValues(); + List rows = csvFile.getValueRows(); + + // MAPPING OPERATION TYPE AS READ, WRITE, etc. + Map mapOperationTypes = new HashMap(); + CSVRow operationTypeRow = rows.get(0); + List rowValues = operationTypeRow.getListValues(); + for (int j = 1; j < rowValues.size(); j++) { + String operationType = rowValues.get(j); + RoleRights.OPERATION_TYPE ot = RoleRights.OPERATION_TYPE.UNKNOWN; + if (operationType.equalsIgnoreCase("R")) { + ot = RoleRights.OPERATION_TYPE.READ; + } else if (operationType.equalsIgnoreCase("RW")) { + ot = RoleRights.OPERATION_TYPE.READ_WRITE; + } else if (operationType.equalsIgnoreCase("W")) { + ot = RoleRights.OPERATION_TYPE.WRITE; + } + + mapOperationTypes.put(headerKeys.get(j), ot); + } + + LOG.debug("Map of operation types: " + mapOperationTypes); + + //Starting from index 1 (means the second row in the CSV) + for (int i = 1; i < rows.size(); i++) { + LOG.trace(i + " row"); + RoleRights useRights = new RoleRights(); + CSVRow row = rows.get(i); + + // to map properties + rowValues = row.getListValues(); + + LOG.debug("rowValues: " + rowValues); + Map mapUserRolePermissions = new HashMap(); + + GcubeUserRole gCubeUserRole = toGcubeUserRole(rowValues.get(0)); + + if (gCubeUserRole == null) { + LOG.warn("The Role " + rowValues.get(0) + " not found into roleName of: " + GcubeUserRole.values()); + continue; + } + + useRights.setUserRole(gCubeUserRole); + + for (int j = 1; j < rowValues.size(); j++) { + mapUserRolePermissions.put(headerKeys.get(j), rowValues.get(j)); + } + LOG.debug("Role: " + useRights.getUserRole()); + LOG.debug("Permissions read: " + mapUserRolePermissions); + + Map listPermessions = new HashMap(); + + for (ACTION_ON_ITEM value : ACTION_ON_ITEM.values()) { + String yesno = mapUserRolePermissions.get(value.name()); + + if (yesno != null && yesno.equalsIgnoreCase("yes")) { + listPermessions.put(value, mapOperationTypes.get(value.name())); + } + + } + + useRights.setListPermessions(listPermessions); + +// String writeOwn = mapUserRolePermissions.get(WRITE_OWN_CONFIG); +// if (writeOwn != null && writeOwn.equalsIgnoreCase("yes")) { +// useRights.setWriteOwn(true); +// } +// +// String writeAny = mapUserRolePermissions.get(WRITE_ANY_CONFIG); +// if (writeAny != null && writeAny.equalsIgnoreCase("yes")) { +// useRights.setWriteAny(true); +// } + + listUserRights.add(useRights); + + } + Log.info("Returning user rights config: " + listUserRights); + return listUserRights; + + } catch (IOException e) { + LOG.error("An error occurred on reading the property file " + USER_RIGHTS_CONFIG_FILENAME, e); + throw new GNAUserRightsConfigNotFoundException("Error on reading the base layers. Is the file '" + + USER_RIGHTS_CONFIG_FILENAME + "' in the application path?"); + } finally { + + if (configurationFile != null) { + try { + configurationFile.delete(); + } catch (Exception e) { + // silent + } + } + } + + } + + /** + * To gcube user role. + * + * @param name the name + * @return the gcube user role + */ + public static GcubeUserRole toGcubeUserRole(String name) { + + for (GcubeUserRole gCubeUserRole : GcubeUserRole.values()) { + if (gCubeUserRole.getName().equalsIgnoreCase(name)) + return gCubeUserRole; + } + + return null; + } +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNA_RoleRights_Configurations.csv b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNA_RoleRights_Configurations.csv new file mode 100644 index 0000000..8678509 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNA_RoleRights_Configurations.csv @@ -0,0 +1,5 @@ +,CREATE_NEW_PROJECT,VIEW_ON_MAP,VIEW_REPORT,EDIT_PROJECT,DELETE_PROJECT +OPERATION_TYPE,W,R,RW,RW,RW +Data-Member,no,yes,no,no,no +Data-Editor,yes,yes,yes,yes,yes +Data-Manager,yes,yes,yes,yes,yes diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ACTION_ON_ITEM.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ACTION_ON_ITEM.java new file mode 100644 index 0000000..a8aea03 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ACTION_ON_ITEM.java @@ -0,0 +1,29 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +/** + * The Class ACTION_ON_ITEM. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 24, 2021 + */ +public enum ACTION_ON_ITEM { + + CREATE_NEW_PROJECT("Create New Project"), + VIEW_ON_MAP("View on Map"), + SHOW_METADATA("Show Metadata"), + VIEW_REPORT("View the Report"), + EDIT_PROJECT("Edit the Project"), + DELETE_PROJECT("Delete the Project"); + + String label; + + ACTION_ON_ITEM(String label){ + this.label = label; + } + + public String getLabel() { + return label; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ActionOnItemType.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ActionOnItemType.java new file mode 100644 index 0000000..9d3dbae --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ActionOnItemType.java @@ -0,0 +1,5 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +public class ActionOnItemType { + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigNotFoundException.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigNotFoundException.java new file mode 100644 index 0000000..525c906 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigNotFoundException.java @@ -0,0 +1,8 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +@SuppressWarnings("serial") +public class GNAUserRightsConfigNotFoundException extends Exception { + public GNAUserRightsConfigNotFoundException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GcubeUserRole.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GcubeUserRole.java new file mode 100644 index 0000000..bdb8845 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GcubeUserRole.java @@ -0,0 +1,55 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +/** + * The Enum GcubeUserRole. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 25, 2021 + */ +public enum GcubeUserRole { + + DATA_MEMBER("Data-Member", false, false), + DATA_EDITOR("Data-Editor", true, false), + DATA_MANAGER("Data-Manager", true, true); + + private String name; + private boolean writeOwn; + private boolean writeAny; + + /** + * Instantiates a new gcube user role. + * + * @param name the name + */ + private GcubeUserRole(String name, boolean writeOwn, boolean writeAny) { + this.name = name; + this.writeOwn = writeOwn; + this.writeAny = writeAny; + } + + public String getName() { + return name; + } + + public boolean isWriteOwn() { + return writeOwn; + } + + public boolean isWriteAny() { + return writeAny; + } + + public void setName(String name) { + this.name = name; + } + + public void setWriteOwn(boolean writeOwn) { + this.writeOwn = writeOwn; + } + + public void setWriteAny(boolean writeAny) { + this.writeAny = writeAny; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/RoleRights.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/RoleRights.java new file mode 100644 index 0000000..1854240 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/RoleRights.java @@ -0,0 +1,100 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +import java.io.Serializable; +import java.util.Map; + +/** + * The Class RoleRights. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 26, 2021 + */ +public class RoleRights implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -304157165851633221L; + + /** + * The Enum OPERATION_TYPE. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 26, 2021 + */ + public static enum OPERATION_TYPE { + READ, WRITE, READ_WRITE, UNKNOWN + } + + private Map listPermessions; + private GcubeUserRole userRole; + + /** + * Instantiates a new user rights. + */ + public RoleRights() { + super(); + } + + /** + * Instantiates a new role rights. + * + * @param myUsername the my username + * @param listPermessions the list permessions + * @param userRole the user role + */ + public RoleRights(Map listPermessions, GcubeUserRole userRole) { + this.listPermessions = listPermessions; + this.userRole = userRole; + } + + /** + * Gets the list permessions. + * + * @return the list permessions + */ + public Map getListPermessions() { + return listPermessions; + } + + /** + * Gets the user role. + * + * @return the user role + */ + public GcubeUserRole getUserRole() { + return userRole; + } + + /** + * Sets the list permessions. + * + * @param listPermessions the list permessions + */ + public void setListPermessions(Map listPermessions) { + this.listPermessions = listPermessions; + } + + /** + * Sets the user role. + * + * @param userRole the new user role + */ + public void setUserRole(GcubeUserRole userRole) { + this.userRole = userRole; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("RoleRights [listPermessions="); + builder.append(listPermessions); + builder.append(", userRole="); + builder.append(userRole); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java new file mode 100644 index 0000000..4750a16 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java @@ -0,0 +1,63 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +import java.io.Serializable; + +/** + * The Class UserRights. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 24, 2021 + */ +public class UserRights implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -304157165851633221L; + + private String myUsername; + + private RoleRights roleRights; + + /** + * Instantiates a new user rights. + */ + public UserRights() { + super(); + } + + public UserRights(String myUsername, RoleRights roleRights) { + super(); + this.myUsername = myUsername; + this.roleRights = roleRights; + } + + public String getMyUsername() { + return myUsername; + } + + public RoleRights getRoleRights() { + return roleRights; + } + + public void setMyUsername(String myUsername) { + this.myUsername = myUsername; + } + + public void setRoleRights(RoleRights roleRights) { + this.roleRights = roleRights; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("UserRights [myUsername="); + builder.append(myUsername); + builder.append(", roleRights="); + builder.append(roleRights); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index b3d9e17..f2d3d38 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -10,35 +10,40 @@ import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader; +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; +import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; +import org.junit.Before; +import org.junit.Test; public class TestClass { - private static String TOKEN = ""; - private static String CONTEXT ="/gcube/devsec/devVRE"; - - - public static void main(String[] args) throws Exception { + private static String CONTEXT = "/gcube/devsec/devVRE"; + private static String USERNAME = "francesco.mangiacrapa"; + +// LocalDateTime ldt = ConvertToServiceModel.toLocalDateTime("2020-10-01 10:20"); +// System.out.println(ldt.toString()); +// +// String latitudine = "-899.2986"; +// // System.out.println(latitudine.matches("^[-]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); +// +// String longitude = "0"; +// System.out.println(longitude.matches("\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); +// +// GeoportalDataEntryServiceImpl g = new GeoportalDataEntryServiceImpl(); +// g.getLinksFor("", ConstantsGeoPortalDataEntryApp.RECORD_TYPE.CONCESSIONE.toString()); + + // getListOfConcessioni(); + + @Before + public void init() { ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); - -// LocalDateTime ldt = ConvertToServiceModel.toLocalDateTime("2020-10-01 10:20"); -// System.out.println(ldt.toString()); -// -// String latitudine = "-899.2986"; -// // System.out.println(latitudine.matches("^[-]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); -// -// String longitude = "0"; -// System.out.println(longitude.matches("\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); -// -// GeoportalDataEntryServiceImpl g = new GeoportalDataEntryServiceImpl(); -// g.getLinksFor("", ConstantsGeoPortalDataEntryApp.RECORD_TYPE.CONCESSIONE.toString()); - - getListOfConcessioni(); - } - public static void getListOfConcessioni() throws Exception { + //@Test + public void getListConcessioniTest() throws Exception { MongoConcessioni clientMongo = mongoConcessioni().build(); Iterator concessioni = clientMongo.getList(); List listOfConcessioni = new ArrayList(); @@ -46,13 +51,20 @@ public class TestClass { while (concessioni.hasNext()) { Concessione concessione = (Concessione) concessioni.next(); listOfConcessioni.add(concessione); - + } } int i = 0; for (Concessione concessione : listOfConcessioni) { - System.out.println(++i+" "+concessione); + System.out.println(++i + " " + concessione); } } + @Test + public void readUserRights() throws Exception { + new GNARoleRitghtsConfigReader(); + List listUserRights = GNARoleRitghtsConfigReader.readRoleRightsConfig(); + System.out.println(listUserRights); + } + } From 6840535bc1ee0372e79f902ad3839bebc3817d03 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 Nov 2021 16:06:35 +0100 Subject: [PATCH 02/16] commented Junit Tests --- .../portlets/user/geoportaldataentry/client/TestClass.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index f2d3d38..453ed95 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -12,7 +12,6 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader; import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; -import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.junit.Before; import org.junit.Test; @@ -36,7 +35,7 @@ public class TestClass { // getListOfConcessioni(); - @Before + //@Before public void init() { ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); @@ -60,7 +59,7 @@ public class TestClass { } } - @Test + //@Test public void readUserRights() throws Exception { new GNARoleRitghtsConfigReader(); List listUserRights = GNARoleRitghtsConfigReader.readRoleRightsConfig(); From ee1e3d83096a36d179493c191e89ef75717424fb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 Nov 2021 16:48:13 +0100 Subject: [PATCH 03/16] fixed pom to include resources of kind *.csv --- pom.xml | 16 ++++++++++++++++ .../server/GeoportalDataEntryServiceImpl.java | 4 ++-- .../config/GNARoleRitghtsConfigReader.java | 15 ++++++++------- .../shared/GNAUserRightsConfigException.java | 8 ++++++++ .../GNAUserRightsConfigNotFoundException.java | 8 -------- .../geoportaldataentry/client/TestClass.java | 14 -------------- 6 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigException.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigNotFoundException.java diff --git a/pom.xml b/pom.xml index 6196c99..1b9b368 100644 --- a/pom.xml +++ b/pom.xml @@ -209,6 +209,22 @@ update them in DevMode --> ${webappDirectory}/WEB-INF/classes + + + src/main/java + + **/*.csv + + + + + + + + + + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index db01754..6a6ec99 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -34,7 +34,7 @@ import org.gcube.portlets.user.geoportaldataentry.server.MongoServiceUtil.Conces import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader; import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; -import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigNotFoundException; +import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException; import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; @@ -920,7 +920,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen UserRights userRights = new UserRights(scope, toRoleRight); LOG.info("returning: " + userRights); return userRights; - } catch (UserRetrievalFault | GroupRetrievalFault | GNAUserRightsConfigNotFoundException e) { + } catch (UserRetrievalFault | GroupRetrievalFault | GNAUserRightsConfigException e) { LOG.error("An error occurred during getMyRightsInTheContext: " + user, e); Map permissions = new HashMap(); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java index 6a97d8b..81cc0c7 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.Map; import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; -import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigNotFoundException; +import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException; import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; @@ -37,11 +37,12 @@ public class GNARoleRitghtsConfigReader { * Read user rights config. * * @return the list - * @throws GNAUserRightsConfigNotFoundException the GNA user rights config not + * @throws GNAUserRightsConfigException the GNA user rights config not * found exception */ - public static List readRoleRightsConfig() throws GNAUserRightsConfigNotFoundException { - + public static List readRoleRightsConfig() throws GNAUserRightsConfigException { + LOG.debug("readRoleRightsConfig called"); + File configurationFile = null; try { @@ -131,9 +132,9 @@ public class GNARoleRitghtsConfigReader { Log.info("Returning user rights config: " + listUserRights); return listUserRights; - } catch (IOException e) { - LOG.error("An error occurred on reading the property file " + USER_RIGHTS_CONFIG_FILENAME, e); - throw new GNAUserRightsConfigNotFoundException("Error on reading the base layers. Is the file '" + } catch (Exception e) { + LOG.error("An error occurred on reading the configuration file " + USER_RIGHTS_CONFIG_FILENAME, e); + throw new GNAUserRightsConfigException("Error on reading the configuration file. Is the file '" + USER_RIGHTS_CONFIG_FILENAME + "' in the application path?"); } finally { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigException.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigException.java new file mode 100644 index 0000000..7684f94 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigException.java @@ -0,0 +1,8 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +@SuppressWarnings("serial") +public class GNAUserRightsConfigException extends Exception { + public GNAUserRightsConfigException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigNotFoundException.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigNotFoundException.java deleted file mode 100644 index 525c906..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigNotFoundException.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.shared; - -@SuppressWarnings("serial") -public class GNAUserRightsConfigNotFoundException extends Exception { - public GNAUserRightsConfigNotFoundException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index 453ed95..14af4bd 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -21,20 +21,6 @@ public class TestClass { private static String CONTEXT = "/gcube/devsec/devVRE"; private static String USERNAME = "francesco.mangiacrapa"; -// LocalDateTime ldt = ConvertToServiceModel.toLocalDateTime("2020-10-01 10:20"); -// System.out.println(ldt.toString()); -// -// String latitudine = "-899.2986"; -// // System.out.println(latitudine.matches("^[-]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); -// -// String longitude = "0"; -// System.out.println(longitude.matches("\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$")); -// -// GeoportalDataEntryServiceImpl g = new GeoportalDataEntryServiceImpl(); -// g.getLinksFor("", ConstantsGeoPortalDataEntryApp.RECORD_TYPE.CONCESSIONE.toString()); - - // getListOfConcessioni(); - //@Before public void init() { ScopeProvider.instance.set(CONTEXT); From ced697f140a6e98264fa37aad838b923f3725670 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 Nov 2021 16:55:43 +0100 Subject: [PATCH 04/16] removed lock file --- .../server/config/.~lock.GNA_UserRights_Configurations.csv# | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/.~lock.GNA_UserRights_Configurations.csv# diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/.~lock.GNA_UserRights_Configurations.csv# b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/.~lock.GNA_UserRights_Configurations.csv# deleted file mode 100644 index 23f831e..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/.~lock.GNA_UserRights_Configurations.csv# +++ /dev/null @@ -1 +0,0 @@ -,francescomangiacrapa,francesco-xps,26.11.2021 11:54,file:///home/francescomangiacrapa/.config/libreoffice/4; \ No newline at end of file From 2de36fd513f5ef5bf2335349999593dfe60b2429 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 Nov 2021 16:59:45 +0100 Subject: [PATCH 05/16] fixing code --- .../server/GeoportalDataEntryServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index 6a6ec99..ddb18a4 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -917,7 +917,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen break; } } - UserRights userRights = new UserRights(scope, toRoleRight); + UserRights userRights = new UserRights(user.getUsername(), toRoleRight); LOG.info("returning: " + userRights); return userRights; } catch (UserRetrievalFault | GroupRetrievalFault | GNAUserRightsConfigException e) { From acae8dd7354a8d690132ba87a5ad655f83a29581 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 Nov 2021 17:06:05 +0100 Subject: [PATCH 06/16] updated modal window --- .../portlets/user/geoportaldataentry/client/ui/ModalWindow.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java index c18f8df..f52934b 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/ModalWindow.java @@ -18,7 +18,7 @@ public class ModalWindow { public ModalWindow(Image icon, String title, String msg, AlertType alertType) { - modal = new Modal(false); + modal = new Modal(true,true); modal.hide(false); modal.setTitle(title); modal.setCloseVisible(true); From 2b98a0849c434e48bf605bf340c2fdab5b9668cb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 1 Dec 2021 11:54:39 +0100 Subject: [PATCH 07/16] #22287 starting integration with the base search, ordering and filtering facility provided by MongoDB --- .classpath | 7 +- .settings/org.eclipse.wst.common.component | 43 +-- CHANGELOG.md | 1 + .../ConstantsGeoPortalDataEntryApp.java | 7 +- .../client/GeoPortalDataEntryApp.java | 8 +- .../client/GeoportalDataEntryService.java | 4 +- .../GeoportalDataEntryServiceAsync.java | 4 +- .../client/events/GetListOfRecordsEvent.java | 8 +- .../client/ui/GeonaMainTabPanel.java | 174 +++++---- .../client/ui/GeonaMainTabPanel.ui.xml | 23 +- .../client/ui/GeonaRecordsPaginatedView.java | 23 +- .../client/ui/table/ItemsTable.java | 88 +---- .../server/GeoportalDataEntryServiceImpl.java | 336 ++++++++++-------- .../server/SessionUtil.java | 2 +- .../config/GNARoleRitghtsConfigReader.java | 1 - .../shared/DisplayField.java | 66 ++++ .../shared/ResultSetPaginatedData.java | 73 ++-- .../shared/ResultSetSorted.java | 8 +- .../{SortFilter.java => SearchingFilter.java} | 54 ++- src/main/webapp/GeoPortalDataEntryApp.css | 22 ++ .../geoportaldataentry/client/TestClass.java | 92 ++++- 21 files changed, 623 insertions(+), 421 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/DisplayField.java rename src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/{SortFilter.java => SearchingFilter.java} (63%) diff --git a/.classpath b/.classpath index 7edc167..d8296e1 100644 --- a/.classpath +++ b/.classpath @@ -1,16 +1,11 @@ - + - - - - - diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 4c4808d..d89609f 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -20,7 +21,8 @@ - + + @@ -41,7 +43,8 @@ - + + @@ -62,7 +65,8 @@ - + + @@ -83,7 +87,7 @@ - + @@ -103,29 +107,10 @@ - - - - - - - - - - - - - - - - - - - - - + + @@ -146,7 +131,8 @@ - + + @@ -167,7 +153,8 @@ - + + diff --git a/CHANGELOG.md b/CHANGELOG.md index fede67f..f4c2f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm #### Enhancements - [#22455] Integrated with roles: (Data-Member as default), Data-Manager, Data-Editor +- [#22287] Integrated with base search, ordering and filtering facility provided by MongoDB ## [v2.0.1] - 2021-11-17 diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index 95d5323..575dc33 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -47,9 +47,9 @@ public class ConstantsGeoPortalDataEntryApp { * Sep 2, 2021 */ public static enum RECORD_FIELD { - NAME("name", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("author", "Author/s"), - PROJECT_START_END_DATE("", "Project Start/End Date"), RECORD_STATUS("recordStatus", "Published with"), CREATED("created", "Created"), - CREATED_BY("createdBy", "Created by"); + NAME("nome", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("author", "Author/s"), + PROJECT_START_END_DATE("", "Project Start/End Date"), RECORD_STATUS("recordStatus", "Published with"), CREATED("creationTime", "Created"), + CREATED_BY("creationUser", "Created by"); String jsonFieldName; String displayName; @@ -83,5 +83,6 @@ public class ConstantsGeoPortalDataEntryApp { return displayName; } } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index 8ca2bd1..27ca84e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -45,8 +45,8 @@ import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.ORDER; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync; import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm; @@ -116,7 +116,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { RECORD_FIELD[] sortByOptions = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.PROJECT_START_END_DATE, RECORD_FIELD.CREATED, RECORD_FIELD.CREATED_BY, RECORD_FIELD.RECORD_STATUS }; - SortFilter initialSortFilter = new SortFilter(RECORD_FIELD.NAME, ORDER.ASC); + SearchingFilter initialSortFilter = new SearchingFilter(RECORD_FIELD.NAME, ORDER.ASC); RootPanel.get(DIV_PORTLET_ID).add(loader); @@ -499,7 +499,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { @Override public void onGetList(GetListOfRecordsEvent getListOfRecordsEvent) { - SortFilter sortFilter = getListOfRecordsEvent.getSortFilter(); + SearchingFilter sortFilter = getListOfRecordsEvent.getSortFilter(); if (sortFilter == null) { sortFilter = mainTabPanel.getCurrentSortFilter(); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java index d596c09..9febbfa 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java @@ -11,7 +11,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; @@ -64,7 +64,7 @@ public interface GeoportalDataEntryService extends RemoteService { * @return the list concessioni * @throws Exception the exception */ - public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SortFilter filter, + public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService) throws Exception; /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java index acc75a4..f9bfb96 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java @@ -11,7 +11,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; @@ -53,7 +53,7 @@ public interface GeoportalDataEntryServiceAsync void getLinksFor(String itemId, RECORD_TYPE recordType, AsyncCallback callback); - void getListConcessioni(Integer start, Integer limit, SortFilter filter, boolean reloadFromService, + void getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService, AsyncCallback callback); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java index cbea945..3f85aaa 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java @@ -2,7 +2,7 @@ package org.gcube.portlets.user.geoportaldataentry.client.events; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; import com.google.gwt.event.shared.GwtEvent; @@ -18,12 +18,12 @@ public class GetListOfRecordsEvent extends GwtEvent TYPE = new Type(); private RECORD_TYPE recordType; - private SortFilter sortFilter; + private SearchingFilter sortFilter; /** * Instantiates a new cancel upload event. */ - public GetListOfRecordsEvent(ConstantsGeoPortalDataEntryApp.RECORD_TYPE recordType, SortFilter sortFilter) { + public GetListOfRecordsEvent(ConstantsGeoPortalDataEntryApp.RECORD_TYPE recordType, SearchingFilter sortFilter) { this.recordType = recordType; this.sortFilter = sortFilter; } @@ -64,7 +64,7 @@ public class GetListOfRecordsEvent extends GwtEvent(listConcessioni, ACTION_ON_ITEM.EDIT_PROJECT)); + appManagerBus + .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.EDIT_PROJECT)); } }); @@ -251,11 +269,46 @@ public class GeonaMainTabPanel extends Composite { if (grpw != null && grpw.getSelectItems() != null) { listConcessioni = grpw.getSelectItems(); } - appManagerBus - .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.DELETE_PROJECT)); + appManagerBus.fireEvent( + new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.DELETE_PROJECT)); } }); + searchField.addKeyPressHandler(new KeyPressHandler() { + + @Override + public void onKeyPress(KeyPressEvent event) { + GWT.log("CHAR CODE: " + event.getCharCode()); + if (com.google.gwt.event.dom.client.KeyCodes.KEY_ENTER == event.getCharCode()) { + GWT.log(searchField.getText()); + String searchText = searchField.getText(); + if (searchText.length() < MIN_LENGHT_SERCHING_STRING) { + Window.alert("Please enter at least "+MIN_LENGHT_SERCHING_STRING+" characters"); + return; + } + + resetSearch.setVisible(true); + appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); + } + + } + }); + + resetSearch.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + searchField.setText(""); + appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); + resetSearch.setVisible(false); + } + }); + + } + + private String toLabelFilter(RECORD_FIELD orderBy, ORDER direction) { + String labelFilter = orderBy.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name(); + return labelFilter; } /** @@ -292,48 +345,43 @@ public class GeonaMainTabPanel extends Composite { loader.setVisible(visible); } - private void setCurrentSortFilter(SortFilter sortFilter) { - this.currentSortFilter = sortFilter; - this.textBoxSortBy.setText(toLabelFilter(sortFilter)); + public SearchingFilter toSortFilter(String labelFilter) { + GWT.log("toSortFilter for label " + labelFilter); + String[] array = labelFilter.split(LABEL_FILTER_SEPARATOR); + + SearchingFilter sortFilter = null; + try { + RECORD_FIELD recordField = null; + for (RECORD_FIELD value : RECORD_FIELD.values()) { + if (array[0].equalsIgnoreCase(value.getDisplayName())) { + recordField = value; + break; + } + } + ORDER orderField = ORDER.valueOf(array[1]); + sortFilter = new SearchingFilter(recordField, orderField); + } catch (Exception e) { + + } + GWT.log("toSortFilter Got " + sortFilter); + return sortFilter; + } - /** - * To label filter. - * - * @param sortFilter the sort filter - * @return the string - */ - public String toLabelFilter(SortFilter sortFilter) { - - String labelFilter = sortFilter.getOrderByField().getDisplayName() + LABEL_FILTER_SEPARATOR - + sortFilter.getOrder().name(); - GWT.log("Got " + sortFilter); - return labelFilter; + private SearchingFilter builtSearchingFilter() { + SearchingFilter searchingFilter = toSortFilter(this.textBoxSortBy.getText()); + String searchText = searchField.getText(); + if (searchText != null && !searchText.isEmpty()) { + Map searchInto = new HashMap(); + searchInto.put(RECORD_FIELD.NAME.getJsonFieldName(), searchText); + searchingFilter.setSearchInto(searchInto); + } + return searchingFilter; } - /** - * To sort filter. - * - * @param labelFilter the label filter - * @return the sort filter - */ - /* - * public SortFilter toSortFilter(String labelFilter) { - * - * String[] array = labelFilter.split(LABEL_FILTER_SEPARATOR); - * - * SortFilter sortFilter = null; try { RECORD_FIELD recordField = - * RECORD_FIELD.valueOf(array[0]); ORDER orderField = ORDER.valueOf(array[1]); - * sortFilter = new SortFilter(recordField, orderField); } catch (Exception e) { - * - * } - * - * GWT.log("Got " + sortFilter); return sortFilter; - * - * } - */ - - public SortFilter getCurrentSortFilter() { + public SearchingFilter getCurrentSortFilter() { + currentSortFilter = builtSearchingFilter(); + GWT.log("currentSortFilter: " + currentSortFilter); return currentSortFilter; } @@ -344,13 +392,13 @@ public class GeonaMainTabPanel extends Composite { public void setTabActive(int index) { tabPanel.selectTab(index); } - + /** - * Dirty solution. - * I created this one because I had problem on firing click event for Tab element + * Dirty solution. I created this one because I had problem on firing click + * event for Tab element * */ - public void instanceAndShowListOfConcessioni(){ + public void instanceAndShowListOfConcessioni() { grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, currentSortFilter); showListOfConcessioniView(grpw); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml index 346c494..116dff0 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml @@ -32,13 +32,22 @@ text-align: right; } + .display-right { + float: right; + } + .max-height-300 { max-height: auto; } - .margin-botttom-5 { + .margin-bottom-5 { margin-bottom: 5px !important; } + + .search-field { + padding-top: 6px; + margin-top: 2px; + } - + New Project - - List of Projects + + List of Projects @@ -99,6 +108,12 @@ Reload Projects + + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java index ca84a21..97277c4 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java @@ -10,7 +10,7 @@ import org.gcube.portlets.user.geoportaldataentry.client.ui.table.ItemsTable; import org.gcube.portlets.user.geoportaldataentry.client.ui.table.SortedCellTable; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; import com.google.gwt.core.client.GWT; import com.google.gwt.event.shared.HandlerManager; @@ -47,10 +47,10 @@ public class GeonaRecordsPaginatedView { private MyCustomDataProvider dataProvider = new MyCustomDataProvider(); protected Widget orginalLoadingIndicator = null; private LoaderIcon loadingPanel = new LoaderIcon("Loading data..."); - private int serverStartIndex; + //private int serverStartIndex; private HandlerManager eventBus; private RECORD_TYPE recordType; - private SortFilter currentSortFilter; + private SearchingFilter currentSortFilter; /** * Instantiates a new geona records paginated view. @@ -61,12 +61,12 @@ public class GeonaRecordsPaginatedView { * @param currentSortFilter the sort by field */ public GeonaRecordsPaginatedView(HandlerManager eventbus, RECORD_TYPE recordType, - RECORD_FIELD[] displayFields, SortFilter currentSortFilter) { + RECORD_FIELD[] displayFields, SearchingFilter currentSortFilter) { this.recordType = recordType; this.currentSortFilter = currentSortFilter; this.initClassFirstRangeChanged = true; this.eventBus = eventbus; - itemsTable = new ItemsTable(eventbus, displayFields, currentSortFilter); + itemsTable = new ItemsTable(eventbus, displayFields); itemsTable.initTable(null, null, dataProvider); orginalLoadingIndicator = itemsTable.getCellTable().getLoadingIndicator(); @@ -120,7 +120,7 @@ public class GeonaRecordsPaginatedView { * @param invalidCache the invalid cache */ private void loadNewPage(final int startIdx, final int limit, final boolean resetStore, - final SortFilter currentSortFilter, final boolean invalidCache) { + final SearchingFilter currentSortFilter, final boolean invalidCache) { // initFirstRangeChanged = resetStore; GWT.log("loadNewPage with parameters [startIdx: " + startIdx + ", limit: " + limit + ", resetStore:" + resetStore + "]"); @@ -131,12 +131,12 @@ public class GeonaRecordsPaginatedView { if (resetStore) { GWT.log("Cleaning all data..."); newStartIndex = 0; - serverStartIndex = 0; + //serverStartIndex = 0; GWT.log("Store reset performed start index is: " + newStartIndex); getTableDataProvider().updateRowCount(ITEMS_PER_PAGE, false); } - loadConcessioni(newStartIndex, limit, serverStartIndex, currentSortFilter, invalidCache); + loadConcessioni(newStartIndex, limit, currentSortFilter, invalidCache); } /** @@ -157,7 +157,7 @@ public class GeonaRecordsPaginatedView { */ private void setNewPageResult(ResultSetPaginatedData result) { GWT.log("setNewPageResult: " + result); - serverStartIndex = result.getServerEndIndex(); + //serverStartIndex = result.getServerEndIndex(); SelectionModel sm = getCellTable().getSelectionModel(); if (sm instanceof SingleSelectionModel) { @@ -197,12 +197,11 @@ public class GeonaRecordsPaginatedView { * @param limit the limit * @param serverIndex the server index */ - private void loadConcessioni(int newStartIndex, int limit, int serverIndex, SortFilter sortFilter, + private void loadConcessioni(int newStartIndex, int limit, SearchingFilter sortFilter, boolean invalidCache) { showLoading(true); - GWT.log("calling loadItemsForStatus with parameters [startIndex: " + newStartIndex + ", limit: " + limit - + ", serverIndex:" + serverIndex + ", sortFilter: " + sortFilter + "]"); + GWT.log("calling loadItemsForStatus with parameters [startIndex: " + newStartIndex + ", limit: " + limit+ ", sortFilter: " + sortFilter + "]"); GeoPortalDataEntryApp.geoportalDataEntryService.getListConcessioni(newStartIndex, limit, sortFilter, invalidCache, new AsyncCallback() { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java index f7b0ca0..a15f001 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java @@ -15,7 +15,6 @@ import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV; import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV.ValidationStatus; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; import com.github.gwtbootstrap.client.ui.ButtonCell; import com.github.gwtbootstrap.client.ui.Pagination; @@ -68,7 +67,6 @@ public class ItemsTable extends AbstractItemsCellTable< private boolean isAsyncronusTable; private TextColumn insertedBy; private Column createdColumn; - private SortFilter currentSortFilter; /** * Instantiates a new items table. @@ -77,9 +75,8 @@ public class ItemsTable extends AbstractItemsCellTable< * @param displayFields the display fields * @param startSortByColumn the start sort by column */ - public ItemsTable(HandlerManager eventBus, RECORD_FIELD[] displayFields, SortFilter currentSortFilter) { + public ItemsTable(HandlerManager eventBus, RECORD_FIELD[] displayFields) { this.eventBus = eventBus; - this.currentSortFilter = currentSortFilter; setDisplayFields(displayFields); } @@ -335,89 +332,6 @@ public class ItemsTable extends AbstractItemsCellTable< sortedCellTable.setColumnWidth(statusColumn, 120, Unit.PX); } - -// ButtonCell showOnMapButton = new ButtonCell(); -// showOnMapButton.setIcon(IconType.MAP_MARKER); -// -// MyToolTipColumn showOnMapColumn = new MyToolTipColumn(showOnMapButton, "Show on Map") { -// -// @Override -// public String getValue(T object) { -// return ""; -// } -// }; -// -// showOnMapColumn.setFieldUpdater(new FieldUpdater() { -// @Override -// public void update(int index, T object, String value) { -// GWT.log("clicked show"); -// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.VIEW_ON_MAP)); -// } -// }); -// sortedCellTable.addColumn(showOnMapColumn); -// sortedCellTable.setColumnWidth(showOnMapColumn, 50, Unit.PX); -// -// ButtonCell showReportRecordButton = new ButtonCell(); -// showReportRecordButton.setIcon(IconType.FILE_TEXT_ALT); -// MyToolTipColumn showReportRecordColumn = new MyToolTipColumn(showReportRecordButton, -// "Show Publication Report") { -// public String getValue(T object) { -// return ""; -// } -// }; -// -// showReportRecordColumn.setFieldUpdater(new FieldUpdater() { -// @Override -// public void update(int index, T object, String value) { -// -// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.VIEW_REPORT)); -// } -// }); -// sortedCellTable.addColumn(showReportRecordColumn); -// sortedCellTable.setColumnWidth(showReportRecordColumn, 50, Unit.PX); -// -// ButtonCell deleteRecordButton = new ButtonCell(); -// deleteRecordButton.setIcon(IconType.TRASH); -// MyToolTipColumn deleteRecordColumn = new MyToolTipColumn(deleteRecordButton, -// "Delete Project") { -// public String getValue(T object) { -// return ""; -// } -// }; -// -// deleteRecordColumn.setFieldUpdater(new FieldUpdater() { -// @Override -// public void update(int index, T object, String value) { -// -// eventBus.fireEvent(new ActionOnItemEvent(Arrays.asList(object), ACTION_ON_ITEM.DELETE_PROJECT)); -// } -// }); -// sortedCellTable.addColumn(deleteRecordColumn); -// sortedCellTable.setColumnWidth(deleteRecordColumn, 50, Unit.PX); - - GWT.log("currentSortFilter: " + currentSortFilter); - - if (currentSortFilter != null) - switch (currentSortFilter.getOrderByField()) { - case NAME: - if (this.displayFields.contains(RECORD_FIELD.NAME)) { - sortedCellTable.setInitialSortColumn(name); - } - break; - case INTRODUCTION: - if (this.displayFields.contains(RECORD_FIELD.INTRODUCTION)) { - sortedCellTable.setInitialSortColumn(introduction); - } - break; - case AUTHOR: - if (this.displayFields.contains(RECORD_FIELD.AUTHOR)) { - sortedCellTable.setInitialSortColumn(author); - } - break; - default: - break; - } - } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index ddb18a4..b08656c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -1,12 +1,13 @@ package org.gcube.portlets.user.geoportaldataentry.server; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; +import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import org.bson.Document; import org.gcube.application.geoportal.common.model.legacy.AbstractRelazione; import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths; @@ -15,6 +16,10 @@ import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo; import org.gcube.application.geoportal.common.model.legacy.UploadedImage; import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport; import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest; +import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction; +import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest; import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportalcommon.ConvertToDataViewModel; @@ -30,10 +35,10 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitl import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; -import org.gcube.portlets.user.geoportaldataentry.server.MongoServiceUtil.ConcessioneValidationReportStatusComparator; import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader; import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.DisplayField; import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException; import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; @@ -41,8 +46,8 @@ import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; -import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter.ORDER; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; +import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; @@ -56,6 +61,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.mongodb.BasicDBObject; /** * The server side implementation of the RPC service. @@ -408,6 +414,176 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen return item; } + /** + * Query on mongo. + * + * @param offset the offset + * @param limit the limit + * @param filter the filter + * @param recordType the record type + * @param reloadFromService the reload from service + * @return the result set paginated data + * @throws Exception the exception + */ + private ResultSetPaginatedData queryOnMongo(Integer offset, Integer limit, SearchingFilter filter, String recordType, + boolean reloadFromService) throws Exception { + + try { + + if (recordType.equalsIgnoreCase(RECORD_TYPE.CONCESSIONE.name())) { + SessionUtil.getCurrentContext(getThreadLocalRequest(), true); + MongoServiceUtil serviceUtil = new MongoServiceUtil(); + MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); + + // TODO MUST BE REPLACED BY COUNT + List listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(), + reloadFromService); + int listConcessioniSize = listOfConcessioni.size(); + + Integer offsetIndex = offset; + Integer limitIndex = limit; + + if (offset == null) { + offsetIndex = 0; + } + if (limit == null) { + limitIndex = listConcessioniSize; + } + + ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false); + searchedData.setTotalItems(listConcessioniSize); + + List toReturnList = new ArrayList(); + Direction sDirection = null; + List fields = new ArrayList(); + + if (filter == null) { + LOG.info("No filter found, creating empty filter"); + filter = new SearchingFilter(); + } + + ORDER order = filter.getOrder(); + + if (order == null) { + sDirection = Direction.ASCENDING; + LOG.info("No direction/order found, using default: " + sDirection); + } + + switch (order) { + case ASC: + sDirection = Direction.ASCENDING; + break; + case DESC: + sDirection = Direction.DESCENDING; + break; + } + + RECORD_FIELD orderByFields = filter.getOrderByField(); + + if (orderByFields == null) { + orderByFields = RECORD_FIELD.NAME; + LOG.info("No fields for searching found, using default: " + orderByFields); + } + + switch (orderByFields) { + case NAME: + fields.add(RECORD_FIELD.NAME.getJsonFieldName()); + break; + case CREATED: + fields.add(RECORD_FIELD.CREATED.getJsonFieldName()); + break; + case CREATED_BY: + fields.add(RECORD_FIELD.CREATED_BY.getJsonFieldName()); + break; + // TODO is buggy must be performed by service + case PROJECT_START_END_DATE: + fields.add("dataInizioProgetto"); + fields.add("dataFineProgetto"); + break; + case RECORD_STATUS: + fields.add("report:status"); + // statusComparator = new ConcessioneValidationReportStatusComparator(); + default: + break; + } + + QueryRequest request = new QueryRequest(); + PagedRequest paging = new PagedRequest(); + paging.setOffset(offsetIndex); + paging.setLimit(limitIndex); + request.setPaging(paging); + + OrderedRequest ordering = new OrderedRequest(); + ordering.setDirection(sDirection); + ordering.setFields(fields); + request.setOrdering(ordering); + + if(filter.getSearchInto()!=null) { + Map searchFields = filter.getSearchInto(); + //List list = new ArrayList(); + //Map map = new HashMap(); + Document query = new Document(); + + for (String key : searchFields.keySet()) { + query.put(key, searchFields.get(key)); + query.put(key, new BasicDBObject("$eq", searchFields.get(key))); + } + + request.setFilter(query); + } + + LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex); + LOG.info("Direction: " + sDirection); + LOG.info("Order by Fields: " + fields); + LOG.info("Search for: " + filter.getSearchInto()); + + Iterator concessioni = clientMongo.query(request); + while (concessioni.hasNext()) { + Concessione concessione = concessioni.next(); + ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); + toReturnList.add(concessioneDV); + } + + searchedData.setData(toReturnList); + + if (listConcessioniSize == limit || listConcessioniSize == 0) { + LOG.debug("Page completed returning " + listConcessioniSize + " items"); + int newOffset = offsetIndex + limitIndex; + searchedData.setServerSearchFinished(newOffset > listConcessioniSize || listConcessioniSize == 0); + LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); + + } + + return searchedData; + } + + } catch (Exception e) { + LOG.error("Error on loading paginated and filtered list of concessioni: ", e); + throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage()); + } + + return null; + + } + + // TODO THIS PART REQUIRES THE JSON MAPPING based on keys read from gCube Meta + /** + * List display fields. + * + * @return the list + */ + // Profile + public List listDisplayFields() { + + List listDisplayFields = new ArrayList(); + + DisplayField df = new DisplayField("Name", Arrays.asList("nome"), true); + // etc + + return listDisplayFields; + + } + /** * Gets the list concessioni. * @@ -419,150 +595,10 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen * @throws Exception the exception */ @Override - public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SortFilter filter, + public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService) throws Exception { LOG.info("getListConcessioni called wit start: " + start + ", limit: " + limit + ", filter: " + filter); - - try { - List listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(), - reloadFromService); - int listConcessioniSize = listOfConcessioni.size(); - - List toReturn = new ArrayList(); - int startIndex; - int limitIndex = 0; - if (start == null && limit == null) { - startIndex = 0; - limitIndex = listConcessioniSize; - } else { - startIndex = start; - limitIndex = start + limit; - if (limitIndex > listConcessioniSize) { - limitIndex = listConcessioniSize; - } - } - - ResultSetPaginatedData searchedData = new ResultSetPaginatedData(start, limit, startIndex, false); - searchedData.setTotalItems(listConcessioniSize); - - RECORD_FIELD orderBy = null; - ORDER order = null; - ConcessioneValidationReportStatusComparator statusComparator = null; - - if (filter == null) { - // unsorted list of records - toReturn = listOfConcessioni.subList(startIndex, limitIndex); - } else { - - orderBy = filter.getOrderByField(); - order = filter.getOrder(); - - if (orderBy == null) - orderBy = RECORD_FIELD.NAME; - - if (order == null) - order = ORDER.ASC; - - // CASE INSENSITIVE COMPARATOR - Comparator comparator = null; - - switch (orderBy) { - case NAME: - if (order.equals(ORDER.ASC)) { - comparator = Comparator.comparing(Concessione::getNome, - Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)); - } else { - comparator = Comparator - .comparing(Concessione::getNome, Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)) - .reversed(); - } - - break; - case CREATED: - if (order.equals(ORDER.ASC)) { - comparator = Comparator.comparing(Concessione::getCreationTime, - Comparator.nullsLast(Comparator.naturalOrder())); - } else { - comparator = Comparator.comparing(Concessione::getCreationTime, - Comparator.nullsLast(Comparator.naturalOrder())).reversed(); - } - break; - - case CREATED_BY: - if (order.equals(ORDER.ASC)) { - comparator = Comparator.comparing(Concessione::getCreationUser, - Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)); - } else { - comparator = Comparator.comparing(Concessione::getCreationUser, - Comparator.nullsLast(String.CASE_INSENSITIVE_ORDER)).reversed(); - } - break; - - // TODO is buggy must be performed by service - case PROJECT_START_END_DATE: - if (order.equals(ORDER.ASC)) { - comparator = Comparator.comparing(Concessione::getDataInizioProgetto, - Comparator.nullsLast(Comparator.naturalOrder())); - } else { - comparator = Comparator.comparing(Concessione::getDataInizioProgetto, - Comparator.nullsLast(Comparator.naturalOrder())).reversed(); - } - break; - - case RECORD_STATUS: - statusComparator = new ConcessioneValidationReportStatusComparator(); - default: - break; - } - - // sorting with nullsLast - if (comparator != null) - listOfConcessioni.sort(Comparator.nullsLast(comparator)); - - // solution quick&dirty - try { - if (statusComparator != null) { - if (order.equals(ORDER.ASC)) { - listOfConcessioni.sort(Comparator.nullsLast(statusComparator)); - } else { - Collections.sort(listOfConcessioni, Comparator.nullsLast( - Collections.reverseOrder(new ConcessioneValidationReportStatusComparator()))); - } - } - } catch (Exception e) { - LOG.warn("comparator Exception: " + e.getMessage()); - } - - LOG.trace("sorted list: " + listOfConcessioni); - // pagination - toReturn = listOfConcessioni.subList(startIndex, limitIndex); - } - - List toReturnList = new ArrayList(toReturn.size()); - - for (Concessione concessione : toReturn) { - ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); - toReturnList.add(concessioneDV); - } - - searchedData.setData(toReturnList); - - if (listConcessioniSize == limit || listConcessioniSize == 0) { - LOG.debug("Page completed returning " + listConcessioniSize + " items"); - int newOffset = startIndex + start; - searchedData.setServerSearchFinished(newOffset > listConcessioniSize || listConcessioniSize == 0); - LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); - return searchedData; - } - - LOG.debug("Returning: " + toReturnList); - LOG.info("Returning list of concessioni with size: " + toReturnList.size()); - return searchedData; - } catch (Exception e) { - LOG.error("Error on loading list of concessioni: ", e); - throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage()); - } - + return queryOnMongo(start, limit, filter, "concessione", reloadFromService); } /** @@ -848,6 +884,12 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } } + /** + * Gets the my rights in the context. + * + * @return the my rights in the context + * @throws Exception the exception + */ @Override public UserRights getMyRightsInTheContext() throws Exception { LOG.info("getMyRightsInTheContext called"); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java index 0b6e5eb..99cb439 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java @@ -147,7 +147,7 @@ public class SessionUtil { SessionUtil.getCurrentContext(httpServletRequest, true); MongoServiceUtil serviceUtil = new MongoServiceUtil(); MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); - + Iterator concessioni = clientMongo.getList(); if (concessioni != null) { while (concessioni.hasNext()) { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java index 81cc0c7..1c6319f 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java @@ -1,7 +1,6 @@ package org.gcube.portlets.user.geoportaldataentry.server.config; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/DisplayField.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/DisplayField.java new file mode 100644 index 0000000..8d5151e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/DisplayField.java @@ -0,0 +1,66 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +import java.io.Serializable; +import java.util.List; + +public class DisplayField implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1856714668390438433L; + + private String displayName; + private List jsonFields; + private boolean sortable; + + public DisplayField(){ + + } + + public DisplayField(String displayName, List jsonFields, boolean sortable) { + super(); + this.displayName = displayName; + this.jsonFields = jsonFields; + this.sortable = sortable; + } + + public String getDisplayName() { + return displayName; + } + + public List getJsonFields() { + return jsonFields; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public void setJsonFields(List jsonFields) { + this.jsonFields = jsonFields; + } + + public boolean isSortable() { + return sortable; + } + + public void setSortable(boolean sortable) { + this.sortable = sortable; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("DisplayField [displayName="); + builder.append(displayName); + builder.append(", jsonFields="); + builder.append(jsonFields); + builder.append(", sortable="); + builder.append(sortable); + builder.append("]"); + return builder.toString(); + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java index d838915..fff009d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java @@ -8,13 +8,12 @@ import java.util.List; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; - /** * The Class ResultSetPaginatedData. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Aug 6, 2021 + * Aug 6, 2021 */ public class ResultSetPaginatedData implements Serializable { @@ -23,9 +22,8 @@ public class ResultSetPaginatedData implements Serializable { */ private static final long serialVersionUID = 6800997954077785719L; private List data; - private int clientStartIndex = 0; + private int offset = 0; private int limit; - private int serverEndIndex = 0; private boolean isServerSearchFinished = false; private long totalItems; @@ -35,20 +33,17 @@ public class ResultSetPaginatedData implements Serializable { public ResultSetPaginatedData() { } - /** * Instantiates a new result set paginated data. * - * @param clientStartIndex the client start index - * @param limit the limit - * @param serverEndIndex the server end index + * @param offset the offset + * @param limit the limit * @param isServerSearchFinished the is server search finished */ - public ResultSetPaginatedData(int clientStartIndex, int limit, int serverEndIndex, boolean isServerSearchFinished) { + public ResultSetPaginatedData(int offset, int limit, boolean isServerSearchFinished) { - this.clientStartIndex = clientStartIndex; + this.offset = offset; this.limit = limit; - this.serverEndIndex = serverEndIndex; this.isServerSearchFinished = isServerSearchFinished; } @@ -67,7 +62,7 @@ public class ResultSetPaginatedData implements Serializable { * @return the client start index */ public int getClientStartIndex() { - return clientStartIndex; + return offset; } /** @@ -79,15 +74,6 @@ public class ResultSetPaginatedData implements Serializable { return limit; } - /** - * Gets the server end index. - * - * @return the server end index - */ - public int getServerEndIndex() { - return serverEndIndex; - } - /** * Checks if is server search finished. * @@ -112,7 +98,7 @@ public class ResultSetPaginatedData implements Serializable { * @param clientStartIndex the new client start index */ public void setClientStartIndex(int clientStartIndex) { - this.clientStartIndex = clientStartIndex; + this.offset = clientStartIndex; } /** @@ -124,15 +110,6 @@ public class ResultSetPaginatedData implements Serializable { this.limit = limit; } - /** - * Sets the server end index. - * - * @param serverEndIndex the new server end index - */ - public void setServerEndIndex(int serverEndIndex) { - this.serverEndIndex = serverEndIndex; - } - /** * Sets the server search finished. * @@ -161,21 +138,41 @@ public class ResultSetPaginatedData implements Serializable { } /** - * To string. + * Gets the serialversionuid. * - * @return the string + * @return the serialversionuid */ + public static long getSerialversionuid() { + return serialVersionUID; + } + + /** + * Gets the offset. + * + * @return the offset + */ + public int getOffset() { + return offset; + } + + /** + * Sets the offset. + * + * @param offset the new offset + */ + public void setOffset(int offset) { + this.offset = offset; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("ResultSetPaginatedData [data="); builder.append(data); - builder.append(", clientStartIndex="); - builder.append(clientStartIndex); + builder.append(", offset="); + builder.append(offset); builder.append(", limit="); builder.append(limit); - builder.append(", serverEndIndex="); - builder.append(serverEndIndex); builder.append(", isServerSearchFinished="); builder.append(isServerSearchFinished); builder.append(", totalItems="); @@ -184,6 +181,4 @@ public class ResultSetPaginatedData implements Serializable { return builder.toString(); } - - } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java index 412d1a0..98017c3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java @@ -12,7 +12,7 @@ public class ResultSetSorted implements Serializable { */ private static final long serialVersionUID = 889420364685643758L; - private SortFilter searchFilter; + private SearchingFilter searchFilter; private List data; @@ -20,13 +20,13 @@ public class ResultSetSorted implements Serializable { } - public ResultSetSorted(SortFilter searchFilter, List data) { + public ResultSetSorted(SearchingFilter searchFilter, List data) { super(); this.searchFilter = searchFilter; this.data = data; } - public SortFilter getSearchFilter() { + public SearchingFilter getSearchFilter() { return searchFilter; } @@ -34,7 +34,7 @@ public class ResultSetSorted implements Serializable { return data; } - public void setSearchFilter(SortFilter searchFilter) { + public void setSearchFilter(SearchingFilter searchFilter) { this.searchFilter = searchFilter; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SortFilter.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchingFilter.java similarity index 63% rename from src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SortFilter.java rename to src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchingFilter.java index 5226711..4990f4c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SortFilter.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchingFilter.java @@ -1,34 +1,45 @@ package org.gcube.portlets.user.geoportaldataentry.shared; import java.io.Serializable; +import java.util.Map; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; /** - * The Class SortFilter. + * The Class SearchingFilter. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Aug 6, 2021 + * Nov 30, 2021 */ -public class SortFilter implements Serializable { +public class SearchingFilter implements Serializable { /** * The Enum ORDER. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Aug 6, 2021 + * Nov 30, 2021 */ public static enum ORDER { ASC("ASCENDING"), DESC("DESCENDING"); String label; + /** + * Instantiates a new order. + * + * @param label the label + */ ORDER(String label) { this.label = label; } + /** + * Gets the label. + * + * @return the label + */ public String getLabel() { return label; } @@ -43,10 +54,12 @@ public class SortFilter implements Serializable { private ORDER order; + private Map searchInto; + /** * Instantiates a new sort filter. */ - public SortFilter() { + public SearchingFilter() { } @@ -56,11 +69,27 @@ public class SortFilter implements Serializable { * @param orderByField the order by field * @param order the order */ - public SortFilter(RECORD_FIELD orderByField, ORDER order) { + public SearchingFilter(RECORD_FIELD orderByField, ORDER order) { this.orderByField = orderByField; this.order = order; } + /** + * Instantiates a new sort filter. + * + * @param orderByField the order by field + * @param order the order + */ + public SearchingFilter(RECORD_FIELD orderByField, ORDER order, Map searchInto) { + this.orderByField = orderByField; + this.order = order; + this.searchInto = searchInto; + } + + public void setSearchInto(Map searchInto) { + this.searchInto = searchInto; + } + /** * Gets the order by field. * @@ -97,18 +126,19 @@ public class SortFilter implements Serializable { this.order = order; } - /** - * To string. - * - * @return the string - */ + public Map getSearchInto() { + return searchInto; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("SortFilter [orderByField="); + builder.append("SearchingFilter [orderByField="); builder.append(orderByField); builder.append(", order="); builder.append(order); + builder.append(", searchInto="); + builder.append(searchInto); builder.append("]"); return builder.toString(); } diff --git a/src/main/webapp/GeoPortalDataEntryApp.css b/src/main/webapp/GeoPortalDataEntryApp.css index 3965771..7f45247 100644 --- a/src/main/webapp/GeoPortalDataEntryApp.css +++ b/src/main/webapp/GeoPortalDataEntryApp.css @@ -119,3 +119,25 @@ h1 { margin-left: 10px; width: 95%; } + +.nav-toolbar-style { + margin-bottom: 5px; +} + +.nav-toolbar-style .container { + padding-top: 5px; +} + +.search-textbox { + padding: 4px 14px !important; + margin-bottom: 0 !important; + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif !important; + font-size: 13px !important; + font-weight: normal !important; + -webkit-border-radius: 15px; + -moz-border-radius: 15px; + border-radius: 15px !important; + float: right !important; + width: 250px !important; + margin-top: 8px !important; +} diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index 14af4bd..786b7ec 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -3,10 +3,18 @@ package org.gcube.portlets.user.geoportaldataentry.client; import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; +import org.bson.Document; import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest; +import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction; +import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest; import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; @@ -15,13 +23,15 @@ import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; import org.junit.Before; import org.junit.Test; +import com.mongodb.BasicDBObject; + public class TestClass { - private static String TOKEN = ""; + private static String TOKEN = "8e74a17c-92f1-405a-b591-3a6090066248-98187548"; private static String CONTEXT = "/gcube/devsec/devVRE"; private static String USERNAME = "francesco.mangiacrapa"; - //@Before + @Before public void init() { ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); @@ -44,6 +54,84 @@ public class TestClass { System.out.println(++i + " " + concessione); } } + + @Test + public void queryConcessioniTest() throws Exception { + try { + MongoConcessioni clientMongo = mongoConcessioni().build(); + int offsetIndex = 0; + int limitIndex = 25; + Direction sDirection = Direction.ASCENDING; + List orderByFields = Arrays.asList("nome"); + + String searchByField = "nome"; + String serchValue = "mock"; + + Map searchFields = new HashMap(); + searchFields.put(searchByField, serchValue); + + + QueryRequest request = new QueryRequest(); + PagedRequest paging = new PagedRequest(); + paging.setOffset(offsetIndex); + paging.setLimit(limitIndex); + request.setPaging(paging); + + OrderedRequest ordering = new OrderedRequest(); + + ordering.setDirection(sDirection); + + ordering.setFields(orderByFields); + request.setOrdering(ordering); + + Document query = null; + + if(searchFields!=null) { + +// BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); +// BasicDBObject bs = null; +// query = new Document(); +// +// for (String key : searchFields.keySet()) { +// //builder.append(key, new BasicDBObject("$eq", searchFields.get(key))); +// //query.put(key, new BasicDBObject("$eq", searchFields.get(key))); +// query = new Document(key, searchFields.get(key)); +// } +// +// request.setFilter(query); + + query = new Document(); + + for (String key : searchFields.keySet()) { + //query.put(key, searchFields.get(key)); + query.put(key, new BasicDBObject("$eq", searchFields.get(key))); + } + + request.setFilter(query); + + } + + System.out.println("Paging offset: " + offsetIndex + ", limit: " + limitIndex); + System.out.println("Direction: " + sDirection); + System.out.println("Order by Fields: " + orderByFields); + System.out.println("Search for: " + query); + System.out.println("Search for Query to JSON: "+query.toJson()); + + Iterator concessioni = clientMongo.query(request); + + + if (concessioni != null) { + while (concessioni.hasNext()) { + Concessione concessione = (Concessione) concessioni.next(); + System.out.println(concessione.getNome()); + + } + + } + }catch (Exception e) { + e.printStackTrace(); + } + } //@Test public void readUserRights() throws Exception { From 62f41a960dcd656ba53045dc6d904cf088904356 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 2 Dec 2021 11:33:01 +0100 Subject: [PATCH 08/16] in progress --- .../client/ui/GeonaMainTabPanel.java | 4 +-- .../client/ui/GeonaMainTabPanel.ui.xml | 2 +- .../client/ui/table/ItemsTable.java | 25 +++++++++++++-- .../server/GeoportalDataEntryServiceImpl.java | 31 ++++++++++++++----- .../shared/ActionOnItemType.java | 5 --- 5 files changed, 49 insertions(+), 18 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ActionOnItemType.java diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java index ba9b9f0..6ebe8c3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java @@ -188,8 +188,8 @@ public class GeonaMainTabPanel extends Composite { for (RECORD_FIELD record_FIELD : sortByFields) { - if (record_FIELD.equals(RECORD_FIELD.RECORD_STATUS)) - continue; +// if (record_FIELD.equals(RECORD_FIELD.RECORD_STATUS)) +// continue; // ASC String labelASC = toLabelFilter(record_FIELD, ORDER.ASC); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml index 116dff0..a50db45 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml @@ -51,7 +51,7 @@ GeoNa + styleName="{style.custom-page-header}">GNA diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java index a15f001..c1be4c0 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java @@ -210,10 +210,29 @@ public class ItemsTable extends AbstractItemsCellTable< public String getValue(T object) { if (object == null) return ""; + + Date dS = null; + Date dE = null; + if(object.getDataInizioProgetto()!=null) { + dS = (((ConcessioneDV) object).getDataInizioProgetto()); + } + + if(object.getDataFineProgetto()!=null) { + dE = (((ConcessioneDV) object).getDataFineProgetto()); + } + + String dateFormat = ""; + if(dS!=null) { + dateFormat+=dtformat.format(dS); + } + + dateFormat+=" / "; + + if(dE!=null) { + dateFormat+=dtformat.format(dE); + } - Date dS = (((ConcessioneDV) object).getDataInizioProgetto()); - Date dE = (((ConcessioneDV) object).getDataFineProgetto()); - return dtformat.format(dS) + " / " + dtformat.format(dE); + return dateFormat; } }; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index b08656c..6e3ba6e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -62,6 +62,7 @@ import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.mongodb.BasicDBObject; +import com.mongodb.BasicDBObjectBuilder; /** * The server side implementation of the RPC service. @@ -501,7 +502,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen fields.add("dataFineProgetto"); break; case RECORD_STATUS: - fields.add("report:status"); + fields.add("report.status"); // statusComparator = new ConcessioneValidationReportStatusComparator(); default: break; @@ -518,17 +519,27 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen ordering.setFields(fields); request.setOrdering(ordering); + Document query = null; if(filter.getSearchInto()!=null) { Map searchFields = filter.getSearchInto(); //List list = new ArrayList(); //Map map = new HashMap(); - Document query = new Document(); - + + BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); for (String key : searchFields.keySet()) { - query.put(key, searchFields.get(key)); - query.put(key, new BasicDBObject("$eq", searchFields.get(key))); +// query.put(key, searchFields.get(key)); +// query.put(key, new BasicDBObject("$eq", searchFields.get(key))); + + BasicDBObject bs = new BasicDBObject(); + bs.append("$regex", searchFields.get(key)); + bs.append("$options", "i"); + builder.append(key, bs); } - + query = new Document(builder.get().toMap()); +// BasicDBList list = new BasicDBList(); +// list.add(builder.get().toMap()); +// query.put("$and", list); + //or(query); request.setFilter(query); } @@ -536,6 +547,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen LOG.info("Direction: " + sDirection); LOG.info("Order by Fields: " + fields); LOG.info("Search for: " + filter.getSearchInto()); + if(query!=null) { + LOG.info("Search query to JSON: " + query.toJson()); + } Iterator concessioni = clientMongo.query(request); while (concessioni.hasNext()) { @@ -545,6 +559,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } searchedData.setData(toReturnList); + if(filter.getSearchInto()!=null){ + searchedData.setTotalItems(toReturnList.size()); + } if (listConcessioniSize == limit || listConcessioniSize == 0) { LOG.debug("Page completed returning " + listConcessioniSize + " items"); @@ -904,7 +921,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen // DEV MODE if (!SessionUtil.isIntoPortal()) { LOG.warn("OUT OF PORTAL - DEV MODE detected"); - GcubeUserRole myRole = GcubeUserRole.DATA_MEMBER; + GcubeUserRole myRole = GcubeUserRole.DATA_MANAGER; for (RoleRights roleRight : listUserRightsForRole) { if (roleRight.getUserRole().equals(myRole)) { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ActionOnItemType.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ActionOnItemType.java deleted file mode 100644 index 9d3dbae..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ActionOnItemType.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.shared; - -public class ActionOnItemType { - -} From deb666d53682085df119dc5e431e7c6eab49ad12 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 2 Dec 2021 12:25:05 +0100 Subject: [PATCH 09/16] integrated "search for" facility --- .../ConstantsGeoPortalDataEntryApp.java | 2 +- .../client/GeoPortalDataEntryApp.java | 4 +- .../client/ui/GeonaMainTabPanel.java | 57 +++++++++-- .../client/ui/GeonaMainTabPanel.ui.xml | 25 +++-- src/main/webapp/GeoPortalDataEntryApp.css | 7 +- .../geoportaldataentry/client/TestClass.java | 99 +++++++++++++++---- 6 files changed, 157 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index 575dc33..ccd02b9 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -47,7 +47,7 @@ public class ConstantsGeoPortalDataEntryApp { * Sep 2, 2021 */ public static enum RECORD_FIELD { - NAME("nome", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("author", "Author/s"), + NAME("nome", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("authors", "Author/s"), PROJECT_START_END_DATE("", "Project Start/End Date"), RECORD_STATUS("recordStatus", "Published with"), CREATED("creationTime", "Created"), CREATED_BY("creationUser", "Created by"); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index 27ca84e..19de25e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -117,10 +117,12 @@ public class GeoPortalDataEntryApp implements EntryPoint { RECORD_FIELD.CREATED, RECORD_FIELD.CREATED_BY, RECORD_FIELD.RECORD_STATUS }; SearchingFilter initialSortFilter = new SearchingFilter(RECORD_FIELD.NAME, ORDER.ASC); + + RECORD_FIELD[] searchForFields = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.AUTHOR}; RootPanel.get(DIV_PORTLET_ID).add(loader); - mainTabPanel = new GeonaMainTabPanel(appManagerBus, sortByOptions, initialSortFilter); + mainTabPanel = new GeonaMainTabPanel(appManagerBus, sortByOptions, searchForFields, initialSortFilter); mainTabPanel.setLoaderVisible("Loading...", true); geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java index 6ebe8c3..1f7df32 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java @@ -16,12 +16,14 @@ import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER; +import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Dropdown; import com.github.gwtbootstrap.client.ui.NavLink; import com.github.gwtbootstrap.client.ui.Tab; import com.github.gwtbootstrap.client.ui.TabPanel; import com.github.gwtbootstrap.client.ui.TextBox; +import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.IconSize; import com.google.gwt.core.client.GWT; @@ -100,9 +102,15 @@ public class GeonaMainTabPanel extends Composite { @UiField Dropdown dropdownSortBy; + + @UiField + Dropdown dropdownSearchFor; @UiField - TextBox textBoxSortBy; + Alert alertSortBy; + + @UiField + Alert alertSearchFor; @UiField NavLink navShowOnMap; @@ -125,6 +133,8 @@ public class GeonaMainTabPanel extends Composite { private HandlerManager appManagerBus; private RECORD_FIELD[] sortByFields; + + private RECORD_FIELD[] searchForFields; private SearchingFilter currentSortFilter; @@ -137,13 +147,22 @@ public class GeonaMainTabPanel extends Composite { * @param sortByFields the sort by fields * @param initialSortFilter */ - public GeonaMainTabPanel(HandlerManager appManagerBus, RECORD_FIELD[] sortByFields, + public GeonaMainTabPanel(HandlerManager appManagerBus, RECORD_FIELD[] sortByFields, RECORD_FIELD[] searchForFields, SearchingFilter initialSortFilter) { initWidget(uiBinder.createAndBindUi(this)); this.appManagerBus = appManagerBus; this.sortByFields = sortByFields; this.currentSortFilter = initialSortFilter; - textBoxSortBy.setText(toLabelFilter(initialSortFilter.getOrderByField(), initialSortFilter.getOrder())); + this.searchForFields = searchForFields; + + alertSortBy.setType(AlertType.INFO); + alertSortBy.setClose(false); + + alertSearchFor.setType(AlertType.INFO); + alertSearchFor.setClose(false); + + alertSearchFor.setText(searchForFields[0].getDisplayName()); + alertSortBy.setText(toLabelFilter(initialSortFilter.getOrderByField(), initialSortFilter.getOrder())); bindEvents(); resetSearch.setIconSize(IconSize.TWO_TIMES); resetSearch.setType(ButtonType.LINK); @@ -200,7 +219,7 @@ public class GeonaMainTabPanel extends Composite { @Override public void onClick(ClickEvent event) { - textBoxSortBy.setText(labelASC); + alertSortBy.setText(labelASC); appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); } }); @@ -214,11 +233,26 @@ public class GeonaMainTabPanel extends Composite { @Override public void onClick(ClickEvent event) { - textBoxSortBy.setText(labelDESC); + alertSortBy.setText(labelDESC); appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); } }); } + + for (RECORD_FIELD record_FIELD : searchForFields) { + + NavLink nav = new NavLink(record_FIELD.getDisplayName()); + dropdownSearchFor.add(nav); + + nav.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + alertSearchFor.setText(record_FIELD.getDisplayName()); + } + }); + } + navShowOnMap.addClickHandler(new ClickHandler() { @@ -369,11 +403,20 @@ public class GeonaMainTabPanel extends Composite { } private SearchingFilter builtSearchingFilter() { - SearchingFilter searchingFilter = toSortFilter(this.textBoxSortBy.getText()); + SearchingFilter searchingFilter = toSortFilter(alertSortBy.getText()); String searchText = searchField.getText(); if (searchText != null && !searchText.isEmpty()) { Map searchInto = new HashMap(); - searchInto.put(RECORD_FIELD.NAME.getJsonFieldName(), searchText); + + String searchForField = RECORD_FIELD.NAME.getJsonFieldName(); + + for (RECORD_FIELD recordField : searchForFields) { + if(recordField.getDisplayName().equals(alertSearchFor.getText())) { + searchForField = recordField.getJsonFieldName(); + continue; + } + } + searchInto.put(searchForField, searchText); searchingFilter.setSearchInto(searchInto); } return searchingFilter; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml index a50db45..71adb1a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml @@ -101,19 +101,30 @@ - + Reload Projects - - + + + + + + + + + + + + diff --git a/src/main/webapp/GeoPortalDataEntryApp.css b/src/main/webapp/GeoPortalDataEntryApp.css index 7f45247..0f43430 100644 --- a/src/main/webapp/GeoPortalDataEntryApp.css +++ b/src/main/webapp/GeoPortalDataEntryApp.css @@ -137,7 +137,12 @@ h1 { -webkit-border-radius: 15px; -moz-border-radius: 15px; border-radius: 15px !important; - float: right !important; width: 250px !important; margin-top: 8px !important; } + +.alert_box_nav { + padding: 4px 10px !important; + margin-top: 8px !important; + margin-bottom: 10px !important; +} diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index 786b7ec..db9597f 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -23,11 +23,13 @@ import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; import org.junit.Before; import org.junit.Test; +import com.mongodb.BasicDBList; import com.mongodb.BasicDBObject; +import com.mongodb.BasicDBObjectBuilder; public class TestClass { - private static String TOKEN = "8e74a17c-92f1-405a-b591-3a6090066248-98187548"; + private static String TOKEN = ""; private static String CONTEXT = "/gcube/devsec/devVRE"; private static String USERNAME = "francesco.mangiacrapa"; @@ -64,11 +66,9 @@ public class TestClass { Direction sDirection = Direction.ASCENDING; List orderByFields = Arrays.asList("nome"); - String searchByField = "nome"; - String serchValue = "mock"; - Map searchFields = new HashMap(); - searchFields.put(searchByField, serchValue); + searchFields.put("nome", "test"); + searchFields.put("authors", "fra"); QueryRequest request = new QueryRequest(); @@ -88,29 +88,84 @@ public class TestClass { if(searchFields!=null) { -// BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); -// BasicDBObject bs = null; -// query = new Document(); -// -// for (String key : searchFields.keySet()) { -// //builder.append(key, new BasicDBObject("$eq", searchFields.get(key))); -// //query.put(key, new BasicDBObject("$eq", searchFields.get(key))); -// query = new Document(key, searchFields.get(key)); -// } -// -// request.setFilter(query); + BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); + + query = new Document(); - + for (String key : searchFields.keySet()) { - //query.put(key, searchFields.get(key)); - query.put(key, new BasicDBObject("$eq", searchFields.get(key))); + //builder.append(key, new BasicDBObject("$eq", searchFields.get(key))); + BasicDBObject bs = new BasicDBObject(); + bs.append("$regex", searchFields.get(key)); + bs.append("$options", "i"); + builder.append(key, bs); + //query.put(key, new BasicDBObject("$eq", searchFields.get(key))); + //query = new Document(key, searchFields.get(key)); } - + +// query.putAll(builder.get().toMap()); +// request.setFilter(query); + + + + BasicDBList list = new BasicDBList(); + list.add(builder.get().toMap()); + query.put("$or", list); + //or(query); request.setFilter(query); + + + //************************************************ AND +// query = new Document(); +// for (String key : searchFields.keySet()) { +// //AND +// BasicDBObject bs = new BasicDBObject(); +// bs.append("$regex", searchFields.get(key)); +// bs.append("$options", "i"); +// query.put(key, bs); +// +// } +// request.setFilter(query); + //******************************************** END AND } + //OR + /*query = new Document(); + BasicDBObject container = new BasicDBObject(); + BsonArray bArray = new BsonArray(); + for (String key : searchFields.keySet()) { + //AND + BasicDBObject bs = new BasicDBObject(); + bs.append("$regex", searchFields.get(key)); + bs.append("$options", "i"); + query.put(key, bs); + + //container.put(key, bs); + + +// BasicDBObject bs2 = new BasicDBObject(); +// bs2.append("$regex", searchFields.get(key)); +// bs2.append("$options", "i"); +// BsonDocument bsK = new BsonDocument(); +// bsK.append(key, new BsonString(bs2.toJson())); +// bArray.add(bsK); + + } +// query.put("$or", bArray); + + BasicDBList list = new BasicDBList(); + list.add(query); + + Document orDocument = new Document(); + orDocument.put("$or", list); +// + query = orDocument; + request.setFilter(query);*/ + + + System.out.println("Paging offset: " + offsetIndex + ", limit: " + limitIndex); System.out.println("Direction: " + sDirection); System.out.println("Order by Fields: " + orderByFields); @@ -119,6 +174,10 @@ public class TestClass { Iterator concessioni = clientMongo.query(request); + if(concessioni.hasNext()) { + System.out.println("Found concessioni, printing them..."); + }else + System.out.println("No concessione found"); if (concessioni != null) { while (concessioni.hasNext()) { From d19f2939302715c3fb489f2ca979241cd1f23feb Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 2 Dec 2021 17:13:55 +0100 Subject: [PATCH 10/16] created GR "GNA-DataEntry-Configs" and using it --- .../client/ui/GeonaMainTabPanel.java | 25 +- .../server/GeoportalDataEntryServiceImpl.java | 20 +- .../server/config/FileUtil.java | 100 ++++--- .../server/config/GNADataEntryConfigs.java | 38 +++ .../GNADataEntryConfigsProfileReader.java | 282 ++++++++++++++++++ .../config/GNARoleRitghtsConfigReader.java | 166 ----------- .../config/GNA_RoleRights_Configurations.csv | 5 - .../geoportaldataentry/client/TestClass.java | 227 +++++++------- 8 files changed, 525 insertions(+), 338 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigs.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigsProfileReader.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNA_RoleRights_Configurations.csv diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java index 1f7df32..952d21a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java @@ -249,6 +249,11 @@ public class GeonaMainTabPanel extends Composite { @Override public void onClick(ClickEvent event) { alertSearchFor.setText(record_FIELD.getDisplayName()); + + if(searchField.getText().length() >= MIN_LENGHT_SERCHING_STRING) { + doSearchEvent(); + } + } }); } @@ -315,14 +320,7 @@ public class GeonaMainTabPanel extends Composite { GWT.log("CHAR CODE: " + event.getCharCode()); if (com.google.gwt.event.dom.client.KeyCodes.KEY_ENTER == event.getCharCode()) { GWT.log(searchField.getText()); - String searchText = searchField.getText(); - if (searchText.length() < MIN_LENGHT_SERCHING_STRING) { - Window.alert("Please enter at least "+MIN_LENGHT_SERCHING_STRING+" characters"); - return; - } - - resetSearch.setVisible(true); - appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); + doSearchEvent(); } } @@ -339,6 +337,17 @@ public class GeonaMainTabPanel extends Composite { }); } + + private void doSearchEvent() { + String searchText = searchField.getText(); + if (searchText.length() < MIN_LENGHT_SERCHING_STRING) { + Window.alert("Please enter at least "+MIN_LENGHT_SERCHING_STRING+" characters"); + return; + } + + resetSearch.setVisible(true); + appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); + } private String toLabelFilter(RECORD_FIELD orderBy, ORDER direction) { String labelFilter = orderBy.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name(); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index 6e3ba6e..d20761d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -35,7 +35,8 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitl import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; -import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader; +import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigs; +import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigsProfileReader; import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.DisplayField; @@ -552,13 +553,19 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } Iterator concessioni = clientMongo.query(request); + int i = 0; while (concessioni.hasNext()) { Concessione concessione = concessioni.next(); ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); toReturnList.add(concessioneDV); + i++; } + LOG.debug("read " + toReturnList +" project/s"); searchedData.setData(toReturnList); + + //TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT + // AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE if(filter.getSearchInto()!=null){ searchedData.setTotalItems(toReturnList.size()); } @@ -593,12 +600,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen public List listDisplayFields() { List listDisplayFields = new ArrayList(); - DisplayField df = new DisplayField("Name", Arrays.asList("nome"), true); // etc - return listDisplayFields; - } /** @@ -916,12 +920,14 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen try { PortalContext pContext = PortalContext.getConfiguration(); user = pContext.getCurrentUser(this.getThreadLocalRequest()); - - List listUserRightsForRole = GNARoleRitghtsConfigReader.readRoleRightsConfig(); + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + GNADataEntryConfigsProfileReader gnaConfigReader = new GNADataEntryConfigsProfileReader(); + GNADataEntryConfigs config = gnaConfigReader.readProfileFromInfrastrucure(); + List listUserRightsForRole = config.getPermissionsForRole(); // DEV MODE if (!SessionUtil.isIntoPortal()) { LOG.warn("OUT OF PORTAL - DEV MODE detected"); - GcubeUserRole myRole = GcubeUserRole.DATA_MANAGER; + GcubeUserRole myRole = GcubeUserRole.DATA_EDITOR; for (RoleRights roleRight : listUserRightsForRole) { if (roleRight.getUserRole().equals(myRole)) { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java index 0902cac..f1b25e5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.geoportaldataentry.server.config; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -7,62 +8,93 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; -// TODO: Auto-generated Javadoc /** * The Class FileUtil. * - * @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy) - * Apr 21, 2020 + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 2, 2021 */ public class FileUtil { - - + /** * Input stream to temp file. * * @param inputStream the input stream - * @param fileName the file name + * @param fileName the file name * @return the file * @throws IOException Signals that an I/O exception has occurred. */ // InputStream -> Temp File - public static File inputStreamToTempFile(InputStream inputStream, String fileName) - throws IOException { - - File tempFile = File.createTempFile(fileName, ".tmp"); - //File tempFile = File.createTempFile("MyAppName-", ".tmp"); - try (FileOutputStream outputStream = new FileOutputStream(tempFile)) { + public static File inputStreamToTempFile(InputStream inputStream, String fileName) throws IOException { - int read; - byte[] bytes = new byte[1024]; + File tempFile = File.createTempFile(fileName, ".tmp"); + // File tempFile = File.createTempFile("MyAppName-", ".tmp"); + try (FileOutputStream outputStream = new FileOutputStream(tempFile)) { - while ((read = inputStream.read(bytes)) != -1) { - outputStream.write(bytes, 0, read); - } - - return tempFile; + int read; + byte[] bytes = new byte[1024]; - }finally { - tempFile.deleteOnExit(); + while ((read = inputStream.read(bytes)) != -1) { + outputStream.write(bytes, 0, read); + } + + return tempFile; + + } finally { + tempFile.deleteOnExit(); } - } - - - /** - * Copy input stream to file. - * - * @param is the is - * @param to the to - * @return the file - * @throws IOException Signals that an I/O exception has occurred. - */ - public static File copyInputStreamToFile(InputStream is, String to) throws IOException { + } + + /** + * Input stream to temp file. + * + * @param copyString the copy string + * @return + * @throws IOException Signals that an I/O exception has occurred. + */ + public static File inputStreamToTempFile(String copyString, String prefixFile) throws IOException { + + File targetFile = null; + try { + InputStream initialStream = new ByteArrayInputStream(copyString.getBytes()); + targetFile = File.createTempFile(prefixFile, ".tmp"); + + java.nio.file.Files.copy(initialStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + + try { + if (initialStream != null) { + initialStream.close(); + } + } catch (IOException ioe) { + // ignore + } + return targetFile; + } finally { + try { + if (targetFile != null) + targetFile.deleteOnExit(); + } catch (Exception e) { + + } + } + } + + /** + * Copy input stream to file. + * + * @param is the is + * @param to the to + * @return the file + * @throws IOException Signals that an I/O exception has occurred. + */ + public static File copyInputStreamToFile(InputStream is, String to) throws IOException { Path dest = Paths.get(to); Files.copy(is, dest); return new File(to); } - } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigs.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigs.java new file mode 100644 index 0000000..cea91a9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigs.java @@ -0,0 +1,38 @@ +package org.gcube.portlets.user.geoportaldataentry.server.config; + +import java.util.List; + +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; + + +public class GNADataEntryConfigs { + + List permissionsForRole = null; + + public GNADataEntryConfigs() { + + } + + public GNADataEntryConfigs(List permissionsForRole) { + super(); + this.permissionsForRole = permissionsForRole; + } + + public List getPermissionsForRole() { + return permissionsForRole; + } + + public void setPermissionsForRole(List permissionsForRole) { + this.permissionsForRole = permissionsForRole; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GNADataEntryConfigs [permissionsForRole="); + builder.append(permissionsForRole); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigsProfileReader.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigsProfileReader.java new file mode 100644 index 0000000..bf267e9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigsProfileReader.java @@ -0,0 +1,282 @@ +package org.gcube.portlets.user.geoportaldataentry.server.config; + +import static org.gcube.resources.discovery.icclient.ICFactory.client; + +import java.io.File; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.gcube.application.geoportalcommon.shared.exception.ApplicationProfileNotFoundException; +import org.gcube.common.resources.gcore.utils.XPathHelper; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; +import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException; +import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; +import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.Query; +import org.gcube.resources.discovery.client.queries.impl.QueryBox; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + +/** + * The Class GNADataEntryConfigsProfileReader. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 2, 2021 + */ +public class GNADataEntryConfigsProfileReader { + + private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body"; + public static final String SECONDARY_TYPE = "ApplicationProfile"; + public static final String GENERIC_RESOURCE_NAME = "GNA-DataEntry-Configs"; + private static final String TEMP_ROLE_RIGHTS_CONFIG_FILENAME = "GNA_RoleRights_Configurations"; + + private String scope; + + private static final Logger LOG = LoggerFactory.getLogger(GNADataEntryConfigsProfileReader.class); + + /** + * Instantiates a new application profile reader. + */ + public GNADataEntryConfigsProfileReader() { + } + + /** + * Read profile from infrastrucure. + * + * @return the map + * @throws Exception the exception + */ + public GNADataEntryConfigs readProfileFromInfrastrucure() throws Exception { + LOG.info("called readProfileFromInfrastrucure"); + String queryString = getGcubeGenericQueryString(SECONDARY_TYPE, GENERIC_RESOURCE_NAME); + LOG.info("Scope " + scope + ", trying to perform query: " + queryString); + this.scope = ScopeProvider.instance.get(); + + if (scope == null) + throw new Exception("Scope is null, set scope into ScopeProvider"); + + GNADataEntryConfigs gnDEC = new GNADataEntryConfigs(); + String permissions_for_role = ""; + try { + + LOG.info("Trying to fetch GR named: " + GENERIC_RESOURCE_NAME + ", in the scope: " + scope + + ", SecondaryType: " + SECONDARY_TYPE); + Query q = new QueryBox(queryString); + DiscoveryClient client = client(); + List appProfile = client.submit(q); + + if (appProfile == null || appProfile.size() == 0) + throw new ApplicationProfileNotFoundException("GR with SecondaryType: " + SECONDARY_TYPE + + ", and name: " + GENERIC_RESOURCE_NAME + " is not registered in the scope: " + scope); + else { + String elem = appProfile.get(0); + DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document doc = docBuilder.parse(new InputSource(new StringReader(elem))); + + XPathHelper helper = new XPathHelper(doc.getDocumentElement()); + + List currValue = null; + String xPathExp = RESOURCE_PROFILE_BODY + "/permssions_for_role/text()"; + currValue = helper.evaluate(xPathExp); + + if (currValue != null && currValue.size() > 0) { + permissions_for_role = currValue.get(0); + } else + throw new Exception("I'm not able to read the path: " + xPathExp); + + //replacing \n with new_line string + LOG.debug("read permissions_for_role: " + permissions_for_role); + String pfr_with_new_lines = permissions_for_role.replaceAll("\\\\n", System.lineSeparator()); + LOG.debug("permissions_for_role with new lines: " + pfr_with_new_lines); + + List listRoleRights = readRoleRightsConfig(pfr_with_new_lines); + gnDEC.setPermissionsForRole(listRoleRights); + LOG.info("returning: " + gnDEC); + return gnDEC; + } + + } catch (Exception e) { + LOG.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType " + + GENERIC_RESOURCE_NAME + " from scope " + scope, e); + return null; + } finally { + + } + + } + + /** + * To gcube user role. + * + * @param name the name + * @return the gcube user role + */ + public static GcubeUserRole toGcubeUserRole(String name) { + + for (GcubeUserRole gCubeUserRole : GcubeUserRole.values()) { + if (gCubeUserRole.getName().equalsIgnoreCase(name)) + return gCubeUserRole; + } + + return null; + } + + /** + * Read user rights config. + * + * @param permissions_for_role the permissions for role + * @return the list + * @throws GNAUserRightsConfigException the GNA user rights config not found + * exception + */ + public List readRoleRightsConfig(String permissions_for_role) throws GNAUserRightsConfigException { + LOG.debug("readRoleRightsConfig called"); + + File configurationFile = null; + List listUserRights = new ArrayList(); + try { + configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, TEMP_ROLE_RIGHTS_CONFIG_FILENAME); + + CSVReader reader = new CSVReader(configurationFile); + CSVFile csvFile = reader.getCsvFile(); + + List headerKeys = csvFile.getHeaderRow().getListValues(); + List rows = csvFile.getValueRows(); + + // MAPPING OPERATION TYPE AS READ, WRITE, etc. + Map mapOperationTypes = new HashMap(); + CSVRow operationTypeRow = rows.get(0); + List rowValues = operationTypeRow.getListValues(); + for (int j = 1; j < rowValues.size(); j++) { + String operationType = rowValues.get(j); + RoleRights.OPERATION_TYPE ot = RoleRights.OPERATION_TYPE.UNKNOWN; + if (operationType.equalsIgnoreCase("R")) { + ot = RoleRights.OPERATION_TYPE.READ; + } else if (operationType.equalsIgnoreCase("RW")) { + ot = RoleRights.OPERATION_TYPE.READ_WRITE; + } else if (operationType.equalsIgnoreCase("W")) { + ot = RoleRights.OPERATION_TYPE.WRITE; + } + + mapOperationTypes.put(headerKeys.get(j), ot); + } + + LOG.debug("Map of operation types: " + mapOperationTypes); + + // Starting from index 1 (means the second row in the CSV) + for (int i = 1; i < rows.size(); i++) { + LOG.trace(i + " row"); + RoleRights useRights = new RoleRights(); + CSVRow row = rows.get(i); + + // to map properties + rowValues = row.getListValues(); + + LOG.debug("rowValues: " + rowValues); + Map mapUserRolePermissions = new HashMap(); + + GcubeUserRole gCubeUserRole = toGcubeUserRole(rowValues.get(0)); + + if (gCubeUserRole == null) { + LOG.warn("The Role " + rowValues.get(0) + " not found into roleName of: " + GcubeUserRole.values()); + continue; + } + + useRights.setUserRole(gCubeUserRole); + + for (int j = 1; j < rowValues.size(); j++) { + mapUserRolePermissions.put(headerKeys.get(j), rowValues.get(j)); + } + LOG.debug("Role: " + useRights.getUserRole()); + LOG.debug("Permissions read: " + mapUserRolePermissions); + + Map listPermessions = new HashMap(); + + for (ACTION_ON_ITEM value : ACTION_ON_ITEM.values()) { + String yesno = mapUserRolePermissions.get(value.name()); + + if (yesno != null && yesno.equalsIgnoreCase("yes")) { + listPermessions.put(value, mapOperationTypes.get(value.name())); + } + + } + + useRights.setListPermessions(listPermessions); + +// String writeOwn = mapUserRolePermissions.get(WRITE_OWN_CONFIG); +// if (writeOwn != null && writeOwn.equalsIgnoreCase("yes")) { +// useRights.setWriteOwn(true); +// } +// +// String writeAny = mapUserRolePermissions.get(WRITE_ANY_CONFIG); +// if (writeAny != null && writeAny.equalsIgnoreCase("yes")) { +// useRights.setWriteAny(true); +// } + + listUserRights.add(useRights); + + } + LOG.info("Returning user rights config: " + listUserRights); + return listUserRights; + + } catch (Exception e) { + LOG.error("An error occurred on reading the GNA DataEntry config from: " + permissions_for_role, e); + throw new GNAUserRightsConfigException("Error on reading the GNA DataEntry from: " + permissions_for_role); + } finally { + + if (configurationFile != null) { + try { + configurationFile.delete(); + } catch (Exception e) { + // silent + } + } + } + + } + + /** + * Gets the gcube generic query string. + * + * @param secondaryType the secondary type + * @param genericResourceName the generic resource name + * @return the gcube generic query string + */ + public static String getGcubeGenericQueryString(String secondaryType, String genericResourceName) { + + return "for $profile in collection('/db/Profiles/GenericResource')//Resource " + + "where $profile/Profile/SecondaryType/string() eq '" + secondaryType + + "' and $profile/Profile/Name/string() " + " eq '" + genericResourceName + "'" + "return $profile"; + } + + /** + * Gets the secondary type. + * + * @return the secondary type + */ + public String getSecondaryType() { + return SECONDARY_TYPE; + } + + /** + * Gets the scope. + * + * @return the scope + */ + public String getScope() { + return scope; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java deleted file mode 100644 index 1c6319f..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNARoleRitghtsConfigReader.java +++ /dev/null @@ -1,166 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.server.config; - -import java.io.File; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; -import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException; -import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.allen_sauer.gwt.log.client.Log; - -/** - * The Class GNARoleRitghtsConfigReader. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Nov 25, 2021 - */ -public class GNARoleRitghtsConfigReader { - - private static final String USER_RIGHTS_CONFIG_FILENAME = "GNA_RoleRights_Configurations.csv"; - private static Logger LOG = LoggerFactory.getLogger(GNARoleRitghtsConfigReader.class); - - public static final String WRITE_OWN_CONFIG = "WRITE_OWN"; - public static final String WRITE_ANY_CONFIG = "WRITE_ANY"; - - /** - * Read user rights config. - * - * @return the list - * @throws GNAUserRightsConfigException the GNA user rights config not - * found exception - */ - public static List readRoleRightsConfig() throws GNAUserRightsConfigException { - LOG.debug("readRoleRightsConfig called"); - - File configurationFile = null; - - try { - - InputStream in = (InputStream) GNARoleRitghtsConfigReader.class.getResourceAsStream(USER_RIGHTS_CONFIG_FILENAME); - configurationFile = FileUtil.inputStreamToTempFile(in, USER_RIGHTS_CONFIG_FILENAME); - CSVReader reader = new CSVReader(configurationFile); - CSVFile csvFile = reader.getCsvFile(); - List listUserRights = new ArrayList(); - - List headerKeys = csvFile.getHeaderRow().getListValues(); - List rows = csvFile.getValueRows(); - - // MAPPING OPERATION TYPE AS READ, WRITE, etc. - Map mapOperationTypes = new HashMap(); - CSVRow operationTypeRow = rows.get(0); - List rowValues = operationTypeRow.getListValues(); - for (int j = 1; j < rowValues.size(); j++) { - String operationType = rowValues.get(j); - RoleRights.OPERATION_TYPE ot = RoleRights.OPERATION_TYPE.UNKNOWN; - if (operationType.equalsIgnoreCase("R")) { - ot = RoleRights.OPERATION_TYPE.READ; - } else if (operationType.equalsIgnoreCase("RW")) { - ot = RoleRights.OPERATION_TYPE.READ_WRITE; - } else if (operationType.equalsIgnoreCase("W")) { - ot = RoleRights.OPERATION_TYPE.WRITE; - } - - mapOperationTypes.put(headerKeys.get(j), ot); - } - - LOG.debug("Map of operation types: " + mapOperationTypes); - - //Starting from index 1 (means the second row in the CSV) - for (int i = 1; i < rows.size(); i++) { - LOG.trace(i + " row"); - RoleRights useRights = new RoleRights(); - CSVRow row = rows.get(i); - - // to map properties - rowValues = row.getListValues(); - - LOG.debug("rowValues: " + rowValues); - Map mapUserRolePermissions = new HashMap(); - - GcubeUserRole gCubeUserRole = toGcubeUserRole(rowValues.get(0)); - - if (gCubeUserRole == null) { - LOG.warn("The Role " + rowValues.get(0) + " not found into roleName of: " + GcubeUserRole.values()); - continue; - } - - useRights.setUserRole(gCubeUserRole); - - for (int j = 1; j < rowValues.size(); j++) { - mapUserRolePermissions.put(headerKeys.get(j), rowValues.get(j)); - } - LOG.debug("Role: " + useRights.getUserRole()); - LOG.debug("Permissions read: " + mapUserRolePermissions); - - Map listPermessions = new HashMap(); - - for (ACTION_ON_ITEM value : ACTION_ON_ITEM.values()) { - String yesno = mapUserRolePermissions.get(value.name()); - - if (yesno != null && yesno.equalsIgnoreCase("yes")) { - listPermessions.put(value, mapOperationTypes.get(value.name())); - } - - } - - useRights.setListPermessions(listPermessions); - -// String writeOwn = mapUserRolePermissions.get(WRITE_OWN_CONFIG); -// if (writeOwn != null && writeOwn.equalsIgnoreCase("yes")) { -// useRights.setWriteOwn(true); -// } -// -// String writeAny = mapUserRolePermissions.get(WRITE_ANY_CONFIG); -// if (writeAny != null && writeAny.equalsIgnoreCase("yes")) { -// useRights.setWriteAny(true); -// } - - listUserRights.add(useRights); - - } - Log.info("Returning user rights config: " + listUserRights); - return listUserRights; - - } catch (Exception e) { - LOG.error("An error occurred on reading the configuration file " + USER_RIGHTS_CONFIG_FILENAME, e); - throw new GNAUserRightsConfigException("Error on reading the configuration file. Is the file '" - + USER_RIGHTS_CONFIG_FILENAME + "' in the application path?"); - } finally { - - if (configurationFile != null) { - try { - configurationFile.delete(); - } catch (Exception e) { - // silent - } - } - } - - } - - /** - * To gcube user role. - * - * @param name the name - * @return the gcube user role - */ - public static GcubeUserRole toGcubeUserRole(String name) { - - for (GcubeUserRole gCubeUserRole : GcubeUserRole.values()) { - if (gCubeUserRole.getName().equalsIgnoreCase(name)) - return gCubeUserRole; - } - - return null; - } -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNA_RoleRights_Configurations.csv b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNA_RoleRights_Configurations.csv deleted file mode 100644 index 8678509..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNA_RoleRights_Configurations.csv +++ /dev/null @@ -1,5 +0,0 @@ -,CREATE_NEW_PROJECT,VIEW_ON_MAP,VIEW_REPORT,EDIT_PROJECT,DELETE_PROJECT -OPERATION_TYPE,W,R,RW,RW,RW -Data-Member,no,yes,no,no,no -Data-Editor,yes,yes,yes,yes,yes -Data-Manager,yes,yes,yes,yes,yes diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index db9597f..ea61850 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -18,8 +18,7 @@ import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedReque import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.portlets.user.geoportaldataentry.server.config.GNARoleRitghtsConfigReader; -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; +import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigsProfileReader; import org.junit.Before; import org.junit.Test; @@ -39,7 +38,7 @@ public class TestClass { SecurityTokenProvider.instance.set(TOKEN); } - //@Test + // @Test public void getListConcessioniTest() throws Exception { MongoConcessioni clientMongo = mongoConcessioni().build(); Iterator concessioni = clientMongo.getList(); @@ -56,68 +55,61 @@ public class TestClass { System.out.println(++i + " " + concessione); } } - - @Test + + // @Test public void queryConcessioniTest() throws Exception { try { - MongoConcessioni clientMongo = mongoConcessioni().build(); - int offsetIndex = 0; - int limitIndex = 25; - Direction sDirection = Direction.ASCENDING; - List orderByFields = Arrays.asList("nome"); - - Map searchFields = new HashMap(); - searchFields.put("nome", "test"); - searchFields.put("authors", "fra"); + MongoConcessioni clientMongo = mongoConcessioni().build(); + int offsetIndex = 0; + int limitIndex = 25; + Direction sDirection = Direction.ASCENDING; + List orderByFields = Arrays.asList("nome"); - - QueryRequest request = new QueryRequest(); - PagedRequest paging = new PagedRequest(); - paging.setOffset(offsetIndex); - paging.setLimit(limitIndex); - request.setPaging(paging); + Map searchFields = new HashMap(); + searchFields.put("nome", "test"); + searchFields.put("authors", "fra"); - OrderedRequest ordering = new OrderedRequest(); + QueryRequest request = new QueryRequest(); + PagedRequest paging = new PagedRequest(); + paging.setOffset(offsetIndex); + paging.setLimit(limitIndex); + request.setPaging(paging); - ordering.setDirection(sDirection); + OrderedRequest ordering = new OrderedRequest(); + + ordering.setDirection(sDirection); + + ordering.setFields(orderByFields); + request.setOrdering(ordering); + + Document query = null; + + if (searchFields != null) { + + BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); + + query = new Document(); + + for (String key : searchFields.keySet()) { + // builder.append(key, new BasicDBObject("$eq", searchFields.get(key))); + BasicDBObject bs = new BasicDBObject(); + bs.append("$regex", searchFields.get(key)); + bs.append("$options", "i"); + builder.append(key, bs); + // query.put(key, new BasicDBObject("$eq", searchFields.get(key))); + // query = new Document(key, searchFields.get(key)); + } - ordering.setFields(orderByFields); - request.setOrdering(ordering); - - Document query = null; - - if(searchFields!=null) { - - BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); - - - - query = new Document(); - - for (String key : searchFields.keySet()) { - //builder.append(key, new BasicDBObject("$eq", searchFields.get(key))); - BasicDBObject bs = new BasicDBObject(); - bs.append("$regex", searchFields.get(key)); - bs.append("$options", "i"); - builder.append(key, bs); - //query.put(key, new BasicDBObject("$eq", searchFields.get(key))); - //query = new Document(key, searchFields.get(key)); - } - // query.putAll(builder.get().toMap()); // request.setFilter(query); - - - - BasicDBList list = new BasicDBList(); - list.add(builder.get().toMap()); - query.put("$or", list); - //or(query); - request.setFilter(query); - - - //************************************************ AND + BasicDBList list = new BasicDBList(); + list.add(builder.get().toMap()); + query.put("$or", list); + // or(query); + request.setFilter(query); + + // ************************************************ AND // query = new Document(); // for (String key : searchFields.keySet()) { // //AND @@ -128,75 +120,74 @@ public class TestClass { // // } // request.setFilter(query); - //******************************************** END AND - } - - //OR - /*query = new Document(); - BasicDBObject container = new BasicDBObject(); - BsonArray bArray = new BsonArray(); - for (String key : searchFields.keySet()) { - //AND - BasicDBObject bs = new BasicDBObject(); - bs.append("$regex", searchFields.get(key)); - bs.append("$options", "i"); - query.put(key, bs); - - //container.put(key, bs); - - -// BasicDBObject bs2 = new BasicDBObject(); -// bs2.append("$regex", searchFields.get(key)); -// bs2.append("$options", "i"); -// BsonDocument bsK = new BsonDocument(); -// bsK.append(key, new BsonString(bs2.toJson())); -// bArray.add(bsK); - - } -// query.put("$or", bArray); - - BasicDBList list = new BasicDBList(); - list.add(query); - - Document orDocument = new Document(); - orDocument.put("$or", list); -// - query = orDocument; - request.setFilter(query);*/ - - - - System.out.println("Paging offset: " + offsetIndex + ", limit: " + limitIndex); - System.out.println("Direction: " + sDirection); - System.out.println("Order by Fields: " + orderByFields); - System.out.println("Search for: " + query); - System.out.println("Search for Query to JSON: "+query.toJson()); - - Iterator concessioni = clientMongo.query(request); - - if(concessioni.hasNext()) { - System.out.println("Found concessioni, printing them..."); - }else - System.out.println("No concessione found"); - - if (concessioni != null) { - while (concessioni.hasNext()) { - Concessione concessione = (Concessione) concessioni.next(); - System.out.println(concessione.getNome()); + // ******************************************** END AND + } + + // OR + /* + * query = new Document(); BasicDBObject container = new BasicDBObject(); + * BsonArray bArray = new BsonArray(); for (String key : searchFields.keySet()) + * { //AND BasicDBObject bs = new BasicDBObject(); bs.append("$regex", + * searchFields.get(key)); bs.append("$options", "i"); query.put(key, bs); + * + * //container.put(key, bs); + * + * + * // BasicDBObject bs2 = new BasicDBObject(); // bs2.append("$regex", + * searchFields.get(key)); // bs2.append("$options", "i"); // BsonDocument bsK = + * new BsonDocument(); // bsK.append(key, new BsonString(bs2.toJson())); // + * bArray.add(bsK); + * + * } // query.put("$or", bArray); + * + * BasicDBList list = new BasicDBList(); list.add(query); + * + * Document orDocument = new Document(); orDocument.put("$or", list); // query = + * orDocument; request.setFilter(query); + */ + + System.out.println("Paging offset: " + offsetIndex + ", limit: " + limitIndex); + System.out.println("Direction: " + sDirection); + System.out.println("Order by Fields: " + orderByFields); + System.out.println("Search for: " + query); + System.out.println("Search for Query to JSON: " + query.toJson()); + + Iterator concessioni = clientMongo.query(request); + + if (concessioni.hasNext()) { + System.out.println("Found concessioni, printing them..."); + } else + System.out.println("No concessione found"); + + if (concessioni != null) { + while (concessioni.hasNext()) { + Concessione concessione = (Concessione) concessioni.next(); + System.out.println(concessione.getNome()); + + } } - - } - }catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } } - //@Test + // @Test +// public void readUserRights() throws Exception { +// new GNARoleRitghtsConfigReader(); +// List listUserRights = GNARoleRitghtsConfigReader.readRoleRightsConfig(); +// System.out.println(listUserRights); +// } + + @Test public void readUserRights() throws Exception { - new GNARoleRitghtsConfigReader(); - List listUserRights = GNARoleRitghtsConfigReader.readRoleRightsConfig(); - System.out.println(listUserRights); + GNADataEntryConfigsProfileReader r = new GNADataEntryConfigsProfileReader(); + try { + r.readProfileFromInfrastrucure(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } From 41209285407e4b8611ef1381145cc692b4309d8a Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 6 Dec 2021 17:24:27 +0100 Subject: [PATCH 11/16] #22506 - Re-engineered the common utilities --- .settings/org.eclipse.wst.common.component | 27 +- CHANGELOG.md | 1 + .../ConstantsGeoPortalDataEntryApp.java | 88 +-- .../client/GeoPortalDataEntryApp.java | 78 ++- .../client/GeoportalDataEntryService.java | 12 +- .../GeoportalDataEntryServiceAsync.java | 8 +- .../client/events/ActionOnItemEvent.java | 2 +- .../client/events/GetListOfRecordsEvent.java | 2 +- .../client/ui/GeonaMainTabPanel.java | 74 +-- .../client/ui/GeonaRecordsPaginatedView.java | 8 +- .../client/ui/table/ItemsTable.java | 533 +++++++++--------- .../server/GeoportalDataEntryServiceImpl.java | 265 ++------- .../server/MongoServiceUtil.java | 2 +- .../server/config/CSVFile.java | 152 ----- .../server/config/CSVReader.java | 192 ------- .../server/config/CSVRow.java | 81 --- .../server/config/FileUtil.java | 100 ---- .../server/config/GNADataEntryConfigs.java | 38 -- .../GNADataEntryConfigsProfileReader.java | 282 --------- .../shared/ACTION_ON_ITEM.java | 29 - .../shared/DisplayField.java | 66 --- .../shared/GNAUserRightsConfigException.java | 8 - .../shared/GcubeUserRole.java | 55 -- .../shared/ResultSetPaginatedData.java | 184 ------ .../shared/ResultSetSorted.java | 1 + .../geoportaldataentry/shared/RoleRights.java | 100 ---- .../shared/SearchingFilter.java | 146 ----- .../geoportaldataentry/shared/UserRights.java | 2 + .../geoportaldataentry/client/TestClass.java | 14 +- 29 files changed, 518 insertions(+), 2032 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVFile.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVReader.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVRow.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigs.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigsProfileReader.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ACTION_ON_ITEM.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/DisplayField.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigException.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GcubeUserRole.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/RoleRights.java delete mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchingFilter.java diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index d89609f..71eda66 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -21,7 +22,8 @@ - + + @@ -43,7 +45,8 @@ - + + @@ -65,7 +68,8 @@ - + + @@ -87,7 +91,11 @@ - + + uses + + + @@ -109,7 +117,8 @@ - + + @@ -131,7 +140,8 @@ - + + @@ -153,7 +163,8 @@ - + + diff --git a/CHANGELOG.md b/CHANGELOG.md index f4c2f01..9286d3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - [#22455] Integrated with roles: (Data-Member as default), Data-Manager, Data-Editor - [#22287] Integrated with base search, ordering and filtering facility provided by MongoDB +- [#22506] Re-engineered the common utilities ## [v2.0.1] - 2021-11-17 diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index ccd02b9..b64d7a8 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -39,50 +39,50 @@ public class ConstantsGeoPortalDataEntryApp { UPDATED_PROJECT } - /** - * The Enum RECORD_FIELD. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Sep 2, 2021 - */ - public static enum RECORD_FIELD { - NAME("nome", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("authors", "Author/s"), - PROJECT_START_END_DATE("", "Project Start/End Date"), RECORD_STATUS("recordStatus", "Published with"), CREATED("creationTime", "Created"), - CREATED_BY("creationUser", "Created by"); - - String jsonFieldName; - String displayName; - - /** - * Instantiates a new record field. - * - * @param jsonFieldName the json field name - * @param displayName the display name - */ - RECORD_FIELD(String jsonFieldName, String displayName) { - this.jsonFieldName = jsonFieldName; - this.displayName = displayName; - } - - /** - * Gets the json field name. - * - * @return the json field name - */ - public String getJsonFieldName() { - return jsonFieldName; - } - - /** - * Gets the display name. - * - * @return the display name - */ - public String getDisplayName() { - return displayName; - } - } +// /** +// * The Enum RECORD_FIELD. +// * +// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it +// * +// * Sep 2, 2021 +// */ +// public static enum RECORD_FIELD { +// NAME("nome", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("authors", "Author/s"), +// PROJECT_START_END_DATE("", "Project Start/End Date"), RECORD_STATUS("recordStatus", "Published with"), CREATED("creationTime", "Created"), +// CREATED_BY("creationUser", "Created by"); +// +// String jsonFieldName; +// String displayName; +// +// /** +// * Instantiates a new record field. +// * +// * @param jsonFieldName the json field name +// * @param displayName the display name +// */ +// RECORD_FIELD(String jsonFieldName, String displayName) { +// this.jsonFieldName = jsonFieldName; +// this.displayName = displayName; +// } +// +// /** +// * Gets the json field name. +// * +// * @return the json field name +// */ +// public String getJsonFieldName() { +// return jsonFieldName; +// } +// +// /** +// * Gets the display name. +// * +// * @return the display name +// */ +// public String getDisplayName() { +// return displayName; +// } +// } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index 19de25e..e63be5e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -8,11 +8,17 @@ import java.util.List; import java.util.TreeMap; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +import org.gcube.application.geoportalcommon.shared.ItemField; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; +import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; +import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole; +import org.gcube.application.geoportalcommon.shared.config.RoleRights; +import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEventHandler; @@ -38,15 +44,9 @@ import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil.HTML_TAG; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.NewBrowserWindow; -import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; -import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync; import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm; @@ -107,26 +107,68 @@ public class GeoPortalDataEntryApp implements EntryPoint { private UserRights myRights = null; private LoaderIcon loader = new LoaderIcon("Loading Application..."); + + private List displayFields = new ArrayList(); + private List sortByFields = new ArrayList(); + private List searchByFields = new ArrayList(); /** * This is the entry point method. */ public void onModuleLoad() { - RECORD_FIELD[] sortByOptions = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.PROJECT_START_END_DATE, - RECORD_FIELD.CREATED, RECORD_FIELD.CREATED_BY, RECORD_FIELD.RECORD_STATUS }; - - SearchingFilter initialSortFilter = new SearchingFilter(RECORD_FIELD.NAME, ORDER.ASC); - - RECORD_FIELD[] searchForFields = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.AUTHOR}; +// RECORD_FIELD[] sortByOptions = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.PROJECT_START_END_DATE, +// RECORD_FIELD.CREATED, RECORD_FIELD.CREATED_BY, RECORD_FIELD.RECORD_STATUS }; +// +// SearchingFilter initialSortFilter = new SearchingFilter(RECORD_FIELD.NAME, ORDER.ASC); +// +// RECORD_FIELD[] searchForFields = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.AUTHOR}; RootPanel.get(DIV_PORTLET_ID).add(loader); - mainTabPanel = new GeonaMainTabPanel(appManagerBus, sortByOptions, searchForFields, initialSortFilter); - mainTabPanel.setLoaderVisible("Loading...", true); - geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus); - mainTabPanel.addFormPanel(geoNaMainForm); + GeoportalDataEntryServiceAsync.Util.getInstance().listDisplayFields(new AsyncCallback>() { + + @Override + public void onFailure(Throwable caught) { + // TODO Auto-generated method stub + + } + + @Override + public void onSuccess(List result) { + + + for (ItemField itemField : result) { + if(itemField.isDisplayIntoTable()) { + displayFields.add(itemField); + } + + if(itemField.isSearchable()) { + searchByFields.add(itemField); + } + + if(itemField.isSortable()) { + sortByFields.add(itemField); + } + } + + + GWT.log("List display fields: "+result); + SearchingFilter initialSortFilter = new SearchingFilter(); + initialSortFilter.setOrder(ORDER.ASC); + initialSortFilter.setOrderByFields(Arrays.asList(new ItemField("Name", Arrays.asList("name"), true, true, true))); + + displayFields = result; + mainTabPanel = new GeonaMainTabPanel(appManagerBus, displayFields, sortByFields, searchByFields, initialSortFilter); + mainTabPanel.setLoaderVisible("Loading...", true); + + geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus); + mainTabPanel.addFormPanel(geoNaMainForm); + + } + }); + GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback() { @@ -505,7 +547,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { if (sortFilter == null) { sortFilter = mainTabPanel.getCurrentSortFilter(); } - grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, sortFilter); + grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, displayFields, sortFilter); mainTabPanel.showListOfConcessioniView(grpw); } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java index 9febbfa..f4879b1 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java @@ -3,6 +3,9 @@ package org.gcube.portlets.user.geoportaldataentry.client; import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +import org.gcube.application.geoportalcommon.shared.ItemField; +import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; @@ -10,8 +13,6 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataE import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; -import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; @@ -139,4 +140,11 @@ public interface GeoportalDataEntryService extends RemoteService { */ UserRights getMyRightsInTheContext() throws Exception; + /** + * List display fields. + * + * @return the list + */ + List listDisplayFields(); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java index f9bfb96..9d60dda 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java @@ -3,6 +3,9 @@ package org.gcube.portlets.user.geoportaldataentry.client; import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +import org.gcube.application.geoportalcommon.shared.ItemField; +import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; @@ -10,8 +13,6 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataE import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; -import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; @@ -78,4 +79,7 @@ public interface GeoportalDataEntryServiceAsync void getMyRightsInTheContext(AsyncCallback callback); + + + void listDisplayFields(AsyncCallback> callback); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java index 11f03b3..1def9fc 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java @@ -2,8 +2,8 @@ package org.gcube.portlets.user.geoportaldataentry.client.events; import java.util.List; +import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; import org.gcube.application.geoportalcommon.shared.products.model.RecordDV; -import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import com.google.gwt.event.shared.GwtEvent; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java index 3f85aaa..bd62d1e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/GetListOfRecordsEvent.java @@ -1,8 +1,8 @@ package org.gcube.portlets.user.geoportaldataentry.client.events; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; import com.google.gwt.event.shared.GwtEvent; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java index 952d21a..df69f5f 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java @@ -1,20 +1,21 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.gcube.application.geoportalcommon.shared.ItemField; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; +import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEvent; import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; -import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER; import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Button; @@ -102,13 +103,13 @@ public class GeonaMainTabPanel extends Composite { @UiField Dropdown dropdownSortBy; - + @UiField Dropdown dropdownSearchFor; @UiField Alert alertSortBy; - + @UiField Alert alertSearchFor; @@ -132,14 +133,16 @@ public class GeonaMainTabPanel extends Composite { private HandlerManager appManagerBus; - private RECORD_FIELD[] sortByFields; - - private RECORD_FIELD[] searchForFields; + private List sortByFields; + + private List searchForFields; private SearchingFilter currentSortFilter; private GeonaRecordsPaginatedView grpw = null; + private List displayFields; + /** * Instantiates a new geona main tab panel. * @@ -147,22 +150,24 @@ public class GeonaMainTabPanel extends Composite { * @param sortByFields the sort by fields * @param initialSortFilter */ - public GeonaMainTabPanel(HandlerManager appManagerBus, RECORD_FIELD[] sortByFields, RECORD_FIELD[] searchForFields, - SearchingFilter initialSortFilter) { + public GeonaMainTabPanel(HandlerManager appManagerBus, List displayFields, List sortByFields, + List searchForFields, SearchingFilter initialSortFilter) { initWidget(uiBinder.createAndBindUi(this)); this.appManagerBus = appManagerBus; this.sortByFields = sortByFields; + this.displayFields = displayFields; this.currentSortFilter = initialSortFilter; this.searchForFields = searchForFields; - + alertSortBy.setType(AlertType.INFO); alertSortBy.setClose(false); alertSearchFor.setType(AlertType.INFO); alertSearchFor.setClose(false); + + alertSearchFor.setText(searchForFields.get(0).getDisplayName()); + alertSortBy.setText(toLabelFilter((initialSortFilter.getOrderByFields().get(0)), initialSortFilter.getOrder())); - alertSearchFor.setText(searchForFields[0].getDisplayName()); - alertSortBy.setText(toLabelFilter(initialSortFilter.getOrderByField(), initialSortFilter.getOrder())); bindEvents(); resetSearch.setIconSize(IconSize.TWO_TIMES); resetSearch.setType(ButtonType.LINK); @@ -205,7 +210,7 @@ public class GeonaMainTabPanel extends Composite { } }); - for (RECORD_FIELD record_FIELD : sortByFields) { + for (ItemField record_FIELD : sortByFields) { // if (record_FIELD.equals(RECORD_FIELD.RECORD_STATUS)) // continue; @@ -238,8 +243,8 @@ public class GeonaMainTabPanel extends Composite { } }); } - - for (RECORD_FIELD record_FIELD : searchForFields) { + + for (ItemField record_FIELD : searchForFields) { NavLink nav = new NavLink(record_FIELD.getDisplayName()); dropdownSearchFor.add(nav); @@ -249,16 +254,15 @@ public class GeonaMainTabPanel extends Composite { @Override public void onClick(ClickEvent event) { alertSearchFor.setText(record_FIELD.getDisplayName()); - - if(searchField.getText().length() >= MIN_LENGHT_SERCHING_STRING) { + + if (searchField.getText().length() >= MIN_LENGHT_SERCHING_STRING) { doSearchEvent(); } - + } }); } - navShowOnMap.addClickHandler(new ClickHandler() { @Override @@ -337,11 +341,11 @@ public class GeonaMainTabPanel extends Composite { }); } - + private void doSearchEvent() { String searchText = searchField.getText(); if (searchText.length() < MIN_LENGHT_SERCHING_STRING) { - Window.alert("Please enter at least "+MIN_LENGHT_SERCHING_STRING+" characters"); + Window.alert("Please enter at least " + MIN_LENGHT_SERCHING_STRING + " characters"); return; } @@ -349,8 +353,8 @@ public class GeonaMainTabPanel extends Composite { appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter())); } - private String toLabelFilter(RECORD_FIELD orderBy, ORDER direction) { - String labelFilter = orderBy.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name(); + private String toLabelFilter(ItemField itemField, ORDER direction) { + String labelFilter = itemField.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name(); return labelFilter; } @@ -394,15 +398,15 @@ public class GeonaMainTabPanel extends Composite { SearchingFilter sortFilter = null; try { - RECORD_FIELD recordField = null; - for (RECORD_FIELD value : RECORD_FIELD.values()) { + ItemField recordField = null; + for (ItemField value : sortByFields) { if (array[0].equalsIgnoreCase(value.getDisplayName())) { recordField = value; break; } } ORDER orderField = ORDER.valueOf(array[1]); - sortFilter = new SearchingFilter(recordField, orderField); + sortFilter = new SearchingFilter(Arrays.asList(recordField), orderField); } catch (Exception e) { } @@ -416,12 +420,12 @@ public class GeonaMainTabPanel extends Composite { String searchText = searchField.getText(); if (searchText != null && !searchText.isEmpty()) { Map searchInto = new HashMap(); - - String searchForField = RECORD_FIELD.NAME.getJsonFieldName(); - - for (RECORD_FIELD recordField : searchForFields) { - if(recordField.getDisplayName().equals(alertSearchFor.getText())) { - searchForField = recordField.getJsonFieldName(); + + String searchForField = ""; + + for (ItemField recordField : searchForFields) { + if (recordField.getDisplayName().equals(alertSearchFor.getText())) { + searchForField = recordField.getJsonFields().get(0); continue; } } @@ -451,7 +455,7 @@ public class GeonaMainTabPanel extends Composite { * */ public void instanceAndShowListOfConcessioni() { - grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, currentSortFilter); + grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, displayFields, currentSortFilter); showListOfConcessioniView(grpw); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java index 97277c4..dabccca 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaRecordsPaginatedView.java @@ -2,15 +2,15 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui; import java.util.List; +import org.gcube.application.geoportalcommon.shared.ItemField; +import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp; import org.gcube.portlets.user.geoportaldataentry.client.ui.table.ItemsTable; import org.gcube.portlets.user.geoportaldataentry.client.ui.table.SortedCellTable; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; -import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; import com.google.gwt.core.client.GWT; import com.google.gwt.event.shared.HandlerManager; @@ -61,7 +61,7 @@ public class GeonaRecordsPaginatedView { * @param currentSortFilter the sort by field */ public GeonaRecordsPaginatedView(HandlerManager eventbus, RECORD_TYPE recordType, - RECORD_FIELD[] displayFields, SearchingFilter currentSortFilter) { + List displayFields, SearchingFilter currentSortFilter) { this.recordType = recordType; this.currentSortFilter = currentSortFilter; this.initClassFirstRangeChanged = true; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java index c1be4c0..f938fc3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/table/ItemsTable.java @@ -5,21 +5,18 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui.table; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Set; import org.gcube.application.geoportalcommon.ConvertToDataViewModel; +import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV; import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV.ValidationStatus; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import com.github.gwtbootstrap.client.ui.ButtonCell; import com.github.gwtbootstrap.client.ui.Pagination; -import com.google.gwt.cell.client.Cell.Context; -import com.google.gwt.cell.client.DateCell; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.shared.HandlerManager; @@ -52,21 +49,10 @@ public class ItemsTable extends AbstractItemsCellTable< private static final int ITEMS_PER_PAGE = 10; private static final String NO_DATA = "No data"; - private TextColumn name; - private TextColumn introduction; - private TextColumn author; public static DateTimeFormat dtformat = DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT); - private AbstractDataProvider dataProvider; - - private List displayFields; - private TextColumn startEndProjectColumn; - private TextColumn statusColumn; - // private Column startProjectDateColumn; - // private Column endProjectDateColumn; + private List displayFields; private boolean isAsyncronusTable; - private TextColumn insertedBy; - private Column createdColumn; /** * Instantiates a new items table. @@ -75,9 +61,9 @@ public class ItemsTable extends AbstractItemsCellTable< * @param displayFields the display fields * @param startSortByColumn the start sort by column */ - public ItemsTable(HandlerManager eventBus, RECORD_FIELD[] displayFields) { + public ItemsTable(HandlerManager eventBus, List displayFields) { this.eventBus = eventBus; - setDisplayFields(displayFields); + this.displayFields = displayFields; } /** @@ -106,15 +92,66 @@ public class ItemsTable extends AbstractItemsCellTable< this.isAsyncronusTable = dataProvider instanceof ListDataProvider ? false : true; setEmptyTableMessage(NO_DATA); - if (this.displayFields.contains(RECORD_FIELD.NAME)) { + int i = 0; + for (ItemField itemField : displayFields) { + String displayName = itemField.getDisplayName(); // NAME - name = new TextColumn() { + TextColumn col = new TextColumn() { @Override public String getValue(T object) { + if (object == null) return ""; - return ((ConcessioneDV) object).getNome(); + + if (displayName.equalsIgnoreCase("Name")) { + return ((ConcessioneDV) object).getNome(); + } else if (displayName.equalsIgnoreCase("Introduction")) { + return ((ConcessioneDV) object).getIntroduzione(); + } else if (displayName.equalsIgnoreCase("Author/s")) { + + String toDisplay = ""; + if (object.getAuthors() != null) { + toDisplay = toDisplayAuthors(((ConcessioneDV) object).getAuthors()); + } + return toDisplay; + } else if (displayName.equalsIgnoreCase("Project Start/End Date")) { + + Date dS = null; + Date dE = null; + if (object.getDataInizioProgetto() != null) { + dS = (((ConcessioneDV) object).getDataInizioProgetto()); + } + + if (object.getDataFineProgetto() != null) { + dE = (((ConcessioneDV) object).getDataFineProgetto()); + } + + String dateFormat = ""; + if (dS != null) { + dateFormat += dtformat.format(dS); + } + + dateFormat += " / "; + + if (dE != null) { + dateFormat += dtformat.format(dE); + } + + return dateFormat; + } else if (displayName.equalsIgnoreCase("Published with")) { + ValidationReportDV vr = ((ConcessioneDV) object).getValidationReport(); + if (vr != null && vr.getStatus() != null) + return vr.getStatus().getLabel(); + return ""; + } else if (displayName.equalsIgnoreCase("Created")) { + Date cd = ((ConcessioneDV) object).getCreationTime(); + return dtformat.format(cd); + } else if (displayName.equalsIgnoreCase("Created by")) { + return ((ConcessioneDV) object).getCreationUser(); + } + + return ""; } // ADDING TOOLTIP @@ -122,240 +159,224 @@ public class ItemsTable extends AbstractItemsCellTable< public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) { if (object == null) return; - sb.appendHtmlConstant("
    "); - super.render(context, object, sb); - sb.appendHtmlConstant("
    "); + + if (displayName.equalsIgnoreCase("Published with")) { + String value = getValue(object); + String color = "#000"; + if (value.compareTo(ValidationStatus.PASSED.getLabel()) == 0) { + color = "#32CD32"; + } else if (value.compareTo(ValidationStatus.WARNING.getLabel()) == 0) { + color = "#FF8000"; + } else if (value.compareTo(ValidationStatus.ERROR.getLabel()) == 0) { + color = "red"; + } + sb.appendHtmlConstant(""); + super.render(context, object, sb); + sb.appendHtmlConstant(""); + } else + super.render(context, object, sb); + }; }; - sortedCellTable.addColumn(name, RECORD_FIELD.NAME.getDisplayName(), true); - - if (!isAsyncronusTable) { - Comparator c = new Comparator() { - @Override - public int compare(T o1, T o2) { - return ((ConcessioneDV) o1).getNome().compareTo(((ConcessioneDV) o2).getNome()); - } - }; - - sortedCellTable.setComparator(name, c); + if(i==0) { + //name + sortedCellTable.setColumnWidth(col, 20, Unit.PCT); + }else if (i == 1) { + // intro + sortedCellTable.setColumnWidth(col, 30, Unit.PCT); + } else if (i == 2) { + sortedCellTable.setColumnWidth(col, 15, Unit.PCT); + }else if(i==displayFields.size()-1) { + sortedCellTable.setColumnWidth(col, 120, Unit.PX); } + + sortedCellTable.addColumn(col, itemField.getDisplayName(), true); + i++; } - if (this.displayFields.contains(RECORD_FIELD.INTRODUCTION)) { - - introduction = new TextColumn() { - @Override - public String getValue(T object) { - if (object == null) - return ""; - return ((ConcessioneDV) object).getIntroduzione() != null - ? ((ConcessioneDV) object).getIntroduzione() - : ""; - } - }; - - sortedCellTable.addColumn(introduction, RECORD_FIELD.INTRODUCTION.getDisplayName(), true); - - if (!isAsyncronusTable) { - Comparator c = new Comparator() { - @Override - public int compare(T o1, T o2) { - return ((ConcessioneDV) o1).getIntroduzione().compareTo(((ConcessioneDV) o2).getIntroduzione()); - } - }; - sortedCellTable.setComparator(introduction, c); - } - - // sortedCellTable.setColumnWidth(introduction, 100, Unit.PCT); - - } - - if (this.displayFields.contains(RECORD_FIELD.AUTHOR)) { - - author = new TextColumn() { - @Override - public String getValue(T object) { - if (object == null) - return ""; - - String toDisplay = toDisplayAuthors(((ConcessioneDV) object).getAuthors()); - return toDisplay; - } - }; - - sortedCellTable.addColumn(author, RECORD_FIELD.AUTHOR.getDisplayName(), true); - - if (!isAsyncronusTable) { - Comparator c = new Comparator() { - @Override - public int compare(T o1, T o2) { - String toDisplay1 = toDisplayAuthors(((ConcessioneDV) o1).getAuthors()); - String toDisplay2 = toDisplayAuthors(((ConcessioneDV) o2).getAuthors()); - return toDisplay1.compareTo(toDisplay2); - } - }; - sortedCellTable.setComparator(author, c); - } - - sortedCellTable.setColumnWidth(author, 220, Unit.PX); - - } - - if (this.displayFields.contains(RECORD_FIELD.PROJECT_START_END_DATE)) { - - startEndProjectColumn = new TextColumn() { - @Override - public String getValue(T object) { - if (object == null) - return ""; - - Date dS = null; - Date dE = null; - if(object.getDataInizioProgetto()!=null) { - dS = (((ConcessioneDV) object).getDataInizioProgetto()); - } - - if(object.getDataFineProgetto()!=null) { - dE = (((ConcessioneDV) object).getDataFineProgetto()); - } - - String dateFormat = ""; - if(dS!=null) { - dateFormat+=dtformat.format(dS); - } - - dateFormat+=" / "; - - if(dE!=null) { - dateFormat+=dtformat.format(dE); - } - - return dateFormat; - } - }; - - sortedCellTable.addColumn(startEndProjectColumn, RECORD_FIELD.PROJECT_START_END_DATE.getDisplayName(), - false); - sortedCellTable.setColumnWidth(startEndProjectColumn, 180, Unit.PX); - - } - - if (this.displayFields.contains(RECORD_FIELD.CREATED)) { - - DateCell date = new DateCell(DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT+" "+ConvertToDataViewModel.TIME_FORMAT)); - createdColumn = new Column(date) { - - @Override - public Date getValue(T object) { - if (object == null) - return null; - - return (((ConcessioneDV) object).getCreationTime()); - } - }; - sortedCellTable.addColumn(createdColumn, RECORD_FIELD.CREATED.getDisplayName(), true); - - if (!isAsyncronusTable) { - Comparator c = new Comparator() { - @Override - public int compare(T o1, T o2) { - if (o1 == null) - return -1; - - if (o2 == null) - return 1; - - Date d1 = (((ConcessioneDV) o1).getCreationTime()); - Date d2 = (((ConcessioneDV) o2).getCreationTime()); - - // GWT.log(d1.toString() + "is after "+d2.toString() +" ? "+d2.after(d1)); - - if (d1.after(d2)) - return 1; - else - return -1; - } - }; - GWT.log("date colum sortable"); - sortedCellTable.setComparator(createdColumn, c); - } - - sortedCellTable.setColumnWidth(createdColumn, 150, Unit.PX); - - } - - if (this.displayFields.contains(RECORD_FIELD.CREATED_BY)) { - - // NAME - insertedBy = new TextColumn() { - @Override - public String getValue(T object) { - if (object == null) - return ""; - return ((ConcessioneDV) object).getCreationUser(); - } - }; - - sortedCellTable.addColumn(insertedBy, RECORD_FIELD.CREATED_BY.getDisplayName(), true); - - if (!isAsyncronusTable) { - Comparator c = new Comparator() { - @Override - public int compare(T o1, T o2) { - return ((ConcessioneDV) o1).getCreationUser().compareTo(((ConcessioneDV) o2).getCreationUser()); - } - }; - - sortedCellTable.setComparator(insertedBy, c); - } - sortedCellTable.setColumnWidth(insertedBy, 220, Unit.PX); - } - - if (this.displayFields.contains(RECORD_FIELD.RECORD_STATUS)) { - - statusColumn = new TextColumn() { - @Override - public String getValue(T object) { - if (object == null) - return ""; - - ValidationReportDV vr = ((ConcessioneDV) object).getValidationReport(); - if (vr != null && vr.getStatus() != null) - return vr.getStatus().getLabel(); - return ""; - } - - @Override - public void render(Context context, T object, SafeHtmlBuilder sb) { - // TODO Auto-generated method stub - - String value = getValue(object); - String color = "#000"; - if (value.compareTo(ValidationStatus.PASSED.getLabel()) == 0) { - color = "#32CD32"; - } else if (value.compareTo(ValidationStatus.WARNING.getLabel()) == 0) { - color = "#FF8000"; - } else if (value.compareTo(ValidationStatus.ERROR.getLabel()) == 0) { - color = "red"; - } - sb.appendHtmlConstant(""); - super.render(context, object, sb); - sb.appendHtmlConstant(""); - - } - }; - - sortedCellTable.addColumn(statusColumn, RECORD_FIELD.RECORD_STATUS.getDisplayName(), false); - sortedCellTable.setColumnWidth(statusColumn, 120, Unit.PX); - - } + /* + * if (this.displayFields.contains(RECORD_FIELD.NAME)) { + * + * // NAME name = new TextColumn() { + * + * @Override public String getValue(T object) { if (object == null) return ""; + * return ((ConcessioneDV) object).getNome(); } + * + * // ADDING TOOLTIP + * + * @Override public void render(com.google.gwt.cell.client.Cell.Context context, + * T object, SafeHtmlBuilder sb) { if (object == null) return; + * sb.appendHtmlConstant("
    "); super.render(context, object, sb); + * sb.appendHtmlConstant("
    "); }; }; + * + * sortedCellTable.addColumn(name, RECORD_FIELD.NAME.getDisplayName(), true); + * + * if (!isAsyncronusTable) { Comparator c = new Comparator() { + * + * @Override public int compare(T o1, T o2) { return ((ConcessioneDV) + * o1).getNome().compareTo(((ConcessioneDV) o2).getNome()); } }; + * + * sortedCellTable.setComparator(name, c); } + * + * } + * + * if (this.displayFields.contains(RECORD_FIELD.INTRODUCTION)) { + * + * introduction = new TextColumn() { + * + * @Override public String getValue(T object) { if (object == null) return ""; + * return ((ConcessioneDV) object).getIntroduzione() != null ? ((ConcessioneDV) + * object).getIntroduzione() : ""; } }; + * + * sortedCellTable.addColumn(introduction, + * RECORD_FIELD.INTRODUCTION.getDisplayName(), true); + * + * if (!isAsyncronusTable) { Comparator c = new Comparator() { + * + * @Override public int compare(T o1, T o2) { return ((ConcessioneDV) + * o1).getIntroduzione().compareTo(((ConcessioneDV) o2).getIntroduzione()); } }; + * sortedCellTable.setComparator(introduction, c); } + * + * // sortedCellTable.setColumnWidth(introduction, 100, Unit.PCT); + * + * } + * + * if (this.displayFields.contains(RECORD_FIELD.AUTHOR)) { + * + * author = new TextColumn() { + * + * @Override public String getValue(T object) { if (object == null) return ""; + * + * String toDisplay = toDisplayAuthors(((ConcessioneDV) object).getAuthors()); + * return toDisplay; } }; + * + * sortedCellTable.addColumn(author, RECORD_FIELD.AUTHOR.getDisplayName(), + * true); + * + * if (!isAsyncronusTable) { Comparator c = new Comparator() { + * + * @Override public int compare(T o1, T o2) { String toDisplay1 = + * toDisplayAuthors(((ConcessioneDV) o1).getAuthors()); String toDisplay2 = + * toDisplayAuthors(((ConcessioneDV) o2).getAuthors()); return + * toDisplay1.compareTo(toDisplay2); } }; sortedCellTable.setComparator(author, + * c); } + * + * sortedCellTable.setColumnWidth(author, 220, Unit.PX); + * + * } + * + * if (this.displayFields.contains(RECORD_FIELD.PROJECT_START_END_DATE)) { + * + * startEndProjectColumn = new TextColumn() { + * + * @Override public String getValue(T object) { if (object == null) return ""; + * + * Date dS = null; Date dE = null; if(object.getDataInizioProgetto()!=null) { dS + * = (((ConcessioneDV) object).getDataInizioProgetto()); } + * + * if(object.getDataFineProgetto()!=null) { dE = (((ConcessioneDV) + * object).getDataFineProgetto()); } + * + * String dateFormat = ""; if(dS!=null) { dateFormat+=dtformat.format(dS); } + * + * dateFormat+=" / "; + * + * if(dE!=null) { dateFormat+=dtformat.format(dE); } + * + * return dateFormat; } }; + * + * sortedCellTable.addColumn(startEndProjectColumn, + * RECORD_FIELD.PROJECT_START_END_DATE.getDisplayName(), false); + * sortedCellTable.setColumnWidth(startEndProjectColumn, 180, Unit.PX); + * + * } + * + * if (this.displayFields.contains(RECORD_FIELD.CREATED)) { + * + * DateCell date = new + * DateCell(DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT+" " + * +ConvertToDataViewModel.TIME_FORMAT)); createdColumn = new Column(date) { + * + * @Override public Date getValue(T object) { if (object == null) return null; + * + * return (((ConcessioneDV) object).getCreationTime()); } }; + * sortedCellTable.addColumn(createdColumn, + * RECORD_FIELD.CREATED.getDisplayName(), true); + * + * if (!isAsyncronusTable) { Comparator c = new Comparator() { + * + * @Override public int compare(T o1, T o2) { if (o1 == null) return -1; + * + * if (o2 == null) return 1; + * + * Date d1 = (((ConcessioneDV) o1).getCreationTime()); Date d2 = + * (((ConcessioneDV) o2).getCreationTime()); + * + * // GWT.log(d1.toString() + "is after "+d2.toString() +" ? "+d2.after(d1)); + * + * if (d1.after(d2)) return 1; else return -1; } }; + * GWT.log("date colum sortable"); sortedCellTable.setComparator(createdColumn, + * c); } + * + * sortedCellTable.setColumnWidth(createdColumn, 150, Unit.PX); + * + * } + * + * if (this.displayFields.contains(RECORD_FIELD.CREATED_BY)) { + * + * // NAME insertedBy = new TextColumn() { + * + * @Override public String getValue(T object) { if (object == null) return ""; + * return ((ConcessioneDV) object).getCreationUser(); } }; + * + * sortedCellTable.addColumn(insertedBy, + * RECORD_FIELD.CREATED_BY.getDisplayName(), true); + * + * if (!isAsyncronusTable) { Comparator c = new Comparator() { + * + * @Override public int compare(T o1, T o2) { return ((ConcessioneDV) + * o1).getCreationUser().compareTo(((ConcessioneDV) o2).getCreationUser()); } }; + * + * sortedCellTable.setComparator(insertedBy, c); } + * sortedCellTable.setColumnWidth(insertedBy, 220, Unit.PX); } + * + * if (this.displayFields.contains(RECORD_FIELD.RECORD_STATUS)) { + * + * statusColumn = new TextColumn() { + * + * @Override public String getValue(T object) { if (object == null) return ""; + * + * ValidationReportDV vr = ((ConcessioneDV) object).getValidationReport(); if + * (vr != null && vr.getStatus() != null) return vr.getStatus().getLabel(); + * return ""; } + * + * @Override public void render(Context context, T object, SafeHtmlBuilder sb) { + * // TODO Auto-generated method stub + * + * String value = getValue(object); String color = "#000"; if + * (value.compareTo(ValidationStatus.PASSED.getLabel()) == 0) { color = + * "#32CD32"; } else if (value.compareTo(ValidationStatus.WARNING.getLabel()) == + * 0) { color = "#FF8000"; } else if + * (value.compareTo(ValidationStatus.ERROR.getLabel()) == 0) { color = "red"; } + * sb.appendHtmlConstant(""); + * super.render(context, object, sb); sb.appendHtmlConstant(""); + * + * } }; + * + * sortedCellTable.addColumn(statusColumn, + * RECORD_FIELD.RECORD_STATUS.getDisplayName(), false); + * sortedCellTable.setColumnWidth(statusColumn, 120, Unit.PX); + * + * } + */ } - - + public void enableWriteOperations() { - + } /** @@ -398,15 +419,15 @@ public class ItemsTable extends AbstractItemsCellTable< } } - /** - * Sets the display fields. - * - * @param fields the new display fields - */ - public void setDisplayFields(RECORD_FIELD[] fields) { - this.displayFields = fields != null && fields.length > 0 ? Arrays.asList(fields) - : Arrays.asList(RECORD_FIELD.values()); - } +// /** +// * Sets the display fields. +// * +// * @param fields the new display fields +// */ +// public void setDisplayFields(List fields) { +// this.displayFields = fields != null && fields.size() > 0 ? Arrays.asList(fields) +// : Arrays.asList(RECORD_FIELD.values()); +// } /** * Reset columns table. @@ -424,7 +445,7 @@ public class ItemsTable extends AbstractItemsCellTable< * * @return the displayFields */ - public List getDisplayFields() { + public List getDisplayFields() { return displayFields; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index d20761d..1400d6f 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -1,13 +1,10 @@ package org.gcube.portlets.user.geoportaldataentry.server; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; -import org.bson.Document; import org.gcube.application.geoportal.common.model.legacy.AbstractRelazione; import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths; @@ -16,39 +13,34 @@ import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo; import org.gcube.application.geoportal.common.model.legacy.UploadedImage; import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport; import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest; -import org.gcube.application.geoportal.common.model.rest.QueryRequest; -import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest; -import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction; -import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest; import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportalcommon.ConvertToDataViewModel; import org.gcube.application.geoportalcommon.GeoportalCommon; +import org.gcube.application.geoportalcommon.MongoServiceCommon; +import org.gcube.application.geoportalcommon.config.GNADataConfigProfileReader; +import org.gcube.application.geoportalcommon.shared.GNADataConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; +import org.gcube.application.geoportalcommon.shared.ItemField; +import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; +import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; +import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole; +import org.gcube.application.geoportalcommon.shared.config.RoleRights; +import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE; +import org.gcube.application.geoportalcommon.shared.exception.GNAUserRightsConfigException; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV; import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; import org.gcube.common.portal.PortalContext; import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle; -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; -import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigs; -import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigsProfileReader; -import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; -import org.gcube.portlets.user.geoportaldataentry.shared.DisplayField; -import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException; -import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; -import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter; -import org.gcube.portlets.user.geoportaldataentry.shared.SearchingFilter.ORDER; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; @@ -62,8 +54,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; -import com.mongodb.BasicDBObject; -import com.mongodb.BasicDBObjectBuilder; /** * The server side implementation of the RPC service. @@ -416,195 +406,6 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen return item; } - /** - * Query on mongo. - * - * @param offset the offset - * @param limit the limit - * @param filter the filter - * @param recordType the record type - * @param reloadFromService the reload from service - * @return the result set paginated data - * @throws Exception the exception - */ - private ResultSetPaginatedData queryOnMongo(Integer offset, Integer limit, SearchingFilter filter, String recordType, - boolean reloadFromService) throws Exception { - - try { - - if (recordType.equalsIgnoreCase(RECORD_TYPE.CONCESSIONE.name())) { - SessionUtil.getCurrentContext(getThreadLocalRequest(), true); - MongoServiceUtil serviceUtil = new MongoServiceUtil(); - MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); - - // TODO MUST BE REPLACED BY COUNT - List listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(), - reloadFromService); - int listConcessioniSize = listOfConcessioni.size(); - - Integer offsetIndex = offset; - Integer limitIndex = limit; - - if (offset == null) { - offsetIndex = 0; - } - if (limit == null) { - limitIndex = listConcessioniSize; - } - - ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false); - searchedData.setTotalItems(listConcessioniSize); - - List toReturnList = new ArrayList(); - Direction sDirection = null; - List fields = new ArrayList(); - - if (filter == null) { - LOG.info("No filter found, creating empty filter"); - filter = new SearchingFilter(); - } - - ORDER order = filter.getOrder(); - - if (order == null) { - sDirection = Direction.ASCENDING; - LOG.info("No direction/order found, using default: " + sDirection); - } - - switch (order) { - case ASC: - sDirection = Direction.ASCENDING; - break; - case DESC: - sDirection = Direction.DESCENDING; - break; - } - - RECORD_FIELD orderByFields = filter.getOrderByField(); - - if (orderByFields == null) { - orderByFields = RECORD_FIELD.NAME; - LOG.info("No fields for searching found, using default: " + orderByFields); - } - - switch (orderByFields) { - case NAME: - fields.add(RECORD_FIELD.NAME.getJsonFieldName()); - break; - case CREATED: - fields.add(RECORD_FIELD.CREATED.getJsonFieldName()); - break; - case CREATED_BY: - fields.add(RECORD_FIELD.CREATED_BY.getJsonFieldName()); - break; - // TODO is buggy must be performed by service - case PROJECT_START_END_DATE: - fields.add("dataInizioProgetto"); - fields.add("dataFineProgetto"); - break; - case RECORD_STATUS: - fields.add("report.status"); - // statusComparator = new ConcessioneValidationReportStatusComparator(); - default: - break; - } - - QueryRequest request = new QueryRequest(); - PagedRequest paging = new PagedRequest(); - paging.setOffset(offsetIndex); - paging.setLimit(limitIndex); - request.setPaging(paging); - - OrderedRequest ordering = new OrderedRequest(); - ordering.setDirection(sDirection); - ordering.setFields(fields); - request.setOrdering(ordering); - - Document query = null; - if(filter.getSearchInto()!=null) { - Map searchFields = filter.getSearchInto(); - //List list = new ArrayList(); - //Map map = new HashMap(); - - BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); - for (String key : searchFields.keySet()) { -// query.put(key, searchFields.get(key)); -// query.put(key, new BasicDBObject("$eq", searchFields.get(key))); - - BasicDBObject bs = new BasicDBObject(); - bs.append("$regex", searchFields.get(key)); - bs.append("$options", "i"); - builder.append(key, bs); - } - query = new Document(builder.get().toMap()); -// BasicDBList list = new BasicDBList(); -// list.add(builder.get().toMap()); -// query.put("$and", list); - //or(query); - request.setFilter(query); - } - - LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex); - LOG.info("Direction: " + sDirection); - LOG.info("Order by Fields: " + fields); - LOG.info("Search for: " + filter.getSearchInto()); - if(query!=null) { - LOG.info("Search query to JSON: " + query.toJson()); - } - - Iterator concessioni = clientMongo.query(request); - int i = 0; - while (concessioni.hasNext()) { - Concessione concessione = concessioni.next(); - ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); - toReturnList.add(concessioneDV); - i++; - } - LOG.debug("read " + toReturnList +" project/s"); - - searchedData.setData(toReturnList); - - //TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT - // AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE - if(filter.getSearchInto()!=null){ - searchedData.setTotalItems(toReturnList.size()); - } - - if (listConcessioniSize == limit || listConcessioniSize == 0) { - LOG.debug("Page completed returning " + listConcessioniSize + " items"); - int newOffset = offsetIndex + limitIndex; - searchedData.setServerSearchFinished(newOffset > listConcessioniSize || listConcessioniSize == 0); - LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); - - } - - return searchedData; - } - - } catch (Exception e) { - LOG.error("Error on loading paginated and filtered list of concessioni: ", e); - throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage()); - } - - return null; - - } - - // TODO THIS PART REQUIRES THE JSON MAPPING based on keys read from gCube Meta - /** - * List display fields. - * - * @return the list - */ - // Profile - public List listDisplayFields() { - - List listDisplayFields = new ArrayList(); - DisplayField df = new DisplayField("Name", Arrays.asList("nome"), true); - // etc - return listDisplayFields; - } - /** * Gets the list concessioni. * @@ -619,7 +420,29 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService) throws Exception { LOG.info("getListConcessioni called wit start: " + start + ", limit: " + limit + ", filter: " + filter); - return queryOnMongo(start, limit, filter, "concessione", reloadFromService); + + try { + + SessionUtil.getCurrentContext(getThreadLocalRequest(), true); + + MongoServiceCommon serviceCommon = new MongoServiceCommon(); +// MongoServiceUtil serviceUtil = new MongoServiceUtil(); +// MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); + + // TODO MUST BE REPLACED BY COUNT + List listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(), + reloadFromService); + int listConcessioniSize = listOfConcessioni.size(); + + ResultSetPaginatedData searchedData = serviceCommon.queryOnMongo(listConcessioniSize, start, limit, filter, + "concessione"); + return searchedData; + + } catch (Exception e) { + LOG.error("Error on loading paginated and filtered list of concessioni: ", e); + throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage()); + } + } /** @@ -921,13 +744,13 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen PortalContext pContext = PortalContext.getConfiguration(); user = pContext.getCurrentUser(this.getThreadLocalRequest()); SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); - GNADataEntryConfigsProfileReader gnaConfigReader = new GNADataEntryConfigsProfileReader(); - GNADataEntryConfigs config = gnaConfigReader.readProfileFromInfrastrucure(); - List listUserRightsForRole = config.getPermissionsForRole(); + GNADataConfigProfileReader gnaConfigReader = new GNADataConfigProfileReader(); + GNADataConfigProfile config = gnaConfigReader.readProfileFromInfrastrucure(); + List listUserRightsForRole = config.getPermissionsForRole(); // DEV MODE if (!SessionUtil.isIntoPortal()) { LOG.warn("OUT OF PORTAL - DEV MODE detected"); - GcubeUserRole myRole = GcubeUserRole.DATA_EDITOR; + GcubeUserRole myRole = GcubeUserRole.DATA_MEMBER; for (RoleRights roleRight : listUserRightsForRole) { if (roleRight.getUserRole().equals(myRole)) { @@ -997,4 +820,16 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } + // TODO THIS PART REQUIRES THE JSON MAPPING based on keys read from gCube Meta + /** + * List display fields. + * + * @return the list + */ + @Override + public List listDisplayFields() { + GeoportalCommon gc = new GeoportalCommon(); + return gc.getGNADataConfig().getListItemFields(); + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java index 42bad84..a092374 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java @@ -23,7 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The Class MongoServiceUtil. + * The Class MongoServiceCommon. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVFile.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVFile.java deleted file mode 100644 index 52385eb..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVFile.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * - */ -package org.gcube.portlets.user.geoportaldataentry.server.config; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * The Class CSVFile. - * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) - * Jan 29, 2019 - */ -public class CSVFile implements Serializable{ - - /** - * - */ - private static final long serialVersionUID = 6408321963787244600L; - private CSVRow headerRow; - private List valueRows; - private String fileName; - - /** - * Instantiates a new CSV file. - */ - public CSVFile(){ - - } - - - /** - * Instantiates a new csv file. - * - * @param fileName the file name - * @param headerRow the header row - * @param valueRows the value rows - */ - public CSVFile(String fileName, CSVRow headerRow, List valueRows) { - this.fileName = fileName; - this.headerRow = headerRow; - this.valueRows = valueRows; - } - - - /** - * Gets the header row. - * - * @return the headerRow - */ - public CSVRow getHeaderRow() { - - return headerRow; - } - - /** - * Adds the value row. - * - * @param row the row - */ - public void addValueRow(CSVRow row) { - if(valueRows==null) - valueRows = new ArrayList(); - - valueRows.add(row); - } - - - /** - * Sets the value rows. - * - * @param valueRows the new value rows - */ - public void setValueRows(List valueRows) { - this.valueRows = valueRows; - } - - - /** - * Gets the value rows. - * - * @return the valueRows - */ - public List getValueRows() { - - return valueRows; - } - - - /** - * Sets the header row. - * - * @param headerRow the headerRow to set - */ - public void setHeaderRow(CSVRow headerRow) { - - this.headerRow = headerRow; - } - - - - - /** - * Gets the file name. - * - * @return the fileName - */ - public String getFileName() { - - return fileName; - } - - - - /** - * Sets the file name. - * - * @param fileName the fileName to set - */ - public void setFileName(String fileName) { - - this.fileName = fileName; - } - - - /** - * To string. - * - * @return the string - */ - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - - StringBuilder builder = new StringBuilder(); - builder.append("CSVFile [headerRow="); - builder.append(headerRow); - builder.append(", valueRows="); - builder.append(valueRows); - builder.append(", fileName="); - builder.append(fileName); - builder.append("]"); - return builder.toString(); - } - - - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVReader.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVReader.java deleted file mode 100644 index 51eb5b9..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVReader.java +++ /dev/null @@ -1,192 +0,0 @@ -/** - * - */ - -package org.gcube.portlets.user.geoportaldataentry.server.config; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -/** - * The Class CSVReader. - * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) - * Jan 29, 2019 - */ -public class CSVReader { - - public static final char DEFAULT_SEPARATOR = ','; - public static final char DEFAULT_QUOTE = '"'; - private File file; - private CSVFile csvFile; - - /** - * Instantiates a new CSV reader. - * - * @param file the file - * @throws FileNotFoundException the file not found exception - */ - public CSVReader(File file) throws FileNotFoundException { - - this.file = file; - this.csvFile = new CSVFile(); - readCSV(file); - } - - /** - * Read csv. - * - * @param file the file - * @throws FileNotFoundException the file not found exception - */ - private void readCSV(File file) throws FileNotFoundException { - - Scanner scanner = new Scanner(file); - csvFile.setFileName(file.getName()); - int i = 0; - while (scanner.hasNext()) { - CSVRow csvRow = new CSVRow(); - List line = parseLine(scanner.nextLine()); - csvRow.setListValues(line); - - if(i==0){ - csvFile.setHeaderRow(csvRow); - }else{ - csvFile.addValueRow(csvRow); - } - i++; - - } - scanner.close(); - } - - /** - * Parses the line. - * - * @param cvsLine the cvs line - * @return the list - */ - public static List parseLine(String cvsLine) { - - return parseLine(cvsLine, DEFAULT_SEPARATOR, DEFAULT_QUOTE); - } - - /** - * Parses the line. - * - * @param cvsLine the cvs line - * @param separators the separators - * @return the list - */ - public static List parseLine(String cvsLine, char separators) { - - return parseLine(cvsLine, separators, DEFAULT_QUOTE); - } - - /** - * Parses the line. - * - * @param cvsLine the cvs line - * @param separators the separators - * @param customQuote the custom quote - * @return the list - */ - private static List parseLine(String cvsLine, char separators, char customQuote) { - - List result = new ArrayList<>(); - // if empty, return! - if (cvsLine == null || cvsLine.isEmpty()) { - return result; - } - if (customQuote == ' ') { - customQuote = DEFAULT_QUOTE; - } - if (separators == ' ') { - separators = DEFAULT_SEPARATOR; - } - StringBuffer curVal = new StringBuffer(); - boolean inQuotes = false; - boolean startCollectChar = false; - boolean doubleQuotesInColumn = false; - char[] chars = cvsLine.toCharArray(); - for (char ch : chars) { - if (inQuotes) { - startCollectChar = true; - if (ch == customQuote) { - inQuotes = false; - doubleQuotesInColumn = false; - } - else { - // Fixed : allow "" in custom quote enclosed - if (ch == '\"') { - if (!doubleQuotesInColumn) { - curVal.append(ch); - doubleQuotesInColumn = true; - } - } - else { - curVal.append(ch); - } - } - } - else { - if (ch == customQuote) { - inQuotes = true; - // Fixed : allow "" in empty quote enclosed - if (chars[0] != '"' && customQuote == '\"') { - curVal.append('"'); - } - // double quotes in column will hit this! - if (startCollectChar) { - curVal.append('"'); - } - } - else if (ch == separators) { - result.add(curVal.toString()); - curVal = new StringBuffer(); - startCollectChar = false; - } - else if (ch == '\r') { - // ignore LF characters - continue; - } - else if (ch == '\n') { - // the end, break! - break; - } - else { - curVal.append(ch); - } - } - } - result.add(curVal.toString()); - return result; - } - - - /** - * Gets the csv file. - * - * @return the csvFile - */ - public CSVFile getCsvFile() { - - return csvFile; - } - - - /** - * Gets the file. - * - * @return the file - */ - public File getFile() { - - return file; - } - - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVRow.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVRow.java deleted file mode 100644 index 7b565e8..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/CSVRow.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * - */ -package org.gcube.portlets.user.geoportaldataentry.server.config; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - - -/** - * The Class CSVRow. - * - * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) - * Jan 29, 2019 - */ -public class CSVRow implements Serializable{ - - /** - * - */ - private static final long serialVersionUID = 6254861811998867626L; - - private List listValues; - - /** - * Instantiates a new CSV row. - */ - public CSVRow(){ - - } - - - /** - * Gets the list values. - * - * @return the listValues - */ - public List getListValues() { - - return listValues; - } - - - - /** - * @param listValues the listValues to set - */ - public void setListValues(List listValues) { - - this.listValues = listValues; - } - - - /** - * Adds the value. - * - * @param value the value - */ - public void addValue(String value) { - if(listValues==null) - listValues = new ArrayList(); - - listValues.add(value); - } - - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - - StringBuilder builder = new StringBuilder(); - builder.append("CSVRow [listValues="); - builder.append(listValues); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java deleted file mode 100644 index f1b25e5..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/FileUtil.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.server.config; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; - -/** - * The Class FileUtil. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Dec 2, 2021 - */ -public class FileUtil { - - /** - * Input stream to temp file. - * - * @param inputStream the input stream - * @param fileName the file name - * @return the file - * @throws IOException Signals that an I/O exception has occurred. - */ - // InputStream -> Temp File - public static File inputStreamToTempFile(InputStream inputStream, String fileName) throws IOException { - - File tempFile = File.createTempFile(fileName, ".tmp"); - // File tempFile = File.createTempFile("MyAppName-", ".tmp"); - try (FileOutputStream outputStream = new FileOutputStream(tempFile)) { - - int read; - byte[] bytes = new byte[1024]; - - while ((read = inputStream.read(bytes)) != -1) { - outputStream.write(bytes, 0, read); - } - - return tempFile; - - } finally { - tempFile.deleteOnExit(); - } - - } - - /** - * Input stream to temp file. - * - * @param copyString the copy string - * @return - * @throws IOException Signals that an I/O exception has occurred. - */ - public static File inputStreamToTempFile(String copyString, String prefixFile) throws IOException { - - File targetFile = null; - try { - InputStream initialStream = new ByteArrayInputStream(copyString.getBytes()); - targetFile = File.createTempFile(prefixFile, ".tmp"); - - java.nio.file.Files.copy(initialStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - - try { - if (initialStream != null) { - initialStream.close(); - } - } catch (IOException ioe) { - // ignore - } - return targetFile; - } finally { - try { - if (targetFile != null) - targetFile.deleteOnExit(); - } catch (Exception e) { - - } - } - } - - /** - * Copy input stream to file. - * - * @param is the is - * @param to the to - * @return the file - * @throws IOException Signals that an I/O exception has occurred. - */ - public static File copyInputStreamToFile(InputStream is, String to) throws IOException { - Path dest = Paths.get(to); - Files.copy(is, dest); - return new File(to); - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigs.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigs.java deleted file mode 100644 index cea91a9..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigs.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.server.config; - -import java.util.List; - -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; - - -public class GNADataEntryConfigs { - - List permissionsForRole = null; - - public GNADataEntryConfigs() { - - } - - public GNADataEntryConfigs(List permissionsForRole) { - super(); - this.permissionsForRole = permissionsForRole; - } - - public List getPermissionsForRole() { - return permissionsForRole; - } - - public void setPermissionsForRole(List permissionsForRole) { - this.permissionsForRole = permissionsForRole; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("GNADataEntryConfigs [permissionsForRole="); - builder.append(permissionsForRole); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigsProfileReader.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigsProfileReader.java deleted file mode 100644 index bf267e9..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/config/GNADataEntryConfigsProfileReader.java +++ /dev/null @@ -1,282 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.server.config; - -import static org.gcube.resources.discovery.icclient.ICFactory.client; - -import java.io.File; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.gcube.application.geoportalcommon.shared.exception.ApplicationProfileNotFoundException; -import org.gcube.common.resources.gcore.utils.XPathHelper; -import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.portlets.user.geoportaldataentry.shared.ACTION_ON_ITEM; -import org.gcube.portlets.user.geoportaldataentry.shared.GNAUserRightsConfigException; -import org.gcube.portlets.user.geoportaldataentry.shared.GcubeUserRole; -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights; -import org.gcube.portlets.user.geoportaldataentry.shared.RoleRights.OPERATION_TYPE; -import org.gcube.resources.discovery.client.api.DiscoveryClient; -import org.gcube.resources.discovery.client.queries.api.Query; -import org.gcube.resources.discovery.client.queries.impl.QueryBox; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; - -/** - * The Class GNADataEntryConfigsProfileReader. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Dec 2, 2021 - */ -public class GNADataEntryConfigsProfileReader { - - private static final String RESOURCE_PROFILE_BODY = "/Resource/Profile/Body"; - public static final String SECONDARY_TYPE = "ApplicationProfile"; - public static final String GENERIC_RESOURCE_NAME = "GNA-DataEntry-Configs"; - private static final String TEMP_ROLE_RIGHTS_CONFIG_FILENAME = "GNA_RoleRights_Configurations"; - - private String scope; - - private static final Logger LOG = LoggerFactory.getLogger(GNADataEntryConfigsProfileReader.class); - - /** - * Instantiates a new application profile reader. - */ - public GNADataEntryConfigsProfileReader() { - } - - /** - * Read profile from infrastrucure. - * - * @return the map - * @throws Exception the exception - */ - public GNADataEntryConfigs readProfileFromInfrastrucure() throws Exception { - LOG.info("called readProfileFromInfrastrucure"); - String queryString = getGcubeGenericQueryString(SECONDARY_TYPE, GENERIC_RESOURCE_NAME); - LOG.info("Scope " + scope + ", trying to perform query: " + queryString); - this.scope = ScopeProvider.instance.get(); - - if (scope == null) - throw new Exception("Scope is null, set scope into ScopeProvider"); - - GNADataEntryConfigs gnDEC = new GNADataEntryConfigs(); - String permissions_for_role = ""; - try { - - LOG.info("Trying to fetch GR named: " + GENERIC_RESOURCE_NAME + ", in the scope: " + scope - + ", SecondaryType: " + SECONDARY_TYPE); - Query q = new QueryBox(queryString); - DiscoveryClient client = client(); - List appProfile = client.submit(q); - - if (appProfile == null || appProfile.size() == 0) - throw new ApplicationProfileNotFoundException("GR with SecondaryType: " + SECONDARY_TYPE - + ", and name: " + GENERIC_RESOURCE_NAME + " is not registered in the scope: " + scope); - else { - String elem = appProfile.get(0); - DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = docBuilder.parse(new InputSource(new StringReader(elem))); - - XPathHelper helper = new XPathHelper(doc.getDocumentElement()); - - List currValue = null; - String xPathExp = RESOURCE_PROFILE_BODY + "/permssions_for_role/text()"; - currValue = helper.evaluate(xPathExp); - - if (currValue != null && currValue.size() > 0) { - permissions_for_role = currValue.get(0); - } else - throw new Exception("I'm not able to read the path: " + xPathExp); - - //replacing \n with new_line string - LOG.debug("read permissions_for_role: " + permissions_for_role); - String pfr_with_new_lines = permissions_for_role.replaceAll("\\\\n", System.lineSeparator()); - LOG.debug("permissions_for_role with new lines: " + pfr_with_new_lines); - - List listRoleRights = readRoleRightsConfig(pfr_with_new_lines); - gnDEC.setPermissionsForRole(listRoleRights); - LOG.info("returning: " + gnDEC); - return gnDEC; - } - - } catch (Exception e) { - LOG.error("Error while trying to read the " + SECONDARY_TYPE + " with SecondaryType " - + GENERIC_RESOURCE_NAME + " from scope " + scope, e); - return null; - } finally { - - } - - } - - /** - * To gcube user role. - * - * @param name the name - * @return the gcube user role - */ - public static GcubeUserRole toGcubeUserRole(String name) { - - for (GcubeUserRole gCubeUserRole : GcubeUserRole.values()) { - if (gCubeUserRole.getName().equalsIgnoreCase(name)) - return gCubeUserRole; - } - - return null; - } - - /** - * Read user rights config. - * - * @param permissions_for_role the permissions for role - * @return the list - * @throws GNAUserRightsConfigException the GNA user rights config not found - * exception - */ - public List readRoleRightsConfig(String permissions_for_role) throws GNAUserRightsConfigException { - LOG.debug("readRoleRightsConfig called"); - - File configurationFile = null; - List listUserRights = new ArrayList(); - try { - configurationFile = FileUtil.inputStreamToTempFile(permissions_for_role, TEMP_ROLE_RIGHTS_CONFIG_FILENAME); - - CSVReader reader = new CSVReader(configurationFile); - CSVFile csvFile = reader.getCsvFile(); - - List headerKeys = csvFile.getHeaderRow().getListValues(); - List rows = csvFile.getValueRows(); - - // MAPPING OPERATION TYPE AS READ, WRITE, etc. - Map mapOperationTypes = new HashMap(); - CSVRow operationTypeRow = rows.get(0); - List rowValues = operationTypeRow.getListValues(); - for (int j = 1; j < rowValues.size(); j++) { - String operationType = rowValues.get(j); - RoleRights.OPERATION_TYPE ot = RoleRights.OPERATION_TYPE.UNKNOWN; - if (operationType.equalsIgnoreCase("R")) { - ot = RoleRights.OPERATION_TYPE.READ; - } else if (operationType.equalsIgnoreCase("RW")) { - ot = RoleRights.OPERATION_TYPE.READ_WRITE; - } else if (operationType.equalsIgnoreCase("W")) { - ot = RoleRights.OPERATION_TYPE.WRITE; - } - - mapOperationTypes.put(headerKeys.get(j), ot); - } - - LOG.debug("Map of operation types: " + mapOperationTypes); - - // Starting from index 1 (means the second row in the CSV) - for (int i = 1; i < rows.size(); i++) { - LOG.trace(i + " row"); - RoleRights useRights = new RoleRights(); - CSVRow row = rows.get(i); - - // to map properties - rowValues = row.getListValues(); - - LOG.debug("rowValues: " + rowValues); - Map mapUserRolePermissions = new HashMap(); - - GcubeUserRole gCubeUserRole = toGcubeUserRole(rowValues.get(0)); - - if (gCubeUserRole == null) { - LOG.warn("The Role " + rowValues.get(0) + " not found into roleName of: " + GcubeUserRole.values()); - continue; - } - - useRights.setUserRole(gCubeUserRole); - - for (int j = 1; j < rowValues.size(); j++) { - mapUserRolePermissions.put(headerKeys.get(j), rowValues.get(j)); - } - LOG.debug("Role: " + useRights.getUserRole()); - LOG.debug("Permissions read: " + mapUserRolePermissions); - - Map listPermessions = new HashMap(); - - for (ACTION_ON_ITEM value : ACTION_ON_ITEM.values()) { - String yesno = mapUserRolePermissions.get(value.name()); - - if (yesno != null && yesno.equalsIgnoreCase("yes")) { - listPermessions.put(value, mapOperationTypes.get(value.name())); - } - - } - - useRights.setListPermessions(listPermessions); - -// String writeOwn = mapUserRolePermissions.get(WRITE_OWN_CONFIG); -// if (writeOwn != null && writeOwn.equalsIgnoreCase("yes")) { -// useRights.setWriteOwn(true); -// } -// -// String writeAny = mapUserRolePermissions.get(WRITE_ANY_CONFIG); -// if (writeAny != null && writeAny.equalsIgnoreCase("yes")) { -// useRights.setWriteAny(true); -// } - - listUserRights.add(useRights); - - } - LOG.info("Returning user rights config: " + listUserRights); - return listUserRights; - - } catch (Exception e) { - LOG.error("An error occurred on reading the GNA DataEntry config from: " + permissions_for_role, e); - throw new GNAUserRightsConfigException("Error on reading the GNA DataEntry from: " + permissions_for_role); - } finally { - - if (configurationFile != null) { - try { - configurationFile.delete(); - } catch (Exception e) { - // silent - } - } - } - - } - - /** - * Gets the gcube generic query string. - * - * @param secondaryType the secondary type - * @param genericResourceName the generic resource name - * @return the gcube generic query string - */ - public static String getGcubeGenericQueryString(String secondaryType, String genericResourceName) { - - return "for $profile in collection('/db/Profiles/GenericResource')//Resource " - + "where $profile/Profile/SecondaryType/string() eq '" + secondaryType - + "' and $profile/Profile/Name/string() " + " eq '" + genericResourceName + "'" + "return $profile"; - } - - /** - * Gets the secondary type. - * - * @return the secondary type - */ - public String getSecondaryType() { - return SECONDARY_TYPE; - } - - /** - * Gets the scope. - * - * @return the scope - */ - public String getScope() { - return scope; - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ACTION_ON_ITEM.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ACTION_ON_ITEM.java deleted file mode 100644 index a8aea03..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ACTION_ON_ITEM.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.shared; - -/** - * The Class ACTION_ON_ITEM. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Nov 24, 2021 - */ -public enum ACTION_ON_ITEM { - - CREATE_NEW_PROJECT("Create New Project"), - VIEW_ON_MAP("View on Map"), - SHOW_METADATA("Show Metadata"), - VIEW_REPORT("View the Report"), - EDIT_PROJECT("Edit the Project"), - DELETE_PROJECT("Delete the Project"); - - String label; - - ACTION_ON_ITEM(String label){ - this.label = label; - } - - public String getLabel() { - return label; - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/DisplayField.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/DisplayField.java deleted file mode 100644 index 8d5151e..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/DisplayField.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.shared; - -import java.io.Serializable; -import java.util.List; - -public class DisplayField implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 1856714668390438433L; - - private String displayName; - private List jsonFields; - private boolean sortable; - - public DisplayField(){ - - } - - public DisplayField(String displayName, List jsonFields, boolean sortable) { - super(); - this.displayName = displayName; - this.jsonFields = jsonFields; - this.sortable = sortable; - } - - public String getDisplayName() { - return displayName; - } - - public List getJsonFields() { - return jsonFields; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - public void setJsonFields(List jsonFields) { - this.jsonFields = jsonFields; - } - - public boolean isSortable() { - return sortable; - } - - public void setSortable(boolean sortable) { - this.sortable = sortable; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("DisplayField [displayName="); - builder.append(displayName); - builder.append(", jsonFields="); - builder.append(jsonFields); - builder.append(", sortable="); - builder.append(sortable); - builder.append("]"); - return builder.toString(); - } - - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigException.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigException.java deleted file mode 100644 index 7684f94..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNAUserRightsConfigException.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.shared; - -@SuppressWarnings("serial") -public class GNAUserRightsConfigException extends Exception { - public GNAUserRightsConfigException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GcubeUserRole.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GcubeUserRole.java deleted file mode 100644 index bdb8845..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GcubeUserRole.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.shared; - -/** - * The Enum GcubeUserRole. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Nov 25, 2021 - */ -public enum GcubeUserRole { - - DATA_MEMBER("Data-Member", false, false), - DATA_EDITOR("Data-Editor", true, false), - DATA_MANAGER("Data-Manager", true, true); - - private String name; - private boolean writeOwn; - private boolean writeAny; - - /** - * Instantiates a new gcube user role. - * - * @param name the name - */ - private GcubeUserRole(String name, boolean writeOwn, boolean writeAny) { - this.name = name; - this.writeOwn = writeOwn; - this.writeAny = writeAny; - } - - public String getName() { - return name; - } - - public boolean isWriteOwn() { - return writeOwn; - } - - public boolean isWriteAny() { - return writeAny; - } - - public void setName(String name) { - this.name = name; - } - - public void setWriteOwn(boolean writeOwn) { - this.writeOwn = writeOwn; - } - - public void setWriteAny(boolean writeAny) { - this.writeAny = writeAny; - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java deleted file mode 100644 index fff009d..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetPaginatedData.java +++ /dev/null @@ -1,184 +0,0 @@ -/** - * - */ -package org.gcube.portlets.user.geoportaldataentry.shared; - -import java.io.Serializable; -import java.util.List; - -import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; - -/** - * The Class ResultSetPaginatedData. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Aug 6, 2021 - */ -public class ResultSetPaginatedData implements Serializable { - - /** - * - */ - private static final long serialVersionUID = 6800997954077785719L; - private List data; - private int offset = 0; - private int limit; - private boolean isServerSearchFinished = false; - private long totalItems; - - /** - * Instantiates a new searched folder. - */ - public ResultSetPaginatedData() { - } - - /** - * Instantiates a new result set paginated data. - * - * @param offset the offset - * @param limit the limit - * @param isServerSearchFinished the is server search finished - */ - public ResultSetPaginatedData(int offset, int limit, boolean isServerSearchFinished) { - - this.offset = offset; - this.limit = limit; - this.isServerSearchFinished = isServerSearchFinished; - } - - /** - * Gets the data. - * - * @return the data - */ - public List getData() { - return data; - } - - /** - * Gets the client start index. - * - * @return the client start index - */ - public int getClientStartIndex() { - return offset; - } - - /** - * Gets the limit. - * - * @return the limit - */ - public int getLimit() { - return limit; - } - - /** - * Checks if is server search finished. - * - * @return true, if is server search finished - */ - public boolean isServerSearchFinished() { - return isServerSearchFinished; - } - - /** - * Sets the data. - * - * @param data the new data - */ - public void setData(List data) { - this.data = data; - } - - /** - * Sets the client start index. - * - * @param clientStartIndex the new client start index - */ - public void setClientStartIndex(int clientStartIndex) { - this.offset = clientStartIndex; - } - - /** - * Sets the limit. - * - * @param limit the new limit - */ - public void setLimit(int limit) { - this.limit = limit; - } - - /** - * Sets the server search finished. - * - * @param isServerSearchFinished the new server search finished - */ - public void setServerSearchFinished(boolean isServerSearchFinished) { - this.isServerSearchFinished = isServerSearchFinished; - } - - /** - * Gets the total items. - * - * @return the total items - */ - public long getTotalItems() { - return totalItems; - } - - /** - * Sets the total items. - * - * @param totalItems the new total items - */ - public void setTotalItems(long totalItems) { - this.totalItems = totalItems; - } - - /** - * Gets the serialversionuid. - * - * @return the serialversionuid - */ - public static long getSerialversionuid() { - return serialVersionUID; - } - - /** - * Gets the offset. - * - * @return the offset - */ - public int getOffset() { - return offset; - } - - /** - * Sets the offset. - * - * @param offset the new offset - */ - public void setOffset(int offset) { - this.offset = offset; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ResultSetPaginatedData [data="); - builder.append(data); - builder.append(", offset="); - builder.append(offset); - builder.append(", limit="); - builder.append(limit); - builder.append(", isServerSearchFinished="); - builder.append(isServerSearchFinished); - builder.append(", totalItems="); - builder.append(totalItems); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java index 98017c3..7cc44dc 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/ResultSetSorted.java @@ -4,6 +4,7 @@ import java.io.Serializable; import java.util.List; import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportalcommon.shared.SearchingFilter; public class ResultSetSorted implements Serializable { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/RoleRights.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/RoleRights.java deleted file mode 100644 index 1854240..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/RoleRights.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.shared; - -import java.io.Serializable; -import java.util.Map; - -/** - * The Class RoleRights. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Nov 26, 2021 - */ -public class RoleRights implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -304157165851633221L; - - /** - * The Enum OPERATION_TYPE. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Nov 26, 2021 - */ - public static enum OPERATION_TYPE { - READ, WRITE, READ_WRITE, UNKNOWN - } - - private Map listPermessions; - private GcubeUserRole userRole; - - /** - * Instantiates a new user rights. - */ - public RoleRights() { - super(); - } - - /** - * Instantiates a new role rights. - * - * @param myUsername the my username - * @param listPermessions the list permessions - * @param userRole the user role - */ - public RoleRights(Map listPermessions, GcubeUserRole userRole) { - this.listPermessions = listPermessions; - this.userRole = userRole; - } - - /** - * Gets the list permessions. - * - * @return the list permessions - */ - public Map getListPermessions() { - return listPermessions; - } - - /** - * Gets the user role. - * - * @return the user role - */ - public GcubeUserRole getUserRole() { - return userRole; - } - - /** - * Sets the list permessions. - * - * @param listPermessions the list permessions - */ - public void setListPermessions(Map listPermessions) { - this.listPermessions = listPermessions; - } - - /** - * Sets the user role. - * - * @param userRole the new user role - */ - public void setUserRole(GcubeUserRole userRole) { - this.userRole = userRole; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("RoleRights [listPermessions="); - builder.append(listPermessions); - builder.append(", userRole="); - builder.append(userRole); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchingFilter.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchingFilter.java deleted file mode 100644 index 4990f4c..0000000 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/SearchingFilter.java +++ /dev/null @@ -1,146 +0,0 @@ -package org.gcube.portlets.user.geoportaldataentry.shared; - -import java.io.Serializable; -import java.util.Map; - -import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_FIELD; - -/** - * The Class SearchingFilter. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Nov 30, 2021 - */ -public class SearchingFilter implements Serializable { - - /** - * The Enum ORDER. - * - * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it - * - * Nov 30, 2021 - */ - public static enum ORDER { - ASC("ASCENDING"), DESC("DESCENDING"); - - String label; - - /** - * Instantiates a new order. - * - * @param label the label - */ - ORDER(String label) { - this.label = label; - } - - /** - * Gets the label. - * - * @return the label - */ - public String getLabel() { - return label; - } - } - - /** - * - */ - private static final long serialVersionUID = -4004094263090373626L; - - private RECORD_FIELD orderByField; - - private ORDER order; - - private Map searchInto; - - /** - * Instantiates a new sort filter. - */ - public SearchingFilter() { - - } - - /** - * Instantiates a new sort filter. - * - * @param orderByField the order by field - * @param order the order - */ - public SearchingFilter(RECORD_FIELD orderByField, ORDER order) { - this.orderByField = orderByField; - this.order = order; - } - - /** - * Instantiates a new sort filter. - * - * @param orderByField the order by field - * @param order the order - */ - public SearchingFilter(RECORD_FIELD orderByField, ORDER order, Map searchInto) { - this.orderByField = orderByField; - this.order = order; - this.searchInto = searchInto; - } - - public void setSearchInto(Map searchInto) { - this.searchInto = searchInto; - } - - /** - * Gets the order by field. - * - * @return the order by field - */ - public RECORD_FIELD getOrderByField() { - return orderByField; - } - - /** - * Gets the order. - * - * @return the order - */ - public ORDER getOrder() { - return order; - } - - /** - * Sets the order by field. - * - * @param orderByField the new order by field - */ - public void setOrderByField(RECORD_FIELD orderByField) { - this.orderByField = orderByField; - } - - /** - * Sets the order. - * - * @param order the new order - */ - public void setOrder(ORDER order) { - this.order = order; - } - - public Map getSearchInto() { - return searchInto; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("SearchingFilter [orderByField="); - builder.append(orderByField); - builder.append(", order="); - builder.append(order); - builder.append(", searchInto="); - builder.append(searchInto); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java index 4750a16..2b25960 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/UserRights.java @@ -2,6 +2,8 @@ package org.gcube.portlets.user.geoportaldataentry.shared; import java.io.Serializable; +import org.gcube.application.geoportalcommon.shared.config.RoleRights; + /** * The Class UserRights. * diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index ea61850..417b437 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -16,11 +16,10 @@ import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedReq import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction; import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest; import org.gcube.application.geoportal.common.rest.MongoConcessioni; +import org.gcube.application.geoportalcommon.config.GNADataConfigProfileReader; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.portlets.user.geoportaldataentry.server.config.GNADataEntryConfigsProfileReader; import org.junit.Before; -import org.junit.Test; import com.mongodb.BasicDBList; import com.mongodb.BasicDBObject; @@ -179,15 +178,6 @@ public class TestClass { // System.out.println(listUserRights); // } - @Test - public void readUserRights() throws Exception { - GNADataEntryConfigsProfileReader r = new GNADataEntryConfigsProfileReader(); - try { - r.readProfileFromInfrastrucure(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + } From ca09e9ef94519baa5099f9a7962cd1ce4e91ef0c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 7 Dec 2021 17:14:03 +0100 Subject: [PATCH 12/16] removed unused code --- .../ConstantsGeoPortalDataEntryApp.java | 49 +------------------ .../client/GeoPortalDataEntryApp.java | 10 +--- 2 files changed, 2 insertions(+), 57 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index b64d7a8..4475190 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -33,56 +33,9 @@ public class ConstantsGeoPortalDataEntryApp { * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Nov 25, 2021 + * Nov 25, 2021 */ public enum ACTION_PERFORMED_ON_ITEM { UPDATED_PROJECT } - -// /** -// * The Enum RECORD_FIELD. -// * -// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it -// * -// * Sep 2, 2021 -// */ -// public static enum RECORD_FIELD { -// NAME("nome", "Name"), INTRODUCTION("introduction", "Introduction"), AUTHOR("authors", "Author/s"), -// PROJECT_START_END_DATE("", "Project Start/End Date"), RECORD_STATUS("recordStatus", "Published with"), CREATED("creationTime", "Created"), -// CREATED_BY("creationUser", "Created by"); -// -// String jsonFieldName; -// String displayName; -// -// /** -// * Instantiates a new record field. -// * -// * @param jsonFieldName the json field name -// * @param displayName the display name -// */ -// RECORD_FIELD(String jsonFieldName, String displayName) { -// this.jsonFieldName = jsonFieldName; -// this.displayName = displayName; -// } -// -// /** -// * Gets the json field name. -// * -// * @return the json field name -// */ -// public String getJsonFieldName() { -// return jsonFieldName; -// } -// -// /** -// * Gets the display name. -// * -// * @return the display name -// */ -// public String getDisplayName() { -// return displayName; -// } -// } - - } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index e63be5e..d6b3d04 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -117,21 +117,13 @@ public class GeoPortalDataEntryApp implements EntryPoint { */ public void onModuleLoad() { -// RECORD_FIELD[] sortByOptions = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.PROJECT_START_END_DATE, -// RECORD_FIELD.CREATED, RECORD_FIELD.CREATED_BY, RECORD_FIELD.RECORD_STATUS }; -// -// SearchingFilter initialSortFilter = new SearchingFilter(RECORD_FIELD.NAME, ORDER.ASC); -// -// RECORD_FIELD[] searchForFields = new RECORD_FIELD[] { RECORD_FIELD.NAME, RECORD_FIELD.AUTHOR}; - RootPanel.get(DIV_PORTLET_ID).add(loader); - GeoportalDataEntryServiceAsync.Util.getInstance().listDisplayFields(new AsyncCallback>() { @Override public void onFailure(Throwable caught) { - // TODO Auto-generated method stub + Window.alert(caught.getMessage()); } From b028fcd4b470b49b09bcbbdebfbf034b17a70a2e Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 13 Dec 2021 11:27:03 +0100 Subject: [PATCH 13/16] Added "Logged in" role label --- .../client/GeoPortalDataEntryApp.java | 15 ++++++++++++--- .../client/ui/GeonaMainTabPanel.java | 8 ++++++++ .../client/ui/GeonaMainTabPanel.ui.xml | 2 ++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index d6b3d04..e354a9e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -186,10 +186,19 @@ public class GeoPortalDataEntryApp implements EntryPoint { } catch (Exception e) { } - - initGUI(); + myRights = result; - + initGUI(); + GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); + String msg = "Logged in as "; + if(userRole != null && userRole.getName()!=null) { + msg+= userRole.getName().substring(userRole.getName().indexOf("-")+1, userRole.getName().length()); + }else + msg+="Member"; + + mainTabPanel.setRoleLabel(msg); + + RoleRights roleRights = myRights.getRoleRights(); boolean canCreateNewItem = roleRights.getListPermessions().keySet().contains(ACTION_ON_ITEM.CREATE_NEW_PROJECT); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java index df69f5f..462bfbd 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java @@ -38,6 +38,7 @@ import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; @@ -130,6 +131,9 @@ public class GeonaMainTabPanel extends Composite { @UiField Button resetSearch; + + @UiField + Label roleLabel; private HandlerManager appManagerBus; @@ -341,6 +345,10 @@ public class GeonaMainTabPanel extends Composite { }); } + + public void setRoleLabel(String msg) { + roleLabel.setText(msg); + } private void doSearchEvent() { String searchText = searchField.getText(); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml index 71adb1a..7f5e5ec 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.ui.xml @@ -52,6 +52,8 @@ GNA + From 03779582ad729d273e20856dd7f35a339aa8a302 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 15 Dec 2021 15:43:36 +0100 Subject: [PATCH 14/16] integrated with WhereClause --- .../geoportaldataentry/client/ui/GeonaMainTabPanel.java | 7 ++++++- .../server/GeoportalDataEntryServiceImpl.java | 2 -- .../portlets/user/geoportaldataentry/client/TestClass.java | 6 ++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java index 462bfbd..7b3b4fc 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaMainTabPanel.java @@ -7,7 +7,9 @@ import java.util.Map; import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.SearchingFilter; +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.config.ACTION_ON_ITEM; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; @@ -438,7 +440,10 @@ public class GeonaMainTabPanel extends Composite { } } searchInto.put(searchForField, searchText); - searchingFilter.setSearchInto(searchInto); + WhereClause where = new WhereClause(); + where.setSearchInto(searchInto); + where.setOperator(LOGICAL_OP.OR); + searchingFilter.setConditions(Arrays.asList(where)); } return searchingFilter; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index 1400d6f..9725262 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -426,8 +426,6 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen SessionUtil.getCurrentContext(getThreadLocalRequest(), true); MongoServiceCommon serviceCommon = new MongoServiceCommon(); -// MongoServiceUtil serviceUtil = new MongoServiceUtil(); -// MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); // TODO MUST BE REPLACED BY COUNT List listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(), diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java index 417b437..4119769 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/client/TestClass.java @@ -16,10 +16,8 @@ import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedReq import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction; import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest; import org.gcube.application.geoportal.common.rest.MongoConcessioni; -import org.gcube.application.geoportalcommon.config.GNADataConfigProfileReader; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; -import org.junit.Before; import com.mongodb.BasicDBList; import com.mongodb.BasicDBObject; @@ -31,7 +29,7 @@ public class TestClass { private static String CONTEXT = "/gcube/devsec/devVRE"; private static String USERNAME = "francesco.mangiacrapa"; - @Before + //@Before public void init() { ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); @@ -55,7 +53,7 @@ public class TestClass { } } - // @Test + //@Test public void queryConcessioniTest() throws Exception { try { MongoConcessioni clientMongo = mongoConcessioni().build(); From 8dd267730cfdd2c61c6900b8fa43d8c951cd6bfd Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 21 Dec 2021 16:51:56 +0100 Subject: [PATCH 15/16] ported to GNADataEntryConfigProfile --- .../client/GeoPortalDataEntryApp.java | 125 ++++++++++++++++-- .../client/GeoportalDataEntryService.java | 18 +-- .../GeoportalDataEntryServiceAsync.java | 55 +++----- .../server/GeoportalDataEntryServiceImpl.java | 88 ++++++------ .../server/SessionUtil.java | 40 +++++- .../shared/GNADataEntryExtConfigProfile.java | 46 +++++++ 6 files changed, 265 insertions(+), 107 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNADataEntryExtConfigProfile.java diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index e354a9e..1cc19fd 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -45,6 +45,7 @@ import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil.HTML_ import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.NewBrowserWindow; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; @@ -119,7 +120,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { RootPanel.get(DIV_PORTLET_ID).add(loader); - GeoportalDataEntryServiceAsync.Util.getInstance().listDisplayFields(new AsyncCallback>() { + /*GeoportalDataEntryServiceAsync.Util.getInstance().listDisplayFields(new AsyncCallback>() { @Override public void onFailure(Throwable caught) { @@ -129,10 +130,9 @@ public class GeoPortalDataEntryApp implements EntryPoint { @Override public void onSuccess(List result) { - for (ItemField itemField : result) { - if(itemField.isDisplayIntoTable()) { + if(itemField.isDisplayAsResult()) { displayFields.add(itemField); } @@ -159,10 +159,9 @@ public class GeoPortalDataEntryApp implements EntryPoint { mainTabPanel.addFormPanel(geoNaMainForm); } - }); + });*/ - - GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback() { + GeoportalDataEntryServiceAsync.Util.getInstance().readDataViewerConfig(new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -176,18 +175,49 @@ public class GeoPortalDataEntryApp implements EntryPoint { } RootPanel.get(DIV_PORTLET_ID).add(alert); Window.alert(errorMsg); - + } @Override - public void onSuccess(UserRights result) { + public void onSuccess(GNADataEntryExtConfigProfile gNADataEntryConfig) { + try { RootPanel.get(DIV_PORTLET_ID).remove(loader); } catch (Exception e) { } - myRights = result; + List itemFields = gNADataEntryConfig.getListItemFields(); + + for (ItemField itemField : itemFields) { + if(itemField.isDisplayAsResult()) { + displayFields.add(itemField); + } + + if(itemField.isSearchable()) { + searchByFields.add(itemField); + } + + if(itemField.isSortable()) { + sortByFields.add(itemField); + } + } + + + GWT.log("List display fields: "+itemFields); + SearchingFilter initialSortFilter = new SearchingFilter(); + initialSortFilter.setOrder(ORDER.ASC); + initialSortFilter.setOrderByFields(Arrays.asList(new ItemField("Name", Arrays.asList("name"), true, true, true))); + + displayFields = itemFields; + mainTabPanel = new GeonaMainTabPanel(appManagerBus, displayFields, sortByFields, searchByFields, initialSortFilter); + mainTabPanel.setLoaderVisible("Loading...", true); + + geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus); + mainTabPanel.addFormPanel(geoNaMainForm); + + //PERMISSIONS + myRights = gNADataEntryConfig.getUserRights(); initGUI(); GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); String msg = "Logged in as "; @@ -231,9 +261,84 @@ public class GeoPortalDataEntryApp implements EntryPoint { } }); - + } }); + + + +// GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback() { +// +// @Override +// public void onFailure(Throwable caught) { +// String errorMsg = "Sorry, an error occurrend on istancing the application. Please, contact the support"; +// Alert alert = new Alert(errorMsg, AlertType.ERROR); +// alert.setClose(false); +// try { +// RootPanel.get(DIV_PORTLET_ID).remove(loader); +// } catch (Exception e) { +// +// } +// RootPanel.get(DIV_PORTLET_ID).add(alert); +// Window.alert(errorMsg); +// +// } +// +// @Override +// public void onSuccess(UserRights result) { +// try { +// RootPanel.get(DIV_PORTLET_ID).remove(loader); +// } catch (Exception e) { +// +// } +// +// myRights = result; +// initGUI(); +// GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); +// String msg = "Logged in as "; +// if(userRole != null && userRole.getName()!=null) { +// msg+= userRole.getName().substring(userRole.getName().indexOf("-")+1, userRole.getName().length()); +// }else +// msg+="Member"; +// +// mainTabPanel.setRoleLabel(msg); +// +// +// RoleRights roleRights = myRights.getRoleRights(); +// boolean canCreateNewItem = roleRights.getListPermessions().keySet().contains(ACTION_ON_ITEM.CREATE_NEW_PROJECT); +// +// if (!canCreateNewItem) { +// // removing Tab "Create New Project" +// mainTabPanel.removeTab(0); +// // activating Tab "List of Project" +// mainTabPanel.setTabActive(0); +// mainTabPanel.instanceAndShowListOfConcessioni(); +// return; +// } +// +// GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback() { +// +// @Override +// public void onFailure(Throwable caught) { +// Window.alert( +// "Sorry, an error occurrend when loading configurations. Please, contact the support"); +// } +// +// @Override +// public void onSuccess(GeonaISConfig result) { +// +// if (result != null && result.getgRSecondaryType() != null +// && result.getScope() != null) { +// callGetMetadataProfiles(result.getScope(), result.getgRSecondaryType()); +// } else +// Window.alert( +// "Sorry, no configuration found in the context. Please, contact the support"); +// +// } +// }); +// +// } +// }); } private void initGUI() { diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java index f4879b1..d2d8bb0 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java @@ -3,7 +3,6 @@ package org.gcube.portlets.user.geoportaldataentry.client; import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; -import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; @@ -11,9 +10,9 @@ import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceCo import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; -import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import com.google.gwt.user.client.rpc.RemoteService; @@ -133,18 +132,11 @@ public interface GeoportalDataEntryService extends RemoteService { List keepCurrentContent, GenericDatasetBean gDBean) throws Exception; /** - * Gets the my rights in the context. + * Read data viewer config. * - * @return the my rights in the context - * @throws Exception + * @return the GNA data entry ext config profile + * @throws Exception the exception */ - UserRights getMyRightsInTheContext() throws Exception; - - /** - * List display fields. - * - * @return the list - */ - List listDisplayFields(); + GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java index 9d60dda..c3593de 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java @@ -3,7 +3,6 @@ package org.gcube.portlets.user.geoportaldataentry.client; import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; -import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; @@ -11,75 +10,57 @@ import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceCo import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; -import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; -public interface GeoportalDataEntryServiceAsync -{ +public interface GeoportalDataEntryServiceAsync { - /** - * Utility class to get the RPC Async interface from client-side code - */ - public static final class Util - { - private static GeoportalDataEntryServiceAsync instance; + /** + * Utility class to get the RPC Async interface from client-side code + */ + public static final class Util { + private static GeoportalDataEntryServiceAsync instance; - public static final GeoportalDataEntryServiceAsync getInstance() - { - if ( instance == null ) - { - instance = (GeoportalDataEntryServiceAsync) GWT.create( GeoportalDataEntryService.class ); - } - return instance; - } - - private Util() - { - // Utility class should not be instantiated - } - } + public static final GeoportalDataEntryServiceAsync getInstance() { + if (instance == null) { + instance = (GeoportalDataEntryServiceAsync) GWT.create(GeoportalDataEntryService.class); + } + return instance; + } + private Util() { + // Utility class should not be instantiated + } + } void saveGeonaDataForms(List listGeonaFormObjects, AsyncCallback callback); - void getGeonaInitConfig(AsyncCallback callback); - void getLinksFor(String itemId, RECORD_TYPE recordType, AsyncCallback callback); - void getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService, AsyncCallback callback); - void deleteRecord(String itemId, RECORD_TYPE recordType, AsyncCallback callback); - void getJSONRecord(String itemId, RECORD_TYPE recordType, AsyncCallback callback); - void updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType, AsyncCallback callback); - void readFileSetPaths(AsyncCallback callback); - void getRecord(String itemId, RECORD_TYPE recordType, AsyncCallback callback); - void updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, List keepCurrentContent, GenericDatasetBean gDBean, AsyncCallback callback); + void readDataViewerConfig(AsyncCallback asyncCallback); - void getMyRightsInTheContext(AsyncCallback callback); - - - void listDisplayFields(AsyncCallback> callback); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index 9725262..b48dca5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -17,19 +17,18 @@ import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportalcommon.ConvertToDataViewModel; import org.gcube.application.geoportalcommon.GeoportalCommon; +//import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.MongoServiceCommon; -import org.gcube.application.geoportalcommon.config.GNADataConfigProfileReader; -import org.gcube.application.geoportalcommon.shared.GNADataConfigProfile; -import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; +import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; +import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; -import org.gcube.application.geoportalcommon.shared.ItemField; import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole; import org.gcube.application.geoportalcommon.shared.config.RoleRights; import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE; -import org.gcube.application.geoportalcommon.shared.exception.GNAUserRightsConfigException; +import org.gcube.application.geoportalcommon.shared.exception.GNAConfigException; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV; @@ -39,6 +38,7 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitl import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; +import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.UserRights; @@ -68,6 +68,29 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen public static final String GEONA_GENERIC_RESOURCE_SECONDARY_TYPE = "GEONA_GENERIC_RESOURCE_SECONDARY_TYPE"; private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataEntryServiceImpl.class); + /** + * Gets the GNA data entry config profile. + * + * @return the GNA data entry config profile + * @throws Exception the exception + */ + private GNADataEntryConfigProfile getGNADataEntryConfigProfile() throws Exception { + + GNADataEntryConfigProfile profile = SessionUtil.getGNADataEntryConfigProfile(getThreadLocalRequest()); + if (profile == null) { + LOG.info(GNADataEntryConfigProfile.class.getSimpleName() + " is null, loading configurations from IS"); + //to be sure + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + GeoportalCommon gCommon = new GeoportalCommon(); + profile = gCommon.readGNADataEntryConfig(); + SessionUtil.setGNADataEntryConfigProfile(getThreadLocalRequest(), profile); + } else { + LOG.info(GNADataEntryConfigProfile.class.getSimpleName() + " read from session"); + } + + return profile; + } + /** * Save geona data forms. * @@ -398,7 +421,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen LOG.info("getLinksFor called"); SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); - GeoNaDataViewerProfile grViewerProfile = SessionUtil.getGeportalViewerResourceProfile(getThreadLocalRequest()); + GNADataViewerConfigProfile grViewerProfile = SessionUtil + .getGeportalViewerResourceProfile(getThreadLocalRequest()); GeoportalCommon gc = new GeoportalCommon(grViewerProfile); GeoNaItemRef item = new GeoNaItemRef(itemId, recordType.toString().toLowerCase()); item = gc.getPublicLinksFor(item, false); @@ -424,7 +448,6 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen try { SessionUtil.getCurrentContext(getThreadLocalRequest(), true); - MongoServiceCommon serviceCommon = new MongoServiceCommon(); // TODO MUST BE REPLACED BY COUNT @@ -725,41 +748,38 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen "Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage()); } } - - /** - * Gets the my rights in the context. - * - * @return the my rights in the context - * @throws Exception the exception - */ + @Override - public UserRights getMyRightsInTheContext() throws Exception { - LOG.info("getMyRightsInTheContext called"); + public GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception { + LOG.info("readDataViewerConfig called"); GCubeUser user = null; - + GNADataEntryExtConfigProfile gnaDEExtConfig = new GNADataEntryExtConfigProfile(); try { PortalContext pContext = PortalContext.getConfiguration(); user = pContext.getCurrentUser(this.getThreadLocalRequest()); - SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); - GNADataConfigProfileReader gnaConfigReader = new GNADataConfigProfileReader(); - GNADataConfigProfile config = gnaConfigReader.readProfileFromInfrastrucure(); + String scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + + GNADataEntryConfigProfile config = getGNADataEntryConfigProfile(); List listUserRightsForRole = config.getPermissionsForRole(); + gnaDEExtConfig.setListItemFields(config.getListItemFields()); + gnaDEExtConfig.setPermissionsForRole(listUserRightsForRole); + // DEV MODE if (!SessionUtil.isIntoPortal()) { LOG.warn("OUT OF PORTAL - DEV MODE detected"); - GcubeUserRole myRole = GcubeUserRole.DATA_MEMBER; + GcubeUserRole myRole = GcubeUserRole.DATA_EDITOR; for (RoleRights roleRight : listUserRightsForRole) { if (roleRight.getUserRole().equals(myRole)) { UserRights userRights = new UserRights(user.getUsername(), roleRight); LOG.warn("DEV MODE returning: " + userRights); - return userRights; + gnaDEExtConfig.setUserRights(userRights); + return gnaDEExtConfig; } } } - String scope = pContext.getCurrentScope(this.getThreadLocalRequest()); long groupId = pContext.getCurrentGroupId(this.getThreadLocalRequest()); if (user == null || scope == null) { @@ -805,29 +825,17 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } UserRights userRights = new UserRights(user.getUsername(), toRoleRight); LOG.info("returning: " + userRights); - return userRights; - } catch (UserRetrievalFault | GroupRetrievalFault | GNAUserRightsConfigException e) { + gnaDEExtConfig.setUserRights(userRights); + return gnaDEExtConfig; + } catch (UserRetrievalFault | GroupRetrievalFault | GNAConfigException e) { LOG.error("An error occurred during getMyRightsInTheContext: " + user, e); Map permissions = new HashMap(); RoleRights roleRights = new RoleRights(permissions, GcubeUserRole.DATA_MEMBER); UserRights ur = new UserRights(user.getUsername(), roleRights); LOG.warn("Returning default user rights: " + ur); - return ur; + gnaDEExtConfig.setUserRights(ur); + return gnaDEExtConfig; } - } - - // TODO THIS PART REQUIRES THE JSON MAPPING based on keys read from gCube Meta - /** - * List display fields. - * - * @return the list - */ - @Override - public List listDisplayFields() { - GeoportalCommon gc = new GeoportalCommon(); - return gc.getGNADataConfig().getListItemFields(); - } - } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java index 99cb439..80e1177 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java @@ -13,7 +13,8 @@ import javax.servlet.http.HttpSession; import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportalcommon.GeoportalCommon; -import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; +import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; +import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; @@ -38,6 +39,8 @@ import com.liferay.portal.service.UserLocalServiceUtil; */ public class SessionUtil { + private static final String GNA_DATAENTRY_CONFIG_PROFILE = "GNA_DATAENTRY_CONFIG_PROFILE"; + private static final String LATEST_RESULT_SET_SORTED = "LATEST_RESULT_SET_SORTED"; private static final String GEONA_DATAVIEWER_PROFILE = "GEONA_DATAVIEWER_PROFILE"; private static final String LIST_OF_CONCESSIONI = "LIST_OF_CONCESSIONI"; /** The log. */ @@ -147,7 +150,7 @@ public class SessionUtil { SessionUtil.getCurrentContext(httpServletRequest, true); MongoServiceUtil serviceUtil = new MongoServiceUtil(); MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); - + Iterator concessioni = clientMongo.getList(); if (concessioni != null) { while (concessioni.hasNext()) { @@ -173,15 +176,15 @@ public class SessionUtil { * @return the geportal viewer resource profile * @throws Exception the exception */ - public static GeoNaDataViewerProfile getGeportalViewerResourceProfile(HttpServletRequest httpServletRequest) + public static GNADataViewerConfigProfile getGeportalViewerResourceProfile(HttpServletRequest httpServletRequest) throws Exception { HttpSession session = httpServletRequest.getSession(); - GeoNaDataViewerProfile geoNaDataViewerProfile = (GeoNaDataViewerProfile) session + GNADataViewerConfigProfile geoNaDataViewerProfile = (GNADataViewerConfigProfile) session .getAttribute(GEONA_DATAVIEWER_PROFILE); if (geoNaDataViewerProfile == null) { GeoportalCommon gc = new GeoportalCommon(); - geoNaDataViewerProfile = gc.getGeoNaDataViewProfile(null); + geoNaDataViewerProfile = gc.readGNADataViewerConfig(null); session.setAttribute(GEONA_DATAVIEWER_PROFILE, geoNaDataViewerProfile); } @@ -197,18 +200,41 @@ public class SessionUtil { */ public static ResultSetSorted getLatestResultSetSorted(HttpServletRequest httpServletRequest) { HttpSession session = httpServletRequest.getSession(); - return (ResultSetSorted) session.getAttribute("LATEST_RESULT_SET_SORTED"); + return (ResultSetSorted) session.getAttribute(LATEST_RESULT_SET_SORTED); } /** * Gets the latest sort filter. * * @param httpServletRequest the http servlet request + * @param rsSorted the rs sorted * @return the latest sort filter */ public static void setLatestResultSetSorted(HttpServletRequest httpServletRequest, ResultSetSorted rsSorted) { HttpSession session = httpServletRequest.getSession(); - session.setAttribute("LATEST_RESULT_SET_SORTED", rsSorted); + session.setAttribute(LATEST_RESULT_SET_SORTED, rsSorted); } + /** + * Gets the GNA data entry config profile. + * + * @param httpServletRequest the http servlet request + * @return the GNA data entry config profile + */ + public static GNADataEntryConfigProfile getGNADataEntryConfigProfile(HttpServletRequest httpServletRequest) { + HttpSession session = httpServletRequest.getSession(); + return (GNADataEntryConfigProfile) session.getAttribute(GNA_DATAENTRY_CONFIG_PROFILE); + } + + /** + * Sets the GNA data entry config profile. + * + * @param httpServletRequest the http servlet request + * @param gNADEConfigProfile the g NADE config profile + */ + public static void setGNADataEntryConfigProfile(HttpServletRequest httpServletRequest, + GNADataEntryConfigProfile gNADEConfigProfile) { + HttpSession session = httpServletRequest.getSession(); + session.setAttribute(GNA_DATAENTRY_CONFIG_PROFILE, gNADEConfigProfile); + } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNADataEntryExtConfigProfile.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNADataEntryExtConfigProfile.java new file mode 100644 index 0000000..944d3b7 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GNADataEntryExtConfigProfile.java @@ -0,0 +1,46 @@ +package org.gcube.portlets.user.geoportaldataentry.shared; + +import java.io.Serializable; + +import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; + +/** + * The Class GNADataEntryExtConfigProfile. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 21, 2021 + */ +public class GNADataEntryExtConfigProfile extends GNADataEntryConfigProfile implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3185317083819447952L; + private UserRights userRights = null; + + /** + * Instantiates a new GNA data entry config profile. + */ + public GNADataEntryExtConfigProfile() { + + } + + public UserRights getUserRights() { + return userRights; + } + + public void setUserRights(UserRights userRights) { + this.userRights = userRights; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GNADataEntryExtConfigProfile [userRights="); + builder.append(userRights); + builder.append("]"); + return builder.toString(); + } + +} From 2bcebc758d4c38d2655eb26c52765b5c89fba847 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 22 Dec 2021 12:20:08 +0100 Subject: [PATCH 16/16] refactoring --- .../client/GeoPortalDataEntryApp.java | 4 +- .../server/GeoportalDataEntryServiceImpl.java | 4 +- .../shared/GeonaISConfig.java | 68 ++++++++++++++----- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index 1cc19fd..6afcf8c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -252,9 +252,9 @@ public class GeoPortalDataEntryApp implements EntryPoint { @Override public void onSuccess(GeonaISConfig result) { - if (result != null && result.getgRSecondaryType() != null + if (result != null && result.getGenericResourceSecondaryType() != null && result.getScope() != null) { - callGetMetadataProfiles(result.getScope(), result.getgRSecondaryType()); + callGetMetadataProfiles(result.getScope(), result.getGenericResourceSecondaryType()); } else Window.alert( "Sorry, no configuration found in the context. Please, contact the support"); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index b48dca5..d6187d5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java @@ -17,7 +17,6 @@ import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportalcommon.ConvertToDataViewModel; import org.gcube.application.geoportalcommon.GeoportalCommon; -//import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.MongoServiceCommon; import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; @@ -396,8 +395,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen try { theSecondaryType = this.getServletContext().getInitParameter(GEONA_GENERIC_RESOURCE_SECONDARY_TYPE); } catch (Exception e) { - LOG.error("I cannot read the init parameter for: " + GEONA_GENERIC_RESOURCE_SECONDARY_TYPE, e); + LOG.warn("I cannot read the init parameter for: " + GEONA_GENERIC_RESOURCE_SECONDARY_TYPE, e); theSecondaryType = "GeoNaMetadata"; + LOG.warn("Using default SecondaryType: " + theSecondaryType); } // LOG.warn("\n\n\nHARD-CABLING THE SCOPE, PLEASE REMOTE IT!!!!\n\n\n"); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GeonaISConfig.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GeonaISConfig.java index 4e35d33..1ec007e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GeonaISConfig.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/shared/GeonaISConfig.java @@ -2,39 +2,73 @@ package org.gcube.portlets.user.geoportaldataentry.shared; import java.io.Serializable; -public class GeonaISConfig implements Serializable{ - - +/** + * The Class GeonaISConfig. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Dec 22, 2021 + */ +public class GeonaISConfig implements Serializable { + + /** * */ - private static final long serialVersionUID = -6700506811708315617L; - - String gRSecondaryType; - String scope; - + private static final long serialVersionUID = 4187839053354198268L; + private String genericResSecondaryType; + private String scope; + + /** + * Instantiates a new geona IS config. + */ public GeonaISConfig() { } + /** + * Instantiates a new geona IS config. + * + * @param gRSecondaryType the g R secondary type + * @param scope the scope + */ public GeonaISConfig(String gRSecondaryType, String scope) { super(); - this.gRSecondaryType = gRSecondaryType; + this.genericResSecondaryType = gRSecondaryType; this.scope = scope; } - - public String getgRSecondaryType() { - return gRSecondaryType; + /** + * Gets the generic resource secondary type. + * + * @return the generic resource secondary type + */ + public String getGenericResourceSecondaryType() { + return genericResSecondaryType; } - public void setgRSecondaryType(String gRSecondaryType) { - this.gRSecondaryType = gRSecondaryType; + /** + * Sets the generic resource secondary type. + * + * @param gRSecondaryType the new generic resource secondary type + */ + public void setGenericResourceSecondaryType(String gRSecondaryType) { + this.genericResSecondaryType = gRSecondaryType; } + /** + * Gets the scope. + * + * @return the scope + */ public String getScope() { return scope; } + /** + * Sets the scope. + * + * @param scope the new scope + */ public void setScope(String scope) { this.scope = scope; } @@ -42,14 +76,12 @@ public class GeonaISConfig implements Serializable{ @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("GeonaISConfig [gRSecondaryType="); - builder.append(gRSecondaryType); + builder.append("GeonaISConfig [genericResSecondaryType="); + builder.append(genericResSecondaryType); builder.append(", scope="); builder.append(scope); builder.append("]"); return builder.toString(); } - - }