1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class DLFileShortcutServiceImpl extends DLFileShortcutServiceBaseImpl {
42  
43      public DLFileShortcut addFileShortcut(
44              long folderId, long toFolderId, String toName,
45              boolean addCommunityPermissions, boolean addGuestPermissions)
46          throws PortalException, SystemException {
47  
48          DLFolderPermission.check(
49              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
50  
51          try {
52              DLFileEntryPermission.check(
53                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
54          }
55          catch (PrincipalException pe) {
56              throw new FileShortcutPermissionException();
57          }
58  
59          return dlFileShortcutLocalService.addFileShortcut(
60              getUserId(), folderId, toFolderId, toName, addCommunityPermissions,
61              addGuestPermissions);
62      }
63  
64      public DLFileShortcut addFileShortcut(
65              long folderId, long toFolderId, String toName,
66              String[] communityPermissions, String[] guestPermissions)
67          throws PortalException, SystemException {
68  
69          DLFolderPermission.check(
70              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
71  
72          try {
73              DLFileEntryPermission.check(
74                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
75          }
76          catch (PrincipalException pe) {
77              throw new FileShortcutPermissionException();
78          }
79  
80          return dlFileShortcutLocalService.addFileShortcut(
81              getUserId(), folderId, toFolderId, toName, communityPermissions,
82              guestPermissions);
83      }
84  
85      public void deleteFileShortcut(long fileShortcutId)
86          throws PortalException, SystemException {
87  
88          DLFileShortcutPermission.check(
89              getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
90  
91          dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
92      }
93  
94      public DLFileShortcut getFileShortcut(long fileShortcutId)
95          throws PortalException, SystemException {
96  
97          DLFileShortcutPermission.check(
98              getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
99  
100         return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
101     }
102 
103     public DLFileShortcut updateFileShortcut(
104             long fileShortcutId, long folderId, long toFolderId, String toName)
105         throws PortalException, SystemException {
106 
107         DLFileShortcutPermission.check(
108             getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
109 
110         try {
111             DLFileEntryPermission.check(
112                 getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
113         }
114         catch (PrincipalException pe) {
115             throw new FileShortcutPermissionException();
116         }
117 
118         return dlFileShortcutLocalService.updateFileShortcut(
119             getUserId(), fileShortcutId, folderId, toFolderId, toName);
120     }
121 
122 }