001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.trash;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.trash.BaseTrashHandler;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portlet.messageboards.asset.MBMessageAssetRendererFactory;
022    import com.liferay.portlet.messageboards.model.MBMessage;
023    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
024    import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
025    
026    /**
027     * Implements trash handling for message boards message entity.
028     *
029     * @author Zsolt Berentey
030     */
031    public class MBMessageTrashHandler extends BaseTrashHandler {
032    
033            public void deleteTrashEntries(long[] classPKs, boolean checkPermission) {
034            }
035    
036            public String getClassName() {
037                    return MBMessageAssetRendererFactory.CLASS_NAME;
038            }
039    
040            @Override
041            public boolean isDeletable() {
042                    return false;
043            }
044    
045            public boolean isInTrash(long classPK)
046                    throws PortalException, SystemException {
047    
048                    MBMessage message = MBMessageLocalServiceUtil.getMBMessage(classPK);
049    
050                    if (message.isInTrash() || message.isInTrashThread()) {
051                            return true;
052                    }
053                    else {
054                            return false;
055                    }
056            }
057    
058            @Override
059            public boolean isInTrashContainer(long classPK)
060                    throws PortalException, SystemException {
061    
062                    MBMessage message = MBMessageLocalServiceUtil.getMBMessage(classPK);
063    
064                    return message.isInTrashThread();
065            }
066    
067            public void restoreTrashEntries(long[] classPKs) {
068            }
069    
070            @Override
071            protected boolean hasPermission(
072                            PermissionChecker permissionChecker, long classPK, String actionId)
073                    throws PortalException, SystemException {
074    
075                    return MBMessagePermission.contains(
076                            permissionChecker, classPK, actionId);
077            }
078    
079    }