setCurrentValues as list (instead of single value)

This commit is contained in:
Francesco Mangiacrapa 2023-04-21 15:25:07 +02:00
parent 4106aada7b
commit 0838dabf80
3 changed files with 37 additions and 19 deletions

View File

@ -232,11 +232,11 @@ public class Geoportal_JSON_Mapper {
if (access != null) { if (access != null) {
if (theFieldName.equalsIgnoreCase("policy")) { if (theFieldName.equalsIgnoreCase("policy")) {
metadataField.setCurrentValue(access.getPolicy().name()); metadataField.setCurrentValues(access.getPolicy().name());
duplicatedList.add(metadataField); duplicatedList.add(metadataField);
continue; continue;
} else if (theFieldName.equalsIgnoreCase("licenseID")) { } else if (theFieldName.equalsIgnoreCase("licenseID")) {
metadataField.setCurrentValue(access.getLicense()); metadataField.setCurrentValues(access.getLicense());
duplicatedList.add(metadataField); duplicatedList.add(metadataField);
continue; continue;
} }
@ -257,23 +257,34 @@ public class Geoportal_JSON_Mapper {
for (int j = 0; j < dataArray.size(); j++) { for (int j = 0; j < dataArray.size(); j++) {
List<MetadataFieldWrapper> cloned = cloneList(Arrays.asList(metadataField)); List<MetadataFieldWrapper> cloned = cloneList(Arrays.asList(metadataField));
MetadataFieldWrapper mfw = cloned.get(0); MetadataFieldWrapper mfw = cloned.get(0);
mfw.setCurrentValue(dataArray.get(j)+"");
//Duplicating MetadataFieldWrapper for data list with isMultiSelection==false
// From the second repeated field settings if(!mfw.isMultiSelection()) {
// mandatory false and one instance mfw.setCurrentValues(dataArray.get(j)+"");
// These properties are managed properly with the // From the second repeated field settings
// first occurrence of the field // mandatory false and one instance
if (j >= 1) { // These properties are managed properly with the
mfw.setMandatory(false); // first occurrence of the field
mfw.setMaxOccurs(1); if (j >= 1) {
mfw.setMandatory(false);
mfw.setMaxOccurs(1);
}
duplicatedList.add(mfw);
}else {
//Setting dataArray as list of current values when isMultiSelection is true
String[] toArray = (String[]) dataArray.toArray(new String[0]);
mfw.setCurrentValues(toArray);
duplicatedList.add(mfw);
//Exit from for
break;
} }
duplicatedList.add(mfw);
} }
//Does not remove this
continue; continue;
} catch (Exception e) { } catch (Exception e) {
LOG.debug("It is not an Array"); LOG.debug("It is not an Array");
String theValue = theOBJFieldValue + ""; String theValue = theOBJFieldValue + "";
metadataField.setCurrentValue(theValue); metadataField.setCurrentValues(theValue);
} }
} }
@ -364,7 +375,10 @@ public class Geoportal_JSON_Mapper {
MetadataFieldWrapper newMfw = new MetadataFieldWrapper(); MetadataFieldWrapper newMfw = new MetadataFieldWrapper();
newMfw.setAsGroup(mfw.getAsGroup()); newMfw.setAsGroup(mfw.getAsGroup());
newMfw.setAsTag(mfw.getAsTag()); newMfw.setAsTag(mfw.getAsTag());
newMfw.setCurrentValue(mfw.getCurrentValue()); List<String> listValues = mfw.getCurrentValues();
if(listValues!=null) {
newMfw.setCurrentValues(listValues.stream().toArray(String[]::new));
}
newMfw.setDefaultValue(mfw.getDefaultValue()); newMfw.setDefaultValue(mfw.getDefaultValue());
newMfw.setFieldId(mfw.getFieldId()); newMfw.setFieldId(mfw.getFieldId());
newMfw.setFieldName(mfw.getFieldName()); newMfw.setFieldName(mfw.getFieldName());
@ -1117,7 +1131,7 @@ public class Geoportal_JSON_Mapper {
System.out.println("***** Metadata"); System.out.println("***** Metadata");
// System.out.println(mfw); // System.out.println(mfw);
System.out.println("\tfieldId: " + fieldWrapper.getFieldId() + ", fieldName: " System.out.println("\tfieldId: " + fieldWrapper.getFieldId() + ", fieldName: "
+ fieldWrapper.getFieldName() + ", CurrentValue: " + fieldWrapper.getCurrentValue()); + fieldWrapper.getFieldName() + ", CurrentValue: " + fieldWrapper.getCurrentValues());
i++; i++;
} }
i = 1; i = 1;

View File

@ -121,7 +121,10 @@ public class MetaDataProfileBeanExt extends MetaDataProfileBean implements Seria
MetadataFieldWrapper newMfw = new MetadataFieldWrapper(); MetadataFieldWrapper newMfw = new MetadataFieldWrapper();
newMfw.setAsGroup(mfw.getAsGroup()); newMfw.setAsGroup(mfw.getAsGroup());
newMfw.setAsTag(mfw.getAsTag()); newMfw.setAsTag(mfw.getAsTag());
newMfw.setCurrentValue(mfw.getCurrentValue()); List<String> list = mfw.getCurrentValues();
if(list!=null) {
newMfw.setCurrentValues(list.stream().toArray(String[]::new));
}
newMfw.setDefaultValue(mfw.getDefaultValue()); newMfw.setDefaultValue(mfw.getDefaultValue());
newMfw.setFieldId(mfw.getFieldId()); newMfw.setFieldId(mfw.getFieldId());
newMfw.setFieldName(mfw.getFieldName()); newMfw.setFieldName(mfw.getFieldName());

View File

@ -39,8 +39,9 @@ public class Geoportal_DataMapper_Tests {
private UseCaseDescriptorCaller clientUCD; private UseCaseDescriptorCaller clientUCD;
private ProjectsCaller clientProjects; private ProjectsCaller clientProjects;
private static String PROFILE_ID = "concessioni-estere"; //private static String PROFILE_ID = "concessioni-estere";
private static String PROJECT_ID = "6399de3ca0a4545420373251"; //63d011c4dcac4551b9a6b930 private static String PROFILE_ID = "profiledConcessioni";
private static String PROJECT_ID = "6442653ac6a0422d9e9042e0"; //63d011c4dcac4551b9a6b930 //6442653ac6a0422d9e9042e0 //6399de3ca0a4545420373251
private static String USERNAME = "francesco.mangiacrapa"; private static String USERNAME = "francesco.mangiacrapa";
@ -85,7 +86,7 @@ public class Geoportal_DataMapper_Tests {
/** /**
* Test read project edit. * Test read project edit.
*/ */
@Test //@Test
public void testReadProjectEdit() { public void testReadProjectEdit() {
try { try {