/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.asset.tags.selector.web.internal.display.context; import com.liferay.asset.kernel.model.AssetTag; import com.liferay.asset.kernel.service.AssetTagServiceUtil; import com.liferay.asset.tags.selector.web.internal.search.EntriesChecker; import com.liferay.portal.kernel.dao.search.SearchContainer; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.theme.ThemeDisplay; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.util.WebKeys; import com.liferay.portlet.asset.util.comparator.AssetTagNameComparator; import java.util.List; import javax.portlet.PortletURL; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.servlet.http.HttpServletRequest; /** * @author Eudaldo Alonso */ public class AssetTagsSelectorDisplayContext { public AssetTagsSelectorDisplayContext( RenderRequest renderRequest, RenderResponse renderResponse, HttpServletRequest request) { _renderRequest = renderRequest; _renderResponse = renderResponse; _request = request; } public String getDisplayStyle() { if (Validator.isNotNull(_displayStyle)) { return _displayStyle; } _displayStyle = ParamUtil.getString(_request, "displayStyle", "list"); return _displayStyle; } public String getEventName() { if (Validator.isNotNull(_eventName)) { return _eventName; } _eventName = ParamUtil.getString( _request, "eventName", _renderResponse.getNamespace() + "selectTag"); return _eventName; } public String getKeywords() { if (Validator.isNotNull(_keywords)) { return _keywords; } _keywords = ParamUtil.getString(_request, "keywords", null); return _keywords; } public String getOrderByCol() { if (Validator.isNotNull(_orderByCol)) { return _orderByCol; } _orderByCol = ParamUtil.getString(_request, "orderByCol", "name"); return _orderByCol; } public String getOrderByType() { if (Validator.isNotNull(_orderByType)) { return _orderByType; } _orderByType = ParamUtil.getString(_request, "orderByType", "asc"); return _orderByType; } public PortletURL getPortletURL() { PortletURL portletURL = _renderResponse.createRenderURL(); portletURL.setParameter("eventName", getEventName()); return portletURL; } public SearchContainer getTagsSearchContainer() { if (_tagsSearchContainer != null) { return _tagsSearchContainer; } ThemeDisplay themeDisplay = (ThemeDisplay)_request.getAttribute( WebKeys.THEME_DISPLAY); SearchContainer tagsSearchContainer = new SearchContainer( _renderRequest, getPortletURL(), null, "there-are-no-tags"); String keywords = getKeywords(); if (Validator.isNotNull(keywords)) { tagsSearchContainer.setSearch(true); } String orderByCol = getOrderByCol(); tagsSearchContainer.setOrderByCol(orderByCol); boolean orderByAsc = false; String orderByType = getOrderByType(); if (orderByType.equals("asc")) { orderByAsc = true; } tagsSearchContainer.setOrderByComparator( new AssetTagNameComparator(orderByAsc)); tagsSearchContainer.setOrderByType(orderByType); tagsSearchContainer.setRowChecker( new EntriesChecker(_renderRequest, _renderResponse)); int tagsCount = AssetTagServiceUtil.getTagsCount( themeDisplay.getScopeGroupId(), keywords); tagsSearchContainer.setTotal(tagsCount); List<AssetTag> tags = AssetTagServiceUtil.getTags( themeDisplay.getScopeGroupId(), keywords, tagsSearchContainer.getStart(), tagsSearchContainer.getEnd(), tagsSearchContainer.getOrderByComparator()); tagsSearchContainer.setResults(tags); _tagsSearchContainer = tagsSearchContainer; return _tagsSearchContainer; } public boolean isDisabledTagsManagementBar() throws PortalException { SearchContainer tagsSearchContainer = getTagsSearchContainer(); if (tagsSearchContainer.getTotal() <= 0) { return true; } return false; } public boolean isShowTagsSearch() throws PortalException { if (Validator.isNotNull(getKeywords())) { return true; } SearchContainer tagsSearchContainer = getTagsSearchContainer(); if (tagsSearchContainer.getTotal() > 0) { return true; } return false; } private String _displayStyle; private String _eventName; private String _keywords; private String _orderByCol; private String _orderByType; private final RenderRequest _renderRequest; private final RenderResponse _renderResponse; private final HttpServletRequest _request; private SearchContainer _tagsSearchContainer; }