From 93c3d1d07da4fbf39cf09e1cdb4f2418ae36655d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 26 Nov 2021 16:05:05 +0100 Subject: [PATCH] #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); + } + }