1 79 package com.ivata.groupware.business.addressbook; 80 81 import java.util.ArrayList ; 82 import java.util.Arrays ; 83 import java.util.Collections ; 84 import java.util.Iterator ; 85 import java.util.List ; 86 import java.util.Stack ; 87 import java.util.Vector ; 88 89 import javax.ejb.EJBException ; 90 91 import com.ivata.groupware.admin.security.Security; 92 import com.ivata.groupware.admin.security.server.SecuritySession; 93 import com.ivata.groupware.admin.security.user.UserDO; 94 import com.ivata.groupware.admin.security.user.UserConstants; 95 import com.ivata.groupware.admin.setting.Settings; 96 import com.ivata.groupware.business.BusinessLogic; 97 import com.ivata.groupware.business.addressbook.address.AddressDO; 98 import com.ivata.groupware.business.addressbook.address.country.CountryDO; 99 import com.ivata.groupware.business.addressbook.person.PersonDO; 100 import com.ivata.groupware.business.addressbook.person.group.GroupConstants; 101 import com.ivata.groupware.business.addressbook.person.group.GroupDO; 102 import com.ivata.groupware.business.addressbook.person.group.right.RightConstants; 103 import com.ivata.groupware.business.addressbook.right.AddressBookRights; 104 import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressConstants; 105 import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressDO; 106 import com.ivata.groupware.container.persistence.QueryPersistenceManager; 107 import com.ivata.groupware.container.persistence.TimestampDOHandling; 108 import com.ivata.groupware.container.persistence.listener.RemovePersistenceListener; 109 import com.ivata.mask.Mask; 110 import com.ivata.mask.MaskFactory; 111 import com.ivata.mask.persistence.PersistenceException; 112 import com.ivata.mask.persistence.PersistenceSession; 113 import com.ivata.mask.util.StringHandling; 114 import com.ivata.mask.util.SystemException; 115 import com.ivata.mask.validation.ValidationError; 116 import com.ivata.mask.validation.ValidationErrors; 117 import com.ivata.mask.validation.ValidationException; 118 import com.ivata.mask.valueobject.ValueObject; 119 120 126 public class AddressBookImpl extends BusinessLogic implements AddressBook, 127 RemovePersistenceListener { 128 129 132 private class CountryComparator implements java.util.Comparator { 133 134 144 public final int compare(final Object object1, 145 final Object object2) { 146 CountryDO country1 = (CountryDO) object1; 147 CountryDO country2 = (CountryDO) object2; 148 return new Integer (country1.getPriority()).compareTo(new Integer (country2.getPriority())); 149 } 150 } 151 152 155 private class PersonComparator implements java.util.Comparator { 156 157 167 public int compare(final Object object1, 168 final Object object2) { 169 PersonDO person1 = (PersonDO) object1; 170 PersonDO person2 = (PersonDO) object2; 171 String fileAs1 = person1.getFileAs(); 172 String fileAs2 = person2.getFileAs(); 173 174 if (fileAs1 == null) { 176 return (fileAs2 == null) ? 0 : 1; 177 } else if (fileAs2 == null) { 178 return 1; 179 } else { 180 fileAs1 += person1.getId(); 183 fileAs2 += person2.getId(); 184 return fileAs1.toLowerCase().compareTo(fileAs2.toLowerCase()); 185 } 186 } 187 } 188 private MaskFactory maskFactory; 189 190 193 private QueryPersistenceManager persistenceManager; 194 private AddressBookRights rights; 195 private Settings settings; 196 201 public AddressBookImpl(final QueryPersistenceManager persistenceManager, 202 final MaskFactory maskFactoryParam, 203 final AddressBookRights rights, 204 final Settings settings) { 205 this.persistenceManager = persistenceManager; 206 this.maskFactory = maskFactoryParam; 207 persistenceManager.addRemoveListener(GroupDO.class, this); 208 this.rights = rights; 209 this.settings = settings; 210 } 211 212 215 public GroupDO addAddressBook(final SecuritySession securitySession, 216 final GroupDO groupDO) 217 throws SystemException { 218 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 219 try { 220 ValidationErrors errors = validate(securitySession, groupDO); 222 if (!errors.isEmpty()) { 223 throw new ValidationException(errors); 224 } 225 GroupDO parent = (GroupDO) persistenceManager.findByPrimaryKey( 226 persistenceSession, 227 GroupDO.class, GroupConstants.ADDRESS_BOOK_PUBLIC); 228 groupDO.setParent(parent); 229 230 TimestampDOHandling.add(securitySession, groupDO); 231 persistenceManager.add(persistenceSession, groupDO); 232 return groupDO; 233 } catch (Exception e) { 234 persistenceSession.cancel(); 235 throw new SystemException(e); 236 } finally { 237 persistenceSession.close(); 238 } 239 } 240 241 244 public GroupDO addGroup(final SecuritySession securitySession, 245 final GroupDO groupDO) 246 throws SystemException { 247 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 248 try { 249 ValidationErrors errors = validate(securitySession, groupDO); 251 if (!errors.isEmpty()) { 252 throw new ValidationException(errors); 253 } 254 255 TimestampDOHandling.add(securitySession, groupDO); 256 return (GroupDO) persistenceManager.add(persistenceSession, groupDO); 257 } catch (Exception e) { 258 persistenceSession.cancel(); 259 throw new SystemException(e); 260 } finally { 261 persistenceSession.close(); 262 } 263 } 264 265 268 public PersonDO addPerson(final SecuritySession securitySession, 269 final PersonDO person) 270 throws SystemException { 271 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 272 try { 273 ValidationErrors errors = validate(securitySession, person); 275 if (!errors.isEmpty()) { 276 throw new ValidationException(errors); 277 } 278 TimestampDOHandling.add(securitySession, person); 279 if (person.getTelecomAddresses() != null) { 280 Iterator telecomAddressIterator = person.getTelecomAddresses().iterator(); 281 while (telecomAddressIterator.hasNext()) { 282 TelecomAddressDO telecomAddress = (TelecomAddressDO) telecomAddressIterator.next(); 283 telecomAddress.setId(null); 285 TimestampDOHandling.add(securitySession, telecomAddress); 286 } 287 } 288 if (person.getAddress() != null) { 290 person.getAddress().setPerson(person); 291 } 292 return (PersonDO) persistenceManager.add(persistenceSession, 293 person); 294 } catch (Exception e) { 295 persistenceSession.cancel(); 296 throw new SystemException(e); 297 } finally { 298 persistenceSession.close(); 299 } 300 } 301 302 305 public GroupDO addUserGroup(final SecuritySession securitySession, 306 final GroupDO groupDO) 307 throws SystemException { 308 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 309 try { 310 ValidationErrors errors = validate(securitySession, groupDO); 312 if (!errors.isEmpty()) { 313 throw new ValidationException(errors); 314 } 315 316 GroupDO parent = (GroupDO) persistenceManager.findByPrimaryKey( 317 persistenceSession, 318 GroupDO.class, GroupConstants.USER_GROUP); 319 groupDO.setParent(parent); 320 321 TimestampDOHandling.add(securitySession, groupDO); 322 return (GroupDO) persistenceManager.add(persistenceSession, groupDO); 323 } catch (Exception e) { 324 persistenceSession.cancel(); 325 throw new SystemException(e); 326 } finally { 327 persistenceSession.close(); 328 } 329 } 330 331 334 public GroupDO amendGroup(final SecuritySession securitySession, 335 final GroupDO groupDO) 336 throws SystemException { 337 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 338 try { 339 ValidationErrors errors = validate(securitySession, groupDO); 341 if (!errors.isEmpty()) { 342 throw new ValidationException(errors); 343 } 344 345 TimestampDOHandling.amend(securitySession, groupDO); 346 persistenceManager.amend(persistenceSession, groupDO); 347 return groupDO; 348 } catch (Exception e) { 349 persistenceSession.cancel(); 350 throw new SystemException(e); 351 } finally { 352 persistenceSession.close(); 353 } 354 } 355 356 359 public PersonDO amendPerson(final SecuritySession securitySession, 360 final PersonDO person) 361 throws SystemException { 362 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 363 try { 364 ValidationErrors errors = validate(securitySession, person); 366 if (!errors.isEmpty()) { 367 throw new ValidationException(errors); 368 } 369 TimestampDOHandling.amend(securitySession, person); 370 if (person.getTelecomAddresses() != null) { 371 Iterator telecomAddressIterator = person.getTelecomAddresses().iterator(); 372 while (telecomAddressIterator.hasNext()) { 373 TelecomAddressDO telecomAddress = (TelecomAddressDO) telecomAddressIterator.next(); 374 if (telecomAddress.getId() == null) { 375 TimestampDOHandling.add(securitySession, telecomAddress); 376 } else { 377 TimestampDOHandling.amend(securitySession, telecomAddress); 378 } 379 } 380 } 381 if (person.getAddress() != null) { 383 person.getAddress().setPerson(person); 384 } 385 if ((person.getEmployee() != null) 388 && (person.getEmployee().getCountry() != null) 389 && (person.getEmployee().getCountry().getId() == null)) { 390 person.getEmployee().setCountry(null); 391 } 392 if ((person.getUser() != null) 395 && !StringHandling.isNullOrEmpty(person.getUser() 396 .getName())) { 397 GroupDO addressBook = person.getGroup().getAddressBook(); 398 if (!GroupConstants.equals( 399 addressBook.getId(), 400 GroupConstants.ADDRESS_BOOK_DEFAULT)) { 401 GroupDO defaultAddressBook = findGroupByPrimaryKey( 402 securitySession, 403 GroupConstants.ADDRESS_BOOK_DEFAULT); 404 person.setGroup(defaultAddressBook); 405 } 406 } 407 persistenceManager.amend(persistenceSession, person); 408 409 return person; 410 } catch (Exception e) { 411 persistenceSession.cancel(); 412 throw new SystemException(e); 413 } finally { 414 persistenceSession.close(); 415 } 416 } 417 418 421 public List findAddressBooks(final SecuritySession securitySession, 422 final boolean includePersonal) 423 throws SystemException { 424 List addressBooks = new ArrayList (); 425 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 426 try { 427 GroupDO addressBookParent = (GroupDO) persistenceManager 428 .findByPrimaryKey( 429 persistenceSession, 430 GroupDO.class, 431 GroupConstants.ADDRESS_BOOK_PUBLIC); 432 List children = persistenceManager.find(persistenceSession, 433 "addressBookGroupsInGroup", new Object []{addressBookParent.getId()}); 434 addressBooks.addAll(children); 435 436 if (includePersonal) { 438 GroupDO personalAddressBook = findPersonalAddressBook(securitySession); 439 addressBooks.add(personalAddressBook); 440 } 441 return Collections.synchronizedList(addressBooks); 442 } catch (Exception e) { 443 persistenceSession.cancel(); 444 throw new SystemException(e); 445 } finally { 446 persistenceSession.close(); 447 } 448 } 449 450 453 public List findAllCountries(final SecuritySession securitySession) 454 throws SystemException { 455 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 456 try { 457 return Collections.synchronizedList(persistenceManager.findAll(persistenceSession, CountryDO.class)); 458 } catch (Exception e) { 459 persistenceSession.cancel(); 460 throw new SystemException(e); 461 } finally { 462 persistenceSession.close(); 463 } 464 } 465 472 private void findAllPeopleInGroup(final GroupDO group, 473 final String lowerCaseInitialLetter, 474 final List totalResults, 475 final Stack parentGroups) throws SystemException { 476 PersistenceSession persistenceSession = persistenceManager.openSession(); 478 parentGroups.push(group); 479 480 Mask groupMask = maskFactory.getMask(GroupDO.class); 481 try { 482 List children = persistenceManager.find(persistenceSession, 483 "addressBookGroupsInGroup", new Object []{group.getId()}); 484 Iterator childIterator = children.iterator(); 485 while(childIterator.hasNext()) { 486 GroupDO child = (GroupDO) childIterator.next(); 487 if (parentGroups.contains(child)) { 488 throw new ValidationException( 489 new ValidationError( 490 "errors.addressbook.group.parent", 491 Arrays.asList(new Object [] { 492 group, 493 child 494 })) 495 ); 496 } 497 findAllPeopleInGroup(child, lowerCaseInitialLetter, totalResults, 498 parentGroups); 499 } 500 } catch (Exception e) { 501 persistenceSession.cancel(); 502 throw new SystemException(e); 503 } finally { 504 parentGroups.pop(); 505 persistenceSession.close(); 506 } 507 508 Iterator personIterator = group.getPeople().iterator(); 511 while(personIterator.hasNext()) { 512 PersonDO person = (PersonDO) personIterator.next(); 513 String fileAs = person.getFileAs(); 514 if (StringHandling.isNullOrEmpty(fileAs)) { 515 continue; 516 } 517 if ((lowerCaseInitialLetter != null) 518 && !lowerCaseInitialLetter 519 .equals(fileAs.substring(0, 1).toLowerCase())) { 520 continue; 521 } 522 totalResults.add(person); 523 } 524 } 525 526 531 public List findAllPeopleInGroup(final SecuritySession securitySession, 532 final GroupDO group, 533 final String initialLetterParam) throws SystemException { 534 boolean demoVersion = settings.getBooleanSetting(securitySession, 535 "demoVersion", null).booleanValue(); 536 List results = new Vector (); 537 String initialLetterLowerCase = initialLetterParam; 538 if (initialLetterLowerCase != null) { 539 initialLetterLowerCase = initialLetterLowerCase.toLowerCase(); 540 } 541 findAllPeopleInGroup(group, initialLetterLowerCase, results, 542 new Stack ()); 543 544 List filteredResults = new Vector (); 549 Iterator peopleIterator = results.iterator(); 550 while (peopleIterator.hasNext()) { 551 PersonDO person = (PersonDO) peopleIterator.next(); 552 if (demoVersion && UserConstants 555 .ADMINISTRATOR.equals(person.getId())) { 556 continue; 557 } 558 if (person.isDeleted()) { 559 continue; 560 } 561 if (!rights.canUser(securitySession, person.getGroup(), 562 RightConstants.ACCESS_VIEW)) { 563 continue; 564 } 565 filteredResults.add(person); 566 } 567 568 return Collections.synchronizedList(filteredResults); 569 } 570 571 574 public CountryDO findCountryByCode(final SecuritySession securitySession, 575 final String countryCode) 576 throws SystemException { 577 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 578 try { 579 return (CountryDO) persistenceManager.findInstance(persistenceSession, 580 "addressBookCountryByCode", new Object [] {countryCode}); 581 } catch (Exception e) { 582 persistenceSession.cancel(); 583 throw new SystemException(e); 584 } finally { 585 persistenceSession.close(); 586 } 587 } 588 589 592 public GroupDO findGroupByPrimaryKey(final SecuritySession securitySession, 593 final Integer id) 594 throws SystemException { 595 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 596 try { 597 return (GroupDO) persistenceManager.findByPrimaryKey(persistenceSession, 598 GroupDO.class, id); 599 } catch (Exception e) { 600 persistenceSession.cancel(); 601 throw new SystemException(e); 602 } finally { 603 persistenceSession.close(); 604 } 605 } 606 607 613 public List findGroupsByParent(final SecuritySession securitySession, 614 final Integer parentId) 615 throws SystemException { 616 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 617 try { 618 return Collections.synchronizedList(persistenceManager.find(persistenceSession, 619 "addressBookGroupsInGroup", new Object []{parentId})); 620 } catch (Exception e) { 621 persistenceSession.cancel(); 622 throw new SystemException(e); 623 } finally { 624 persistenceSession.close(); 625 } 626 } 627 628 631 public GroupDO findPersonalAddressBook(final SecuritySession securitySession) 632 throws SystemException { 633 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 634 try { 635 return (GroupDO) persistenceManager.findInstance(persistenceSession, 636 "addressBookGroupsInGroupByName", 637 new Object [] {GroupConstants.ADDRESS_BOOK_PRIVATE, 638 securitySession.getUser().getName()}); 639 } catch (Exception e) { 640 persistenceSession.cancel(); 641 throw new SystemException(e); 642 } finally { 643 persistenceSession.close(); 644 } 645 } 646 647 650 public PersonDO findPersonByPrimaryKey(final SecuritySession securitySession, 651 final String id) 652 throws SystemException { 653 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 654 try { 655 return (PersonDO) persistenceManager.findByPrimaryKey(persistenceSession, 656 PersonDO.class, id); 657 } catch (Exception e) { 658 persistenceSession.cancel(); 659 throw new SystemException(e); 660 } finally { 661 persistenceSession.close(); 662 } 663 } 664 665 672 public PersonDO findPersonByUserName(final SecuritySession securitySession, 673 final String userName) throws SystemException { 674 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 675 try { 676 return (PersonDO) persistenceManager.findInstance(persistenceSession, 677 "addressBookPersonByUserName", new Object [] {userName}); 678 } catch (Exception e) { 679 persistenceSession.cancel(); 680 throw new SystemException(e); 681 } finally { 682 persistenceSession.close(); 683 } 684 } 685 686 689 public List findUserGroups(final SecuritySession securitySession, 690 final boolean includeAdministrator) 691 throws SystemException { 692 List userGroups = new ArrayList (); 693 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 694 try { 695 GroupDO userGroupParent = (GroupDO) 696 persistenceManager.findByPrimaryKey( 697 persistenceSession, 698 GroupDO.class, 699 GroupConstants.USER_GROUP); 700 List children = persistenceManager.find(persistenceSession, 701 "addressBookGroupsInGroup", new Object []{userGroupParent.getId()}); 702 userGroups.addAll(children); 703 704 if (!includeAdministrator) { 706 Iterator iterator = userGroups.iterator(); 707 while(iterator.hasNext()) { 708 GroupDO userGroup = (GroupDO) iterator.next(); 709 if (GroupConstants.equals(userGroup.getId(), 710 GroupConstants.GROUP_ADMINISTRATOR)) { 711 userGroups.remove(userGroup); 712 break; 713 } 714 } 715 } 716 userGroups.add(userGroupParent); 718 return Collections.synchronizedList(userGroups); 719 } catch (Exception e) { 720 persistenceSession.cancel(); 721 throw new SystemException(e); 722 } finally { 723 persistenceSession.close(); 724 } 725 } 726 727 735 public void onRemove(final PersistenceSession persistenceSession, 736 final ValueObject valueObject) throws PersistenceException { 737 if (!(valueObject instanceof GroupDO)) { 739 return; 740 } 741 GroupDO groupDO = (GroupDO) valueObject; 742 743 GroupDO parent = groupDO.getParent(); 745 746 List children = persistenceManager.find(persistenceSession, 747 "addressBookGroupsInGroup", new Object []{groupDO.getId()}); 748 749 if (GroupConstants.equals(groupDO.getParent().getId(), 751 GroupConstants.ADDRESS_BOOK_PRIVATE) 752 || GroupConstants.equals(groupDO.getParent().getId(), 753 GroupConstants.ADDRESS_BOOK_PRIVATE)) { 754 assert (children.size() > 0); 755 assert (groupDO.getPeople().size() == 0); 756 } 757 Iterator childIterator = children.iterator(); 759 while (childIterator.hasNext()) { 760 GroupDO child = (GroupDO) childIterator.next(); 761 child.setParent(parent); 762 persistenceManager.amend(persistenceSession, child); 763 } 764 Iterator personIterator = groupDO.getPeople().iterator(); 765 while (personIterator.hasNext()) { 766 PersonDO person = (PersonDO) personIterator.next(); 767 person.setGroup(parent); 768 persistenceManager.amend(persistenceSession, person); 769 } 770 } 771 772 775 public void removeGroup(final SecuritySession securitySession, 776 final Integer id) 777 throws SystemException { 778 assert (id != null); 780 PersistenceSession persistenceSession = persistenceManager.openSession(securitySession); 781 try { 782 persistenceManager.remove(persistenceSession, GroupDO.class, id); 783 } catch (Exception e) { 784 persistenceSession.cancel(); 785 throw new SystemException(e); 786 } finally { 787 persistenceSession.close(); 788 } 789 } 790 791 794 public void removePerson(final SecuritySession securitySession, 795 final Integer id) 796 throws SystemException { 797 if (id == null) { 799 throw new EJBException ("ERROR in AddressBookBean: cannot remove a person with a null id"); 800 } 801 PersistenceSession persistenceSession = 802 persistenceManager.openSession(securitySession); 803 PersonDO person; 804 try { 805 person = (PersonDO)persistenceManager.findByPrimaryKey( 806 persistenceSession, PersonDO.class, id); 807 } finally { 808 persistenceSession.close(); 809 } 810 persistenceSession = persistenceManager.openSession(securitySession); 811 try { 812 if (person.getUser() == null) { 814 persistenceManager.remove(persistenceSession, person); 815 } else { 816 person.setDeleted(true); 817 person.getUser().setDeleted(true); 818 persistenceManager.amend(persistenceSession, person); 819 } 820 } catch (Exception e) { 821 persistenceSession.cancel(); 822 throw new SystemException(e); 823 } finally { 824 persistenceSession.close(); 825 } 826 } 827 828 835 public ValidationErrors validate(final SecuritySession securitySession, 836 final AddressDO addressDO) { 837 ValidationErrors errors = new ValidationErrors(); 838 Mask mask = maskFactory.getMask(AddressDO.class); 839 840 if ((addressDO.getCountry() == null) 841 || StringHandling.isNullOrEmpty(addressDO.getCountry().getCode())) { 842 errors.add(new ValidationError( 843 "person.address", 844 AddressBook.BUNDLE_PATH, 845 mask.getField("country"), 846 "errors.required")); 847 } 848 if (StringHandling.isNullOrEmpty(addressDO.getStreetAddress())) { 849 errors.add(new ValidationError( 850 "person.address", 851 AddressBook.BUNDLE_PATH, 852 mask.getField("streetAddress"), 853 "errors.required")); 854 } 855 if (StringHandling.isNullOrEmpty(addressDO.getTown())) { 856 errors.add(new ValidationError( 857 "person.address", 858 AddressBook.BUNDLE_PATH, 859 mask.getField("town"), 860 "errors.required")); 861 } 862 return errors; 863 } 864 865 868 public ValidationErrors validate(final SecuritySession securitySession, 869 final GroupDO groupDO) { 870 ValidationErrors errors = new ValidationErrors(); 871 Mask mask = maskFactory.getMask(GroupDO.class); 872 873 if (StringHandling.isNullOrEmpty(groupDO.getName())) { 875 errors.add(new ValidationError( 876 "group", 877 AddressBook.BUNDLE_PATH, 878 mask.getField("name"), 879 "errors.required")); 880 } 881 return errors; 882 } 883 884 891 public ValidationErrors validate(final SecuritySession securitySession, 892 final PersonDO personDO) { 893 ValidationErrors errors = new ValidationErrors(); 894 Mask mask = maskFactory.getMask(PersonDO.class); 895 Mask userMask = maskFactory.getMask(UserDO.class); 896 897 if (StringHandling.isNullOrEmpty(personDO.getFileAs())) { 898 errors.add(new ValidationError( 899 "personDetails", 900 AddressBook.BUNDLE_PATH, 901 mask.getField("fileAs"), 902 "errors.required")); 903 } 904 if (StringHandling.isNullOrEmpty(personDO.getFirstNames())) { 905 errors.add(new ValidationError( 906 "personDetails", 907 AddressBook.BUNDLE_PATH, 908 mask.getField("firstNames"), 909 "errors.required")); 910 } 911 if (StringHandling.isNullOrEmpty(personDO.getLastName())) { 912 errors.add(new ValidationError( 913 "personDetails", 914 AddressBook.BUNDLE_PATH, 915 mask.getField("lastName"), 916 "errors.required")); 917 918 } 920 if (personDO.getGroup() == null) { 921 errors.add(new ValidationError( 922 "personDetails", 923 AddressBook.BUNDLE_PATH, 924 mask.getField("addressBookName"), 925 "errors.required")); 926 } 927 if (UserConstants.ADMINISTRATOR.equals(personDO.getId())) { 930 if ((personDO.getUser() == null) 931 || !personDO.getUser().isEnabled() 932 || personDO.getUser().isDeleted()) { 933 errors.add(new ValidationError( 934 "user", 935 Security.BUNDLE_PATH, 936 userMask.getField("name"), 937 "errors.addressBook.user.administrator")); 938 939 } 940 } 941 942 943 if (personDO.getUser() != null) { 944 if (personDO.getUser().getName() == null) { 945 errors.add(new ValidationError( 946 "user", 947 Security.BUNDLE_PATH, 948 userMask.getField("name"), 949 "errors.required")); 950 } 951 952 boolean foundEmail = false; 955 956 for (Iterator i = personDO.getTelecomAddresses().iterator(); i.hasNext();) { 957 int type = ((TelecomAddressDO) i.next()).getType(); 958 if (type == TelecomAddressConstants.TYPE_EMAIL) { 959 foundEmail = true; 960 break; 961 } 962 } 963 if (!foundEmail) { 964 errors.add(new ValidationError( 965 "personDetails", 966 AddressBook.BUNDLE_PATH, 967 mask.getField("emailAddress"), 968 "errors.required")); 969 } 970 } 971 if (personDO.getAddress() != null) { 973 ValidationErrors addressErrors = validate(securitySession, 974 personDO.getAddress()); 975 if (addressErrors != null) { 976 errors.addAll(addressErrors); 977 } 978 } 979 980 return errors; 981 } 982 } 983 | Popular Tags |