Merge pull request 'task_24532' (#6) from task_24532 into master
Reviewed-on: #6
This commit is contained in:
commit
999d201737
|
@ -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
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>org.gcube.application</groupId>
|
||||
<artifactId>geoportal-data-common</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<description>GeoPortal Data Common is common library used by GUI components developed for GeoNA</description>
|
||||
|
||||
<scm>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -101,6 +101,10 @@ public class ConvertToDataValueObjectModel {
|
|||
public static List<String> 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<String, String> documentAsMap = new LinkedHashMap<String, String>(listDocumentKeys.size());
|
||||
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(listDocumentKeys.size());
|
||||
for (String key : listDocumentKeys) {
|
||||
|
||||
documentAsMap = fillMapValue(document, key, documentAsMap);
|
||||
|
@ -877,7 +881,7 @@ public class ConvertToDataValueObjectModel {
|
|||
|
||||
if (getFullMap) {
|
||||
Set<String> keySet = document.keySet();
|
||||
LinkedHashMap<String, String> documentAsMap = new LinkedHashMap<String, String>(keySet.size());
|
||||
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(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<String, String> fillMapValue(Document document, String key,
|
||||
LinkedHashMap<String, String> documentAsMap) {
|
||||
public static LinkedHashMap<String, Object> fillMapValue(Document document, String key,
|
||||
LinkedHashMap<String, Object> 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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1295,7 +1299,8 @@ public class ConvertToDataValueObjectModel {
|
|||
* @return the temporal reference DV
|
||||
* @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;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ public class DocumentDV implements Serializable {
|
|||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4978517506036855883L;
|
||||
protected LinkedHashMap<String, String> documentAsMap;
|
||||
protected LinkedHashMap<String, Object> documentAsMap;
|
||||
private String documentAsJSON;
|
||||
private ConfigurationDV<?> configuration;
|
||||
|
||||
|
@ -19,11 +19,11 @@ public class DocumentDV implements Serializable {
|
|||
public DocumentDV() {
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, String> getDocumentAsMap() {
|
||||
public LinkedHashMap<String, Object> getDocumentAsMap() {
|
||||
return documentAsMap;
|
||||
}
|
||||
|
||||
public Entry<String, String> getFirstEntryOfMap() {
|
||||
public Entry<String, Object> 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<String, String> documentAsMap) {
|
||||
public void setDocumentAsMap(LinkedHashMap<String, Object> documentAsMap) {
|
||||
this.documentAsMap = documentAsMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,9 +49,9 @@ public class ResultDocumentDV extends DocumentDV implements Serializable {
|
|||
public void addItemToMap(String property, Object value) {
|
||||
|
||||
if (documentAsMap == null)
|
||||
documentAsMap = new LinkedHashMap<String, String>();
|
||||
documentAsMap = new LinkedHashMap<String, Object>();
|
||||
|
||||
documentAsMap.put(property, value!=null?value.toString():null);
|
||||
documentAsMap.put(property, value);
|
||||
}
|
||||
|
||||
public BasicLifecycleInformationDV getLifecycleInfo() {
|
||||
|
|
|
@ -80,7 +80,7 @@ public class Project_Tests {
|
|||
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
|
||||
System.out.println(projectDV);
|
||||
|
||||
LinkedHashMap<String, String> theMap = projectDV.getTheDocument().getDocumentAsMap();
|
||||
LinkedHashMap<String, Object> theMap = projectDV.getTheDocument().getDocumentAsMap();
|
||||
for (String key : theMap.keySet()) {
|
||||
Object theValue = theMap.get(key);
|
||||
System.out.println("The key: " + key + " has value: " + theValue);
|
||||
|
|
Loading…
Reference in New Issue