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.
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

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.application</groupId>
<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>
<scm>
@ -88,7 +88,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
<version>20090211</version>
<scope>compile</scope>
</dependency>

View File

@ -1242,9 +1242,10 @@ public class ConvertToDataValueObjectModel {
* @param targetProjectID the target project ID
* @param relationName the relation name
* @return the JSON object
* @throws JSONException
*/
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()
.addOptions(Option.ALWAYS_RETURN_LIST);
@ -1257,25 +1258,50 @@ public class ConvertToDataValueObjectModel {
if (relationName != null)
targetJsonObject.put("relationship_name", relationName);
for (Object key : sourceJsonTemplate.keySet()) {
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) + ", ";
Iterator itKeys = sourceJsonTemplate.keys();
if(itKeys!=null) {
while (itKeys.hasNext()) {
Object key = itKeys.next();
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);
}
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;
@ -1287,8 +1313,9 @@ public class ConvertToDataValueObjectModel {
* @param theProject the the project
* @param timelineJSONObject the timeline JSON object
* @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;