From 2c2109836c1e088234e5923d225bd448609d9be2 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 26 May 2022 17:43:48 +0200 Subject: [PATCH] created the CloneOperationPanel.. --- .settings/org.eclipse.wst.common.component | 35 ++-- pom.xml | 8 +- .../client/GeoPortalDataEntryApp.java | 176 +++++------------- .../client/GeoportalDataEntryService.java | 10 + .../GeoportalDataEntryServiceAsync.java | 2 + .../client/events/CloneProjectEvent.java | 54 ++++++ .../events/CloneProjectEventHandler.java | 20 ++ .../client/events/CreateNewProjectEvent.java | 21 ++- .../client/ui/CloneOperationPanel.java | 79 ++++++++ .../client/ui/CloneOperationPanel.ui.xml | 79 ++++++++ .../client/ui/GeonaMainTabPanel.ui.xml | 2 +- .../server/GeoportalDataEntryServiceImpl.java | 51 ++++- 12 files changed, 381 insertions(+), 156 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CloneProjectEvent.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CloneProjectEventHandler.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/CloneOperationPanel.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/CloneOperationPanel.ui.xml diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index c37aa99..2a1378f 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,7 @@ - + + + @@ -24,7 +26,9 @@ - + + + @@ -49,7 +53,9 @@ - + + + @@ -74,7 +80,9 @@ - + + + @@ -99,10 +107,9 @@ - - uses - - + + + @@ -127,7 +134,9 @@ - + + + @@ -152,7 +161,9 @@ - + + + @@ -177,7 +188,9 @@ - + + + diff --git a/pom.xml b/pom.xml index f4dd68c..34a86c1 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ - 2.8.2 + 2.9.0 ${project.build.directory}/${project.build.finalName} UTF-8 @@ -163,13 +163,17 @@ org.gcube.application geoportal-client - [1.0.0, 1.0.7-SNAPSHOT) + [1.0.0, 1.0.8-SNAPSHOT) compile javax.servlet servlet-api + + org.ow2.asm + asm + 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 7db1a3f..4024dd0 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 @@ -24,6 +24,8 @@ import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEven 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.CloneProjectEvent; +import org.gcube.portlets.user.geoportaldataentry.client.events.CloneProjectEventHandler; 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; @@ -31,6 +33,7 @@ import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecords 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.CloneOperationPanel; 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; @@ -120,40 +123,6 @@ public class GeoPortalDataEntryApp implements EntryPoint { RootPanel.get(DIV_PORTLET_ID).add(loader); - /* - * 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); - * - * } }); - */ - GeoportalDataEntryServiceAsync.Util.getInstance() .readDataViewerConfig(new AsyncCallback() { @@ -262,79 +231,6 @@ public class GeoPortalDataEntryApp implements EntryPoint { } }); - -// GeoportalDataEntryServiceAsync.Util.getInstance().getMyRightsInTheContext(new AsyncCallback() { -// -// @Override -// public void onFailure(Throwable caught) { -// String errorMsg = "Sorry, an error occurrend on istancing the application. Please, contact the support"; -// Alert alert = new Alert(errorMsg, AlertType.ERROR); -// alert.setClose(false); -// try { -// RootPanel.get(DIV_PORTLET_ID).remove(loader); -// } catch (Exception e) { -// -// } -// RootPanel.get(DIV_PORTLET_ID).add(alert); -// Window.alert(errorMsg); -// -// } -// -// @Override -// public void onSuccess(UserRights result) { -// try { -// RootPanel.get(DIV_PORTLET_ID).remove(loader); -// } catch (Exception e) { -// -// } -// -// myRights = result; -// initGUI(); -// GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); -// String msg = "Logged in as "; -// if(userRole != null && userRole.getName()!=null) { -// msg+= userRole.getName().substring(userRole.getName().indexOf("-")+1, userRole.getName().length()); -// }else -// msg+="Member"; -// -// mainTabPanel.setRoleLabel(msg); -// -// -// RoleRights roleRights = myRights.getRoleRights(); -// boolean canCreateNewItem = roleRights.getListPermessions().keySet().contains(ACTION_ON_ITEM.CREATE_NEW_PROJECT); -// -// if (!canCreateNewItem) { -// // removing Tab "Create New Project" -// mainTabPanel.removeTab(0); -// // activating Tab "List of Project" -// mainTabPanel.setTabActive(0); -// mainTabPanel.instanceAndShowListOfConcessioni(); -// return; -// } -// -// GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback() { -// -// @Override -// public void onFailure(Throwable caught) { -// Window.alert( -// "Sorry, an error occurrend when loading configurations. Please, contact the support"); -// } -// -// @Override -// public void onSuccess(GeonaISConfig result) { -// -// if (result != null && result.getgRSecondaryType() != null -// && result.getScope() != null) { -// callGetMetadataProfiles(result.getScope(), result.getgRSecondaryType()); -// } else -// Window.alert( -// "Sorry, no configuration found in the context. Please, contact the support"); -// -// } -// }); -// -// } -// }); } private void initGUI() { @@ -654,6 +550,38 @@ public class GeoPortalDataEntryApp implements EntryPoint { } }); + appManagerBus.addHandler(CloneProjectEvent.TYPE, new CloneProjectEventHandler() { + + @Override + public void onCreateNewProject(CloneProjectEvent cloneProject) { + + if (cloneProject.getConcessione() != null) { + + GeoportalDataEntryServiceAsync.Util.getInstance().cloneTheRecord( + cloneProject.getConcessione().getItemId(), cloneProject.getNewProjectName(), + new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + Alert alert = new Alert(caught.getMessage()); + alert.setType(AlertType.ERROR); + alert.setClose(false); + Modal modal = new Modal(true); + modal.add(alert); + + } + + @Override + public void onSuccess(CommitReport result) { + // TODO Auto-generated method stub + + } + }); + } + + } + }); + appManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() { @Override @@ -844,32 +772,20 @@ public class GeoPortalDataEntryApp implements EntryPoint { 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 Modal modal3 = new Modal(true, true); + modal3.setTitle("Creating a copy of the project..."); + modal3.setWidth(950); + modal3.setHeight("700px"); + modal3.setCloseVisible(true); + ((Element) modal3.getElement().getChildNodes().getItem(1)) + .addClassName("modal-body-custom"); - final DialogConfirm dialog = new DialogConfirm(null, "Cloning Confirm?", htmlMsg); - dialog.center(); + CloneOperationPanel clonePanel = new CloneOperationPanel(appManagerBus, concessione); - 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); - - } - }); + modal3.add(clonePanel); + modal3.show(); break; + } case DELETE_PROJECT: { 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 d2d8bb0..16154ae 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 @@ -139,4 +139,14 @@ public interface GeoportalDataEntryService extends RemoteService { */ GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception; + /** + * Clone the record. + * + * @param itemId the item id + * @param newProjectName the new project name + * @return the commit report + * @throws Exception the exception + */ + CommitReport cloneTheRecord(String itemId, String newProjectName) 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 c3593de..e16267e 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 @@ -63,4 +63,6 @@ public interface GeoportalDataEntryServiceAsync { void readDataViewerConfig(AsyncCallback asyncCallback); + void cloneTheRecord(String itemId, String newProjectName, AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CloneProjectEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CloneProjectEvent.java new file mode 100644 index 0000000..5dd4955 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CloneProjectEvent.java @@ -0,0 +1,54 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; + +import com.google.gwt.event.shared.GwtEvent; + +/** + * The Class CloneProjectEvent. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * May 26, 2022 + */ +public class CloneProjectEvent extends GwtEvent { + + /** The type. */ + public static Type TYPE = new Type(); + private ConcessioneDV concessione; + private String newProjectName; + + public CloneProjectEvent(ConcessioneDV concessione, String newProjectName) { + this.concessione = concessione; + this.newProjectName = newProjectName; + } + + /** + * Gets the associated type. + * + * @return the associated type + */ + /* + * (non-Javadoc) + * + * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType() + */ + @Override + public Type getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(CloneProjectEventHandler handler) { + handler.onCreateNewProject(this); + } + + public ConcessioneDV getConcessione() { + return concessione; + } + + public String getNewProjectName() { + return newProjectName; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CloneProjectEventHandler.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CloneProjectEventHandler.java new file mode 100644 index 0000000..1bce0da --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CloneProjectEventHandler.java @@ -0,0 +1,20 @@ +package org.gcube.portlets.user.geoportaldataentry.client.events; + +import com.google.gwt.event.shared.EventHandler; + +/** + * The Interface CreateNewProjectEventHandler. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * + * Oct 13, 2020 + */ +public interface CloneProjectEventHandler extends EventHandler { + + /** + * On create new project. + * + * @param cloneProject the clone project + */ + void onCreateNewProject(CloneProjectEvent cloneProject); +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CreateNewProjectEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CreateNewProjectEvent.java index bbcce94..f809984 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CreateNewProjectEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/CreateNewProjectEvent.java @@ -2,23 +2,18 @@ package org.gcube.portlets.user.geoportaldataentry.client.events; import com.google.gwt.event.shared.GwtEvent; - -// TODO: Auto-generated Javadoc /** * The Class CreateNewProjectEvent. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * - * Oct 13, 2020 + * Oct 13, 2020 */ public class CreateNewProjectEvent extends GwtEvent { - + /** The type. */ public static Type TYPE = new Type(); - /** - * Instantiates a new cancel upload event. - */ public CreateNewProjectEvent() { } @@ -27,7 +22,9 @@ public class CreateNewProjectEvent extends GwtEvent { + } + + private HandlerManager appManagerBus; + + public CloneOperationPanel(HandlerManager appManagerBus, ConcessioneDV concessione) { + initWidget(uiBinder.createAndBindUi(this)); + this.appManagerBus = appManagerBus; + } + + @UiField + TextBox projectNameTextBox; + + @UiField + AlertBlock infoBlock; + + @UiField + AlertBlock infoProjectName; + + @UiField + Button publishNewProjectButton; + + private ConcessioneDV selectedProject; + + public CloneOperationPanel(ConcessioneDV concessione) { + initWidget(uiBinder.createAndBindUi(this)); + + this.selectedProject = concessione; + infoProjectName.setText(selectedProject.getNome()); + projectNameTextBox.setText(selectedProject.getNome()); + projectNameTextBox.setEnabled(false); + + publishNewProjectButton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + boolean isValid = checkIsValidForm(); + + if (isValid) { + appManagerBus.fireEvent(event); + } + } + }); + } + + protected boolean checkIsValidForm() { + String text = projectNameTextBox.getText(); + if (text == null || text.isEmpty()) { + infoBlock.setVisible(true); + infoBlock.setText("The Project's name cannot be empty!"); + infoBlock.setType(AlertType.ERROR); + return false; + } + + return true; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/CloneOperationPanel.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/CloneOperationPanel.ui.xml new file mode 100644 index 0000000..44e30dc --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/CloneOperationPanel.ui.xml @@ -0,0 +1,79 @@ + + + + .form-main-style { + margin-left: 10px; + } + + .fieldset-border-style { + border: 1px groove #444; + -webkit-box-shadow: 0px 0px 0px 0px #000; + box-shadow: 0px 0px 0px 0px #000; + padding: 10px; + } + + .legend-style { + width: auto; + padding: 10px; + margin-bottom: 0px; + } + + @external .form-horizontal .input-large; + .form-horizontal .input-large { + width: 95%; + } + + .block-alert-style { + margin-top: 10px; + padding: 10px; + margin-bottom: 10px; + } + + .button-save-style { + margin-top: 10px; + float: right; + } + + + + + + + + Clone Project + + * + is required + + + + + + * + Name : + + + + + + + + + + + + + Publish as New Project + + + \ No newline at end of file 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 b7f75e8..71654ef 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 @@ -91,7 +91,7 @@ Edit Clone Project + icon="COPY">Clone Project Delete Project 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 d6187d5..53a8fec 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 @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.gcube.application.geoportal.client.utils.ConcessioniUtils; import org.gcube.application.geoportal.common.model.legacy.AbstractRelazione; import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths; @@ -66,6 +67,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen public static final String GEONA_GENERIC_RESOURCE_SECONDARY_TYPE = "GEONA_GENERIC_RESOURCE_SECONDARY_TYPE"; private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataEntryServiceImpl.class); + // private String mongoId; /** * Gets the GNA data entry config profile. @@ -78,7 +80,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen GNADataEntryConfigProfile profile = SessionUtil.getGNADataEntryConfigProfile(getThreadLocalRequest()); if (profile == null) { LOG.info(GNADataEntryConfigProfile.class.getSimpleName() + " is null, loading configurations from IS"); - //to be sure + // to be sure SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); GeoportalCommon gCommon = new GeoportalCommon(); profile = gCommon.readGNADataEntryConfig(); @@ -381,6 +383,45 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen } + /** + * Clone the record. + * + * @param itemId the item id + * @param newProjectName the new project name + * @return the commit report + * @throws Exception the exception + */ + @Override + public CommitReport cloneTheRecord(String itemId, String newProjectName) throws Exception { + + try { + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + MongoServiceUtil serviceUtil = new MongoServiceUtil(); + MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); + // TO be sure + Concessione concessione = clientMongo.getById(itemId); + Concessione concessioneNew = ConcessioniUtils.clone(clientMongo, concessione.getMongo_id()); + // Publishing cloned Concessione + concessioneNew = clientMongo.publish(concessioneNew.getMongo_id()); + // server report + ValidationReport report = concessioneNew.getReport(); + LOG.info("ValidationReport: " + report); + + // to client + CommitReport cRep = new CommitReport(); + // cRep.setRecordId(concessione.getId()); + cRep.setMongoId(concessioneNew.getMongo_id()); + ValidationReportDV vr = ConvertToDataViewModel.toValidationReport(report); + cRep.setValidationReportDV(vr); + + return cRep; + + } catch (Exception e) { + LOG.warn("Error occurred during cloning the project with id: " + itemId, e); + throw new Exception("Sorry an error occurred during cloning the Project. Refresh and try again"); + } + } + /** * Gets the geona init config. * @@ -748,7 +789,13 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen "Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage()); } } - + + /** + * Read data viewer config. + * + * @return the GNA data entry ext config profile + * @throws Exception the exception + */ @Override public GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception { LOG.info("readDataViewerConfig called");