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