]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java
abbbd7600066188e68c2c9a52f4495d5c5a14721
[addressbook-war.git] / src / java / org / mxchange / addressbook / beans / contact / AddressbookAdminContactWebRequestBean.java
1 /*
2  * Copyright (C) 2016 - 2022 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.addressbook.beans.contact;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import javax.ejb.EJB;
22 import javax.enterprise.context.RequestScoped;
23 import javax.enterprise.event.Event;
24 import javax.enterprise.event.Observes;
25 import javax.enterprise.inject.Any;
26 import javax.faces.FacesException;
27 import javax.inject.Inject;
28 import javax.inject.Named;
29 import org.mxchange.addressbook.beans.BaseAddressbookBean;
30 import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
31 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
32 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
33 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
34 import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent;
35 import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
36 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
37 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
38 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
39 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
40 import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
41 import org.mxchange.jcontacts.model.contact.Contact;
42 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
43 import org.mxchange.jcontacts.model.contact.UserContact;
44 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
45 import org.mxchange.jcontacts.model.utils.ContactUtils;
46 import org.mxchange.jcountry.model.data.Country;
47 import org.mxchange.jphone.model.phonenumbers.DialableNumber;
48 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
49 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
50 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
51 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
52 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
53 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
54 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
55
56 /**
57  * An administrative user bean (controller)
58  * <p>
59  * @author Roland Häder<roland@mxchange.org>
60  */
61 @Named ("adminContactController")
62 @RequestScoped
63 public class AddressbookAdminContactWebRequestBean extends BaseAddressbookBean implements AddressbookAdminContactWebRequestController {
64
65         /**
66          * Serial number
67          */
68         private static final long serialVersionUID = 542_145_351_001L;
69
70         /**
71          * Academic academicTitle
72          */
73         private String academicTitle;
74
75         /**
76          * An event fired when the administrator has added a new contact
77          */
78         @Inject
79         @Any
80         private Event<ObservableAdminAddedContactEvent> addedContactEvent;
81
82         /**
83          * Administrative contact EJB
84          */
85         @EJB (lookup = "java:global/addressbook-ejb/adminContact!org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote")
86         private AdminContactSessionBeanRemote adminContactBean;
87
88         /**
89          * Birth day
90          */
91         private Date birthday;
92
93         /**
94          * City
95          */
96         private String city;
97
98         /**
99          * Optional comments
100          */
101         private String comment;
102
103         /**
104          * Current contact instance
105          */
106         private Contact contact;
107
108         /**
109          * EJB for general contact purposes
110          */
111         @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
112         private ContactSessionBeanRemote contactBean;
113
114         /**
115          * Country instance
116          */
117         private Country contactCountry;
118
119         /**
120          * Contact id
121          */
122         private Long contactId;
123
124         /**
125          * An instance of a contact list controller
126          */
127         @Inject
128         private AddressbookContactListWebViewController contactListController;
129
130         /**
131          * Event being fired when an administrator has deleted a contact
132          */
133         @Any
134         @Inject
135         private Event<ObservableAdminDeletedContactEvent> deletedContactEvent;
136
137         /**
138          * Email address
139          */
140         private String emailAddress;
141
142         /**
143          * Family name
144          */
145         private String familyName;
146
147         /**
148          * Fax number's area code
149          */
150         private Integer faxAreaCode;
151
152         /**
153          * Country instance for fax number
154          */
155         private Country faxCountry;
156
157         /**
158          * Fax id number
159          */
160         private Long faxId;
161
162         /**
163          * Fax number
164          */
165         private Long faxNumber;
166
167         /**
168          * First name
169          */
170         private String firstName;
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 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          * Whether a mobile entry has been unlinked
194          */
195         private boolean isMobileNumberUnlinked;
196
197         /**
198          * Phone number area code
199          */
200         private Integer landLineAreaCode;
201
202         /**
203          * Country instance for phone number
204          */
205         private Country landLineCountry;
206
207         /**
208          * Land-line id number
209          */
210         private Long landLineId;
211
212         /**
213          * Phone number
214          */
215         private Long landLineNumber;
216
217         /**
218          * Mobile id number
219          */
220         private Long mobileId;
221
222         /**
223          * Mobile number
224          */
225         private Long mobileNumber;
226
227         /**
228          * Mobile number's provider
229          */
230         private MobileProvider mobileProvider;
231
232         /**
233          * PersonalTitle instance
234          */
235         private PersonalTitle personalTitle;
236
237         /**
238          * Street
239          */
240         private String street;
241
242         /**
243          * An event fired when the administrator has updated contact data
244          */
245         @Inject
246         @Any
247         private Event<ObservableAdminUpdatedContactEvent> updatedContactEvent;
248
249         /**
250          * ZIP code
251          */
252         private Integer zipCode;
253
254         /**
255          * Default constructor
256          */
257         public AddressbookAdminContactWebRequestBean () {
258                 // Call super constructor
259                 super();
260         }
261
262         /**
263          * Adds contact data to database and redirects on success. If the contact is
264          * already found, a proper exception is thrown.
265          */
266         public void addContact () {
267                 // Are all minimum fields set?
268                 if (this.getPersonalTitle() == null) {
269                         // Throw NPE
270                         throw new NullPointerException("personalTitle is null"); //NOI18N
271                 } else if (this.getFirstName() == null) {
272                         // Throw NPE
273                         throw new NullPointerException("firstName is null"); //NOI18N
274                 } else if (this.getFirstName().isEmpty()) {
275                         // Empty string
276                         throw new IllegalStateException("firstName is empty"); //NOI18N
277                 } else if (this.getFamilyName() == null) {
278                         // Throw NPE
279                         throw new NullPointerException("familyName is null"); //NOI18N
280                 } else if (this.getFamilyName().isEmpty()) {
281                         // Empty string
282                         throw new IllegalStateException("familyName is empty"); //NOI18N
283                 }
284
285                 // Create new contact instance
286                 final Contact createdContact = this.createContactInstance();
287
288                 // Default is not same contact
289                 if (this.contactListController.isContactFound(createdContact)) {
290                         // Already registered
291                         throw new FacesException(new ContactAlreadyAddedException(createdContact));
292                 }
293
294                 // Init contact
295                 final Contact updatedContact;
296
297                 // Try to call EJB
298                 try {
299                         // Call EJB
300                         updatedContact = this.adminContactBean.addContact(createdContact);
301                 } catch (final ContactAlreadyAddedException ex) {
302                         // Throw again
303                         throw new FacesException(ex);
304                 }
305
306                 // Fire event
307                 this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
308
309                 // Clear this bean
310                 this.clear();
311         }
312
313         /**
314          * Observer for events being fired when a bean helper has successfully
315          * created a contact instance.
316          * <p>
317          * @param event Event being fired
318          */
319         public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
320                 // Log message
321                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
322
323                 // The event instance must be valid
324                 if (null == event) {
325                         // Throw NPE again
326                         throw new NullPointerException("event is null"); //NOI18N
327                 } else if (event.getCreatedContact() == null) {
328                         // Throw NPE again
329                         throw new NullPointerException("event.createdContact is null"); //NOI18N
330                 } else if (event.getCreatedContact().getContactId() == null) {
331                         // Throw NPE again
332                         throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N
333                 } else if (event.getCreatedContact().getContactId() < 1) {
334                         // Not valid
335                         throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
336                 }
337
338                 // Set contact for e.g. delete method
339                 this.setContact(event.getCreatedContact());
340
341                 // Get contact instance from event
342                 final Contact createdContact = event.getCreatedContact();
343
344                 // Set all fields: contact
345                 this.setContactId(createdContact.getContactId());
346                 this.setAcademicTitle(createdContact.getContactTitle());
347                 this.setBirthday(createdContact.getContactBirthday());
348                 this.setCity(createdContact.getContactCity());
349                 this.setComment(createdContact.getContactComment());
350                 this.setContactCountry(createdContact.getContactCountry());
351                 this.setEmailAddress(createdContact.getContactEmailAddress());
352                 this.setFamilyName(createdContact.getContactFamilyName());
353                 this.setFirstName(createdContact.getContactFirstName());
354                 this.setPersonalTitle(createdContact.getContactPersonalTitle());
355                 this.setHouseNumber(createdContact.getContactHouseNumber());
356                 this.setHouseNumberExtension(createdContact.getContactHouseNumberExtension());
357                 this.setStreet(createdContact.getContactStreet());
358                 this.setZipCode(createdContact.getContactZipCode());
359
360                 // Is the cell phone set?
361                 if (createdContact.getContactMobileNumber() instanceof DialableMobileNumber) {
362                         // ... cmobile data
363                         this.setMobileId(createdContact.getContactMobileNumber().getMobileId());
364                         this.setMobileProvider(createdContact.getContactMobileNumber().getMobileProvider());
365                         this.setMobileNumber(createdContact.getContactMobileNumber().getMobileNumber());
366                 }
367
368                 // Is the fax set?
369                 if (createdContact.getContactFaxNumber() instanceof DialableFaxNumber) {
370                         // ... fax data
371                         this.setFaxId(createdContact.getContactFaxNumber().getPhoneId());
372                         this.setFaxAreaCode(createdContact.getContactFaxNumber().getPhoneAreaCode());
373                         this.setFaxCountry(createdContact.getContactFaxNumber().getPhoneCountry());
374                         this.setFaxNumber(createdContact.getContactFaxNumber().getPhoneNumber());
375                 }
376
377                 // Is the land-line number set?
378                 if (createdContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
379                         // .. land-line data
380                         this.setLandLineId(createdContact.getContactLandLineNumber().getPhoneId());
381                         this.setLandLineAreaCode(createdContact.getContactLandLineNumber().getPhoneAreaCode());
382                         this.setLandLineCountry(createdContact.getContactLandLineNumber().getPhoneCountry());
383                         this.setLandLineNumber(createdContact.getContactLandLineNumber().getPhoneNumber());
384                 }
385
386                 // Log message
387                 //* NOISY-DEBUG: */ System.out.println("AdminContactController::afterCreatedContactEvent(): EXIT!"); //NOI18N
388         }
389
390         @Override
391         public Contact createContactInstance () {
392                 // Are all minimum fields set?
393                 if (this.getPersonalTitle() == null) {
394                         // Throw NPE
395                         throw new NullPointerException("personalTitle is null"); //NOI18N
396                 } else if (this.getFirstName() == null) {
397                         // Throw NPE
398                         throw new NullPointerException("firstName is null"); //NOI18N
399                 } else if (this.getFirstName().isEmpty()) {
400                         // Empty string
401                         throw new IllegalStateException("firstName is empty"); //NOI18N
402                 } else if (this.getFamilyName() == null) {
403                         // Throw NPE
404                         throw new NullPointerException("familyName is null"); //NOI18N
405                 } else if (this.getFamilyName().isEmpty()) {
406                         // Empty string
407                         throw new IllegalStateException("familyName is empty"); //NOI18N
408                 } else if (this.getContactCountry() == null) {
409                         // Throw NPE
410                         throw new NullPointerException("contactCountry is null"); //NOI18N
411                 } else if (this.getContactCountry().getCountryId() == null) {
412                         // Throw it again
413                         throw new NullPointerException("contactCountry.countryId is null"); //NOI18N
414                 } else if (this.getContactCountry().getCountryId() < 1) {
415                         // Throw IAE
416                         throw new IllegalArgumentException(MessageFormat.format("contactCountry.countryId={0} is invalid", this.getContactCountry().getCountryId())); //NOI18N
417                 }
418
419                 // Generate phone number
420                 DialableLandLineNumber landLine = null;
421                 DialableMobileNumber mobile = null;
422                 DialableFaxNumber fax = null;
423
424                 // Are all fields set?
425                 if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
426                         // Init instance
427                         landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
428                 }
429
430                 // Are all fields set?
431                 if (this.getMobileProvider() instanceof MobileProvider && this.getMobileNumber() != null) {
432                         // Initialize instance
433                         mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
434                 }
435
436                 // Are all fields set?
437                 if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
438                         // Initialize instance
439                         fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
440                 }
441
442                 // Create new instance
443                 final Contact localContact = new UserContact(
444                                           this.getPersonalTitle(),
445                                           this.getFirstName(),
446                                           this.getFamilyName(),
447                                           this.getContactCountry(),
448                                           Boolean.FALSE,
449                                           this.getStreet(),
450                                           this.getHouseNumber(),
451                                           this.getHouseNumberExtension(),
452                                           this.getZipCode(),
453                                           this.getCity(),
454                                           this.getEmailAddress(),
455                                           this.getAcademicTitle(),
456                                           this.getBirthday(),
457                                           this.getComment()
458                           );
459
460                 // Add missing fields
461                 localContact.setContactId(this.getContactId());
462
463                 // Don't set null or wrong references
464                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
465                         // Now the number must be given
466                         if (landLine.getPhoneAreaCode() == null) {
467                                 // Is null
468                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
469                         } else if (landLine.getPhoneAreaCode() < 1) {
470                                 // Abort here
471                                 throw new IllegalStateException("phone.phoneAreaCode is zero or below."); //NOI18N
472                         } else if (landLine.getPhoneNumber() == null) {
473                                 // Is null
474                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
475                         } else if (landLine.getPhoneNumber() < 1) {
476                                 // Abort here
477                                 throw new IllegalStateException("phone.phoneNumber is zero or below."); //NOI18N
478                         }
479
480                         // Set phone number
481                         localContact.setContactLandLineNumber(landLine);
482                 }
483
484                 // Don't set null or wrong references
485                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
486                         // Now the number must be given
487                         if (fax.getPhoneAreaCode() == null) {
488                                 // Is null
489                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
490                         } else if (fax.getPhoneAreaCode() < 1) {
491                                 // Abort here
492                                 throw new IllegalStateException("fax.phoneAreaCode is zero or below."); //NOI18N
493                         } else if (fax.getPhoneNumber() == null) {
494                                 // Is null
495                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
496                         } else if (fax.getPhoneNumber() < 1) {
497                                 // Abort here
498                                 throw new IllegalStateException("fax.phoneNumber is zero or below."); //NOI18N
499                         }
500
501                         // Set fax number
502                         localContact.setContactFaxNumber(fax);
503                 }
504
505                 // Is the provider set?
506                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
507                         // Is the number set?
508                         if (mobile.getMobileNumber() == null) {
509                                 // Is null
510                                 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
511                         } else if (mobile.getMobileNumber() < 1) {
512                                 // Abort here
513                                 throw new IllegalStateException("cmobile.phoneNumber is zero or below."); //NOI18N
514                         }
515
516                         // Set cmobile number
517                         localContact.setContactMobileNumber(mobile);
518                 }
519
520                 // Return it
521                 return localContact;
522         }
523
524         /**
525          * Deletes currently chosen contact and returns to list view
526          *
527          * @return
528          */
529         public String deleteContactData () {
530                 // Is contact set?
531                 if (this.getContact() == null) {
532                         // Throw NPE
533                         throw new NullPointerException("this.contact is null");
534                 } else if (this.getContact().getContactId() == null) {
535                         // Throw NPE again
536                         throw new NullPointerException("this.contact.contactId is null");
537                 } else if (this.getContact().getContactId() < 1) {
538                         // Throw IAE
539                         throw new NullPointerException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId()));
540                 }
541
542                 try {
543                         // Invoke EJB
544                         this.adminContactBean.deleteContactData(this.getContact());
545                 } catch (final ContactNotFoundException ex) {
546                         // Throw it again
547                         throw new FacesException(ex);
548                 }
549
550                 // Fire event
551                 this.deletedContactEvent.fire(new AdminDeletedContactEvent(this.getContact()));
552
553                 // Return to list view
554                 return "admin_list_contacts";
555         }
556
557         /**
558          * Edits currently loaded contact's data in database.
559          */
560         public void editContactData () {
561                 // Get contact instance
562                 final Contact createdContact = this.createContactInstance();
563
564                 // Check if contact instance is in helper and valid
565                 if (null == createdContact) {
566                         // Throw NPE
567                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
568                 } else if (createdContact.getContactId() == null) {
569                         // Throw NPE again
570                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N
571                 } else if (createdContact.getContactId() < 1) {
572                         // Invalid id
573                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", createdContact.getContactId())); //NOI18N
574                 }
575
576                 // Update all data in contact
577                 this.updateContactData(createdContact);
578
579                 // Init updated contact instance
580                 final Contact updatedContact;
581
582                 try {
583                         // Call EJB for updating contact data
584                         updatedContact = this.contactBean.updateContactData(createdContact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
585                 } catch (final ContactNotFoundException ex) {
586                         // Throw as a cause
587                         throw new FacesException(ex);
588                 }
589
590                 // Fire event
591                 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
592
593                 // Clear bean
594                 this.clear();
595         }
596
597         /**
598          * Returns a text representation of given mobile number or null if not set.
599          * <p>
600          * @param mobileNumber Mobile number
601          * <p>
602          * @return Text representation or null
603          */
604         public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
605                 // Is it null?
606                 if (null == mobileNumber) {
607                         // Return null
608                         return null;
609                 }
610
611                 // Get all data
612                 final String number = String.format(
613                                          "%s%d%d", //NOI18N
614                                          mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
615                                          mobileNumber.getMobileProvider().getProviderDialPrefix(),
616                                          mobileNumber.getMobileNumber()
617                          );
618
619                 // Return it
620                 return number;
621         }
622
623         /**
624          * Returns a text representation of given land-line or fax number or null if
625          * not set.
626          * <p>
627          * @param phoneNumber Land-line or fax number
628          * <p>
629          * @return Text representation or null
630          */
631         public String generatePhoneNumber (final DialableNumber phoneNumber) {
632                 // Is it null?
633                 if (null == phoneNumber) {
634                         // Return null
635                         return null;
636                 }
637
638                 // Generate it
639                 final String number = String.format(
640                                          "%s%d%d", //NOI18N
641                                          phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
642                                          phoneNumber.getPhoneAreaCode(),
643                                          phoneNumber.getPhoneNumber()
644                          );
645
646                 // Return it
647                 return number;
648         }
649
650         /**
651          * Getter for academic title
652          * <p>
653          * @return Academic title
654          */
655         public String getAcademicTitle () {
656                 return this.academicTitle;
657         }
658
659         /**
660          * Setter for academic title
661          * <p>
662          * @param academicTitle Academic title
663          */
664         public void setAcademicTitle (final String academicTitle) {
665                 this.academicTitle = academicTitle;
666         }
667
668         /**
669          * Getter for birth day
670          * <p>
671          * @return Birth day
672          */
673         @SuppressWarnings ("ReturnOfDateField")
674         public Date getBirthday () {
675                 return this.birthday;
676         }
677
678         /**
679          * Setter for birth day
680          * <p>
681          * @param birthday Birth day
682          */
683         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
684         public void setBirthday (final Date birthday) {
685                 this.birthday = birthday;
686         }
687
688         /**
689          * Getter for city name
690          * <p>
691          * @return City name
692          */
693         public String getCity () {
694                 return this.city;
695         }
696
697         /**
698          * Setter for city name
699          * <p>
700          * @param city City name
701          */
702         public void setCity (final String city) {
703                 this.city = city;
704         }
705
706         /**
707          * Getter for comments
708          * <p>
709          * @return Comments
710          */
711         public String getComment () {
712                 return this.comment;
713         }
714
715         /**
716          * Setter for comment
717          * <p>
718          * @param comment Comments
719          */
720         public void setComment (final String comment) {
721                 this.comment = comment;
722         }
723
724         /**
725          * Getter for contact instance
726          * <p>
727          * @return Contact instance
728          */
729         public Contact getContact () {
730                 return this.contact;
731         }
732
733         /**
734          * Setter for contact instance
735          * <p>
736          * @param contact Contact instance
737          */
738         public void setContact (final Contact contact) {
739                 this.contact = contact;
740         }
741
742         /**
743          * Getter for contactCountry instance
744          * <p>
745          * @return Country instance
746          */
747         public Country getContactCountry () {
748                 return this.contactCountry;
749         }
750
751         /**
752          * Setter for contactCountry instance
753          * <p>
754          * @param contactCountry Country instance
755          */
756         public void setContactCountry (final Country contactCountry) {
757                 this.contactCountry = contactCountry;
758         }
759
760         /**
761          * Getter for contact id
762          * <p>
763          * @return Contact id
764          */
765         public Long getContactId () {
766                 return this.contactId;
767         }
768
769         /**
770          * Setter for contact id
771          * <p>
772          * @param contactId Contact id
773          */
774         public void setContactId (final Long contactId) {
775                 this.contactId = contactId;
776         }
777
778         @Override
779         public String getControllerType () {
780                 return "admin"; //NOI18N
781         }
782
783         /**
784          * Getter for email address
785          * <p>
786          * @return Email address
787          */
788         public String getEmailAddress () {
789                 return this.emailAddress;
790         }
791
792         /**
793          * Setter for email address
794          * <p>
795          * @param emailAddress Email address
796          */
797         public void setEmailAddress (final String emailAddress) {
798                 this.emailAddress = emailAddress;
799         }
800
801         /**
802          * Family name
803          * <p>
804          * @return the familyName
805          */
806         public String getFamilyName () {
807                 return this.familyName;
808         }
809
810         /**
811          * Family name
812          * <p>
813          * @param familyName the familyName to set
814          */
815         public void setFamilyName (final String familyName) {
816                 this.familyName = familyName;
817         }
818
819         /**
820          * Getter for fax number's area code
821          * <p>
822          * @return Fax number's area code
823          */
824         public Integer getFaxAreaCode () {
825                 return this.faxAreaCode;
826         }
827
828         /**
829          * Setter for fax number's area code
830          * <p>
831          * @param faxAreaCode Fax number's area code
832          */
833         public void setFaxAreaCode (final Integer faxAreaCode) {
834                 this.faxAreaCode = faxAreaCode;
835         }
836
837         /**
838          * Getter for fax's country instance
839          * <p>
840          * @return Fax' country instance
841          */
842         public Country getFaxCountry () {
843                 return this.faxCountry;
844         }
845
846         /**
847          * Setter for fax's country instance
848          * <p>
849          * @param faxCountry Fax' country instance
850          */
851         public void setFaxCountry (final Country faxCountry) {
852                 this.faxCountry = faxCountry;
853         }
854
855         /**
856          * Getter for fax id
857          * <p>
858          * @return Fax id
859          */
860         public Long getFaxId () {
861                 return this.faxId;
862         }
863
864         /**
865          * Setter for fax id
866          * <p>
867          * @param faxId Fax id
868          */
869         public void setFaxId (final Long faxId) {
870                 this.faxId = faxId;
871         }
872
873         /**
874          * Getter for fax number
875          * <p>
876          * @return Fax number
877          */
878         public Long getFaxNumber () {
879                 return this.faxNumber;
880         }
881
882         /**
883          * Setter for fax number
884          * <p>
885          * @param faxNumber Fax number
886          */
887         public void setFaxNumber (final Long faxNumber) {
888                 this.faxNumber = faxNumber;
889         }
890
891         /**
892          * Getter for first name
893          * <p>
894          * @return First name
895          */
896         public String getFirstName () {
897                 return this.firstName;
898         }
899
900         /**
901          * Setter for first name
902          * <p>
903          * @param firstName First name
904          */
905         public void setFirstName (final String firstName) {
906                 this.firstName = firstName;
907         }
908
909         /**
910          * Getter for house number
911          * <p>
912          * @return House number
913          */
914         public Short getHouseNumber () {
915                 return this.houseNumber;
916         }
917
918         /**
919          * Setter for house number
920          * <p>
921          * @param houseNumber House number
922          */
923         public void setHouseNumber (final Short houseNumber) {
924                 this.houseNumber = houseNumber;
925         }
926
927         /**
928          * Getter for house number extension. Example: 123a, 'a' is the extension
929          * and 123 is the house number.
930          * <p>
931          * @return House number extension
932          */
933         public String getHouseNumberExtension () {
934                 return this.houseNumberExtension;
935         }
936
937         /**
938          * Setter for house number extension
939          * <p>
940          * @param houseNumberExtension House number extension
941          */
942         public void setHouseNumberExtension (final String houseNumberExtension) {
943                 this.houseNumberExtension = houseNumberExtension;
944         }
945
946         /**
947          * Getter for land-line number's area code
948          * <p>
949          * @return Land-line number's area code
950          */
951         public Integer getLandLineAreaCode () {
952                 return this.landLineAreaCode;
953         }
954
955         /**
956          * Setter for land-line number's area code
957          * <p>
958          * @param landLineAreaCode Land-line number's area code
959          */
960         public void setLandLineAreaCode (final Integer landLineAreaCode) {
961                 this.landLineAreaCode = landLineAreaCode;
962         }
963
964         /**
965          * Getter for land-line number's country instance
966          * <p>
967          * @return Land-line number's country instance
968          */
969         public Country getLandLineCountry () {
970                 return this.landLineCountry;
971         }
972
973         /**
974          * Setter for land-line number's country instance
975          * <p>
976          * @param landLineCountry Land-line number's country instance
977          */
978         public void setLandLineCountry (final Country landLineCountry) {
979                 this.landLineCountry = landLineCountry;
980         }
981
982         /**
983          * Getter for land-line id
984          * <p>
985          * @return Land-line id
986          */
987         public Long getLandLineId () {
988                 return this.landLineId;
989         }
990
991         /**
992          * Setter for land-line id
993          * <p>
994          * @param landLineId Land-line id
995          */
996         public void setLandLineId (final Long landLineId) {
997                 this.landLineId = landLineId;
998         }
999
1000         /**
1001          * Getter for land-line number
1002          * <p>
1003          * @return Land-line number
1004          */
1005         public Long getLandLineNumber () {
1006                 return this.landLineNumber;
1007         }
1008
1009         /**
1010          * Setter for land-line number
1011          * <p>
1012          * @param landLineNumber Land-line number
1013          */
1014         public void setLandLineNumber (final Long landLineNumber) {
1015                 this.landLineNumber = landLineNumber;
1016         }
1017
1018         /**
1019          * Getter for mobile id
1020          * <p>
1021          * @return Mobile id
1022          */
1023         public Long getMobileId () {
1024                 return this.mobileId;
1025         }
1026
1027         /**
1028          * Setter for mobile id
1029          * <p>
1030          * @param mobileId Mobile id
1031          */
1032         public void setMobileId (final Long mobileId) {
1033                 this.mobileId = mobileId;
1034         }
1035
1036         /**
1037          * Getter for mobile number
1038          * <p>
1039          * @return Mobile number
1040          */
1041         public Long getMobileNumber () {
1042                 return this.mobileNumber;
1043         }
1044
1045         /**
1046          * Setter for mobile number
1047          * <p>
1048          * @param mobileNumber Mobile number
1049          */
1050         public void setMobileNumber (final Long mobileNumber) {
1051                 this.mobileNumber = mobileNumber;
1052         }
1053
1054         /**
1055          * Getter for mobile number's carrier
1056          * <p>
1057          * @return Mobile number's carrier
1058          */
1059         public MobileProvider getMobileProvider () {
1060                 return this.mobileProvider;
1061         }
1062
1063         /**
1064          * Setter for mobile number's carrier prefix
1065          * <p>
1066          * @param mobileProvider Mobile number's carrier prefix
1067          */
1068         public void setMobileProvider (final MobileProvider mobileProvider) {
1069                 this.mobileProvider = mobileProvider;
1070         }
1071
1072         /**
1073          * Getter for personal title
1074          * <p>
1075          * @return Personal title
1076          */
1077         public PersonalTitle getPersonalTitle () {
1078                 return this.personalTitle;
1079         }
1080
1081         /**
1082          * Setter for personal title
1083          * <p>
1084          * @param personalTitle Personal title
1085          */
1086         public void setPersonalTitle (final PersonalTitle personalTitle) {
1087                 this.personalTitle = personalTitle;
1088         }
1089
1090         /**
1091          * Getter for street name
1092          * <p>
1093          * @return Street name
1094          */
1095         public String getStreet () {
1096                 return this.street;
1097         }
1098
1099         /**
1100          * Setter for street name
1101          * <p>
1102          * @param street Street name
1103          */
1104         public void setStreet (final String street) {
1105                 this.street = street;
1106         }
1107
1108         /**
1109          * Getter for ZIP code
1110          * <p>
1111          * @return ZIP code
1112          */
1113         public Integer getZipCode () {
1114                 return this.zipCode;
1115         }
1116
1117         /**
1118          * Setter for ZIP code
1119          * <p>
1120          * @param zipCode ZIP code
1121          */
1122         public void setZipCode (final Integer zipCode) {
1123                 this.zipCode = zipCode;
1124         }
1125
1126         @Override
1127         public void validateContactData () {
1128                 if (this.getPersonalTitle() == null) {
1129                         // Throw NPE again
1130                         throw new NullPointerException("contactController.personalTitle is null"); //NOI18N
1131                 } else if (this.getFirstName() == null) {
1132                         // ... and again
1133                         throw new NullPointerException("contactController.firstName is null"); //NOI18N
1134                 } else if (this.getFirstName().isEmpty()) {
1135                         // ... and again
1136                         throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1137                 } else if (this.getFamilyName() == null) {
1138                         // ... and again
1139                         throw new NullPointerException("contactController.familyName is null"); //NOI18N
1140                 } else if (this.getFamilyName().isEmpty()) {
1141                         // ... and again
1142                         throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1143                 } else if (this.getEmailAddress() == null) {
1144                         // ... and again
1145                         throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1146                 } else if (this.getEmailAddress().isEmpty()) {
1147                         // ... and again
1148                         throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1149                 }
1150         }
1151
1152         /**
1153          * Clears this bean
1154          */
1155         private void clear () {
1156                 // Clear all data
1157                 this.setContact(null);
1158
1159                 // - personal data
1160                 this.setAcademicTitle(null);
1161                 this.setFirstName(null);
1162                 this.setFamilyName(null);
1163                 this.setStreet(null);
1164                 this.setHouseNumber(null);
1165                 this.setHouseNumberExtension(null);
1166                 this.setZipCode(null);
1167                 this.setCity(null);
1168                 this.setContactCountry(null);
1169
1170                 // - contact data
1171                 this.setEmailAddress(null);
1172                 this.setLandLineCountry(null);
1173                 this.setLandLineAreaCode(null);
1174                 this.setLandLineNumber(null);
1175                 this.setMobileProvider(null);
1176                 this.setMobileNumber(null);
1177                 this.setFaxCountry(null);
1178                 this.setFaxAreaCode(null);
1179                 this.setFaxNumber(null);
1180
1181                 // - other data
1182                 this.setBirthday(null);
1183                 this.setComment(null);
1184         }
1185
1186         /**
1187          * Updates all data in contact instance.
1188          * <p>
1189          * @param contact Contact instance
1190          */
1191         private void updateContactData (final Contact contact) {
1192                 // Contact instance should be valid
1193                 if (null == contact) {
1194                         // Throw NPE
1195                         throw new NullPointerException("contact is null"); //NOI18N
1196                 } else if (contact.getContactId() == null) {
1197                         // Throw NPE again
1198                         throw new NullPointerException("contact.contactId is null"); //NOI18N
1199                 } else if (contact.getContactId() < 1) {
1200                         // Invalid id
1201                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1202                 }
1203
1204                 // Update all fields
1205                 contact.setContactPersonalTitle(this.getPersonalTitle());
1206                 contact.setContactTitle(this.getAcademicTitle());
1207                 contact.setContactFirstName(this.getFirstName());
1208                 contact.setContactFamilyName(this.getFamilyName());
1209                 contact.setContactStreet(this.getStreet());
1210                 contact.setContactHouseNumber(this.getHouseNumber());
1211                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1212                 contact.setContactZipCode(this.getZipCode());
1213                 contact.setContactCity(this.getCity());
1214                 contact.setContactCountry(this.getContactCountry());
1215
1216                 // Update contact's cmobile number
1217                 this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1218
1219                 // Update contact's land-line number
1220                 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1221
1222                 // Update contact's fax number
1223                 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
1224         }
1225
1226 }