diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 59a42fb..1c62c02 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -50,7 +51,8 @@ - + + @@ -101,7 +103,8 @@ - + + @@ -152,7 +155,8 @@ - + + @@ -203,13 +207,21 @@ - + + + + uses + + + uses + uses - + + @@ -260,7 +272,8 @@ - + + @@ -311,7 +324,8 @@ - + + @@ -362,7 +376,8 @@ - + + diff --git a/pom.xml b/pom.xml index 4746aea..d1a22f2 100644 --- a/pom.xml +++ b/pom.xml @@ -237,6 +237,12 @@ 4.11 test + + + com.google.guava + guava + test + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index 9abde4b..8a237b3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -91,9 +91,7 @@ import com.google.gwt.event.logical.shared.ResizeHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Label; diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java index 5ae32ca..d495c17 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/Complex_Tests.java @@ -1,8 +1,10 @@ package org.gcube.portlets.user.geoportaldataentry; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import org.bson.Document; import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; @@ -17,17 +19,22 @@ import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV; +import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView; +import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView; +import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; +import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider; public class Complex_Tests { @@ -37,12 +44,12 @@ public class Complex_Tests { private static String TOKEN = ""; // devVRE private static String PROFILE_ID = "profiledConcessioni"; - private static String PROJECT_ID = "630f905855e2947b0278c1a8"; + private static String PROJECT_ID = "632c633155e2947b0278c999"; public static final String JSON_$_POINTER = "$"; private static final Logger LOG = LoggerFactory.getLogger(Complex_Tests.class); - //@Before + @Before public void init() { ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); @@ -50,7 +57,7 @@ public class Complex_Tests { clientUCD = GeoportalClientCaller.useCaseDescriptors(); } - //@Test + @Test public void testReadProjectForUCDDataEntry() { ScopeProvider.instance.set(CONTEXT); SecurityTokenProvider.instance.set(TOKEN); @@ -84,6 +91,8 @@ public class Complex_Tests { SecurityTokenProvider.instance.set(TOKEN); List listProfiles = metaProfileBUilder.getProfilesInTheScopeForName(CONTEXT, gcubeProfileDV.getGcubeSecondaryType(), gcubeProfileDV.getGcubeName()); + + String key = gcubeProfileDV.getGcubeSecondaryType()+gcubeProfileDV.getGcubeName(); System.out.println("for key: "+key+ " readi profiles: "+listGcubeProfiles); linkedHashProfiles.put(gcubeProfileDV.getGcubeSecondaryType()+gcubeProfileDV.getGcubeName(), listProfiles); @@ -92,12 +101,25 @@ public class Complex_Tests { Project theProject = clientPrj.getProjectByID(PROFILE_ID, PROJECT_ID); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); ProjectDV theProjectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder); - System.out.println("theProjectDV as JSON: "+theProject.getTheDocument().toJson()); + String theWholeProjectAsJSON = theProject.getTheDocument().toJson(); + + System.out.println("theProjectDV as JSON: "+theWholeProjectAsJSON); System.out.println("theProjectDV as MAP: "+theProjectDV.getTheDocument().getDocumentAsMap()); + ProjectView projectView = new ProjectView(); + projectView.setTheProjectDV(theProjectDV); + + com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() + .jsonProvider(new JsonOrgJsonProvider()).build(); + + for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) { - LOG.debug("The profile is: " + gcubeProfileDV); + SectionView sectionView = new SectionView(); + + sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle()); + + LOG.debug("\n\nThe profile is: " + gcubeProfileDV); // Building JSON/section full PATH and section name String sectionJSONPath = ""; @@ -112,33 +134,116 @@ public class Complex_Tests { parentPathFromProfile.endsWith(".") ? parentPathFromProfile : parentPathFromProfile + ".", theSectionName); } LOG.debug("The sectionJSONPath is: " + sectionJSONPath); + + //Object jsonFile = configuration.jsonProvider().parse(theWholeProjectAsJSON); + //Object data = JsonPath.using(configuration).parse(theWholeProjectAsJSON).read(sectionJSONPath); + + JsonPath jsonPath = JsonPath.compile(sectionJSONPath); + Object data= jsonPath.read(theWholeProjectAsJSON, configuration); + +// Object jsonFile = configuration.jsonProvider().parse(theWholeProjectAsJSON); +// Object data = JsonPath.read(jsonFile, sectionJSONPath); - // Building Parent PATH - String parentPath = sectionJSONPath.compareTo(JSON_$_POINTER) == 0 ? JSON_$_POINTER - : sectionJSONPath.substring(0, sectionJSONPath.lastIndexOf(".")); + System.out.println("Data is instace of: "+data.getClass()); + System.out.println("data to string: "+data.toString()); - JsonPath parentJSONPath = JsonPath.compile(parentPath); + List listBSONDocument = new ArrayList(); + if(data instanceof org.json.JSONObject) { + String jsonString = data.toString(); + Document doc = Document.parse(jsonString); + System.out.println("the JSON to string: "+doc.toJson()); + listBSONDocument.add(doc); + }else if(data instanceof org.json.JSONArray) { + org.json.JSONArray dataArray = (org.json.JSONArray) data; + for (int i=0; i listSubDocuments = new ArrayList(); List theProfileBeans = linkedHashProfiles.get(gcubeProfileDV.getGcubeSecondaryType()+gcubeProfileDV.getGcubeName()); MetaDataProfileBean theProfileBean = theProfileBeans.get(0); - for (MetadataFieldWrapper metadataField : theProfileBean.getMetadataFields()) { - String theFieldName = metadataField.getFieldId()!=null?metadataField.getFieldId():metadataField.getFieldName(); - theProjectDV.getTheDocument().getDocumentAsMap().get(linkedHashProfiles); + + for (int i = 0; i < listBSONDocument.size(); i++) { + Document fromDoc = listBSONDocument.get(i); + SubDocumentView subDocumentView = new SubDocumentView(); +// LOG.debug("subDocumentString is: " + subDocumentString); +// Document doc = Document.parse(subDocumentString); +// DocumentDV readTheDocument = ConvertToDataValueObjectModel.toGenericDocumentDV(doc, DocumentDV.class, null, true); +// LOG.debug("toDocumentDV is: " + readTheDocument); + + Document toDoc = new Document(); + for (MetadataFieldWrapper metadataField : theProfileBean.getMetadataFields()) { + + String theFieldName = metadataField.getFieldId()!=null?metadataField.getFieldId():metadataField.getFieldName(); + LOG.debug("reading theFieldName: " + theFieldName); + Object theOBJFieldIntoDocument = fromDoc.get(theFieldName); + + toDoc = sanitizeDocumentValue(toDoc, metadataField.getFieldName(), theOBJFieldIntoDocument); + + + } + String subToJSON = toDoc.toJson(); + LOG.debug("theSubSetionDoc is: " + subToJSON); + subDocumentView.setMetadataAsJSON(toDoc.toJson()); + sectionView.addSubDocument(subDocumentView); + } + projectView.addSectionView(sectionView); } for (String key : linkedHashProfiles.keySet()) { System.out.println("For key: "+key+" got profiles: "+linkedHashProfiles.get(key)); } + + + for (SectionView section : projectView.getListSections()) { + System.out.println("##### Section Title: " + section.getSectionTitle()); + int i = 0; + for (SubDocumentView subDocument : section.getListSubDocuments()) { + System.out.println("\t " + ++i + ") SubDocumentView meta: " + + new JSONObject(subDocument.getMetadataAsJSON()).toString(2)); + } + + } } catch (Exception e) { System.out.println("error"); e.printStackTrace(); } - System.out.println("termimated"); + System.out.println("\n\n Procedure termimated!!!"); } + + private Document sanitizeDocumentValue(Document toDoc, String fieldLabel, Object theObjectField) { + + if(theObjectField != null) { + + //LOG.debug("theOBJFieldIntoDocument instance of: " + theObjectField.getClass() + " value: "+theObjectField); + if(theObjectField instanceof String) { + String toString = (String) theObjectField; + if(toString!=null && !toString.isEmpty()) { + toDoc.append(fieldLabel, theObjectField); + } + }else if(theObjectField instanceof ArrayList) { + ArrayList toArrayList = (ArrayList) theObjectField; + if(toArrayList!=null && !toArrayList.isEmpty()) { + toDoc.append(fieldLabel, theObjectField); + } + } + + toDoc.append(fieldLabel, theObjectField); + } + + return toDoc; + } + /** * To list gcube profiles. diff --git a/src/test/java/org/gcube/portlets/user/geoportaldataentry/UCD_Tests.java b/src/test/java/org/gcube/portlets/user/geoportaldataentry/UCD_Tests.java index 8d1dd02..4e1bda9 100644 --- a/src/test/java/org/gcube/portlets/user/geoportaldataentry/UCD_Tests.java +++ b/src/test/java/org/gcube/portlets/user/geoportaldataentry/UCD_Tests.java @@ -13,7 +13,6 @@ import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescrip import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.scope.api.ScopeProvider; import org.junit.Before; -import org.junit.Test; public class UCD_Tests {