diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index b0ea40a..ebcf40f 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,8 @@ - + + + + @@ -96,7 +99,10 @@ - + + + + @@ -193,7 +199,10 @@ - + + + + @@ -290,7 +299,10 @@ - + + + + @@ -387,7 +399,10 @@ - + + + + @@ -445,10 +460,10 @@ uses - - uses - - + + + + @@ -545,7 +560,10 @@ - + + + + @@ -642,7 +660,10 @@ - + + + + @@ -739,7 +760,10 @@ - + + + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/FormDataObjectToJSON.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/FormDataObjectToJSON.java index 7b6201e..d38362e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/FormDataObjectToJSON.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/FormDataObjectToJSON.java @@ -47,7 +47,7 @@ public class FormDataObjectToJSON { // the root, instancing new json document if (tree_Node.isRoot()) { - theRootDocument = JSONObjecOrdered.instance(); + theRootDocument = JSONObjectOrdered.instance(); } Configuration configuration = Configuration.builder().jsonProvider(new JsonOrgJsonProvider()).build(); @@ -163,7 +163,7 @@ public class FormDataObjectToJSON { */ protected JSONObject genericDatasetBeanToJSON(GenericDatasetBean gdb) throws JSONException { - JSONObject sectJSONObject = JSONObjecOrdered.instance(); + JSONObject sectJSONObject = JSONObjectOrdered.instance(); LinkedHashMap> mapFields = gdb.getFormDataEntryFields(); LOG.debug("Map ordered: " + mapFields); @@ -246,7 +246,7 @@ public class FormDataObjectToJSON { * * Mar 10, 2022 */ - public static class JSONObjecOrdered { + public static class JSONObjectOrdered { /** * Instance. 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 6153979..1bdf275 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 @@ -5,7 +5,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; -import java.lang.reflect.Type; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -18,7 +17,6 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -67,7 +65,7 @@ import org.gcube.common.portal.PortalContext; import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException; import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService; import org.gcube.portlets.user.geoportaldataentry.client.ProjectFormCard; -import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON.JSONObjecOrdered; +import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtendedConfigProfile; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; @@ -87,13 +85,13 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.gson.internal.LinkedTreeMap; -import com.google.gson.reflect.TypeToken; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.jayway.jsonpath.Configuration; +import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.spi.json.GsonJsonProvider; -import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider; /** * The server side implementation of the RPC service. @@ -248,46 +246,57 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen // Converter FormDataObjectToJSON metadataConverter = new FormDataObjectToJSON(); // JSON Section to update converted as JSONObject - JSONObject jsonSectionObject = metadataConverter.genericDatasetBeanToJSON(sectionBean); - LOG.info("Json Section Object: {}", jsonSectionObject.toString()); - - Configuration configuration = Configuration.builder().jsonProvider(new GsonJsonProvider()).build(); + JSONObject updatedSectionObject = metadataConverter.genericDatasetBeanToJSON(sectionBean); + LOG.info("Input Json Section (to update): {}", updatedSectionObject.toString()); + + Configuration configurationGson = Configuration.builder().jsonProvider(new GsonJsonProvider()).build(); // Type type = new TypeToken>>() {}.getType(); // Set> myMap = gson.fromJson(json, type); // Source Project - String jsonSourceProject = getJSONDocumentInTheProject(profileID, projectID); - LOG.info("Json source Object: {}", jsonSourceProject); - - //If the section path is the Root document, passed as "$.", fixing as "$" - if(sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER+".")==0) + String theDocumentJson = getJSONDocumentInTheProject(profileID, projectID); + LOG.info("Source document: {}", theDocumentJson); + + // If the section path is the Root document, passed as "$.", fixing as "$" + if (sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER + ".") == 0) sectionPath = FormDataObjectToJSON.JSON_$_POINTER; - + ProjectsCaller client = GeoportalClientCaller.projects(); - - JSONObject currentSectionJObject = JsonPath.parse(jsonSourceProject, configuration).read(sectionPath); - LOG.info("currentSectionJObject: {}", currentSectionJObject.toString()); + com.google.gson.JsonObject targetSectionJObject = JsonPath.parse(theDocumentJson, configurationGson) + .read(sectionPath); + LOG.info("Current Section path {} in the Document is {}", sectionPath, targetSectionJObject.toString()); + String srcJ = updatedSectionObject.toString(); + String trgJ = targetSectionJObject.toString(); + LOG.info("Merging src {} in the target: {}", srcJ, trgJ); + String mergedDoc = JsonMerge.merge(srcJ, trgJ); + LOG.info("mergedDoc: {}", mergedDoc); - // Merged section between updated and current - JSONObject mergedSection = JSONObjecOrdered.instance(); - mergedSection = FormDataObjectToJSON.deepMerge(jsonSectionObject, - currentSectionJObject); - - LOG.info("Merged section: {}", mergedSection.toString()); + String newDocJson; + // If Updating path is first level of the root + if (sectionPath.equals(FormDataObjectToJSON.JSON_$_POINTER)) { + // The merged DOC is the root Document, no action required + newDocJson = mergedDoc; + } else { + // If the merged DOC is a child of the root Document, setting it as child of the + // Document in the proper section + Gson gson = new Gson(); + JsonObject gsonOject = gson.fromJson(mergedDoc, JsonObject.class); + // Putting the merged section into Document + DocumentContext newContextDocJson = JsonPath.parse(theDocumentJson, configurationGson).set(sectionPath, + gsonOject); + newDocJson = newContextDocJson.json().toString(); - // Putting the merged section into Document - Object newDocument = JsonPath.parse(jsonSourceProject, configuration).set(sectionPath, mergedSection) - .json(); - - String newDocumentString = newDocument.toString(); - LOG.debug("Going to call updateProject with document: {}", newDocumentString); + } + + Document updatedDocument = Serialization.read(newDocJson.toString(), Document.class); + LOG.info("New document is: {}", updatedDocument.toJson()); - Document updatedDocument = Serialization.read(newDocumentString, Document.class); Project project = client.updateProject(profileID, projectID, updatedDocument); LOG.debug("Medatata Updated with document: {}", project.getTheDocument()); - + SessionUtil.getCurrentContext(getThreadLocalRequest(), true); + //Cleaning all the fileset path of the section (defined in the UCD) for (FilePathDV filePath: listFilePaths) { @@ -308,7 +317,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen LOG.info("Project with id " + project.getId() + " updated correclty"); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); ProjectDV toProjectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder); - newDocumentString = toProjectDV.getTheDocument().getDocumentAsJSON(); + String newDocumentString = toProjectDV.getTheDocument().getDocumentAsJSON(); LOG.info("Got Document: {} ", newDocumentString); return new CommitReport(projectID, profileID, newDocumentString, null); } catch (Exception e) { @@ -526,7 +535,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen input = new File(file.getTempSystemPath()); output = new File(tmpDirPath, file.getFileName()); copyContent(input, output); - LOG.info("Temp file: " + file.getTempSystemPath() + ", copied to new file: " + output.getName()); + LOG.info( + "Temp file: " + file.getTempSystemPath() + ", copied to new file: " + output.getName()); } collFieldDef.addFile(output); @@ -551,10 +561,10 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen File[] fileset = uploadedFileset.getFileset(); FilePathDV filePath = uploadedFileset.getFilePathDV(); Access access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument, sectionJSONPath); - - LOG.info("Going to registrer files: "+Arrays.asList(fileset).toString()); - mongoService.registerFileSet(theProject.getProfileID(), theProject, sectionJSONPath, - filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset); + + LOG.info("Going to registrer files: " + Arrays.asList(fileset).toString()); +// mongoService.registerFileSet(theProject.getProfileID(), theProject, sectionJSONPath, +// filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset); } } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/json/JsonMerge.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/json/JsonMerge.java new file mode 100644 index 0000000..80a1189 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/json/JsonMerge.java @@ -0,0 +1,188 @@ +package org.gcube.portlets.user.geoportaldataentry.server.json; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Map; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * This class provides methods to merge two json of any nested level into a single json. + * + * copied from: https://github.com/hemantsonu20/json-merge + */ +public class JsonMerge { + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + /** + * Method to merge two json objects into single json object. + * + *

It merges two json of any nested level into a single json following below logic.

+ *
    + *
  • When keys are different, both keys with there values will be copied at same level.
  • + *
  • + *

    When keys are same at some level, following table denotes what value will be used.

    + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    Src / TargetJSON ValueJSON ArrayJSON Object
    JSON Value1SrcSrcSrc
    JSON ArraySrc2MergeSrc
    JSON ObjectSrcSrcMerge3
    + *
      + *
    • 1 Json Value denotes boolean, number or string value in json.
    • + *
    • 2 Src denotes Src value will be copied.
    • + *
    • 3 Merge denotes both Src and Target values will be merged.
    • + *
    + *
  • + *
+ * + *

Examples

+ *

Example 1

+ *

Source Json

+ *
{@code
+     * {
+     *   "name": "json-merge-src"
+     * }
+     * }
+ *

Target Json

+ *
{@code
+     * {
+     *   "name": "json-merge-target"
+     * }
+     * }
+ *

Output

+ *
{@code
+     * {
+     *   "name": "json-merge-src"
+     * }
+     * }
+ *

Example 2

+ *

Source Json

+ *
{@code
+     * {
+     *   "level1": {
+     *     "key1": "SrcValue1"
+     *   }
+     * }
+     * }
+ *

Target Json

+ *
{@code
+     * {
+     *   "level1": {
+     *     "key1": "targetValue1",
+     *     "level2": {
+     *       "key2": "value2"
+     *     }
+     *   }
+     * }
+     * }
+ *

Output

+ *
{@code
+     * {
+     *   "level1": {
+     *     "key1": "SrcValue1",
+     *     "level2": {
+     *       "key2": "value2"
+     *     }
+     *   }
+     * }
+     * }
+ * + * @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); + JsonNode targetNode = OBJECT_MAPPER.readTree(targetJsonStr); + JsonNode result = merge(srcNode, targetNode); + return OBJECT_MAPPER.writeValueAsString(result); + } catch (IOException e) { + throw new JsonMergeException("Unable to merge json", e); + } + } + + public static JsonNode merge(JsonNode srcNode, JsonNode targetNode) { + + // if both nodes are object node, merged object node is returned + if (srcNode.isObject() && targetNode.isObject()) { + return merge((ObjectNode) srcNode, (ObjectNode) targetNode); + } + + // if both nodes are array node, merged array node is returned + if (srcNode.isArray() && targetNode.isArray()) { + return merge((ArrayNode) srcNode, (ArrayNode) targetNode); + } + + // special case when src node is null + if (srcNode.isNull()) { + return targetNode; + } + + return srcNode; + } + + public static ObjectNode merge(ObjectNode srcNode, ObjectNode targetNode) { + + ObjectNode result = OBJECT_MAPPER.createObjectNode(); + + Iterator> srcItr = srcNode.fields(); + while (srcItr.hasNext()) { + + Map.Entry entry = srcItr.next(); + + // 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()))); + } 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> targetItr = targetNode.fields(); + while (targetItr.hasNext()) { + Map.Entry entry = targetItr.next(); + if (!result.has(entry.getKey())) { + result.set(entry.getKey(), entry.getValue()); + } + } + return result; + } + + public static ArrayNode merge(ArrayNode srcNode, ArrayNode targetNode) { + ArrayNode result = OBJECT_MAPPER.createArrayNode(); + return result.addAll(srcNode).addAll(targetNode); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/json/JsonMergeException.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/json/JsonMergeException.java new file mode 100644 index 0000000..d3307e4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/json/JsonMergeException.java @@ -0,0 +1,20 @@ +package org.gcube.portlets.user.geoportaldataentry.server.json; + +/** + * Exception to be thrown in case of any error occured while merging two json. + * + */ +public class JsonMergeException extends RuntimeException { + + public JsonMergeException() { + super(); + } + + public JsonMergeException(String msg) { + super(msg); + } + + public JsonMergeException(String msg, Throwable th) { + super(msg, th); + } +} diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java index f259060..df9692f 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java @@ -1,9 +1,16 @@ package org.gcube.portlets.user.geoportaldataentry; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.Set; import org.bson.Document; import org.gcube.application.geoportal.client.utils.Serialization; @@ -31,10 +38,15 @@ import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView; import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON; +import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON.JSONObjectOrdered; +import org.gcube.portlets.user.geoportaldataentry.server.json.JsonMerge; 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.MetadataFieldWrapper; import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; @@ -42,19 +54,29 @@ import org.slf4j.LoggerFactory; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.jayway.jsonpath.Configuration; +import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.spi.json.GsonJsonProvider; import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider; public class Complex_Tests { + + private static final String GCUBE_CONFIG_PROPERTIES_FILENAME = "gcube_config.properties"; + // APP Working Directory + /src/test/resources must be the location of + // gcube_config.properties + private static String gcube_config_path = String.format("%s/%s", + System.getProperty("user.dir") + "/src/test/resources", GCUBE_CONFIG_PROPERTIES_FILENAME); + private static String CONTEXT; + private static String TOKEN; private UseCaseDescriptorCaller clientUCD = null; private ProjectsCaller clientPrj = null; - private static String CONTEXT = "/gcube/devsec/devVRE"; - private static String TOKEN = ""; // devVRE + private static String PROFILE_ID = "profiledConcessioni"; - private static String PROJECT_ID = "632c633155e2947b0278c999"; private static String MY_LOGIN = "francesco.mangiacrapa"; @@ -93,14 +115,141 @@ public class Complex_Tests { } } + + /** + * Read context settings. + */ + public static void readContextSettings() { - //@Before + try (InputStream input = new FileInputStream(gcube_config_path)) { + + Properties prop = new Properties(); + + // load a properties file + prop.load(input); + + CONTEXT = prop.getProperty("CONTEXT"); + TOKEN = prop.getProperty("TOKEN"); + // get the property value and print it out + System.out.println("CONTEXT: " + CONTEXT); + System.out.println("TOKEN: " + TOKEN); + + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + @Before public void init() { + readContextSettings(); ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); clientPrj = GeoportalClientCaller.projects(); clientUCD = GeoportalClientCaller.useCaseDescriptors(); } + + //@Test + public void testSectionPathInnerParse() throws Exception { + String sectionPath = "$.abstractRelazione"; + + String profileID = "profiledConcessioni"; + String projectID = "6425598a8593b215a1281e1c"; + + Configuration configurationGSON = Configuration.builder().jsonProvider(new GsonJsonProvider()).build(); + + ProjectsCaller client = GeoportalClientCaller.projects(); + + Project proejct = client.getProjectByID(profileID, projectID); + + String jsonSourceProject = proejct.getTheDocument().toJson(); + + //If the section path is the Root document, passed as "$.", fixing as "$" + if(sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER+".")==0) + sectionPath = FormDataObjectToJSON.JSON_$_POINTER; + + LOG.info("theString: {}", jsonSourceProject); + com.google.gson.JsonObject currentSectionJObject = JsonPath.parse(jsonSourceProject, configurationGSON).read(sectionPath); + LOG.info("currentSectionJObject: {}", currentSectionJObject.toString()); + LOG.info("sourceSectionObject: {}", currentSectionJObject.toString()); + + JSONObject targetSectionJObject = new JSONObjectOrdered().instance(); + targetSectionJObject.put("abstractIta", "Prova REJECT 1"); + targetSectionJObject.put("titolo", "Prova REJECT abstract relazione di scavo 1"); + LOG.info("targetSectionJObject: {}", targetSectionJObject.toString()); + + String mergedDoc = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString()); + LOG.info("output: {}", mergedDoc); + + String newDocJson; + //Updating path is first level of the root + if(sectionPath.equals(FormDataObjectToJSON.JSON_$_POINTER)) { + //The merged DOC is the root Document + newDocJson = mergedDoc; + }else { + //The merged DOC is a child of the root Document + Gson gson = new Gson(); + JsonObject gsonOject = gson.fromJson(mergedDoc, JsonObject.class); + // Putting the merged section into Document + DocumentContext newContextDocJson = JsonPath.parse(jsonSourceProject, configurationGSON).set(sectionPath, gsonOject); + newDocJson = newContextDocJson.json().toString(); + + } + + Document updatedDocument = Serialization.read(newDocJson.toString(), Document.class); + LOG.info("New document is: {}", updatedDocument.toJson()); + + } + + @Test + public void testSectionPathRootParse() throws Exception { + String sectionPath = "$."; + + String profileID = "profiledConcessioni"; + String projectID = "6425598a8593b215a1281e1c"; + + Configuration configurationGSON = Configuration.builder().jsonProvider(new GsonJsonProvider()).build(); + + ProjectsCaller client = GeoportalClientCaller.projects(); + + Project proejct = client.getProjectByID(profileID, projectID); + + String jsonSourceProject = proejct.getTheDocument().toJson(); + + //If the section path is the Root document, passed as "$.", fixing as "$" + if(sectionPath.compareTo(FormDataObjectToJSON.JSON_$_POINTER+".")==0) + sectionPath = FormDataObjectToJSON.JSON_$_POINTER; + + LOG.info("theString: {}", jsonSourceProject); + com.google.gson.JsonObject currentSectionJObject = JsonPath.parse(jsonSourceProject, configurationGSON).read(sectionPath); + LOG.info("currentSectionJObject: {}", currentSectionJObject.toString()); + LOG.info("sourceSectionObject: {}", currentSectionJObject.toString()); + + JSONObject targetSectionJObject = new JSONObjectOrdered().instance(); + targetSectionJObject.put("nome", proejct.getTheDocument().get("nome")+" 1"); + targetSectionJObject.put("titolo", proejct.getTheDocument().get("introduzione")+ " 1"); + LOG.info("targetSectionJObject: {}", targetSectionJObject.toString()); + +// JSONObject mergedSection = FormDataObjectToJSON.deepMerge(sourceSectionObject, +// targetSectionJObject); + + String output = JsonMerge.merge(targetSectionJObject.toString(), currentSectionJObject.toString()); + LOG.info("output: {}", output); + + Gson gson = new Gson(); + JsonObject gsonOject = gson.fromJson(output, JsonObject.class); + + // Putting the merged section into Document + DocumentContext newContextDocJson = JsonPath.parse(jsonSourceProject, configurationGSON).set(sectionPath, gsonOject); + //DocumentContext newDocument = JsonPath.parse(jsonSourceProject, configurationGSON).set(sectionPath, new JSONObject(output)); + //String newDocJson = JsonPath.parse(jsonSourceProject).set(sectionPath, new JSONObject(output)).jsonString(); + String newDocJson = newContextDocJson.json().toString(); + LOG.info("Going to call updateProject with document: {}", newDocJson); + + Document updatedDocument = Serialization.read(newDocJson.toString(), Document.class); + LOG.info("New document is: {}", updatedDocument.toJson()); + + } + //@Before public void preloadgCubeProfilesForUCDs() { @@ -295,7 +444,7 @@ public class Complex_Tests { String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName()); List listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON); FilesetDV filesetDV = new FilesetDV(); - filesetDV.setName(filePath.getGcubeProfileFieldName()); + filesetDV.setGcubeProfileFieldName(filePath.getGcubeProfileFieldName()); for (Payload payload : listPayloads) { PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload); filesetDV.addPayloadDV(payloadDV); @@ -330,7 +479,7 @@ public class Complex_Tests { System.out.println("***** Files"); if (subDocument.getListFiles() != null) { for (FilesetDV filesetDV : subDocument.getListFiles()) { - System.out.println("******* File Fileset name: " + filesetDV.getName()); + System.out.println("******* File Fileset name: " + filesetDV.getGcubeProfileFieldName()); for (PayloadDV payload : filesetDV.getListPayload()) { System.out.println("********* Payload: " + payload); } @@ -339,7 +488,7 @@ public class Complex_Tests { System.out.println("***** Images"); if (subDocument.getListImages() != null) { for (FilesetDV filesetDV : subDocument.getListImages()) { - System.out.println("******* Image Fileset name: " + filesetDV.getName()); + System.out.println("******* Image Fileset name: " + filesetDV.getGcubeProfileFieldName()); for (PayloadDV payload : filesetDV.getListPayload()) { System.out.println("********* Payload: " + payload); }