001    /**
002     * Copyright (c) 2000-2010 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.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            public DLFileShortcut addFileShortcut(
035                            long groupId, long folderId, long toFolderId, String toName,
036                            ServiceContext serviceContext)
037                    throws PortalException, SystemException {
038    
039                    DLFolderPermission.check(
040                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_SHORTCUT);
041    
042                    try {
043                            DLFileEntryPermission.check(
044                                    getPermissionChecker(), groupId, toFolderId, toName,
045                                    ActionKeys.VIEW);
046                    }
047                    catch (PrincipalException pe) {
048                            throw new FileShortcutPermissionException();
049                    }
050    
051                    return dlFileShortcutLocalService.addFileShortcut(
052                            getUserId(), groupId, folderId, toFolderId, toName, serviceContext);
053            }
054    
055            public void deleteFileShortcut(long fileShortcutId)
056                    throws PortalException, SystemException {
057    
058                    DLFileShortcutPermission.check(
059                            getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
060    
061                    dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
062            }
063    
064            public DLFileShortcut getFileShortcut(long fileShortcutId)
065                    throws PortalException, SystemException {
066    
067                    DLFileShortcutPermission.check(
068                            getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
069    
070                    return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
071            }
072    
073            public DLFileShortcut updateFileShortcut(
074                            long fileShortcutId, long folderId, long toFolderId, String toName,
075                            ServiceContext serviceContext)
076                    throws PortalException, SystemException {
077    
078                    DLFileShortcutPermission.check(
079                            getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
080    
081                    DLFileShortcut fileShortcut =
082                            dlFileShortcutLocalService.getDLFileShortcut(fileShortcutId);
083    
084                    try {
085                            DLFileEntryPermission.check(
086                                    getPermissionChecker(), fileShortcut.getGroupId(), toFolderId,
087                                    toName, ActionKeys.VIEW);
088                    }
089                    catch (PrincipalException pe) {
090                            throw new FileShortcutPermissionException();
091                    }
092    
093                    return dlFileShortcutLocalService.updateFileShortcut(
094                            getUserId(), fileShortcutId, folderId, toFolderId, toName,
095                            serviceContext);
096            }
097    
098    }