1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.documentlibrary.service.impl;
21  
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.security.auth.PrincipalException;
25  import com.liferay.portal.security.permission.ActionKeys;
26  import com.liferay.portlet.documentlibrary.FileShortcutPermissionException;
27  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
28  import com.liferay.portlet.documentlibrary.service.base.DLFileShortcutServiceBaseImpl;
29  import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
30  import com.liferay.portlet.documentlibrary.service.permission.DLFileShortcutPermission;
31  import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
32  
33  /**
34   * <a href="DLFileShortcutServiceImpl.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class DLFileShortcutServiceImpl extends DLFileShortcutServiceBaseImpl {
40  
41      public DLFileShortcut addFileShortcut(
42              long folderId, long toFolderId, String toName,
43              boolean addCommunityPermissions, boolean addGuestPermissions)
44          throws PortalException, SystemException {
45  
46          DLFolderPermission.check(
47              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
48  
49          try {
50              DLFileEntryPermission.check(
51                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
52          }
53          catch (PrincipalException pe) {
54              throw new FileShortcutPermissionException();
55          }
56  
57          return dlFileShortcutLocalService.addFileShortcut(
58              getUserId(), folderId, toFolderId, toName, addCommunityPermissions,
59              addGuestPermissions);
60      }
61  
62      public DLFileShortcut addFileShortcut(
63              long folderId, long toFolderId, String toName,
64              String[] communityPermissions, String[] guestPermissions)
65          throws PortalException, SystemException {
66  
67          DLFolderPermission.check(
68              getPermissionChecker(), folderId, ActionKeys.ADD_SHORTCUT);
69  
70          try {
71              DLFileEntryPermission.check(
72                  getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
73          }
74          catch (PrincipalException pe) {
75              throw new FileShortcutPermissionException();
76          }
77  
78          return dlFileShortcutLocalService.addFileShortcut(
79              getUserId(), folderId, toFolderId, toName, communityPermissions,
80              guestPermissions);
81      }
82  
83      public void deleteFileShortcut(long fileShortcutId)
84          throws PortalException, SystemException {
85  
86          DLFileShortcutPermission.check(
87              getPermissionChecker(), fileShortcutId, ActionKeys.DELETE);
88  
89          dlFileShortcutLocalService.deleteFileShortcut(fileShortcutId);
90      }
91  
92      public DLFileShortcut getFileShortcut(long fileShortcutId)
93          throws PortalException, SystemException {
94  
95          DLFileShortcutPermission.check(
96              getPermissionChecker(), fileShortcutId, ActionKeys.VIEW);
97  
98          return dlFileShortcutLocalService.getFileShortcut(fileShortcutId);
99      }
100 
101     public DLFileShortcut updateFileShortcut(
102             long fileShortcutId, long folderId, long toFolderId, String toName)
103         throws PortalException, SystemException {
104 
105         DLFileShortcutPermission.check(
106             getPermissionChecker(), fileShortcutId, ActionKeys.UPDATE);
107 
108         try {
109             DLFileEntryPermission.check(
110                 getPermissionChecker(), toFolderId, toName, ActionKeys.VIEW);
111         }
112         catch (PrincipalException pe) {
113             throw new FileShortcutPermissionException();
114         }
115 
116         return dlFileShortcutLocalService.updateFileShortcut(
117             getUserId(), fileShortcutId, folderId, toFolderId, toName);
118     }
119 
120 }