Francesco Mangiacrapa 2023-02-09 17:40:05 +01:00
parent 132891988a
commit f5a8e08b88
1 changed files with 74 additions and 20 deletions

View File

@ -55,6 +55,8 @@ public class Geoportal_JSON_Mapper {
public static final String _MATERIALIZATIONS = "_materializations";
public static final String _TYPE_GCUBE_SDI_LAYER = "gcube-sdi-layer";
private static final Logger LOG = LoggerFactory.getLogger(Geoportal_JSON_Mapper.class);
public static final String FILESET = "fileset";
@ -543,19 +545,36 @@ public class Geoportal_JSON_Mapper {
// Reading Fileset _payloads
String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName());
List<Payload> listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON);
FilesetDV filesetDV = new FilesetDV();
filesetDV.setName(filePath.getGcubeProfileFieldName());
if(LOG.isDebugEnabled()) {
for (Payload payload : listPayloads) {
LOG.debug("read payload: " + payload);
}
}
FilesetDV filesetImages = new FilesetDV();
FilesetDV filesetFiles = new FilesetDV();
for (Payload payload : listPayloads) {
PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload);
filesetDV.addPayloadDV(payloadDV);
//filesetDV.addPayloadDV(payloadDV);
boolean isImage = ImageDetector.isImage(payload.getMimetype());
if (isImage) {
listImages.add(filesetDV);
filesetImages.setName(filePath.getGcubeProfileFieldName());
filesetImages.addPayloadDV(payloadDV);
} else {
listFiles.add(filesetDV);
filesetFiles.addPayloadDV(payloadDV);
filesetFiles.setName(filePath.getGcubeProfileFieldName());
}
}
//Setting only if one element exists
if(filesetImages.getListPayload()!=null && filesetImages.getListPayload().size()>0) {
listImages.add(filesetImages);
}
if(filesetFiles.getListPayload()!=null && filesetFiles.getListPayload().size()>0) {
listFiles.add(filesetFiles);
}
// Reading Fileset _materializations
listLayers = readGcubeSDILayersForFileset(filesetJSONPath, fromSectionDocJSON);
@ -573,6 +592,7 @@ public class Geoportal_JSON_Mapper {
projectView.addSectionView(sectionView);
}
LOG.debug("returning the projectView: " + projectView);
return projectView;
}
@ -592,7 +612,7 @@ public class Geoportal_JSON_Mapper {
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build();
LOG.info("Reading sectionPath at {} into section document {}", _payloadsJSONPath, sectionJSONDocument);
LOG.debug("Reading sectionPath at {} into section document {}", _payloadsJSONPath, sectionJSONDocument);
JsonPath theSectionPolycJsonPath = JsonPath.compile(_payloadsJSONPath);
Object _payloads = theSectionPolycJsonPath.read(sectionJSONDocument, configuration).toString();
@ -632,7 +652,7 @@ public class Geoportal_JSON_Mapper {
.jsonProvider(new JsonOrgJsonProvider()).build();
// Reading Fileset _payloads
String filesetJSONPath = String.format("%s.%s", parentJSONPath, _PAYLOADS);
LOG.info("Reading sectionPath {} into section document {}", filesetJSONPath, sectionJSONDocument);
LOG.debug("Reading sectionPath {} into section document {}", filesetJSONPath, sectionJSONDocument);
JsonPath theSectionPolycJsonPath = JsonPath.compile(filesetJSONPath);
Object _filesets = theSectionPolycJsonPath.read(sectionJSONDocument, config);
@ -672,22 +692,27 @@ public class Geoportal_JSON_Mapper {
LOG.debug("readGcubeSDILayersForFileset called");
List<GCubeSDIViewerLayerDV> listSDILayers = new ArrayList<GCubeSDIViewerLayerDV>();
String _materializationsJSONPath = String.format("%s.%s", materializationParentJSONPath, _MATERIALIZATIONS);
// _materializations AT THE MOMENT ARE ONLY OF TYPE gcube-sdi-layer. I'm adding
// the filtering "_type": "gcube-sdi-layer" to be sure of reading SDI layer
String _materializationsJSONPath = String.format("%s.%s[?(@._type=='%s')]", materializationParentJSONPath,
_MATERIALIZATIONS, _TYPE_GCUBE_SDI_LAYER);
try {
com.jayway.jsonpath.Configuration configurationJSONSmart = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build();
LOG.info("Reading sectionPath {} into section document {}", _materializationsJSONPath, sectionJSONDocument);
JsonPath theSectionPolycJsonPath = JsonPath.compile(_materializationsJSONPath);
Object _materializations = theSectionPolycJsonPath.read(sectionJSONDocument, configurationJSONSmart);
LOG.debug("GcubeSDILayers Reading sectionPath {} into section document {}", _materializationsJSONPath,
sectionJSONDocument);
JsonPath theSectionMaterializationJsonPath = JsonPath.compile(_materializationsJSONPath);
Object _materializations = theSectionMaterializationJsonPath.read(sectionJSONDocument,
configurationJSONSmart);
LOG.trace("_materializations.class(): " + _materializations.getClass());
listSDILayers = recursiveFetchingLayers(configurationJSONSmart, _materializations, listSDILayers);
} catch (Exception e) {
LOG.warn("Error on reading the JSON Path " + _materializationsJSONPath + " in the doc "
LOG.info("Error on reading the JSON Path " + _materializationsJSONPath + " in the doc "
+ sectionJSONDocument, e);
}
LOG.info("returning list of layers {}", listSDILayers);
@ -854,23 +879,52 @@ public class Geoportal_JSON_Mapper {
* @return true, if successful
*/
private static boolean checkAccessPolicy(String sectionDocumentJSON, String myLogin) {
LOG.debug("checkAccessPolicy called");
LOG.info("checkAccessPolicy called");
// CHECKING THE POLICY
String accessPolicyPath = JSON_$_POINTER + "._access._policy";
// see ticket #24390
// First reading the access policy from the fileset
String accessPolicyPath = JSON_$_POINTER + ".fileset._access._policy";
boolean isAccessible = true;
try {
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
.jsonProvider(new JsonOrgJsonProvider()).build();
LOG.info("Reading access policy at {} into section document {}", accessPolicyPath, sectionDocumentJSON);
JsonPath theSectionPolycJsonPath = JsonPath.compile(accessPolicyPath);
String _policy = theSectionPolycJsonPath.read(sectionDocumentJSON, configuration).toString();
LOG.info("The section {} has policy {}", accessPolicyPath, _policy);
LOG.debug("Reading access policy at {} into section document {}", accessPolicyPath, sectionDocumentJSON);
String _policy = null;
try {
JsonPath theSectionPolycJsonPath = JsonPath.compile(accessPolicyPath);
_policy = theSectionPolycJsonPath.read(sectionDocumentJSON, configuration).toString();
if (_policy == null)
throw new Exception("Policy is null");
} catch (Exception e) {
LOG.debug("Access policy not found in: " + accessPolicyPath);
}
// If policy does not exist into fileset, reading from the parent section
if (_policy == null) {
accessPolicyPath = JSON_$_POINTER + "._access._policy";
LOG.debug("Reading access policy at {} into section document {}", accessPolicyPath,
sectionDocumentJSON);
try {
JsonPath theSectionPolycJsonPath = JsonPath.compile(accessPolicyPath);
_policy = theSectionPolycJsonPath.read(sectionDocumentJSON, configuration).toString();
if (_policy == null)
throw new Exception("Policy is null");
} catch (Exception e) {
LOG.debug("Access policy not found in: " + accessPolicyPath);
}
}
LOG.debug("The section {} has policy {}", accessPolicyPath, _policy);
isAccessible = GeportalCheckAccessPolicy.isAccessible(_policy, myLogin);
} catch (Exception e) {
LOG.error(accessPolicyPath + " not found. Check OK");
}
LOG.info("Is the section {} accessible? {}", sectionDocumentJSON, isAccessible);
LOG.info("It is {} accessible the section {} accessible? {}", isAccessible, sectionDocumentJSON);
return isAccessible;
}
@ -888,7 +942,7 @@ public class Geoportal_JSON_Mapper {
if (theObjectFieldValue instanceof String) {
String toString = (String) theObjectFieldValue;
if (toString != null && !toString.isEmpty()) {
toDoc.append(fieldLabel, theObjectFieldValue);
toDoc.append(fieldLabel, toString.trim());
} else {
LOG.debug("Skipping String field " + fieldLabel + " its value is null or empty");
}