Added method get Access from the Document

This commit is contained in:
Francesco Mangiacrapa 2023-02-03 11:40:56 +01:00
parent 2ef9a4fa8c
commit 2fb4767205
3 changed files with 84 additions and 7 deletions

View File

@ -4,11 +4,12 @@
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-02
## [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

View File

@ -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;
}
}

View File

@ -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.
*
@ -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;