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.portal.service.ServiceContext;
30  import com.liferay.portlet.documentlibrary.FileShortcutPermissionException;
31  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
32  import com.liferay.portlet.documentlibrary.service.base.DLFileShortcutServiceBaseImpl;
33  import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
34  import com.liferay.portlet.documentlibrary.service.permission.DLFileShortcutPermission;
35  import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
36  
37  /**
38   * <a href="DLFileShortcutServiceImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
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              ServiceContext serviceContext)
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, serviceContext);
83      }
84  
85      public DLFileShortcut addFileShortcut(
86              long folderId, long toFolderId, String toName,
87              String[] communityPermissions, String[] guestPermissions)
88          throws PortalException, SystemException {
89  
90          DLFolderPermission.check(
91              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
92  
93          try {
94              DLFileEntryPermission.check(
95                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
96          }
97          catch (PrincipalException pe) {
98              throw new FileShortcutPermissionException();
99          }
100 
101         return dlFileShortcutLocalService.addFileShortcut(
102             getUserId(), folderId, toFolderId, toName, communityPermissions,
103             guestPermissions);
104     }
105 
106     public void deleteFileShortcut(long fileShortcutId)
107         throws PortalException, SystemException {
108 
109         DLFileShortcutPermission.check(
110             getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
111 
112         dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
113     }
114 
115     public DLFileShortcut getFileShortcut(long fileShortcutId)
116         throws PortalException, SystemException {
117 
118         DLFileShortcutPermission.check(
119             getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
120 
121         return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
122     }
123 
124     public DLFileShortcut updateFileShortcut(
125             long fileShortcutId, long folderId, long toFolderId, String toName)
126         throws PortalException, SystemException {
127 
128         DLFileShortcutPermission.check(
129             getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
130 
131         try {
132             DLFileEntryPermission.check(
133                 getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
134         }
135         catch (PrincipalException pe) {
136             throw new FileShortcutPermissionException();
137         }
138 
139         return dlFileShortcutLocalService.updateFileShortcut(
140             getUserId(), fileShortcutId, folderId, toFolderId, toName);
141     }
142 
143     public DLFileShortcut updateFileShortcut(
144             long fileShortcutId, long folderId, long toFolderId, String toName,
145             ServiceContext serviceContext)
146         throws PortalException, SystemException {
147 
148         DLFileShortcutPermission.check(
149             getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
150 
151         try {
152             DLFileEntryPermission.check(
153                 getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
154         }
155         catch (PrincipalException pe) {
156             throw new FileShortcutPermissionException();
157         }
158 
159         return dlFileShortcutLocalService.updateFileShortcut(
160             getUserId(), fileShortcutId, folderId, toFolderId, toName,
161             serviceContext);
162     }
163 
164 }