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