com.liferay.announcements.web.internal.search.AnnouncementsEntryChecker.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.announcements.web.internal.search.AnnouncementsEntryChecker.java

Source

/**
 * 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.announcements.web.internal.search;

import com.liferay.announcements.kernel.model.AnnouncementsEntry;
import com.liferay.announcements.kernel.service.AnnouncementsEntryLocalServiceUtil;
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.exception.PortalException;
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.StringBundler;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portlet.announcements.service.permission.AnnouncementsEntryPermission;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Roberto Daz
 */
public class AnnouncementsEntryChecker extends EmptyOnClickRowChecker {

    public AnnouncementsEntryChecker(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 request) {
        return null;
    }

    @Override
    public String getRowCheckBox(HttpServletRequest request, boolean checked, boolean disabled, String primaryKey) {

        long entryId = GetterUtil.getLong(primaryKey);

        AnnouncementsEntry entry = null;

        try {
            entry = AnnouncementsEntryLocalServiceUtil.getEntry(entryId);
        } catch (PortalException pe) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(pe, pe);
            }

            return StringPool.BLANK;
        }

        String name = AnnouncementsEntry.class.getSimpleName();

        boolean showInput = false;

        try {
            if (AnnouncementsEntryPermission.contains(_permissionChecker, entry, ActionKeys.DELETE)) {

                showInput = true;

                if (!showInput) {
                    return StringPool.BLANK;
                }
            }
        } catch (PortalException pe) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(pe, pe);
            }

            return StringPool.BLANK;
        }

        StringBundler sb = new StringBundler(5);

        sb.append("['");
        sb.append(_liferayPortletResponse.getNamespace());
        sb.append(RowChecker.ROW_IDS);
        sb.append(AnnouncementsEntry.class.getSimpleName());
        sb.append("']");

        String checkBoxRowIds = sb.toString();

        String checkBoxAllRowIds = "'#" + getAllRowIds() + "'";

        return getRowCheckBox(request, checked, disabled,
                _liferayPortletResponse.getNamespace() + RowChecker.ROW_IDS + name, primaryKey, checkBoxRowIds,
                checkBoxAllRowIds, StringPool.BLANK);
    }

    private static final Log _log = LogFactoryUtil.getLog(AnnouncementsEntryChecker.class);

    private final LiferayPortletResponse _liferayPortletResponse;
    private final PermissionChecker _permissionChecker;

}