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.exceptions.ContactNotFoundException;
44 import org.mxchange.jcountry.data.Country;
45 import org.mxchange.jjobs.beans.BaseJobsController;
46 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
47 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
48 import org.mxchange.jphone.events.cellphone.remove.AdminRemoveCellphoneNumberFromListEvent;
49 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
50 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
51 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
52 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
53 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
54 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
55 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
56 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
57 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
58 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
59 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
60 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
61 import org.mxchange.jusercore.model.user.User;
64 * A general contact controller (bean)
66 * @author Roland Haeder<roland@mxchange.org>
68 @Named ("contactController")
70 public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController {
75 private static final long serialVersionUID = 542_145_347_916L;
80 private Date birthday;
83 * Cellphone number's carrier
85 private MobileProvider cellphoneCarrier;
90 private Long cellphoneNumber;
100 private String comment;
103 * Remote contact bean
105 private final ContactSessionBeanRemote contactBean;
110 private final List<Contact> contactList;
115 private Country country;
120 private String emailAddress;
125 private final List<String> emailAddressList;
128 * Email address repeated
130 private String emailAddressRepeat;
135 private String familyName;
138 * Fax number's area code
140 private Integer faxAreaCode;
143 * Country instance for fax number
145 private Country faxCountry;
150 private Long faxNumber;
155 private String firstName;
160 private Gender gender;
165 private Short houseNumber;
168 * House number extension
170 private String houseNumberExtension;
173 * Whether a cellphone entry has been unlinked
175 private boolean isCellphoneUnlinked;
178 * Whether a fax entry has been unlinked
180 private boolean isFaxUnlinked;
183 * Whether a land-line number has been unlinked
185 private boolean isLandLineUnlinked;
188 * Phone number area code
190 private Integer phoneAreaCode;
193 * Country instance for phone number
195 private Country phoneCountry;
200 private Long phoneNumber;
203 * A list of all selectable contacts
205 private List<Contact> selectableContacts;
210 private String street;
215 private String title;
218 * Regular user controller
221 private JobsUserWebSessionController userController;
224 * Login controller (bean)
227 private JobsUserLoginWebSessionController userLoginController;
232 private Integer zipCode;
235 * Default constructor
237 public JobsContactWebSessionBean () {
240 // Get initial context
241 Context context = new InitialContext();
244 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
245 } catch (final NamingException e) {
247 throw new FaceletException(e);
251 this.contactList = new LinkedList<>();
252 this.emailAddressList = new LinkedList<>();
256 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
257 // The event must be valid
260 throw new NullPointerException("event is null"); //NOI18N
261 } else if (event.getAddedContact() == null) {
263 throw new NullPointerException("event.addedContact is null"); //NOI18N
264 } else if (event.getAddedContact().getContactId() == null) {
266 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
267 } else if (event.getAddedContact().getContactId() < 1) {
269 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
276 this.uniqueAddContact(event.getAddedContact());
278 // Add to selectable contacts
279 this.selectableContacts.add(event.getAddedContact());
283 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
284 // event should not be null
287 throw new NullPointerException("event is null"); //NOI18N
288 } else if (event.getAddedUser() == null) {
290 throw new NullPointerException("event.addedUser is null"); //NOI18N
291 } else if (event.getAddedUser().getUserId() == null) {
293 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
294 } else if (event.getAddedUser().getUserId() < 1) {
296 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
304 public void afterAdminDeletedContactEvent (@Observes final AdminDeletedContactEvent event) {
305 // event should not be null
308 throw new NullPointerException("event is null"); //NOI18N
309 } else if (event.getDeletedContact() == null) {
311 throw new NullPointerException("event.deletedContact is null"); //NOI18N
312 } else if (event.getDeletedContact().getContactId() == null) {
314 throw new NullPointerException("event.deletedContact.contactId is null"); //NOI18N
315 } else if (event.getDeletedContact().getContactId() < 1) {
317 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedContact(), event.getDeletedContact().getContactId())); //NOI18N
320 // Remove from both lists
321 this.contactList.remove(event.getDeletedContact());
322 this.selectableContacts.remove(event.getDeletedContact());
329 public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) {
330 // event should not be null
333 throw new NullPointerException("event is null"); //NOI18N
334 } else if (event.getLinkedUser() == null) {
336 throw new NullPointerException("event.linkedUser is null"); //NOI18N
337 } else if (event.getLinkedUser().getUserContact() == null) {
339 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
340 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
342 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
343 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
345 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
348 // Remove contact from list available contacts list
349 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
356 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
357 // event should not be null
360 throw new NullPointerException("event is null"); //NOI18N
361 } else if (event.getUpdatedContact() == null) {
363 throw new NullPointerException("event.updatedContact is null"); //NOI18N
364 } else if (event.getUpdatedContact().getContactId() == null) {
366 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
367 } else if (event.getUpdatedContact().getContactId() < 1) {
369 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
372 // Add contact instance only once
373 this.uniqueAddContact(event.getUpdatedContact());
375 // Add email address to list
376 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
380 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
381 // event should not be null
384 throw new NullPointerException("event is null"); //NOI18N
385 } else if (event.getRegisteredUser() == null) {
387 throw new NullPointerException("event.registeredUser is null"); //NOI18N
388 } else if (event.getRegisteredUser().getUserId() == null) {
390 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
391 } else if (event.getRegisteredUser().getUserId() < 1) {
393 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
397 Contact registeredContact = event.getRegisteredUser().getUserContact();
399 // Copy all data from registered->user
400 this.copyContact(registeredContact);
402 // Add contact instance only once
403 this.uniqueAddContact(registeredContact);
405 // Add user name and email address
406 this.addUserNameEmailAddress(registeredContact);
413 public void afterUserConfirmedAccountEvent (@Observes final UserConfirmedAccountEvent event) {
414 // event should not be null
417 throw new NullPointerException("event is null"); //NOI18N
418 } else if (event.getConfirmedUser() == null) {
420 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
421 } else if (event.getConfirmedUser().getUserId() == null) {
423 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
424 } else if (event.getConfirmedUser().getUserId() < 1) {
426 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
429 // Add contact instance only once
430 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
434 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
435 // event should not be null
438 throw new NullPointerException("event is null"); //NOI18N
439 } else if (event.getLoggedInUser() == null) {
441 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
442 } else if (event.getLoggedInUser().getUserId() == null) {
444 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
445 } else if (event.getLoggedInUser().getUserId() < 1) {
447 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
450 // Copy all data to this bean
451 this.copyContact(event.getLoggedInUser().getUserContact());
455 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
456 public List<Contact> allContacts () {
458 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
460 // Return un-modified list
461 return this.contactList;
465 public Contact createContactInstance () {
467 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
469 // Is all required data set?
470 if (!this.isRequiredPersonalDataSet()) {
471 // No, then abort here
472 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
475 // Generate phone number
476 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
477 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
478 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
480 // Create new contact
481 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
482 contact.setContactStreet(this.getStreet());
483 contact.setContactHouseNumber(this.getHouseNumber());
484 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
485 contact.setContactZipCode(this.getZipCode());
486 contact.setContactCity(this.getCity());
487 contact.setContactCountry(this.getCountry());
488 contact.setContactEmailAddress(this.getEmailAddress());
489 contact.setContactBirthday(this.getBirthday());
490 contact.setContactComment(this.getComment());
493 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
494 // Don't set null or wrong references
495 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
496 // Now the number must be given
497 if (phone.getPhoneAreaCode() == null) {
499 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
500 } else if (phone.getPhoneAreaCode() < 1) {
502 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
503 } else if (phone.getPhoneNumber() == null) {
505 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
506 } else if (phone.getPhoneNumber() < 1) {
508 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
512 contact.setContactLandLineNumber(phone);
515 // Don't set null or wrong references
516 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
517 // Now the number must be given
518 if (fax.getPhoneAreaCode() == null) {
520 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
521 } else if (fax.getPhoneAreaCode() < 1) {
523 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
524 } else if (fax.getPhoneNumber() == null) {
526 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
527 } else if (fax.getPhoneNumber() < 1) {
529 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
533 contact.setContactFaxNumber(fax);
536 // Is the provider set?
537 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
538 // Is the number set?
539 if (cellphone.getPhoneNumber() == null) {
541 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
542 } else if (cellphone.getPhoneNumber() < 1) {
544 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
547 // Set cellphone number
548 contact.setContactCellphoneNumber(cellphone);
552 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
558 public String doChangePersonalContactData () {
559 // This method shall only be called if the user is logged-in
560 if (!this.userLoginController.isUserLoggedIn()) {
562 throw new IllegalStateException("User is not logged-in"); //NOI18N
563 } else if (!this.isRequiredChangePersonalDataSet()) {
564 // Not all required fields are set
565 throw new FaceletException("Not all required fields are set."); //NOI18N
566 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
567 // Password not matching
568 this.showFacesMessage("form_login_change_personal:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N
572 // Get contact instance
573 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
575 // It should be there, so run some tests on it
576 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
577 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
578 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
581 contact.setContactGender(this.getGender());
582 contact.setContactFirstName(this.getFirstName());
583 contact.setContactFamilyName(this.getFamilyName());
584 contact.setContactStreet(this.getStreet());
585 contact.setContactHouseNumber(this.getHouseNumber());
586 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
587 contact.setContactZipCode(this.getZipCode());
588 contact.setContactCity(this.getCity());
589 contact.setContactCountry(this.getCountry());
591 // Update contact's cellphone number
592 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
594 // Update contact's land-line number
595 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
597 // Update contact's fax number
598 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
600 // Send it to the EJB
601 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
604 return "contact_data_saved"; //NOI18N
608 @SuppressWarnings ("ReturnOfDateField")
609 public Date getBirthday () {
610 return this.birthday;
614 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
615 public void setBirthday (final Date birthday) {
616 this.birthday = birthday;
620 public MobileProvider getCellphoneCarrier () {
621 return this.cellphoneCarrier;
625 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
626 this.cellphoneCarrier = cellphoneCarrier;
630 public Long getCellphoneNumber () {
631 return this.cellphoneNumber;
635 public void setCellphoneNumber (Long cellphoneNumber) {
636 this.cellphoneNumber = cellphoneNumber;
640 public String getCity () {
645 public void setCity (final String city) {
650 public String getComment () {
655 public void setComment (final String comment) {
656 this.comment = comment;
660 public String getControllerType () {
661 return "general"; //NOI18N
666 public void setControllerType (final String controllerType) {
667 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
671 public Country getCountry () {
676 public void setCountry (final Country country) {
677 this.country = country;
681 public String getEmailAddress () {
682 return this.emailAddress;
686 public void setEmailAddress (final String emailAddress) {
687 this.emailAddress = emailAddress;
691 public String getEmailAddressRepeat () {
692 return this.emailAddressRepeat;
696 public void setEmailAddressRepeat (final String emailAddressRepeat) {
697 this.emailAddressRepeat = emailAddressRepeat;
701 public String getFamilyName () {
702 return this.familyName;
706 public void setFamilyName (final String familyName) {
707 this.familyName = familyName;
711 public Integer getFaxAreaCode () {
712 return this.faxAreaCode;
716 public void setFaxAreaCode (final Integer faxAreaCode) {
717 this.faxAreaCode = faxAreaCode;
721 public Country getFaxCountry () {
722 return this.faxCountry;
726 public void setFaxCountry (final Country faxCountry) {
727 this.faxCountry = faxCountry;
731 public Long getFaxNumber () {
732 return this.faxNumber;
736 public void setFaxNumber (final Long faxNumber) {
737 this.faxNumber = faxNumber;
741 public String getFirstName () {
742 return this.firstName;
746 public void setFirstName (final String firstName) {
747 this.firstName = firstName;
751 public Gender getGender () {
756 public void setGender (final Gender gender) {
757 this.gender = gender;
761 public Short getHouseNumber () {
762 return this.houseNumber;
766 public void setHouseNumber (final Short houseNumber) {
767 this.houseNumber = houseNumber;
771 public String getHouseNumberExtension () {
772 return this.houseNumberExtension;
776 public void setHouseNumberExtension (final String houseNumberExtension) {
777 this.houseNumberExtension = houseNumberExtension;
781 public Integer getPhoneAreaCode () {
782 return this.phoneAreaCode;
786 public void setPhoneAreaCode (final Integer phoneAreaCode) {
787 this.phoneAreaCode = phoneAreaCode;
791 public Country getPhoneCountry () {
792 return this.phoneCountry;
796 public void setPhoneCountry (final Country phoneCountry) {
797 this.phoneCountry = phoneCountry;
801 public Long getPhoneNumber () {
802 return this.phoneNumber;
806 public void setPhoneNumber (final Long phoneNumber) {
807 this.phoneNumber = phoneNumber;
811 public String getStreet () {
816 public void setStreet (final String street) {
817 this.street = street;
821 public String getTitle () {
826 public void setTitle (final String title) {
831 public Integer getZipCode () {
836 public void setZipCode (final Integer zipCode) {
837 this.zipCode = zipCode;
841 * Post-initialization of this class
844 public void init () {
845 // Get full email address list for reducing EJB calls
846 this.emailAddressList.addAll(this.contactBean.getEmailAddressList());
848 // Get full contact list
849 this.contactList.addAll(this.contactBean.getAllContacts());
852 List<User> allUsers = this.userController.allUsers();
855 List<Contact> allContacts = this.contactBean.getAllContacts();
858 Iterator<Contact> iterator = allContacts.iterator();
861 while (iterator.hasNext()) {
863 Contact next = iterator.next();
866 Iterator<User> userIterator = allUsers.iterator();
868 // Loop through all users
869 while (userIterator.hasNext()) {
871 User nextUser = userIterator.next();
874 if (Objects.equals(next, nextUser.getUserContact())) {
883 this.selectableContacts = allContacts;
887 public boolean isEmailAddressRegistered (final Contact contact) {
889 if (null == contact) {
891 throw new NullPointerException("contact is null"); //NOI18N
892 } else if (contact.getContactEmailAddress() == null) {
894 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
895 } else if (contact.getContactEmailAddress().isEmpty()) {
897 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
901 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
905 public boolean isRequiredChangePersonalDataSet () {
906 return ((this.getGender() != null) &&
907 (this.getFirstName() != null) &&
908 (this.getFamilyName() != null) &&
909 (this.getStreet() != null) &&
910 (this.getHouseNumber() != null) &&
911 (this.getZipCode() != null) &&
912 (this.getCity() != null));
916 public boolean isRequiredPersonalDataSet () {
917 return ((this.getGender() != null) &&
918 (this.getFirstName() != null) &&
919 (this.getFamilyName() != null) &&
920 (this.getStreet() != null) &&
921 (this.getHouseNumber() != null) &&
922 (this.getZipCode() != null) &&
923 (this.getCity() != null) &&
924 (this.getEmailAddress() != null) &&
925 (this.getEmailAddressRepeat() != null));
929 public boolean isSameEmailAddressEntered () {
930 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
934 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
936 Contact localContact = null;
941 // Try to lookup it in visible user list
942 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
944 Contact next = iterator.next();
946 // Is the user id found?
947 if (Objects.equals(next.getContactId(), contactId)) {
948 // Copy to other variable
955 if (null == localContact) {
956 // Not visible for the current user
957 throw new ContactNotFoundException(contactId);
960 // Copy all data to this bean
961 this.copyContact(localContact);
968 public void removeCellphoneNumberFromListEvent (@Observes final AdminRemoveCellphoneNumberFromListEvent event) {
969 // event should not be null
972 throw new NullPointerException("event is null"); //NOI18N
973 } else if (event.getCellphoneList()== null) {
975 throw new NullPointerException("event.cellphoneList is null"); //NOI18N
976 } else if (event.getCellphoneList().isEmpty()) {
977 // List is empty, no need to check
982 for (final Contact contact : this.contactList) {
983 // Is the cell phone instance set and in list?
984 if ((contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) && (event.getCellphoneList().contains(contact.getContactCellphoneNumber()))) {
985 // Found it, so remvoe it from list
986 event.getCellphoneList().remove(contact.getContactCellphoneNumber());
992 public List<Contact> selectableContacts () {
993 return Collections.unmodifiableList(this.selectableContacts);
997 public void updateContactDataFromController (final Contact contact) {
998 // Is the instance valid?
999 if (null == contact) {
1001 throw new NullPointerException("contact is null"); //NOI18N
1002 } else if (contact.getContactId() == null) {
1004 throw new NullPointerException("contact.contactId is null"); //NOI18N
1005 } else if (contact.getContactId() < 1) {
1006 // Not valid id number
1007 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1011 this.copyContact(contact);
1015 * Adds email address to bean's internal list.
1017 * @param contact Contact instance
1019 private void addUserNameEmailAddress (final Contact contact) {
1020 // Make sure the entry is not added yet
1021 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
1023 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
1027 this.emailAddressList.add(contact.getContactEmailAddress());
1033 private void clear () {
1036 this.setGender(null);
1037 this.setTitle(null);
1038 this.setFirstName(null);
1039 this.setFamilyName(null);
1040 this.setStreet(null);
1041 this.setHouseNumber(null);
1042 this.setHouseNumberExtension(null);
1043 this.setZipCode(null);
1045 this.setCountry(null);
1048 this.setEmailAddress(null);
1049 this.setEmailAddressRepeat(null);
1050 this.setPhoneAreaCode(null);
1051 this.setPhoneCountry(null);
1052 this.setPhoneNumber(null);
1053 this.setCellphoneCarrier(null);
1054 this.setCellphoneNumber(null);
1055 this.setFaxAreaCode(null);
1056 this.setFaxCountry(null);
1057 this.setFaxNumber(null);
1060 this.setBirthday(null);
1061 this.setComment(null);
1065 * Copies given contact into the controller
1067 * @param contact Contact instance
1069 private void copyContact (final Contact contact) {
1070 // Is the instance valid?
1071 if (null == contact) {
1073 throw new NullPointerException("contact is null"); //NOI18N
1074 } else if (contact.getContactId() == null) {
1076 throw new NullPointerException("contact.contactId is null"); //NOI18N
1077 } else if (contact.getContactId() < 1) {
1078 // Not valid id number
1079 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1084 this.setGender(contact.getContactGender());
1085 this.setTitle(contact.getContactTitle());
1086 this.setFirstName(contact.getContactFirstName());
1087 this.setFamilyName(contact.getContactFamilyName());
1088 this.setStreet(contact.getContactStreet());
1089 this.setHouseNumber(contact.getContactHouseNumber());
1090 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
1091 this.setZipCode(contact.getContactZipCode());
1092 this.setCity(contact.getContactCity());
1093 this.setCountry(contact.getContactCountry());
1094 this.setEmailAddress(contact.getContactEmailAddress());
1095 this.setBirthday(contact.getContactBirthday());
1096 this.setComment(contact.getContactComment());
1098 // Get cellphone, phone and fax instance
1099 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1100 DialableFaxNumber fax = contact.getContactFaxNumber();
1101 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1104 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1105 this.setPhoneCountry(phone.getPhoneCountry());
1106 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1107 this.setPhoneNumber(phone.getPhoneNumber());
1110 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1111 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1112 this.setCellphoneNumber(cellphone.getPhoneNumber());
1115 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1116 this.setFaxCountry(fax.getPhoneCountry());
1117 this.setFaxAreaCode(fax.getPhoneAreaCode());
1118 this.setFaxNumber(fax.getPhoneNumber());
1123 * Removes given contact from all lists
1125 * @param contact Contact instance to remove
1127 private void removeContact (final Contact contact) {
1128 // Is the instance valid?
1129 if (null == contact) {
1131 throw new NullPointerException("contact is null"); //NOI18N
1132 } else if (contact.getContactId() == null) {
1134 throw new NullPointerException("contact.contactId is null"); //NOI18N
1135 } else if (contact.getContactId() < 1) {
1136 // Not valid id number
1137 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1140 // Remove from general list
1141 if (!this.contactList.remove(contact)) {
1142 // Did not remove contact
1143 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1146 // Remove from other lists
1147 this.emailAddressList.remove(contact.getContactEmailAddress());
1151 * Adds unique instance to contact list. First any existing instance is
1152 * being removed, then the new instance is added.
1154 * @param contact Contact instance to add uniquely
1156 private void uniqueAddContact (final Contact contact) {
1157 // Is the instance valid?
1158 if (null == contact) {
1160 throw new NullPointerException("contact is null"); //NOI18N
1161 } else if (contact.getContactId() == null) {
1163 throw new NullPointerException("contact.contactId is null"); //NOI18N
1164 } else if (contact.getContactId() < 1) {
1165 // Not valid id number
1166 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1169 // Get iterator from list
1170 Iterator<Contact> iterator = this.contactList.iterator();
1172 // "Walk" through all entries
1173 while (iterator.hasNext()) {
1175 Contact next = iterator.next();
1177 // Is id number the same?
1178 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1179 // Found entry, so remove it and abort
1180 this.removeContact(next);
1185 // Add contact to list
1186 this.contactList.add(contact);