]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java
Continued with rewriting:
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / contact / AddressbookContactWebSessionBean.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.addressbook.beans.contact;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Objects;
24 import javax.annotation.PostConstruct;
25 import javax.enterprise.context.SessionScoped;
26 import javax.enterprise.event.Observes;
27 import javax.faces.view.facelets.FaceletException;
28 import javax.inject.Inject;
29 import javax.inject.Named;
30 import javax.naming.Context;
31 import javax.naming.InitialContext;
32 import javax.naming.NamingException;
33 import org.mxchange.addressbook.beans.login.AddressbookUserLoginWebSessionController;
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.update.AdminUpdatedContactEvent;
40 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
41 import org.mxchange.jcountry.data.Country;
42 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
43 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
44 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
45 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
46 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
47 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
48 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
49 import org.mxchange.jusercore.events.login.UserLoggedInEvent;
50 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
51 import org.mxchange.jusercore.exceptions.UserPasswordMismatchException;
52
53 /**
54  * A general contact bean (controller)
55  * <p>
56  * @author Roland Haeder<roland@mxchange.org>
57  */
58 @Named ("contactController")
59 @SessionScoped
60 public class AddressbookContactWebSessionBean implements AddressbookContactWebSessionController {
61
62         /**
63          * Serial number
64          */
65         private static final long serialVersionUID = 542_145_347_916L;
66
67         /**
68          * Birth day
69          */
70         private Date birthday;
71
72         /**
73          * Cellphone number's carrier
74          */
75         private MobileProvider cellphoneCarrier;
76
77         /**
78          * Cellphone number
79          */
80         private Long cellphoneNumber;
81
82         /**
83          * City
84          */
85         private String city;
86
87         /**
88          * Optional comments
89          */
90         private String comment;
91
92         /**
93          * Remote contact bean
94          */
95         private final ContactSessionBeanRemote contactBean;
96
97         /**
98          * Contact list
99          */
100         private List<Contact> contactList;
101
102         /**
103          * Country instance
104          */
105         private Country country;
106
107         /**
108          * Email address
109          */
110         private String emailAddress;
111
112         /**
113          * Email address list
114          */
115         private List<String> emailAddressList;
116
117         /**
118          * Email address repeated
119          */
120         private String emailAddressRepeat;
121
122         /**
123          * Family name
124          */
125         private String familyName;
126
127         /**
128          * Fax number's area code
129          */
130         private Integer faxAreaCode;
131
132         /**
133          * Country instance for fax number
134          */
135         private Country faxCountry;
136
137         /**
138          * Fax number
139          */
140         private Long faxNumber;
141
142         /**
143          * First name
144          */
145         private String firstName;
146
147         /**
148          * Gender instance
149          */
150         private Gender gender;
151
152         /**
153          * House number
154          */
155         private Short houseNumber;
156
157         /**
158          * Whether a cellphone entry has been unlinked
159          */
160         private boolean isCellphoneUnlinked;
161
162         /**
163          * Whether a fax entry has been unlinked
164          */
165         private boolean isFaxUnlinked;
166
167         /**
168          * Whether a land-line number has been unlinked
169          */
170         private boolean isLandLineUnlinked;
171
172         /**
173          * Login bean (controller)
174          */
175         @Inject
176         private AddressbookUserLoginWebSessionController loginController;
177
178         /**
179          * Phone number area code
180          */
181         private Integer phoneAreaCode;
182
183         /**
184          * Country instance for phone number
185          */
186         private Country phoneCountry;
187
188         /**
189          * Phone number
190          */
191         private Long phoneNumber;
192
193         /**
194          * Street
195          */
196         private String street;
197
198         /**
199          * ZIP code
200          */
201         private Integer zipCode;
202
203         /**
204          * Default constructor
205          */
206         public AddressbookContactWebSessionBean () {
207                 // Set gender to UNKNOWN
208                 this.gender = Gender.UNKNOWN;
209
210                 // Try it
211                 try {
212                         // Get initial context
213                         Context context = new InitialContext();
214
215                         // Try to lookup
216                         this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
217                 } catch (final NamingException e) {
218                         // Throw again
219                         throw new FaceletException(e);
220                 }
221         }
222
223         @Override
224         public void addEmailAddress (final String contactEmailAddress) {
225                 // Add it
226                 this.emailAddressList.add(contactEmailAddress);
227         }
228
229         @Override
230         public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) {
231                 // Trace message
232                 System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N
233
234                 // event should not be null
235                 if (null == event) {
236                         // Throw NPE
237                         throw new NullPointerException("event is null"); //NOI18N
238                 } else if (event.getUpdatedContact()== null) {
239                         // Throw NPE again
240                         throw new NullPointerException("event.user is null"); //NOI18N
241                 } else if (event.getUpdatedContact().getContactId() == null) {
242                         // userId is null
243                         throw new NullPointerException("event.user.userId is null"); //NOI18N
244                 } else if (event.getUpdatedContact().getContactId() < 1) {
245                         // Not avalid id
246                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
247                 }
248
249                 // Get iterator from list
250                 Iterator<Contact> iterator = this.contactList.iterator();
251
252                 // "Walk" through all entries
253                 while (iterator.hasNext()) {
254                         // Get next element
255                         Contact next = iterator.next();
256
257                         // Is id number the same?
258                         if (Objects.equals(event.getUpdatedContact().getContactId(), next.getContactId())) {
259                                 // Found entry, so remove it and abort
260                                 this.contactList.remove(next);
261
262                                 // Remove also email from list
263                                 this.emailAddressList.remove(next.getContactEmailAddress());
264                                 break;
265                         }
266                 }
267
268                 // Add contact to list
269                 this.contactList.add(event.getUpdatedContact());
270
271                 // Add email address to list
272                 this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress());
273         }
274
275         @Override
276         public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) {
277                 // Trace message
278                 System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N
279
280                 // event should not be null
281                 if (null == event) {
282                         // Throw NPE
283                         throw new NullPointerException("event is null"); //NOI18N
284                 } else if (event.getRegisteredUser() == null) {
285                         // Throw NPE again
286                         throw new NullPointerException("event.user is null"); //NOI18N
287                 } else if (event.getRegisteredUser().getUserId() == null) {
288                         // userId is null
289                         throw new NullPointerException("event.user.userId is null"); //NOI18N
290                 } else if (event.getRegisteredUser().getUserId() < 1) {
291                         // Not avalid id
292                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
293                 }
294
295                 // Get user instance
296                 Contact registeredContact = event.getRegisteredUser().getUserContact();
297
298                 // Debug message
299                 System.out.println(MessageFormat.format("ContactWebBean:afterRegistration: registeredContact={0}", registeredContact)); //NOI18N
300
301                 // Copy all data from registered->user
302                 this.copyContact(registeredContact);
303
304                 // Add user name and email address
305                 this.addUserNameEmailAddress(registeredContact);
306
307                 // Clear all data
308                 this.clear();
309
310                 // Trace message
311                 System.out.println("ContactWebBean:afterRegistration: EXIT!"); //NOI18N
312         }
313
314         @Override
315         public void afterUserLogin (final @Observes UserLoggedInEvent event) {
316                 // Trace message
317                 System.out.println(MessageFormat.format("ContactWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N
318
319                 // event should not be null
320                 if (null == event) {
321                         // Throw NPE
322                         throw new NullPointerException("event is null"); //NOI18N
323                 } else if (event.getLoggedInUser() == null) {
324                         // Throw NPE again
325                         throw new NullPointerException("event.user is null"); //NOI18N
326                 } else if (event.getLoggedInUser().getUserId() == null) {
327                         // userId is null
328                         throw new NullPointerException("event.user.userId is null"); //NOI18N
329                 } else if (event.getLoggedInUser().getUserId() < 1) {
330                         // Not avalid id
331                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
332                 }
333
334                 // Copy all data to this bean
335                 this.copyContact(event.getLoggedInUser().getUserContact());
336
337                 // Trace message
338                 System.out.println("ContactWebBean:afterUserLogin - EXIT!"); //NOI18N
339         }
340
341         /**
342          * Clears this bean
343          */
344         @Override
345         public void clear () {
346                 // Clear all data
347                 // - personal data
348                 this.setGender(Gender.UNKNOWN);
349                 this.setFirstName(null);
350                 this.setFamilyName(null);
351                 this.setStreet(null);
352                 this.setHouseNumber(null);
353                 this.setZipCode(null);
354                 this.setCity(null);
355                 this.setCountry(null);
356
357                 // - contact data
358                 this.setEmailAddress(null);
359                 this.setEmailAddressRepeat(null);
360                 this.setPhoneAreaCode(null);
361                 this.setCellphoneCarrier(null);
362                 this.setFaxAreaCode(null);
363
364                 // - other data
365                 this.setBirthday(null);
366                 this.setComment(null);
367         }
368
369         @Override
370         public Contact createContactInstance () {
371                 // User message
372                 //this.getLogger().logTrace("createContactInstance: CALLED!");
373
374                 // Required personal data must be set
375                 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
376
377                 // Create new contact instance
378                 Contact localContact = new UserContact();
379
380                 // Generate phone number
381                 DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
382                 DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
383                 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
384
385                 // Create new contact
386                 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
387                 contact.setContactStreet(this.getStreet());
388                 contact.setContactHouseNumber(this.getHouseNumber());
389                 contact.setContactZipCode(this.getZipCode());
390                 contact.setContactCity(this.getCity());
391                 contact.setContactCountry(this.getCountry());
392                 contact.setContactEmailAddress(this.getEmailAddress());
393
394                 // Don't set null or wrong references
395                 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
396                         // Now the number must be given
397                         if (phone.getPhoneAreaCode() == null) {
398                                 // Is null
399                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
400                         } else if (phone.getPhoneAreaCode() < 1) {
401                                 // Abort here
402                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
403                         } else if (phone.getPhoneNumber() == null) {
404                                 // Is null
405                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
406                         } else if (phone.getPhoneNumber() < 1) {
407                                 // Abort here
408                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
409                         }
410
411                         // Set phone number
412                         contact.setContactLandLineNumber(phone);
413                 }
414
415                 // Don't set null or wrong references
416                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
417                         // Now the number must be given
418                         if (fax.getPhoneAreaCode() == null) {
419                                 // Is null
420                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
421                         } else if (fax.getPhoneAreaCode() < 1) {
422                                 // Abort here
423                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
424                         } else if (fax.getPhoneNumber() == null) {
425                                 // Is null
426                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
427                         } else if (fax.getPhoneNumber() < 1) {
428                                 // Abort here
429                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
430                         }
431
432                         // Set fax number
433                         contact.setContactFaxNumber(fax);
434                 }
435
436                 // Is the provider set?
437                 if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
438                         // Is the number set?
439                         if (cellphone.getPhoneNumber() == null) {
440                                 // Is null
441                                 throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
442                         } else if (cellphone.getPhoneNumber() < 1) {
443                                 // Abort here
444                                 throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
445                         }
446
447                         // Set cellphone number
448                         contact.setContactCellphoneNumber(cellphone);
449                 }
450
451                 contact.setContactBirthday(this.getBirthday());
452                 contact.setContactComment(this.getComment());
453
454                 // Created timestamp and ownContact
455                 contact.setContactOwnContact(Boolean.TRUE);
456
457                 // Trace message
458                 //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact));
459
460                 // Return it
461                 return localContact;
462         }
463
464         @Override
465         public String doChangePersonalContactData () {
466                 // This method shall only be called if the user is logged-in
467                 if (!this.loginController.isUserLoggedIn()) {
468                         // Not logged-in
469                         throw new IllegalStateException("User is not logged-in"); //NOI18N
470                 } else if (!this.isRequiredChangePersonalDataSet()) {
471                         // Not all required fields are set
472                         throw new FaceletException("Not all required fields are set."); //NOI18N
473                 } else if (!this.loginController.ifCurrentPasswordMatches()) {
474                         // Password not matching
475                         throw new FaceletException(new UserPasswordMismatchException(this.loginController.getLoggedInUser()));
476                 }
477
478                 // Get contact instance
479                 Contact contact = this.loginController.getLoggedInUser().getUserContact();
480
481                 // It should be there, so run some tests on it
482                 assert (contact instanceof Contact) : "Instance loginController.loggedInUser.userContact is null"; //NOI18N
483                 assert (contact.getContactId() instanceof Long) : "Instance loginController.userContact.contactId is null"; //NOI18N
484                 assert (contact.getContactId() > 0) : MessageFormat.format("Instance loginController.userContact.contactId={0} is invalid", contact.getContactId()); //NOI18N
485
486                 // Update all fields
487                 contact.setContactGender(this.getGender());
488                 contact.setContactFirstName(this.getFirstName());
489                 contact.setContactFamilyName(this.getFamilyName());
490                 contact.setContactStreet(this.getStreet());
491                 contact.setContactHouseNumber(this.getHouseNumber());
492                 contact.setContactZipCode(this.getZipCode());
493                 contact.setContactCity(this.getCity());
494                 contact.setContactCountry(this.getCountry());
495
496                 // Update contact's cellphone number
497                 this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber());
498
499                 // Update contact's land-line number
500                 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
501
502                 // Update contact's fax number
503                 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
504
505                 // Send it to the EJB
506                 this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
507
508                 // All fine
509                 return "contact_data_saved"; //NOI18N
510         }
511
512         @Override
513         public Date getBirthday () {
514                 return this.birthday;
515         }
516
517         @Override
518         public void setBirthday (final Date birthday) {
519                 this.birthday = birthday;
520         }
521
522         @Override
523         public MobileProvider getCellphoneCarrier () {
524                 return this.cellphoneCarrier;
525         }
526
527         @Override
528         public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
529                 this.cellphoneCarrier = cellphoneCarrier;
530         }
531
532         @Override
533         public Long getCellphoneNumber () {
534                 return this.cellphoneNumber;
535         }
536
537         @Override
538         public void setCellphoneNumber (Long cellphoneNumber) {
539                 this.cellphoneNumber = cellphoneNumber;
540         }
541
542         @Override
543         public String getCity () {
544                 return this.city;
545         }
546
547         @Override
548         public void setCity (final String city) {
549                 this.city = city;
550         }
551
552         @Override
553         public String getComment () {
554                 return this.comment;
555         }
556
557         @Override
558         public void setComment (final String comment) {
559                 this.comment = comment;
560         }
561
562         @Override
563         public Country getCountry () {
564                 return this.country;
565         }
566
567         @Override
568         public void setCountry (final Country country) {
569                 this.country = country;
570         }
571
572         @Override
573         public String getEmailAddress () {
574                 return this.emailAddress;
575         }
576
577         @Override
578         public void setEmailAddress (final String emailAddress) {
579                 this.emailAddress = emailAddress;
580         }
581
582         @Override
583         public String getEmailAddressRepeat () {
584                 return this.emailAddressRepeat;
585         }
586
587         @Override
588         public void setEmailAddressRepeat (final String emailAddressRepeat) {
589                 this.emailAddressRepeat = emailAddressRepeat;
590         }
591
592         @Override
593         public String getFamilyName () {
594                 return this.familyName;
595         }
596
597         @Override
598         public void setFamilyName (final String familyName) {
599                 this.familyName = familyName;
600         }
601
602         @Override
603         public Integer getFaxAreaCode () {
604                 return this.faxAreaCode;
605         }
606
607         @Override
608         public void setFaxAreaCode (final Integer faxAreaCode) {
609                 this.faxAreaCode = faxAreaCode;
610         }
611
612         @Override
613         public Country getFaxCountry () {
614                 return this.faxCountry;
615         }
616
617         @Override
618         public void setFaxCountry (final Country faxCountry) {
619                 this.faxCountry = faxCountry;
620         }
621
622         @Override
623         public Long getFaxNumber () {
624                 return this.faxNumber;
625         }
626
627         @Override
628         public void setFaxNumber (final Long faxNumber) {
629                 this.faxNumber = faxNumber;
630         }
631
632         @Override
633         public String getFirstName () {
634                 return this.firstName;
635         }
636
637         @Override
638         public void setFirstName (final String firstName) {
639                 this.firstName = firstName;
640         }
641
642         @Override
643         public Gender getGender () {
644                 return this.gender;
645         }
646
647         @Override
648         public void setGender (final Gender gender) {
649                 this.gender = gender;
650         }
651
652         @Override
653         public Short getHouseNumber () {
654                 return this.houseNumber;
655         }
656
657         @Override
658         public void setHouseNumber (final Short houseNumber) {
659                 this.houseNumber = houseNumber;
660         }
661
662         @Override
663         public Integer getPhoneAreaCode () {
664                 return this.phoneAreaCode;
665         }
666
667         @Override
668         public void setPhoneAreaCode (final Integer phoneAreaCode) {
669                 this.phoneAreaCode = phoneAreaCode;
670         }
671
672         @Override
673         public Country getPhoneCountry () {
674                 return this.phoneCountry;
675         }
676
677         @Override
678         public void setPhoneCountry (final Country phoneCountry) {
679                 this.phoneCountry = phoneCountry;
680         }
681
682         @Override
683         public Long getPhoneNumber () {
684                 return this.phoneNumber;
685         }
686
687         @Override
688         public void setPhoneNumber (final Long phoneNumber) {
689                 this.phoneNumber = phoneNumber;
690         }
691
692         @Override
693         public String getStreet () {
694                 return this.street;
695         }
696
697         @Override
698         public void setStreet (final String street) {
699                 this.street = street;
700         }
701
702         @Override
703         public Integer getZipCode () {
704                 return this.zipCode;
705         }
706
707         @Override
708         public void setZipCode (final Integer zipCode) {
709                 this.zipCode = zipCode;
710         }
711
712         /**
713          * Post-initialization of this class
714          */
715         @PostConstruct
716         public void init () {
717                 // Get full email address list for reducing EJB calls
718                 this.emailAddressList = this.contactBean.getEmailAddressList();
719
720                 // Get full contact list
721                 this.contactList = this.contactBean.getAllContacts();
722         }
723
724         @Override
725         public boolean isEmailAddressRegistered (final Contact contact) {
726                 return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress())));
727         }
728
729         @Override
730         public boolean isRequiredChangePersonalDataSet () {
731                 return ((this.getGender() != null) &&
732                                 (this.getFirstName() != null) &&
733                                 (this.getFamilyName() != null) &&
734                                 (this.getStreet() != null) &&
735                                 (this.getHouseNumber() != null) &&
736                                 (this.getZipCode() != null) &&
737                                 (this.getCity() != null));
738         }
739
740         @Override
741         public boolean isRequiredPersonalDataSet () {
742                 return ((this.getGender() != null) &&
743                                 (this.getFirstName() != null) &&
744                                 (this.getFamilyName() != null) &&
745                                 (this.getStreet() != null) &&
746                                 (this.getHouseNumber() != null) &&
747                                 (this.getZipCode() != null) &&
748                                 (this.getCity() != null) &&
749                                 (this.getEmailAddress() != null) &&
750                                 (this.getEmailAddressRepeat() != null));
751         }
752
753         @Override
754         public boolean isSameEmailAddressEntered () {
755                 return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
756         }
757
758         @Override
759         public Contact lookupContactById (final Long contactId) throws ContactNotFoundException {
760                 // Init variable
761                 Contact localContact = null;
762
763                 // Clear this bean
764                 this.clear();
765
766                 // Try to lookup it in visible user list
767                 for (final Iterator<Contact> iterator = this.contactList.iterator(); iterator.hasNext();) {
768                         // Get next user
769                         Contact next = iterator.next();
770
771                         // Is the user id found?
772                         if (Objects.equals(next.getContactId(), contactId)) {
773                                 // Copy to other variable
774                                 localContact = next;
775                                 break;
776                         }
777                 }
778
779                 // Is it still null?
780                 if (null == localContact) {
781                         // Not visible for the current user
782                         throw new ContactNotFoundException(contactId);
783                 }
784
785                 // Copy all data to this bean
786                 this.copyContact(localContact);
787
788                 // Return it
789                 return localContact;
790         }
791
792         @Override
793         public void updateContactDataFromController (final Contact userContact) {
794                 // Is the instance valid?
795                 if (null == userContact) {
796                         // Throw NPE
797                         throw new NullPointerException("userContact is null"); //NOI18N
798                 } else if (userContact.getContactId() == null) {
799                         // Throw NPE
800                         throw new NullPointerException("userContact.contactId is null"); //NOI18N
801                 } else if (userContact.getContactId() < 1) {
802                         // Not valid id number
803                         throw new IllegalArgumentException(MessageFormat.format("userContact.contactId={0} is not valid.", userContact.getContactId())); //NOI18N
804                 }
805
806                 // Set all
807                 this.copyContact(userContact);
808         }
809
810         /**
811          * Adds email address to bean's internal list.
812          * <p>
813          * @param contact Contact instance
814          */
815         private void addUserNameEmailAddress (final Contact contact) {
816                 // Make sure the entry is not added yet
817                 if (this.emailAddressList.contains(contact.getContactEmailAddress())) {
818                         // Already added
819                         throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
820                 }
821
822                 // Add email addres
823                 this.emailAddressList.add(contact.getContactEmailAddress());
824         }
825
826         /**
827          * Copies given contact into the controller
828          * <p>
829          * @param contact Contact instance
830          */
831         private void copyContact (final Contact contact) {
832                 // Copy all fields:
833                 // - base data
834                 this.setGender(contact.getContactGender());
835                 this.setFirstName(contact.getContactFirstName());
836                 this.setFamilyName(contact.getContactFamilyName());
837                 this.setStreet(contact.getContactStreet());
838                 this.setHouseNumber(contact.getContactHouseNumber());
839                 this.setZipCode(contact.getContactZipCode());
840                 this.setCity(contact.getContactCity());
841                 this.setCountry(contact.getContactCountry());
842
843                 // Get cellphone, phone and fax instance
844                 DialableCellphoneNumber cellphone = contact.getContactCellphoneNumber();
845                 DialableFaxNumber fax = contact.getContactFaxNumber();
846                 DialableLandLineNumber phone = contact.getContactLandLineNumber();
847
848                 // - contact data
849                 if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
850                         this.setPhoneCountry(phone.getPhoneCountry());
851                         this.setPhoneAreaCode(phone.getPhoneAreaCode());
852                         this.setPhoneNumber(phone.getPhoneNumber());
853                 }
854                 if ((cellphone instanceof DialableCellphoneNumber) && (cellphone.getCellphoneProvider() instanceof MobileProvider)) {
855                         this.setCellphoneCarrier(cellphone.getCellphoneProvider());
856                         this.setCellphoneNumber(cellphone.getPhoneNumber());
857                 }
858                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
859                         this.setFaxCountry(fax.getPhoneCountry());
860                         this.setFaxAreaCode(fax.getPhoneAreaCode());
861                         this.setFaxNumber(fax.getPhoneNumber());
862                 }
863                 this.setEmailAddress(contact.getContactEmailAddress());
864
865                 // -- other data
866                 this.setBirthday(contact.getContactBirthday());
867                 this.setComment(contact.getContactComment());
868         }
869
870 }