From 240ac0a74b8f609e9c17f22ba1f64f0e513d57d1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 7 Dec 2022 09:43:48 +0100 Subject: [PATCH] Integrated with the geoportal-data-mapper library --- .settings/org.eclipse.wst.common.component | 48 ++++++-- CHANGELOG.md | 1 + pom.xml | 24 ++-- .../GeoPortalDataEntryApp.gwt.xml | 8 +- .../client/GeoPortalDataEntryApp.java | 10 +- .../client/GeoportalDataEntryService.java | 22 +++- .../GeoportalDataEntryServiceAsync.java | 3 + .../client/ui/edit/UpdateRecord.java | 112 ++++++++++++++++++ .../client/ui/edit/UpdateRecord.ui.xml | 50 ++++++++ .../server/GeoportalDataEntryServiceImpl.java | 64 +++++++--- .../GeoPortalDataEntryApp.gwt.xml | 31 +++-- 11 files changed, 307 insertions(+), 66 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.java create mode 100644 src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.ui.xml diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 36c275a..dfc3851 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,8 @@ - + + + + @@ -72,7 +75,10 @@ - + + + + @@ -145,7 +151,10 @@ - + + + + @@ -218,7 +227,10 @@ - + + + + @@ -291,7 +303,10 @@ - + + + + @@ -316,10 +331,10 @@ - - uses - - + + + + @@ -392,7 +407,10 @@ - + + + + @@ -465,7 +483,10 @@ - + + + + @@ -538,7 +559,10 @@ - + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 621d00f..ecfb043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v3.1.0-SNAPSHOT] - 2022-11-30 - [#24166] Implemented the Update facility +- [#24244] Integrated with the geoportal-data-mapper library ## [v3.0.0] - 2022-11-09 diff --git a/pom.xml b/pom.xml index b90cf1a..4c3fd1d 100644 --- a/pom.xml +++ b/pom.xml @@ -68,22 +68,6 @@ provided - - - - - - - - - - - - - - - - com.google.gwt gwt-servlet @@ -107,6 +91,14 @@ gwt-bootstrap compile + + + org.gcube.application + geoportal-data-mapper + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + compile + + org.gcube.portlets.widgets metadata-profile-form-builder-widget diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/GeoPortalDataEntryApp.gwt.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/GeoPortalDataEntryApp.gwt.xml index 8e50a33..bcdccbb 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/GeoPortalDataEntryApp.gwt.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/GeoPortalDataEntryApp.gwt.xml @@ -13,9 +13,13 @@ + name='org.gcube.application.geoportalcommon.GeoportalDataCommon' /> - + + + 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 d452a39..b8dff5c 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 @@ -50,7 +50,7 @@ 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.edit.UpdateRecord; import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm; import org.gcube.portlets.user.geoportaldataentry.client.ui.report.LifecycleInformationPanel; import org.gcube.portlets.user.geoportaldataentry.client.ui.report.ReportTemplateToHTML; @@ -1481,8 +1481,12 @@ public class GeoPortalDataEntryApp implements EntryPoint { modal3.setCloseVisible(true); ((Element) modal3.getElement().getChildNodes().getItem(1)) .addClassName("modal-body-custom"); - EditModeRecord emr = new EditModeRecord(appManagerBus, resultDocumentDV); - modal3.add(emr); + //EditModeRecord emr = new EditModeRecord(appManagerBus, resultDocumentDV); + + + UpdateRecord ur = new UpdateRecord(appManagerBus, resultDocumentDV.getProfileID(), resultDocumentDV.getId()); + + modal3.add(ur); modal3.show(); break; } 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 85514af..09a2493 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.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.TemporalReferenceDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.RelationshipDefinitionDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; +import org.gcube.application.geoportaldatamapper.shared.ProjectEdit; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtendedConfigProfile; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; @@ -31,6 +32,15 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @RemoteServiceRelativePath("geoportaldataentryservice") public interface GeoportalDataEntryService extends RemoteService { + /** + * Save geona data forms. + * + * @param profileID the profile ID + * @param tree_Node the tree node + * @param stepsOnPostCreation the steps on post creation + * @return the commit report + * @throws Exception the exception + */ CommitReport saveGeonaDataForms(String profileID, Tree_Node tree_Node, List stepsOnPostCreation) throws Exception; @@ -184,7 +194,7 @@ public interface GeoportalDataEntryService extends RemoteService { * @param id the id * @param toProfileID the to profile ID * @param toProjectID the to project ID - * @return + * @return the result document DV * @throws Exception the exception */ ResultDocumentDV deleteRelationship(String fromProfileID, String fromProjectID, String id, String toProfileID, @@ -199,4 +209,14 @@ public interface GeoportalDataEntryService extends RemoteService { */ TemporalReferenceDV temporalReferenceForProject(String profileID, String projectID); + /** + * Gets the project edit. + * + * @param profileID the profile ID + * @param projectID the project ID + * @return the project edit + * @throws Exception the exception + */ + ProjectEdit getProjectEdit(String profileID, String projectID) 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 c34c038..e118e3a 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.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.TemporalReferenceDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.RelationshipDefinitionDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; +import org.gcube.application.geoportaldatamapper.shared.ProjectEdit; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtendedConfigProfile; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; @@ -88,4 +89,6 @@ public interface GeoportalDataEntryServiceAsync { void temporalReferenceForProject(String profileID, String projectID, AsyncCallback callback); + void getProjectEdit(String profileID, String projectID, AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.java new file mode 100644 index 0000000..b1ba221 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.java @@ -0,0 +1,112 @@ +package org.gcube.portlets.user.geoportaldataentry.client.ui.edit; + +import java.util.List; + +import org.gcube.application.geoportaldatamapper.shared.MetaDataProfileBeanExt; +import org.gcube.application.geoportaldatamapper.shared.ProjectEdit; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp; +import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryServiceAsync; +import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; +import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.ControlGroup; +import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + +public class UpdateRecord extends Composite { + + private static UpdateRecordUiBinder uiBinder = GWT.create(UpdateRecordUiBinder.class); + + interface UpdateRecordUiBinder extends UiBinder { + } + + @UiField + ListBox listBoxSections; + + @UiField + HTMLPanel htmlSectionContent; + + @UiField + HTMLPanel alertHTMLPanel; + + @UiField + ControlGroup controlsControlGroup; + + private LoaderIcon loaderProjectSections = new LoaderIcon("Loading Project sections..., please wait"); + + public UpdateRecord(HandlerManager editorManagerBus, String profileID, String projectID) { + initWidget(uiBinder.createAndBindUi(this)); + + alertHTMLPanel.add(loaderProjectSections); + + GeoportalDataEntryServiceAsync.Util.getInstance().getProjectEdit(profileID, projectID, + new AsyncCallback() { + + @Override + public void onSuccess(ProjectEdit result) { + + try { + alertHTMLPanel.remove(loaderProjectSections); + } catch (Exception e) { + + } + + for (final MetaDataProfileBeanExt profileBean : result.getTheProfileBeans()) { + + listBoxSections.addItem(profileBean.getType(), profileBean.getType()); + + listBoxSections.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + controlsControlGroup.setVisible(true); + htmlSectionContent.clear(); + List listMeta = profileBean.getMetadataFields(); + if (listMeta != null && listMeta.size() > 0) { + MetadataFieldWrapper firstMeta = listMeta.get(0); + FlowPanel fp = new FlowPanel(); + fp.add(new HTML(firstMeta.getFieldName())); + fp.add(new HTML(firstMeta.getCurrentValue())); + htmlSectionContent.add(fp); + } + + } + }); + } + + } + + @Override + public void onFailure(Throwable caught) { + alertHTMLPanel.remove(loaderProjectSections); + + String errorMsg = caught.getMessage(); + Alert alert = new Alert(errorMsg, AlertType.ERROR); + alert.setClose(false); + try { + alertHTMLPanel.remove(loaderProjectSections); + } catch (Exception e) { + + } + alertHTMLPanel.add(alert); + Window.alert(errorMsg); + + } + }); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.ui.xml new file mode 100644 index 0000000..42d0d65 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateRecord.ui.xml @@ -0,0 +1,50 @@ + + + .important { + font-weight: bold; + } + + .button-save-style { + margin-top: 10px; + float: right; + } + + .max-height-500 { + max-height: 450px; + } + + + + + + + + + Select the section of the document you want to update... + + + + + + Manage the content of + + + + + + + + + + + + + UPDATE + + \ No newline at end of file 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 002a044..6f5a80d 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 @@ -53,6 +53,8 @@ import org.gcube.application.geoportalcommon.shared.geoportal.project.TemporalRe import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.RelationshipDefinitionDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; +import org.gcube.application.geoportaldatamapper.Geoportal_JSON_Mapper; +import org.gcube.application.geoportaldatamapper.shared.ProjectEdit; import org.gcube.common.portal.PortalContext; import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; @@ -521,26 +523,26 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen searchedData.setTotalItems(totalProjectForProfile); LOG.info("Total Docs read from config: " + totalProjectForProfile); - + // Saving client PROJECTION LinkedHashMap originalProjection = filter.getProjection(); int totalItems = totalProjectForProfile; - //PERFORMING FIRST QUERY FOR IDS IF AND ONLY IF WHERE CONDITIONS IN THE QUERY. - //SEARCHING FACILITY IS ENACTING. - if(filter.getConditions()!=null) { - + // PERFORMING FIRST QUERY FOR IDS IF AND ONLY IF WHERE CONDITIONS IN THE QUERY. + // SEARCHING FACILITY IS ENACTING. + if (filter.getConditions() != null) { + // Setting PROJECTION ONLY FOR PROEJCT ID LinkedHashMap projectionForIDs = new LinkedHashMap(); projectionForIDs.put(Project.ID, 1); filter.setProjection(projectionForIDs); - + // FIRST QUERY TO RETRIEVE IDs // LIMIT IS NULL MEANS THAT IT IS EQUAL TO NUMBER TOTAL OF DOCUMENTS - //Calculating always the size starting from 0 + // Calculating always the size starting from 0 final Iterator projectsIDs = client.queryOnMongo(theProfileID, totalProjectForProfile, 0, null, filter); - - //Getting the Project IDs from the Iterable + + // Getting the Project IDs from the Iterable Iterable itP = () -> projectsIDs; Stream targetStream = StreamSupport.stream(itP.spliterator(), false); List listProjectIDs = targetStream.map(Project::getId).collect(Collectors.toList()); @@ -548,13 +550,12 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen searchedData.setTotalItems(totalItems); LOG.info("Total Docs read from query per ID: " + totalItems); } - - //NOW PERFORMING THE (REAL) SECOND QUERY FROM CLIENT + + // NOW PERFORMING THE (REAL) SECOND QUERY FROM CLIENT // SETTING ORIGINAL PROJECTION FROM CLIENT filter.setProjection(originalProjection); // LIMIT IS FROM CLIENT - Iterator projects = client.queryOnMongo(theProfileID, totalItems, start, limit, - filter); + Iterator projects = client.queryOnMongo(theProfileID, totalItems, start, limit, filter); searchedData.setClientStartIndex(start); searchedData.setLimit(limit); @@ -562,9 +563,10 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen List toReturnList = ConvertToDataValueObjectModel.toListResultDocument(projects); searchedData.setData(toReturnList); - - LOG.info("Total Docs page size returned:" + toReturnList.size() + ", start: " + start + ", limit: " + limit); - + + LOG.info( + "Total Docs page size returned:" + toReturnList.size() + ", start: " + start + ", limit: " + limit); + if (totalProjectForProfile == limit || totalProjectForProfile == 0) { LOG.debug("Page completed returning " + totalProjectForProfile + " projects"); int newOffset = start + limit; @@ -1129,6 +1131,36 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen return null; } + @Override + public ProjectEdit getProjectEdit(String profileID, String projectID) throws Exception { + LOG.info("getProjectEdit called for profileID: {}, and projectID: {}", profileID, projectID); + try { + PortalContext pContext = PortalContext.getConfiguration(); + GCubeUser user = pContext.getCurrentUser(this.getThreadLocalRequest()); + String scope = SessionUtil.getCurrentContext(getThreadLocalRequest(), true); + + ProjectsCaller clientProjects = GeoportalClientCaller.projects(); + Project theProject = clientProjects.getProjectByID(profileID, projectID); + ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); + projectBuilder.relationships(true); + ProjectDV theProjectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder); + + ProjectEdit projectEdit = Geoportal_JSON_Mapper.loadProjectEdit(theProjectDV, scope, user.getUsername()); + + if (LOG.isDebugEnabled()) { + Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectEdit); + } + + LOG.info("getProjectEdit returing not null: " + (projectEdit != null)); + return projectEdit; + } catch (Exception e) { + String erroMsg = "Error occurred on reading ProjectEdit DTO for id: " + projectID; + LOG.warn(erroMsg, e); + throw new Exception( + erroMsg + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support"); + } + } + /** * Pretty print client data entry map. * diff --git a/src/main/resources/org/gcube/portlets/user/geoportaldataentry/GeoPortalDataEntryApp.gwt.xml b/src/main/resources/org/gcube/portlets/user/geoportaldataentry/GeoPortalDataEntryApp.gwt.xml index 66f97a0..bcdccbb 100644 --- a/src/main/resources/org/gcube/portlets/user/geoportaldataentry/GeoPortalDataEntryApp.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/geoportaldataentry/GeoPortalDataEntryApp.gwt.xml @@ -12,28 +12,27 @@ + + + + - - - - - - - + + - - + - + + - - - - - - + + +