1   /**
2    * Copyright (c) 2000-2009 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.security.auth.PrincipalException;
28  import com.liferay.portal.security.permission.ActionKeys;
29  import com.liferay.portlet.documentlibrary.FileShortcutPermissionException;
30  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
31  import com.liferay.portlet.documentlibrary.service.base.DLFileShortcutServiceBaseImpl;
32  import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
33  import com.liferay.portlet.documentlibrary.service.permission.DLFileShortcutPermission;
34  import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
35  
36  /**
37   * <a href="DLFileShortcutServiceImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class DLFileShortcutServiceImpl extends DLFileShortcutServiceBaseImpl {
43  
44      public DLFileShortcut addFileShortcut(
45              long folderId, long toFolderId, String toName,
46              boolean addCommunityPermissions, boolean addGuestPermissions)
47          throws PortalException, SystemException {
48  
49          DLFolderPermission.check(
50              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
51  
52          try {
53              DLFileEntryPermission.check(
54                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
55          }
56          catch (PrincipalException pe) {
57              throw new FileShortcutPermissionException();
58          }
59  
60          return dlFileShortcutLocalService.addFileShortcut(
61              getUserId(), folderId, toFolderId, toName, addCommunityPermissions,
62              addGuestPermissions);
63      }
64  
65      public DLFileShortcut addFileShortcut(
66              long folderId, long toFolderId, String toName,
67              String[] communityPermissions, String[] guestPermissions)
68          throws PortalException, SystemException {
69  
70          DLFolderPermission.check(
71              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
72  
73          try {
74              DLFileEntryPermission.check(
75                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
76          }
77          catch (PrincipalException pe) {
78              throw new FileShortcutPermissionException();
79          }
80  
81          return dlFileShortcutLocalService.addFileShortcut(
82              getUserId(), folderId, toFolderId, toName, communityPermissions,
83              guestPermissions);
84      }
85  
86      public void deleteFileShortcut(long fileShortcutId)
87          throws PortalException, SystemException {
88  
89          DLFileShortcutPermission.check(
90              getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
91  
92          dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
93      }
94  
95      public DLFileShortcut getFileShortcut(long fileShortcutId)
96          throws PortalException, SystemException {
97  
98          DLFileShortcutPermission.check(
99              getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
100 
101         return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
102     }
103 
104     public DLFileShortcut updateFileShortcut(
105             long fileShortcutId, long folderId, long toFolderId, String toName)
106         throws PortalException, SystemException {
107 
108         DLFileShortcutPermission.check(
109             getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
110 
111         try {
112             DLFileEntryPermission.check(
113                 getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
114         }
115         catch (PrincipalException pe) {
116             throw new FileShortcutPermissionException();
117         }
118 
119         return dlFileShortcutLocalService.updateFileShortcut(
120             getUserId(), fileShortcutId, folderId, toFolderId, toName);
121     }
122 
123 }