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