From eb6a8ff58711ce3ae282ce04308a75c4c0ad1b8d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 24 May 2022 18:33:33 +0200 Subject: [PATCH] #23390 Implementing facility: "Clone Project" --- .classpath | 4 +- .../com.gwtplugins.gdt.eclipse.core.prefs | 2 +- .settings/org.eclipse.wst.common.component | 28 +- CHANGELOG.md | 6 + pom.xml | 28 +- .../client/GeoPortalDataEntryApp.java | 367 ++++++++++-------- .../client/ui/GeonaMainTabPanel.java | 23 +- .../client/ui/GeonaMainTabPanel.ui.xml | 2 + 8 files changed, 274 insertions(+), 186 deletions(-) diff --git a/.classpath b/.classpath index d8296e1..15db912 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + @@ -30,5 +30,5 @@ - + diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs index 876328d..0a87b1c 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.1.0-SNAPSHOT +lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-2.2.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 98ea8c3..c37aa99 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,5 @@ - + @@ -22,8 +22,10 @@ - - + + + + @@ -47,7 +49,8 @@ - + + @@ -71,7 +74,8 @@ - + + @@ -95,10 +99,11 @@ - + uses - + + @@ -122,7 +127,8 @@ - + + @@ -146,7 +152,8 @@ - + + @@ -170,7 +177,8 @@ - + + diff --git a/CHANGELOG.md b/CHANGELOG.md index a69f535..77bb3e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ 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.2.0-SNAPSHOT] - 2022-05-25 + +#### Enhancements + +- [#23390] Implemented facility: "Clone Project" + ## [v2.1.0] - 2021-11-24 #### Enhancements diff --git a/pom.xml b/pom.xml index d855017..f4dd68c 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.gcube.portlets.user geoportal-data-entry-app war - 2.1.0 + 2.2.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 @@ -25,7 +25,7 @@ - 2.9.0 + 2.8.2 ${project.build.directory}/${project.build.finalName} UTF-8 @@ -98,6 +98,9 @@ gwt-bootstrap compile + + + org.gcube.portlets.widgets metadata-profile-form-builder-widget @@ -136,16 +139,31 @@ [1.0.0, 2.0.0-SNAPSHOT) compile + + + + + org.gcube.application + geoportal-common + [1.0.0,1.0.8-SNAPSHOT) + + + + org.gcube.common + metadata-profile-discovery + [1.0.0-SNAPSHOT, 1.1.0-SNAPSHOT) + + org.gcube.application geoportal-data-common - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + [1.0.0-SNAPSHOT, 1.5.0-SNAPSHOT) compile org.gcube.application geoportal-client - [1.0.0, 2.0.0-SNAPSHOT) + [1.0.0, 1.0.7-SNAPSHOT) compile @@ -154,6 +172,8 @@ + + org.gcube.portlets.user gcube-widgets 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 6afcf8c..7db1a3f 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 @@ -108,7 +108,7 @@ 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(); @@ -120,152 +120,148 @@ 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) { + * Window.alert(caught.getMessage()); + * + * } + * + * @Override public void onSuccess(List result) { + * + * for (ItemField itemField : result) { if(itemField.isDisplayAsResult()) { + * 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); + * + * } }); + */ - @Override - public void onFailure(Throwable caught) { - Window.alert(caught.getMessage()); - - } - - @Override - public void onSuccess(List result) { - - for (ItemField itemField : result) { - if(itemField.isDisplayAsResult()) { - 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().readDataViewerConfig(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(GNADataEntryExtConfigProfile gNADataEntryConfig) { - - try { - RootPanel.get(DIV_PORTLET_ID).remove(loader); - } catch (Exception e) { - - } - - 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 "; - 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() { + GeoportalDataEntryServiceAsync.Util.getInstance() + .readDataViewerConfig(new AsyncCallback() { @Override public void onFailure(Throwable caught) { - Window.alert( - "Sorry, an error occurrend when loading configurations. 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(GNADataEntryExtConfigProfile gNADataEntryConfig) { - if (result != null && result.getGenericResourceSecondaryType() != null - && result.getScope() != null) { - callGetMetadataProfiles(result.getScope(), result.getGenericResourceSecondaryType()); + try { + RootPanel.get(DIV_PORTLET_ID).remove(loader); + } catch (Exception e) { + + } + + 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 "; + if (userRole != null && userRole.getName() != null) { + msg += userRole.getName().substring(userRole.getName().indexOf("-") + 1, + userRole.getName().length()); } else - Window.alert( - "Sorry, no configuration found in the context. Please, contact the support"); + 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.getGenericResourceSecondaryType() != null + && result.getScope() != null) { + callGetMetadataProfiles(result.getScope(), + result.getGenericResourceSecondaryType()); + } else + Window.alert( + "Sorry, no configuration found in the context. Please, contact the support"); + + } + }); } }); - - } - }); - - // GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback() { // @@ -657,7 +653,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { mainTabPanel.showListOfConcessioniView(grpw); } }); - + appManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() { @Override @@ -731,40 +727,44 @@ public class GeoPortalDataEntryApp implements EntryPoint { final ConcessioneDV concessione = (ConcessioneDV) item; 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; + 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); + + 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) + // 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); + 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()){ + 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"; + 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); + ModalWindow modalW = new ModalWindow(new Image(Images.ICONS.accessDenied()), title, msg, + AlertType.WARNING); modalW.show(); return; } - switch (action) { - case VIEW_ON_MAP: + case VIEW_ON_MAP: { final Modal modal = new Modal(true, true); modal.setCloseVisible(true); final HorizontalPanel hpGetLink = new HorizontalPanel(); @@ -798,8 +798,9 @@ public class GeoPortalDataEntryApp implements EntryPoint { modal.show(); break; + } - case VIEW_REPORT: + case VIEW_REPORT: { final Modal modal2 = new Modal(true, true); modal2.setTitle( @@ -817,8 +818,9 @@ public class GeoPortalDataEntryApp implements EntryPoint { modal2.show(); break; + } - case EDIT_PROJECT: + case EDIT_PROJECT: { final Modal modal3 = new Modal(true, true); modal3.setTitle( "Edit: " @@ -833,12 +835,43 @@ public class GeoPortalDataEntryApp implements EntryPoint { modal3.add(emr); modal3.show(); break; + } // case UPDATED_PROJECT: // appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, // mainTabPanel.getCurrentSortFilter())); // break; - case DELETE_PROJECT: + + case CLONE_PROJECT: { + + String htmlMsg = "Going to create a copy of the project with:"; + htmlMsg += "
    "; + htmlMsg += "
  • id: " + concessione.getItemId() + "
  • "; + htmlMsg += "
  • name: " + concessione.getNome() + "
  • "; + htmlMsg += "
"; + htmlMsg += "
"; + htmlMsg += "Would you like to proceed?"; + + final DialogConfirm dialog = new DialogConfirm(null, "Cloning Confirm?", htmlMsg); + dialog.center(); + + dialog.getYesButton().addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + dialog.hide(); + final Modal modal = new Modal(true, true); + modal.setCloseVisible(true); + final HorizontalPanel hp = new HorizontalPanel(); + final LoaderIcon lc = new LoaderIcon("Creating a copy of the project..."); + hp.add(lc); + modal.add(hp); + + } + }); + break; + } + case DELETE_PROJECT: { String htmlMsg = "Going to delete the project with:"; htmlMsg += "
    "; @@ -895,6 +928,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { modal.show(); } }); + } default: break; @@ -907,8 +941,9 @@ public class GeoPortalDataEntryApp implements EntryPoint { }); } - - private boolean checkAccessToOperationType(GcubeUserRole userRole, OPERATION_TYPE allowedAction, ConcessioneDV concessione) { + + private boolean checkAccessToOperationType(GcubeUserRole userRole, OPERATION_TYPE allowedAction, + ConcessioneDV concessione) { boolean writeAnyAPassed = false; boolean writeOwnPassed = false; @@ -924,37 +959,37 @@ public class GeoPortalDataEntryApp implements EntryPoint { String ownerUser = concessione.getCreationUser(); if (ownerUser == null || ownerUser.isEmpty()) { writeOwnPassed = false; - }else if (ownerUser.compareTo(myRights.getMyUsername()) == 0) { + } 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 + // Access to READ operation is allowed to everyone operationAllowed = true; - GWT.log(OPERATION_TYPE.READ+ " ALLOWED? "+operationAllowed); + GWT.log(OPERATION_TYPE.READ + " ALLOWED? " + operationAllowed); break; case READ_WRITE: - //Access to READ_WRITE operation + // Access to READ_WRITE operation operationAllowed = writeAnyAPassed || writeOwnPassed; - GWT.log(OPERATION_TYPE.READ_WRITE+ " ALLOWED? "+operationAllowed); + GWT.log(OPERATION_TYPE.READ_WRITE + " ALLOWED? " + operationAllowed); break; case WRITE: - //Access to WRITE operation + // Access to WRITE operation operationAllowed = writeAnyAPassed || writeOwnPassed; - GWT.log(OPERATION_TYPE.WRITE+ " ALLOWED? "+operationAllowed); + GWT.log(OPERATION_TYPE.WRITE + " ALLOWED? " + operationAllowed); break; case UNKNOWN: operationAllowed = false; - GWT.log(OPERATION_TYPE.UNKNOWN+ " ALLOWED? "+operationAllowed); + GWT.log(OPERATION_TYPE.UNKNOWN + " ALLOWED? " + operationAllowed); break; default: break; } - + return operationAllowed; } 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 7b3b4fc..524d8d9 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 @@ -125,6 +125,9 @@ public class GeonaMainTabPanel extends Composite { @UiField NavLink navEditMode; + @UiField + NavLink navCloneProject; + @UiField NavLink navDelete; @@ -133,7 +136,7 @@ public class GeonaMainTabPanel extends Composite { @UiField Button resetSearch; - + @UiField Label roleLabel; @@ -173,7 +176,7 @@ public class GeonaMainTabPanel extends Composite { alertSearchFor.setText(searchForFields.get(0).getDisplayName()); alertSortBy.setText(toLabelFilter((initialSortFilter.getOrderByFields().get(0)), initialSortFilter.getOrder())); - + bindEvents(); resetSearch.setIconSize(IconSize.TWO_TIMES); resetSearch.setType(ButtonType.LINK); @@ -310,6 +313,20 @@ public class GeonaMainTabPanel extends Composite { } }); + navCloneProject.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + List listConcessioni = null; + if (grpw != null && grpw.getSelectItems() != null) { + listConcessioni = grpw.getSelectItems(); + } + appManagerBus + .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.CLONE_PROJECT)); + } + }); + navDelete.addClickHandler(new ClickHandler() { @Override @@ -347,7 +364,7 @@ public class GeonaMainTabPanel extends Composite { }); } - + public void setRoleLabel(String msg) { roleLabel.setText(msg); } 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 7f5e5ec..b7f75e8 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 @@ -90,6 +90,8 @@ title="Show Publication Report" icon="FILE_TEXT_ALT">Publication Report Edit + Clone Project Delete Project