|
|
|
@ -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";
|
|
|
|
@ -68,7 +70,7 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
public static final String JSON_$_POINTER = "$";
|
|
|
|
|
|
|
|
|
|
public static final String _THEDOCUMENT = "_theDocument";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ProjectEdit loadProjectEdit(ProjectDV theProjectDV, String scope, String username) throws Exception {
|
|
|
|
|
|
|
|
|
|
String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON();
|
|
|
|
@ -112,19 +114,20 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
|
|
|
|
|
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
|
|
|
|
|
.jsonProvider(new JsonOrgJsonProvider()).build();
|
|
|
|
|
|
|
|
|
|
//LinkedHashMap<Integer, MetaDataProfileBeanExt> mapOfProfilesBeanExt = new LinkedHashMap<Integer, MetaDataProfileBeanExt>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LinkedHashMap<Integer, MetaDataProfileBeanExt> mapOfProfilesBeanExt = new
|
|
|
|
|
// LinkedHashMap<Integer, MetaDataProfileBeanExt>();
|
|
|
|
|
|
|
|
|
|
ArrayList<MetaDataProfileBeanExt> listOfProfilesBeanExt = new ArrayList<MetaDataProfileBeanExt>();
|
|
|
|
|
|
|
|
|
|
// Reading the Project according to list of Profile defined in the UCD
|
|
|
|
|
for (GcubeProfilesMetadataForUCD gcubeProfileMetaForUCD : listProfilesBean) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GcubeProfileDV gcubeProfileDV = gcubeProfileMetaForUCD.getGcubeProfile();
|
|
|
|
|
// SectionView sectionView = new SectionView();
|
|
|
|
|
// sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle());
|
|
|
|
|
|
|
|
|
|
System.out.println("\n\n##### Sto creando la sezione: "+gcubeProfileDV.getSectionTitle());
|
|
|
|
|
|
|
|
|
|
System.out.println("\n\n##### Sto creando la sezione: " + gcubeProfileDV.getSectionTitle());
|
|
|
|
|
LOG.debug("\n\nThe profile is: " + gcubeProfileDV);
|
|
|
|
|
// Building JSON/section full PATH and section name
|
|
|
|
|
String sectionJSONPath = "";
|
|
|
|
@ -178,17 +181,16 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
LOG.debug("Result for " + gcubeProfileDV.getSectionName() + " is: " + listBSONDocument);
|
|
|
|
|
List<MetaDataProfileBean> theProfileBeans = gcubeProfileMetaForUCD.getListMetadataProfileBean();
|
|
|
|
|
MetaDataProfileBean theProfileBean = theProfileBeans.get(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For each bson.Document filling the MetaDataProfileBean and its file
|
|
|
|
|
for (int i = 0; i < listBSONDocument.size(); i++) {
|
|
|
|
|
|
|
|
|
|
System.out.println("DOCUMENT number "+i+ " of the section: "+theProfileBean.getTitle());
|
|
|
|
|
|
|
|
|
|
System.out.println("DOCUMENT number " + i + " of the section: " + theProfileBean.getTitle());
|
|
|
|
|
MetaDataProfileBeanExt theProfileBeanExt = new MetaDataProfileBeanExt();
|
|
|
|
|
theProfileBeanExt.setCategories(theProfileBean.getCategories());
|
|
|
|
|
theProfileBeanExt.setTitle(theProfileBean.getTitle());
|
|
|
|
|
theProfileBeanExt.setType(theProfileBean.getType());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// System.out.println("\nPRINTING PROJECT VIEW ON START: ");
|
|
|
|
|
// for (int j = 0; j < listOfProfilesBeanExt.size(); j++) {
|
|
|
|
|
// MetaDataProfileBeanExt metaDataProfileBeanExt = listOfProfilesBeanExt.get(j);
|
|
|
|
@ -198,56 +200,57 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
// System.out.println("\t MetadataFieldWrapper index: " + z++ + " " + mfw);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Document fromSectionDoc = listBSONDocument.get(i);
|
|
|
|
|
LOG.debug("\n\nNew section DOC for index " + i + " is: " + new JSONObject(fromSectionDoc.toJson()).toString(2));
|
|
|
|
|
//Creating the corresponding MetaDataProfileBeanExt for each section
|
|
|
|
|
LOG.debug("\n\nNew section DOC for index " + i + " is: "
|
|
|
|
|
+ new JSONObject(fromSectionDoc.toJson()).toString(2));
|
|
|
|
|
// Creating the corresponding MetaDataProfileBeanExt for each section
|
|
|
|
|
|
|
|
|
|
//Reading policy and license statically
|
|
|
|
|
//eg. "_access":{"_policy":"OPEN","_license":"CC0-1.0"}}
|
|
|
|
|
// Reading policy and license statically
|
|
|
|
|
// eg. "_access":{"_policy":"OPEN","_license":"CC0-1.0"}}
|
|
|
|
|
Document docAccess = null;
|
|
|
|
|
Access access = null;
|
|
|
|
|
try {
|
|
|
|
|
docAccess = fromSectionDoc.get("_access", Document.class);
|
|
|
|
|
System.out.println("docAccess is: "+docAccess);
|
|
|
|
|
System.out.println("docAccess is: " + docAccess);
|
|
|
|
|
access = new Access();
|
|
|
|
|
access.setPolicy(AccessPolicy.valueOf(docAccess.getString("_policy")));
|
|
|
|
|
access.setLicense(docAccess.getString("_license"));
|
|
|
|
|
// Access. access.get("_policy");
|
|
|
|
|
// access.get("_license");
|
|
|
|
|
System.out.println("access is: "+access);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
// Access. access.get("_policy");
|
|
|
|
|
// access.get("_license");
|
|
|
|
|
System.out.println("access is: " + access);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//List<MetadataFieldWrapper> copyOfMetadataFields = new ArrayList<MetadataFieldWrapper>(theProfileBean.getMetadataFields());
|
|
|
|
|
//int forIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// List<MetadataFieldWrapper> copyOfMetadataFields = new
|
|
|
|
|
// ArrayList<MetadataFieldWrapper>(theProfileBean.getMetadataFields());
|
|
|
|
|
// int forIndex = 0;
|
|
|
|
|
|
|
|
|
|
List<MetadataFieldWrapper> cloneListOfMFW = cloneList(theProfileBean.getMetadataFields());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (MetadataFieldWrapper metadataField : cloneListOfMFW) {
|
|
|
|
|
|
|
|
|
|
String theFieldName = metadataField.getFieldId() != null ? metadataField.getFieldId()
|
|
|
|
|
: metadataField.getFieldName();
|
|
|
|
|
LOG.debug("reading theFieldName: " + theFieldName);
|
|
|
|
|
Object theOBJFieldValue = fromSectionDoc.get(theFieldName);
|
|
|
|
|
metadataField.setCurrentValue(theOBJFieldValue+"");
|
|
|
|
|
|
|
|
|
|
if(access!=null) {
|
|
|
|
|
if(theFieldName.equalsIgnoreCase("policy")) {
|
|
|
|
|
metadataField.setCurrentValue(theOBJFieldValue + "");
|
|
|
|
|
|
|
|
|
|
if (access != null) {
|
|
|
|
|
if (theFieldName.equalsIgnoreCase("policy")) {
|
|
|
|
|
metadataField.setCurrentValue(access.getPolicy().name());
|
|
|
|
|
}else if(theFieldName.equalsIgnoreCase("licenseID")) {
|
|
|
|
|
} else if (theFieldName.equalsIgnoreCase("licenseID")) {
|
|
|
|
|
metadataField.setCurrentValue(access.getLicense());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//copyOfMetadataFields.set(forIndex++, metadataField);
|
|
|
|
|
// copyOfMetadataFields.set(forIndex++, metadataField);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.debug("Before assigning it Metadata fields are: "+cloneListOfMFW);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOG.debug("Before assigning it Metadata fields are: " + cloneListOfMFW);
|
|
|
|
|
|
|
|
|
|
theProfileBeanExt.setMetadataFields(new ArrayList<MetadataFieldWrapper>(cloneListOfMFW));
|
|
|
|
|
LOG.debug("Metadata fields are: "+theProfileBeanExt.getMetadataFields());
|
|
|
|
|
LOG.debug("Metadata fields are: " + theProfileBeanExt.getMetadataFields());
|
|
|
|
|
|
|
|
|
|
// Reading filePaths
|
|
|
|
|
List<FilePathDV> filePaths = gcubeProfileDV.getFilePaths();
|
|
|
|
@ -272,17 +275,18 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reading Fileset _materializations
|
|
|
|
|
//listLayers = readGcubeSDILayersForFileset(filesetJSONPath, fromSectionDocJSON);
|
|
|
|
|
//theProfileBeanExt.set
|
|
|
|
|
// listLayers = readGcubeSDILayersForFileset(filesetJSONPath,
|
|
|
|
|
// fromSectionDocJSON);
|
|
|
|
|
// theProfileBeanExt.set
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
theProfileBeanExt.setListFileset(listFiles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("\nputting theProfileBeanExt: "+theProfileBeanExt);
|
|
|
|
|
|
|
|
|
|
System.out.println("\nputting theProfileBeanExt: " + theProfileBeanExt);
|
|
|
|
|
listOfProfilesBeanExt.add(theProfileBeanExt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// System.out.println("\nPRINTING PROJECT VIEW ON END: ");
|
|
|
|
|
// for (int j = 0; j < listOfProfilesBeanExt.size(); j++) {
|
|
|
|
|
// MetaDataProfileBeanExt metaDataProfileBeanExt = listOfProfilesBeanExt.get(j);
|
|
|
|
@ -294,15 +298,15 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// System.out.println(listProfileBeansExt.get(listProfileBeansExt.size()-1));
|
|
|
|
|
//Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView);
|
|
|
|
|
// Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
projectView.setTheProfileBeans(listOfProfilesBeanExt);
|
|
|
|
|
|
|
|
|
|
//Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView);
|
|
|
|
|
|
|
|
|
|
// Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView);
|
|
|
|
|
|
|
|
|
|
return projectView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -647,22 +651,29 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
LOG.info("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);
|
|
|
|
|
// [?(@._access._policy=='%s')]
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
com.jayway.jsonpath.Configuration configurationJSONSmart = com.jayway.jsonpath.Configuration.builder()
|
|
|
|
|
.jsonProvider(new JsonOrgJsonProvider()).build();
|
|
|
|
|
|
|
|
|
|
LOG.debug("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.debug("Error on reading the JSON Path " + _materializationsJSONPath + " in the doc "
|
|
|
|
|
+ sectionJSONDocument, e);
|
|
|
|
|
}
|
|
|
|
|
LOG.info("returning list of layers {}", listSDILayers);
|
|
|
|
@ -686,14 +697,14 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
|
|
|
|
|
if (objectJSON instanceof JSONArray) {
|
|
|
|
|
JSONArray theJsonArray = (JSONArray) objectJSON;
|
|
|
|
|
LOG.trace("jsonArray: " + theJsonArray.toString(3));
|
|
|
|
|
LOG.debug("jsonArray: " + theJsonArray.toString(3));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < theJsonArray.length(); i++) {
|
|
|
|
|
recursiveFetchingLayers(config, theJsonArray.get(i), listSDILayers);
|
|
|
|
|
}
|
|
|
|
|
} else if (objectJSON instanceof JSONObject) {
|
|
|
|
|
JSONObject theJsonObject = (JSONObject) objectJSON;
|
|
|
|
|
LOG.trace("theJSONObject: " + theJsonObject.toString(3));
|
|
|
|
|
LOG.debug("theJSONObject: " + theJsonObject.toString(3));
|
|
|
|
|
GCubeSDIViewerLayerDV gsdiLayer = converLayer(config, theJsonObject);
|
|
|
|
|
listSDILayers.add(gsdiLayer);
|
|
|
|
|
}
|
|
|
|
@ -806,7 +817,7 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
* @param myLogin the my login
|
|
|
|
|
* @return true, if is accessible section according to policy
|
|
|
|
|
*/
|
|
|
|
|
private static boolean isAccessibleSectionAccordingToPolicy(Document section, String sectionJSONPath,
|
|
|
|
|
public static boolean isAccessibleSectionAccordingToPolicy(Document section, String sectionJSONPath,
|
|
|
|
|
String myLogin) {
|
|
|
|
|
LOG.debug("isAccessibleSectionAccordingToPolicy called");
|
|
|
|
|
boolean isAccessible = true;
|
|
|
|
@ -829,8 +840,8 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
private static boolean checkAccessPolicy(String sectionDocumentJSON, String myLogin) {
|
|
|
|
|
LOG.info("checkAccessPolicy called");
|
|
|
|
|
// CHECKING THE POLICY
|
|
|
|
|
//see ticket #24390
|
|
|
|
|
//First reading the access policy from the fileset
|
|
|
|
|
// see ticket #24390
|
|
|
|
|
// First reading the access policy from the fileset
|
|
|
|
|
String accessPolicyPath = JSON_$_POINTER + ".fileset._access._policy";
|
|
|
|
|
boolean isAccessible = true;
|
|
|
|
|
try {
|
|
|
|
@ -842,36 +853,37 @@ public class Geoportal_JSON_Mapper {
|
|
|
|
|
try {
|
|
|
|
|
JsonPath theSectionPolycJsonPath = JsonPath.compile(accessPolicyPath);
|
|
|
|
|
_policy = theSectionPolycJsonPath.read(sectionDocumentJSON, configuration).toString();
|
|
|
|
|
|
|
|
|
|
if(_policy==null)
|
|
|
|
|
|
|
|
|
|
if (_policy == null)
|
|
|
|
|
throw new Exception("Policy is null");
|
|
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
LOG.debug("Access policy not found in: "+accessPolicyPath);
|
|
|
|
|
|
|
|
|
|
} 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) {
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
if (_policy == null)
|
|
|
|
|
throw new Exception("Policy is null");
|
|
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
LOG.debug("Access policy not found in: "+accessPolicyPath);
|
|
|
|
|
|
|
|
|
|
} 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|