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 thread 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            public boolean isInTrash(long classPK)
041                    throws PortalException, SystemException {
042    
043                    MBMessage message = MBMessageLocalServiceUtil.getMBMessage(classPK);
044    
045                    if (message.isInTrash() || message.isInTrashThread()) {
046                            return true;
047                    }
048                    else {
049                            return false;
050                    }
051            }
052    
053            @Override
054            public boolean isInTrashContainer(long classPK)
055                    throws PortalException, SystemException {
056    
057                    MBMessage message = MBMessageLocalServiceUtil.getMBMessage(classPK);
058    
059                    return message.isInTrashThread();
060            }
061    
062            public void restoreTrashEntries(long[] classPKs) {
063            }
064    
065            @Override
066            protected boolean hasPermission(
067                            PermissionChecker permissionChecker, long classPK, String actionId)
068                    throws PortalException, SystemException {
069    
070                    return MBMessagePermission.contains(
071                            permissionChecker, classPK, actionId);
072            }
073    
074    }