]> git.mxchange.org Git - jfinancials-war.git/blob - src/java/org/mxchange/jfinancials/beans/contact/FinancialsAdminContactWebRequestBean.java
Updated copyright year
[jfinancials-war.git] / src / java / org / mxchange / jfinancials / beans / contact / FinancialsAdminContactWebRequestBean.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.jfinancials.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.jcontacts.events.contact.add.AdminAddedContactEvent;
30 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
31 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
32 import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent;
33 import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
34 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
35 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
36 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
37 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
38 import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
39 import org.mxchange.jcontacts.model.contact.Contact;
40 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
41 import org.mxchange.jcontacts.model.contact.Contacts;
42 import org.mxchange.jcontacts.model.contact.UserContact;
43 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
44 import org.mxchange.jcountry.model.data.Country;
45 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
46 import org.mxchange.jfinancials.beans.contact.list.FinancialsContactListWebViewController;
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 FinancialsAdminContactWebRequestBean extends BaseFinancialsBean implements FinancialsAdminContactWebRequestController {
64
65         /**
66          * Serial number
67          */
68         private static final long serialVersionUID = 542_145_347_916L;
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/jfinancials-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/jfinancials-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 FinancialsContactListWebViewController 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 cmobile 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 FinancialsAdminContactWebRequestBean () {
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                 }
409
410                 // Generate phone number
411                 DialableLandLineNumber landLine = null;
412                 DialableMobileNumber mobile = null;
413                 DialableFaxNumber fax = null;
414
415                 // Are all fields set?
416                 if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
417                         // Init instance
418                         landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
419                 }
420
421                 // Are all fields set?
422                 if (this.getMobileProvider() instanceof MobileProvider && this.getMobileNumber() != null) {
423                         // Initialize instance
424                         mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
425                 }
426
427                 // Are all fields set?
428                 if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
429                         // Initialize instance
430                         fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
431                 }
432
433                 // Create new instance
434                 final Contact localContact = new UserContact(
435                                           this.getPersonalTitle(),
436                                           this.getFirstName(),
437                                           this.getFamilyName()
438                           );
439
440                 // Add all others
441                 localContact.setContactBirthday(this.getBirthday());
442                 localContact.setContactCity(this.getCity());
443                 localContact.setContactComment(this.getComment());
444                 localContact.setContactCountry(this.getContactCountry());
445                 localContact.setContactEmailAddress(this.getEmailAddress());
446                 localContact.setContactHouseNumber(this.getHouseNumber());
447                 localContact.setContactId(this.getContactId());
448                 localContact.setContactStreet(this.getStreet());
449                 localContact.setContactTitle(this.getAcademicTitle());
450                 localContact.setContactZipCode(this.getZipCode());
451
452                 // Set ownContact
453                 localContact.setContactOwnContact(Boolean.TRUE);
454
455                 // Don't set null or wrong references
456                 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
457                         // Now the number must be given
458                         if (landLine.getPhoneAreaCode() == null) {
459                                 // Is null
460                                 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
461                         } else if (landLine.getPhoneAreaCode() < 1) {
462                                 // Abort here
463                                 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
464                         } else if (landLine.getPhoneNumber() == null) {
465                                 // Is null
466                                 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
467                         } else if (landLine.getPhoneNumber() < 1) {
468                                 // Abort here
469                                 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
470                         }
471
472                         // Set phone number
473                         localContact.setContactLandLineNumber(landLine);
474                 }
475
476                 // Don't set null or wrong references
477                 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
478                         // Now the number must be given
479                         if (fax.getPhoneAreaCode() == null) {
480                                 // Is null
481                                 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
482                         } else if (fax.getPhoneAreaCode() < 1) {
483                                 // Abort here
484                                 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
485                         } else if (fax.getPhoneNumber() == null) {
486                                 // Is null
487                                 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
488                         } else if (fax.getPhoneNumber() < 1) {
489                                 // Abort here
490                                 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
491                         }
492
493                         // Set fax number
494                         localContact.setContactFaxNumber(fax);
495                 }
496
497                 // Is the provider set?
498                 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
499                         // Is the number set?
500                         if (mobile.getMobileNumber() == null) {
501                                 // Is null
502                                 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
503                         } else if (mobile.getMobileNumber() < 1) {
504                                 // Abort here
505                                 throw new IllegalArgumentException("cmobile.phoneNumber is zero or below."); //NOI18N
506                         }
507
508                         // Set cmobile number
509                         localContact.setContactMobileNumber(mobile);
510                 }
511
512                 // Return it
513                 return localContact;
514         }
515
516         /**
517          * Deletes currently chosen contact and returns to list view
518          *
519          * @return
520          */
521         public String deleteContactData () {
522                 // Is contact set?
523                 if (this.getContact() == null) {
524                         // Throw NPE
525                         throw new NullPointerException("this.contact is null");
526                 } else if (this.getContact().getContactId() == null) {
527                         // Throw NPE again
528                         throw new NullPointerException("this.contact.contactId is null");
529                 } else if (this.getContact().getContactId() < 1) {
530                         // Throw IAE
531                         throw new NullPointerException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId()));
532                 }
533
534                 try {
535                         // Invoke EJB
536                         this.adminContactBean.deleteContactData(this.getContact());
537                 } catch (final ContactNotFoundException ex) {
538                         // Throw it again
539                         throw new FacesException(ex);
540                 }
541
542                 // Fire event
543                 this.deletedContactEvent.fire(new AdminDeletedContactEvent(this.getContact()));
544
545                 // Return to list view
546                 return "admin_list_contacts";
547         }
548
549         /**
550          * Edits currently loaded contact's data in database.
551          */
552         public void editContactData () {
553                 // Get contact instance
554                 final Contact createdContact = this.createContactInstance();
555
556                 // Check if contact instance is in helper and valid
557                 if (null == createdContact) {
558                         // Throw NPE
559                         throw new NullPointerException("beanHelper.contact is null"); //NOI18N
560                 } else if (createdContact.getContactId() == null) {
561                         // Throw NPE again
562                         throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N
563                 } else if (createdContact.getContactId() < 1) {
564                         // Invalid id
565                         throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", createdContact.getContactId())); //NOI18N
566                 }
567
568                 // Update all data in contact
569                 this.updateContactData(createdContact);
570
571                 // Init updated contact instance
572                 final Contact updatedContact;
573
574                 try {
575                         // Call EJB for updating contact data
576                         updatedContact = this.contactBean.updateContactData(createdContact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
577                 } catch (final ContactNotFoundException ex) {
578                         // Throw as a cause
579                         throw new FacesException(ex);
580                 }
581
582                 // Fire event
583                 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
584
585                 // Clear bean
586                 this.clear();
587         }
588
589         /**
590          * Returns a text representation of given mobile number or null if not set.
591          * <p>
592          * @param mobileNumber Mobile number
593          * <p>
594          * @return Text representation or null
595          */
596         public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
597                 // Is it null?
598                 if (null == mobileNumber) {
599                         // Return null
600                         return null;
601                 }
602
603                 // Get all data
604                 final String number = String.format(
605                                          "%s%d%d", //NOI18N
606                                          mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
607                                          mobileNumber.getMobileProvider().getProviderDialPrefix(),
608                                          mobileNumber.getMobileNumber()
609                          );
610
611                 // Return it
612                 return number;
613         }
614
615         /**
616          * Returns a text representation of given land-line or fax number or null if
617          * not set.
618          * <p>
619          * @param phoneNumber Land-line or fax number
620          * <p>
621          * @return Text representation or null
622          */
623         public String generatePhoneNumber (final DialableNumber phoneNumber) {
624                 // Is it null?
625                 if (null == phoneNumber) {
626                         // Return null
627                         return null;
628                 }
629
630                 // Generate it
631                 final String number = String.format(
632                                          "%s%d%d", //NOI18N
633                                          phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
634                                          phoneNumber.getPhoneAreaCode(),
635                                          phoneNumber.getPhoneNumber()
636                          );
637
638                 // Return it
639                 return number;
640         }
641
642         /**
643          * Getter for academic title
644          * <p>
645          * @return Academic title
646          */
647         public String getAcademicTitle () {
648                 return this.academicTitle;
649         }
650
651         /**
652          * Setter for academic title
653          * <p>
654          * @param academicTitle Academic title
655          */
656         public void setAcademicTitle (final String academicTitle) {
657                 this.academicTitle = academicTitle;
658         }
659
660         /**
661          * Getter for birth day
662          * <p>
663          * @return Birth day
664          */
665         @SuppressWarnings ("ReturnOfDateField")
666         public Date getBirthday () {
667                 return this.birthday;
668         }
669
670         /**
671          * Setter for birth day
672          * <p>
673          * @param birthday Birth day
674          */
675         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
676         public void setBirthday (final Date birthday) {
677                 this.birthday = birthday;
678         }
679
680         /**
681          * Getter for city name
682          * <p>
683          * @return City name
684          */
685         public String getCity () {
686                 return this.city;
687         }
688
689         /**
690          * Setter for city name
691          * <p>
692          * @param city City name
693          */
694         public void setCity (final String city) {
695                 this.city = city;
696         }
697
698         /**
699          * Getter for comments
700          * <p>
701          * @return Comments
702          */
703         public String getComment () {
704                 return this.comment;
705         }
706
707         /**
708          * Setter for comment
709          * <p>
710          * @param comment Comments
711          */
712         public void setComment (final String comment) {
713                 this.comment = comment;
714         }
715
716         /**
717          * Getter for contact instance
718          * <p>
719          * @return Contact instance
720          */
721         public Contact getContact () {
722                 return this.contact;
723         }
724
725         /**
726          * Setter for contact instance
727          * <p>
728          * @param contact Contact instance
729          */
730         public void setContact (final Contact contact) {
731                 this.contact = contact;
732         }
733
734         /**
735          * Getter for contactCountry instance
736          * <p>
737          * @return Country instance
738          */
739         public Country getContactCountry () {
740                 return this.contactCountry;
741         }
742
743         /**
744          * Setter for contactCountry instance
745          * <p>
746          * @param contactCountry Country instance
747          */
748         public void setContactCountry (final Country contactCountry) {
749                 this.contactCountry = contactCountry;
750         }
751
752         /**
753          * Getter for contact id
754          * <p>
755          * @return Contact id
756          */
757         public Long getContactId () {
758                 return this.contactId;
759         }
760
761         /**
762          * Setter for contact id
763          * <p>
764          * @param contactId Contact id
765          */
766         public void setContactId (final Long contactId) {
767                 this.contactId = contactId;
768         }
769
770         @Override
771         public String getControllerType () {
772                 return "admin"; //NOI18N
773         }
774
775         /**
776          * Getter for email address
777          * <p>
778          * @return Email address
779          */
780         public String getEmailAddress () {
781                 return this.emailAddress;
782         }
783
784         /**
785          * Setter for email address
786          * <p>
787          * @param emailAddress Email address
788          */
789         public void setEmailAddress (final String emailAddress) {
790                 this.emailAddress = emailAddress;
791         }
792
793         /**
794          * Family name
795          * <p>
796          * @return the familyName
797          */
798         public String getFamilyName () {
799                 return this.familyName;
800         }
801
802         /**
803          * Family name
804          * <p>
805          * @param familyName the familyName to set
806          */
807         public void setFamilyName (final String familyName) {
808                 this.familyName = familyName;
809         }
810
811         /**
812          * Getter for fax number's area code
813          * <p>
814          * @return Fax number's area code
815          */
816         public Integer getFaxAreaCode () {
817                 return this.faxAreaCode;
818         }
819
820         /**
821          * Setter for fax number's area code
822          * <p>
823          * @param faxAreaCode Fax number's area code
824          */
825         public void setFaxAreaCode (final Integer faxAreaCode) {
826                 this.faxAreaCode = faxAreaCode;
827         }
828
829         /**
830          * Getter for fax's country instance
831          * <p>
832          * @return Fax' country instance
833          */
834         public Country getFaxCountry () {
835                 return this.faxCountry;
836         }
837
838         /**
839          * Setter for fax's country instance
840          * <p>
841          * @param faxCountry Fax' country instance
842          */
843         public void setFaxCountry (final Country faxCountry) {
844                 this.faxCountry = faxCountry;
845         }
846
847         /**
848          * Getter for fax id
849          * <p>
850          * @return Fax id
851          */
852         public Long getFaxId () {
853                 return this.faxId;
854         }
855
856         /**
857          * Setter for fax id
858          * <p>
859          * @param faxId Fax id
860          */
861         public void setFaxId (final Long faxId) {
862                 this.faxId = faxId;
863         }
864
865         /**
866          * Getter for fax number
867          * <p>
868          * @return Fax number
869          */
870         public Long getFaxNumber () {
871                 return this.faxNumber;
872         }
873
874         /**
875          * Setter for fax number
876          * <p>
877          * @param faxNumber Fax number
878          */
879         public void setFaxNumber (final Long faxNumber) {
880                 this.faxNumber = faxNumber;
881         }
882
883         /**
884          * Getter for first name
885          * <p>
886          * @return First name
887          */
888         public String getFirstName () {
889                 return this.firstName;
890         }
891
892         /**
893          * Setter for first name
894          * <p>
895          * @param firstName First name
896          */
897         public void setFirstName (final String firstName) {
898                 this.firstName = firstName;
899         }
900
901         /**
902          * Getter for house number
903          * <p>
904          * @return House number
905          */
906         public Short getHouseNumber () {
907                 return this.houseNumber;
908         }
909
910         /**
911          * Setter for house number
912          * <p>
913          * @param houseNumber House number
914          */
915         public void setHouseNumber (final Short houseNumber) {
916                 this.houseNumber = houseNumber;
917         }
918
919         /**
920          * Getter for house number extension. Example: 123a, 'a' is the extension
921          * and 123 is the house number.
922          * <p>
923          * @return House number extension
924          */
925         public String getHouseNumberExtension () {
926                 return this.houseNumberExtension;
927         }
928
929         /**
930          * Setter for house number extension
931          * <p>
932          * @param houseNumberExtension House number extension
933          */
934         public void setHouseNumberExtension (final String houseNumberExtension) {
935                 this.houseNumberExtension = houseNumberExtension;
936         }
937
938         /**
939          * Getter for land-line number's area code
940          * <p>
941          * @return Land-line number's area code
942          */
943         public Integer getLandLineAreaCode () {
944                 return this.landLineAreaCode;
945         }
946
947         /**
948          * Setter for land-line number's area code
949          * <p>
950          * @param landLineAreaCode Land-line number's area code
951          */
952         public void setLandLineAreaCode (final Integer landLineAreaCode) {
953                 this.landLineAreaCode = landLineAreaCode;
954         }
955
956         /**
957          * Getter for land-line number's country instance
958          * <p>
959          * @return Land-line number's country instance
960          */
961         public Country getLandLineCountry () {
962                 return this.landLineCountry;
963         }
964
965         /**
966          * Setter for land-line number's country instance
967          * <p>
968          * @param landLineCountry Land-line number's country instance
969          */
970         public void setLandLineCountry (final Country landLineCountry) {
971                 this.landLineCountry = landLineCountry;
972         }
973
974         /**
975          * Getter for land-line id
976          * <p>
977          * @return Land-line id
978          */
979         public Long getLandLineId () {
980                 return this.landLineId;
981         }
982
983         /**
984          * Setter for land-line id
985          * <p>
986          * @param landLineId Land-line id
987          */
988         public void setLandLineId (final Long landLineId) {
989                 this.landLineId = landLineId;
990         }
991
992         /**
993          * Getter for land-line number
994          * <p>
995          * @return Land-line number
996          */
997         public Long getLandLineNumber () {
998                 return this.landLineNumber;
999         }
1000
1001         /**
1002          * Setter for land-line number
1003          * <p>
1004          * @param landLineNumber Land-line number
1005          */
1006         public void setLandLineNumber (final Long landLineNumber) {
1007                 this.landLineNumber = landLineNumber;
1008         }
1009
1010         /**
1011          * Getter for mobile id
1012          * <p>
1013          * @return Mobile id
1014          */
1015         public Long getMobileId () {
1016                 return this.mobileId;
1017         }
1018
1019         /**
1020          * Setter for mobile id
1021          * <p>
1022          * @param mobileId Mobile id
1023          */
1024         public void setMobileId (final Long mobileId) {
1025                 this.mobileId = mobileId;
1026         }
1027
1028         /**
1029          * Getter for mobile number
1030          * <p>
1031          * @return Mobile number
1032          */
1033         public Long getMobileNumber () {
1034                 return this.mobileNumber;
1035         }
1036
1037         /**
1038          * Setter for mobile number
1039          * <p>
1040          * @param mobileNumber Mobile number
1041          */
1042         public void setMobileNumber (final Long mobileNumber) {
1043                 this.mobileNumber = mobileNumber;
1044         }
1045
1046         /**
1047          * Getter for mobile number's carrier
1048          * <p>
1049          * @return Mobile number's carrier
1050          */
1051         public MobileProvider getMobileProvider () {
1052                 return this.mobileProvider;
1053         }
1054
1055         /**
1056          * Setter for mobile number's carrier prefix
1057          * <p>
1058          * @param mobileProvider Mobile number's carrier prefix
1059          */
1060         public void setMobileProvider (final MobileProvider mobileProvider) {
1061                 this.mobileProvider = mobileProvider;
1062         }
1063
1064         /**
1065          * Getter for personal title
1066          * <p>
1067          * @return Personal title
1068          */
1069         public PersonalTitle getPersonalTitle () {
1070                 return this.personalTitle;
1071         }
1072
1073         /**
1074          * Setter for personal title
1075          * <p>
1076          * @param personalTitle Personal title
1077          */
1078         public void setPersonalTitle (final PersonalTitle personalTitle) {
1079                 this.personalTitle = personalTitle;
1080         }
1081
1082         /**
1083          * Getter for street name
1084          * <p>
1085          * @return Street name
1086          */
1087         public String getStreet () {
1088                 return this.street;
1089         }
1090
1091         /**
1092          * Setter for street name
1093          * <p>
1094          * @param street Street name
1095          */
1096         public void setStreet (final String street) {
1097                 this.street = street;
1098         }
1099
1100         /**
1101          * Getter for ZIP code
1102          * <p>
1103          * @return ZIP code
1104          */
1105         public Integer getZipCode () {
1106                 return this.zipCode;
1107         }
1108
1109         /**
1110          * Setter for ZIP code
1111          * <p>
1112          * @param zipCode ZIP code
1113          */
1114         public void setZipCode (final Integer zipCode) {
1115                 this.zipCode = zipCode;
1116         }
1117
1118         @Override
1119         public void validateContactData () {
1120                 if (this.getPersonalTitle() == null) {
1121                         // Throw NPE again
1122                         throw new NullPointerException("contactController.gender is null"); //NOI18N
1123                 } else if (this.getFirstName() == null) {
1124                         // ... and again
1125                         throw new NullPointerException("contactController.firstName is null"); //NOI18N
1126                 } else if (this.getFirstName().isEmpty()) {
1127                         // ... and again
1128                         throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1129                 } else if (this.getFamilyName() == null) {
1130                         // ... and again
1131                         throw new NullPointerException("contactController.familyName is null"); //NOI18N
1132                 } else if (this.getFamilyName().isEmpty()) {
1133                         // ... and again
1134                         throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1135                 } else if (this.getEmailAddress() == null) {
1136                         // ... and again
1137                         throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1138                 } else if (this.getEmailAddress().isEmpty()) {
1139                         // ... and again
1140                         throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1141                 }
1142         }
1143
1144         /**
1145          * Clears this bean
1146          */
1147         private void clear () {
1148                 // Clear all data
1149                 this.setContact(null);
1150
1151                 // - personal data
1152                 this.setAcademicTitle(null);
1153                 this.setFirstName(null);
1154                 this.setFamilyName(null);
1155                 this.setStreet(null);
1156                 this.setHouseNumber(null);
1157                 this.setHouseNumberExtension(null);
1158                 this.setZipCode(null);
1159                 this.setCity(null);
1160                 this.setContactCountry(null);
1161
1162                 // - contact data
1163                 this.setEmailAddress(null);
1164                 this.setLandLineCountry(null);
1165                 this.setLandLineAreaCode(null);
1166                 this.setLandLineNumber(null);
1167                 this.setMobileProvider(null);
1168                 this.setMobileNumber(null);
1169                 this.setFaxCountry(null);
1170                 this.setFaxAreaCode(null);
1171                 this.setFaxNumber(null);
1172
1173                 // - other data
1174                 this.setBirthday(null);
1175                 this.setComment(null);
1176         }
1177
1178         /**
1179          * Updates all data in contact instance.
1180          * <p>
1181          * @param contact Contact instance
1182          */
1183         private void updateContactData (final Contact contact) {
1184                 // Contact instance should be valid
1185                 if (null == contact) {
1186                         // Throw NPE
1187                         throw new NullPointerException("contact is null"); //NOI18N
1188                 } else if (contact.getContactId() == null) {
1189                         // Throw NPE again
1190                         throw new NullPointerException("contact.contactId is null"); //NOI18N
1191                 } else if (contact.getContactId() < 1) {
1192                         // Invalid id
1193                         throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1194                 }
1195
1196                 // Update all fields
1197                 contact.setContactPersonalTitle(this.getPersonalTitle());
1198                 contact.setContactTitle(this.getAcademicTitle());
1199                 contact.setContactFirstName(this.getFirstName());
1200                 contact.setContactFamilyName(this.getFamilyName());
1201                 contact.setContactStreet(this.getStreet());
1202                 contact.setContactHouseNumber(this.getHouseNumber());
1203                 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1204                 contact.setContactZipCode(this.getZipCode());
1205                 contact.setContactCity(this.getCity());
1206                 contact.setContactCountry(this.getContactCountry());
1207
1208                 // Update contact's cmobile number
1209                 this.isMobileNumberUnlinked = Contacts.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1210
1211                 // Update contact's land-line number
1212                 this.isLandLineUnlinked = Contacts.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1213
1214                 // Update contact's fax number
1215                 this.isFaxUnlinked = Contacts.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
1216         }
1217
1218 }