Implemented update project by JSONEditor
This commit is contained in:
parent
28277db942
commit
589acc519f
|
@ -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.
|
||||
|
|
|
@ -63,7 +63,7 @@ public interface GeoportalDataEntryServiceAsync {
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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<ProjectDV>() {
|
||||
|
||||
Window.alert("buttonJSONUpdate addClickHandler must be revisited");
|
||||
/*
|
||||
* GeoPortalDataEntryApp.geoportalDataEntryService.updateRecord(selectedProject.
|
||||
* getItemId(), jsEditor.getText(), recordType, new
|
||||
* AsyncCallback<ConcessioneDV>() {
|
||||
*
|
||||
* @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<ConcessioneDV>(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<ConcessioneDV>(
|
||||
* 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<ConcessioneDV>(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<ConcessioneDV>(
|
||||
// Arrays.asList(result), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
editorManagerBus.addHandler(OperationPerformedOnItemEvent.TYPE, new OperationPerformedOnItemEventHandler() {
|
||||
|
||||
@Override
|
||||
public <T extends DocumentDV> void onDoActionPerformedFired(
|
||||
OperationPerformedOnItemEvent<T> actionPerformedOnItemEvent) {
|
||||
|
||||
Window.alert("OperationPerformedOnItemEvent must be revisited");
|
||||
|
||||
/*
|
||||
* ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction();
|
||||
* List<T> 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<ConcessioneDV>(
|
||||
* (List<ConcessioneDV>) items, ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
|
||||
*
|
||||
* } }
|
||||
*/
|
||||
|
||||
}
|
||||
});
|
||||
// editorManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() {
|
||||
//
|
||||
// @Override
|
||||
// public <T extends RecordDV> void onDoActionPerformedFired(
|
||||
// ActionPerformedOnItemEvent<T> actionPerformedOnItemEvent) {
|
||||
// ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction();
|
||||
// List<T> 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<ConcessioneDV>(
|
||||
// (List<ConcessioneDV>) items, ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue