1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.documentlibrary.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.security.permission.ActionKeys;
28  import com.liferay.portal.security.auth.PrincipalException;
29  import com.liferay.portal.service.impl.PrincipalBean;
30  import com.liferay.portlet.documentlibrary.FileShortcutPermissionException;
31  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
32  import com.liferay.portlet.documentlibrary.service.DLFileShortcutLocalServiceUtil;
33  import com.liferay.portlet.documentlibrary.service.DLFileShortcutService;
34  import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
35  import com.liferay.portlet.documentlibrary.service.permission.DLFileShortcutPermission;
36  import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
37  
38  /**
39   * <a href="DLFileShortcutServiceImpl.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   *
43   */
44  public class DLFileShortcutServiceImpl
45      extends PrincipalBean implements DLFileShortcutService {
46  
47      public DLFileShortcut addFileShortcut(
48              long folderId, long toFolderId, String toName,
49              boolean addCommunityPermissions, boolean addGuestPermissions)
50          throws PortalException, SystemException {
51  
52          DLFolderPermission.check(
53              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
54  
55          try {
56              DLFileEntryPermission.check(
57                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
58          }
59          catch (PrincipalException pe) {
60              throw new FileShortcutPermissionException();
61          }
62  
63          return DLFileShortcutLocalServiceUtil.addFileShortcut(
64              getUserId(), folderId, toFolderId, toName, addCommunityPermissions,
65              addGuestPermissions);
66      }
67  
68      public DLFileShortcut addFileShortcut(
69              long folderId, long toFolderId, String toName,
70              String[] communityPermissions, String[] guestPermissions)
71          throws PortalException, SystemException {
72  
73          DLFolderPermission.check(
74              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
75  
76          try {
77              DLFileEntryPermission.check(
78                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
79          }
80          catch (PrincipalException pe) {
81              throw new FileShortcutPermissionException();
82          }
83  
84          return DLFileShortcutLocalServiceUtil.addFileShortcut(
85              getUserId(), folderId, toFolderId, toName, communityPermissions,
86              guestPermissions);
87      }
88  
89      public void deleteFileShortcut(long fileShortcutId)
90          throws PortalException, SystemException {
91  
92          DLFileShortcutPermission.check(
93              getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
94  
95          DLFileShortcutLocalServiceUtil.deleteFileShortcut(fileShortcutId);
96      }
97  
98      public DLFileShortcut getFileShortcut(long fileShortcutId)
99          throws PortalException, SystemException {
100 
101         DLFileShortcutPermission.check(
102             getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
103 
104         return DLFileShortcutLocalServiceUtil.getFileShortcut(fileShortcutId);
105     }
106 
107     public DLFileShortcut updateFileShortcut(
108             long fileShortcutId, long folderId, long toFolderId, String toName)
109         throws PortalException, SystemException {
110 
111         DLFileShortcutPermission.check(
112             getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
113 
114         try {
115             DLFileEntryPermission.check(
116                 getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
117         }
118         catch (PrincipalException pe) {
119             throw new FileShortcutPermissionException();
120         }
121 
122         return DLFileShortcutLocalServiceUtil.updateFileShortcut(
123             getUserId(), fileShortcutId, folderId, toFolderId, toName);
124     }
125 
126 }