com.liferay.journal.web.internal.search.EntriesChecker 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.search;
import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.model.JournalFolder;
import com.liferay.journal.service.JournalArticleLocalServiceUtil;
import com.liferay.journal.service.JournalFolderLocalServiceUtil;
import com.liferay.journal.web.internal.security.permission.resource.JournalArticlePermission;
import com.liferay.journal.web.internal.security.permission.resource.JournalFolderPermission;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.dao.search.EmptyOnClickRowChecker;
import com.liferay.portal.kernel.dao.search.RowChecker;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.WebKeys;
import javax.servlet.http.HttpServletRequest;
/**
* @author Sergio González
*/
public class EntriesChecker extends EmptyOnClickRowChecker {
public EntriesChecker(
LiferayPortletRequest liferayPortletRequest,
LiferayPortletResponse liferayPortletResponse) {
super(liferayPortletResponse);
_liferayPortletResponse = liferayPortletResponse;
ThemeDisplay themeDisplay =
(ThemeDisplay)liferayPortletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
_permissionChecker = themeDisplay.getPermissionChecker();
}
@Override
public String getAllRowsCheckBox() {
return null;
}
@Override
public String getAllRowsCheckBox(HttpServletRequest httpServletRequest) {
return null;
}
@Override
public String getRowCheckBox(
HttpServletRequest httpServletRequest, boolean checked,
boolean disabled, String primaryKey) {
ThemeDisplay themeDisplay =
(ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
JournalFolder folder = null;
String articleId = GetterUtil.getString(primaryKey);
JournalArticle article = JournalArticleLocalServiceUtil.fetchArticle(
themeDisplay.getScopeGroupId(), articleId);
if (article == null) {
long folderId = GetterUtil.getLong(primaryKey);
folder = JournalFolderLocalServiceUtil.fetchFolder(folderId);
}
String name = null;
boolean showInput = false;
if (article != null) {
name = JournalArticle.class.getSimpleName();
try {
if (JournalArticlePermission.contains(
_permissionChecker, article, ActionKeys.DELETE) ||
JournalArticlePermission.contains(
_permissionChecker, article, ActionKeys.EXPIRE) ||
JournalArticlePermission.contains(
_permissionChecker, article, ActionKeys.UPDATE)) {
showInput = true;
}
}
catch (Exception exception) {
if (_log.isDebugEnabled()) {
_log.debug(exception);
}
}
}
else if (folder != null) {
name = JournalFolder.class.getSimpleName();
try {
if (JournalFolderPermission.contains(
_permissionChecker, folder, ActionKeys.DELETE)) {
showInput = true;
}
}
catch (Exception exception) {
if (_log.isDebugEnabled()) {
_log.debug(exception);
}
}
}
if (!showInput) {
return StringPool.BLANK;
}
String checkBoxRowIds = StringBundler.concat(
"['", _liferayPortletResponse.getNamespace(), RowChecker.ROW_IDS,
JournalFolder.class.getSimpleName(), "', '",
_liferayPortletResponse.getNamespace(), RowChecker.ROW_IDS,
JournalArticle.class.getSimpleName(), "']");
return getRowCheckBox(
httpServletRequest, checked, disabled,
StringBundler.concat(
_liferayPortletResponse.getNamespace(), RowChecker.ROW_IDS,
name, StringPool.BLANK),
primaryKey, checkBoxRowIds, "'#" + getAllRowIds() + "'",
StringPool.BLANK);
}
private static final Log _log = LogFactoryUtil.getLog(EntriesChecker.class);
private final LiferayPortletResponse _liferayPortletResponse;
private final PermissionChecker _permissionChecker;
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy