001    /**
002     * Copyright (c) 2000-present 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.exportimport.trash;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.trash.BaseTrashHandler;
019    import com.liferay.portal.kernel.trash.TrashRenderer;
020    import com.liferay.portal.model.Group;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.GroupLocalServiceUtil;
023    import com.liferay.portal.service.permission.GroupPermissionUtil;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portal.util.WebKeys;
026    import com.liferay.portlet.exportimport.model.ExportImportConfiguration;
027    import com.liferay.portlet.exportimport.service.ExportImportConfigurationLocalServiceUtil;
028    import com.liferay.portlet.trash.model.TrashEntry;
029    
030    import javax.portlet.PortletRequest;
031    
032    /**
033     * @author Levente Hud??k
034     */
035    public class ExportImportConfigurationTrashHandler extends BaseTrashHandler {
036    
037            @Override
038            public void deleteTrashEntry(long classPK) throws PortalException {
039                    ExportImportConfigurationLocalServiceUtil.
040                            deleteExportImportConfiguration(classPK);
041            }
042    
043            @Override
044            public String getClassName() {
045                    return ExportImportConfiguration.class.getName();
046            }
047    
048            @Override
049            public String getRestoreMessage(
050                    PortletRequest portletRequest, long classPK) {
051    
052                    ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(
053                            WebKeys.THEME_DISPLAY);
054    
055                    return themeDisplay.translate("export-import-template");
056            }
057    
058            @Override
059            public TrashEntry getTrashEntry(long classPK) throws PortalException {
060                    ExportImportConfiguration exportImportConfiguration =
061                            ExportImportConfigurationLocalServiceUtil.
062                                    getExportImportConfiguration(classPK);
063    
064                    return exportImportConfiguration.getTrashEntry();
065            }
066    
067            @Override
068            public TrashRenderer getTrashRenderer(long classPK) throws PortalException {
069                    ExportImportConfiguration exportImportConfiguration =
070                            ExportImportConfigurationLocalServiceUtil.
071                                    getExportImportConfiguration(classPK);
072    
073                    return new ExportImportConfigurationTrashRenderer(
074                            exportImportConfiguration);
075            }
076    
077            @Override
078            public boolean isInTrash(long classPK) throws PortalException {
079                    ExportImportConfiguration exportImportConfiguration =
080                            ExportImportConfigurationLocalServiceUtil.
081                                    getExportImportConfiguration(classPK);
082    
083                    return exportImportConfiguration.isInTrash();
084            }
085    
086            @Override
087            public void restoreTrashEntry(long userId, long classPK)
088                    throws PortalException {
089    
090                    ExportImportConfigurationLocalServiceUtil.
091                            restoreExportImportConfigurationFromTrash(userId, classPK);
092            }
093    
094            @Override
095            protected boolean hasPermission(
096                            PermissionChecker permissionChecker, long classPK, String actionId)
097                    throws PortalException {
098    
099                    ExportImportConfiguration exportImportConfiguration =
100                            ExportImportConfigurationLocalServiceUtil.
101                                    getExportImportConfiguration(classPK);
102    
103                    Group group = GroupLocalServiceUtil.getGroup(
104                            exportImportConfiguration.getGroupId());
105    
106                    return GroupPermissionUtil.contains(permissionChecker, group, actionId);
107            }
108    
109    }