diff --git a/src/main/java/org/gcube/application/geoportaldatamapper/Geoportal_JSON_Mapper.java b/src/main/java/org/gcube/application/geoportaldatamapper/Geoportal_JSON_Mapper.java index e12b7ee..da776cb 100644 --- a/src/main/java/org/gcube/application/geoportaldatamapper/Geoportal_JSON_Mapper.java +++ b/src/main/java/org/gcube/application/geoportaldatamapper/Geoportal_JSON_Mapper.java @@ -1,6 +1,7 @@ package org.gcube.application.geoportaldatamapper; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -219,24 +220,61 @@ public class Geoportal_JSON_Mapper { List cloneListOfMFW = cloneList(theProfileBean.getMetadataFields()); + List duplicatedList = new ArrayList(); + 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(access.getPolicy().name()); + continue; } else if (theFieldName.equalsIgnoreCase("licenseID")) { metadataField.setCurrentValue(access.getLicense()); + continue; } } + + Object theOBJFieldValue = fromSectionDoc.get(theFieldName); + + if(theOBJFieldValue!=null) { + //Converting multiple values stored as array (e.g. [a,b,c]) in multiple MetadataFieldWrapper + //repeatable fields + LOG.debug("value "+theOBJFieldValue+ " is instanceof Array"); + try { + JSONArray dataArray = new JSONArray(theOBJFieldValue+""); + LOG.debug("It is an Array"); + for (int j=0; j cloned = cloneList(Arrays.asList(metadataField)); + MetadataFieldWrapper mfw = cloned.get(0); + mfw.setCurrentValue(dataArray.getString(j)); + + //From the second repeated field settings + //mandatory false and one instance + //These properties are managed properly with the + //first occurrence of the field + if(j>=1) { + mfw.setMandatory(false); + mfw.setMaxOccurs(1); + } + duplicatedList.add(mfw); + } + continue; + }catch (Exception e) { + LOG.debug("It is not an Array"); + String theValue = theOBJFieldValue + ""; + metadataField.setCurrentValue(theValue); + } + } + + duplicatedList.add(metadataField); + } - theProfileBeanExt.setMetadataFields(new ArrayList(cloneListOfMFW)); + theProfileBeanExt.setMetadataFields(new ArrayList(duplicatedList)); theProfileBeanExt.setDocumentSectionAsJSON(fromSectionDoc.toJson()); theProfileBeanExt.setGcubeProfile(gcubeProfileDV); LOG.debug("Metadata fields are: " + theProfileBeanExt.getMetadataFields());