From 8eab316e709db03b1a11194549e6d6f8801f499d Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 29 Nov 2022 12:32:19 +0100 Subject: [PATCH] fixed loadProjectEdit method --- .settings/org.eclipse.wst.common.component | 30 ++-- .../server/Geoportal_JSON_Mapper.java | 140 +++++++----------- .../GeoportalViewer_Tests.java | 6 +- 3 files changed, 78 insertions(+), 98 deletions(-) diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 25ec451..9e732b6 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -35,7 +36,8 @@ - + + @@ -71,7 +73,8 @@ - + + @@ -107,7 +110,8 @@ - + + @@ -143,7 +147,8 @@ - + + @@ -179,7 +184,8 @@ - + + @@ -215,7 +221,8 @@ - + + @@ -251,7 +258,8 @@ - + + @@ -287,7 +295,8 @@ - + + @@ -323,7 +332,8 @@ - + + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java index b283dc9..210f3cc 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/Geoportal_JSON_Mapper.java @@ -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> 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 mapOfProfilesBeanExt = new LinkedHashMap(); - - ArrayList listOfProfilesBeanExt = new ArrayList(); + + List listOfProfilesBeanExt = new ArrayList(); // 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 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 copyOfMetadataFields = new ArrayList(theProfileBean.getMetadataFields()); - //int forIndex = 0; - + List 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(cloneListOfMFW)); - LOG.debug("Metadata fields are: "+theProfileBeanExt.getMetadataFields()); + LOG.debug("Metadata fields are: " + theProfileBeanExt.getMetadataFields()); // Reading filePaths List filePaths = gcubeProfileDV.getFilePaths(); - List listLayers = new ArrayList(); // 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 cloneList(List 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++; } diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataviewer/GeoportalViewer_Tests.java b/src/test/java/org/gcube/portlets/user/geoportaldataviewer/GeoportalViewer_Tests.java index b2663ab..7cd71e0 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataviewer/GeoportalViewer_Tests.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataviewer/GeoportalViewer_Tests.java @@ -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();