List of usage examples for com.liferay.portal.kernel.search BaseModelSearchResult getBaseModels
public List<T> getBaseModels()
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
private List<AssetEntryResult> _getAssetEntryResultsByClassName(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); int total = 0; for (long classNameId : classNameIds) { assetEntryQuery.setClassNameIds(new long[] { classNameId }); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);/*www . j a v a 2s .co m*/ int groupTotal = baseModelSearchResult.getLength(); total += groupTotal; List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < groupTotal)) { AssetRendererFactory<?> groupAssetRendererFactory = AssetRendererFactoryRegistryUtil .getAssetRendererFactoryByClassNameId(classNameId); String title = ResourceActionsUtil.getModelResource(locale, groupAssetRendererFactory.getClassName()); assetEntryResults.add(new AssetEntryResult(title, assetEntries)); } if (!portletName.equals(AssetPublisherPortletKeys.RECENT_CONTENT)) { if (groupTotal > 0) { if ((end > 0) && (end > groupTotal)) { end -= groupTotal; } else { end = 0; } if ((start > 0) && (start > groupTotal)) { start -= groupTotal; } else { start = 0; } } assetEntryQuery.setEnd(QueryUtil.ALL_POS); assetEntryQuery.setStart(QueryUtil.ALL_POS); } } searchContainer.setTotal(total); return assetEntryResults; }
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
private List<AssetEntryResult> _getAssetEntryResultsByDefault(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); assetEntryQuery.setClassNameIds(classNameIds); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);//from ww w . ja v a 2 s . co m int total = baseModelSearchResult.getLength(); searchContainer.setTotal(total); List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < total)) { assetEntryResults.add(new AssetEntryResult(assetEntries)); } return assetEntryResults; }
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 a v a 2 s.com 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.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java
License:Open Source License
protected void exportAssetObjects(PortletDataContext portletDataContext, PortletPreferences portletPreferences) throws Exception { List<AssetEntry> assetEntries = null; Layout layout = _layoutLocalService.getLayout(portletDataContext.getPlid()); String selectionStyle = portletPreferences.getValue("selectionStyle", "dynamic"); if (selectionStyle.equals("dynamic")) { if (!_assetPublisherWebConfiguration.dynamicExportEnabled()) { return; }/*from w w w. j av a2 s . c o m*/ AssetEntryQuery assetEntryQuery = getAssetEntryQuery(layout, portletDataContext.getCompanyGroupId(), portletDataContext.getScopeGroupId(), portletPreferences); long assetVocabularyId = GetterUtil.getLong(portletPreferences.getValue("assetVocabularyId", null)); if (assetVocabularyId > 0) { mergeAnyCategoryIds(assetEntryQuery, assetVocabularyId); if (ArrayUtil.isEmpty(assetEntryQuery.getAnyCategoryIds())) { return; } } BaseModelSearchResult<AssetEntry> baseModelSearchResult = AssetPublisherUtil.getAssetEntries( assetEntryQuery, layout, portletPreferences, AssetPublisherPortletKeys.ASSET_PUBLISHER, LocaleUtil.getDefault(), TimeZoneUtil.getDefault(), portletDataContext.getCompanyId(), portletDataContext.getScopeGroupId(), UserConstants.USER_ID_DEFAULT, new HashMap<String, Serializable>(), assetEntryQuery.getStart(), assetEntryQuery.getEnd()); assetEntries = baseModelSearchResult.getBaseModels(); } else { if (!_assetPublisherWebConfiguration.manualExportEnabled()) { return; } long[] groupIds = AssetPublisherUtil.getGroupIds(portletPreferences, portletDataContext.getScopeGroupId(), layout); assetEntries = AssetPublisherUtil.getAssetEntries(null, portletPreferences, PermissionThreadLocal.getPermissionChecker(), groupIds, false, false); } for (AssetEntry assetEntry : assetEntries) { AssetRenderer<?> assetRenderer = assetEntry.getAssetRenderer(); if ((assetRenderer == null) || !(assetRenderer.getAssetObject() instanceof StagedModel)) { continue; } StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, portletDataContext.getPortletId(), (StagedModel) assetRenderer.getAssetObject()); } }
From source file:com.liferay.asset.publisher.web.internal.messaging.AssetEntriesCheckerUtil.java
License:Open Source License
private List<AssetEntry> _getAssetEntries(PortletPreferences portletPreferences, Layout layout) throws PortalException { AssetPublisherWebConfiguration assetPublisherWebConfiguration = _configurationProvider .getCompanyConfiguration(AssetPublisherWebConfiguration.class, layout.getCompanyId()); AssetEntryQuery assetEntryQuery = AssetPublisherUtil.getAssetEntryQuery(portletPreferences, layout.getGroupId(), layout, null, null); assetEntryQuery.setEnd(assetPublisherWebConfiguration.dynamicSubscriptionLimit()); assetEntryQuery.setStart(0);//w ww. j a v a 2s . c o m try { SearchContext searchContext = SearchContextFactory.getInstance(new long[0], new String[0], null, layout.getCompanyId(), StringPool.BLANK, layout, LocaleThreadLocal.getSiteDefaultLocale(), layout.getGroupId(), TimeZoneThreadLocal.getDefaultTimeZone(), 0); BaseModelSearchResult<AssetEntry> baseModelSearchResult = _assetHelper.searchAssetEntries(searchContext, assetEntryQuery, 0, assetPublisherWebConfiguration.dynamicSubscriptionLimit()); return baseModelSearchResult.getBaseModels(); } catch (Exception e) { return Collections.emptyList(); } }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
protected static List<AssetEntryResult> getAssetEntryResultsByClassName(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); int total = 0; for (long classNameId : classNameIds) { assetEntryQuery.setClassNameIds(new long[] { classNameId }); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);//from w ww . ja va2 s . c o m int groupTotal = baseModelSearchResult.getLength(); total += groupTotal; List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < groupTotal)) { AssetRendererFactory<?> groupAssetRendererFactory = AssetRendererFactoryRegistryUtil .getAssetRendererFactoryByClassNameId(classNameId); String title = ResourceActionsUtil.getModelResource(locale, groupAssetRendererFactory.getClassName()); assetEntryResults.add(new AssetEntryResult(title, assetEntries)); } if (!portletName.equals(AssetPublisherPortletKeys.RECENT_CONTENT)) { if (groupTotal > 0) { if ((end > 0) && (end > groupTotal)) { end -= groupTotal; } else { end = 0; } if ((start > 0) && (start > groupTotal)) { start -= groupTotal; } else { start = 0; } } assetEntryQuery.setEnd(QueryUtil.ALL_POS); assetEntryQuery.setStart(QueryUtil.ALL_POS); } } searchContainer.setTotal(total); return assetEntryResults; }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
protected static List<AssetEntryResult> getAssetEntryResultsByDefault(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); assetEntryQuery.setClassNameIds(classNameIds); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);/*from w w w . j a v a 2 s. c o m*/ int total = baseModelSearchResult.getLength(); searchContainer.setTotal(total); List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < total)) { assetEntryResults.add(new AssetEntryResult(assetEntries)); } return assetEntryResults; }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
protected static 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);/* w ww . j a v a 2 s .co 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.search.test.AssetTagsSearchTest.java
License:Open Source License
@Test public void testPartialMatchSearch() throws Exception { List<String> searchAssetTags = Arrays.asList("tag1", "tag2", "tag3"); for (String assetTag : searchAssetTags) { AssetTagLocalServiceUtil.addTag(TestPropsValues.getUserId(), _group.getGroupId(), assetTag, _serviceContext);/*w w w .jav a 2 s.c o m*/ } BaseModelSearchResult<AssetTag> searchResult = AssetTagLocalServiceUtil .searchTags(new long[] { _group.getGroupId() }, "tag", 0, 20, null); List<AssetTag> assetTags = searchResult.getBaseModels(); Stream<AssetTag> assetTagsStream = assetTags.stream(); Stream<String> assetTagsNamesStream = assetTagsStream.map(assetTag -> assetTag.getName()); List<String> assetTagsNames = assetTagsNamesStream.collect(Collectors.toList()); Assert.assertTrue(assetTagsNames.containsAll(searchAssetTags)); }
From source file:com.liferay.asset.tags.admin.web.internal.display.context.AssetTagsDisplayContext.java
License:Open Source License
public SearchContainer getTagsSearchContainer() throws PortalException { if (_tagsSearchContainer != null) { return _tagsSearchContainer; }// w w w. j a v a 2 s. c o m SearchContainer tagsSearchContainer = new SearchContainer(_renderRequest, _renderResponse.createRenderURL(), null, "there-are-no-tags"); String keywords = getKeywords(); if (Validator.isNull(keywords)) { if (isShowAddButton()) { tagsSearchContainer.setEmptyResultsMessage("there-are-no-tags.-you-can-add-a-tag-by-clicking-the-" + "plus-button-on-the-bottom-right-corner"); tagsSearchContainer .setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn"); } } else { tagsSearchContainer.setSearch(true); } tagsSearchContainer.setRowChecker(new EmptyOnClickRowChecker(_renderResponse)); ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); if (Validator.isNotNull(keywords)) { Sort sort = null; String orderByCol = getOrderByCol(); if (orderByCol.equals("name")) { sort = SortFactoryUtil.getSort(AssetTag.class, Sort.STRING_TYPE, Field.NAME, getOrderByType()); } else if (orderByCol.equals("usages")) { sort = SortFactoryUtil.getSort(AssetTag.class, Sort.INT_TYPE, "assetCount_Number", getOrderByType()); } BaseModelSearchResult<AssetTag> baseModelSearchResult = AssetTagLocalServiceUtil.searchTags( new long[] { themeDisplay.getScopeGroupId() }, keywords, tagsSearchContainer.getStart(), tagsSearchContainer.getEnd(), sort); tagsSearchContainer.setResults(baseModelSearchResult.getBaseModels()); tagsSearchContainer.setTotal(baseModelSearchResult.getLength()); } else { String orderByCol = getOrderByCol(); tagsSearchContainer.setOrderByCol(orderByCol); OrderByComparator<AssetTag> orderByComparator = null; boolean orderByAsc = false; String orderByType = getOrderByType(); if (orderByType.equals("asc")) { orderByAsc = true; } if (orderByCol.equals("name")) { orderByComparator = new AssetTagNameComparator(orderByAsc); } else if (orderByCol.equals("usages")) { orderByComparator = new AssetTagAssetCountComparator(orderByAsc); } tagsSearchContainer.setOrderByComparator(orderByComparator); tagsSearchContainer.setOrderByType(orderByType); long scopeGroupId = themeDisplay.getScopeGroupId(); int tagsCount = AssetTagServiceUtil.getTagsCount(scopeGroupId, keywords); tagsSearchContainer.setTotal(tagsCount); List<AssetTag> tags = AssetTagServiceUtil.getTags(scopeGroupId, StringPool.BLANK, tagsSearchContainer.getStart(), tagsSearchContainer.getEnd(), tagsSearchContainer.getOrderByComparator()); tagsSearchContainer.setResults(tags); } _tagsSearchContainer = tagsSearchContainer; return _tagsSearchContainer; }