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, long 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, long 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, long 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, long 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 the organization with the primary key. 381 * 382 * @param organizationId the primary key of the organization 383 * @return the organization with the primary key, or <code>null</code> if an 384 * organization with the primary key could not be found or if the 385 * user did not have permission to view the organization 386 * @throws PortalException if a portal exception occurred 387 */ 388 @Override 389 public Organization fetchOrganization(long organizationId) 390 throws PortalException { 391 392 Organization organization = organizationLocalService.fetchOrganization( 393 organizationId); 394 395 if (organization != null) { 396 OrganizationPermissionUtil.check( 397 getPermissionChecker(), organizationId, ActionKeys.VIEW); 398 } 399 400 return organization; 401 } 402 403 /** 404 * Returns all the organizations which the user has permission to manage. 405 * 406 * @param actionId the permitted action 407 * @param max the maximum number of the organizations to be considered 408 * @return the organizations which the user has permission to manage 409 * @throws PortalException if a portal exception occurred 410 * @deprecated As of 6.2.0, replaced by {@link #getOrganizations(long, long, 411 * int, int)} 412 */ 413 @Deprecated 414 @Override 415 public List<Organization> getManageableOrganizations( 416 String actionId, int max) 417 throws PortalException { 418 419 PermissionChecker permissionChecker = getPermissionChecker(); 420 421 if (permissionChecker.isCompanyAdmin()) { 422 return organizationLocalService.search( 423 permissionChecker.getCompanyId(), 424 OrganizationConstants.ANY_PARENT_ORGANIZATION_ID, null, null, 425 null, null, null, 0, max); 426 } 427 428 LinkedHashMap<String, Object> params = new LinkedHashMap<>(); 429 430 List<Organization> userOrganizations = 431 organizationLocalService.getUserOrganizations( 432 permissionChecker.getUserId()); 433 434 params.put("organizationsTree", userOrganizations); 435 436 List<Organization> manageableOrganizations = 437 organizationLocalService.search( 438 permissionChecker.getCompanyId(), 439 OrganizationConstants.ANY_PARENT_ORGANIZATION_ID, null, null, 440 null, null, params, 0, max); 441 442 manageableOrganizations = ListUtil.copy(manageableOrganizations); 443 444 Iterator<Organization> itr = manageableOrganizations.iterator(); 445 446 while (itr.hasNext()) { 447 Organization organization = itr.next(); 448 449 if (!OrganizationPermissionUtil.contains( 450 permissionChecker, organization, actionId)) { 451 452 itr.remove(); 453 } 454 } 455 456 return manageableOrganizations; 457 } 458 459 /** 460 * Returns the organization with the primary key. 461 * 462 * @param organizationId the primary key of the organization 463 * @return the organization with the primary key 464 * @throws PortalException if an organization with the primary key could not 465 * be found or if the user did not have permission to view the 466 * organization 467 */ 468 @Override 469 public Organization getOrganization(long organizationId) 470 throws PortalException { 471 472 Organization organization = organizationLocalService.getOrganization( 473 organizationId); 474 475 OrganizationPermissionUtil.check( 476 getPermissionChecker(), organization, ActionKeys.VIEW); 477 478 return organization; 479 } 480 481 /** 482 * Returns the primary key of the organization with the name. 483 * 484 * @param companyId the primary key of the organization's company 485 * @param name the organization's name 486 * @return the primary key of the organization with the name, or 487 * <code>0</code> if the organization could not be found 488 * @throws PortalException if the user did not have permission to view the 489 * organization 490 */ 491 @Override 492 public long getOrganizationId(long companyId, String name) 493 throws PortalException { 494 495 long organizationId = organizationLocalService.getOrganizationId( 496 companyId, name); 497 498 OrganizationPermissionUtil.check( 499 getPermissionChecker(), organizationId, ActionKeys.VIEW); 500 501 return organizationId; 502 } 503 504 /** 505 * Returns all the organizations belonging to the parent organization. 506 * 507 * @param companyId the primary key of the organizations' company 508 * @param parentOrganizationId the primary key of the organizations' parent 509 * organization 510 * @return the organizations belonging to the parent organization 511 */ 512 @Override 513 public List<Organization> getOrganizations( 514 long companyId, long parentOrganizationId) { 515 516 if (parentOrganizationId == 517 OrganizationConstants.ANY_PARENT_ORGANIZATION_ID) { 518 519 return organizationPersistence.filterFindByCompanyId(companyId); 520 } 521 522 return organizationPersistence.filterFindByC_P( 523 companyId, parentOrganizationId); 524 } 525 526 /** 527 * Returns a range of all the organizations belonging to the parent 528 * organization. 529 * 530 * <p> 531 * Useful when paginating results. Returns a maximum of <code>end - 532 * start</code> instances. <code>start</code> and <code>end</code> are not 533 * primary keys, they are indexes in the result set. Thus, <code>0</code> 534 * refers to the first result in the set. Setting both <code>start</code> 535 * and <code>end</code> to {@link 536 * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full 537 * result set. 538 * </p> 539 * 540 * @param companyId the primary key of the organizations' company 541 * @param parentOrganizationId the primary key of the organizations' parent 542 * organization 543 * @param start the lower bound of the range of organizations to return 544 * @param end the upper bound of the range of organizations to return (not 545 * inclusive) 546 * @return the range of organizations belonging to the parent organization 547 */ 548 @Override 549 public List<Organization> getOrganizations( 550 long companyId, long parentOrganizationId, int start, int end) { 551 552 if (parentOrganizationId == 553 OrganizationConstants.ANY_PARENT_ORGANIZATION_ID) { 554 555 return organizationPersistence.filterFindByCompanyId( 556 companyId, start, end); 557 } 558 559 return organizationPersistence.filterFindByC_P( 560 companyId, parentOrganizationId, start, end); 561 } 562 563 /** 564 * Returns the number of organizations belonging to the parent organization. 565 * 566 * @param companyId the primary key of the organizations' company 567 * @param parentOrganizationId the primary key of the organizations' parent 568 * organization 569 * @return the number of organizations belonging to the parent organization 570 */ 571 @Override 572 public int getOrganizationsCount( 573 long companyId, long parentOrganizationId) { 574 575 if (parentOrganizationId == 576 OrganizationConstants.ANY_PARENT_ORGANIZATION_ID) { 577 578 return organizationPersistence.filterCountByCompanyId(companyId); 579 } 580 581 return organizationPersistence.filterCountByC_P( 582 companyId, parentOrganizationId); 583 } 584 585 /** 586 * Returns all the organizations with which the user is explicitly 587 * associated. 588 * 589 * <p> 590 * A user is considered to be <i>explicitly</i> associated with an 591 * organization if his account is individually created within the 592 * organization or if the user is later added as a member. 593 * </p> 594 * 595 * @param userId the primary key of the user 596 * @return the organizations with which the user is explicitly associated 597 * @throws PortalException if a user with the primary key could not be found 598 */ 599 @Override 600 public List<Organization> getUserOrganizations(long userId) 601 throws PortalException { 602 603 UserPermissionUtil.check( 604 getPermissionChecker(), userId, ActionKeys.VIEW); 605 606 return organizationLocalService.getUserOrganizations(userId); 607 } 608 609 /** 610 * Sets the organizations in the group, removing and adding organizations to 611 * the group as necessary. 612 * 613 * @param groupId the primary key of the group 614 * @param organizationIds the primary keys of the organizations 615 * @throws PortalException if a group or organization with the primary key 616 * could not be found or if the user did not have permission to 617 * assign group members 618 */ 619 @Override 620 public void setGroupOrganizations(long groupId, long[] organizationIds) 621 throws PortalException { 622 623 GroupPermissionUtil.check( 624 getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS); 625 626 organizationLocalService.setGroupOrganizations( 627 groupId, organizationIds); 628 } 629 630 /** 631 * Removes the organizations from the group. 632 * 633 * @param groupId the primary key of the group 634 * @param organizationIds the primary keys of the organizations 635 * @throws PortalException if a group or organization with the primary key 636 * could not be found or if the user did not have permission to 637 * assign group members 638 */ 639 @Override 640 public void unsetGroupOrganizations(long groupId, long[] organizationIds) 641 throws PortalException { 642 643 GroupPermissionUtil.check( 644 getPermissionChecker(), groupId, ActionKeys.ASSIGN_MEMBERS); 645 646 organizationLocalService.unsetGroupOrganizations( 647 groupId, organizationIds); 648 } 649 650 /** 651 * Removes the organizations from the password policy. 652 * 653 * @param passwordPolicyId the primary key of the password policy 654 * @param organizationIds the primary keys of the organizations 655 * @throws PortalException if a password policy or organization with the 656 * primary key could not be found, or if the user did not have 657 * permission to update the password policy 658 */ 659 @Override 660 public void unsetPasswordPolicyOrganizations( 661 long passwordPolicyId, long[] organizationIds) 662 throws PortalException { 663 664 PasswordPolicyPermissionUtil.check( 665 getPermissionChecker(), passwordPolicyId, ActionKeys.UPDATE); 666 667 organizationLocalService.unsetPasswordPolicyOrganizations( 668 passwordPolicyId, organizationIds); 669 } 670 671 /** 672 * Updates the organization with additional parameters. 673 * 674 * @param organizationId the primary key of the organization 675 * @param parentOrganizationId the primary key of the organization's 676 * parent organization 677 * @param name the organization's name 678 * @param type the organization's type 679 * @param recursable whether the permissions of the organization are to 680 * be inherited by its suborganizations 681 * @param regionId the primary key of the organization's region 682 * @param countryId the primary key of the organization's country 683 * @param statusId the organization's workflow status 684 * @param comments the comments about the organization 685 * @param site whether the organization is to be associated with a main 686 * site 687 * @param addresses the organization's addresses 688 * @param emailAddresses the organization's email addresses 689 * @param orgLabors the organization's hours of operation 690 * @param phones the organization's phone numbers 691 * @param websites the organization's websites 692 * @param serviceContext the service context to be applied (optionally 693 * <code>null</code>). Can set asset category IDs and asset tag 694 * names for the organization, and merge expando bridge 695 * attributes for the organization. 696 * @return the organization 697 * @throws PortalException if an organization or parent organization 698 * with the primary key could not be found, if the user did not 699 * have permission to update the organization information, or if 700 * the new information was invalid 701 * @deprecated As of 6.2.0, replaced by {@link #updateOrganization(long, 702 * long, String, String, long, long, int, String, boolean, 703 * byte[], boolean, java.util.List, java.util.List, 704 * java.util.List, java.util.List, java.util.List, 705 * ServiceContext)} 706 */ 707 @Deprecated 708 @Override 709 public Organization updateOrganization( 710 long organizationId, long parentOrganizationId, String name, 711 String type, boolean recursable, long regionId, long countryId, 712 long statusId, String comments, boolean site, 713 List<Address> addresses, List<EmailAddress> emailAddresses, 714 List<OrgLabor> orgLabors, List<Phone> phones, 715 List<Website> websites, ServiceContext serviceContext) 716 throws PortalException { 717 718 return updateOrganization( 719 organizationId, parentOrganizationId, name, type, regionId, 720 countryId, statusId, comments, true, null, site, addresses, 721 emailAddresses, orgLabors, phones, websites, serviceContext); 722 } 723 724 /** 725 * Updates the organization. 726 * 727 * @param organizationId the primary key of the organization 728 * @param parentOrganizationId the primary key of the organization's 729 * parent organization 730 * @param name the organization's name 731 * @param type the organization's type 732 * @param recursable whether permissions of the organization are to be 733 * inherited by its suborganizations 734 * @param regionId the primary key of the organization's region 735 * @param countryId the primary key of the organization's country 736 * @param statusId the organization's workflow status 737 * @param comments the comments about the organization 738 * @param site whether the organization is to be associated with a main 739 * site 740 * @param serviceContext the service context to be applied (optionally 741 * <code>null</code>). Can set asset category IDs and asset tag 742 * names for the organization, and merge expando bridge 743 * attributes for the organization. 744 * @return the organization 745 * @throws PortalException if an organization or parent organization 746 * with the primary key could not be found, if the user did not 747 * have permission to update the organization, or if the new 748 * information was invalid 749 * @deprecated As of 6.2.0, replaced by {@link #updateOrganization(long, 750 * long, String, String, long, long, int, String, boolean, 751 * ServiceContext)} 752 */ 753 @Deprecated 754 @Override 755 public Organization updateOrganization( 756 long organizationId, long parentOrganizationId, String name, 757 String type, boolean recursable, long regionId, long countryId, 758 long statusId, String comments, boolean site, 759 ServiceContext serviceContext) 760 throws PortalException { 761 762 return updateOrganization( 763 organizationId, parentOrganizationId, name, type, regionId, 764 countryId, statusId, comments, site, serviceContext); 765 } 766 767 /** 768 * Updates the organization with additional parameters. 769 * 770 * @param organizationId the primary key of the organization 771 * @param parentOrganizationId the primary key of the organization's parent 772 * organization 773 * @param name the organization's name 774 * @param type the organization's type 775 * @param regionId the primary key of the organization's region 776 * @param countryId the primary key of the organization's country 777 * @param statusId the organization's workflow status 778 * @param comments the comments about the organization 779 * @param logo whether to update the ogranization's logo 780 * @param logoBytes the new logo image data 781 * @param site whether the organization is to be associated with a main 782 * site 783 * @param addresses the organization's addresses 784 * @param emailAddresses the organization's email addresses 785 * @param orgLabors the organization's hours of operation 786 * @param phones the organization's phone numbers 787 * @param websites the organization's websites 788 * @param serviceContext the service context to be applied (optionally 789 * <code>null</code>). Can set asset category IDs and asset tag 790 * names for the organization, and merge expando bridge attributes 791 * for the organization. 792 * @return the organization 793 * @throws PortalException if an organization or parent organization with 794 * the primary key could not be found, if the user did not have 795 * permission to update the organization information, or if the new 796 * information was invalid 797 */ 798 @Override 799 public Organization updateOrganization( 800 long organizationId, long parentOrganizationId, String name, 801 String type, long regionId, long countryId, long statusId, 802 String comments, boolean logo, byte[] logoBytes, boolean site, 803 List<Address> addresses, List<EmailAddress> emailAddresses, 804 List<OrgLabor> orgLabors, List<Phone> phones, 805 List<Website> websites, ServiceContext serviceContext) 806 throws PortalException { 807 808 Organization organization = organizationPersistence.findByPrimaryKey( 809 organizationId); 810 811 OrganizationPermissionUtil.check( 812 getPermissionChecker(), organization, ActionKeys.UPDATE); 813 814 if (organization.getParentOrganizationId() != parentOrganizationId) { 815 if (parentOrganizationId == 816 OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID) { 817 818 PortalPermissionUtil.check( 819 getPermissionChecker(), ActionKeys.ADD_ORGANIZATION); 820 } 821 else { 822 OrganizationPermissionUtil.check( 823 getPermissionChecker(), parentOrganizationId, 824 ActionKeys.ADD_ORGANIZATION); 825 } 826 } 827 828 if (addresses != null) { 829 UsersAdminUtil.updateAddresses( 830 Organization.class.getName(), organizationId, addresses); 831 } 832 833 if (emailAddresses != null) { 834 UsersAdminUtil.updateEmailAddresses( 835 Organization.class.getName(), organizationId, emailAddresses); 836 } 837 838 if (orgLabors != null) { 839 UsersAdminUtil.updateOrgLabors(organizationId, orgLabors); 840 } 841 842 if (phones != null) { 843 UsersAdminUtil.updatePhones( 844 Organization.class.getName(), organizationId, phones); 845 } 846 847 if (websites != null) { 848 UsersAdminUtil.updateWebsites( 849 Organization.class.getName(), organizationId, websites); 850 } 851 852 User user = getUser(); 853 854 Organization oldOrganization = organization; 855 856 List<AssetCategory> oldAssetCategories = 857 assetCategoryLocalService.getCategories( 858 Organization.class.getName(), organizationId); 859 860 List<AssetTag> oldAssetTags = assetTagLocalService.getTags( 861 Organization.class.getName(), organizationId); 862 863 ExpandoBridge oldExpandoBridge = oldOrganization.getExpandoBridge(); 864 865 Map<String, Serializable> oldExpandoAttributes = 866 oldExpandoBridge.getAttributes(); 867 868 organization = organizationLocalService.updateOrganization( 869 user.getCompanyId(), organizationId, parentOrganizationId, name, 870 type, regionId, countryId, statusId, comments, logo, logoBytes, 871 site, serviceContext); 872 873 OrganizationMembershipPolicyUtil.verifyPolicy( 874 organization, oldOrganization, oldAssetCategories, oldAssetTags, 875 oldExpandoAttributes); 876 877 return organization; 878 } 879 880 /** 881 * Updates the organization with additional parameters. 882 * 883 * @param organizationId the primary key of the organization 884 * @param parentOrganizationId the primary key of the organization's 885 * parent organization 886 * @param name the organization's name 887 * @param type the organization's type 888 * @param regionId the primary key of the organization's region 889 * @param countryId the primary key of the organization's country 890 * @param statusId the organization's workflow status 891 * @param comments the comments about the organization 892 * @param site whether the organization is to be associated with a main 893 * site 894 * @param addresses the organization's addresses 895 * @param emailAddresses the organization's email addresses 896 * @param orgLabors the organization's hours of operation 897 * @param phones the organization's phone numbers 898 * @param websites the organization's websites 899 * @param serviceContext the service context to be applied (optionally 900 * <code>null</code>). Can set asset category IDs and asset tag 901 * names for the organization, and merge expando bridge 902 * attributes for the organization. 903 * @return the organization 904 * @throws PortalException if an organization or parent organization 905 * with the primary key could not be found, if the user did not 906 * have permission to update the organization information, or if 907 * the new information was invalid 908 * @deprecated As of 7.0.0, replaced by {@link #updateOrganization(long, 909 * long, String, String, long, long, int, String, boolean, 910 * byte[], boolean, java.util.List, java.util.List, 911 * java.util.List, java.util.List, java.util.List, 912 * ServiceContext)} 913 */ 914 @Deprecated 915 @Override 916 public Organization updateOrganization( 917 long organizationId, long parentOrganizationId, String name, 918 String type, long regionId, long countryId, long statusId, 919 String comments, boolean site, List<Address> addresses, 920 List<EmailAddress> emailAddresses, List<OrgLabor> orgLabors, 921 List<Phone> phones, List<Website> websites, 922 ServiceContext serviceContext) 923 throws PortalException { 924 925 return updateOrganization( 926 organizationId, parentOrganizationId, name, type, regionId, 927 countryId, statusId, comments, true, null, site, addresses, 928 emailAddresses, orgLabors, phones, websites, serviceContext); 929 } 930 931 /** 932 * Updates the organization. 933 * 934 * @param organizationId the primary key of the organization 935 * @param parentOrganizationId the primary key of the organization's parent 936 * organization 937 * @param name the organization's name 938 * @param type the organization's type 939 * @param regionId the primary key of the organization's region 940 * @param countryId the primary key of the organization's country 941 * @param statusId the organization's workflow status 942 * @param comments the comments about the organization 943 * @param site whether the organization is to be associated with a main 944 * site 945 * @param serviceContext the service context to be applied (optionally 946 * <code>null</code>). Can set asset category IDs and asset tag 947 * names for the organization, and merge expando bridge attributes 948 * for the organization. 949 * @return the organization 950 * @throws PortalException if an organization or parent organization with 951 * the primary key could not be found, if the user did not have 952 * permission to update the organization, or if the new information 953 * was invalid 954 */ 955 @Override 956 public Organization updateOrganization( 957 long organizationId, long parentOrganizationId, String name, 958 String type, long regionId, long countryId, long statusId, 959 String comments, boolean site, ServiceContext serviceContext) 960 throws PortalException { 961 962 return updateOrganization( 963 organizationId, parentOrganizationId, name, type, regionId, 964 countryId, statusId, comments, true, null, site, null, null, null, 965 null, null, serviceContext); 966 } 967 968 }