Fixing JSON library v20090211 (see #24263#note-1). New version is

2.0.1-SNAPSHOT
This commit is contained in:
Francesco Mangiacrapa 2022-12-13 14:23:04 +01:00
parent 265dfaec22
commit a54747c5ac
3 changed files with 50 additions and 20 deletions

View File

@ -4,6 +4,9 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.0.1-SNAPSHOT] - 2022-12-13
- [#24263] Fixing JSON library v20090211
## [v2.0.0] - 2022-11-17 ## [v2.0.0] - 2022-11-17

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.application</groupId> <groupId>org.gcube.application</groupId>
<artifactId>geoportal-data-common</artifactId> <artifactId>geoportal-data-common</artifactId>
<version>2.0.0</version> <version>2.0.1-SNAPSHOT</version>
<description>GeoPortal Data Common is common library used by GUI components developed for GeoNA</description> <description>GeoPortal Data Common is common library used by GUI components developed for GeoNA</description>
<scm> <scm>
@ -88,7 +88,7 @@
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20140107</version> <version>20090211</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>

View File

@ -1242,9 +1242,10 @@ public class ConvertToDataValueObjectModel {
* @param targetProjectID the target project ID * @param targetProjectID the target project ID
* @param relationName the relation name * @param relationName the relation name
* @return the JSON object * @return the JSON object
* @throws JSONException
*/ */
public static JSONObject toTimelineJSONModel(Project theProject, JSONObject sourceJsonTemplate, String targetUCD, public static JSONObject toTimelineJSONModel(Project theProject, JSONObject sourceJsonTemplate, String targetUCD,
String targetProjectID, String relationName) { String targetProjectID, String relationName) throws JSONException {
com.jayway.jsonpath.Configuration jsonPathConfig = com.jayway.jsonpath.Configuration.defaultConfiguration() com.jayway.jsonpath.Configuration jsonPathConfig = com.jayway.jsonpath.Configuration.defaultConfiguration()
.addOptions(Option.ALWAYS_RETURN_LIST); .addOptions(Option.ALWAYS_RETURN_LIST);
@ -1257,25 +1258,50 @@ public class ConvertToDataValueObjectModel {
if (relationName != null) if (relationName != null)
targetJsonObject.put("relationship_name", relationName); targetJsonObject.put("relationship_name", relationName);
for (Object key : sourceJsonTemplate.keySet()) { Iterator itKeys = sourceJsonTemplate.keys();
String jsonPath = null; if(itKeys!=null) {
String theKey = null; while (itKeys.hasNext()) {
try { Object key = itKeys.next();
theKey = key + ""; String jsonPath = null;
LOG.debug("Searching key: " + theKey); String theKey = null;
jsonPath = sourceJsonTemplate.getString(theKey); try {
LOG.debug("with key: " + theKey + " read JSON path: " + jsonPath); theKey = key + "";
List<String> listValue = targetDoc.read(jsonPath); LOG.debug("Searching key: " + theKey);
String result = ""; jsonPath = sourceJsonTemplate.getString(theKey);
for (int i = 0; i < listValue.size() - 1; i++) { LOG.debug("with key: " + theKey + " read JSON path: " + jsonPath);
result += listValue.get(i) + ", "; List<String> listValue = targetDoc.read(jsonPath);
String result = "";
for (int i = 0; i < listValue.size() - 1; i++) {
result += listValue.get(i) + ", ";
}
result += listValue.get(listValue.size() - 1);
targetJsonObject.put(theKey, result);
} catch (Exception e) {
LOG.trace("Error on setting key: {}, path: {}", theKey, jsonPath);
} }
result += listValue.get(listValue.size() - 1);
targetJsonObject.put(theKey, result);
} catch (Exception e) {
LOG.trace("Error on setting key: {}, path: {}", theKey, jsonPath);
} }
} }
// for (Object key : sourceJsonTemplate.keys()) {
// String jsonPath = null;
// String theKey = null;
// try {
// theKey = key + "";
// LOG.debug("Searching key: " + theKey);
// jsonPath = sourceJsonTemplate.getString(theKey);
// LOG.debug("with key: " + theKey + " read JSON path: " + jsonPath);
// List<String> listValue = targetDoc.read(jsonPath);
// String result = "";
// for (int i = 0; i < listValue.size() - 1; i++) {
// result += listValue.get(i) + ", ";
// }
// result += listValue.get(listValue.size() - 1);
// targetJsonObject.put(theKey, result);
// } catch (Exception e) {
// LOG.trace("Error on setting key: {}, path: {}", theKey, jsonPath);
// }
// }
return targetJsonObject; return targetJsonObject;
@ -1287,8 +1313,9 @@ public class ConvertToDataValueObjectModel {
* @param theProject the the project * @param theProject the the project
* @param timelineJSONObject the timeline JSON object * @param timelineJSONObject the timeline JSON object
* @return the temporal reference DV * @return the temporal reference DV
* @throws JSONException
*/ */
public static TemporalReferenceDV toTemporalReferenceDV(Project theProject, JSONObject timelineJSONObject) { public static TemporalReferenceDV toTemporalReferenceDV(Project theProject, JSONObject timelineJSONObject) throws JSONException {
TemporalReferenceDV tr = null; TemporalReferenceDV tr = null;