001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.auth.PrincipalException;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portlet.documentlibrary.FileShortcutPermissionException;
023    import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
024    import com.liferay.portlet.documentlibrary.service.base.DLFileShortcutServiceBaseImpl;
025    import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
026    import com.liferay.portlet.documentlibrary.service.permission.DLFileShortcutPermission;
027    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     */
032    public class DLFileShortcutServiceImpl extends DLFileShortcutServiceBaseImpl {
033    
034            @Override
035            public DLFileShortcut addFileShortcut(
036                            long groupId, long folderId, long toFileEntryId,
037                            ServiceContext serviceContext)
038                    throws PortalException, SystemException {
039    
040                    DLFolderPermission.check(
041                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_SHORTCUT);
042    
043                    try {
044                            DLFileEntryPermission.check(
045                                    getPermissionChecker(), toFileEntryId, ActionKeys.VIEW);
046                    }
047                    catch (PrincipalException pe) {
048                            throw new FileShortcutPermissionException();
049                    }
050    
051                    return dlFileShortcutLocalService.addFileShortcut(
052                            getUserId(), groupId, folderId, toFileEntryId, serviceContext);
053            }
054    
055            @Override
056            public void deleteFileShortcut(long fileShortcutId)
057                    throws PortalException, SystemException {
058    
059                    DLFileShortcutPermission.check(
060                            getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
061    
062                    dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
063            }
064    
065            @Override
066            public DLFileShortcut getFileShortcut(long fileShortcutId)
067                    throws PortalException, SystemException {
068    
069                    DLFileShortcutPermission.check(
070                            getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
071    
072                    return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
073            }
074    
075            @Override
076            public DLFileShortcut updateFileShortcut(
077                            long fileShortcutId, long folderId, long toFileEntryId,
078                            ServiceContext serviceContext)
079                    throws PortalException, SystemException {
080    
081                    DLFileShortcutPermission.check(
082                            getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
083    
084                    try {
085                            DLFileEntryPermission.check(
086                                    getPermissionChecker(), toFileEntryId, ActionKeys.VIEW);
087                    }
088                    catch (PrincipalException pe) {
089                            throw new FileShortcutPermissionException();
090                    }
091    
092                    return dlFileShortcutLocalService.updateFileShortcut(
093                            getUserId(), fileShortcutId, folderId, toFileEntryId,
094                            serviceContext);
095            }
096    
097    }