#24494 Converting multiple values stored as array (e.g. [a,b,c]) in
multiple MetadataFieldWrapper repeatable fields
This commit is contained in:
parent
b1a4a22cc6
commit
132891988a
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.application.geoportaldatamapper;
|
package org.gcube.application.geoportaldatamapper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -219,24 +220,61 @@ public class Geoportal_JSON_Mapper {
|
||||||
|
|
||||||
List<MetadataFieldWrapper> cloneListOfMFW = cloneList(theProfileBean.getMetadataFields());
|
List<MetadataFieldWrapper> cloneListOfMFW = cloneList(theProfileBean.getMetadataFields());
|
||||||
|
|
||||||
|
List<MetadataFieldWrapper> duplicatedList = new ArrayList<MetadataFieldWrapper>();
|
||||||
|
|
||||||
for (MetadataFieldWrapper metadataField : cloneListOfMFW) {
|
for (MetadataFieldWrapper metadataField : cloneListOfMFW) {
|
||||||
|
|
||||||
String theFieldName = metadataField.getFieldId() != null ? metadataField.getFieldId()
|
String theFieldName = metadataField.getFieldId() != null ? metadataField.getFieldId()
|
||||||
: metadataField.getFieldName();
|
: metadataField.getFieldName();
|
||||||
LOG.debug("reading theFieldName: " + theFieldName);
|
LOG.debug("reading theFieldName: " + theFieldName);
|
||||||
Object theOBJFieldValue = fromSectionDoc.get(theFieldName);
|
|
||||||
metadataField.setCurrentValue(theOBJFieldValue + "");
|
|
||||||
|
|
||||||
if (access != null) {
|
if (access != null) {
|
||||||
if (theFieldName.equalsIgnoreCase("policy")) {
|
if (theFieldName.equalsIgnoreCase("policy")) {
|
||||||
metadataField.setCurrentValue(access.getPolicy().name());
|
metadataField.setCurrentValue(access.getPolicy().name());
|
||||||
|
continue;
|
||||||
} else if (theFieldName.equalsIgnoreCase("licenseID")) {
|
} else if (theFieldName.equalsIgnoreCase("licenseID")) {
|
||||||
metadataField.setCurrentValue(access.getLicense());
|
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<dataArray.length(); j++) {
|
||||||
|
List<MetadataFieldWrapper> 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<MetadataFieldWrapper>(cloneListOfMFW));
|
theProfileBeanExt.setMetadataFields(new ArrayList<MetadataFieldWrapper>(duplicatedList));
|
||||||
theProfileBeanExt.setDocumentSectionAsJSON(fromSectionDoc.toJson());
|
theProfileBeanExt.setDocumentSectionAsJSON(fromSectionDoc.toJson());
|
||||||
theProfileBeanExt.setGcubeProfile(gcubeProfileDV);
|
theProfileBeanExt.setGcubeProfile(gcubeProfileDV);
|
||||||
LOG.debug("Metadata fields are: " + theProfileBeanExt.getMetadataFields());
|
LOG.debug("Metadata fields are: " + theProfileBeanExt.getMetadataFields());
|
||||||
|
|
Loading…
Reference in New Issue