001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.search.Indexer;
020    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
021    import com.liferay.portal.kernel.util.ListUtil;
022    import com.liferay.portal.model.Address;
023    import com.liferay.portal.model.EmailAddress;
024    import com.liferay.portal.model.OrgLabor;
025    import com.liferay.portal.model.Organization;
026    import com.liferay.portal.model.OrganizationConstants;
027    import com.liferay.portal.model.Phone;
028    import com.liferay.portal.model.User;
029    import com.liferay.portal.model.Website;
030    import com.liferay.portal.security.auth.PrincipalException;
031    import com.liferay.portal.security.membershippolicy.OrganizationMembershipPolicyUtil;
032    import com.liferay.portal.security.permission.ActionKeys;
033    import com.liferay.portal.security.permission.PermissionChecker;
034    import com.liferay.portal.service.ServiceContext;
035    import com.liferay.portal.service.base.OrganizationServiceBaseImpl;
036    import com.liferay.portal.service.permission.GroupPermissionUtil;
037    import com.liferay.portal.service.permission.OrganizationPermissionUtil;
038    import com.liferay.portal.service.permission.PasswordPolicyPermissionUtil;
039    import com.liferay.portal.service.permission.PortalPermissionUtil;
040    import com.liferay.portal.service.permission.UserPermissionUtil;
041    import com.liferay.portlet.asset.model.AssetCategory;
042    import com.liferay.portlet.asset.model.AssetTag;
043    import com.liferay.portlet.expando.model.ExpandoBridge;
044    import com.liferay.portlet.usersadmin.util.UsersAdminUtil;
045    
046    import java.io.Serializable;
047    
048    import java.util.Iterator;
049    import java.util.LinkedHashMap;
050    import java.util.List;
051    import java.util.Map;
052    
053    /**
054     * Provides the remote service for accessing, adding, deleting, and updating
055     * organizations. Its methods include permission checks.
056     *
057     * @author Brian Wing Shun Chan
058     * @author Jorge Ferrer
059     * @author Julio Camarero
060     */
061    public class OrganizationServiceImpl extends OrganizationServiceBaseImpl {
062    
063            /**
064             * Adds the organizations to the group.
065             *
066             * @param  groupId the primary key of the group
067             * @param  organizationIds the primary keys of the organizations
068             * @throws PortalException if a group or organization with the primary key
069             *         could not be found or if the user did not have permission to
070             *         assign group members
071             * @throws SystemException if a system exception occurred
072             */
073            public void addGroupOrganizations(long groupId, long[] organizationIds)
074                    throws PortalException, SystemException {
075    
076                    GroupPermissionUtil.check(
077                            getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
078    
079                    organizationLocalService.addGroupOrganizations(
080                            groupId, organizationIds);
081            }
082    
083            /**
084             * Adds an organization with additional parameters.
085             *
086             * <p>
087             * This method handles the creation and bookkeeping of the organization
088             * including its resources, metadata, and internal data structures.
089             * </p>
090             *
091             * @param      parentOrganizationId the primary key of the organization's
092             *             parent organization
093             * @param      name the organization's name
094             * @param      type the organization's type
095             * @param      recursable whether the permissions of the organization are to
096             *             be inherited by its suborganizations
097             * @param      regionId the primary key of the organization's region
098             * @param      countryId the primary key of the organization's country
099             * @param      statusId the organization's workflow status
100             * @param      comments the comments about the organization
101             * @param      site whether the organization is to be associated with a main
102             *             site
103             * @param      addresses the organization's addresses
104             * @param      emailAddresses the organization's email addresses
105             * @param      orgLabors the organization's hours of operation
106             * @param      phones the organization's phone numbers
107             * @param      websites the organization's websites
108             * @param      serviceContext the service context to be applied (optionally
109             *             <code>null</code>). Can set asset category IDs, asset tag
110             *             names, and expando bridge attributes for the organization.
111             * @return     the organization
112             * @throws     PortalException if a parent organization with the primary key
113             *             could not be found, if the organization's information was
114             *             invalid, or if the user did not have permission to add the
115             *             organization
116             * @throws     SystemException if a system exception occurred
117             * @deprecated As of 6.2.0, replaced by {@link #addOrganization(long,
118             *             String, String, long, long, int, String, boolean,
119             *             java.util.List, java.util.List, java.util.List,
120             *             java.util.List, java.util.List, ServiceContext)}
121             */
122            public Organization addOrganization(
123                            long parentOrganizationId, String name, String type,
124                            boolean recursable, long regionId, long countryId, int statusId,
125                            String comments, boolean site, List<Address> addresses,
126                            List<EmailAddress> emailAddresses, List<OrgLabor> orgLabors,
127                            List<Phone> phones, List<Website> websites,
128                            ServiceContext serviceContext)
129                    throws PortalException, SystemException {
130    
131                    return addOrganization(
132                            parentOrganizationId, name, type, regionId, countryId, statusId,
133                            comments, site, addresses, emailAddresses, orgLabors, phones,
134                            websites, serviceContext);
135            }
136    
137            /**
138             * Adds an organization.
139             *
140             * <p>
141             * This method handles the creation and bookkeeping of the organization
142             * including its resources, metadata, and internal data structures.
143             * </p>
144             *
145             * @param      parentOrganizationId the primary key of the organization's
146             *             parent organization
147             * @param      name the organization's name
148             * @param      type the organization's type
149             * @param      recursable whether the permissions of the organization are to
150             *             be inherited by its suborganizations
151             * @param      regionId the primary key of the organization's region
152             * @param      countryId the primary key of the organization's country
153             * @param      statusId the organization's workflow status
154             * @param      comments the comments about the organization
155             * @param      site whether the organization is to be associated with a main
156             *             site
157             * @param      serviceContext the service context to be applied (optionally
158             *             <code>null</code>). Can set asset category IDs, asset tag
159             *             names, and expando bridge attributes for the organization.
160             * @return     the organization
161             * @throws     PortalException if the parent organization with the primary
162             *             key could not be found, if the organization information was
163             *             invalid, or if the user did not have permission to add the
164             *             organization
165             * @throws     SystemException if a system exception occurred
166             * @deprecated As of 6.2.0, replaced by {@link #addOrganization(long,
167             *             String, String, long, long, int, String, boolean,
168             *             ServiceContext)}
169             */
170            public Organization addOrganization(
171                            long parentOrganizationId, String name, String type,
172                            boolean recursable, long regionId, long countryId, int statusId,
173                            String comments, boolean site, ServiceContext serviceContext)
174                    throws PortalException, SystemException {
175    
176                    return addOrganization(
177                            parentOrganizationId, name, type, regionId, countryId, statusId,
178                            comments, site, serviceContext);
179            }
180    
181            /**
182             * Adds an organization with additional parameters.
183             *
184             * <p>
185             * This method handles the creation and bookkeeping of the organization
186             * including its resources, metadata, and internal data structures.
187             * </p>
188             *
189             * @param  parentOrganizationId the primary key of the organization's parent
190             *         organization
191             * @param  name the organization's name
192             * @param  type the organization's type
193             * @param  regionId the primary key of the organization's region
194             * @param  countryId the primary key of the organization's country
195             * @param  statusId the organization's workflow status
196             * @param  comments the comments about the organization
197             * @param  site whether the organization is to be associated with a main
198             *         site
199             * @param  addresses the organization's addresses
200             * @param  emailAddresses the organization's email addresses
201             * @param  orgLabors the organization's hours of operation
202             * @param  phones the organization's phone numbers
203             * @param  websites the organization's websites
204             * @param  serviceContext the service context to be applied (optionally
205             *         <code>null</code>). Can set asset category IDs, asset tag names,
206             *         and expando bridge attributes for the organization.
207             * @return the organization
208             * @throws PortalException if a parent organization with the primary key
209             *         could not be found, if the organization's information was
210             *         invalid, or if the user did not have permission to add the
211             *         organization
212             * @throws SystemException if a system exception occurred
213             */
214            public Organization addOrganization(
215                            long parentOrganizationId, String name, String type, long regionId,
216                            long countryId, int statusId, String comments, boolean site,
217                            List<Address> addresses, List<EmailAddress> emailAddresses,
218                            List<OrgLabor> orgLabors, List<Phone> phones,
219                            List<Website> websites, ServiceContext serviceContext)
220                    throws PortalException, SystemException {
221    
222                    boolean indexingEnabled = serviceContext.isIndexingEnabled();
223    
224                    serviceContext.setIndexingEnabled(false);
225    
226                    try {
227                            Organization organization = addOrganization(
228                                    parentOrganizationId, name, type, regionId, countryId, statusId,
229                                    comments, site, serviceContext);
230    
231                            UsersAdminUtil.updateAddresses(
232                                    Organization.class.getName(), organization.getOrganizationId(),
233                                    addresses);
234    
235                            UsersAdminUtil.updateEmailAddresses(
236                                    Organization.class.getName(), organization.getOrganizationId(),
237                                    emailAddresses);
238    
239                            UsersAdminUtil.updateOrgLabors(
240                                    organization.getOrganizationId(), orgLabors);
241    
242                            UsersAdminUtil.updatePhones(
243                                    Organization.class.getName(), organization.getOrganizationId(),
244                                    phones);
245    
246                            UsersAdminUtil.updateWebsites(
247                                    Organization.class.getName(), organization.getOrganizationId(),
248                                    websites);
249    
250                            if (indexingEnabled) {
251                                    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
252                                            Organization.class);
253    
254                                    indexer.reindex(organization);
255                            }
256    
257                            return organization;
258                    }
259                    finally {
260                            serviceContext.setIndexingEnabled(indexingEnabled);
261                    }
262            }
263    
264            /**
265             * Adds an organization.
266             *
267             * <p>
268             * This method handles the creation and bookkeeping of the organization
269             * including its resources, metadata, and internal data structures.
270             * </p>
271             *
272             * @param  parentOrganizationId the primary key of the organization's parent
273             *         organization
274             * @param  name the organization's name
275             * @param  type the organization's type
276             * @param  regionId the primary key of the organization's region
277             * @param  countryId the primary key of the organization's country
278             * @param  statusId the organization's workflow status
279             * @param  comments the comments about the organization
280             * @param  site whether the organization is to be associated with a main
281             *         site
282             * @param  serviceContext the service context to be applied (optionally
283             *         <code>null</code>). Can set asset category IDs, asset tag names,
284             *         and expando bridge attributes for the organization.
285             * @return the organization
286             * @throws PortalException if the parent organization with the primary key
287             *         could not be found, if the organization information was invalid,
288             *         or if the user did not have permission to add the organization
289             * @throws SystemException if a system exception occurred
290             */
291            public Organization addOrganization(
292                            long parentOrganizationId, String name, String type, long regionId,
293                            long countryId, int statusId, String comments, boolean site,
294                            ServiceContext serviceContext)
295                    throws PortalException, SystemException {
296    
297                    if (!OrganizationPermissionUtil.contains(
298                                    getPermissionChecker(), parentOrganizationId,
299                                    ActionKeys.MANAGE_SUBORGANIZATIONS) &&
300                            !PortalPermissionUtil.contains(
301                                    getPermissionChecker(), ActionKeys.ADD_ORGANIZATION)) {
302    
303                            throw new PrincipalException(
304                                    "User " + getUserId() + " does not have permissions to add " +
305                                            "an organization with parent " + parentOrganizationId);
306                    }
307    
308                    Organization organization = organizationLocalService.addOrganization(
309                            getUserId(), parentOrganizationId, name, type, regionId, countryId,
310                            statusId, comments, site, serviceContext);
311    
312                    OrganizationMembershipPolicyUtil.verifyPolicy(organization);
313    
314                    return organization;
315            }
316    
317            /**
318             * Assigns the password policy to the organizations, removing any other
319             * currently assigned password policies.
320             *
321             * @param  passwordPolicyId the primary key of the password policy
322             * @param  organizationIds the primary keys of the organizations
323             * @throws PortalException if the user did not have permission to update the
324             *         password policy
325             * @throws SystemException if a system exception occurred
326             */
327            public void addPasswordPolicyOrganizations(
328                            long passwordPolicyId, long[] organizationIds)
329                    throws PortalException, SystemException {
330    
331                    PasswordPolicyPermissionUtil.check(
332                            getPermissionChecker(), passwordPolicyId, ActionKeys.UPDATE);
333    
334                    organizationLocalService.addPasswordPolicyOrganizations(
335                            passwordPolicyId, organizationIds);
336            }
337    
338            /**
339             * Deletes the logo of the organization.
340             *
341             * @param  organizationId the primary key of the organization
342             * @throws PortalException if an organization with the primary key could not
343             *         be found, if the organization's logo could not be found, or if
344             *         the user did not have permission to update the organization
345             * @throws SystemException if a system exception occurred
346             */
347            public void deleteLogo(long organizationId)
348                    throws PortalException, SystemException {
349    
350                    OrganizationPermissionUtil.check(
351                            getPermissionChecker(), organizationId, ActionKeys.UPDATE);
352    
353                    organizationLocalService.deleteLogo(organizationId);
354            }
355    
356            /**
357             * Deletes the organization. The organization's associated resources and
358             * assets are also deleted.
359             *
360             * @param  organizationId the primary key of the organization
361             * @throws PortalException if an organization with the primary key could not
362             *         be found, if the user did not have permission to delete the
363             *         organization, if the organization had a workflow in approved
364             *         status, or if the organization was a parent organization
365             * @throws SystemException if a system exception occurred
366             */
367            public void deleteOrganization(long organizationId)
368                    throws PortalException, SystemException {
369    
370                    OrganizationPermissionUtil.check(
371                            getPermissionChecker(), organizationId, ActionKeys.DELETE);
372    
373                    organizationLocalService.deleteOrganization(organizationId);
374            }
375    
376            /**
377             * Returns all the organizations which the user has permission to manage.
378             *
379             * @param      actionId the permitted action
380             * @param      max the maximum number of the organizations to be considered
381             * @return     the organizations which the user has permission to manage
382             * @throws     PortalException if a portal exception occurred
383             * @throws     SystemException if a system exception occurred
384             * @deprecated As of 6.2.0, replaced by {@link #getOrganizations(long, long,
385             *             int, int)}
386             */
387            public List<Organization> getManageableOrganizations(
388                            String actionId, int max)
389                    throws PortalException, SystemException {
390    
391                    PermissionChecker permissionChecker = getPermissionChecker();
392    
393                    if (permissionChecker.isCompanyAdmin()) {
394                            return organizationLocalService.search(
395                                    permissionChecker.getCompanyId(),
396                                    OrganizationConstants.ANY_PARENT_ORGANIZATION_ID, null, null,
397                                    null, null, null, 0, max);
398                    }
399    
400                    LinkedHashMap<String, Object> params =
401                            new LinkedHashMap<String, Object>();
402    
403                    List<Organization> userOrganizations =
404                            organizationLocalService.getUserOrganizations(
405                                    permissionChecker.getUserId());
406    
407                    params.put("organizationsTree", userOrganizations);
408    
409                    List<Organization> manageableOrganizations =
410                            organizationLocalService.search(
411                                    permissionChecker.getCompanyId(),
412                                    OrganizationConstants.ANY_PARENT_ORGANIZATION_ID, null, null,
413                                    null, null, params, 0, max);
414    
415                    manageableOrganizations = ListUtil.copy(manageableOrganizations);
416    
417                    Iterator<Organization> itr = manageableOrganizations.iterator();
418    
419                    while (itr.hasNext()) {
420                            Organization organization = itr.next();
421    
422                            if (!OrganizationPermissionUtil.contains(
423                                            permissionChecker, organization, actionId)) {
424    
425                                    itr.remove();
426                            }
427                    }
428    
429                    return manageableOrganizations;
430            }
431    
432            /**
433             * Returns the organization with the primary key.
434             *
435             * @param  organizationId the primary key of the organization
436             * @return the organization with the primary key
437             * @throws PortalException if an organization with the primary key could not
438             *         be found or if the user did not have permission to view the
439             *         organization
440             * @throws SystemException if a system exception occurred
441             */
442            public Organization getOrganization(long organizationId)
443                    throws PortalException, SystemException {
444    
445                    OrganizationPermissionUtil.check(
446                            getPermissionChecker(), organizationId, ActionKeys.VIEW);
447    
448                    return organizationLocalService.getOrganization(organizationId);
449            }
450    
451            /**
452             * Returns the primary key of the organization with the name.
453             *
454             * @param  companyId the primary key of the organization's company
455             * @param  name the organization's name
456             * @return the primary key of the organization with the name, or
457             *         <code>0</code> if the organization could not be found
458             * @throws PortalException if the user did not have permission to view the
459             *         organization
460             * @throws SystemException if a system exception occurred
461             */
462            public long getOrganizationId(long companyId, String name)
463                    throws PortalException, SystemException {
464    
465                    long organizationId = organizationLocalService.getOrganizationId(
466                            companyId, name);
467    
468                    OrganizationPermissionUtil.check(
469                            getPermissionChecker(), organizationId, ActionKeys.VIEW);
470    
471                    return organizationId;
472            }
473    
474            /**
475             * Returns all the organizations belonging to the parent organization.
476             *
477             * @param  companyId the primary key of the organizations' company
478             * @param  parentOrganizationId the primary key of the organizations' parent
479             *         organization
480             * @return the organizations belonging to the parent organization
481             * @throws SystemException if a system exception occurred
482             */
483            public List<Organization> getOrganizations(
484                            long companyId, long parentOrganizationId)
485                    throws SystemException {
486    
487                    return organizationPersistence.filterFindByC_P(
488                            companyId, parentOrganizationId);
489            }
490    
491            /**
492             * Returns a range of all the organizations belonging to the parent
493             * organization.
494             *
495             * <p>
496             * Useful when paginating results. Returns a maximum of <code>end -
497             * start</code> instances. <code>start</code> and <code>end</code> are not
498             * primary keys, they are indexes in the result set. Thus, <code>0</code>
499             * refers to the first result in the set. Setting both <code>start</code>
500             * and <code>end</code> to {@link
501             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
502             * result set.
503             * </p>
504             *
505             * @param  companyId the primary key of the organizations' company
506             * @param  parentOrganizationId the primary key of the organizations' parent
507             *         organization
508             * @param  start the lower bound of the range of organizations to return
509             * @param  end the upper bound of the range of organizations to return (not
510             *         inclusive)
511             * @return the range of organizations belonging to the parent organization
512             * @throws SystemException if a system exception occurred
513             */
514            public List<Organization> getOrganizations(
515                            long companyId, long parentOrganizationId, int start, int end)
516                    throws SystemException {
517    
518                    return organizationPersistence.filterFindByC_P(
519                            companyId, parentOrganizationId, start, end);
520            }
521    
522            /**
523             * Returns the number of organizations belonging to the parent organization.
524             *
525             * @param  companyId the primary key of the organizations' company
526             * @param  parentOrganizationId the primary key of the organizations' parent
527             *         organization
528             * @return the number of organizations belonging to the parent organization
529             * @throws SystemException if a system exception occurred
530             */
531            public int getOrganizationsCount(long companyId, long parentOrganizationId)
532                    throws SystemException {
533    
534                    return organizationPersistence.filterCountByC_P(
535                            companyId, parentOrganizationId);
536            }
537    
538            /**
539             * Returns all the organizations associated with the user.
540             *
541             * @param  userId the primary key of the user
542             * @return the organizations associated with the user
543             * @throws PortalException if a user with the primary key could not be found
544             * @throws SystemException if a system exception occurred
545             */
546            public List<Organization> getUserOrganizations(long userId)
547                    throws PortalException, SystemException {
548    
549                    UserPermissionUtil.check(
550                            getPermissionChecker(), userId, ActionKeys.VIEW);
551    
552                    return organizationLocalService.getUserOrganizations(userId);
553            }
554    
555            /**
556             * Sets the organizations in the group, removing and adding organizations to
557             * the group as necessary.
558             *
559             * @param  groupId the primary key of the group
560             * @param  organizationIds the primary keys of the organizations
561             * @throws PortalException if a group or organization with the primary key
562             *         could not be found or if the user did not have permission to
563             *         assign group members
564             * @throws SystemException if a system exception occurred
565             */
566            public void setGroupOrganizations(long groupId, long[] organizationIds)
567                    throws PortalException, SystemException {
568    
569                    GroupPermissionUtil.check(
570                            getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
571    
572                    organizationLocalService.setGroupOrganizations(
573                            groupId, organizationIds);
574            }
575    
576            /**
577             * Removes the organizations from the group.
578             *
579             * @param  groupId the primary key of the group
580             * @param  organizationIds the primary keys of the organizations
581             * @throws PortalException if a group or organization with the primary key
582             *         could not be found or if the user did not have permission to
583             *         assign group members
584             * @throws SystemException if a system exception occurred
585             */
586            public void unsetGroupOrganizations(long groupId, long[] organizationIds)
587                    throws PortalException, SystemException {
588    
589                    GroupPermissionUtil.check(
590                            getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS);
591    
592                    organizationLocalService.unsetGroupOrganizations(
593                            groupId, organizationIds);
594            }
595    
596            /**
597             * Removes the organizations from the password policy.
598             *
599             * @param  passwordPolicyId the primary key of the password policy
600             * @param  organizationIds the primary keys of the organizations
601             * @throws PortalException if a password policy or organization with the
602             *         primary key could not be found, or if the user did not have
603             *         permission to update the password policy
604             * @throws SystemException if a system exception occurred
605             */
606            public void unsetPasswordPolicyOrganizations(
607                            long passwordPolicyId, long[] organizationIds)
608                    throws PortalException, SystemException {
609    
610                    PasswordPolicyPermissionUtil.check(
611                            getPermissionChecker(), passwordPolicyId, ActionKeys.UPDATE);
612    
613                    organizationLocalService.unsetPasswordPolicyOrganizations(
614                            passwordPolicyId, organizationIds);
615            }
616    
617            /**
618             * Updates the organization with additional parameters.
619             *
620             * @param      organizationId the primary key of the organization
621             * @param      parentOrganizationId the primary key of the organization's
622             *             parent organization
623             * @param      name the organization's name
624             * @param      type the organization's type
625             * @param      recursable whether the permissions of the organization are to
626             *             be inherited by its suborganizations
627             * @param      regionId the primary key of the organization's region
628             * @param      countryId the primary key of the organization's country
629             * @param      statusId the organization's workflow status
630             * @param      comments the comments about the organization
631             * @param      site whether the organization is to be associated with a main
632             *             site
633             * @param      addresses the organization's addresses
634             * @param      emailAddresses the organization's email addresses
635             * @param      orgLabors the organization's hours of operation
636             * @param      phones the organization's phone numbers
637             * @param      websites the organization's websites
638             * @param      serviceContext the service context to be applied (optionally
639             *             <code>null</code>). Can set asset category IDs and asset tag
640             *             names for the organization, and merge expando bridge
641             *             attributes for the organization.
642             * @return     the organization
643             * @throws     PortalException if an organization or parent organization
644             *             with the primary key could not be found, if the user did not
645             *             have permission to update the organization information, or if
646             *             the new information was invalid
647             * @throws     SystemException if a system exception occurred
648             * @deprecated As of 6.2.0, replaced by {@link #updateOrganization(long,
649             *             long, String, String, long, long, int, String, boolean,
650             *             java.util.List, java.util.List, java.util.List,
651             *             java.util.List, java.util.List, ServiceContext)}
652             */
653            public Organization updateOrganization(
654                            long organizationId, long parentOrganizationId, String name,
655                            String type, boolean recursable, long regionId, long countryId,
656                            int statusId, String comments, boolean site,
657                            List<Address> addresses, List<EmailAddress> emailAddresses,
658                            List<OrgLabor> orgLabors, List<Phone> phones,
659                            List<Website> websites, ServiceContext serviceContext)
660                    throws PortalException, SystemException {
661    
662                    return updateOrganization(
663                            organizationId, parentOrganizationId, name, type, regionId,
664                            countryId, statusId, comments, site, addresses, emailAddresses,
665                            orgLabors, phones, websites, serviceContext);
666            }
667    
668            /**
669             * Updates the organization.
670             *
671             * @param      organizationId the primary key of the organization
672             * @param      parentOrganizationId the primary key of the organization's
673             *             parent organization
674             * @param      name the organization's name
675             * @param      type the organization's type
676             * @param      recursable whether permissions of the organization are to be
677             *             inherited by its suborganizations
678             * @param      regionId the primary key of the organization's region
679             * @param      countryId the primary key of the organization's country
680             * @param      statusId the organization's workflow status
681             * @param      comments the comments about the organization
682             * @param      site whether the organization is to be associated with a main
683             *             site
684             * @param      serviceContext the service context to be applied (optionally
685             *             <code>null</code>). Can set asset category IDs and asset tag
686             *             names for the organization, and merge expando bridge
687             *             attributes for the organization.
688             * @return     the organization
689             * @throws     PortalException if an organization or parent organization
690             *             with the primary key could not be found, if the user did not
691             *             have permission to update the organization, or if the new
692             *             information was invalid
693             * @throws     SystemException if a system exception occurred
694             * @deprecated As of 6.2.0, replaced by {@link #updateOrganization(long,
695             *             long, String, String, long, long, int, String, boolean,
696             *             ServiceContext)}
697             */
698            public Organization updateOrganization(
699                            long organizationId, long parentOrganizationId, String name,
700                            String type, boolean recursable, long regionId, long countryId,
701                            int statusId, String comments, boolean site,
702                            ServiceContext serviceContext)
703                    throws PortalException, SystemException {
704    
705                    return updateOrganization(
706                            organizationId, parentOrganizationId, name, type, regionId,
707                            countryId, statusId, comments, site, serviceContext);
708            }
709    
710            /**
711             * Updates the organization with additional parameters.
712             *
713             * @param  organizationId the primary key of the organization
714             * @param  parentOrganizationId the primary key of the organization's parent
715             *         organization
716             * @param  name the organization's name
717             * @param  type the organization's type
718             * @param  regionId the primary key of the organization's region
719             * @param  countryId the primary key of the organization's country
720             * @param  statusId the organization's workflow status
721             * @param  comments the comments about the organization
722             * @param  site whether the organization is to be associated with a main
723             *         site
724             * @param  addresses the organization's addresses
725             * @param  emailAddresses the organization's email addresses
726             * @param  orgLabors the organization's hours of operation
727             * @param  phones the organization's phone numbers
728             * @param  websites the organization's websites
729             * @param  serviceContext the service context to be applied (optionally
730             *         <code>null</code>). Can set asset category IDs and asset tag
731             *         names for the organization, and merge expando bridge attributes
732             *         for the organization.
733             * @return the organization
734             * @throws PortalException if an organization or parent organization with
735             *         the primary key could not be found, if the user did not have
736             *         permission to update the organization information, or if the new
737             *         information was invalid
738             * @throws SystemException if a system exception occurred
739             */
740            public Organization updateOrganization(
741                            long organizationId, long parentOrganizationId, String name,
742                            String type, long regionId, long countryId, int statusId,
743                            String comments, boolean site, List<Address> addresses,
744                            List<EmailAddress> emailAddresses, List<OrgLabor> orgLabors,
745                            List<Phone> phones, List<Website> websites,
746                            ServiceContext serviceContext)
747                    throws PortalException, SystemException {
748    
749                    Organization organization = organizationPersistence.findByPrimaryKey(
750                            organizationId);
751    
752                    OrganizationPermissionUtil.check(
753                            getPermissionChecker(), organization, ActionKeys.UPDATE);
754    
755                    if (organization.getParentOrganizationId() != parentOrganizationId) {
756                            if (parentOrganizationId ==
757                                            OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID) {
758    
759                                    PortalPermissionUtil.check(
760                                            getPermissionChecker(), ActionKeys.ADD_ORGANIZATION);
761                            }
762                            else {
763                                    if (!OrganizationPermissionUtil.contains(
764                                                    getPermissionChecker(), parentOrganizationId,
765                                                    ActionKeys.MANAGE_SUBORGANIZATIONS) &&
766                                            !PortalPermissionUtil.contains(
767                                                    getPermissionChecker(), ActionKeys.ADD_ORGANIZATION)) {
768    
769                                            throw new PrincipalException(
770                                                    "User " + getUserId() + " does not have permissions " +
771                                                            "to move organization " + organizationId + "to " +
772                                                                    "parent " + parentOrganizationId);
773                                    }
774                            }
775                    }
776    
777                    if (addresses != null) {
778                            UsersAdminUtil.updateAddresses(
779                                    Organization.class.getName(), organizationId, addresses);
780                    }
781    
782                    if (emailAddresses != null) {
783                            UsersAdminUtil.updateEmailAddresses(
784                                    Organization.class.getName(), organizationId, emailAddresses);
785                    }
786    
787                    if (orgLabors != null) {
788                            UsersAdminUtil.updateOrgLabors(organizationId, orgLabors);
789                    }
790    
791                    if (phones != null) {
792                            UsersAdminUtil.updatePhones(
793                                    Organization.class.getName(), organizationId, phones);
794                    }
795    
796                    if (websites != null) {
797                            UsersAdminUtil.updateWebsites(
798                                    Organization.class.getName(), organizationId, websites);
799                    }
800    
801                    User user = getUser();
802    
803                    Organization oldOrganization = organization;
804    
805                    List<AssetCategory> oldAssetCategories =
806                            assetCategoryLocalService.getCategories(
807                                    Organization.class.getName(), organizationId);
808    
809                    List<AssetTag> oldAssetTags = assetTagLocalService.getTags(
810                            Organization.class.getName(), organizationId);
811    
812                    ExpandoBridge oldExpandoBridge = oldOrganization.getExpandoBridge();
813    
814                    Map<String, Serializable> oldExpandoAttributes =
815                            oldExpandoBridge.getAttributes();
816    
817                    organization = organizationLocalService.updateOrganization(
818                            user.getCompanyId(), organizationId, parentOrganizationId, name,
819                            type, regionId, countryId, statusId, comments, site,
820                            serviceContext);
821    
822                    OrganizationMembershipPolicyUtil.verifyPolicy(
823                            organization, oldOrganization, oldAssetCategories, oldAssetTags,
824                            oldExpandoAttributes);
825    
826                    return organization;
827            }
828    
829            /**
830             * Updates the organization.
831             *
832             * @param  organizationId the primary key of the organization
833             * @param  parentOrganizationId the primary key of the organization's parent
834             *         organization
835             * @param  name the organization's name
836             * @param  type the organization's type
837             * @param  regionId the primary key of the organization's region
838             * @param  countryId the primary key of the organization's country
839             * @param  statusId the organization's workflow status
840             * @param  comments the comments about the organization
841             * @param  site whether the organization is to be associated with a main
842             *         site
843             * @param  serviceContext the service context to be applied (optionally
844             *         <code>null</code>). Can set asset category IDs and asset tag
845             *         names for the organization, and merge expando bridge attributes
846             *         for the organization.
847             * @return the organization
848             * @throws PortalException if an organization or parent organization with
849             *         the primary key could not be found, if the user did not have
850             *         permission to update the organization, or if the new information
851             *         was invalid
852             * @throws SystemException if a system exception occurred
853             */
854            public Organization updateOrganization(
855                            long organizationId, long parentOrganizationId, String name,
856                            String type, long regionId, long countryId, int statusId,
857                            String comments, boolean site, ServiceContext serviceContext)
858                    throws PortalException, SystemException {
859    
860                    return updateOrganization(
861                            organizationId, parentOrganizationId, name, type, regionId,
862                            countryId, statusId, comments, site, null, null, null, null, null,
863                            serviceContext);
864            }
865    
866    }