001    /**
002     * Copyright (c) 2000-2013 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            @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    }