fixed loadProjectEdit method

This commit is contained in:
Francesco Mangiacrapa 2022-11-29 12:32:19 +01:00
parent 55456b4040
commit 8eab316e70
3 changed files with 78 additions and 98 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
@ -35,7 +36,8 @@
<wb-module deploy-name="geoportal-data-viewer-app-3.0.0-SNAPSHOT">
@ -71,7 +73,8 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -107,7 +110,8 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -143,7 +147,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
@ -179,7 +184,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
@ -215,7 +221,8 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
@ -251,7 +258,8 @@
<property name="java-output-path" value="/geoportal-data-viewer-app/target/geoportal-data-viewer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/>
@ -287,7 +295,8 @@
<property name="context-root" value="geoportal-data-viewer-app"/>
@ -323,7 +332,8 @@
</wb-module>

View File

@ -68,16 +68,17 @@ 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 {
public static ProjectEdit loadProjectEdit(ProjectDV theProjectDV, String scope, String username) throws Exception {
LOG.debug("loadProjectEdit called");
String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON();
LOG.debug("theProjectDV as JSON: " + theWholeProjectAsJSON);
LOG.debug("theProjectDV as MAP: " + theProjectDV.getTheDocument().getDocumentAsMap());
LOG.trace("theProjectDV as MAP: " + theProjectDV.getTheDocument().getDocumentAsMap());
ProjectEdit projectView = new ProjectEdit();
projectView.setTheProjectDV(theProjectDV);
ProjectEdit projectEdit = new ProjectEdit();
projectEdit.setTheProjectDV(theProjectDV);
LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> linkedMap_UCDId_gCubeProfiles = GcubeProfilesPerUCDIdCache
.get(scope);
@ -112,19 +113,14 @@ 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>();
ArrayList<MetaDataProfileBeanExt> listOfProfilesBeanExt = new ArrayList<MetaDataProfileBeanExt>();
List<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());
LOG.debug("\n\n##### Creating the section: " + gcubeProfileDV.getSectionTitle());
LOG.debug("\n\nThe profile is: " + gcubeProfileDV);
// Building JSON/section full PATH and section name
String sectionJSONPath = "";
@ -178,80 +174,64 @@ 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());
LOG.trace("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);
// System.out.println("MetaDataProfileBeanExt index: " + j + " "+metaDataProfileBeanExt.getType() +" "+metaDataProfileBeanExt.hashCode());
// int z = 0;
// for (MetadataFieldWrapper mfw : metaDataProfileBeanExt.getMetadataFields()) {
// 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
//Reading policy and license statically
//eg. "_access":{"_policy":"OPEN","_license":"CC0-1.0"}}
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
// 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);
LOG.trace("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) {
e.printStackTrace();
// Access. access.get("_policy");
// access.get("_license");
System.out.println("access is: " + access);
} catch (Exception e) {
LOG.warn("No " + AccessPolicy.class.getSimpleName() + "found in the section "
+ fromSectionDoc.toJson());
LOG.debug("No AccessPolicy.class.getSimpleName(): ", e);
}
//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);
}
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();
List<GCubeSDIViewerLayerDV> listLayers = new ArrayList<GCubeSDIViewerLayerDV>();
// READING fileset* field ACCORDING TO filePaths OF THE 'gcubeProfiles' CONFIG
if (filePaths != null) {
@ -268,42 +248,25 @@ public class Geoportal_JSON_Mapper {
for (Payload payload : listPayloads) {
PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload);
filesetDV.addPayloadDV(payloadDV);
listFiles.add(filesetDV);
}
// Reading Fileset _materializations
//listLayers = readGcubeSDILayersForFileset(filesetJSONPath, fromSectionDocJSON);
//theProfileBeanExt.set
listFiles.add(filesetDV);
}
theProfileBeanExt.setListFileset(listFiles);
}
System.out.println("\nputting theProfileBeanExt: "+theProfileBeanExt);
LOG.trace("\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);
// System.out.println("MetaDataProfileBeanExt index: " + j + " "+metaDataProfileBeanExt.getType() +" "+metaDataProfileBeanExt.hashCode());
// int z = 0;
// for (MetadataFieldWrapper mfw : metaDataProfileBeanExt.getMetadataFields()) {
// System.out.println("\t MetadataFieldWrapper index: " + z++ + " " + mfw);
// }
// }
//
// System.out.println(listProfileBeansExt.get(listProfileBeansExt.size()-1));
//Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView);
}
}
projectView.setTheProfileBeans(listOfProfilesBeanExt);
//Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectView);
return projectView;
projectEdit.setTheProfileBeans(listOfProfilesBeanExt);
LOG.info("returning ProjectEdit with " + projectEdit.getTheProfileBeans().size() + " profile beans");
return projectEdit;
}
public static List<MetadataFieldWrapper> cloneList(List<MetadataFieldWrapper> list) {
@ -583,8 +546,8 @@ public class Geoportal_JSON_Mapper {
LOG.trace("The _payloads is a String {}", toStringPayloads);
JSONArray jsonArray = new JSONArray(toStringPayloads);
for (int i = 0; i < jsonArray.length(); i++) {
Payload payloadDV = Serialization.read(jsonArray.getJSONObject(i).toString(), Payload.class);
listPayloads.add(payloadDV);
Payload payload = Serialization.read(jsonArray.getJSONObject(i).toString(), Payload.class);
listPayloads.add(payload);
}
}
@ -962,8 +925,15 @@ public class Geoportal_JSON_Mapper {
i = 1;
System.out.println("***** Files");
for (FilesetDV fileSet : mpb.getListFileset()) {
System.out.println("## " + FilesetDV.class.getSimpleName() + " n." + i);
System.out.println(fileSet);
System.out.println(
"## " + FilesetDV.class.getSimpleName() + " n." + i + " has name: " + fileSet.getName());
if (fileSet.getListPayload() != null) {
int j = 0;
for (PayloadDV payload : fileSet.getListPayload()) {
System.out.println("\t" + ++j + ") " + payload);
}
}
i++;
}

View File

@ -62,7 +62,7 @@ public class GeoportalViewer_Tests {
//private static String TOKEN = ""; // devVRE
private static String PROFILE_ID = "profiledConcessioni";
private static String PROJECT_ID = "637ceb4d21dd0d6fb9f24706";
private static String PROJECT_ID = "6384c56c308f5c28c5ee0986";
private static String USERNAME = "francesco.mangiacrapa";
@ -71,7 +71,7 @@ public class GeoportalViewer_Tests {
*
* @return the client
*/
//@Before
@Before
public void getClient() {
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
ScopeProvider.instance.set(CONTEXT);
@ -235,7 +235,7 @@ public class GeoportalViewer_Tests {
// ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(theProjectDV, CONTEXT, USERNAME);
// Geoportal_JSON_Mapper.prettyPrintProjectView(projectView);
System.out.println("testReadProjectEdit terminated");
System.out.println("\n\n testReadProjectEdit terminated!!!");
} catch (Exception e) {
System.err.println("Error");
e.printStackTrace();