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.documentlibrary.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.security.auth.PrincipalException;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.documentlibrary.exception.FileShortcutPermissionException;
022    import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
023    import com.liferay.portlet.documentlibrary.service.base.DLFileShortcutServiceBaseImpl;
024    import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
025    import com.liferay.portlet.documentlibrary.service.permission.DLFileShortcutPermission;
026    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class DLFileShortcutServiceImpl extends DLFileShortcutServiceBaseImpl {
032    
033            @Override
034            public DLFileShortcut addFileShortcut(
035                            long groupId, long repositoryId, long folderId, long toFileEntryId,
036                            ServiceContext serviceContext)
037                    throws PortalException {
038    
039                    DLFolderPermission.check(
040                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_SHORTCUT);
041    
042                    try {
043                            DLFileEntryPermission.check(
044                                    getPermissionChecker(), toFileEntryId, ActionKeys.VIEW);
045                    }
046                    catch (PrincipalException pe) {
047                            throw new FileShortcutPermissionException(pe);
048                    }
049    
050                    return dlFileShortcutLocalService.addFileShortcut(
051                            getUserId(), groupId, repositoryId, folderId, toFileEntryId,
052                            serviceContext);
053            }
054    
055            @Override
056            public void deleteFileShortcut(long fileShortcutId) throws PortalException {
057                    DLFileShortcutPermission.check(
058                            getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
059    
060                    dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
061            }
062    
063            @Override
064            public DLFileShortcut getFileShortcut(long fileShortcutId)
065                    throws PortalException {
066    
067                    DLFileShortcutPermission.check(
068                            getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
069    
070                    return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
071            }
072    
073            @Override
074            public DLFileShortcut updateFileShortcut(
075                            long fileShortcutId, long repositoryId, long folderId,
076                            long toFileEntryId, ServiceContext serviceContext)
077                    throws PortalException {
078    
079                    DLFileShortcutPermission.check(
080                            getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
081    
082                    try {
083                            DLFileEntryPermission.check(
084                                    getPermissionChecker(), toFileEntryId, ActionKeys.VIEW);
085                    }
086                    catch (PrincipalException pe) {
087                            throw new FileShortcutPermissionException(pe);
088                    }
089    
090                    return dlFileShortcutLocalService.updateFileShortcut(
091                            getUserId(), fileShortcutId, repositoryId, folderId, toFileEntryId,
092                            serviceContext);
093            }
094    
095            @Override
096            public void updateFileShortcuts(
097                            long oldToFileEntryId, long newToFileEntryId)
098                    throws PortalException {
099    
100                    try {
101                            DLFileEntryPermission.check(
102                                    getPermissionChecker(), oldToFileEntryId, ActionKeys.VIEW);
103    
104                            DLFileEntryPermission.check(
105                                    getPermissionChecker(), newToFileEntryId, ActionKeys.VIEW);
106                    }
107                    catch (PrincipalException pe) {
108                            throw new FileShortcutPermissionException(pe);
109                    }
110    
111                    dlFileShortcutLocalService.updateFileShortcuts(
112                            oldToFileEntryId, newToFileEntryId);
113            }
114    
115    }