001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.impl;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.security.permission.ActionKeys;
026: import com.liferay.portal.model.Organization;
027: import com.liferay.portal.security.auth.PrincipalException;
028: import com.liferay.portal.service.base.OrganizationServiceBaseImpl;
029: import com.liferay.portal.service.permission.GroupPermissionUtil;
030: import com.liferay.portal.service.permission.OrganizationPermissionUtil;
031: import com.liferay.portal.service.permission.PasswordPolicyPermissionUtil;
032: import com.liferay.portal.service.permission.PortalPermissionUtil;
033:
034: import java.util.List;
035:
036: /**
037: * <a href="OrganizationServiceImpl.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: * @author Jorge Ferrer
041: *
042: */
043: public class OrganizationServiceImpl extends
044: OrganizationServiceBaseImpl {
045:
046: public void addGroupOrganizations(long groupId,
047: long[] organizationIds) throws PortalException,
048: SystemException {
049:
050: GroupPermissionUtil.check(getPermissionChecker(), groupId,
051: ActionKeys.ASSIGN_MEMBERS);
052:
053: organizationLocalService.addGroupOrganizations(groupId,
054: organizationIds);
055: }
056:
057: public void addPasswordPolicyOrganizations(long passwordPolicyId,
058: long[] organizationIds) throws PortalException,
059: SystemException {
060:
061: PasswordPolicyPermissionUtil.check(getPermissionChecker(),
062: passwordPolicyId, ActionKeys.UPDATE);
063:
064: organizationLocalService.addPasswordPolicyOrganizations(
065: passwordPolicyId, organizationIds);
066: }
067:
068: public Organization addOrganization(long parentOrganizationId,
069: String name, int type, boolean recursable, long regionId,
070: long countryId, int statusId, String comments)
071: throws PortalException, SystemException {
072:
073: if (!OrganizationPermissionUtil.contains(
074: getPermissionChecker(), parentOrganizationId,
075: ActionKeys.MANAGE_SUBORGANIZATIONS)
076: && !PortalPermissionUtil.contains(
077: getPermissionChecker(),
078: ActionKeys.ADD_ORGANIZATION)) {
079:
080: throw new PrincipalException("User " + getUserId()
081: + " does not have permissions to add "
082: + "an organization with parent "
083: + parentOrganizationId);
084: }
085:
086: return organizationLocalService.addOrganization(getUserId(),
087: parentOrganizationId, name, type, recursable, regionId,
088: countryId, statusId, comments);
089: }
090:
091: public void deleteOrganization(long organizationId)
092: throws PortalException, SystemException {
093:
094: checkPermission(organizationId, ActionKeys.DELETE);
095:
096: organizationLocalService.deleteOrganization(organizationId);
097: }
098:
099: public Organization getOrganization(long organizationId)
100: throws PortalException, SystemException {
101:
102: checkPermission(organizationId, ActionKeys.VIEW);
103:
104: return organizationLocalService.getOrganization(organizationId);
105: }
106:
107: public long getOrganizationId(long companyId, String name)
108: throws PortalException, SystemException {
109:
110: return organizationLocalService.getOrganizationId(companyId,
111: name);
112: }
113:
114: public List getUserOrganizations(long userId)
115: throws PortalException, SystemException {
116:
117: return organizationLocalService.getUserOrganizations(userId);
118: }
119:
120: public void setGroupOrganizations(long groupId,
121: long[] organizationIds) throws PortalException,
122: SystemException {
123:
124: GroupPermissionUtil.check(getPermissionChecker(), groupId,
125: ActionKeys.ASSIGN_MEMBERS);
126:
127: organizationLocalService.setGroupOrganizations(groupId,
128: organizationIds);
129: }
130:
131: public void unsetGroupOrganizations(long groupId,
132: long[] organizationIds) throws PortalException,
133: SystemException {
134:
135: GroupPermissionUtil.check(getPermissionChecker(), groupId,
136: ActionKeys.ASSIGN_MEMBERS);
137:
138: organizationLocalService.unsetGroupOrganizations(groupId,
139: organizationIds);
140: }
141:
142: public void unsetPasswordPolicyOrganizations(long passwordPolicyId,
143: long[] organizationIds) throws PortalException,
144: SystemException {
145:
146: PasswordPolicyPermissionUtil.check(getPermissionChecker(),
147: passwordPolicyId, ActionKeys.UPDATE);
148:
149: organizationLocalService.unsetPasswordPolicyOrganizations(
150: passwordPolicyId, organizationIds);
151: }
152:
153: public Organization updateOrganization(long organizationId,
154: long parentOrganizationId, String name, int type,
155: boolean recursable, long regionId, long countryId,
156: int statusId, String comments) throws PortalException,
157: SystemException {
158:
159: checkPermission(organizationId, ActionKeys.UPDATE);
160:
161: return organizationLocalService.updateOrganization(getUser()
162: .getCompanyId(), organizationId, parentOrganizationId,
163: name, type, recursable, regionId, countryId, statusId,
164: comments);
165: }
166:
167: protected void checkPermission(long organizationId, String actionId)
168: throws PortalException, SystemException {
169:
170: OrganizationPermissionUtil.check(getPermissionChecker(),
171: organizationId, actionId);
172: }
173:
174: }
|