DDMFormValuesToPropertiesConverter { public Dictionary<String, Object> getProperties() { Dictionary<String, Object> properties = new Hashtable<>(); AttributeDefinition[] attributeDefinitions = _configurationModel.getAttributeDefinitions(ConfigurationModel.ALL); for (AttributeDefinition attributeDefinition : attributeDefinitions) { Object value = null; List<DDMFormFieldValue> ddmFormFieldValues = _ddmFormFieldValuesMap.get(attributeDefinition.getID()); if (attributeDefinition.getCardinality() == 0) { value = toSimpleValue(ddmFormFieldValues.get(0)); } else if (attributeDefinition.getCardinality() > 0) { value = toArrayValue(ddmFormFieldValues); } else if (attributeDefinition.getCardinality() < 0) { value = toVectorValue(ddmFormFieldValues); } String[] defaultValues = attributeDefinition.getDefaultValue(); if ((ArrayUtil.getLength(defaultValues) == 1) && _isDefaultResourceValue( defaultValues[0], attributeDefinition.getType(), value)) { value = defaultValues[0]; } properties.put(attributeDefinition.getID(), value); } return properties; } DDMFormValuesToPropertiesConverter(
		ConfigurationModel configurationModel, DDMFormValues ddmFormValues,
		JSONFactory jsonFactory, Locale locale);  DDMFormValuesToPropertiesConverter(
		ConfigurationModel configurationModel, DDMFormValues ddmFormValues,
		JSONFactory jsonFactory, Locale locale,
		LocationVariableResolver locationVariableResolver); Dictionary<String, Object> getProperties();  }
@Test public void testArrayBooleanValues() { DDMForm ddmForm = new DDMForm(); ddmForm.addAvailableLocale(_enLocale); ddmForm.setDefaultLocale(_enLocale); DDMFormField booleanDDMFormField = DDMFormTestUtil.createDDMFormField( "Boolean", "Boolean", DDMFormFieldType.CHECKBOX, "boolean", false, true, false); ddmForm.addDDMFormField(booleanDDMFormField); DDMFormValues ddmFormValues = new DDMFormValues(ddmForm); ddmFormValues.addAvailableLocale(_enLocale); ddmFormValues.setDefaultLocale(_enLocale); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Boolean", "true", _enLocale)); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Boolean", "false", _enLocale)); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Boolean", "true", _enLocale)); ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); Configuration configuration = mock(Configuration.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 3); whenGetID(extendedAttributeDefinition, "Boolean"); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValuesToPropertiesConverter ddmFormValuesToPropertiesConverter = new DDMFormValuesToPropertiesConverter( configurationModel, ddmFormValues, _jsonFactory, _enLocale); Dictionary<String, Object> properties = ddmFormValuesToPropertiesConverter.getProperties(); Object value = properties.get("Boolean"); Boolean[] booleanValues = (Boolean[])value; Assert.assertEquals(true, booleanValues[0]); Assert.assertEquals(false, booleanValues[1]); Assert.assertEquals(true, booleanValues[2]); }
@Test public void testSimpleBooleanValue() { DDMForm ddmForm = new DDMForm(); ddmForm.addAvailableLocale(_enLocale); ddmForm.setDefaultLocale(_enLocale); DDMFormField booleanDDMFormField = DDMFormTestUtil.createDDMFormField( "Boolean", "Boolean", DDMFormFieldType.CHECKBOX, "boolean", false, false, false); ddmForm.addDDMFormField(booleanDDMFormField); DDMFormValues ddmFormValues = new DDMFormValues(ddmForm); ddmFormValues.addAvailableLocale(_enLocale); ddmFormValues.setDefaultLocale(_enLocale); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Boolean", "true", _enLocale)); ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); Configuration configuration = mock(Configuration.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Boolean"); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValuesToPropertiesConverter ddmFormValuesToPropertiesConverter = new DDMFormValuesToPropertiesConverter( configurationModel, ddmFormValues, _jsonFactory, _enLocale); Dictionary<String, Object> properties = ddmFormValuesToPropertiesConverter.getProperties(); Assert.assertEquals(true, properties.get("Boolean")); }
@Test public void testSimpleIntegerInvalidValue() { DDMForm ddmForm = new DDMForm(); ddmForm.addAvailableLocale(_enLocale); ddmForm.setDefaultLocale(_enLocale); DDMFormField integerDDMFormField = DDMFormTestUtil.createDDMFormField( "Integer", "Integer", DDMFormFieldType.TEXT, "integer", false, false, false); ddmForm.addDDMFormField(integerDDMFormField); DDMFormValues ddmFormValues = new DDMFormValues(ddmForm); ddmFormValues.addAvailableLocale(_enLocale); ddmFormValues.setDefaultLocale(_enLocale); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Integer", "42f", _enLocale)); ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); Configuration configuration = mock(Configuration.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Integer"); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValuesToPropertiesConverter ddmFormValuesToPropertiesConverter = new DDMFormValuesToPropertiesConverter( configurationModel, ddmFormValues, _jsonFactory, _enLocale); Dictionary<String, Object> properties = ddmFormValuesToPropertiesConverter.getProperties(); Assert.assertEquals(0, properties.get("Integer")); }
@Test public void testSimpleIntegerValue() { DDMForm ddmForm = new DDMForm(); ddmForm.addAvailableLocale(_enLocale); ddmForm.setDefaultLocale(_enLocale); DDMFormField integerDDMFormField = DDMFormTestUtil.createDDMFormField( "Integer", "Integer", DDMFormFieldType.TEXT, "integer", false, false, false); ddmForm.addDDMFormField(integerDDMFormField); DDMFormValues ddmFormValues = new DDMFormValues(ddmForm); ddmFormValues.addAvailableLocale(_enLocale); ddmFormValues.setDefaultLocale(_enLocale); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Integer", "42", _enLocale)); ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); Configuration configuration = mock(Configuration.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Integer"); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValuesToPropertiesConverter ddmFormValuesToPropertiesConverter = new DDMFormValuesToPropertiesConverter( configurationModel, ddmFormValues, _jsonFactory, _enLocale); Dictionary<String, Object> properties = ddmFormValuesToPropertiesConverter.getProperties(); Assert.assertEquals(42, properties.get("Integer")); }
@Test public void testSimpleSelectValue() { DDMForm ddmForm = new DDMForm(); ddmForm.addAvailableLocale(_enLocale); ddmForm.setDefaultLocale(_enLocale); DDMFormField integerDDMFormField = DDMFormTestUtil.createDDMFormField( "Select", "Select", DDMFormFieldType.SELECT, "integer", false, false, false); ddmForm.addDDMFormField(integerDDMFormField); DDMFormValues ddmFormValues = new DDMFormValues(ddmForm); ddmFormValues.addAvailableLocale(_enLocale); ddmFormValues.setDefaultLocale(_enLocale); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Select", "[\"42\"]", _enLocale)); ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); Configuration configuration = mock(Configuration.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Select"); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValuesToPropertiesConverter ddmFormValuesToPropertiesConverter = new DDMFormValuesToPropertiesConverter( configurationModel, ddmFormValues, _jsonFactory, _enLocale); Dictionary<String, Object> properties = ddmFormValuesToPropertiesConverter.getProperties(); Assert.assertEquals(42, properties.get("Select")); }
@SuppressWarnings("unchecked") @Test public void testVectorBooleanValues() { DDMForm ddmForm = new DDMForm(); ddmForm.addAvailableLocale(_enLocale); ddmForm.setDefaultLocale(_enLocale); DDMFormField booleanDDMFormField = DDMFormTestUtil.createDDMFormField( "Boolean", "Boolean", DDMFormFieldType.CHECKBOX, "boolean", false, true, false); ddmForm.addDDMFormField(booleanDDMFormField); DDMFormValues ddmFormValues = new DDMFormValues(ddmForm); ddmFormValues.addAvailableLocale(_enLocale); ddmFormValues.setDefaultLocale(_enLocale); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Boolean", "true", _enLocale)); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Boolean", "false", _enLocale)); ddmFormValues.addDDMFormFieldValue( createDDMFormFieldValue("Boolean", "true", _enLocale)); ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); Configuration configuration = mock(Configuration.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, -3); whenGetID(extendedAttributeDefinition, "Boolean"); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValuesToPropertiesConverter ddmFormValuesToPropertiesConverter = new DDMFormValuesToPropertiesConverter( configurationModel, ddmFormValues, _jsonFactory, _enLocale); Dictionary<String, Object> properties = ddmFormValuesToPropertiesConverter.getProperties(); Object value = properties.get("Boolean"); Vector<Boolean> booleanValues = (Vector<Boolean>)value; Assert.assertEquals(true, booleanValues.get(0)); Assert.assertEquals(false, booleanValues.get(1)); Assert.assertEquals(true, booleanValues.get(2)); }