List of usage examples for com.liferay.portal.kernel.json JSONObject get
public Object get(String key);
From source file:com.liferay.adaptive.media.blogs.editor.configuration.internal.stat1c.StaticAdaptiveMediaBlogsEditorConfigContributorTest.java
License:Open Source License
@Test public void testAnyExtraPluginsArePreserved() throws Exception { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("extraPlugins", "testPlugin"); jsonObject.put("filebrowserImageBrowseLinkUrl", "browseLinkUrl"); Mockito.doReturn(Arrays.asList(_getItemSelectorCriterion(ImageItemSelectorCriterion.class))) .when(_itemSelector).getItemSelectorCriteria(Mockito.anyString()); PortletURL portletURL = Mockito.mock(PortletURL.class); Mockito.doReturn(portletURL).when(_itemSelector).getItemSelectorURL( Mockito.any(RequestBackedPortletURLFactory.class), Mockito.anyString(), Mockito.any(ItemSelectorCriterion[].class)); StaticAdaptiveMediaBlogsEditorConfigContributor staticAdaptiveMediaBlogsEditorConfigContributor = new StaticAdaptiveMediaBlogsEditorConfigContributor(); staticAdaptiveMediaBlogsEditorConfigContributor.setItemSelector(_itemSelector); staticAdaptiveMediaBlogsEditorConfigContributor.populateConfigJSONObject(jsonObject, _inputEditorTaglibAttributes, _themeDisplay, _requestBackedPortletURLFactory); Assert.assertEquals("testPlugin,adaptivemedia", jsonObject.get("extraPlugins")); }
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.data.provider.internal.DDMRESTDataProvider.java
License:Open Source License
protected DDMDataProviderResponse createDDMDataProviderResponse(JSONArray jsonArray, DDMDataProviderContext ddmDataProviderContext) { List<Map<Object, Object>> data = new ArrayList<>(); Set<String> outputParameterPaths = getOutputParameterPaths(ddmDataProviderContext); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Map<Object, Object> map = new HashMap<>(); data.add(map);/*from w w w . ja va 2s . c o m*/ for (String path : outputParameterPaths) { map.put(path, jsonObject.get(path)); } } return new DDMDataProviderResponse(data); }
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.io.internal.DDMFormValuesJSONDeserializerImpl.java
License:Open Source License
protected Value getValue(DDMFormField ddmFormField, JSONObject jsonObject) { DDMFormFieldValueJSONDeserializer ddmFormFieldValueJSONDeserializer = getDDMFormFieldValueJSONDeserializer( ddmFormField);//from www . j ava 2s .c o m if (ddmFormFieldValueJSONDeserializer != null) { return ddmFormFieldValueJSONDeserializer.deserialize(ddmFormField, String.valueOf(jsonObject.get("value"))); } JSONObject valueJSONObject = jsonObject.getJSONObject("value"); if (isLocalized(valueJSONObject)) { return getLocalizedValue(valueJSONObject); } else { return new UnlocalizedValue(jsonObject.getString("value")); } }
From source file:com.liferay.dynamic.data.mapping.type.document.library.internal.DocumentLibraryDDMFormFieldTemplateContextContributor.java
License:Open Source License
@Override public Map<String, Object> getParameters(DDMFormField ddmFormField, DDMFormFieldRenderingContext ddmFormFieldRenderingContext) { Map<String, Object> parameters = new HashMap<>(); HttpServletRequest request = ddmFormFieldRenderingContext.getHttpServletRequest(); if (ddmFormFieldRenderingContext.isReadOnly() && Validator.isNotNull(ddmFormFieldRenderingContext.getValue())) { JSONObject valueJSONObject = getValueJSONObject(ddmFormFieldRenderingContext.getValue()); if ((valueJSONObject != null) && (valueJSONObject.length() > 0)) { parameters.put("fileEntryTitle", valueJSONObject.get("title")); parameters.put("fileEntryURL", getFileEntryURL(request, valueJSONObject)); }//www .ja v a 2s . c o m } parameters.put("groupId", ddmFormFieldRenderingContext.getProperty("groupId")); parameters.put("lexiconIconsPath", getLexiconIconsPath(request)); Map<String, String> stringsMap = new HashMap<>(); ResourceBundle resourceBundle = getResourceBundle(ddmFormFieldRenderingContext.getLocale()); stringsMap.put("select", LanguageUtil.get(resourceBundle, "select")); parameters.put("strings", stringsMap); parameters.put("value", jsonFactory.looseDeserialize(ddmFormFieldRenderingContext.getValue())); return parameters; }
From source file:com.liferay.frontend.editor.alloyeditor.accessibility.web.internal.editor.configuration.AlloyEditorAccessibilityConfigContributor.java
License:Open Source License
@Override public void populateConfigJSONObject(JSONObject jsonObject, Map<String, Object> inputEditorTaglibAttributes, ThemeDisplay themeDisplay, RequestBackedPortletURLFactory requestBackedPortletURLFactory) { JSONObject toolbarsJSONObject = jsonObject.getJSONObject("toolbars"); if (toolbarsJSONObject == null) { toolbarsJSONObject = JSONFactoryUtil.createJSONObject(); }/*from ww w . ja v a 2 s . c om*/ JSONObject stylesJSONObject = toolbarsJSONObject.getJSONObject("styles"); if (stylesJSONObject == null) { stylesJSONObject = JSONFactoryUtil.createJSONObject(); } JSONArray selectionsJSONArray = stylesJSONObject.getJSONArray("selections"); for (int i = 0; i < selectionsJSONArray.length(); i++) { JSONObject selection = selectionsJSONArray.getJSONObject(i); if (Objects.equals(selection.get("name"), "image")) { JSONArray buttons = selection.getJSONArray("buttons"); buttons.put("imageAlt"); } } stylesJSONObject.put("selections", selectionsJSONArray); toolbarsJSONObject.put("styles", stylesJSONObject); jsonObject.put("toolbars", toolbarsJSONObject); }
From source file:com.liferay.journal.internal.exportimport.content.processor.ImageExportDDMFormFieldValueTransformer.java
License:Open Source License
@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; }// w ww . j a v a 2 s .com 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); } } }
From source file:com.liferay.journal.internal.exportimport.content.processor.JournalArticleArticleExportImportContentProcessor.java
License:Open Source License
protected String replaceExportJournalArticleReferences(PortletDataContext portletDataContext, JournalArticle article, String content, boolean exportReferencedContent) throws Exception { Group group = _groupLocalService.fetchGroup(portletDataContext.getGroupId()); if (group.isStagingGroup()) { group = group.getLiveGroup();// w w w .ja v a 2 s .c o m } if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(JournalPortletKeys.JOURNAL)) { return content; } StringBuilder sb = new StringBuilder(content); int beginPos = 0; int endPos = 0; while (true) { beginPos = sb.indexOf(_DDM_JOURNAL_ARTICLE_TYPE, endPos); if (beginPos == -1) { break; } endPos = beginPos; while (true) { beginPos = sb.indexOf(_CDATA_BEGIN, endPos); if (beginPos == -1) { break; } beginPos += _CDATA_BEGIN.length(); endPos = sb.indexOf(_CDATA_END, beginPos); String jsonData = sb.substring(beginPos, endPos); JSONObject jsonObject = _jsonFactory.createJSONObject(jsonData); long classPK = GetterUtil.getLong(jsonObject.get("classPK")); JournalArticle journalArticle = _journalArticleLocalService.fetchLatestArticle(classPK); if (journalArticle == null) { if (_log.isInfoEnabled()) { StringBundler messageSB = new StringBundler(); messageSB.append("Staged model with class name "); messageSB.append(article.getModelClassName()); messageSB.append(" and primary key "); messageSB.append(article.getPrimaryKeyObj()); messageSB.append(" references missing journal "); messageSB.append("article with class primary key "); messageSB.append(classPK); _log.info(messageSB.toString()); } continue; } String journalArticleReference = "[$journal-article-reference=" + journalArticle.getPrimaryKey() + "$]"; if (_log.isDebugEnabled()) { _log.debug("Replacing " + jsonData + " with " + journalArticleReference); } sb.replace(beginPos, endPos, journalArticleReference); endPos = beginPos + journalArticleReference.length(); if (exportReferencedContent) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, journalArticle, PortletDataContext.REFERENCE_TYPE_DEPENDENCY); } else { Element entityElement = portletDataContext.getExportDataElement(article); portletDataContext.addReferenceElement(article, entityElement, journalArticle, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); } } } return sb.toString(); }
From source file:com.liferay.journal.internal.exportimport.content.processor.JournalArticleArticleExportImportContentProcessor.java
License:Open Source License
protected void validateJournalArticleReferences(String content) throws PortalException { StringBuilder sb = new StringBuilder(content); int beginPos = 0; int endPos = 0; List<Throwable> throwables = new ArrayList<>(); while (true) { beginPos = sb.indexOf(_DDM_JOURNAL_ARTICLE_TYPE, endPos); if (beginPos == -1) { break; }/* w w w. j av a 2 s .c o m*/ endPos = beginPos; while (true) { beginPos = sb.indexOf(_CDATA_BEGIN, endPos); if (beginPos == -1) { break; } beginPos += _CDATA_BEGIN.length(); endPos = sb.indexOf(_CDATA_END, beginPos); String json = sb.substring(beginPos, endPos); if (Validator.isNull(json)) { if (_log.isDebugEnabled()) { _log.debug("No journal article reference is specified"); } continue; } JSONObject jsonObject = _jsonFactory.createJSONObject(json); long classPK = GetterUtil.getLong(jsonObject.get("classPK")); JournalArticle journalArticle = _journalArticleLocalService.fetchLatestArticle(classPK); if (journalArticle == null) { Throwable throwable = new NoSuchArticleException( "No JournalArticle exists with the key " + "{resourcePrimKey=" + classPK + "}"); throwables.add(throwable); } } } if (!throwables.isEmpty()) { throw new PortalException( new BulkException("Unable to validate journal article references", throwables)); } }