protected Serializable toSimpleValue( DDMFormField ddmFormField, DDMFormFieldValue ddmFormFieldValue) { Value value = ddmFormFieldValue.getValue(); return FieldConstants.getSerializable(ddmFormField.getDataType(), value.getString(_locale)); }
protected void setDDMFormFieldValueLocalizedValue( HttpServletRequest httpServletRequest, String fieldType, String ddmFormFieldParameterName, LocalizedValue predefinedValue, DDMFormFieldValue ddmFormFieldValue) { Locale defaultLocale = getDefaultLocale(httpServletRequest); Value value = new LocalizedValue(defaultLocale); Set<Locale> availableLocales = getAvailableLocales(httpServletRequest); for (Locale availableLocale : availableLocales) { String ddmFormFieldParameterValue = getDDMFormFieldParameterValue( httpServletRequest, fieldType, ddmFormFieldParameterName, predefinedValue.getString(availableLocale), availableLocale); value.addString(availableLocale, ddmFormFieldParameterValue); } ddmFormFieldValue.setValue(value); }
@Override public void transform(DDMFormFieldValue ddmFormFieldValue) throws PortalException { Value value = ddmFormFieldValue.getValue(); for (Locale locale : value.getAvailableLocales()) { String valueString = value.getString(locale); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString); long groupId = GetterUtil.getLong(jsonObject.get("groupId")); long layoutId = GetterUtil.getLong(jsonObject.getLong("layoutId")); boolean privateLayout = jsonObject.getBoolean("privateLayout"); Layout layout = _layoutLocalService.getLayout(groupId, privateLayout, layoutId); Element entityElement = _portletDataContext.getExportDataElement(_stagedModel); _portletDataContext.addReferenceElement( _stagedModel, entityElement, layout, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); } }
protected void testHTMLDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue) { Assert.assertEquals("lamn", ddmFormFieldValue.getInstanceId()); Value value = ddmFormFieldValue.getValue(); Assert.assertEquals("<p>This is a test.</p>", value.getString(LocaleUtil.US)); Assert.assertEquals("<p>Isto e um teste.</p>", value.getString(LocaleUtil.BRAZIL)); }
protected void testBooleanDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue) { Assert.assertEquals("maky", ddmFormFieldValue.getInstanceId()); Value value = ddmFormFieldValue.getValue(); Assert.assertEquals("false", value.getString(LocaleUtil.US)); Assert.assertEquals("true", value.getString(LocaleUtil.BRAZIL)); }
protected void testTextDDMFormFieldValue( DDMFormFieldValue ddmFormFieldValue, String expected_en_US, String expected_pt_BR) { Assert.assertNotNull(ddmFormFieldValue); Value value = ddmFormFieldValue.getValue(); Assert.assertEquals(expected_en_US, value.getString(LocaleUtil.US)); Assert.assertEquals(expected_pt_BR, value.getString(LocaleUtil.BRAZIL)); }
protected void testDocumentLibraryDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue) throws Exception { Assert.assertEquals("autx", ddmFormFieldValue.getInstanceId()); JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject(); expectedJSONObject.put("groupId", 10192); expectedJSONObject.put("uuid", "c8acdf70-e101-46a6-83e5-c5f5e087b0dc"); expectedJSONObject.put("version", 1.0); Value value = ddmFormFieldValue.getValue(); JSONAssert.assertEquals(expectedJSONObject.toString(), value.getString(LocaleUtil.US), false); JSONAssert.assertEquals( expectedJSONObject.toString(), value.getString(LocaleUtil.BRAZIL), false); }
@Override public void transform(DDMFormFieldValue ddmFormFieldValue) throws PortalException { Value value = ddmFormFieldValue.getValue(); for (Locale locale : value.getAvailableLocales()) { String valueString = value.getString(locale); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString); Layout importedLayout = fetchImportedLayout(_portletDataContext, jsonObject); if (importedLayout == null) { continue; } value.addString(locale, toJSON(importedLayout)); } }
@Test public void testGetWithCheckboxField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock(ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock(ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.REQUIRED); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Boolean"); whenGetType(extendedAttributeDefinition, ExtendedAttributeDefinition.BOOLEAN); ConfigurationModel configurationModel = new ConfigurationModel(extendedObjectClassDefinition, null, null, null, false); ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = new ConfigurationModelToDDMFormConverter( configurationModel, _enLocale, new EmptyResourceBundle()); DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm(); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false); DDMFormField ddmFormField = ddmFormFieldsMap.get("Boolean"); Assert.assertNotNull(ddmFormField); Assert.assertEquals(DDMFormFieldType.CHECKBOX, ddmFormField.getType()); Assert.assertEquals("boolean", ddmFormField.getDataType()); Assert.assertFalse(ddmFormField.isRepeatable()); Assert.assertFalse(ddmFormField.isRequired()); Value predefinedValue = ddmFormField.getPredefinedValue(); Assert.assertEquals("false", predefinedValue.getString(_enLocale)); }
protected String getDDMFormFieldValueString(DDMFormFieldValue ddmFormFieldValue) { Value value = ddmFormFieldValue.getValue(); String valueString = value.getString(_locale); String type = getDDMFormFieldType(ddmFormFieldValue.getName()); if (type.equals(DDMFormFieldType.SELECT)) { try { JSONArray jsonArray = _jsonFactory.createJSONArray(valueString); if (jsonArray.length() == 1) { valueString = jsonArray.getString(0); } } catch (JSONException je) { ReflectionUtil.throwException(je); } } return valueString; }
protected void testSelectDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue) throws Exception { Assert.assertEquals("yhar", ddmFormFieldValue.getInstanceId()); Value value = ddmFormFieldValue.getValue(); JSONArray expectedJSONArray = JSONFactoryUtil.createJSONArray(); expectedJSONArray.put("Value 1"); expectedJSONArray.put("Value 3"); JSONAssert.assertEquals(expectedJSONArray.toString(), value.getString(LocaleUtil.US), false); expectedJSONArray = JSONFactoryUtil.createJSONArray(); expectedJSONArray.put("Value 2"); expectedJSONArray.put("Value 3"); JSONAssert.assertEquals( expectedJSONArray.toString(), value.getString(LocaleUtil.BRAZIL), false); }
protected void testImageDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue) throws Exception { Assert.assertEquals("labt", ddmFormFieldValue.getInstanceId()); Value value = ddmFormFieldValue.getValue(); JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject(); expectedJSONObject.put("alt", "This is a image description."); expectedJSONObject.put("data", "base64Value"); JSONAssert.assertEquals(expectedJSONObject.toString(), value.getString(LocaleUtil.US), false); expectedJSONObject = JSONFactoryUtil.createJSONObject(); expectedJSONObject.put("alt", "Isto e uma descricao de imagem."); expectedJSONObject.put("data", "valorEmBase64"); JSONAssert.assertEquals( expectedJSONObject.toString(), value.getString(LocaleUtil.BRAZIL), false); }
protected void testGeolocationDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue) throws Exception { Assert.assertEquals("powq", ddmFormFieldValue.getInstanceId()); Value value = ddmFormFieldValue.getValue(); JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject(); expectedJSONObject.put("latitude", 34.0286226); expectedJSONObject.put("longitude", -117.8103367); JSONAssert.assertEquals(expectedJSONObject.toString(), value.getString(LocaleUtil.US), false); expectedJSONObject = JSONFactoryUtil.createJSONObject(); expectedJSONObject.put("latitude", -8.0349219); expectedJSONObject.put("longitude", -34.91922120); JSONAssert.assertEquals( expectedJSONObject.toString(), value.getString(LocaleUtil.BRAZIL), false); }
@Override public void transform(DDMFormFieldValue ddmFormFieldValue) throws PortalException { Value value = ddmFormFieldValue.getValue(); for (Locale locale : value.getAvailableLocales()) { String valueString = value.getString(locale); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString); long groupId = GetterUtil.getLong(jsonObject.get("groupId")); String uuid = jsonObject.getString("uuid"); if ((groupId == 0) || Validator.isNull(uuid)) { continue; } FileEntry fileEntry = _dlAppService.getFileEntryByUuidAndGroupId(uuid, groupId); if (_exportReferencedContent) { StagedModelDataHandlerUtil.exportReferenceStagedModel( _portletDataContext, _stagedModel, fileEntry, _portletDataContext.REFERENCE_TYPE_DEPENDENCY); } else { Element entityElement = _portletDataContext.getExportDataElement(_stagedModel); _portletDataContext.addReferenceElement( _stagedModel, entityElement, fileEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); } } }
protected void testLinkToPageDDMFormFieldValueValues(DDMFormFieldValue ddmFormFieldValue) throws Exception { Assert.assertEquals("nast", ddmFormFieldValue.getInstanceId()); Value value = ddmFormFieldValue.getValue(); JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject(); expectedJSONObject.put("groupId", 10192); expectedJSONObject.put("layoutId", 1); expectedJSONObject.put("privateLayout", false); JSONAssert.assertEquals(expectedJSONObject.toString(), value.getString(LocaleUtil.US), false); expectedJSONObject = JSONFactoryUtil.createJSONObject(); expectedJSONObject.put("groupId", 10192); expectedJSONObject.put("layoutId", 2); expectedJSONObject.put("privateLayout", false); JSONAssert.assertEquals( expectedJSONObject.toString(), value.getString(LocaleUtil.BRAZIL), false); }
@Test public void testDeserializationWithUnlocalizableField() throws Exception { String serializedDDMFormValues = read("ddm-form-values-json-deserializer-unlocalizable-fields.json"); DDMFormValues ddmFormValues = _ddmFormValuesJSONDeserializer.deserialize(null, serializedDDMFormValues); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals(2, ddmFormFieldValues.size()); DDMFormFieldValue booleanDDMFormFieldValue = ddmFormFieldValues.get(0); Assert.assertEquals("usht", booleanDDMFormFieldValue.getInstanceId()); Value booleanValue = booleanDDMFormFieldValue.getValue(); Assert.assertFalse(booleanValue.isLocalized()); Assert.assertEquals("false", booleanValue.getString(LocaleUtil.US)); Assert.assertEquals("false", booleanValue.getString(LocaleUtil.BRAZIL)); DDMFormFieldValue documentLibraryDDMFormFieldValue = ddmFormFieldValues.get(1); Assert.assertEquals("xdwp", documentLibraryDDMFormFieldValue.getInstanceId()); Value documentLibraryValue = documentLibraryDDMFormFieldValue.getValue(); Assert.assertFalse(documentLibraryValue.isLocalized()); JSONObject expectedJSONObject = JSONFactoryUtil.createJSONObject(); expectedJSONObject.put("groupId", 10192); expectedJSONObject.put("uuid", "c8acdf70-e101-46a6-83e5-c5f5e087b0dc"); expectedJSONObject.put("version", 1.0); JSONAssert.assertEquals( expectedJSONObject.toString(), documentLibraryValue.getString(LocaleUtil.US), false); JSONAssert.assertEquals( expectedJSONObject.toString(), documentLibraryValue.getString(LocaleUtil.BRAZIL), false); }