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