1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.documentlibrary.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.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 folderId, long toFolderId, String toName,
38              boolean addCommunityPermissions, boolean addGuestPermissions)
39          throws PortalException, SystemException {
40  
41          DLFolderPermission.check(
42              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
43  
44          try {
45              DLFileEntryPermission.check(
46                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
47          }
48          catch (PrincipalException pe) {
49              throw new FileShortcutPermissionException();
50          }
51  
52          return dlFileShortcutLocalService.addFileShortcut(
53              getUserId(), folderId, toFolderId, toName, addCommunityPermissions,
54              addGuestPermissions);
55      }
56  
57      public DLFileShortcut addFileShortcut(
58              long folderId, long toFolderId, String toName,
59              ServiceContext serviceContext)
60          throws PortalException, SystemException {
61  
62          DLFolderPermission.check(
63              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
64  
65          try {
66              DLFileEntryPermission.check(
67                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
68          }
69          catch (PrincipalException pe) {
70              throw new FileShortcutPermissionException();
71          }
72  
73          return dlFileShortcutLocalService.addFileShortcut(
74              getUserId(), folderId, toFolderId, toName, serviceContext);
75      }
76  
77      public DLFileShortcut addFileShortcut(
78              long folderId, long toFolderId, String toName,
79              String[] communityPermissions, String[] guestPermissions)
80          throws PortalException, SystemException {
81  
82          DLFolderPermission.check(
83              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
84  
85          try {
86              DLFileEntryPermission.check(
87                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
88          }
89          catch (PrincipalException pe) {
90              throw new FileShortcutPermissionException();
91          }
92  
93          return dlFileShortcutLocalService.addFileShortcut(
94              getUserId(), folderId, toFolderId, toName, communityPermissions,
95              guestPermissions);
96      }
97  
98      public void deleteFileShortcut(long fileShortcutId)
99          throws PortalException, SystemException {
100 
101         DLFileShortcutPermission.check(
102             getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
103 
104         dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
105     }
106 
107     public DLFileShortcut getFileShortcut(long fileShortcutId)
108         throws PortalException, SystemException {
109 
110         DLFileShortcutPermission.check(
111             getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
112 
113         return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
114     }
115 
116     public DLFileShortcut updateFileShortcut(
117             long fileShortcutId, long folderId, long toFolderId, String toName)
118         throws PortalException, SystemException {
119 
120         DLFileShortcutPermission.check(
121             getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
122 
123         try {
124             DLFileEntryPermission.check(
125                 getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
126         }
127         catch (PrincipalException pe) {
128             throw new FileShortcutPermissionException();
129         }
130 
131         return dlFileShortcutLocalService.updateFileShortcut(
132             getUserId(), fileShortcutId, folderId, toFolderId, toName);
133     }
134 
135     public DLFileShortcut updateFileShortcut(
136             long fileShortcutId, long folderId, long toFolderId, String toName,
137             ServiceContext serviceContext)
138         throws PortalException, SystemException {
139 
140         DLFileShortcutPermission.check(
141             getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
142 
143         try {
144             DLFileEntryPermission.check(
145                 getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
146         }
147         catch (PrincipalException pe) {
148             throw new FileShortcutPermissionException();
149         }
150 
151         return dlFileShortcutLocalService.updateFileShortcut(
152             getUserId(), fileShortcutId, folderId, toFolderId, toName,
153             serviceContext);
154     }
155 
156 }