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.blogs.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.blogs.model.BlogsEntry;
022    import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
023    import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
024    import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
025    
026    /**
027     * Implements trash handling for the blogs entry entity.
028     *
029     * @author Zsolt Berentey
030     */
031    public class BlogsEntryTrashHandler extends BaseTrashHandler {
032    
033            public static final String CLASS_NAME = BlogsEntry.class.getName();
034    
035            public void deleteTrashEntries(long[] classPKs, boolean checkPermission)
036                    throws PortalException, SystemException {
037    
038                    for (long classPK : classPKs) {
039                            if (checkPermission) {
040                                    BlogsEntryServiceUtil.deleteEntry(classPK);
041                            }
042                            else {
043                                    BlogsEntryLocalServiceUtil.deleteEntry(classPK);
044                            }
045                    }
046            }
047    
048            public String getClassName() {
049                    return CLASS_NAME;
050            }
051    
052            public boolean isInTrash(long classPK)
053                    throws PortalException, SystemException {
054    
055                    BlogsEntry entry = BlogsEntryServiceUtil.getEntry(classPK);
056    
057                    return entry.isInTrash();
058            }
059    
060            public void restoreTrashEntries(long[] classPKs)
061                    throws PortalException, SystemException {
062    
063                    for (long classPK : classPKs) {
064                            BlogsEntryServiceUtil.restoreEntryFromTrash(classPK);
065                    }
066            }
067    
068            @Override
069            protected boolean hasPermission(
070                            PermissionChecker permissionChecker, long classPK, String actionId)
071                    throws PortalException, SystemException {
072    
073                    return BlogsEntryPermission.contains(
074                            permissionChecker, classPK, actionId);
075            }
076    
077    }