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