List of usage examples for com.liferay.portal.kernel.util ArrayUtil append
public static <T> T[][] append(T[][] array1, T[][] array2)
From source file:com.liferay.asset.categories.admin.web.internal.exportimport.data.handler.AssetVocabularySettingsExportHelper.java
License:Open Source License
protected JSONObject createSettingsMetadataJSONObject() throws PortalException { JSONObject settingsMetadataJSONObject = _jsonFactory.createJSONObject(); String settings = getSettings(); if (Validator.isNotNull(settings)) { String[] classNameIdsAndClassTypePKs = ArrayUtil.append(getRequiredClassNameIdsAndClassTypePKs(), getClassNameIdsAndClassTypePKs()); for (String classNameIdAndClassTypePK : classNameIdsAndClassTypePKs) { long classNameId = getClassNameId(classNameIdAndClassTypePK); if (classNameId == AssetCategoryConstants.ALL_CLASS_NAME_ID) { continue; }/*w ww. j a v a 2s .c o m*/ long classTypePK = getClassTypePK(classNameIdAndClassTypePK); JSONObject classTypeJSONObject = getClassTypeJSONObject(settingsMetadataJSONObject, classNameId); putClassTypeJSONObject(classTypeJSONObject, classNameId, classTypePK); } } return settingsMetadataJSONObject; }
From source file:com.liferay.asset.categories.admin.web.internal.exportimport.data.handler.AssetVocabularySettingsImportHelper.java
License:Open Source License
protected void fillClassNameIdsAndClassTypePKs(String[] classNameIdsAndClassTypePKs, boolean required) { for (String classNameIdAndClassTypePK : classNameIdsAndClassTypePKs) { long oldClassNameId = getClassNameId(classNameIdAndClassTypePK); if (!existClassName(oldClassNameId)) { continue; }/*from www .j a va 2 s .c om*/ long newClassNameId = getNewClassNameId(oldClassNameId); _classNameIds = ArrayUtil.append(_classNameIds, newClassNameId); long oldClassTypePK = getClassTypePK(classNameIdAndClassTypePK); long newClassTypePK = getNewClassTypePK(oldClassNameId, newClassNameId, oldClassTypePK); _classTypePKs = ArrayUtil.append(_classTypePKs, newClassTypePK); _requireds = ArrayUtil.append(_requireds, required); } }
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
@Override public long[] getAssetCategoryIds(PortletPreferences portletPreferences) { long[] assetCategoryIds = new long[0]; for (int i = 0; true; i++) { String[] queryValues = portletPreferences.getValues("queryValues" + i, null); if (ArrayUtil.isEmpty(queryValues)) { break; }/* w w w . ja v a2 s .co m*/ boolean queryContains = GetterUtil .getBoolean(portletPreferences.getValue("queryContains" + i, StringPool.BLANK)); boolean queryAndOperator = GetterUtil .getBoolean(portletPreferences.getValue("queryAndOperator" + i, StringPool.BLANK)); String queryName = portletPreferences.getValue("queryName" + i, StringPool.BLANK); if (Objects.equals(queryName, "assetCategories") && queryContains && (queryAndOperator || (queryValues.length == 1))) { assetCategoryIds = ArrayUtil.append(assetCategoryIds, GetterUtil.getLongValues(queryValues)); } } return assetCategoryIds; }
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
private List<AssetEntryResult> _getAssetEntryResultsByVocabulary(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, long assetVocabularyId, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); List<AssetCategory> assetCategories = _assetCategoryLocalService .getVocabularyRootCategories(assetVocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); assetEntryQuery.setClassNameIds(classNameIds); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); int total = 0; for (AssetCategory assetCategory : assetCategories) { long[] oldAllCategoryIds = assetEntryQuery.getAllCategoryIds(); long[] newAllAssetCategoryIds = ArrayUtil.append(oldAllCategoryIds, assetCategory.getCategoryId()); assetEntryQuery.setAllCategoryIds(newAllAssetCategoryIds); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);//from ww w .j ava 2s . c o m int groupTotal = baseModelSearchResult.getLength(); total += groupTotal; List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < groupTotal)) { String title = assetCategory.getTitle(locale); assetEntryResults.add(new AssetEntryResult(title, assetEntries)); } if (groupTotal > 0) { if ((end > 0) && (end > groupTotal)) { end -= groupTotal; } else { end = 0; } if ((start > 0) && (start > groupTotal)) { start -= groupTotal; } else { start = 0; } } assetEntryQuery.setAllCategoryIds(oldAllCategoryIds); assetEntryQuery.setEnd(QueryUtil.ALL_POS); assetEntryQuery.setStart(QueryUtil.ALL_POS); } searchContainer.setTotal(total); return assetEntryResults; }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
protected void testExportImportAssetEntries(List<Group> scopeGroups) throws Exception { List<AssetEntry> assetEntries = new ArrayList<>(); String[] scopeIds = new String[0]; for (Group scopeGroup : scopeGroups) { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); if (scopeGroup.isLayout()) { // Creating structures and templates in layout scope group is // not possible Company company = CompanyLocalServiceUtil.getCompany(layout.getCompanyId()); serviceContext.setAttribute("ddmGroupId", company.getGroupId()); }/* w ww.j a v a 2 s . c o m*/ assetEntries = addAssetEntries(scopeGroup, 3, assetEntries, serviceContext); String scopeId = _assetPublisherHelper.getScopeId(scopeGroup, group.getGroupId()); scopeIds = ArrayUtil.append(scopeIds, scopeId); } Map<String, String[]> preferenceMap = new HashMap<>(); preferenceMap.put("assetEntryXml", getAssetEntriesXmls(assetEntries)); preferenceMap.put("scopeIds", scopeIds); PortletPreferences importedPortletPreferences = getImportedPortletPreferences(preferenceMap); String[] importedScopeIds = importedPortletPreferences.getValues("scopeIds", null); long[] selectedGroupIds = getGroupIdsFromScopeIds(importedScopeIds, importedLayout); List<AssetEntry> actualAssetEntries = _assetPublisherHelper.getAssetEntries(new MockPortletRequest(), importedPortletPreferences, _permissionChecker, selectedGroupIds, false, false); assertAssetEntries(assetEntries, actualAssetEntries); }
From source file:com.liferay.asset.publisher.service.test.AssetPublisherServiceTest.java
License:Open Source License
protected void addAssetCategories(long vocabularyId) throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); for (String assetCategoryName : _ASSET_CATEGORY_NAMES) { AssetCategory assetCategory = AssetCategoryLocalServiceUtil.addCategory(TestPropsValues.getUserId(), serviceContext.getScopeGroupId(), assetCategoryName, vocabularyId, serviceContext); _assetCategoryIds = ArrayUtil.append(_assetCategoryIds, assetCategory.getCategoryId()); }//from w w w . ja v a 2 s . c o m }
From source file:com.liferay.asset.publisher.service.test.AssetPublisherServiceTest.java
License:Open Source License
protected List<AssetEntry> addAssetEntries(long[] assetCategoryIds, String[] assetTagNames, int count, boolean manualMode) throws Exception { List<AssetEntry> assetEntries = new ArrayList<>(); for (int i = 0; i < count; i++) { JournalArticle article = JournalTestUtil.addArticle(_group.getGroupId(), RandomTestUtil.randomString(), RandomTestUtil.randomString(100)); JournalArticleLocalServiceUtil.updateAsset(TestPropsValues.getUserId(), article, assetCategoryIds, assetTagNames, null, null); AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), article.getResourcePrimKey()); assetEntries.add(assetEntry);/*from w ww . j a v a2 s . co m*/ if (manualMode) { _assetEntryXmls = ArrayUtil.append(_assetEntryXmls, AssetPublisherTestUtil.getAssetEntryXml(assetEntry)); } } return assetEntries; }
From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java
License:Open Source License
public long[] getAllAssetCategoryIds() throws Exception { if (_allAssetCategoryIds != null) { return _allAssetCategoryIds; }/*from w w w .ja v a 2 s.c o m*/ _allAssetCategoryIds = new long[0]; long assetCategoryId = ParamUtil.getLong(_request, "categoryId"); String selectionStyle = getSelectionStyle(); if (selectionStyle.equals("dynamic")) { _allAssetCategoryIds = AssetPublisherUtil.getAssetCategoryIds(_portletPreferences); } if ((assetCategoryId > 0) && !ArrayUtil.contains(_allAssetCategoryIds, assetCategoryId)) { _allAssetCategoryIds = ArrayUtil.append(_allAssetCategoryIds, assetCategoryId); } return _allAssetCategoryIds; }
From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java
License:Open Source License
public String[] getAllAssetTagNames() throws Exception { if (_allAssetTagNames != null) { return _allAssetTagNames; }/* www. j ava 2 s. c o m*/ _allAssetTagNames = new String[0]; String assetTagName = ParamUtil.getString(_request, "tag"); String selectionStyle = getSelectionStyle(); if (selectionStyle.equals("dynamic")) { _allAssetTagNames = AssetPublisherUtil.getAssetTagNames(_portletPreferences); } if (Validator.isNotNull(assetTagName) && !ArrayUtil.contains(_allAssetTagNames, assetTagName)) { _allAssetTagNames = ArrayUtil.append(_allAssetTagNames, assetTagName); } if (isMergeURLTags()) { _allAssetTagNames = ArrayUtil.append(_allAssetTagNames, getCompilerTagNames()); } _allAssetTagNames = ArrayUtil.distinct(_allAssetTagNames, new StringComparator()); return _allAssetTagNames; }
From source file:com.liferay.asset.publisher.web.display.context.AssetPublisherDisplayContext.java
License:Open Source License
public JSONArray getAutoFieldRulesJSONArray() { ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); String queryLogicIndexesParam = ParamUtil.getString(_request, "queryLogicIndexes"); int[] queryLogicIndexes = null; if (Validator.isNotNull(queryLogicIndexesParam)) { queryLogicIndexes = StringUtil.split(queryLogicIndexesParam, 0); } else {/* w ww .j a va 2s . c o m*/ queryLogicIndexes = new int[0]; for (int i = 0; true; i++) { String queryValues = PrefsParamUtil.getString(_portletPreferences, _request, "queryValues" + i); if (Validator.isNull(queryValues)) { break; } queryLogicIndexes = ArrayUtil.append(queryLogicIndexes, i); } if (queryLogicIndexes.length == 0) { queryLogicIndexes = ArrayUtil.append(queryLogicIndexes, -1); } } JSONArray rulesJSONArray = JSONFactoryUtil.createJSONArray(); for (int queryLogicIndex : queryLogicIndexes) { JSONObject ruleJSONObject = JSONFactoryUtil.createJSONObject(); boolean queryAndOperator = PrefsParamUtil.getBoolean(_portletPreferences, _request, "queryAndOperator" + queryLogicIndex); ruleJSONObject.put("queryAndOperator", queryAndOperator); boolean queryContains = PrefsParamUtil.getBoolean(_portletPreferences, _request, "queryContains" + queryLogicIndex, true); ruleJSONObject.put("queryContains", queryContains); String queryValues = StringUtil .merge(_portletPreferences.getValues("queryValues" + queryLogicIndex, new String[0])); String queryName = PrefsParamUtil.getString(_portletPreferences, _request, "queryName" + queryLogicIndex, "assetTags"); if (Objects.equals(queryName, "assetTags")) { queryValues = ParamUtil.getString(_request, "queryTagNames" + queryLogicIndex, queryValues); queryValues = _assetPublisherWebUtil.filterAssetTagNames(themeDisplay.getScopeGroupId(), queryValues); } else { queryValues = ParamUtil.getString(_request, "queryCategoryIds" + queryLogicIndex, queryValues); JSONArray categoryIdsTitles = JSONFactoryUtil.createJSONArray(); long[] categoryIds = GetterUtil.getLongValues(queryValues.split(",")); for (long categoryId : categoryIds) { AssetCategory category = AssetCategoryLocalServiceUtil.fetchAssetCategory(categoryId); categoryIdsTitles.put(category.getTitle(themeDisplay.getLocale())); } ruleJSONObject.put("categoryIdsTitles", categoryIdsTitles); } ruleJSONObject.put("queryValues", queryValues); ruleJSONObject.put("type", queryName); rulesJSONArray.put(ruleJSONObject); } return rulesJSONArray; }