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