2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Collections;
21 import java.util.Date;
22 import java.util.Iterator;
23 import java.util.LinkedList;
24 import java.util.List;
25 import java.util.Objects;
26 import javax.annotation.PostConstruct;
27 import javax.enterprise.context.SessionScoped;
28 import javax.enterprise.event.Observes;
29 import javax.faces.view.facelets.FaceletException;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import javax.naming.Context;
33 import javax.naming.InitialContext;
34 import javax.naming.NamingException;
35 import org.mxchange.jcontacts.contact.Contact;
36 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
37 import org.mxchange.jcontacts.contact.UserContact;
38 import org.mxchange.jcontacts.contact.gender.Gender;
39 import org.mxchange.jcontacts.contact.utils.ContactUtils;
40 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent;
42 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
43 import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
44 import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
45 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
46 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
47 import org.mxchange.jcountry.data.Country;
48 import org.mxchange.jjobs.beans.BaseJobsController;
49 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
50 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
51 import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent;
52 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
53 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
54 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
55 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
56 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
57 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
58 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
59 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
60 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
61 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
62 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
63 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
64 import org.mxchange.jusercore.model.user.User;
67 * A general contact controller (bean)
69 * @author Roland Haeder<roland@mxchange.org>
71 @Named ("contactController")
73 public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController {
78 private static final long serialVersionUID = 542_145_347_916L;
83 private Date birthday;
93 private String comment;
98 private final ContactSessionBeanRemote contactBean;
103 private final List<Contact> contacts;
108 private Country country;
113 private String emailAddress;
116 * Email address repeated
118 private String emailAddressRepeat;
123 private final List<String> emailAddresses;
128 private String familyName;
131 * Fax number's area code
133 private Integer faxAreaCode;
136 * Country instance for fax number
138 private Country faxCountry;
143 private Long faxNumber;
148 private String firstName;
153 private Gender gender;
158 private Short houseNumber;
161 * House number extension
163 private String houseNumberExtension;
166 * Whether a fax entry has been unlinked
168 private boolean isFaxUnlinked;
171 * Whether a land-line number has been unlinked
173 private boolean isLandLineUnlinked;
176 * Whether a mobile entry has been unlinked
178 private boolean isMobileUnlinked;
181 * Land-line number area code
183 private Integer landLineAreaCode;
186 * Country instance for land-line number
188 private Country landLineCountry;
193 private Long landLineNumber;
198 private Long mobileNumber;
203 private MobileProvider mobileProvider;
206 * A list of all selectable contacts
208 private List<Contact> selectableContacts;
213 private String street;
218 private String title;
221 * Regular user controller
224 private JobsUserWebSessionController userController;
227 * Login controller (bean)
230 private JobsUserLoginWebSessionController userLoginController;
235 private Integer zipCode;
238 * Default constructor
240 public JobsContactWebSessionBean () {
243 // Get initial context
244 Context context = new InitialContext();
247 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
248 } catch (final NamingException e) {
250 throw new FaceletException(e);
254 this.contacts = new LinkedList<>();
255 this.emailAddresses = new LinkedList<>();
259 public void afterAdminAddedContactEvent (@Observes final AdminAddedContactEvent event) {
260 // The event must be valid
263 throw new NullPointerException("event is null"); //NOI18N
264 } else if (event.getAddedContact() == null) {
266 throw new NullPointerException("event.addedContact is null"); //NOI18N
267 } else if (event.getAddedContact().getContactId() == null) {
269 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
270 } else if (event.getAddedContact().getContactId() < 1) {
272 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
279 this.uniqueAddContact(event.getAddedContact());
281 // Add to selectable contacts
282 this.selectableContacts.add(event.getAddedContact());
286 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
287 // event should not be null
290 throw new NullPointerException("event is null"); //NOI18N
291 } else if (event.getAddedUser() == null) {
293 throw new NullPointerException("event.addedUser is null"); //NOI18N
294 } else if (event.getAddedUser().getUserId() == null) {
296 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
297 } else if (event.getAddedUser().getUserId() < 1) {
299 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
307 public void afterAdminDeletedContactEvent (@Observes final AdminDeletedContactEvent event) {
308 // event should not be null
311 throw new NullPointerException("event is null"); //NOI18N
312 } else if (event.getDeletedContact() == null) {
314 throw new NullPointerException("event.deletedContact is null"); //NOI18N
315 } else if (event.getDeletedContact().getContactId() == null) {
317 throw new NullPointerException("event.deletedContact.contactId is null"); //NOI18N
318 } else if (event.getDeletedContact().getContactId() < 1) {
320 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedContact(), event.getDeletedContact().getContactId())); //NOI18N
323 // Remove from both lists
324 this.contacts.remove(event.getDeletedContact());
325 this.selectableContacts.remove(event.getDeletedContact());
332 public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) {
333 // event should not be null
336 throw new NullPointerException("event is null"); //NOI18N
337 } else if (event.getLinkedUser() == null) {
339 throw new NullPointerException("event.linkedUser is null"); //NOI18N
340 } else if (event.getLinkedUser().getUserContact() == null) {
342 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
343 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
345 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
346 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
348 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
351 // Remove contact from list available contacts list
352 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
359 public void afterAdminUnlinkedFaxContactDataEvent (@Observes final AdminUnlinkedFaxNumberEvent event) {
360 // event should not be null
363 throw new NullPointerException("event is null"); //NOI18N
364 } else if (event.getUnlinkedFaxNumber() == null) {
366 throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N
367 } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) {
369 throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N
370 } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) {
372 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N
375 // Remove it from list
376 this.removeFromContacts(event.getUnlinkedFaxNumber());
383 public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final AdminUnlinkedLandLineNumberEvent event) {
384 // event should not be null
387 throw new NullPointerException("event is null"); //NOI18N
388 } else if (event.getUnlinkedLandLineNumber() == null) {
390 throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N
391 } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) {
393 throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N
394 } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) {
396 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N
399 // Remove it from list
400 this.removeFromContacts(event.getUnlinkedLandLineNumber());
407 public void afterAdminUnlinkedMobileContactDataEvent (@Observes final AdminUnlinkedMobileNumberEvent event) {
408 // event should not be null
411 throw new NullPointerException("event is null"); //NOI18N
412 } else if (event.getUnlinkedMobileNumber() == null) {
414 throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N
415 } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) {
417 throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N
418 } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) {
420 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N
423 // Remove it from list
424 this.removeFromContacts(event.getUnlinkedMobileNumber());
431 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
432 // event should not be null
435 throw new NullPointerException("event is null"); //NOI18N
436 } else if (event.getUpdatedContact() == null) {
438 throw new NullPointerException("event.updatedContact is null"); //NOI18N
439 } else if (event.getUpdatedContact().getContactId() == null) {
441 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
442 } else if (event.getUpdatedContact().getContactId() < 1) {
444 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
447 // Add contact instance only once
448 this.uniqueAddContact(event.getUpdatedContact());
450 // Add email address to list
451 this.emailAddresses.add(event.getUpdatedContact().getContactEmailAddress());
455 public void afterUserRegistrationEvent (@Observes final UserRegisteredEvent event) {
456 // event should not be null
459 throw new NullPointerException("event is null"); //NOI18N
460 } else if (event.getRegisteredUser() == null) {
462 throw new NullPointerException("event.registeredUser is null"); //NOI18N
463 } else if (event.getRegisteredUser().getUserId() == null) {
465 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
466 } else if (event.getRegisteredUser().getUserId() < 1) {
468 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
472 Contact registeredContact = event.getRegisteredUser().getUserContact();
474 // Copy all data from registered->user
475 this.copyContact(registeredContact);
477 // Add contact instance only once
478 this.uniqueAddContact(registeredContact);
480 // Add user name and email address
481 this.addUserNameEmailAddress(registeredContact);
488 public void afterUserConfirmedAccountEventEvent (@Observes final UserConfirmedAccountEvent event) {
489 // event should not be null
492 throw new NullPointerException("event is null"); //NOI18N
493 } else if (event.getConfirmedUser() == null) {
495 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
496 } else if (event.getConfirmedUser().getUserId() == null) {
498 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
499 } else if (event.getConfirmedUser().getUserId() < 1) {
501 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
504 // Add contact instance only once
505 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
509 public void afterUserLoginEvent (@Observes final UserLoggedInEvent event) {
510 // event should not be null
513 throw new NullPointerException("event is null"); //NOI18N
514 } else if (event.getLoggedInUser() == null) {
516 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
517 } else if (event.getLoggedInUser().getUserId() == null) {
519 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
520 } else if (event.getLoggedInUser().getUserId() < 1) {
522 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
525 // Copy all data to this bean
526 this.copyContact(event.getLoggedInUser().getUserContact());
530 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
531 public List<Contact> allContacts () {
533 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
535 // Return un-modified list
536 return this.contacts;
540 public Contact createContactInstance () {
542 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
544 // Is all required data set?
545 if (!this.isRequiredPersonalDataSet()) {
546 // No, then abort here
547 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
550 // Generate phone number
551 DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
552 DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
553 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
555 // Create new contact
556 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
557 contact.setContactStreet(this.getStreet());
558 contact.setContactHouseNumber(this.getHouseNumber());
559 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
560 contact.setContactZipCode(this.getZipCode());
561 contact.setContactCity(this.getCity());
562 contact.setContactCountry(this.getCountry());
563 contact.setContactEmailAddress(this.getEmailAddress());
564 contact.setContactBirthday(this.getBirthday());
565 contact.setContactComment(this.getComment());
568 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
569 // Don't set null or wrong references
570 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
571 // Now the number must be given
572 if (phone.getPhoneAreaCode() == null) {
574 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
575 } else if (phone.getPhoneAreaCode() < 1) {
577 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
578 } else if (phone.getPhoneNumber() == null) {
580 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
581 } else if (phone.getPhoneNumber() < 1) {
583 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
587 contact.setContactLandLineNumber(phone);
590 // Don't set null or wrong references
591 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
592 // Now the number must be given
593 if (fax.getPhoneAreaCode() == null) {
595 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
596 } else if (fax.getPhoneAreaCode() < 1) {
598 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
599 } else if (fax.getPhoneNumber() == null) {
601 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
602 } else if (fax.getPhoneNumber() < 1) {
604 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
608 contact.setContactFaxNumber(fax);
611 // Is the provider set?
612 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
613 // Is the number set?
614 if (mobile.getPhoneNumber() == null) {
616 throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
617 } else if (mobile.getPhoneNumber() < 1) {
619 throw new IllegalArgumentException("mobileNumber.phoneNumber is zero or below."); //NOI18N
623 contact.setContactMobileNumber(mobile);
627 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
633 public String doChangePersonalContactData () {
634 // This method shall only be called if the user is logged-in
635 if (!this.userLoginController.isUserLoggedIn()) {
637 throw new IllegalStateException("User is not logged-in"); //NOI18N
638 } else if (!this.isRequiredChangePersonalDataSet()) {
639 // Not all required fields are set
640 throw new FaceletException("Not all required fields are set."); //NOI18N
641 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
642 // Password not matching
643 this.showFacesMessage("form_login_change_personal:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N
647 // Get contact instance
648 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
650 // It should be there, so run some tests on it
651 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
652 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
653 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
656 contact.setContactGender(this.getGender());
657 contact.setContactFirstName(this.getFirstName());
658 contact.setContactFamilyName(this.getFamilyName());
659 contact.setContactStreet(this.getStreet());
660 contact.setContactHouseNumber(this.getHouseNumber());
661 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
662 contact.setContactZipCode(this.getZipCode());
663 contact.setContactCity(this.getCity());
664 contact.setContactCountry(this.getCountry());
666 // Update contact's mobile number
667 this.isMobileUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getMobileProvider(), this.getMobileNumber());
669 // Update contact's land-line number
670 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
672 // Update contact's fax number
673 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
675 // Send it to the EJB
676 this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
679 return "contact_data_saved"; //NOI18N
683 @SuppressWarnings ("ReturnOfDateField")
684 public Date getBirthday () {
685 return this.birthday;
689 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
690 public void setBirthday (final Date birthday) {
691 this.birthday = birthday;
695 public String getCity () {
700 public void setCity (final String city) {
705 public String getComment () {
710 public void setComment (final String comment) {
711 this.comment = comment;
715 public String getControllerType () {
716 return "general"; //NOI18N
721 public void setControllerType (final String controllerType) {
722 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
726 public Country getCountry () {
731 public void setCountry (final Country country) {
732 this.country = country;
736 public String getEmailAddress () {
737 return this.emailAddress;
741 public void setEmailAddress (final String emailAddress) {
742 this.emailAddress = emailAddress;
746 public String getEmailAddressRepeat () {
747 return this.emailAddressRepeat;
751 public void setEmailAddressRepeat (final String emailAddressRepeat) {
752 this.emailAddressRepeat = emailAddressRepeat;
756 public String getFamilyName () {
757 return this.familyName;
761 public void setFamilyName (final String familyName) {
762 this.familyName = familyName;
766 public Integer getFaxAreaCode () {
767 return this.faxAreaCode;
771 public void setFaxAreaCode (final Integer faxAreaCode) {
772 this.faxAreaCode = faxAreaCode;
776 public Country getFaxCountry () {
777 return this.faxCountry;
781 public void setFaxCountry (final Country faxCountry) {
782 this.faxCountry = faxCountry;
786 public Long getFaxNumber () {
787 return this.faxNumber;
791 public void setFaxNumber (final Long faxNumber) {
792 this.faxNumber = faxNumber;
796 public String getFirstName () {
797 return this.firstName;
801 public void setFirstName (final String firstName) {
802 this.firstName = firstName;
806 public Gender getGender () {
811 public void setGender (final Gender gender) {
812 this.gender = gender;
816 public Short getHouseNumber () {
817 return this.houseNumber;
821 public void setHouseNumber (final Short houseNumber) {
822 this.houseNumber = houseNumber;
826 public String getHouseNumberExtension () {
827 return this.houseNumberExtension;
831 public void setHouseNumberExtension (final String houseNumberExtension) {
832 this.houseNumberExtension = houseNumberExtension;
836 public Integer getLandLineAreaCode () {
837 return this.landLineAreaCode;
841 public void setLandLineAreaCode (final Integer landLineAreaCode) {
842 this.landLineAreaCode = landLineAreaCode;
846 public Country getLandLineCountry () {
847 return this.landLineCountry;
851 public void setLandLineCountry (final Country landLineCountry) {
852 this.landLineCountry = landLineCountry;
856 public Long getLandLineNumber () {
857 return this.landLineNumber;
861 public void setLandLineNumber (final Long landLineNumber) {
862 this.landLineNumber = landLineNumber;
866 public Long getMobileNumber () {
867 return this.mobileNumber;
871 public void setMobileNumber (Long mobileNumber) {
872 this.mobileNumber = mobileNumber;
876 public MobileProvider getMobileProvider () {
877 return this.mobileProvider;
881 public void setMobileProvider (final MobileProvider mobileProvider) {
882 this.mobileProvider = mobileProvider;
886 public String getStreet () {
891 public void setStreet (final String street) {
892 this.street = street;
896 public String getTitle () {
901 public void setTitle (final String title) {
906 public Integer getZipCode () {
911 public void setZipCode (final Integer zipCode) {
912 this.zipCode = zipCode;
916 * Post-initialization of this class
919 public void init () {
920 // Get full email address list for reducing EJB calls
921 this.emailAddresses.addAll(this.contactBean.getEmailAddressList());
923 // Get full contact list
924 this.contacts.addAll(this.contactBean.getAllContacts());
927 List<User> allUsers = this.userController.allUsers();
930 List<Contact> allContacts = this.contactBean.getAllContacts();
933 Iterator<Contact> iterator = allContacts.iterator();
936 while (iterator.hasNext()) {
938 Contact next = iterator.next();
941 Iterator<User> userIterator = allUsers.iterator();
943 // Loop through all users
944 while (userIterator.hasNext()) {
946 User nextUser = userIterator.next();
949 if (Objects.equals(next, nextUser.getUserContact())) {
958 this.selectableContacts = allContacts;
962 public boolean isEmailAddressRegistered (final Contact contact) {
964 if (null == contact) {
966 throw new NullPointerException("contact is null"); //NOI18N
967 } else if (contact.getContactEmailAddress() == null) {
969 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
970 } else if (contact.getContactEmailAddress().isEmpty()) {
972 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
976 return ((this.emailAddresses instanceof List) && (this.emailAddresses.contains(contact.getContactEmailAddress())));
980 public boolean isRequiredChangePersonalDataSet () {
981 return ((this.getGender() != null) &&
982 (this.getFirstName() != null) &&
983 (this.getFamilyName() != null) &&
984 (this.getStreet() != null) &&
985 (this.getHouseNumber() != null) &&
986 (this.getZipCode() != null) &&
987 (this.getCity() != null));
991 public boolean isRequiredPersonalDataSet () {
992 return ((this.getGender() != null) &&
993 (this.getFirstName() != null) &&
994 (this.getFamilyName() != null) &&
995 (this.getStreet() != null) &&
996 (this.getHouseNumber() != null) &&
997 (this.getZipCode() != null) &&
998 (this.getCity() != null) &&
999 (this.getEmailAddress() != null) &&
1000 (this.getEmailAddressRepeat() != null));
1004 public boolean isSameEmailAddressEntered () {
1005 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
1009 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
1011 Contact localContact = null;
1016 // Try to lookup it in visible user list
1017 for (final Iterator<Contact> iterator = this.contacts.iterator(); iterator.hasNext();) {
1019 Contact next = iterator.next();
1021 // Is the user id found?
1022 if (Objects.equals(next.getContactId(), contactId)) {
1023 // Copy to other variable
1024 localContact = next;
1029 // Is it still null?
1030 if (null == localContact) {
1031 // Not visible for the current user
1032 throw new ContactNotFoundException(contactId);
1035 // Copy all data to this bean
1036 this.copyContact(localContact);
1039 return localContact;
1043 public void removeMobileNumberFromListEvent (@Observes final AdminRemoveMobileNumberFromListEvent event) {
1044 // event should not be null
1045 if (null == event) {
1047 throw new NullPointerException("event is null"); //NOI18N
1048 } else if (event.getMobileNumberList() == null) {
1050 throw new NullPointerException("event.mobileList is null"); //NOI18N
1051 } else if (event.getMobileNumberList().isEmpty()) {
1052 // List is empty, no need to check
1056 // Check all entries
1057 for (final Contact contact : this.contacts) {
1058 // Is the mobile instance set and in list?
1059 if ((contact.getContactMobileNumber() instanceof DialableMobileNumber) && (event.getMobileNumberList().contains(contact.getContactMobileNumber()))) {
1060 // Found it, so remvoe it from list
1061 event.getMobileNumberList().remove(contact.getContactMobileNumber());
1067 public List<Contact> selectableContacts () {
1068 return Collections.unmodifiableList(this.selectableContacts);
1072 public void updateContactDataFromController (final Contact contact) {
1073 // Is the instance valid?
1074 if (null == contact) {
1076 throw new NullPointerException("contact is null"); //NOI18N
1077 } else if (contact.getContactId() == null) {
1079 throw new NullPointerException("contact.contactId is null"); //NOI18N
1080 } else if (contact.getContactId() < 1) {
1081 // Not valid id number
1082 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1086 this.copyContact(contact);
1090 * Adds email address to bean's internal list.
1092 * @param contact Contact instance
1094 private void addUserNameEmailAddress (final Contact contact) {
1095 // Make sure the entry is not added yet
1096 if (this.emailAddresses.contains(contact.getContactEmailAddress())) {
1098 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1102 this.emailAddresses.add(contact.getContactEmailAddress());
1108 private void clear () {
1111 this.setGender(null);
1112 this.setTitle(null);
1113 this.setFirstName(null);
1114 this.setFamilyName(null);
1115 this.setStreet(null);
1116 this.setHouseNumber(null);
1117 this.setHouseNumberExtension(null);
1118 this.setZipCode(null);
1120 this.setCountry(null);
1123 this.setEmailAddress(null);
1124 this.setEmailAddressRepeat(null);
1125 this.setLandLineAreaCode(null);
1126 this.setLandLineCountry(null);
1127 this.setLandLineNumber(null);
1128 this.setMobileProvider(null);
1129 this.setMobileNumber(null);
1130 this.setFaxAreaCode(null);
1131 this.setFaxCountry(null);
1132 this.setFaxNumber(null);
1135 this.setBirthday(null);
1136 this.setComment(null);
1140 * Copies given contact into the controller
1142 * @param contact Contact instance
1144 private void copyContact (final Contact contact) {
1145 // Is the instance valid?
1146 if (null == contact) {
1148 throw new NullPointerException("contact is null"); //NOI18N
1149 } else if (contact.getContactId() == null) {
1151 throw new NullPointerException("contact.contactId is null"); //NOI18N
1152 } else if (contact.getContactId() < 1) {
1153 // Not valid id number
1154 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1159 this.setGender(contact.getContactGender());
1160 this.setTitle(contact.getContactTitle());
1161 this.setFirstName(contact.getContactFirstName());
1162 this.setFamilyName(contact.getContactFamilyName());
1163 this.setStreet(contact.getContactStreet());
1164 this.setHouseNumber(contact.getContactHouseNumber());
1165 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1166 this.setZipCode(contact.getContactZipCode());
1167 this.setCity(contact.getContactCity());
1168 this.setCountry(contact.getContactCountry());
1169 this.setEmailAddress(contact.getContactEmailAddress());
1170 this.setBirthday(contact.getContactBirthday());
1171 this.setComment(contact.getContactComment());
1173 // Get mobile, phone and fax instance
1174 DialableMobileNumber mobile = contact.getContactMobileNumber();
1175 DialableFaxNumber fax = contact.getContactFaxNumber();
1176 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1179 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1180 this.setLandLineCountry(phone.getPhoneCountry());
1181 this.setLandLineAreaCode(phone.getPhoneAreaCode());
1182 this.setLandLineNumber(phone.getPhoneNumber());
1185 if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
1186 this.setMobileProvider(mobile.getMobileProvider());
1187 this.setMobileNumber(mobile.getPhoneNumber());
1190 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1191 this.setFaxCountry(fax.getPhoneCountry());
1192 this.setFaxAreaCode(fax.getPhoneAreaCode());
1193 this.setFaxNumber(fax.getPhoneNumber());
1198 * Removes given contact from all lists
1200 * @param contact Contact instance to remove
1202 private void removeContact (final Contact contact) {
1203 // Is the instance valid?
1204 if (null == contact) {
1206 throw new NullPointerException("contact is null"); //NOI18N
1207 } else if (contact.getContactId() == null) {
1209 throw new NullPointerException("contact.contactId is null"); //NOI18N
1210 } else if (contact.getContactId() < 1) {
1211 // Not valid id number
1212 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1215 // Remove from general list
1216 if (!this.contacts.remove(contact)) {
1217 // Did not remove contact
1218 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1221 // Remove from other lists
1222 this.emailAddresses.remove(contact.getContactEmailAddress());
1226 * Removes given fax number from all contacts
1228 * @param faxNumber Fax number to remove
1230 private void removeFromContacts (final DialableFaxNumber faxNumber) {
1232 if (null == faxNumber) {
1234 throw new NullPointerException("faxNumber is null"); //NOI18N
1235 } else if (faxNumber.getPhoneId() == null) {
1237 throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
1238 } else if (faxNumber.getPhoneId() < 1) {
1240 throw new NullPointerException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N
1243 // Loop through all contacts
1244 for (final Contact contact : this.contacts) {
1245 // Is the number set?
1246 if (Objects.equals(contact.getContactFaxNumber(), faxNumber)) {
1248 contact.setContactFaxNumber(null);
1254 * Removes given land-line number from all contacts
1256 * @param landLineNumber Land-line number to remove
1258 private void removeFromContacts (final DialableLandLineNumber landLineNumber) {
1260 if (null == landLineNumber) {
1262 throw new NullPointerException("landLineNumber is null"); //NOI18N
1263 } else if (landLineNumber.getPhoneId() == null) {
1265 throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
1266 } else if (landLineNumber.getPhoneId() < 1) {
1268 throw new NullPointerException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N
1271 // Loop through all contacts
1272 for (final Contact contact : this.contacts) {
1273 // Is the number set?
1274 if (Objects.equals(contact.getContactLandLineNumber(), landLineNumber)) {
1276 contact.setContactLandLineNumber(null);
1282 * Removes given mobile number from all contacts
1284 * @param mobileNumber Mobile number to remove
1286 private void removeFromContacts (final DialableMobileNumber mobileNumber) {
1288 System.out.println(MessageFormat.format("{0}.removeFromContacts: CALLED!", this.getClass().getSimpleName())); //NOI18N
1291 if (null == mobileNumber) {
1293 throw new NullPointerException("mobileNumber is null"); //NOI18N
1294 } else if (mobileNumber.getPhoneId() == null) {
1296 throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
1297 } else if (mobileNumber.getPhoneId() < 1) {
1299 throw new NullPointerException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N
1302 // Loop through all contacts
1303 for (final Contact contact : this.contacts) {
1305 System.out.println(MessageFormat.format("{0}.removeFromContacts: contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N
1307 // Is the number set?
1308 if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) {
1310 System.out.println(MessageFormat.format("{0}.removeFromContacts: Unsetting ...", this.getClass().getSimpleName())); //NOI18N
1313 contact.setContactMobileNumber(null);
1319 * Adds unique instance to contact list. First any existing instance is
1320 * being removed, then the new instance is added.
1322 * @param contact Contact instance to add uniquely
1324 private void uniqueAddContact (final Contact contact) {
1325 // Is the instance valid?
1326 if (null == contact) {
1328 throw new NullPointerException("contact is null"); //NOI18N
1329 } else if (contact.getContactId() == null) {
1331 throw new NullPointerException("contact.contactId is null"); //NOI18N
1332 } else if (contact.getContactId() < 1) {
1333 // Not valid id number
1334 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1337 // Get iterator from list
1338 Iterator<Contact> iterator = this.contacts.iterator();
1340 // "Walk" through all entries
1341 while (iterator.hasNext()) {
1343 Contact next = iterator.next();
1345 // Is id number the same?
1346 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1347 // Found entry, so remove it and abort
1348 this.removeContact(next);
1353 // Add contact to list
1354 this.contacts.add(contact);