Implemented update project by JSONEditor

This commit is contained in:
Francesco Mangiacrapa 2022-09-14 10:12:07 +02:00
parent 28277db942
commit 589acc519f
4 changed files with 87 additions and 101 deletions

View File

@ -87,13 +87,13 @@ public interface GeoportalDataEntryService extends RemoteService {
/** /**
* Update record. * Update record.
* *
* @param itemId the item id * @param profileID the profile ID
* @param projectID the project ID
* @param jsonUpdate the json update * @param jsonUpdate the json update
* @param recordType the record type * @return the project DV
* @return the concessione DV
* @throws Exception the exception * @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. * Read file set paths.

View File

@ -63,7 +63,7 @@ public interface GeoportalDataEntryServiceAsync {
void getJSONDocumentInTheProject(String profileID, String projectID, AsyncCallback<String> callback); void getJSONDocumentInTheProject(String profileID, String projectID, AsyncCallback<String> callback);
void updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType, AsyncCallback<ConcessioneDV> callback); void updateRecord(String profileID, String projectID, String jsonUpdate, AsyncCallback<ProjectDV> callback);
void readFileSetPaths(AsyncCallback<FileSetPathsDV> callback); void readFileSetPaths(AsyncCallback<FileSetPathsDV> callback);

View File

@ -1,12 +1,11 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui.edit; 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.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.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp; 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.edit.jseditor.JSONEditorWrapper;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon;
import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Button;
@ -83,10 +82,9 @@ public class EditModeRecord extends Composite {
this.filesUpdatePanel.setHeight("490px"); this.filesUpdatePanel.setHeight("490px");
// filesUpdatePanel.getElement().getStyle().setProperty("maxHeight", "550px"); // filesUpdatePanel.getElement().getStyle().setProperty("maxHeight", "550px");
// TODO Must be instanceUpdateFilesetEditor
//TODO Must be instanceUpdateFilesetEditor
tabUploadFiles.asWidget().getElement().getStyle().setVisibility(Visibility.HIDDEN); tabUploadFiles.asWidget().getElement().getStyle().setVisibility(Visibility.HIDDEN);
instanceJSONEditor(); instanceJSONEditor();
instanceUpdateFilesetEditor(); instanceUpdateFilesetEditor();
bindEvents(); bindEvents();
@ -94,7 +92,7 @@ public class EditModeRecord extends Composite {
private void instanceUpdateFilesetEditor() { private void instanceUpdateFilesetEditor() {
//Window.alert("instanceUpdateFilesetEditor must be revisited"); // Window.alert("instanceUpdateFilesetEditor must be revisited");
/* /*
* GeoPortalDataEntryApp.geoportalDataEntryService.readFileSetPaths(new * GeoPortalDataEntryApp.geoportalDataEntryService.readFileSetPaths(new
@ -169,77 +167,68 @@ public class EditModeRecord extends Composite {
buttonJSONUpdate.setEnabled(false); buttonJSONUpdate.setEnabled(false);
final LoaderIcon loader = new LoaderIcon("Updating the project..."); final LoaderIcon loader = new LoaderIcon("Updating the project...");
tabRawUpdate.add(loader); tabRawUpdate.add(loader);
GeoPortalDataEntryApp.geoportalDataEntryService.updateRecord(selectedProject.getProfileID(),
selectedProject.getId(), jsEditor.getText(), new AsyncCallback<ProjectDV>() {
Window.alert("buttonJSONUpdate addClickHandler must be revisited"); @Override
/* public void onFailure(Throwable caught) {
* GeoPortalDataEntryApp.geoportalDataEntryService.updateRecord(selectedProject. buttonJSONUpdate.setEnabled(true);
* getItemId(), jsEditor.getText(), recordType, new try {
* AsyncCallback<ConcessioneDV>() { rawUpdatePanel.getElement().removeClassName("disable-div");
* tabRawUpdate.remove(loader);
* @Override public void onFailure(Throwable caught) { } catch (Exception e) {
* buttonJSONUpdate.setEnabled(true); try { // TODO: handle exception
* rawUpdatePanel.getElement().removeClassName("disable-div"); }
* tabRawUpdate.remove(loader); } catch (Exception e) { // TODO: handle
* exception } // editorManagerBus.fireEvent(new ActionPerformedOnItemEvent<ConcessioneDV>(null,
* // ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
* Window.alert("buttonJSONUpdate must be revisited");
*
* editorManagerBus.fireEvent(new }
* OperationPerformedOnItemEvent<ConcessioneDV>(null,
* ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); @Override
* public void onSuccess(ProjectDV result) {
* buttonJSONUpdate.setEnabled(true);
* } try {
* rawUpdatePanel.getElement().removeClassName("disable-div");
* @Override public void onSuccess(ConcessioneDV result) { tabRawUpdate.remove(loader);
* buttonJSONUpdate.setEnabled(true); try { } catch (Exception e) {
* rawUpdatePanel.getElement().removeClassName("disable-div"); // TODO: handle exception
* tabRawUpdate.remove(loader); } catch (Exception e) { // TODO: handle }
* exception }
* DialogInform di = new DialogInform(null, "Project updated!",
* DialogInform di = new DialogInform(null, "Project updated!", "Project '" + "Project ID '" + result.getId() + "' updated correctly");
* result.getNome() + "' updated correctly"); di.setZIndex(100000); di.center(); di.setZIndex(100000);
* di.center();
* Window.alert("buttonJSONUpdate ConcessioneDV must be revisited");
* // editorManagerBus.fireEvent(new ActionPerformedOnItemEvent<ConcessioneDV>(
* editorManagerBus.fireEvent(new OperationPerformedOnItemEvent<ConcessioneDV>( // Arrays.asList(result), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
* Arrays.asList(result), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
* }
* } }); });
*/
} }
}); });
editorManagerBus.addHandler(OperationPerformedOnItemEvent.TYPE, new OperationPerformedOnItemEventHandler() { // editorManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() {
//
@Override // @Override
public <T extends DocumentDV> void onDoActionPerformedFired( // public <T extends RecordDV> void onDoActionPerformedFired(
OperationPerformedOnItemEvent<T> actionPerformedOnItemEvent) { // ActionPerformedOnItemEvent<T> actionPerformedOnItemEvent) {
// ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction();
Window.alert("OperationPerformedOnItemEvent must be revisited"); // List<T> items = actionPerformedOnItemEvent.getSelectItems();
//
/* // if (items != null) {
* ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction(); // selectedConcessione = (BaseConcessioneDV) items.get(0);
* List<T> items = actionPerformedOnItemEvent.getSelectItems(); // instanceJSONEditor();
* //
* if (items != null) { selectedProject = (BaseConcessioneDV) items.get(0); // if (action.equals(ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)) {
* instanceJSONEditor(); // appManagerBus.fireEvent(new ActionPerformedOnItemEvent<ConcessioneDV>(
* // (List<ConcessioneDV>) items, ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
* 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<ConcessioneDV>(
* (List<ConcessioneDV>) items, ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
*
* } }
*/
}
});
} }
} }

View File

@ -8,6 +8,8 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; 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.Project;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation; import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.model.legacy.Concessione;
@ -504,38 +506,33 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
/** /**
* Update record. * Update record.
* *
* @param itemId the item id * @param profileID the profile ID
* @param projectID the project ID
* @param jsonUpdate the json update * @param jsonUpdate the json update
* @param recordType the record type
* @return the updated JSON string representing the itemId * @return the updated JSON string representing the itemId
* @throws Exception the exception * @throws Exception the exception
*/ */
@Override @Override
public ConcessioneDV updateRecord(String itemId, String jsonUpdate, RECORD_TYPE recordType) throws Exception { public ProjectDV updateRecord(String profileID, String projectID, String jsonUpdate) throws Exception {
LOG.info("updateRecord called with itemId: " + itemId + ", recordType: " + recordType); LOG.info("updateRecord called with profileID: " + profileID + ", projectID: " + projectID);
try { try {
if (itemId == null) if (projectID == null)
throw new Exception("Item id is null"); throw new Exception("projectID 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;
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) { } 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( 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());
} }
} }