List of usage examples for com.liferay.portal.kernel.json JSONArray getString
public String getString(int index);
From source file:br.com.petrobras.ddm.type.region.internal.RegionDDMFormFieldValueRenderer.java
License:Open Source License
@Override public String render(DDMFormFieldValue ddmFormFieldValue, Locale locale) { System.out.println(this); JSONArray optionsValuesJSONArray = regionDDMFormFieldValueAccessor.getValue(ddmFormFieldValue, locale); DDMFormFieldOptions ddmFormFieldOptions = getDDMFormFieldOptions(ddmFormFieldValue); if (optionsValuesJSONArray.length() == 0) { return StringPool.BLANK; }/* www.j a v a 2 s .com*/ StringBundler sb = new StringBundler(optionsValuesJSONArray.length() * 2 - 1); for (int i = 0; i < optionsValuesJSONArray.length(); i++) { String optionValue = optionsValuesJSONArray.getString(i); if (isManualDataSourceType(ddmFormFieldValue.getDDMFormField())) { LocalizedValue optionLabel = ddmFormFieldOptions.getOptionLabels(optionValue); sb.append(optionLabel.getString(locale)); } else { sb.append(optionValue); } sb.append(StringPool.COMMA_AND_SPACE); } sb.setIndex(sb.index() - 1); return sb.toString(); }
From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAdaptiveMediaImageURLItemSelectorReturnTypeResolverTest.java
License:Open Source License
private void _assertAttibutes(JSONObject sourceJSONObject, int expectedMaxWidth, int expectedMinWidth) { JSONObject attributesJSONObject = sourceJSONObject.getJSONObject("attributes"); JSONArray attributeNamesJSONArray = attributesJSONObject.names(); boolean assertedMaxWidth = false; boolean assertedMinWidth = false; for (int i = 0; i < attributeNamesJSONArray.length(); i++) { String key = attributeNamesJSONArray.getString(i); Assert.assertTrue("Unexpected attribute found '" + key + "'", key.equals("max-width") || key.equals("min-width")); String value = attributesJSONObject.getString(key); if (key.equals("max-width")) { Assert.assertEquals(expectedMaxWidth + "px", value); assertedMaxWidth = true;//from www. j a v a 2 s.com } else if (key.equals("min-width")) { Assert.assertEquals(expectedMinWidth + "px", value); assertedMinWidth = true; } } Assert.assertTrue("Couldn't find expected max-width of '" + expectedMaxWidth + "' in '" + sourceJSONObject.toString() + "'", (expectedMaxWidth == 0) || assertedMaxWidth); Assert.assertTrue("Couldn't find expected min-width of '" + expectedMinWidth + "' in '" + sourceJSONObject.toString() + "'", (expectedMinWidth == 0) || assertedMinWidth); }
From source file:com.liferay.configuration.admin.web.internal.util.DDMFormValuesToPropertiesConverter.java
License:Open Source License
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 {/*from w w w.java 2 s . c o m*/ JSONArray jsonArray = _jsonFactory.createJSONArray(valueString); if (jsonArray.length() == 1) { valueString = jsonArray.getString(0); } } catch (JSONException jsone) { ReflectionUtil.throwException(jsone); } } String dataType = getDDMFormFieldDataType(ddmFormFieldValue.getName()); if (valueString.equals(StringPool.BLANK)) { valueString = getDataTypeDefaultValue(dataType); } return valueString; }
From source file:com.liferay.dynamic.data.lists.form.web.internal.converter.DDLFormRuleToDDMFormRuleConverterTest.java
License:Open Source License
@Test public void testAutoFillActions() throws Exception { JSONArray expectedDDMFormRulesJSONArray = jsonFactory .createJSONArray(read("ddm-form-rules-auto-fill-actions.json")); List<DDMFormRule> actualDDMFormRules = convert("ddl-form-rules-auto-fill-actions.json"); JSONArray actualDDMFormRulesJSONArray = jsonFactory.createJSONArray(serialize(actualDDMFormRules)); Assert.assertEquals(expectedDDMFormRulesJSONArray.length(), actualDDMFormRulesJSONArray.length()); JSONObject expectedAutoFillDDMRuleJSONObject = expectedDDMFormRulesJSONArray.getJSONObject(0); JSONObject actualAutoFillDDMRuleJSONObject = actualDDMFormRulesJSONArray.getJSONObject(0); Assert.assertEquals(expectedAutoFillDDMRuleJSONObject.get("condition"), actualAutoFillDDMRuleJSONObject.get("condition")); JSONArray expectedActionDDMRuleJSONArray = expectedAutoFillDDMRuleJSONObject.getJSONArray("actions"); JSONArray actualActionDDMRuleJSONArray = actualAutoFillDDMRuleJSONObject.getJSONArray("actions"); Assert.assertEquals(expectedActionDDMRuleJSONArray.length(), actualActionDDMRuleJSONArray.length()); String expectedCallFunction = expectedActionDDMRuleJSONArray.getString(0); String actualCallFunction = actualActionDDMRuleJSONArray.getString(0); List<String> expectedCallFunctionParameters = extractCallFunctionParameters(expectedCallFunction); List<String> actualCallFunctionParameters = extractCallFunctionParameters(actualCallFunction); String expectedDDMDataProviderInstanceUUID = expectedCallFunctionParameters.get(0); String actualDDMDataProviderInstanceUUID = actualCallFunctionParameters.get(0); Assert.assertEquals(expectedDDMDataProviderInstanceUUID, actualDDMDataProviderInstanceUUID); String expectedInputParametersExpression = expectedCallFunctionParameters.get(1); String actualInputParametersExpression = actualCallFunctionParameters.get(1); assertCallFunctionParametersExpression(expectedInputParametersExpression, actualInputParametersExpression); String expectedOutputParametersExpression = expectedCallFunctionParameters.get(2); String actualOutputParametersExpression = actualCallFunctionParameters.get(2); assertCallFunctionParametersExpression(expectedOutputParametersExpression, actualOutputParametersExpression); }
From source file:com.liferay.dynamic.data.mapping.form.builder.internal.context.DDMFormContextToDDMForm.java
License:Open Source License
protected Set<Locale> getAvailableLocales(JSONArray jsonArray) { Set<Locale> availableLocales = new HashSet<>(); for (int i = 0; i < jsonArray.length(); i++) { availableLocales.add(LocaleUtil.fromLanguageId(jsonArray.getString(i))); }/*from w w w . jav a2 s .c o m*/ return availableLocales; }
From source file:com.liferay.dynamic.data.mapping.form.builder.internal.converter.DDMFormRuleToDDMFormRuleModelConverterTest.java
License:Open Source License
@Test public void testAutoFillActions1() throws Exception { JSONArray expectedDDMFormRulesJSONArray = jsonFactory .createJSONArray(read("ddm-form-rules-model-auto-fill-actions.json")); List<com.liferay.dynamic.data.mapping.model.DDMFormRule> actualDDMFormRules = convert( "ddm-form-rules-auto-fill-actions.json"); JSONArray actualDDMFormRulesJSONArray = jsonFactory.createJSONArray(serialize(actualDDMFormRules)); Assert.assertEquals(expectedDDMFormRulesJSONArray.length(), actualDDMFormRulesJSONArray.length()); JSONObject expectedAutoFillDDMRuleJSONObject = expectedDDMFormRulesJSONArray.getJSONObject(0); JSONObject actualAutoFillDDMRuleJSONObject = actualDDMFormRulesJSONArray.getJSONObject(0); Assert.assertEquals(expectedAutoFillDDMRuleJSONObject.get("condition"), actualAutoFillDDMRuleJSONObject.get("condition")); JSONArray expectedActionDDMRuleJSONArray = expectedAutoFillDDMRuleJSONObject.getJSONArray("actions"); JSONArray actualActionDDMRuleJSONArray = actualAutoFillDDMRuleJSONObject.getJSONArray("actions"); Assert.assertEquals(expectedActionDDMRuleJSONArray.length(), actualActionDDMRuleJSONArray.length()); String expectedCallFunction = expectedActionDDMRuleJSONArray.getString(0); String actualCallFunction = actualActionDDMRuleJSONArray.getString(0); List<String> expectedCallFunctionParameters = extractCallFunctionParameters(expectedCallFunction); List<String> actualCallFunctionParameters = extractCallFunctionParameters(actualCallFunction); String expectedDDMDataProviderInstanceUUID = expectedCallFunctionParameters.get(0); String actualDDMDataProviderInstanceUUID = actualCallFunctionParameters.get(0); Assert.assertEquals(expectedDDMDataProviderInstanceUUID, actualDDMDataProviderInstanceUUID); String expectedInputParametersExpression = expectedCallFunctionParameters.get(1); String actualInputParametersExpression = actualCallFunctionParameters.get(1); assertCallFunctionParametersExpression(expectedInputParametersExpression, actualInputParametersExpression); String expectedOutputParametersExpression = expectedCallFunctionParameters.get(2); String actualOutputParametersExpression = actualCallFunctionParameters.get(2); assertCallFunctionParametersExpression(expectedOutputParametersExpression, actualOutputParametersExpression); }
From source file:com.liferay.dynamic.data.mapping.form.builder.internal.servlet.DDMDataProviderInstanceParameterSettingsServlet.java
License:Open Source License
protected String getType(String type) { try {/* www. j av a2s .co m*/ JSONArray typeJSONArray = _jsonFactory.createJSONArray(type); return typeJSONArray.getString(0); } catch (JSONException jsone) { if (_log.isDebugEnabled()) { _log.debug(jsone); } return type; } }
From source file:com.liferay.dynamic.data.mapping.form.evaluator.impl.internal.DDMFormEvaluatorHelper.java
License:Open Source License
protected String getJSONArrayValueString(String valueString) { try {/*w ww . j av a 2s .c o m*/ JSONArray jsonArray = _jsonFactory.createJSONArray(valueString); return jsonArray.getString(0); } catch (JSONException jsone) { // LPS-52675 if (_log.isDebugEnabled()) { _log.debug(jsone, jsone); } return valueString; } }
From source file:com.liferay.dynamic.data.mapping.form.evaluator.impl.internal.functions.CallFunction.java
License:Open Source License
protected String getOutputParameterType( DDMDataProviderOutputParametersSettings ddmDataProviderOutputParametersSettings) { String outputParameterType = ddmDataProviderOutputParametersSettings.outputParameterType(); try {//from w w w. j a v a 2 s . c om JSONArray jsonArray = _jsonFactory.createJSONArray(outputParameterType); return jsonArray.getString(0); } catch (JSONException jsone) { if (_log.isDebugEnabled()) { _log.debug(jsone, jsone); } } return outputParameterType; }
From source file:com.liferay.dynamic.data.mapping.form.evaluator.test.DDMFormFieldTypeSettingsEvaluatorTest.java
License:Open Source License
@Test public void testSelectCallGetDataProviderInstanceOutputParameters() throws Exception { List<DDMDataProviderOutputParametersSettings> outputParametersSettings = ListUtil.fromArray( new DDMDataProviderOutputParametersSettings[] { new DDMDataProviderOutputParametersSettings() { @Override/* w w w .j a v a2 s . c om*/ public String outputParameterName() { return "Countries"; } @Override public String outputParameterPath() { return "nameCurrentValue"; } @Override public String outputParameterType() { return "[\"list\"]"; } } }); DDMFormFieldEvaluationResult ddmDataProviderInstanceOutputFieldEvaluationResult = evaluateCallFunctionExpression( outputParametersSettings); JSONArray jsonArray = ddmDataProviderInstanceOutputFieldEvaluationResult.getValue(); Assert.assertEquals(1, jsonArray.length()); Assert.assertEquals("Countries", jsonArray.getString(0)); }