1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.documentlibrary.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.security.auth.PrincipalException;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.service.ServiceContext;
22  import com.liferay.portlet.documentlibrary.FileShortcutPermissionException;
23  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
24  import com.liferay.portlet.documentlibrary.service.base.DLFileShortcutServiceBaseImpl;
25  import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
26  import com.liferay.portlet.documentlibrary.service.permission.DLFileShortcutPermission;
27  import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
28  
29  /**
30   * <a href="DLFileShortcutServiceImpl.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   */
34  public class DLFileShortcutServiceImpl extends DLFileShortcutServiceBaseImpl {
35  
36      public DLFileShortcut addFileShortcut(
37              long groupId, long folderId, long toFolderId, String toName,
38              ServiceContext serviceContext)
39          throws PortalException, SystemException {
40  
41          DLFolderPermission.check(
42              getPermissionChecker(), groupId, folderId, ActionKeys.ADD_SHORTCUT);
43  
44          try {
45              DLFileEntryPermission.check(
46                  getPermissionChecker(), groupId, toFolderId, toName,
47                  ActionKeys.VIEW);
48          }
49          catch (PrincipalException pe) {
50              throw new FileShortcutPermissionException();
51          }
52  
53          return dlFileShortcutLocalService.addFileShortcut(
54              null, getUserId(), groupId, folderId, toFolderId, toName,
55              serviceContext);
56      }
57  
58      public void deleteFileShortcut(long fileShortcutId)
59          throws PortalException, SystemException {
60  
61          DLFileShortcutPermission.check(
62              getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
63  
64          dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
65      }
66  
67      public DLFileShortcut getFileShortcut(long fileShortcutId)
68          throws PortalException, SystemException {
69  
70          DLFileShortcutPermission.check(
71              getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
72  
73          return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
74      }
75  
76      public DLFileShortcut updateFileShortcut(
77              long fileShortcutId, long folderId, long toFolderId, String toName,
78              ServiceContext serviceContext)
79          throws PortalException, SystemException {
80  
81          DLFileShortcutPermission.check(
82              getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
83  
84          DLFileShortcut fileShortcut =
85              dlFileShortcutLocalService.getDLFileShortcut(fileShortcutId);
86  
87          try {
88              DLFileEntryPermission.check(
89                  getPermissionChecker(), fileShortcut.getGroupId(), toFolderId,
90                  toName, ActionKeys.VIEW);
91          }
92          catch (PrincipalException pe) {
93              throw new FileShortcutPermissionException();
94          }
95  
96          return dlFileShortcutLocalService.updateFileShortcut(
97              getUserId(), fileShortcutId, folderId, toFolderId, toName,
98              serviceContext);
99      }
100 
101 }