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