From a54747c5ac3fd01c7011b5712fb9b0de2291fcb7 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 13 Dec 2022 14:23:04 +0100 Subject: [PATCH] Fixing JSON library v20090211 (see #24263#note-1). New version is 2.0.1-SNAPSHOT --- CHANGELOG.md | 3 + pom.xml | 4 +- .../ConvertToDataValueObjectModel.java | 63 +++++++++++++------ 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42f584e..7686626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pom.xml b/pom.xml index 7e08e2e..22241c7 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.application geoportal-data-common - 2.0.0 + 2.0.1-SNAPSHOT GeoPortal Data Common is common library used by GUI components developed for GeoNA @@ -88,7 +88,7 @@ org.json json - 20140107 + 20090211 compile diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java index a609d57..6de23f7 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java +++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java @@ -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 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 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 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;