DataDefinitionUtil { public static DDMForm toDDMForm( DataDefinition dataDefinition, DDMFormFieldTypeServicesTracker ddmFormFieldTypeServicesTracker) { if (dataDefinition == null) { return new DDMForm(); } DDMForm ddmForm = new DDMForm(); ddmForm.setAvailableLocales( _toLocales(dataDefinition.getAvailableLanguageIds())); ddmForm.setDDMFormFields( _toDDMFormFields( dataDefinition.getDataDefinitionFields(), ddmFormFieldTypeServicesTracker, dataDefinition.getDefaultLanguageId())); ddmForm.setDefaultLocale( LocaleUtil.fromLanguageId(dataDefinition.getDefaultLanguageId())); return ddmForm; }  static DataDefinition toDataDefinition(
			DataDefinitionContentTypeTracker dataDefinitionContentTypeTracker,
			DDMFormFieldTypeServicesTracker ddmFormFieldTypeServicesTracker,
			DDMStructure ddmStructure,
			DDMStructureLayoutLocalService ddmStructureLayoutLocalService,
			SPIDDMFormRuleConverter spiDDMFormRuleConverter); static DDMForm toDDMForm(
		DataDefinition dataDefinition,
		DDMFormFieldTypeServicesTracker ddmFormFieldTypeServicesTracker);  }
@Test public void testToDDMFormEquals() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm( SetUtil.fromArray(new Locale[] {LocaleUtil.BRAZIL, LocaleUtil.US}), LocaleUtil.US); Locale defaultLocale = ddmForm.getDefaultLocale(); ddmForm.addDDMFormField( new DDMFormField() { { setIndexType("text"); setLabel( LocalizedValueUtil.toLocalizedValue( HashMapBuilder.<String, Object>put( "en_US", "label1" ).put( "pt_BR", "rótulo1" ).build(), defaultLocale)); setLocalizable(true); setName("name1"); setPredefinedValue( LocalizedValueUtil.toLocalizedValue( HashMapBuilder.<String, Object>put( "en_US", "enter a text" ).put( "pt_BR", "insira um texto" ).build(), defaultLocale)); setReadOnly(true); setRepeatable(true); setRequired(true); setShowLabel(true); setTip( LocalizedValueUtil.toLocalizedValue( HashMapBuilder.<String, Object>put( "en_US", "tip1" ).put( "pt_BR", "ajuda1" ).build(), defaultLocale)); setType("text"); } }); ddmForm.addDDMFormField( new DDMFormField() { { setIndexType("keyword"); setLabel( LocalizedValueUtil.toLocalizedValue( HashMapBuilder.<String, Object>put( "en_US", "label2" ).put( "pt_BR", "rótulo2" ).build(), defaultLocale)); setName("name2"); setLocalizable(false); setPredefinedValue( LocalizedValueUtil.toLocalizedValue( HashMapBuilder.<String, Object>put( "en_US", "select an option" ).put( "pt_BR", "selecione uma opção" ).build(), defaultLocale)); setReadOnly(false); setRepeatable(false); setRequired(false); setShowLabel(false); setTip( LocalizedValueUtil.toLocalizedValue( HashMapBuilder.<String, Object>put( "en_US", "tip2" ).put( "pt_BR", "ajuda2" ).build(), defaultLocale)); setType("select"); } }); Assert.assertEquals( ddmForm, DataDefinitionUtil.toDDMForm( new DataDefinition() { { setAvailableLanguageIds( new String[] {"en_US", "pt_BR"}); setDataDefinitionFields( new DataDefinitionField[] { new DataDefinitionField() { { setDefaultValue( HashMapBuilder.<String, Object>put( "en_US", "enter a text" ).put( "pt_BR", "insira um texto" ).build()); setFieldType("text"); setIndexType(IndexType.TEXT); setLabel( HashMapBuilder.<String, Object>put( "en_US", "label1" ).put( "pt_BR", "rótulo1" ).build()); setLocalizable(true); setName("name1"); setReadOnly(true); setRepeatable(true); setRequired(true); setShowLabel(true); setTip( HashMapBuilder.<String, Object>put( "en_US", "tip1" ).put( "pt_BR", "ajuda1" ).build()); } }, new DataDefinitionField() { { setDefaultValue( HashMapBuilder.<String, Object>put( "en_US", "select an option" ).put( "pt_BR", "selecione uma opção" ).build()); setFieldType("select"); setIndexType(IndexType.KEYWORD); setLabel( HashMapBuilder.<String, Object>put( "en_US", "label2" ).put( "pt_BR", "rótulo2" ).build()); setName("name2"); setLocalizable(false); setReadOnly(false); setRepeatable(false); setRequired(false); setShowLabel(false); setTip( HashMapBuilder.<String, Object>put( "en_US", "tip2" ).put( "pt_BR", "ajuda2" ).build()); } } }); setDefaultLanguageId("en_US"); } }, _ddmFormFieldTypeServicesTracker)); }
@Test public void testToDDMFormWithEmptyDataDefinition() { DDMForm ddmForm = DataDefinitionUtil.toDDMForm( new DataDefinition(), _ddmFormFieldTypeServicesTracker); Assert.assertTrue(SetUtil.isEmpty(ddmForm.getAvailableLocales())); Assert.assertTrue(ListUtil.isEmpty(ddmForm.getDDMFormFields())); Assert.assertNull(LocaleUtil.toLanguageId(ddmForm.getDefaultLocale())); }
@Test public void testToDDMFormWithNullDataDefinition() { Assert.assertEquals( new DDMForm(), DataDefinitionUtil.toDDMForm( null, _ddmFormFieldTypeServicesTracker)); }