From 589acc519f329d32aaf746ad867b6fed260c32d5 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 14 Sep 2022 10:12:07 +0200 Subject: [PATCH] Implemented update project by JSONEditor --- .../client/GeoportalDataEntryService.java | 8 +- .../GeoportalDataEntryServiceAsync.java | 2 +- .../client/ui/edit/EditModeRecord.java | 137 ++++++++---------- .../server/GeoportalDataEntryServiceImpl.java | 41 +++--- 4 files changed, 87 insertions(+), 101 deletions(-) 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 b677b0e..98c88a6 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 @@ -87,13 +87,13 @@ public interface GeoportalDataEntryService extends RemoteService { /** * Update record. * - * @param itemId the item id + * @param profileID the profile ID + * @param projectID the project ID * @param jsonUpdate the json update - * @param recordType the record type - * @return the concessione DV + * @return the project DV * @throws Exception the exception */ - ConcessioneDV updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception; + ProjectDV updateRecord(String profileID, String projectID, String jsonUpdate) throws Exception; /** * Read file set paths. 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 91fc022..785fecc 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,7 +63,7 @@ public interface GeoportalDataEntryServiceAsync { void getJSONDocumentInTheProject(String profileID, String projectID, AsyncCallback callback); - void updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType, AsyncCallback callback); + void updateRecord(String profileID, String projectID, String jsonUpdate, AsyncCallback callback); void readFileSetPaths(AsyncCallback callback); 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 0361e13..fcb53c6 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 @@ -1,12 +1,11 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui.edit; -import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; +import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; 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.OperationPerformedOnItemEvent; -import org.gcube.portlets.user.geoportaldataentry.client.events.OperationPerformedOnItemEventHandler; 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; import com.github.gwtbootstrap.client.ui.Button; @@ -83,10 +82,9 @@ public class EditModeRecord extends Composite { this.filesUpdatePanel.setHeight("490px"); // filesUpdatePanel.getElement().getStyle().setProperty("maxHeight", "550px"); - - //TODO Must be instanceUpdateFilesetEditor + // TODO Must be instanceUpdateFilesetEditor tabUploadFiles.asWidget().getElement().getStyle().setVisibility(Visibility.HIDDEN); - + instanceJSONEditor(); instanceUpdateFilesetEditor(); bindEvents(); @@ -94,7 +92,7 @@ public class EditModeRecord extends Composite { private void instanceUpdateFilesetEditor() { - //Window.alert("instanceUpdateFilesetEditor must be revisited"); + // Window.alert("instanceUpdateFilesetEditor must be revisited"); /* * GeoPortalDataEntryApp.geoportalDataEntryService.readFileSetPaths(new @@ -169,77 +167,68 @@ public class EditModeRecord extends Composite { buttonJSONUpdate.setEnabled(false); final LoaderIcon loader = new LoaderIcon("Updating the project..."); tabRawUpdate.add(loader); + GeoPortalDataEntryApp.geoportalDataEntryService.updateRecord(selectedProject.getProfileID(), + selectedProject.getId(), jsEditor.getText(), new AsyncCallback() { - Window.alert("buttonJSONUpdate addClickHandler must be revisited"); - /* - * GeoPortalDataEntryApp.geoportalDataEntryService.updateRecord(selectedProject. - * getItemId(), jsEditor.getText(), recordType, new - * AsyncCallback() { - * - * @Override public void onFailure(Throwable caught) { - * buttonJSONUpdate.setEnabled(true); try { - * rawUpdatePanel.getElement().removeClassName("disable-div"); - * tabRawUpdate.remove(loader); } catch (Exception e) { // TODO: handle - * exception } - * - * Window.alert("buttonJSONUpdate must be revisited"); - * - * editorManagerBus.fireEvent(new - * OperationPerformedOnItemEvent(null, - * ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); - * - * - * } - * - * @Override public void onSuccess(ConcessioneDV result) { - * buttonJSONUpdate.setEnabled(true); try { - * rawUpdatePanel.getElement().removeClassName("disable-div"); - * tabRawUpdate.remove(loader); } catch (Exception e) { // TODO: handle - * exception } - * - * DialogInform di = new DialogInform(null, "Project updated!", "Project '" + - * result.getNome() + "' updated correctly"); di.setZIndex(100000); di.center(); - * - * Window.alert("buttonJSONUpdate ConcessioneDV must be revisited"); - * - * editorManagerBus.fireEvent(new OperationPerformedOnItemEvent( - * Arrays.asList(result), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); - * - * } }); - */ + @Override + public void onFailure(Throwable caught) { + buttonJSONUpdate.setEnabled(true); + try { + rawUpdatePanel.getElement().removeClassName("disable-div"); + tabRawUpdate.remove(loader); + } catch (Exception e) { + // TODO: handle exception + } + +// editorManagerBus.fireEvent(new ActionPerformedOnItemEvent(null, +// ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); + + + } + + @Override + public void onSuccess(ProjectDV result) { + buttonJSONUpdate.setEnabled(true); + try { + rawUpdatePanel.getElement().removeClassName("disable-div"); + tabRawUpdate.remove(loader); + } catch (Exception e) { + // TODO: handle exception + } + + DialogInform di = new DialogInform(null, "Project updated!", + "Project ID '" + result.getId() + "' updated correctly"); + di.setZIndex(100000); + di.center(); + +// editorManagerBus.fireEvent(new ActionPerformedOnItemEvent( +// Arrays.asList(result), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); + + } + }); } }); - editorManagerBus.addHandler(OperationPerformedOnItemEvent.TYPE, new OperationPerformedOnItemEventHandler() { - - @Override - public void onDoActionPerformedFired( - OperationPerformedOnItemEvent actionPerformedOnItemEvent) { - - Window.alert("OperationPerformedOnItemEvent must be revisited"); - - /* - * ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction(); - * List items = actionPerformedOnItemEvent.getSelectItems(); - * - * if (items != null) { selectedProject = (BaseConcessioneDV) items.get(0); - * instanceJSONEditor(); - * - * if (action.equals(ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)) { - * - * Window. - * alert("ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT ConcessioneDV must be revisited" - * ); - * - * - * appManagerBus.fireEvent(new OperationPerformedOnItemEvent( - * (List) items, ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); - * - * } } - */ - - } - }); +// editorManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() { +// +// @Override +// 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_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/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java index ed98d1c..7296127 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 @@ -8,6 +8,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.bson.Document; +import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation; import org.gcube.application.geoportal.common.model.legacy.Concessione; @@ -504,38 +506,33 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen /** * Update record. * - * @param itemId the item id + * @param profileID the profile ID + * @param projectID the project ID * @param jsonUpdate the json update - * @param recordType the record type * @return the updated JSON string representing the itemId * @throws Exception the exception */ @Override - public ConcessioneDV updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception { - LOG.info("updateRecord called with itemId: " + itemId + ", recordType: " + recordType); + public ProjectDV updateRecord(String profileID, String projectID, String jsonUpdate) throws Exception { + LOG.info("updateRecord called with profileID: " + profileID + ", projectID: " + projectID); try { - if (itemId == null) - throw new Exception("Item id is null"); - - LOG.debug("jsonUpdate is: " + jsonUpdate); - if (recordType.equals(RECORD_TYPE.CONCESSIONE)) { - SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); - MongoServiceUtil serviceUtil = new MongoServiceUtil(); - MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); - Concessione concessione = clientMongo.update(itemId, jsonUpdate); - LOG.debug("Got Record updated: " + concessione); - ConcessioneDV concessionDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); - LOG.info("Record with id " + concessionDV.getItemId() + "updated correclty"); - return concessionDV; - } - - return null; + if (projectID == null) + throw new Exception("projectID is null"); + ProjectsCaller client = GeoportalClientCaller.projects(); + SessionUtil.getCurrentContext(getThreadLocalRequest(), true); + + Document updatedDocument = Serialization.read(jsonUpdate, Document.class); + LOG.info("updatedDocument is {}", updatedDocument); + Project project = client.updateProject(profileID, projectID, updatedDocument); + LOG.info("Project with id " + project.getId() + " updated correclty"); + ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); + return ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder); } catch (Exception e) { - LOG.error("Error on updating the project with item id: " + itemId, e); + LOG.error("Error on updating the project with item id: " + projectID, e); throw new Exception( - "Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage()); + "Error occurred on updating the project with id: " + projectID + ". Error: " + e.getMessage()); } }