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.List;
24 import java.util.Objects;
25 import javax.annotation.PostConstruct;
26 import javax.enterprise.context.SessionScoped;
27 import javax.enterprise.event.Observes;
28 import javax.faces.view.facelets.FaceletException;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33 import javax.naming.NamingException;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
36 import org.mxchange.jcontacts.contact.UserContact;
37 import org.mxchange.jcontacts.contact.gender.Gender;
38 import org.mxchange.jcontacts.contact.utils.ContactUtils;
39 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
40 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
41 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
42 import org.mxchange.jcountry.data.Country;
43 import org.mxchange.jjobs.beans.BaseJobsController;
44 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
45 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
46 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
47 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
48 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
49 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
50 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
51 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
52 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
53 import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent;
54 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
55 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
56 import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
57 import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent;
58 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
59 import org.mxchange.jusercore.model.user.User;
62 * A general contact bean (controller)
64 * @author Roland Haeder<roland@mxchange.org>
66 @Named ("contactController")
68 public class JobsContactWebSessionBean extends BaseJobsController implements JobsContactWebSessionController {
73 private static final long serialVersionUID = 542_145_347_916L;
78 private Date birthday;
81 * Cellphone number's carrier
83 private MobileProvider cellphoneCarrier;
88 private Long cellphoneNumber;
98 private String comment;
101 * Remote contact bean
103 private final ContactSessionBeanRemote contactBean;
108 private List<Contact> contactList;
113 private Country country;
118 private String emailAddress;
123 private List<String> emailAddressList;
126 * Email address repeated
128 private String emailAddressRepeat;
133 private String familyName;
136 * Fax number's area code
138 private Integer faxAreaCode;
141 * Country instance for fax number
143 private Country faxCountry;
148 private Long faxNumber;
153 private String firstName;
158 private Gender gender;
163 private Short houseNumber;
166 * Whether a cellphone entry has been unlinked
168 private boolean isCellphoneUnlinked;
171 * Whether a fax entry has been unlinked
173 private boolean isFaxUnlinked;
176 * Whether a land-line number has been unlinked
178 private boolean isLandLineUnlinked;
181 * Phone number area code
183 private Integer phoneAreaCode;
186 * Country instance for phone number
188 private Country phoneCountry;
193 private Long phoneNumber;
196 * A list of all selectable contacts
198 private List<Contact> selectableContacts;
203 private String street;
206 * Regular user controller
209 private JobsUserWebSessionController userController;
212 * Login bean (controller)
215 private JobsUserLoginWebSessionController userLoginController;
220 private Integer zipCode;
223 * Default constructor
225 public JobsContactWebSessionBean () {
228 // Get initial context
229 Context context = new InitialContext();
232 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
233 } catch (final NamingException e) {
235 throw new FaceletException(e);
240 public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) {
241 // The event must be valid
244 throw new NullPointerException("event is null"); //NOI18N
245 } else if (event.getAddedContact() == null) {
247 throw new NullPointerException("event.addedContact is null"); //NOI18N
248 } else if (event.getAddedContact().getContactId() == null) {
250 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
251 } else if (event.getAddedContact().getContactId() < 1) {
253 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N
260 this.uniqueAddContact(event.getAddedContact());
262 // Add to selectable contacts
263 this.selectableContacts.add(event.getAddedContact());
267 public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) {
268 // event should not be null
271 throw new NullPointerException("event is null"); //NOI18N
272 } else if (event.getAddedUser() == null) {
274 throw new NullPointerException("event.addedUser is null"); //NOI18N
275 } else if (event.getAddedUser().getUserId() == null) {
277 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
278 } else if (event.getAddedUser().getUserId() < 1) {
280 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
288 public void afterAdminLinkedUser (@Observes final AdminLinkedUserEvent event) {
289 // event should not be null
292 throw new NullPointerException("event is null"); //NOI18N
293 } else if (event.getLinkedUser() == null) {
295 throw new NullPointerException("event.linkedUser is null"); //NOI18N
296 } else if (event.getLinkedUser().getUserContact() == null) {
298 throw new NullPointerException("event.linkedUser.userContact is null"); //NOI18N
299 } else if (event.getLinkedUser().getUserContact().getContactId() == null) {
301 throw new NullPointerException("event.linkedUser.userContact.contactId is null"); //NOI18N
302 } else if (event.getLinkedUser().getUserContact().getContactId() < 1) {
304 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
307 // Remove contact from list available contacts list
308 this.selectableContacts.remove(event.getLinkedUser().getUserContact());
315 public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
316 // event should not be null
319 throw new NullPointerException("event is null"); //NOI18N
320 } else if (event.getUpdatedContact() == null) {
322 throw new NullPointerException("event.updatedContact is null"); //NOI18N
323 } else if (event.getUpdatedContact().getContactId() == null) {
325 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
326 } else if (event.getUpdatedContact().getContactId() < 1) {
328 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
331 // Add contact instance only once
332 this.uniqueAddContact(event.getUpdatedContact());
334 // Add email address to list
335 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
339 public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
340 // event should not be null
343 throw new NullPointerException("event is null"); //NOI18N
344 } else if (event.getRegisteredUser() == null) {
346 throw new NullPointerException("event.registeredUser is null"); //NOI18N
347 } else if (event.getRegisteredUser().getUserId() == null) {
349 throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
350 } else if (event.getRegisteredUser().getUserId() < 1) {
352 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
356 Contact registeredContact = event.getRegisteredUser().getUserContact();
358 // Copy all data from registered->user
359 this.copyContact(registeredContact);
361 // Add contact instance only once
362 this.uniqueAddContact(registeredContact);
364 // Add user name and email address
365 this.addUserNameEmailAddress(registeredContact);
372 public void afterUserConfirmedAccount (@Observes final UserConfirmedAccountEvent event) {
373 // event should not be null
376 throw new NullPointerException("event is null"); //NOI18N
377 } else if (event.getConfirmedUser() == null) {
379 throw new NullPointerException("event.confirmedUser is null"); //NOI18N
380 } else if (event.getConfirmedUser().getUserId() == null) {
382 throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
383 } else if (event.getConfirmedUser().getUserId() < 1) {
385 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
388 // Add contact instance only once
389 this.uniqueAddContact(event.getConfirmedUser().getUserContact());
393 public void afterUserLogin (@Observes final UserLoggedInEvent event) {
394 // event should not be null
397 throw new NullPointerException("event is null"); //NOI18N
398 } else if (event.getLoggedInUser() == null) {
400 throw new NullPointerException("event.loggedInUser is null"); //NOI18N
401 } else if (event.getLoggedInUser().getUserId() == null) {
403 throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
404 } else if (event.getLoggedInUser().getUserId() < 1) {
406 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
409 // Copy all data to this bean
410 this.copyContact(event.getLoggedInUser().getUserContact());
414 public List<Contact> allContacts () {
416 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size()));
418 // Return un-modified list
419 return Collections.unmodifiableList(this.contactList);
423 public Contact createContactInstance () {
425 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName()));
427 // Is all required data set?
428 if (!this.isRequiredPersonalDataSet()) {
429 // No, then abort here
430 throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
433 // Generate phone number
434 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
435 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
436 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
438 // Create new contact
439 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
440 contact.setContactStreet(this.getStreet());
441 contact.setContactHouseNumber(this.getHouseNumber());
442 contact.setContactZipCode(this.getZipCode());
443 contact.setContactCity(this.getCity());
444 contact.setContactCountry(this.getCountry());
445 contact.setContactEmailAddress(this.getEmailAddress());
446 contact.setContactBirthday(this.getBirthday());
447 contact.setContactComment(this.getComment());
450 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress()));
452 // Don't set null or wrong references
453 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
454 // Now the number must be given
455 if (phone.getPhoneAreaCode() == null) {
457 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
458 } else if (phone.getPhoneAreaCode() < 1) {
460 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
461 } else if (phone.getPhoneNumber() == null) {
463 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
464 } else if (phone.getPhoneNumber() < 1) {
466 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
470 contact.setContactLandLineNumber(phone);
473 // Don't set null or wrong references
474 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
475 // Now the number must be given
476 if (fax.getPhoneAreaCode() == null) {
478 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
479 } else if (fax.getPhoneAreaCode() < 1) {
481 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
482 } else if (fax.getPhoneNumber() == null) {
484 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
485 } else if (fax.getPhoneNumber() < 1) {
487 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
491 contact.setContactFaxNumber(fax);
494 // Is the provider set?
495 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
496 // Is the number set?
497 if (cellphone.getPhoneNumber() == null) {
499 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
500 } else if (cellphone.getPhoneNumber() < 1) {
502 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
505 // Set cellphone number
506 contact.setContactCellphoneNumber(cellphone);
510 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact));
517 public String doChangePersonalContactData () {
518 // This method shall only be called if the user is logged-in
519 if (!this.userLoginController.isUserLoggedIn()) {
521 throw new IllegalStateException("User is not logged-in"); //NOI18N
522 } else if (!this.isRequiredChangePersonalDataSet()) {
523 // Not all required fields are set
524 throw new FaceletException("Not all required fields are set."); //NOI18N
525 } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
526 // Password not matching
527 this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
531 // Get contact instance
532 Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
534 // It should be there, so run some tests on it
535 assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
536 assert (contact.getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N
537 assert (contact.getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
540 contact.setContactGender(this.getGender());
541 contact.setContactFirstName(this.getFirstName());
542 contact.setContactFamilyName(this.getFamilyName());
543 contact.setContactStreet(this.getStreet());
544 contact.setContactHouseNumber(this.getHouseNumber());
545 contact.setContactZipCode(this.getZipCode());
546 contact.setContactCity(this.getCity());
547 contact.setContactCountry(this.getCountry());
549 // Update contact's cellphone number
550 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
552 // Update contact's land-line number
553 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
555 // Update contact's fax number
556 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
558 // Send it to the EJB
559 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
562 return "contact_data_saved"; //NOI18N
566 @SuppressWarnings ("ReturnOfDateField")
567 public Date getBirthday () {
568 return this.birthday;
572 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
573 public void setBirthday (final Date birthday) {
574 this.birthday = birthday;
578 public MobileProvider getCellphoneCarrier () {
579 return this.cellphoneCarrier;
583 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
584 this.cellphoneCarrier = cellphoneCarrier;
588 public Long getCellphoneNumber () {
589 return this.cellphoneNumber;
593 public void setCellphoneNumber (Long cellphoneNumber) {
594 this.cellphoneNumber = cellphoneNumber;
598 public String getCity () {
603 public void setCity (final String city) {
608 public String getComment () {
613 public void setComment (final String comment) {
614 this.comment = comment;
618 public String getControllerType () {
619 return "general"; //NOI18N
624 public void setControllerType (final String controllerType) {
625 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
629 public Country getCountry () {
634 public void setCountry (final Country country) {
635 this.country = country;
639 public String getEmailAddress () {
640 return this.emailAddress;
644 public void setEmailAddress (final String emailAddress) {
645 this.emailAddress = emailAddress;
649 public String getEmailAddressRepeat () {
650 return this.emailAddressRepeat;
654 public void setEmailAddressRepeat (final String emailAddressRepeat) {
655 this.emailAddressRepeat = emailAddressRepeat;
659 public String getFamilyName () {
660 return this.familyName;
664 public void setFamilyName (final String familyName) {
665 this.familyName = familyName;
669 public Integer getFaxAreaCode () {
670 return this.faxAreaCode;
674 public void setFaxAreaCode (final Integer faxAreaCode) {
675 this.faxAreaCode = faxAreaCode;
679 public Country getFaxCountry () {
680 return this.faxCountry;
684 public void setFaxCountry (final Country faxCountry) {
685 this.faxCountry = faxCountry;
689 public Long getFaxNumber () {
690 return this.faxNumber;
694 public void setFaxNumber (final Long faxNumber) {
695 this.faxNumber = faxNumber;
699 public String getFirstName () {
700 return this.firstName;
704 public void setFirstName (final String firstName) {
705 this.firstName = firstName;
709 public Gender getGender () {
714 public void setGender (final Gender gender) {
715 this.gender = gender;
719 public Short getHouseNumber () {
720 return this.houseNumber;
724 public void setHouseNumber (final Short houseNumber) {
725 this.houseNumber = houseNumber;
729 public Integer getPhoneAreaCode () {
730 return this.phoneAreaCode;
734 public void setPhoneAreaCode (final Integer phoneAreaCode) {
735 this.phoneAreaCode = phoneAreaCode;
739 public Country getPhoneCountry () {
740 return this.phoneCountry;
744 public void setPhoneCountry (final Country phoneCountry) {
745 this.phoneCountry = phoneCountry;
749 public Long getPhoneNumber () {
750 return this.phoneNumber;
754 public void setPhoneNumber (final Long phoneNumber) {
755 this.phoneNumber = phoneNumber;
759 public String getStreet () {
764 public void setStreet (final String street) {
765 this.street = street;
769 public Integer getZipCode () {
774 public void setZipCode (final Integer zipCode) {
775 this.zipCode = zipCode;
779 public boolean hasContacts () {
780 return (!this.contactList.isEmpty());
784 * Post-initialization of this class
787 public void init () {
788 // Get full email address list for reducing EJB calls
789 this.emailAddressList = this.contactBean.getEmailAddressList();
791 // Get full contact list
792 this.contactList = this.contactBean.getAllContacts();
795 List<User> allUsers = this.userController.allUsers();
798 List<Contact> allContacts = this.contactBean.getAllContacts();
801 Iterator<Contact> iterator = allContacts.iterator();
804 while (iterator.hasNext()) {
806 Contact next = iterator.next();
809 Iterator<User> userIterator = allUsers.iterator();
811 // Loop through all users
812 while (userIterator.hasNext()) {
814 User nextUser = userIterator.next();
817 if (Objects.equals(next, nextUser.getUserContact())) {
826 this.selectableContacts = allContacts;
830 public boolean isEmailAddressRegistered (final Contact contact) {
832 if (null == contact) {
834 throw new NullPointerException("contact is null"); //NOI18N
835 } else if (contact.getContactEmailAddress() == null) {
837 throw new NullPointerException("contact.contactEmailAddress is null"); //NOI18N
838 } else if (contact.getContactEmailAddress().isEmpty()) {
840 throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
844 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
848 public boolean isRequiredChangePersonalDataSet () {
849 return ((this.getGender() != null) &&
850 (this.getFirstName() != null) &&
851 (this.getFamilyName() != null) &&
852 (this.getStreet() != null) &&
853 (this.getHouseNumber() != null) &&
854 (this.getZipCode() != null) &&
855 (this.getCity() != null));
859 public boolean isRequiredPersonalDataSet () {
860 return ((this.getGender() != null) &&
861 (this.getFirstName() != null) &&
862 (this.getFamilyName() != null) &&
863 (this.getStreet() != null) &&
864 (this.getHouseNumber() != null) &&
865 (this.getZipCode() != null) &&
866 (this.getCity() != null) &&
867 (this.getEmailAddress() != null) &&
868 (this.getEmailAddressRepeat() != null));
872 public boolean isSameEmailAddressEntered () {
873 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
877 public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
879 Contact localContact = null;
884 // Try to lookup it in visible user list
885 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
887 Contact next = iterator.next();
889 // Is the user id found?
890 if (Objects.equals(next.getContactId(), contactId)) {
891 // Copy to other variable
898 if (null == localContact) {
899 // Not visible for the current user
900 throw new ContactNotFoundException(contactId);
903 // Copy all data to this bean
904 this.copyContact(localContact);
911 public List<Contact> selectableContacts () {
912 return Collections.unmodifiableList(this.selectableContacts);
916 public void updateContactDataFromController (final Contact contact) {
917 // Is the instance valid?
918 if (null == contact) {
920 throw new NullPointerException("contact is null"); //NOI18N
921 } else if (contact.getContactId() == null) {
923 throw new NullPointerException("contact.contactId is null"); //NOI18N
924 } else if (contact.getContactId() < 1) {
925 // Not valid id number
926 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
930 this.copyContact(contact);
934 * Adds email address to bean's internal list.
936 * @param contact Contact instance
938 private void addUserNameEmailAddress (final Contact contact) {
939 // Make sure the entry is not added yet
940 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
942 throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
946 this.emailAddressList.add(contact.getContactEmailAddress());
952 private void clear () {
955 this.setGender(null);
956 // TODO: Unfinished this.setTitle(null);
957 this.setFirstName(null);
958 this.setFamilyName(null);
959 this.setStreet(null);
960 this.setHouseNumber(null);
961 this.setZipCode(null);
963 this.setCountry(null);
966 this.setEmailAddress(null);
967 this.setEmailAddressRepeat(null);
968 this.setPhoneAreaCode(null);
969 this.setPhoneCountry(null);
970 this.setPhoneNumber(null);
971 this.setCellphoneCarrier(null);
972 this.setCellphoneNumber(null);
973 this.setFaxAreaCode(null);
974 this.setFaxCountry(null);
975 this.setFaxNumber(null);
978 this.setBirthday(null);
979 this.setComment(null);
983 * Copies given contact into the controller
985 * @param contact Contact instance
987 private void copyContact (final Contact contact) {
988 // Is the instance valid?
989 if (null == contact) {
991 throw new NullPointerException("contact is null"); //NOI18N
992 } else if (contact.getContactId() == null) {
994 throw new NullPointerException("contact.contactId is null"); //NOI18N
995 } else if (contact.getContactId() < 1) {
996 // Not valid id number
997 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1002 this.setGender(contact.getContactGender());
1003 this.setFirstName(contact.getContactFirstName());
1004 this.setFamilyName(contact.getContactFamilyName());
1005 this.setStreet(contact.getContactStreet());
1006 this.setHouseNumber(contact.getContactHouseNumber());
1007 this.setZipCode(contact.getContactZipCode());
1008 this.setCity(contact.getContactCity());
1009 this.setCountry(contact.getContactCountry());
1010 this.setEmailAddress(contact.getContactEmailAddress());
1011 this.setBirthday(contact.getContactBirthday());
1012 this.setComment(contact.getContactComment());
1014 // Get cellphone, phone and fax instance
1015 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
1016 DialableFaxNumber fax = contact.getContactFaxNumber();
1017 DialableLandLineNumber phone = contact.getContactLandLineNumber();
1020 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
1021 this.setPhoneCountry(phone.getPhoneCountry());
1022 this.setPhoneAreaCode(phone.getPhoneAreaCode());
1023 this.setPhoneNumber(phone.getPhoneNumber());
1026 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
1027 this.setCellphoneCarrier(cellphone.getCellphoneProvider());
1028 this.setCellphoneNumber(cellphone.getPhoneNumber());
1031 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
1032 this.setFaxCountry(fax.getPhoneCountry());
1033 this.setFaxAreaCode(fax.getPhoneAreaCode());
1034 this.setFaxNumber(fax.getPhoneNumber());
1039 * Removes given contact from all lists
1041 * @param contact Contact instance to remove
1043 private void removeContact (final Contact contact) {
1044 // Is the instance valid?
1045 if (null == contact) {
1047 throw new NullPointerException("contact is null"); //NOI18N
1048 } else if (contact.getContactId() == null) {
1050 throw new NullPointerException("contact.contactId is null"); //NOI18N
1051 } else if (contact.getContactId() < 1) {
1052 // Not valid id number
1053 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
1056 // Remove from general list
1057 if (!this.contactList.remove(contact)) {
1058 // Did not remove contact
1059 throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
1062 // Remove from other lists
1063 this.emailAddressList.remove(contact.getContactEmailAddress());
1067 * Adds unique instance to contact list. First any existing instance is
1068 * being removed, then the new instance is added.
1070 * @param contact Contact instance to add uniquely
1072 private void uniqueAddContact (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
1085 // Get iterator from list
1086 Iterator<Contact> iterator = this.contactList.iterator();
1088 // "Walk" through all entries
1089 while (iterator.hasNext()) {
1091 Contact next = iterator.next();
1093 // Is id number the same?
1094 if (Objects.equals(contact.getContactId(), next.getContactId())) {
1095 // Found entry, so remove it and abort
1096 this.removeContact(next);
1101 // Add contact to list
1102 this.contactList.add(contact);