tree node built on the client-side
This commit is contained in:
parent
7932c31c52
commit
7c2be535a2
|
@ -57,6 +57,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
|||
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.Tree_Node;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
|
||||
|
@ -112,7 +113,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
|
|||
|
||||
private GeonaMainTabPanel mainTabPanel;
|
||||
|
||||
private LinkedHashMap<String, List<GeoNaFormDataObject>> savedMap = new LinkedHashMap<String, List<GeoNaFormDataObject>>();
|
||||
private LinkedHashMap<String, Tree_Node<GeoNaFormDataObject>> savedMap = new LinkedHashMap<String, Tree_Node<GeoNaFormDataObject>>();
|
||||
|
||||
private boolean projectSavedWithSuccess;
|
||||
|
||||
|
@ -518,7 +519,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
|
|||
|
||||
geoNaMainForm.enableButtonSave(false);
|
||||
|
||||
if (saveGeonaDataFormsEvent.getListGeonaDataForms() != null) {
|
||||
if (saveGeonaDataFormsEvent.getTreeNode() != null) {
|
||||
|
||||
final Modal modal = new Modal(true);
|
||||
modal.setCloseVisible(false);
|
||||
|
@ -533,7 +534,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
|
|||
modal.add(modalContainerPanel);
|
||||
|
||||
GeoportalDataEntryServiceAsync.Util.getInstance().saveGeonaDataForms(
|
||||
saveGeonaDataFormsEvent.getProfileID(), saveGeonaDataFormsEvent.getListGeonaDataForms(),
|
||||
saveGeonaDataFormsEvent.getProfileID(), saveGeonaDataFormsEvent.getTreeNode(),
|
||||
new AsyncCallback<CommitReport>() {
|
||||
|
||||
@Override
|
||||
|
@ -606,7 +607,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
|
|||
|
||||
try {
|
||||
savedMap.put(result.getProjectID(),
|
||||
saveGeonaDataFormsEvent.getListGeonaDataForms());
|
||||
saveGeonaDataFormsEvent.getTreeNode());
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
|||
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.Tree_Node;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
|
||||
|
||||
import com.google.gwt.user.client.rpc.RemoteService;
|
||||
|
@ -29,7 +30,7 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
|||
@RemoteServiceRelativePath("geoportaldataentryservice")
|
||||
public interface GeoportalDataEntryService extends RemoteService {
|
||||
|
||||
CommitReport saveGeonaDataForms(String profileID, List<GeoNaFormDataObject> listGeonaFormObjects) throws Exception;
|
||||
CommitReport saveGeonaDataForms(String profileID, Tree_Node<GeoNaFormDataObject> tree_Node) throws Exception;
|
||||
|
||||
/**
|
||||
* Gets the geona init config.
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
|||
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.Tree_Node;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
|
@ -39,7 +40,7 @@ public interface GeoportalDataEntryServiceAsync {
|
|||
}
|
||||
}
|
||||
|
||||
void saveGeonaDataForms(String profileID, List<GeoNaFormDataObject> listGeonaFormObjects, AsyncCallback<CommitReport> callback);
|
||||
void saveGeonaDataForms(String profileID, Tree_Node<GeoNaFormDataObject> tree_Node, AsyncCallback<CommitReport> callback);
|
||||
|
||||
void getGeonaInitConfig(AsyncCallback<GeonaISConfig> callback);
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package org.gcube.portlets.user.geoportaldataentry.client.events;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.Tree_Node;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
@ -12,23 +11,23 @@ import com.google.gwt.event.shared.GwtEvent;
|
|||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Oct 20, 2020
|
||||
* Oct 20, 2020
|
||||
*/
|
||||
public class SaveGeonaDataFormsEvent extends GwtEvent<SaveGeonaDataFormsHandler> {
|
||||
|
||||
|
||||
/** The type. */
|
||||
public static Type<SaveGeonaDataFormsHandler> TYPE = new Type<SaveGeonaDataFormsHandler>();
|
||||
private List<GeoNaFormDataObject> listGeonaDataForms;
|
||||
private Tree_Node<GeoNaFormDataObject> treeNode;
|
||||
private String profileID;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new save geona data forms event.
|
||||
*
|
||||
* @param listGeonaDataForms the list geona data forms
|
||||
* @param profileID the profile ID
|
||||
* @param treeNode the tree node
|
||||
*/
|
||||
public SaveGeonaDataFormsEvent(String profileID, List<GeoNaFormDataObject> listGeonaDataForms) {
|
||||
this.listGeonaDataForms = listGeonaDataForms;
|
||||
public SaveGeonaDataFormsEvent(String profileID, Tree_Node<GeoNaFormDataObject> treeNode) {
|
||||
this.treeNode = treeNode;
|
||||
this.profileID = profileID;
|
||||
}
|
||||
|
||||
|
@ -37,7 +36,9 @@ public class SaveGeonaDataFormsEvent extends GwtEvent<SaveGeonaDataFormsHandler>
|
|||
*
|
||||
* @return the associated type
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
|
||||
*/
|
||||
@Override
|
||||
|
@ -50,18 +51,27 @@ public class SaveGeonaDataFormsEvent extends GwtEvent<SaveGeonaDataFormsHandler>
|
|||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.
|
||||
* EventHandler)
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(SaveGeonaDataFormsHandler handler) {
|
||||
handler.onSave(this);
|
||||
}
|
||||
|
||||
public List<GeoNaFormDataObject> getListGeonaDataForms() {
|
||||
return listGeonaDataForms;
|
||||
|
||||
public Tree_Node<GeoNaFormDataObject> getTreeNode() {
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the profile ID.
|
||||
*
|
||||
* @return the profile ID
|
||||
*/
|
||||
public String getProfileID() {
|
||||
return profileID;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui.form;
|
|||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsEvent;
|
||||
import org.gcube.portlets.user.geoportaldataentry.client.events.TreeItemEvent;
|
||||
import org.gcube.portlets.user.geoportaldataentry.client.events.TreeItemEvent.ACTION;
|
||||
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel;
|
||||
|
@ -228,6 +229,7 @@ public class GeonaDataEntryMainForm extends Composite {
|
|||
// }
|
||||
// appManagerBus.fireEvent(new SaveGeonaDataFormsEvent(profileID, listGeonaFormObjects));
|
||||
|
||||
appManagerBus.fireEvent(new SaveGeonaDataFormsEvent(profileID, treeNode));
|
||||
TreeVisitUtil.preOrderVisit(treeNode);
|
||||
showAlertOnSaveAction("Andiamo a salvare", AlertType.INFO, true);
|
||||
|
||||
|
@ -277,6 +279,7 @@ public class GeonaDataEntryMainForm extends Composite {
|
|||
}else {
|
||||
//root of the tree
|
||||
tNode = new Tree_Node<GeoNaFormDataObject>(root.getText(), null);
|
||||
tNode.setRoot(true);
|
||||
}
|
||||
|
||||
// Total children count
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||
|
||||
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.Tree_Node;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -26,17 +27,78 @@ public class FormDataObjectToJSON {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FormDataObjectToJSON.class);
|
||||
|
||||
|
||||
/**
|
||||
* Convert.
|
||||
*
|
||||
* @param listGeonaFormObjects the list geona form objects
|
||||
* @param tree_Node the tree node
|
||||
* @return the JSON object
|
||||
* @throws JSONException the JSON exception
|
||||
*/
|
||||
public JSONObject convert(List<GeoNaFormDataObject> listGeonaFormObjects) throws JSONException {
|
||||
public JSONObject convert(Tree_Node<GeoNaFormDataObject> tree_Node, JSONObject theDocument) throws JSONException {
|
||||
|
||||
//JSONObject theDocument = JSONObjecOrdered.instance();
|
||||
|
||||
if(tree_Node==null)
|
||||
return theDocument;
|
||||
|
||||
//the root, instancing new json document
|
||||
if(tree_Node.isRoot()) {
|
||||
theDocument = JSONObjecOrdered.instance();
|
||||
}
|
||||
|
||||
for (Tree_Node<GeoNaFormDataObject> treeNodeChild : tree_Node.getChildren()) {
|
||||
|
||||
//Building the JSON section
|
||||
List<GenericDatasetBean> listGDB = tree_Node.getData().getListGDB();
|
||||
GcubeProfileDV profile = tree_Node.getData().getGcubeProfileDV();
|
||||
LOG.debug("The profile is: " + profile);
|
||||
|
||||
String jsonPathExp = String.format("%s%s", profile.getParentName(), profile.getSectionName());
|
||||
LOG.debug("The json path to build: " + jsonPathExp);
|
||||
// jsonPathExp = "$.chidl1.child2.child3";
|
||||
|
||||
String toJsonPathExp = jsonPathExp.replaceFirst("\\$", "");
|
||||
String[] jsonPathDeep = toJsonPathExp.split("\\.");
|
||||
List<JSONObject> listJSONObject = toListJonObject(listGDB, jsonPathDeep);
|
||||
|
||||
// adding as JSONObject to theDocument at first deep level (under the root or at section specified)
|
||||
if (listJSONObject.size() == 1) {
|
||||
theDocument = deepMerge(listJSONObject.get(0), theDocument);
|
||||
//theDocument = theDocument.put(listJSONObject.get(0), jsonArray);
|
||||
} else {
|
||||
// adding as JSONArray to theDocument under the section specified
|
||||
// to jsonPathDeep[1]
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
for (JSONObject jsonObject : listJSONObject) {
|
||||
// reading the i-mo JSONObject created in the list with the key as
|
||||
// jsonPathDeep[1]
|
||||
jsonArray.put(jsonObject.get(jsonPathDeep[1]));
|
||||
}
|
||||
theDocument.put(jsonPathDeep[1], jsonArray);
|
||||
|
||||
}
|
||||
|
||||
//recursive call...
|
||||
theDocument = convert(treeNodeChild,theDocument);
|
||||
}
|
||||
|
||||
LOG.debug("Partial Root Document is: " + theDocument);
|
||||
return theDocument;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert.
|
||||
*
|
||||
* @param tree_Node the tree node
|
||||
* @return the JSON object
|
||||
* @throws JSONException the JSON exception
|
||||
*/
|
||||
/*public JSONObject convert(Tree_Node<GeoNaFormDataObject> tree_Node) throws JSONException {
|
||||
|
||||
JSONObject theDocument = JSONObjecOrdered.instance();
|
||||
for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) {
|
||||
for (GeoNaFormDataObject geoNaFormDataObject : tree_Node) {
|
||||
|
||||
List<GenericDatasetBean> listGDB = geoNaFormDataObject.getListGDB();
|
||||
|
||||
|
@ -72,7 +134,7 @@ public class FormDataObjectToJSON {
|
|||
|
||||
LOG.debug("Final JSON Document is: " + theDocument);
|
||||
return theDocument;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Generic dataset bean to JSON.
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
|||
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.Tree_Node;
|
||||
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
|
||||
|
@ -108,7 +109,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
@Override
|
||||
public CommitReport saveGeonaDataForms(String profileID, List<GeoNaFormDataObject> listGeonaFormObjects)
|
||||
public CommitReport saveGeonaDataForms(String profileID, Tree_Node<GeoNaFormDataObject> tree_Node)
|
||||
throws Exception {
|
||||
LOG.info("saveGeonaDataForms called for profileID {}", profileID);
|
||||
|
||||
|
@ -117,7 +118,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|||
try {
|
||||
|
||||
FormDataObjectToJSON metadataConverter = new FormDataObjectToJSON();
|
||||
JSONObject theDocument = metadataConverter.convert(listGeonaFormObjects);
|
||||
JSONObject theDocument = metadataConverter.convert(tree_Node);
|
||||
theDocumentString = theDocument.toString();
|
||||
LOG.info("Got Document: " + theDocumentString);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -21,6 +21,7 @@ public class Tree_Node<T> implements Serializable {
|
|||
private T data;
|
||||
private List<Tree_Node<T>> children = new ArrayList<Tree_Node<T>>();
|
||||
private Tree_Node<T> parent;
|
||||
private boolean isRoot;
|
||||
|
||||
/**
|
||||
* Instantiates a new tree node.
|
||||
|
@ -40,6 +41,24 @@ public class Tree_Node<T> implements Serializable {
|
|||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is root.
|
||||
*
|
||||
* @return true, if is root
|
||||
*/
|
||||
public boolean isRoot() {
|
||||
return isRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the root.
|
||||
*
|
||||
* @param isRoot the new root
|
||||
*/
|
||||
public void setRoot(boolean isRoot) {
|
||||
this.isRoot = isRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the child.
|
||||
*
|
||||
|
@ -120,9 +139,10 @@ public class Tree_Node<T> implements Serializable {
|
|||
builder.append(name);
|
||||
builder.append(", data=");
|
||||
builder.append(data);
|
||||
builder.append(", isRoot=");
|
||||
builder.append(isRoot);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue