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