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.portal.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.model.Organization;
20  import com.liferay.portal.security.auth.PrincipalException;
21  import com.liferay.portal.security.permission.ActionKeys;
22  import com.liferay.portal.service.base.OrganizationServiceBaseImpl;
23  import com.liferay.portal.service.permission.GroupPermissionUtil;
24  import com.liferay.portal.service.permission.OrganizationPermissionUtil;
25  import com.liferay.portal.service.permission.PasswordPolicyPermissionUtil;
26  import com.liferay.portal.service.permission.PortalPermissionUtil;
27  
28  import java.util.List;
29  
30  /**
31   * <a href="OrganizationServiceImpl.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   * @author Jorge Ferrer
35   */
36  public class OrganizationServiceImpl extends OrganizationServiceBaseImpl {
37  
38      public void addGroupOrganizations(long groupId, long[] organizationIds)
39          throws PortalException, SystemException {
40  
41          GroupPermissionUtil.check(
42              getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
43  
44          organizationLocalService.addGroupOrganizations(
45              groupId, organizationIds);
46      }
47  
48      public void addPasswordPolicyOrganizations(
49              long passwordPolicyId, long[] organizationIds)
50          throws PortalException, SystemException {
51  
52          PasswordPolicyPermissionUtil.check(
53              getPermissionChecker(), passwordPolicyId, ActionKeys.UPDATE);
54  
55          organizationLocalService.addPasswordPolicyOrganizations(
56              passwordPolicyId, organizationIds);
57      }
58  
59      public Organization addOrganization(
60              long parentOrganizationId, String name, int type,
61              boolean recursable, long regionId, long countryId, int statusId,
62              String comments)
63          throws PortalException, SystemException {
64  
65          if (!OrganizationPermissionUtil.contains(
66                  getPermissionChecker(), parentOrganizationId,
67                  ActionKeys.MANAGE_SUBORGANIZATIONS) &&
68              !PortalPermissionUtil.contains(
69                  getPermissionChecker(), ActionKeys.ADD_ORGANIZATION)) {
70  
71              throw new PrincipalException(
72                  "User " + getUserId() + " does not have permissions to add " +
73                      "an organization with parent " + parentOrganizationId);
74          }
75  
76          return organizationLocalService.addOrganization(
77              getUserId(), parentOrganizationId, name, type, recursable,
78              regionId, countryId, statusId, comments);
79      }
80  
81      public void deleteOrganization(long organizationId)
82          throws PortalException, SystemException {
83  
84          OrganizationPermissionUtil.check(
85              getPermissionChecker(), organizationId, ActionKeys.DELETE);
86  
87          organizationLocalService.deleteOrganization(organizationId);
88      }
89  
90      public Organization getOrganization(long organizationId)
91          throws PortalException, SystemException {
92  
93          OrganizationPermissionUtil.check(
94              getPermissionChecker(), organizationId, ActionKeys.VIEW);
95  
96          return organizationLocalService.getOrganization(organizationId);
97      }
98  
99      public long getOrganizationId(long companyId, String name)
100         throws SystemException {
101 
102         return organizationLocalService.getOrganizationId(companyId, name);
103     }
104 
105     public List<Organization> getUserOrganizations(long userId)
106         throws PortalException, SystemException {
107 
108         return organizationLocalService.getUserOrganizations(userId);
109     }
110 
111     public List<Organization> getUserOrganizations(
112             long userId, boolean inheritUserGroups)
113         throws PortalException, SystemException {
114 
115         return organizationLocalService.getUserOrganizations(
116             userId, inheritUserGroups);
117     }
118 
119     public void setGroupOrganizations(long groupId, long[] organizationIds)
120         throws PortalException, SystemException {
121 
122         GroupPermissionUtil.check(
123             getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
124 
125         organizationLocalService.setGroupOrganizations(
126             groupId, organizationIds);
127     }
128 
129     public void unsetGroupOrganizations(long groupId, long[] organizationIds)
130         throws PortalException, SystemException {
131 
132         GroupPermissionUtil.check(
133             getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
134 
135         organizationLocalService.unsetGroupOrganizations(
136             groupId, organizationIds);
137     }
138 
139     public void unsetPasswordPolicyOrganizations(
140             long passwordPolicyId, long[] organizationIds)
141         throws PortalException, SystemException {
142 
143         PasswordPolicyPermissionUtil.check(
144             getPermissionChecker(), passwordPolicyId, ActionKeys.UPDATE);
145 
146         organizationLocalService.unsetPasswordPolicyOrganizations(
147             passwordPolicyId, organizationIds);
148     }
149 
150     public Organization updateOrganization(
151             long organizationId, long parentOrganizationId, String name,
152             int type, boolean recursable, long regionId, long countryId,
153             int statusId, String comments)
154         throws PortalException, SystemException {
155 
156         OrganizationPermissionUtil.check(
157             getPermissionChecker(), organizationId, ActionKeys.UPDATE);
158 
159         return organizationLocalService.updateOrganization(
160             getUser().getCompanyId(), organizationId, parentOrganizationId,
161             name, type, recursable, regionId, countryId, statusId, comments);
162     }
163 
164 }