diff --git a/CHANGELOG.md b/CHANGELOG.md
index bcb74d1..caa7834 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,13 @@
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.2-SNAPSHOT] - 2022-02-03
+
+#### Enhancements
+
+- [#24432] Reverted serialization from Sting to Object values returning the Document as Map
+- [#24475] Propagated the Access Policy in the fileset
+
## [v2.0.1] - 2022-01-19
#### Bug fixes
diff --git a/pom.xml b/pom.xml
index 438b614..1e565a7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.gcube.application
geoportal-data-common
- 2.0.1
+ 2.0.2-SNAPSHOT
GeoPortal Data Common is common library used by GUI components developed for GeoNA
diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataServiceModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataServiceModel.java
new file mode 100644
index 0000000..779a39d
--- /dev/null
+++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataServiceModel.java
@@ -0,0 +1,71 @@
+package org.gcube.application.geoportalcommon;
+
+import org.gcube.application.geoportal.common.model.document.access.Access;
+import org.gcube.application.geoportal.common.model.document.access.AccessPolicy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
+
+/**
+ * The Class ConvertToDataServiceModel.
+ *
+ * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
+ *
+ * Feb 3, 2023
+ */
+public class ConvertToDataServiceModel {
+
+ private static Logger LOG = LoggerFactory.getLogger(ConvertToDataServiceModel.class);
+
+ /**
+ * Gets the access from document section.
+ *
+ * @param theJSONDocument the the JSON document
+ * @param sectionJSONPath the section JSON path
+ * @return the access from document section
+ */
+ public static Access getAccessFromDocumentSection(String theJSONDocument, String sectionJSONPath) {
+ String accessPolicyPath = String.format("%s.%s", sectionJSONPath, ConvertToDataValueObjectModel.POLICY);
+
+ AccessPolicy accessPolicy = null;
+ com.jayway.jsonpath.Configuration config = com.jayway.jsonpath.Configuration.builder()
+ .jsonProvider(new JsonOrgJsonProvider()).build();
+
+ // Reading policy fields
+ try {
+ JsonPath theSectionPolycJsonPath = JsonPath.compile(accessPolicyPath);
+ String policy = theSectionPolycJsonPath.read(theJSONDocument, config).toString();
+ LOG.debug("Read " + ConvertToDataValueObjectModel.POLICY + ": " + policy + ", from section: "
+ + accessPolicyPath);
+ if (policy != null) {
+ accessPolicy = AccessPolicy.valueOf(policy.toUpperCase());
+ }
+ } catch (Exception e) {
+ LOG.info("No " + ConvertToDataValueObjectModel.POLICY + " found in the path: " + accessPolicyPath);
+ }
+
+ // Reading policy fields
+ String licenseIDPath = String.format("%s.%s", sectionJSONPath, ConvertToDataValueObjectModel.LICENSE_ID);
+ String licenseID = null;
+ try {
+ JsonPath theSectionLicenseJsonPath = JsonPath.compile(licenseIDPath);
+ licenseID = theSectionLicenseJsonPath.read(theJSONDocument, config).toString();
+ LOG.debug("Read " + ConvertToDataValueObjectModel.LICENSE_ID + ": " + licenseID + ", from section: "
+ + licenseIDPath);
+ } catch (Exception e) {
+ LOG.info("No " + ConvertToDataValueObjectModel.LICENSE_ID + " found in the path: " + licenseIDPath);
+ }
+
+ Access access = new Access();
+ if (accessPolicy != null)
+ access.setPolicy(accessPolicy);
+ if (licenseID != null)
+ access.setLicense(licenseID);
+
+ LOG.info("Access is: " + access.getPolicy() + " / " + access.getLicense());
+ return access;
+ }
+
+}
diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java
index 7023d7a..9610900 100644
--- a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java
+++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java
@@ -101,6 +101,10 @@ public class ConvertToDataValueObjectModel {
public static List KEYSET_POSSIBLE_DATE = Arrays.asList("start", "end", "created", "updated", "inizio",
"fine", "creato", "aggiornato");
+ public static String LICENSE_ID = "licenseID";
+
+ public static String POLICY = "policy";
+
/**
* To use case descriptor DV.
*
@@ -867,7 +871,7 @@ public class ConvertToDataValueObjectModel {
}
if (listDocumentKeys != null && !getFullMap) {
- LinkedHashMap documentAsMap = new LinkedHashMap(listDocumentKeys.size());
+ LinkedHashMap documentAsMap = new LinkedHashMap(listDocumentKeys.size());
for (String key : listDocumentKeys) {
documentAsMap = fillMapValue(document, key, documentAsMap);
@@ -877,7 +881,7 @@ public class ConvertToDataValueObjectModel {
if (getFullMap) {
Set keySet = document.keySet();
- LinkedHashMap documentAsMap = new LinkedHashMap(keySet.size());
+ LinkedHashMap documentAsMap = new LinkedHashMap(keySet.size());
for (String key : keySet) {
// documentAsMap.put(key, document.get(key));
documentAsMap = fillMapValue(document, key, documentAsMap);
@@ -979,8 +983,8 @@ public class ConvertToDataValueObjectModel {
* @param documentAsMap the document as map
* @return the linked hash map
*/
- public static LinkedHashMap fillMapValue(Document document, String key,
- LinkedHashMap documentAsMap) {
+ public static LinkedHashMap fillMapValue(Document document, String key,
+ LinkedHashMap documentAsMap) {
Object value = document.get(key);
String keyLower = key.toLowerCase();
@@ -1000,7 +1004,7 @@ public class ConvertToDataValueObjectModel {
}
}
- documentAsMap.put(key, value!=null?value.toString():null);
+ documentAsMap.put(key, value);
return documentAsMap;
}
@@ -1242,7 +1246,7 @@ public class ConvertToDataValueObjectModel {
* @param targetProjectID the target project ID
* @param relationName the relation name
* @return the JSON object
- * @throws JSONException
+ * @throws JSONException
*/
public static JSONObject toTimelineJSONModel(Project theProject, JSONObject sourceJsonTemplate, String targetUCD,
String targetProjectID, String relationName) throws JSONException {
@@ -1259,7 +1263,7 @@ public class ConvertToDataValueObjectModel {
targetJsonObject.put("relationship_name", relationName);
Iterator itKeys = sourceJsonTemplate.keys();
- if(itKeys!=null) {
+ if (itKeys != null) {
while (itKeys.hasNext()) {
Object key = itKeys.next();
String jsonPath = null;
@@ -1279,10 +1283,10 @@ public class ConvertToDataValueObjectModel {
} catch (Exception e) {
LOG.trace("Error on setting key: {}, path: {}", theKey, jsonPath);
}
-
+
}
}
-
+
return targetJsonObject;
}
@@ -1293,9 +1297,10 @@ public class ConvertToDataValueObjectModel {
* @param theProject the the project
* @param timelineJSONObject the timeline JSON object
* @return the temporal reference DV
- * @throws JSONException
+ * @throws JSONException
*/
- public static TemporalReferenceDV toTemporalReferenceDV(Project theProject, JSONObject timelineJSONObject) throws JSONException {
+ public static TemporalReferenceDV toTemporalReferenceDV(Project theProject, JSONObject timelineJSONObject)
+ throws JSONException {
TemporalReferenceDV tr = null;
diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/DocumentDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/DocumentDV.java
index 771b6f9..4c845f2 100644
--- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/DocumentDV.java
+++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/DocumentDV.java
@@ -10,7 +10,7 @@ public class DocumentDV implements Serializable {
*
*/
private static final long serialVersionUID = 4978517506036855883L;
- protected LinkedHashMap documentAsMap;
+ protected LinkedHashMap documentAsMap;
private String documentAsJSON;
private ConfigurationDV> configuration;
@@ -19,11 +19,11 @@ public class DocumentDV implements Serializable {
public DocumentDV() {
}
- public LinkedHashMap getDocumentAsMap() {
+ public LinkedHashMap getDocumentAsMap() {
return documentAsMap;
}
- public Entry getFirstEntryOfMap() {
+ public Entry getFirstEntryOfMap() {
if (documentAsMap != null && documentAsMap.size() >= 1) {
return documentAsMap.entrySet().iterator().next();
}
@@ -43,7 +43,7 @@ public class DocumentDV implements Serializable {
return documentAsJSON;
}
- public void setDocumentAsMap(LinkedHashMap documentAsMap) {
+ public void setDocumentAsMap(LinkedHashMap documentAsMap) {
this.documentAsMap = documentAsMap;
}
diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java
index 959c8c3..e463d98 100644
--- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java
+++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ResultDocumentDV.java
@@ -49,9 +49,9 @@ public class ResultDocumentDV extends DocumentDV implements Serializable {
public void addItemToMap(String property, Object value) {
if (documentAsMap == null)
- documentAsMap = new LinkedHashMap();
+ documentAsMap = new LinkedHashMap();
- documentAsMap.put(property, value!=null?value.toString():null);
+ documentAsMap.put(property, value);
}
public BasicLifecycleInformationDV getLifecycleInfo() {
diff --git a/src/test/java/org/gcube/application/Project_Tests.java b/src/test/java/org/gcube/application/Project_Tests.java
index 94b3ac8..c4b8414 100644
--- a/src/test/java/org/gcube/application/Project_Tests.java
+++ b/src/test/java/org/gcube/application/Project_Tests.java
@@ -80,7 +80,7 @@ public class Project_Tests {
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
System.out.println(projectDV);
- LinkedHashMap theMap = projectDV.getTheDocument().getDocumentAsMap();
+ LinkedHashMap theMap = projectDV.getTheDocument().getDocumentAsMap();
for (String key : theMap.keySet()) {
Object theValue = theMap.get(key);
System.out.println("The key: " + key + " has value: " + theValue);