com.liferay.journal.web.internal.display.context.JournalDisplayContext Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.journal.web.internal.display.context;
import com.liferay.asset.display.page.portlet.AssetDisplayPageFriendlyURLProvider;
import com.liferay.asset.kernel.model.AssetEntry;
import com.liferay.asset.kernel.service.AssetEntryLocalServiceUtil;
import com.liferay.depot.util.SiteConnectedGroupGroupProviderUtil;
import com.liferay.dynamic.data.mapping.item.selector.DDMStructureItemSelectorReturnType;
import com.liferay.dynamic.data.mapping.item.selector.criterion.DDMStructureItemSelectorCriterion;
import com.liferay.dynamic.data.mapping.model.DDMStructure;
import com.liferay.dynamic.data.mapping.service.DDMStructureLocalServiceUtil;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.DropdownItem;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.NavigationItem;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.NavigationItemListBuilder;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.TabsItem;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.TabsItemList;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.TabsItemListBuilder;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.VerticalNavItemList;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.VerticalNavItemListBuilder;
import com.liferay.item.selector.ItemSelector;
import com.liferay.journal.configuration.JournalServiceConfiguration;
import com.liferay.journal.constants.JournalArticleConstants;
import com.liferay.journal.constants.JournalFolderConstants;
import com.liferay.journal.constants.JournalPortletKeys;
import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.model.JournalArticleDisplay;
import com.liferay.journal.model.JournalFolder;
import com.liferay.journal.service.JournalArticleLocalServiceUtil;
import com.liferay.journal.service.JournalArticleServiceUtil;
import com.liferay.journal.service.JournalFolderLocalServiceUtil;
import com.liferay.journal.service.JournalFolderServiceUtil;
import com.liferay.journal.util.JournalHelper;
import com.liferay.journal.util.comparator.FolderArticleArticleIdComparator;
import com.liferay.journal.util.comparator.FolderArticleCreateDateComparator;
import com.liferay.journal.util.comparator.FolderArticleDisplayDateComparator;
import com.liferay.journal.util.comparator.FolderArticleModifiedDateComparator;
import com.liferay.journal.util.comparator.FolderArticleTitleComparator;
import com.liferay.journal.web.internal.asset.model.JournalArticleAssetRenderer;
import com.liferay.journal.web.internal.configuration.JournalWebConfiguration;
import com.liferay.journal.web.internal.constants.JournalWebConstants;
import com.liferay.journal.web.internal.dao.search.JournalRecentArticlesResultRowSplitter;
import com.liferay.journal.web.internal.dao.search.JournalResultRowSplitter;
import com.liferay.journal.web.internal.portlet.action.ActionUtil;
import com.liferay.journal.web.internal.search.EntriesChecker;
import com.liferay.journal.web.internal.search.EntriesMover;
import com.liferay.journal.web.internal.security.permission.resource.JournalArticlePermission;
import com.liferay.journal.web.internal.security.permission.resource.JournalFolderPermission;
import com.liferay.journal.web.internal.servlet.taglib.util.JournalArticleActionDropdownItemsProvider;
import com.liferay.journal.web.internal.servlet.taglib.util.JournalFolderActionDropdownItems;
import com.liferay.journal.web.internal.util.DDMStructureUtil;
import com.liferay.journal.web.internal.util.JournalPortletUtil;
import com.liferay.journal.web.internal.util.JournalSearcherUtil;
import com.liferay.journal.web.internal.util.JournalUtil;
import com.liferay.message.boards.model.MBMessage;
import com.liferay.message.boards.service.MBMessageLocalServiceUtil;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.petra.string.StringUtil;
import com.liferay.portal.configuration.module.configuration.ConfigurationProviderUtil;
import com.liferay.portal.kernel.bean.BeanParamUtil;
import com.liferay.portal.kernel.dao.search.ResultRowSplitter;
import com.liferay.portal.kernel.dao.search.SearchContainer;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.json.JSONUtil;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.ResourceConstants;
import com.liferay.portal.kernel.model.Role;
import com.liferay.portal.kernel.model.role.RoleConstants;
import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.portlet.PortalPreferences;
import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil;
import com.liferay.portal.kernel.portlet.PortletRequestModel;
import com.liferay.portal.kernel.portlet.RequestBackedPortletURLFactory;
import com.liferay.portal.kernel.portlet.RequestBackedPortletURLFactoryUtil;
import com.liferay.portal.kernel.portlet.url.builder.PortletURLBuilder;
import com.liferay.portal.kernel.search.BooleanClause;
import com.liferay.portal.kernel.search.BooleanClauseFactoryUtil;
import com.liferay.portal.kernel.search.BooleanClauseOccur;
import com.liferay.portal.kernel.search.BooleanQuery;
import com.liferay.portal.kernel.search.Document;
import com.liferay.portal.kernel.search.Field;
import com.liferay.portal.kernel.search.Hits;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.IndexerRegistryUtil;
import com.liferay.portal.kernel.search.QueryConfig;
import com.liferay.portal.kernel.search.SearchContext;
import com.liferay.portal.kernel.search.SearchContextFactory;
import com.liferay.portal.kernel.search.Sort;
import com.liferay.portal.kernel.search.filter.BooleanFilter;
import com.liferay.portal.kernel.search.filter.Filter;
import com.liferay.portal.kernel.search.generic.BooleanQueryImpl;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.service.ResourcePermissionLocalService;
import com.liferay.portal.kernel.service.RoleLocalService;
import com.liferay.portal.kernel.service.permission.GroupPermissionUtil;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ArrayUtil;
import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.HashMapBuilder;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.LinkedHashMapBuilder;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.search.searcher.SearchResponse;
import com.liferay.portal.servlet.BrowserSnifferUtil;
import com.liferay.staging.StagingGroupHelper;
import com.liferay.staging.StagingGroupHelperUtil;
import com.liferay.trash.TrashHelper;
import java.io.Serializable;
import java.text.Format;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.PortletURL;
import javax.servlet.http.HttpServletRequest;
/**
* @author Eudaldo Alonso
*/
public class JournalDisplayContext {
public static JournalDisplayContext create(
AssetDisplayPageFriendlyURLProvider assetDisplayPageFriendlyURLProvider,
ItemSelector itemSelector, JournalHelper journalHelper,
JournalWebConfiguration journalWebConfiguration,
PortletRequest portletRequest, PortletResponse portletResponse,
ResourcePermissionLocalService resourcePermissionLocalService,
RoleLocalService roleLocalService, TrashHelper trashHelper) {
JournalDisplayContext journalDisplayContext =
(JournalDisplayContext)portletRequest.getAttribute(
JournalWebConstants.JOURNAL_DISPLAY_CONTEXT);
if (journalDisplayContext == null) {
journalDisplayContext = new JournalDisplayContext(
assetDisplayPageFriendlyURLProvider, itemSelector,
journalHelper, journalWebConfiguration, portletRequest,
portletResponse, resourcePermissionLocalService,
roleLocalService, trashHelper);
portletRequest.setAttribute(
JournalWebConstants.JOURNAL_DISPLAY_CONTEXT,
journalDisplayContext);
}
return journalDisplayContext;
}
public long[] getAddMenuFavItems() throws PortalException {
if (_addMenuFavItems != null) {
return _addMenuFavItems;
}
PortalPreferences portalPreferences =
PortletPreferencesFactoryUtil.getPortalPreferences(
_httpServletRequest);
List addMenuFavItemsList = new ArrayList<>();
String[] addMenuFavItems = portalPreferences.getValues(
JournalPortletKeys.JOURNAL,
JournalPortletUtil.getAddMenuFavItemKey(
_journalHelper, _liferayPortletRequest),
new String[0]);
for (DDMStructure ddmStructure : getDDMStructures()) {
if (ArrayUtil.contains(
addMenuFavItems,
String.valueOf(ddmStructure.getStructureId()))) {
addMenuFavItemsList.add(ddmStructure.getStructureId());
}
}
_addMenuFavItems = ArrayUtil.toLongArray(addMenuFavItemsList);
return _addMenuFavItems;
}
public int getAddMenuFavItemsLength() throws PortalException {
long[] addMenuFavItems = getAddMenuFavItems();
return addMenuFavItems.length;
}
public JournalArticle getArticle() throws PortalException {
if (_article != null) {
return _article;
}
_article = ActionUtil.getArticle(_httpServletRequest);
return _article;
}
public List getArticleActionDropdownItems(
JournalArticle article)
throws Exception {
JournalArticleActionDropdownItemsProvider
articleActionDropdownItemsProvider =
new JournalArticleActionDropdownItemsProvider(
article, _liferayPortletRequest, _liferayPortletResponse,
_assetDisplayPageFriendlyURLProvider, _trashHelper);
return articleActionDropdownItemsProvider.getActionDropdownItems();
}
public JournalArticleDisplay getArticleDisplay() throws Exception {
if (_articleDisplay != null) {
return _articleDisplay;
}
JournalArticle article = JournalArticleLocalServiceUtil.fetchArticle(
ParamUtil.getLong(_httpServletRequest, "groupId"),
ParamUtil.getString(_httpServletRequest, "articleId"),
ParamUtil.getDouble(_httpServletRequest, "version"));
if (article == null) {
return _articleDisplay;
}
_articleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(
article, article.getDDMTemplateKey(), null,
_themeDisplay.getLanguageId(),
ParamUtil.getInteger(_httpServletRequest, "page"),
new PortletRequestModel(
_liferayPortletRequest, _liferayPortletResponse),
_themeDisplay);
return _articleDisplay;
}
public List getArticleHistoryActionDropdownItems(
JournalArticle article)
throws Exception {
JournalArticleActionDropdownItemsProvider
articleActionDropdownItemsProvider =
new JournalArticleActionDropdownItemsProvider(
article, _liferayPortletRequest, _liferayPortletResponse,
_assetDisplayPageFriendlyURLProvider, _trashHelper);
return articleActionDropdownItemsProvider.
getArticleHistoryActionDropdownItems();
}
public List getArticleInfoPanelDropdownItems(
JournalArticle article)
throws Exception {
return getArticleActionDropdownItems(article);
}
public String getArticleSubtitle(JournalArticle article) {
if (isNavigationMine() || isNavigationRecent()) {
return _getSubtitle(
article.getCreateDate(), "created-x-ago-by-x",
article.getUserName());
}
return _getSubtitle(
article.getModifiedDate(), "modified-x-ago-by-x",
article.getStatusByUserName());
}
public List getArticleVersionActionDropdownItems(
JournalArticle article)
throws Exception {
JournalArticleActionDropdownItemsProvider
articleActionDropdownItemsProvider =
new JournalArticleActionDropdownItemsProvider(
article, _liferayPortletRequest, _liferayPortletResponse,
_assetDisplayPageFriendlyURLProvider, _trashHelper);
return articleActionDropdownItemsProvider.
getArticleVersionActionDropdownItems();
}
public String getAvailableActions(JournalArticle article)
throws PortalException {
List availableActions = new ArrayList<>();
PermissionChecker permissionChecker =
_themeDisplay.getPermissionChecker();
if (JournalArticlePermission.contains(
permissionChecker, article, ActionKeys.DELETE)) {
availableActions.add("deleteEntries");
}
if (JournalArticlePermission.contains(
permissionChecker, article, ActionKeys.PERMISSIONS)) {
availableActions.add("changePermissions");
}
long scopeGroupId = _themeDisplay.getScopeGroupId();
StagingGroupHelper stagingGroupHelper =
StagingGroupHelperUtil.getStagingGroupHelper();
try {
if (GroupPermissionUtil.contains(
permissionChecker, scopeGroupId,
ActionKeys.EXPORT_IMPORT_PORTLET_INFO) &&
stagingGroupHelper.isStagingGroup(scopeGroupId) &&
stagingGroupHelper.isStagedPortlet(
scopeGroupId, JournalPortletKeys.JOURNAL)) {
availableActions.add("publishEntriesToLive");
}
}
catch (PortalException portalException) {
if (_log.isDebugEnabled()) {
_log.debug(
"An exception occured when checking if the publish " +
"action should be displayed",
portalException);
}
}
if (JournalArticlePermission.contains(
permissionChecker, article, ActionKeys.EXPIRE) &&
(article.getStatus() == WorkflowConstants.STATUS_APPROVED)) {
availableActions.add("expireEntries");
}
if (JournalArticlePermission.contains(
permissionChecker, article, ActionKeys.UPDATE)) {
availableActions.add("moveEntries");
}
if (JournalArticlePermission.contains(
permissionChecker, article, ActionKeys.VIEW)) {
availableActions.add("exportTranslation");
}
return StringUtil.merge(availableActions, StringPool.COMMA);
}
public String getAvailableActions(JournalFolder folder)
throws PortalException {
List availableActions = new ArrayList<>();
if (JournalFolderPermission.contains(
_themeDisplay.getPermissionChecker(), folder,
ActionKeys.UPDATE)) {
availableActions.add("deleteEntries");
}
if (JournalFolderPermission.contains(
_themeDisplay.getPermissionChecker(), folder,
ActionKeys.DELETE)) {
availableActions.add("moveEntries");
}
return StringUtil.merge(availableActions, StringPool.COMMA);
}
public String[] getCharactersBlacklist() throws PortalException {
JournalServiceConfiguration journalServiceConfiguration =
ConfigurationProviderUtil.getCompanyConfiguration(
JournalServiceConfiguration.class,
_themeDisplay.getCompanyId());
return journalServiceConfiguration.charactersblacklist();
}
public int getCommentsTotal() throws PortalException {
SearchContainer commentsSearchContainer =
_getCommentsSearchContainer();
return commentsSearchContainer.getTotal();
}
public Map getComponentContext() throws Exception {
return Collections.singletonMap(
"trashEnabled",
_trashHelper.isTrashEnabled(_themeDisplay.getScopeGroupId()));
}
public List getConfigurationTabsItems() {
TabsItemList tabsItemList = TabsItemListBuilder.add(
tabsItem -> {
tabsItem.setActive(true);
tabsItem.setLabel(
LanguageUtil.get(_httpServletRequest, "email-from"));
}
).add(
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(
_httpServletRequest, "web-content-added-email"))
).add(
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(
_httpServletRequest, "web-content-expired-email"))
).add(
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(
_httpServletRequest, "web-content-moved-from-folder-email"))
).add(
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(
_httpServletRequest, "web-content-moved-to-folder-email"))
).add(
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(
_httpServletRequest, "web-content-review-email"))
).add(
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(
_httpServletRequest, "web-content-updated-email"))
).build();
if (JournalUtil.hasWorkflowDefinitionsLinks(_themeDisplay)) {
tabsItemList.add(
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(
_httpServletRequest,
"web-content-approval-denied-email")));
tabsItemList.add(
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(
_httpServletRequest,
"web-content-approval-granted-email")));
tabsItemList.add(
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(
_httpServletRequest,
"web-content-approval-requested-email")));
}
return tabsItemList;
}
public long getDDMStructureId() {
if (_ddmStructureId != null) {
return _ddmStructureId;
}
_ddmStructureId = ParamUtil.getLong(
_httpServletRequest, "ddmStructureId");
return _ddmStructureId;
}
public String getDDMStructureName() {
if (_ddmStructureName != null) {
return _ddmStructureName;
}
_ddmStructureName = LanguageUtil.get(
_httpServletRequest, "basic-web-content");
if (getDDMStructureId() <= 0) {
return _ddmStructureName;
}
DDMStructure ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(
getDDMStructureId());
if (ddmStructure != null) {
_ddmStructureName = ddmStructure.getName(_themeDisplay.getLocale());
}
return _ddmStructureName;
}
public List getDDMStructures() throws PortalException {
return getDDMStructures(getRestrictionType());
}
public List getDDMStructures(Integer restrictionType)
throws PortalException {
if (_ddmStructures != null) {
return _ddmStructures;
}
if (restrictionType == null) {
restrictionType = getRestrictionType();
}
_ddmStructures = JournalFolderServiceUtil.getDDMStructures(
SiteConnectedGroupGroupProviderUtil.
getCurrentAndAncestorSiteAndDepotGroupIds(
_themeDisplay.getScopeGroupId(), false, true),
getFolderId(), restrictionType);
if (_journalWebConfiguration.journalBrowseByStructuresSortedByName()) {
Locale locale = _themeDisplay.getLocale();
_ddmStructures.sort(
(ddmStructure1, ddmStructure2) -> {
String name1 = ddmStructure1.getName(locale);
String name2 = ddmStructure2.getName(locale);
return name1.compareTo(name2);
});
}
return _ddmStructures;
}
public VerticalNavItemList getDDMStructureVerticalNavItemList() {
VerticalNavItemList verticalNavItemList = new VerticalNavItemList();
for (DDMStructure ddmStructure :
DDMStructureUtil.getHighlightedDDMStructures(_themeDisplay)) {
verticalNavItemList.add(
verticalNavItem -> {
verticalNavItem.setActive(
getHighlightedDDMStructureId() ==
ddmStructure.getStructureId());
verticalNavItem.setHref(
PortletURLBuilder.createRenderURL(
_liferayPortletResponse
).setParameter(
"highlightedDDMStructureId",
ddmStructure.getStructureId()
).buildString());
String name = ddmStructure.getName(
_themeDisplay.getLocale());
verticalNavItem.setId(name);
verticalNavItem.setLabel(name);
});
}
return verticalNavItemList;
}
public int getDefaultStatus() {
PermissionChecker permissionChecker =
_themeDisplay.getPermissionChecker();
if (permissionChecker.isContentReviewer(
_themeDisplay.getCompanyId(),
_themeDisplay.getScopeGroupId()) ||
isNavigationMine()) {
return WorkflowConstants.STATUS_ANY;
}
return WorkflowConstants.STATUS_APPROVED;
}
public String getDisplayStyle() {
if (_displayStyle != null) {
return _displayStyle;
}
PortalPreferences portalPreferences =
PortletPreferencesFactoryUtil.getPortalPreferences(
_httpServletRequest);
_displayStyle = ParamUtil.getString(
_httpServletRequest, "displayStyle");
if (Validator.isNull(_displayStyle)) {
_displayStyle = portalPreferences.getValue(
JournalPortletKeys.JOURNAL, "display-style", "descriptive");
}
portalPreferences.setValue(
JournalPortletKeys.JOURNAL, "display-style", _displayStyle);
return _displayStyle;
}
public JournalFolder getFolder() {
if (_folder != null) {
return _folder;
}
_folder = (JournalFolder)_httpServletRequest.getAttribute(
WebKeys.JOURNAL_FOLDER);
if (_folder != null) {
return _folder;
}
_folder = JournalFolderLocalServiceUtil.fetchFolder(
ParamUtil.getLong(_httpServletRequest, "folderId"));
return _folder;
}
public List getFolderActionDropdownItems(JournalFolder folder)
throws Exception {
JournalFolderActionDropdownItems folderActionDropdownItems =
new JournalFolderActionDropdownItems(
folder, _liferayPortletRequest, _liferayPortletResponse,
_trashHelper);
return folderActionDropdownItems.getActionDropdownItems();
}
public long getFolderId() {
if (_folderId != null) {
return _folderId;
}
_folderId = BeanParamUtil.getLong(
getFolder(), _httpServletRequest, "folderId",
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);
return _folderId;
}
public List getFolderInfoPanelDropdownItems(
JournalFolder folder)
throws Exception {
JournalFolderActionDropdownItems folderActionDropdownItems =
new JournalFolderActionDropdownItems(
folder, _liferayPortletRequest, _liferayPortletResponse,
_trashHelper);
return folderActionDropdownItems.getInfoPanelActionDropdownItems();
}
public JSONArray getFoldersJSONArray() {
return JSONUtil.put(
JSONUtil.put(
"children",
_getFoldersJSONArray(
_themeDisplay.getScopeGroupId(),
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID)
).put(
"id", JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID
).put(
"name", LanguageUtil.get(_themeDisplay.getLocale(), "home")
));
}
public String getFolderSubtitle(JournalFolder folder) {
if (isNavigationMine() || isNavigationRecent()) {
return _getSubtitle(
folder.getCreateDate(), "created-x-ago-by-x",
folder.getUserName());
}
return _getSubtitle(
folder.getModifiedDate(), "modified-x-ago-by-x",
folder.getUserName());
}
public long getHighlightedDDMStructureId() {
if (_highlightedDDMStructureId != null) {
return _highlightedDDMStructureId;
}
_highlightedDDMStructureId = ParamUtil.getLong(
_httpServletRequest, "highlightedDDMStructureId");
return _highlightedDDMStructureId;
}
public List getInfoPanelTabsItems(boolean journalArticle) {
return TabsItemListBuilder.add(
tabsItem -> {
tabsItem.setActive(true);
tabsItem.setLabel(
LanguageUtil.get(_httpServletRequest, "details"));
}
).add(
() -> journalArticle,
tabsItem -> tabsItem.setLabel(
LanguageUtil.get(_httpServletRequest, "versions"))
).build();
}
public String getKeywords() {
if (_keywords != null) {
return _keywords;
}
_keywords = ParamUtil.getString(_httpServletRequest, "keywords");
return _keywords;
}
public JournalArticle getLatestArticle(JournalArticle journalArticle) {
JournalArticle latestArticle =
JournalArticleLocalServiceUtil.fetchLatestArticle(
journalArticle.getGroupId(), journalArticle.getArticleId(),
WorkflowConstants.STATUS_ANY);
if (latestArticle != null) {
return latestArticle;
}
return journalArticle;
}
public String getNavigation() {
if (_navigation != null) {
return _navigation;
}
_navigation = ParamUtil.getString(
_httpServletRequest, "navigation", "all");
return _navigation;
}
public List getNavigationItems(String currentItem) {
Group group = _themeDisplay.getScopeGroup();
return NavigationItemListBuilder.add(
navigationItem -> {
navigationItem.setActive(currentItem.equals("web-content"));
navigationItem.setHref(
_liferayPortletResponse.createRenderURL());
navigationItem.setLabel(
LanguageUtil.get(_httpServletRequest, "web-content"));
}
).add(
() -> !group.isLayout(),
navigationItem -> {
navigationItem.setActive(currentItem.equals("structures"));
navigationItem.setHref(
_liferayPortletResponse.createRenderURL(), "mvcPath",
"/view_ddm_structures.jsp");
navigationItem.setLabel(
LanguageUtil.get(_httpServletRequest, "structures"));
}
).add(
() -> !group.isLayout(),
navigationItem -> {
navigationItem.setActive(currentItem.equals("templates"));
navigationItem.setHref(
_liferayPortletResponse.createRenderURL(), "mvcPath",
"/view_ddm_templates.jsp");
navigationItem.setLabel(
LanguageUtil.get(_httpServletRequest, "templates"));
}
).add(
() ->
_journalWebConfiguration.showFeeds() &&
PortalUtil.isRSSFeedsEnabled(),
navigationItem -> {
navigationItem.setActive(currentItem.equals("feeds"));
navigationItem.setHref(_getFeedsURL());
navigationItem.setLabel(
LanguageUtil.get(_httpServletRequest, "feeds"));
}
).build();
}
public String getOrderByCol() {
if (_orderByCol != null) {
return _orderByCol;
}
_orderByCol = ParamUtil.getString(_httpServletRequest, "orderByCol");
if (Validator.isNull(_orderByCol)) {
if (isSearch()) {
_orderByCol = _portalPreferences.getValue(
JournalPortletKeys.JOURNAL, "order-by-col", "relevance");
}
else {
_orderByCol = _portalPreferences.getValue(
JournalPortletKeys.JOURNAL, "order-by-col",
"modified-date");
if (Objects.equals(_orderByCol, "relevance")) {
_orderByCol = "modified-date";
_portalPreferences.setValue(
JournalPortletKeys.JOURNAL, "order-by-col", null);
}
}
}
else {
_portalPreferences.setValue(
JournalPortletKeys.JOURNAL, "order-by-col", _orderByCol);
}
return _orderByCol;
}
public String getOrderByType() {
if (_orderByType != null) {
return _orderByType;
}
if (isNavigationRecent() ||
Objects.equals(getOrderByCol(), "relevance")) {
return "desc";
}
_orderByType = ParamUtil.getString(_httpServletRequest, "orderByType");
if (Validator.isNull(_orderByType)) {
String defaultOrderByType = "asc";
if (Objects.equals(getOrderByCol(), "create-date") ||
Objects.equals(getOrderByCol(), "modified-date")) {
defaultOrderByType = "desc";
}
_orderByType = _portalPreferences.getValue(
JournalPortletKeys.JOURNAL, "order-by-type",
defaultOrderByType);
}
else {
_portalPreferences.setValue(
JournalPortletKeys.JOURNAL, "order-by-type", _orderByType);
}
return _orderByType;
}
public String[] getOrderColumns() {
String[] orderColumns = {
"display-date", "modified-date", "create-date", "title"
};
if (isSearch()) {
orderColumns = ArrayUtil.append(orderColumns, "relevance");
}
if (!_journalWebConfiguration.journalArticleForceAutogenerateId() ||
_journalWebConfiguration.journalArticleShowId()) {
orderColumns = ArrayUtil.append(orderColumns, "id");
}
return orderColumns;
}
public String getOriginalAuthorUserName(JournalArticle article) {
AssetEntry assetEntry = AssetEntryLocalServiceUtil.fetchEntry(
JournalArticle.class.getName(),
JournalArticleAssetRenderer.getClassPK(article));
if (assetEntry != null) {
return assetEntry.getUserName();
}
return article.getUserName();
}
public long getParentFolderId() {
if (_parentFolderId != null) {
return _parentFolderId;
}
_parentFolderId = ParamUtil.getLong(
_httpServletRequest, "parentFolderId",
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);
return _parentFolderId;
}
public PortletURL getPortletURL(String tab) {
PortletURL portletURL = _getBasePortletURL(tab);
String searchIn = _getSearchIn();
if (Validator.isNotNull(searchIn)) {
portletURL.setParameter("searchIn", searchIn);
}
String searchLocation = _getSearchLocation();
if (Validator.isNotNull(searchLocation)) {
portletURL.setParameter("searchLocation", searchLocation);
}
return portletURL;
}
public int getRestrictionType() {
if (_restrictionType != null) {
return _restrictionType;
}
JournalFolder folder = getFolder();
if (folder != null) {
_restrictionType = folder.getRestrictionType();
}
else {
_restrictionType = JournalFolderConstants.RESTRICTION_TYPE_INHERIT;
}
return _restrictionType;
}
public ResultRowSplitter getResultRowSplitter() {
if (isNavigationRecent()) {
return new JournalRecentArticlesResultRowSplitter(_themeDisplay);
}
if (Objects.equals(getDisplayStyle(), "icon")) {
return new JournalResultRowSplitter();
}
return null;
}
public String getScheduledArticleMessage(JournalArticle journalArticle) {
int count = JournalArticleServiceUtil.getArticlesCountByArticleId(
journalArticle.getGroupId(), journalArticle.getArticleId(),
WorkflowConstants.STATUS_SCHEDULED);
if (count > 1) {
return LanguageUtil.get(
_themeDisplay.getLocale(),
"multiple-publications-were-scheduled");
}
return _dateTimeFormat.format(journalArticle.getDisplayDate());
}
public SearchContainer> getSearchContainer() throws PortalException {
if (_searchContainer != null) {
return _searchContainer;
}
if (isShowComments()) {
_searchContainer = _getCommentsSearchContainer();
return _searchContainer;
}
if (isIndexAllArticleVersions() && isShowVersions()) {
_searchContainer = _getVersionsSearchContainer();
return _searchContainer;
}
_searchContainer = _getArticlesSearchContainer();
return _searchContainer;
}
public String getSearchInLabel() {
if (Objects.equals(_getSearchIn(), "title")) {
return LanguageUtil.get(_themeDisplay.getLocale(), "title-only");
}
if (Objects.equals(_getSearchIn(), "comments")) {
return LanguageUtil.get(_themeDisplay.getLocale(), "comments");
}
return LanguageUtil.get(_themeDisplay.getLocale(), "all-fields");
}
public String getSearchLocationLabel() {
if (getFolderId() == JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
return null;
}
if (_isSearchLocationCurrentFolder()) {
JournalFolder folder = getFolder();
return folder.getName();
}
return LanguageUtil.get(_themeDisplay.getLocale(), "everywhere");
}
public Map getSearchProps() throws PortalException {
return HashMapBuilder.put(
"searchIn", _getSearchIn()
).put(
"searchInCommentsURL",
String.valueOf(_getSearchInCommentsPortletURL())
).put(
"searchInOptions",
() -> {
if (isSearch()) {
return _getSearchInOptionsJSONArray();
}
return null;
}
).put(
"searchLocation", _getSearchLocation()
).put(
"searchLocationOptions",
() -> {
if ((getFolderId() ==
JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) ||
!isSearch()) {
return null;
}
JournalFolder folder = getFolder();
return JSONUtil.putAll(
JSONUtil.put(
"label", folder.getName()
).put(
"value", "current-folder"
),
JSONUtil.put(
"label",
LanguageUtil.get(
_themeDisplay.getLocale(), "everywhere")
).put(
"value", "everywhere"
));
}
).put(
"searchResults", getTab()
).put(
"searchURL", String.valueOf(_getBasePortletURL(getTab()))
).build();
}
public String getSearchResultsLabel() throws PortalException {
String searchResults = getTab();
if (Objects.equals(searchResults, "comments")) {
return LanguageUtil.get(_themeDisplay.getLocale(), "comments");
}
else if (Objects.equals(searchResults, "versions")) {
return LanguageUtil.get(_themeDisplay.getLocale(), "versions");
}
return LanguageUtil.get(_themeDisplay.getLocale(), "web-content");
}
public String getSelectDDMStructureURL() {
RequestBackedPortletURLFactory requestBackedPortletURLFactory =
RequestBackedPortletURLFactoryUtil.create(_liferayPortletRequest);
DDMStructureItemSelectorCriterion ddmStructureItemSelectorCriterion =
new DDMStructureItemSelectorCriterion();
ddmStructureItemSelectorCriterion.setClassNameId(
PortalUtil.getClassNameId(JournalArticle.class));
ddmStructureItemSelectorCriterion.setDesiredItemSelectorReturnTypes(
new DDMStructureItemSelectorReturnType());
return String.valueOf(
_itemSelector.getItemSelectorURL(
requestBackedPortletURLFactory,
_liferayPortletResponse.getNamespace() + "selectDDMStructure",
ddmStructureItemSelectorCriterion));
}
public int getStatus() {
if (_status != null) {
return _status;
}
_status = ParamUtil.getInteger(
_httpServletRequest, "status", getDefaultStatus());
return _status;
}
public String getTab() {
if (Objects.equals(_getSearchIn(), "comments")) {
return "comments";
}
return getType();
}
public String getTitle() throws PortalException {
if (isFilterApplied() || isSearch()) {
return LanguageUtil.get(_httpServletRequest, "search-results");
}
DDMStructure ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(
getHighlightedDDMStructureId());
if (ddmStructure != null) {
return ddmStructure.getName(_themeDisplay.getLocale());
}
ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(
getDDMStructureId());
if (ddmStructure != null) {
return ddmStructure.getName(_themeDisplay.getLocale());
}
return LanguageUtil.get(_httpServletRequest, "content-library");
}
public int getTotalItems() throws PortalException {
SearchContainer> articleSearchContainer =
_getArticlesSearchContainer();
return articleSearchContainer.getTotal();
}
public String getType() {
if (_type != null) {
return _type;
}
_type = ParamUtil.getString(_httpServletRequest, "type", "web-content");
return _type;
}
public int getVersionsTotal() throws PortalException {
SearchContainer articleSearchContainer =
_getVersionsSearchContainer();
return articleSearchContainer.getTotal();
}
public VerticalNavItemList getVerticalNavItemList() {
return VerticalNavItemListBuilder.add(
verticalNavItem -> {
verticalNavItem.setActive(!isHighlightedDDMStructure());
verticalNavItem.setHref(
PortletURLBuilder.createRenderURL(
_liferayPortletResponse
).buildString());
String name = LanguageUtil.get(
_httpServletRequest, "content-library");
verticalNavItem.setId(name);
verticalNavItem.setLabel(name);
}
).build();
}
public boolean hasAssetFilter() {
if (ArrayUtil.isEmpty(_getAssetCategoryIds()) &&
ArrayUtil.isEmpty(_getAssetTagNames())) {
return false;
}
return true;
}
public boolean hasCommentsResults() throws PortalException {
if (getCommentsTotal() > 0) {
return true;
}
return false;
}
public boolean hasGuestViewPermission(JournalArticle journalArticle)
throws PortalException {
if (_guestRole == null) {
_guestRole = _roleLocalService.getRole(
journalArticle.getCompanyId(), RoleConstants.GUEST);
}
return _resourcePermissionLocalService.hasResourcePermission(
journalArticle.getCompanyId(), JournalArticle.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(journalArticle.getResourcePrimKey()),
_guestRole.getRoleId(), ActionKeys.VIEW);
}
public boolean hasHighlightedDDMStructure() {
return ListUtil.isNotEmpty(
DDMStructureUtil.getHighlightedDDMStructures(_themeDisplay));
}
public boolean hasResults() throws PortalException {
if (getTotalItems() > 0) {
return true;
}
return false;
}
public boolean hasVersionsResults() throws PortalException {
if (getVersionsTotal() > 0) {
return true;
}
return false;
}
public boolean isCommentsTabSelected() throws PortalException {
if (Objects.equals(getTab(), "comments")) {
return true;
}
return false;
}
public boolean isFilterApplied() {
if ((getStatus() != WorkflowConstants.STATUS_ANY) ||
isNavigationMine() || isNavigationRecent() || isTypeVersions()) {
return true;
}
for (String parameterName : _PARAMETER_NAMES) {
if (Validator.isNotNull(
ParamUtil.getString(_httpServletRequest, parameterName))) {
return true;
}
}
return false;
}
public boolean isHighlightedDDMStructure() {
if (getHighlightedDDMStructureId() > 0) {
return true;
}
return false;
}
public boolean isIndexAllArticleVersions() {
try {
JournalServiceConfiguration journalServiceConfiguration =
ConfigurationProviderUtil.getCompanyConfiguration(
JournalServiceConfiguration.class,
_themeDisplay.getCompanyId());
return journalServiceConfiguration.indexAllArticleVersionsEnabled();
}
catch (Exception exception) {
_log.error(exception);
}
return false;
}
public boolean isNavigationHome() {
if (Objects.equals(getNavigation(), "all")) {
return true;
}
return false;
}
public boolean isNavigationMine() {
if (_navigationMine != null) {
return _navigationMine;
}
_navigationMine = ParamUtil.getBoolean(
_httpServletRequest, "navigationMine");
return _navigationMine;
}
public boolean isNavigationRecent() {
if (_navigationRecent != null) {
return _navigationRecent;
}
_navigationRecent = ParamUtil.getBoolean(
_httpServletRequest, "navigationRecent");
return _navigationRecent;
}
public boolean isNavigationStructure() {
if (Objects.equals(getNavigation(), "structure")) {
return true;
}
return false;
}
public boolean isSearch() {
if (Validator.isNotNull(getKeywords())) {
return true;
}
return false;
}
public boolean isShowComments() throws PortalException {
if (Objects.equals(_getSearchIn(), "comments")) {
return true;
}
if ((isTypeWebContent() && !hasResults() && !hasVersionsResults() &&
hasCommentsResults()) ||
(isTypeVersions() && !hasVersionsResults() &&
hasCommentsResults())) {
_searchIn = "comments";
return true;
}
return false;
}
public boolean isShowInfoButton() throws PortalException {
if (hasAssetFilter() || isNavigationMine() || isNavigationRecent() ||
isSearch() || isTypeVersions()) {
return false;
}
return true;
}
public boolean isShowVersions() throws PortalException {
if (isTypeVersions()) {
return true;
}
if (isIndexAllArticleVersions() && isTypeWebContent() &&
!hasResults() && hasVersionsResults()) {
_type = "versions";
return true;
}
return false;
}
public boolean isShowWebContent() throws PortalException {
if (isTypeWebContent() && !isShowComments() && !isShowVersions()) {
return true;
}
return false;
}
public boolean isTypeVersions() {
if (Objects.equals(getType(), "versions")) {
return true;
}
return false;
}
public boolean isTypeWebContent() {
if (Objects.equals(getType(), "web-content")) {
return true;
}
return false;
}
public boolean isVersionsTabSelected() throws PortalException {
if (Objects.equals(getTab(), "versions")) {
return true;
}
return false;
}
public boolean isWebContentTabSelected() throws PortalException {
if (Objects.equals(getTab(), "web-content")) {
return true;
}
return false;
}
private JournalDisplayContext(
AssetDisplayPageFriendlyURLProvider assetDisplayPageFriendlyURLProvider,
ItemSelector itemSelector, JournalHelper journalHelper,
JournalWebConfiguration journalWebConfiguration,
PortletRequest portletRequest, PortletResponse portletResponse,
ResourcePermissionLocalService resourcePermissionLocalService,
RoleLocalService roleLocalService, TrashHelper trashHelper) {
_assetDisplayPageFriendlyURLProvider =
assetDisplayPageFriendlyURLProvider;
_itemSelector = itemSelector;
_journalHelper = journalHelper;
_journalWebConfiguration = journalWebConfiguration;
_resourcePermissionLocalService = resourcePermissionLocalService;
_roleLocalService = roleLocalService;
_trashHelper = trashHelper;
_httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest);
_liferayPortletRequest = PortalUtil.getLiferayPortletRequest(
portletRequest);
_liferayPortletResponse = PortalUtil.getLiferayPortletResponse(
portletResponse);
_portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(
_httpServletRequest);
_themeDisplay = (ThemeDisplay)_httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
_dateTimeFormat = FastDateFormatFactoryUtil.getDateTime(
_themeDisplay.getLocale(), _themeDisplay.getTimeZone());
}
private SearchContainer
© 2015 - 2024 Weber Informatics LLC | Privacy Policy