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.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 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();
048                    }
049    
050                    return dlFileShortcutLocalService.addFileShortcut(
051                            getUserId(), groupId, folderId, toFileEntryId, serviceContext);
052            }
053    
054            @Override
055            public void deleteFileShortcut(long fileShortcutId) throws PortalException {
056                    DLFileShortcutPermission.check(
057                            getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
058    
059                    dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
060            }
061    
062            @Override
063            public DLFileShortcut getFileShortcut(long fileShortcutId)
064                    throws PortalException {
065    
066                    DLFileShortcutPermission.check(
067                            getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
068    
069                    return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
070            }
071    
072            @Override
073            public DLFileShortcut updateFileShortcut(
074                            long fileShortcutId, long folderId, long toFileEntryId,
075                            ServiceContext serviceContext)
076                    throws PortalException {
077    
078                    DLFileShortcutPermission.check(
079                            getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
080    
081                    try {
082                            DLFileEntryPermission.check(
083                                    getPermissionChecker(), toFileEntryId, ActionKeys.VIEW);
084                    }
085                    catch (PrincipalException pe) {
086                            throw new FileShortcutPermissionException();
087                    }
088    
089                    return dlFileShortcutLocalService.updateFileShortcut(
090                            getUserId(), fileShortcutId, folderId, toFileEntryId,
091                            serviceContext);
092            }
093    
094    }