improved the Update GUI
This commit is contained in:
parent
5c031270a0
commit
e8b3c59a6d
|
@ -1533,7 +1533,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
|
||||||
// modal3.setHeight("700px");
|
// modal3.setHeight("700px");
|
||||||
modal3.setCloseVisible(true);
|
modal3.setCloseVisible(true);
|
||||||
((Element) modal3.getElement().getChildNodes().getItem(1))
|
((Element) modal3.getElement().getChildNodes().getItem(1))
|
||||||
.addClassName("modal-body-custom");
|
.addClassName("modal-body-edit");
|
||||||
int height = Window.getClientHeight() * 70 / 100;
|
int height = Window.getClientHeight() * 70 / 100;
|
||||||
|
|
||||||
int width = Window.getClientWidth() * 70 / 100;
|
int width = Window.getClientWidth() * 70 / 100;
|
||||||
|
@ -1569,7 +1569,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
UpdateRecord ur = new UpdateRecord(appManagerBus, resultDocumentDV.getProfileID(),
|
UpdateRecord ur = new UpdateRecord(appManagerBus, resultDocumentDV.getProfileID(),
|
||||||
resultDocumentDV.getId());
|
resultDocumentDV.getId(), height);
|
||||||
|
|
||||||
if (isNotInDRAFT) {
|
if (isNotInDRAFT) {
|
||||||
ur.noUpdateMode();
|
ur.noUpdateMode();
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class UpdateRecord extends Composite {
|
||||||
|
|
||||||
private HandlerManager appManagerBus;
|
private HandlerManager appManagerBus;
|
||||||
|
|
||||||
public UpdateRecord(HandlerManager appManagerBus, String profileID, String projectID) {
|
public UpdateRecord(HandlerManager appManagerBus, String profileID, String projectID, int modalHeight) {
|
||||||
initWidget(uiBinder.createAndBindUi(this));
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
this.appManagerBus = appManagerBus;
|
this.appManagerBus = appManagerBus;
|
||||||
this.profileID = profileID;
|
this.profileID = profileID;
|
||||||
|
@ -100,7 +100,7 @@ public class UpdateRecord extends Composite {
|
||||||
|
|
||||||
alertHTMLPanel.add(loaderProjectSections);
|
alertHTMLPanel.add(loaderProjectSections);
|
||||||
|
|
||||||
scrollSectionContent.getElement().getStyle().setProperty("maxHeight", "500px");
|
scrollSectionContent.setHeight((modalHeight-300)+"px");
|
||||||
|
|
||||||
GeoportalDataEntryServiceAsync.Util.getInstance().getProjectEdit(profileID, projectID,
|
GeoportalDataEntryServiceAsync.Util.getInstance().getProjectEdit(profileID, projectID,
|
||||||
new AsyncCallback<ProjectEdit>() {
|
new AsyncCallback<ProjectEdit>() {
|
||||||
|
|
|
@ -66,6 +66,7 @@ import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendEx
|
||||||
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService;
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.client.ProjectFormCard;
|
import org.gcube.portlets.user.geoportaldataentry.client.ProjectFormCard;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge;
|
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge;
|
||||||
|
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge.MERGE_OPTION;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtendedConfigProfile;
|
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtendedConfigProfile;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
||||||
|
@ -269,7 +270,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
String srcJ = updatedSectionObject.toString();
|
String srcJ = updatedSectionObject.toString();
|
||||||
String trgJ = targetSectionJObject.toString();
|
String trgJ = targetSectionJObject.toString();
|
||||||
LOG.info("Merging src {} in the target: {}", srcJ, trgJ);
|
LOG.info("Merging src {} in the target: {}", srcJ, trgJ);
|
||||||
String mergedDoc = JsonMerge.merge(srcJ, trgJ);
|
String mergedDoc = JsonMerge.merge(srcJ, trgJ, MERGE_OPTION.REPLACE);
|
||||||
LOG.info("mergedDoc: {}", mergedDoc);
|
LOG.info("mergedDoc: {}", mergedDoc);
|
||||||
|
|
||||||
String newDocJson;
|
String newDocJson;
|
||||||
|
@ -292,26 +293,30 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
Document updatedDocument = Serialization.read(newDocJson.toString(), Document.class);
|
Document updatedDocument = Serialization.read(newDocJson.toString(), Document.class);
|
||||||
LOG.info("New document is: {}", updatedDocument.toJson());
|
LOG.info("New document is: {}", updatedDocument.toJson());
|
||||||
|
|
||||||
Project project = client.updateProject(profileID, projectID, updatedDocument);
|
//Project project = client.updateProject(profileID, projectID, updatedDocument);
|
||||||
|
Project project = client.getProjectByID(profileID, projectID);
|
||||||
LOG.debug("Medatata Updated with document: {}", project.getTheDocument());
|
LOG.debug("Medatata Updated with document: {}", project.getTheDocument());
|
||||||
|
|
||||||
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
||||||
|
|
||||||
|
if(listFilePaths!=null) {
|
||||||
//Cleaning all the fileset path of the section (defined in the UCD)
|
|
||||||
for (FilePathDV filePath: listFilePaths) {
|
|
||||||
|
|
||||||
String filesetFieldName = filePath.getFieldName();
|
//Cleaning all the fileset path of the section (defined in the UCD)
|
||||||
String filesetPath = sectionPath+"."+filesetFieldName;
|
for (FilePathDV filePath: listFilePaths) {
|
||||||
//Replacing $.abc with $..abc
|
|
||||||
filesetPath = filesetPath.replaceFirst("\\.", "..");
|
String filesetFieldName = filePath.getFieldName();
|
||||||
LOG.info("Going to delete fileset path: {}", filesetPath);
|
String filesetPath = sectionPath+"."+filesetFieldName;
|
||||||
//client.deleteFileset(profileID, projectID, filesetPath, true);
|
//Replacing $.abc with $..abc
|
||||||
}
|
filesetPath = filesetPath.replaceFirst("\\.", "..");
|
||||||
|
LOG.info("Going to delete fileset path: {}", filesetPath);
|
||||||
List<? extends FileUploaded> filesUploaded = sectionBean.getFilesUploaded();
|
//client.deleteFileset(profileID, projectID, filesetPath, true);
|
||||||
if(filesUploaded!=null && !filesUploaded.isEmpty()) {
|
}
|
||||||
replaceFiles(project, sectionPath, section.getGcubeProfileDV(), filesUploaded);
|
|
||||||
|
//Registering new files
|
||||||
|
List<? extends FileUploaded> filesUploaded = sectionBean.getFilesUploaded();
|
||||||
|
if(filesUploaded!=null && !filesUploaded.isEmpty()) {
|
||||||
|
replaceFiles(project, sectionPath, section.getGcubeProfileDV(), filesUploaded);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Project with id " + project.getId() + " updated correclty");
|
LOG.info("Project with id " + project.getId() + " updated correclty");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.portlets.user.geoportaldataentry.server.json;
|
package org.gcube.portlets.user.geoportaldataentry.server.json;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -10,179 +11,318 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides methods to merge two json of any nested level into a single json.
|
* This class provides methods to merge two json of any nested level into a
|
||||||
|
* single json.
|
||||||
*
|
*
|
||||||
* copied from: https://github.com/hemantsonu20/json-merge
|
* copied from: https://github.com/hemantsonu20/json-merge
|
||||||
|
*
|
||||||
|
* @maintainer updated by Francesco Mangiacrapa at ISTI-CNR
|
||||||
|
* francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Apr 21, 2023
|
||||||
*/
|
*/
|
||||||
public class JsonMerge {
|
public class JsonMerge {
|
||||||
|
|
||||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to merge two json objects into single json object.
|
* The Enum MERGE_OPTION.
|
||||||
*
|
*
|
||||||
* <p>It merges two json of any nested level into a single json following below logic.</p>
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
* <ul>
|
*
|
||||||
* <li>When keys are different, both keys with there values will be copied at same level.</li>
|
* Apr 21, 2023
|
||||||
* <li>
|
*/
|
||||||
* <p>When keys are same at some level, following table denotes what value will be used.</p>
|
public static enum MERGE_OPTION {
|
||||||
* <table border="1" summary="">
|
MERGE, REPLACE
|
||||||
* <thead>
|
}
|
||||||
* <tr>
|
|
||||||
* <th align="left">Src / Target</th>
|
|
||||||
* <th align="left">JSON Value</th>
|
|
||||||
* <th align="left">JSON Array</th>
|
|
||||||
* <th align="left">JSON Object</th>
|
|
||||||
* </tr>
|
|
||||||
* </thead>
|
|
||||||
* <tbody>
|
|
||||||
* <tr>
|
|
||||||
* <td align="left">JSON Value<sup>1</sup></td>
|
|
||||||
* <td align="left">Src</td>
|
|
||||||
* <td align="left">Src</td>
|
|
||||||
* <td align="left">Src</td>
|
|
||||||
* </tr>
|
|
||||||
* <tr>
|
|
||||||
* <td align="left">JSON Array</td>
|
|
||||||
* <td align="left">Src<sup>2</sup></td>
|
|
||||||
* <td align="left">Merge</td>
|
|
||||||
* <td align="left">Src</td>
|
|
||||||
* </tr>
|
|
||||||
* <tr>
|
|
||||||
* <td align="left">JSON Object</td>
|
|
||||||
* <td align="left">Src</td>
|
|
||||||
* <td align="left">Src</td>
|
|
||||||
* <td align="left">Merge<sup>3</sup></td>
|
|
||||||
* </tr>
|
|
||||||
* </tbody>
|
|
||||||
* </table>
|
|
||||||
* <ul>
|
|
||||||
* <li><sup><strong>1</strong></sup> Json Value denotes boolean, number or string value in json.</li>
|
|
||||||
* <li><sup><strong>2</strong></sup> Src denotes <code>Src</code> value will be copied.</li>
|
|
||||||
* <li><sup><strong>3</strong></sup> Merge denotes both <code>Src</code> and <code>Target</code> values will be merged.</li>
|
|
||||||
* </ul>
|
|
||||||
* </li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* <h2>Examples</h2>
|
|
||||||
* <h3>Example 1</h3>
|
|
||||||
* <p><strong>Source Json</strong></p>
|
|
||||||
* <pre>{@code
|
|
||||||
* {
|
|
||||||
* "name": "json-merge-src"
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
* <p><strong>Target Json</strong></p>
|
|
||||||
* <pre>{@code
|
|
||||||
* {
|
|
||||||
* "name": "json-merge-target"
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
* <p><strong>Output</strong></p>
|
|
||||||
* <pre>{@code
|
|
||||||
* {
|
|
||||||
* "name": "json-merge-src"
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
* <h3>Example 2</h3>
|
|
||||||
* <p><strong>Source Json</strong></p>
|
|
||||||
* <pre>{@code
|
|
||||||
* {
|
|
||||||
* "level1": {
|
|
||||||
* "key1": "SrcValue1"
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
* <p><strong>Target Json</strong></p>
|
|
||||||
* <pre>{@code
|
|
||||||
* {
|
|
||||||
* "level1": {
|
|
||||||
* "key1": "targetValue1",
|
|
||||||
* "level2": {
|
|
||||||
* "key2": "value2"
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
* <p><strong>Output</strong></p>
|
|
||||||
* <pre>{@code
|
|
||||||
* {
|
|
||||||
* "level1": {
|
|
||||||
* "key1": "SrcValue1",
|
|
||||||
* "level2": {
|
|
||||||
* "key2": "value2"
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }</pre>
|
|
||||||
*
|
|
||||||
* @param srcJsonStr source json string
|
|
||||||
* @param targetJsonStr target json string
|
|
||||||
* @return merged json as a string
|
|
||||||
*/
|
|
||||||
public static String merge(String srcJsonStr, String targetJsonStr) {
|
|
||||||
|
|
||||||
try {
|
/**
|
||||||
JsonNode srcNode = OBJECT_MAPPER.readTree(srcJsonStr);
|
* Method to merge two json objects into single json object.
|
||||||
JsonNode targetNode = OBJECT_MAPPER.readTree(targetJsonStr);
|
*
|
||||||
JsonNode result = merge(srcNode, targetNode);
|
* <p>
|
||||||
return OBJECT_MAPPER.writeValueAsString(result);
|
* It merges two json of any nested level into a single json following below
|
||||||
} catch (IOException e) {
|
* logic.
|
||||||
throw new JsonMergeException("Unable to merge json", e);
|
* </p>
|
||||||
}
|
* <ul>
|
||||||
}
|
* <li>When keys are different, both keys with there values will be copied at
|
||||||
|
* same level.</li>
|
||||||
|
* <li>
|
||||||
|
* <p>
|
||||||
|
* When keys are same at some level, following table denotes what value will be
|
||||||
|
* used.
|
||||||
|
* </p>
|
||||||
|
* <table border="1" summary="">
|
||||||
|
* <thead>
|
||||||
|
* <tr>
|
||||||
|
* <th align="left">Src / Target</th>
|
||||||
|
* <th align="left">JSON Value</th>
|
||||||
|
* <th align="left">JSON Array</th>
|
||||||
|
* <th align="left">JSON Object</th>
|
||||||
|
* </tr>
|
||||||
|
* </thead> <tbody>
|
||||||
|
* <tr>
|
||||||
|
* <td align="left">JSON Value<sup>1</sup></td>
|
||||||
|
* <td align="left">Src</td>
|
||||||
|
* <td align="left">Src</td>
|
||||||
|
* <td align="left">Src</td>
|
||||||
|
* </tr>
|
||||||
|
* <tr>
|
||||||
|
* <td align="left">JSON Array</td>
|
||||||
|
* <td align="left">Src<sup>2</sup></td>
|
||||||
|
* <td align="left">Merge</td>
|
||||||
|
* <td align="left">Src</td>
|
||||||
|
* </tr>
|
||||||
|
* <tr>
|
||||||
|
* <td align="left">JSON Object</td>
|
||||||
|
* <td align="left">Src</td>
|
||||||
|
* <td align="left">Src</td>
|
||||||
|
* <td align="left">Merge<sup>3</sup></td>
|
||||||
|
* </tr>
|
||||||
|
* </tbody>
|
||||||
|
* </table>
|
||||||
|
* <ul>
|
||||||
|
* <li><sup><strong>1</strong></sup> Json Value denotes boolean, number or
|
||||||
|
* string value in json.</li>
|
||||||
|
* <li><sup><strong>2</strong></sup> Src denotes <code>Src</code> value will be
|
||||||
|
* copied.</li>
|
||||||
|
* <li><sup><strong>3</strong></sup> Merge denotes both <code>Src</code> and
|
||||||
|
* <code>Target</code> values will be merged.</li>
|
||||||
|
* </ul>
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <h2>Examples</h2>
|
||||||
|
* <h3>Example 1</h3>
|
||||||
|
* <p>
|
||||||
|
* <strong>Source Json</strong>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* {
|
||||||
|
* "name": "json-merge-src"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* <p>
|
||||||
|
* <strong>Target Json</strong>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* {
|
||||||
|
* "name": "json-merge-target"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* <p>
|
||||||
|
* <strong>Output</strong>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* {
|
||||||
|
* "name": "json-merge-src"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* <h3>Example 2</h3>
|
||||||
|
* <p>
|
||||||
|
* <strong>Source Json</strong>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* {
|
||||||
|
* "level1": {
|
||||||
|
* "key1": "SrcValue1"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* <p>
|
||||||
|
* <strong>Target Json</strong>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* {
|
||||||
|
* "level1": {
|
||||||
|
* "key1": "targetValue1",
|
||||||
|
* "level2": {
|
||||||
|
* "key2": "value2"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* <p>
|
||||||
|
* <strong>Output</strong>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* {
|
||||||
|
* "level1": {
|
||||||
|
* "key1": "SrcValue1",
|
||||||
|
* "level2": {
|
||||||
|
* "key2": "value2"
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param srcJsonStr source json string
|
||||||
|
* @param targetJsonStr target json string
|
||||||
|
* @param option the option
|
||||||
|
* @return merged json as a string
|
||||||
|
*/
|
||||||
|
public static String merge(String srcJsonStr, String targetJsonStr, MERGE_OPTION option) {
|
||||||
|
|
||||||
public static JsonNode merge(JsonNode srcNode, JsonNode targetNode) {
|
try {
|
||||||
|
if (option == null)
|
||||||
|
option = MERGE_OPTION.MERGE;
|
||||||
|
|
||||||
// if both nodes are object node, merged object node is returned
|
JsonNode srcNode = OBJECT_MAPPER.readTree(srcJsonStr);
|
||||||
if (srcNode.isObject() && targetNode.isObject()) {
|
JsonNode targetNode = OBJECT_MAPPER.readTree(targetJsonStr);
|
||||||
return merge((ObjectNode) srcNode, (ObjectNode) targetNode);
|
JsonNode result = merge(srcNode, targetNode, option);
|
||||||
}
|
return OBJECT_MAPPER.writeValueAsString(result);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JsonMergeException("Unable to merge json", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if both nodes are array node, merged array node is returned
|
/**
|
||||||
if (srcNode.isArray() && targetNode.isArray()) {
|
* Merge.
|
||||||
return merge((ArrayNode) srcNode, (ArrayNode) targetNode);
|
*
|
||||||
}
|
* @param srcNode the src node
|
||||||
|
* @param targetNode the target node
|
||||||
|
* @param option the option
|
||||||
|
* @return the json node
|
||||||
|
*/
|
||||||
|
public static JsonNode merge(JsonNode srcNode, JsonNode targetNode, MERGE_OPTION option) {
|
||||||
|
|
||||||
// special case when src node is null
|
if (option == null)
|
||||||
if (srcNode.isNull()) {
|
option = MERGE_OPTION.MERGE;
|
||||||
return targetNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
return srcNode;
|
// if both nodes are object node, merged object node is returned
|
||||||
}
|
if (srcNode.isObject() && targetNode.isObject()) {
|
||||||
|
return merge((ObjectNode) srcNode, (ObjectNode) targetNode, option);
|
||||||
|
}
|
||||||
|
|
||||||
public static ObjectNode merge(ObjectNode srcNode, ObjectNode targetNode) {
|
// if both nodes are array node, merged array node is returned
|
||||||
|
if (srcNode.isArray() && targetNode.isArray()) {
|
||||||
|
return mergeArray((ArrayNode) srcNode, (ArrayNode) targetNode, option);
|
||||||
|
}
|
||||||
|
|
||||||
ObjectNode result = OBJECT_MAPPER.createObjectNode();
|
// special case when src node is null
|
||||||
|
if (srcNode.isNull()) {
|
||||||
|
return targetNode;
|
||||||
|
}
|
||||||
|
|
||||||
Iterator<Map.Entry<String, JsonNode>> srcItr = srcNode.fields();
|
return srcNode;
|
||||||
while (srcItr.hasNext()) {
|
}
|
||||||
|
|
||||||
Map.Entry<String, JsonNode> entry = srcItr.next();
|
/**
|
||||||
|
* Merge.
|
||||||
|
*
|
||||||
|
* @param srcNode the src node
|
||||||
|
* @param targetNode the target node
|
||||||
|
* @param option the option
|
||||||
|
* @return the object node
|
||||||
|
*/
|
||||||
|
public static ObjectNode merge(ObjectNode srcNode, ObjectNode targetNode, MERGE_OPTION option) {
|
||||||
|
|
||||||
// check key in src json exists in target json or not at same level
|
ObjectNode result = OBJECT_MAPPER.createObjectNode();
|
||||||
if (targetNode.has(entry.getKey())) {
|
|
||||||
result.set(entry.getKey(), merge(entry.getValue(), targetNode.get(entry.getKey())));
|
|
||||||
} else {
|
|
||||||
// if key in src json doesn't exist in target json, just copy the same in result
|
|
||||||
result.set(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy fields from target json into result which were missing in src json
|
Iterator<Map.Entry<String, JsonNode>> srcItr = srcNode.fields();
|
||||||
Iterator<Map.Entry<String, JsonNode>> targetItr = targetNode.fields();
|
while (srcItr.hasNext()) {
|
||||||
while (targetItr.hasNext()) {
|
|
||||||
Map.Entry<String, JsonNode> entry = targetItr.next();
|
|
||||||
if (!result.has(entry.getKey())) {
|
|
||||||
result.set(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayNode merge(ArrayNode srcNode, ArrayNode targetNode) {
|
Map.Entry<String, JsonNode> entry = srcItr.next();
|
||||||
ArrayNode result = OBJECT_MAPPER.createArrayNode();
|
|
||||||
return result.addAll(srcNode).addAll(targetNode);
|
// check key in src json exists in target json or not at same level
|
||||||
}
|
if (targetNode.has(entry.getKey())) {
|
||||||
|
result.set(entry.getKey(), merge(entry.getValue(), targetNode.get(entry.getKey()), option));
|
||||||
|
} else {
|
||||||
|
// if key in src json doesn't exist in target json, just copy the same in result
|
||||||
|
result.set(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy fields from target json into result which were missing in src json
|
||||||
|
Iterator<Map.Entry<String, JsonNode>> targetItr = targetNode.fields();
|
||||||
|
while (targetItr.hasNext()) {
|
||||||
|
Map.Entry<String, JsonNode> entry = targetItr.next();
|
||||||
|
if (!result.has(entry.getKey())) {
|
||||||
|
result.set(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge.
|
||||||
|
*
|
||||||
|
* @param srcNode the src node
|
||||||
|
* @param targetNode the target node
|
||||||
|
* @param option the option
|
||||||
|
* @return the array node
|
||||||
|
*/
|
||||||
|
public static ArrayNode mergeArray(ArrayNode srcNode, ArrayNode targetNode, MERGE_OPTION option) {
|
||||||
|
ArrayNode result = OBJECT_MAPPER.createArrayNode();
|
||||||
|
|
||||||
|
switch (option) {
|
||||||
|
case REPLACE:
|
||||||
|
//Replacing source json value as result
|
||||||
|
return result.addAll(srcNode);
|
||||||
|
//return result.addAll(srcNode).addAll(targetNode);
|
||||||
|
default:
|
||||||
|
return mergeSet(srcNode, targetNode);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Added by Francesco Mangiacrapa Merge set.
|
||||||
|
*
|
||||||
|
* @param srcNode the src node
|
||||||
|
* @param targetNode the target node
|
||||||
|
* @return the array node
|
||||||
|
*/
|
||||||
|
public static ArrayNode mergeSet(ArrayNode srcNode, ArrayNode targetNode) {
|
||||||
|
ArrayNode result = OBJECT_MAPPER.createArrayNode();
|
||||||
|
|
||||||
|
HashSet<JsonNode> set = new HashSet<>();
|
||||||
|
|
||||||
|
set = toHashSet(set, srcNode);
|
||||||
|
set = toHashSet(set, targetNode);
|
||||||
|
|
||||||
|
Iterator<JsonNode> itr = set.iterator();
|
||||||
|
while (itr != null && itr.hasNext()) {
|
||||||
|
JsonNode arrayValue = itr.next();
|
||||||
|
result.add(arrayValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To hash set.
|
||||||
|
*
|
||||||
|
* @param set the set
|
||||||
|
* @param srcNode the src node
|
||||||
|
* @return the hash set
|
||||||
|
*/
|
||||||
|
public static HashSet<JsonNode> toHashSet(HashSet<JsonNode> set, ArrayNode srcNode) {
|
||||||
|
if (srcNode != null) {
|
||||||
|
Iterator<JsonNode> itr = srcNode.elements();
|
||||||
|
while (itr != null && itr.hasNext()) {
|
||||||
|
JsonNode arrayValue = itr.next();
|
||||||
|
set.add(arrayValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -100,6 +100,9 @@ h1 {
|
||||||
max-height: 700px !important;
|
max-height: 700px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.modal-body-edit {
|
||||||
|
max-height: none !important;
|
||||||
|
}
|
||||||
.disable-div {
|
.disable-div {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,9 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.geoportal.client.utils.Serialization;
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||||
|
@ -41,11 +38,11 @@ import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON;
|
import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON.JSONObjectOrdered;
|
import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON.JSONObjectOrdered;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge;
|
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge;
|
||||||
|
import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge.MERGE_OPTION;
|
||||||
import org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl;
|
import org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl;
|
||||||
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
|
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
|
||||||
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper;
|
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -54,7 +51,6 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.jayway.jsonpath.Configuration;
|
import com.jayway.jsonpath.Configuration;
|
||||||
|
@ -177,7 +173,7 @@ public class Complex_Tests {
|
||||||
targetSectionJObject.put("titolo", "Prova REJECT abstract relazione di scavo 1");
|
targetSectionJObject.put("titolo", "Prova REJECT abstract relazione di scavo 1");
|
||||||
LOG.info("targetSectionJObject: {}", targetSectionJObject.toString());
|
LOG.info("targetSectionJObject: {}", targetSectionJObject.toString());
|
||||||
|
|
||||||
String mergedDoc = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString());
|
String mergedDoc = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString(), MERGE_OPTION.REPLACE);
|
||||||
LOG.info("output: {}", mergedDoc);
|
LOG.info("output: {}", mergedDoc);
|
||||||
|
|
||||||
String newDocJson;
|
String newDocJson;
|
||||||
|
@ -232,7 +228,7 @@ public class Complex_Tests {
|
||||||
// JSONObject mergedSection = FormDataObjectToJSON.deepMerge(sourceSectionObject,
|
// JSONObject mergedSection = FormDataObjectToJSON.deepMerge(sourceSectionObject,
|
||||||
// targetSectionJObject);
|
// targetSectionJObject);
|
||||||
|
|
||||||
String output = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString());
|
String output = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString(), MERGE_OPTION.REPLACE);
|
||||||
LOG.info("output: {}", output);
|
LOG.info("output: {}", output);
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
|
|
Loading…
Reference in New Issue