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