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