001    /**
002     * Copyright (c) 2000-2013 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.repository.model.FileEntry;
020    import com.liferay.portal.kernel.trash.BaseTrashHandler;
021    import com.liferay.portal.model.ContainerModel;
022    import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
025    import com.liferay.portlet.messageboards.model.MBMessage;
026    import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
027    import com.liferay.portlet.messageboards.service.MBMessageServiceUtil;
028    import com.liferay.portlet.messageboards.service.permission.MBMessagePermission;
029    import com.liferay.portlet.messageboards.util.MBMessageAttachmentsUtil;
030    
031    /**
032     * Implements trash handling for message boards message entity.
033     *
034     * @author Zsolt Berentey
035     */
036    public class MBMessageTrashHandler extends BaseTrashHandler {
037    
038            public void deleteTrashEntry(long classPK) {
039            }
040    
041            public String getClassName() {
042                    return MBMessage.class.getName();
043            }
044    
045            @Override
046            public ContainerModel getTrashContainer(long classPK)
047                    throws PortalException, SystemException {
048    
049                    MBMessage message = MBMessageLocalServiceUtil.getMBMessage(classPK);
050    
051                    return message.getTrashContainer();
052            }
053    
054            @Override
055            public boolean isDeletable() {
056                    return false;
057            }
058    
059            public boolean isInTrash(long classPK)
060                    throws PortalException, SystemException {
061    
062                    MBMessage message = MBMessageLocalServiceUtil.getMBMessage(classPK);
063    
064                    return message.isInTrash();
065            }
066    
067            @Override
068            public boolean isInTrashContainer(long classPK)
069                    throws PortalException, SystemException {
070    
071                    MBMessage message = MBMessageLocalServiceUtil.getMBMessage(classPK);
072    
073                    return message.isInTrashThread();
074            }
075    
076            @Override
077            public void restoreRelatedTrashEntry(String className, long classPK)
078                    throws PortalException, SystemException {
079    
080                    if (!className.equals(DLFileEntry.class.getName())) {
081                            return;
082                    }
083    
084                    FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(
085                            classPK);
086    
087                    MBMessage message = MBMessageAttachmentsUtil.getMessage(classPK);
088    
089                    MBMessageServiceUtil.restoreMessageAttachmentFromTrash(
090                            message.getMessageId(), fileEntry.getTitle());
091            }
092    
093            public void restoreTrashEntry(long userId, long classPK) {
094            }
095    
096            @Override
097            protected boolean hasPermission(
098                            PermissionChecker permissionChecker, long classPK, String actionId)
099                    throws PortalException, SystemException {
100    
101                    return MBMessagePermission.contains(
102                            permissionChecker, classPK, actionId);
103            }
104    
105    }