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