2 * Copyright (C) 2016 - 2024 Free Software Foundation
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.
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.
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/>.
17 package org.mxchange.addressbook.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Date;
22 import javax.enterprise.context.RequestScoped;
23 import javax.enterprise.event.Event;
24 import javax.enterprise.event.Observes;
25 import javax.enterprise.inject.Any;
26 import javax.faces.FacesException;
27 import javax.inject.Inject;
28 import javax.inject.Named;
29 import org.mxchange.addressbook.beans.BaseAddressbookBean;
30 import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
31 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
32 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
33 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
34 import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent;
35 import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
36 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
37 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
38 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
39 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
40 import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
41 import org.mxchange.jcontacts.model.contact.Contact;
42 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
43 import org.mxchange.jcontacts.model.contact.UserContact;
44 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
45 import org.mxchange.jcontacts.model.utils.ContactUtils;
46 import org.mxchange.jcountry.model.data.Country;
47 import org.mxchange.jphone.model.phonenumbers.DialableNumber;
48 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
49 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
50 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
51 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
52 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
53 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
54 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
57 * An administrative user bean (controller)
59 * @author Roland Häder<roland@mxchange.org>
61 @Named ("adminContactController")
63 public class AddressbookAdminContactWebRequestBean extends BaseAddressbookBean implements AddressbookAdminContactWebRequestController {
68 private static final long serialVersionUID = 542_145_351_001L;
71 * Academic academicTitle
73 private String academicTitle;
76 * An event fired when the administrator has added a new contact
80 private Event<ObservableAdminAddedContactEvent> addedContactEvent;
83 * Administrative contact EJB
85 @EJB (lookup = "java:global/addressbook-ejb/adminContact!org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote")
86 private AdminContactSessionBeanRemote adminContactBean;
91 private Date birthday;
101 private String comment;
104 * Current contact instance
106 private Contact contact;
109 * EJB for general contact purposes
111 @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
112 private ContactSessionBeanRemote contactBean;
117 private Country contactCountry;
122 private Long contactId;
125 * An instance of a contact list controller
128 private AddressbookContactListWebViewController contactListController;
131 * Event being fired when an administrator has deleted a contact
135 private Event<ObservableAdminDeletedContactEvent> deletedContactEvent;
140 private String emailAddress;
145 private String familyName;
148 * Fax number's area code
150 private Integer faxAreaCode;
153 * Country instance for fax number
155 private Country faxCountry;
165 private Long faxNumber;
170 private String firstName;
175 private Short houseNumber;
178 * House number extension
180 private String houseNumberExtension;
183 * Whether a fax entry has been unlinked
185 private boolean isFaxUnlinked;
188 * Whether a land-line number has been unlinked
190 private boolean isLandLineUnlinked;
193 * Whether a mobile entry has been unlinked
195 private boolean isMobileNumberUnlinked;
198 * Phone number area code
200 private Integer landLineAreaCode;
203 * Country instance for phone number
205 private Country landLineCountry;
208 * Land-line id number
210 private Long landLineId;
215 private Long landLineNumber;
220 private Long mobileId;
225 private Long mobileNumber;
228 * Mobile number's provider
230 private MobileProvider mobileProvider;
233 * PersonalTitle instance
235 private PersonalTitle personalTitle;
240 private String street;
243 * An event fired when the administrator has updated contact data
247 private Event<ObservableAdminUpdatedContactEvent> updatedContactEvent;
252 private Integer zipCode;
255 * Default constructor
257 public AddressbookAdminContactWebRequestBean () {
258 // Call super constructor
263 * Adds contact data to database and redirects on success. If the contact is
264 * already found, a proper exception is thrown.
266 public void addContact () {
267 // Are all minimum fields set?
268 if (this.getPersonalTitle() == null) {
270 throw new NullPointerException("personalTitle is null"); //NOI18N
271 } else if (this.getFirstName() == null) {
273 throw new NullPointerException("firstName is null"); //NOI18N
274 } else if (this.getFirstName().isEmpty()) {
276 throw new IllegalStateException("firstName is empty"); //NOI18N
277 } else if (this.getFamilyName() == null) {
279 throw new NullPointerException("familyName is null"); //NOI18N
280 } else if (this.getFamilyName().isEmpty()) {
282 throw new IllegalStateException("familyName is empty"); //NOI18N
285 // Create new contact instance
286 final Contact createdContact = this.createContactInstance();
288 // Default is not same contact
289 if (this.contactListController.isContactFound(createdContact)) {
290 // Already registered
291 throw new FacesException(new ContactAlreadyAddedException(createdContact));
295 final Contact updatedContact;
300 updatedContact = this.adminContactBean.addContact(createdContact);
301 } catch (final ContactAlreadyAddedException ex) {
303 throw new FacesException(ex);
307 this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
314 * Observer for events being fired when a bean helper has successfully
315 * created a contact instance.
317 * @param event Event being fired
319 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
321 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
323 // The event instance must be valid
326 throw new NullPointerException("event is null"); //NOI18N
327 } else if (event.getCreatedContact() == null) {
329 throw new NullPointerException("event.createdContact is null"); //NOI18N
330 } else if (event.getCreatedContact().getContactId() == null) {
332 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N
333 } else if (event.getCreatedContact().getContactId() < 1) {
335 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
338 // Set contact for e.g. delete method
339 this.setContact(event.getCreatedContact());
341 // Get contact instance from event
342 final Contact createdContact = event.getCreatedContact();
344 // Set all fields: contact
345 this.setContactId(createdContact.getContactId());
346 this.setAcademicTitle(createdContact.getContactTitle());
347 this.setBirthday(createdContact.getContactBirthday());
348 this.setCity(createdContact.getContactCity());
349 this.setComment(createdContact.getContactComment());
350 this.setContactCountry(createdContact.getContactCountry());
351 this.setEmailAddress(createdContact.getContactEmailAddress());
352 this.setFamilyName(createdContact.getContactFamilyName());
353 this.setFirstName(createdContact.getContactFirstName());
354 this.setPersonalTitle(createdContact.getContactPersonalTitle());
355 this.setHouseNumber(createdContact.getContactHouseNumber());
356 this.setHouseNumberExtension(createdContact.getContactHouseNumberExtension());
357 this.setStreet(createdContact.getContactStreet());
358 this.setZipCode(createdContact.getContactZipCode());
360 // Is the cell phone set?
361 if (createdContact.getContactMobileNumber() instanceof DialableMobileNumber) {
363 this.setMobileId(createdContact.getContactMobileNumber().getMobileId());
364 this.setMobileProvider(createdContact.getContactMobileNumber().getMobileProvider());
365 this.setMobileNumber(createdContact.getContactMobileNumber().getMobileNumber());
369 if (createdContact.getContactFaxNumber() instanceof DialableFaxNumber) {
371 this.setFaxId(createdContact.getContactFaxNumber().getPhoneId());
372 this.setFaxAreaCode(createdContact.getContactFaxNumber().getPhoneAreaCode());
373 this.setFaxCountry(createdContact.getContactFaxNumber().getPhoneCountry());
374 this.setFaxNumber(createdContact.getContactFaxNumber().getPhoneNumber());
377 // Is the land-line number set?
378 if (createdContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
380 this.setLandLineId(createdContact.getContactLandLineNumber().getPhoneId());
381 this.setLandLineAreaCode(createdContact.getContactLandLineNumber().getPhoneAreaCode());
382 this.setLandLineCountry(createdContact.getContactLandLineNumber().getPhoneCountry());
383 this.setLandLineNumber(createdContact.getContactLandLineNumber().getPhoneNumber());
387 //* NOISY-DEBUG: */ System.out.println("AdminContactController::afterCreatedContactEvent(): EXIT!"); //NOI18N
391 public Contact createContactInstance () {
392 // Are all minimum fields set?
393 if (this.getPersonalTitle() == null) {
395 throw new NullPointerException("personalTitle is null"); //NOI18N
396 } else if (this.getFirstName() == null) {
398 throw new NullPointerException("firstName is null"); //NOI18N
399 } else if (this.getFirstName().isEmpty()) {
401 throw new IllegalStateException("firstName is empty"); //NOI18N
402 } else if (this.getFamilyName() == null) {
404 throw new NullPointerException("familyName is null"); //NOI18N
405 } else if (this.getFamilyName().isEmpty()) {
407 throw new IllegalStateException("familyName is empty"); //NOI18N
408 } else if (this.getContactCountry() == null) {
410 throw new NullPointerException("contactCountry is null"); //NOI18N
411 } else if (this.getContactCountry().getCountryId() == null) {
413 throw new NullPointerException("contactCountry.countryId is null"); //NOI18N
414 } else if (this.getContactCountry().getCountryId() < 1) {
416 throw new IllegalArgumentException(MessageFormat.format("contactCountry.countryId={0} is invalid", this.getContactCountry().getCountryId())); //NOI18N
419 // Generate phone number
420 DialableLandLineNumber landLine = null;
421 DialableMobileNumber mobile = null;
422 DialableFaxNumber fax = null;
424 // Are all fields set?
425 if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
427 landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
430 // Are all fields set?
431 if (this.getMobileProvider() instanceof MobileProvider && this.getMobileNumber() != null) {
432 // Initialize instance
433 mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
436 // Are all fields set?
437 if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
438 // Initialize instance
439 fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
442 // Create new instance
443 final Contact localContact = new UserContact(
444 this.getPersonalTitle(),
446 this.getFamilyName(),
447 this.getContactCountry(),
450 this.getHouseNumber(),
451 this.getHouseNumberExtension(),
454 this.getEmailAddress(),
455 this.getAcademicTitle(),
460 // Add missing fields
461 localContact.setContactId(this.getContactId());
463 // Don't set null or wrong references
464 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
465 // Now the number must be given
466 if (landLine.getPhoneAreaCode() == null) {
468 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
469 } else if (landLine.getPhoneAreaCode() < 1) {
471 throw new IllegalStateException("phone.phoneAreaCode is zero or below."); //NOI18N
472 } else if (landLine.getPhoneNumber() == null) {
474 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
475 } else if (landLine.getPhoneNumber() < 1) {
477 throw new IllegalStateException("phone.phoneNumber is zero or below."); //NOI18N
481 localContact.setContactLandLineNumber(landLine);
484 // Don't set null or wrong references
485 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
486 // Now the number must be given
487 if (fax.getPhoneAreaCode() == null) {
489 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
490 } else if (fax.getPhoneAreaCode() < 1) {
492 throw new IllegalStateException("fax.phoneAreaCode is zero or below."); //NOI18N
493 } else if (fax.getPhoneNumber() == null) {
495 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
496 } else if (fax.getPhoneNumber() < 1) {
498 throw new IllegalStateException("fax.phoneNumber is zero or below."); //NOI18N
502 localContact.setContactFaxNumber(fax);
505 // Is the provider set?
506 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
507 // Is the number set?
508 if (mobile.getMobileNumber() == null) {
510 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
511 } else if (mobile.getMobileNumber() < 1) {
513 throw new IllegalStateException("cmobile.phoneNumber is zero or below."); //NOI18N
516 // Set cmobile number
517 localContact.setContactMobileNumber(mobile);
525 * Deletes currently chosen contact and returns to list view
529 public String deleteContactData () {
531 if (this.getContact() == null) {
533 throw new NullPointerException("this.contact is null");
534 } else if (this.getContact().getContactId() == null) {
536 throw new NullPointerException("this.contact.contactId is null");
537 } else if (this.getContact().getContactId() < 1) {
539 throw new NullPointerException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId()));
544 this.adminContactBean.deleteContactData(this.getContact());
545 } catch (final ContactNotFoundException ex) {
547 throw new FacesException(ex);
551 this.deletedContactEvent.fire(new AdminDeletedContactEvent(this.getContact()));
553 // Return to list view
554 return "admin_list_contacts";
558 * Edits currently loaded contact's data in database.
560 public void editContactData () {
561 // Get contact instance
562 final Contact createdContact = this.createContactInstance();
564 // Check if contact instance is in helper and valid
565 if (null == createdContact) {
567 throw new NullPointerException("beanHelper.contact is null"); //NOI18N
568 } else if (createdContact.getContactId() == null) {
570 throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N
571 } else if (createdContact.getContactId() < 1) {
573 throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", createdContact.getContactId())); //NOI18N
576 // Update all data in contact
577 this.updateContactData(createdContact);
579 // Init updated contact instance
580 final Contact updatedContact;
583 // Call EJB for updating contact data
584 updatedContact = this.contactBean.updateContactData(createdContact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
585 } catch (final ContactNotFoundException ex) {
587 throw new FacesException(ex);
591 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
598 * Returns a text representation of given mobile number or null if not set.
600 * @param mobileNumber Mobile number
602 * @return Text representation or null
604 public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
606 if (null == mobileNumber) {
612 final String number = String.format(
614 mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
615 mobileNumber.getMobileProvider().getProviderDialPrefix(),
616 mobileNumber.getMobileNumber()
624 * Returns a text representation of given land-line or fax number or null if
627 * @param phoneNumber Land-line or fax number
629 * @return Text representation or null
631 public String generatePhoneNumber (final DialableNumber phoneNumber) {
633 if (null == phoneNumber) {
639 final String number = String.format(
641 phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
642 phoneNumber.getPhoneAreaCode(),
643 phoneNumber.getPhoneNumber()
651 * Getter for academic title
653 * @return Academic title
655 public String getAcademicTitle () {
656 return this.academicTitle;
660 * Setter for academic title
662 * @param academicTitle Academic title
664 public void setAcademicTitle (final String academicTitle) {
665 this.academicTitle = academicTitle;
669 * Getter for birth day
673 @SuppressWarnings ("ReturnOfDateField")
674 public Date getBirthday () {
675 return this.birthday;
679 * Setter for birth day
681 * @param birthday Birth day
683 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
684 public void setBirthday (final Date birthday) {
685 this.birthday = birthday;
689 * Getter for city name
693 public String getCity () {
698 * Setter for city name
700 * @param city City name
702 public void setCity (final String city) {
707 * Getter for comments
711 public String getComment () {
718 * @param comment Comments
720 public void setComment (final String comment) {
721 this.comment = comment;
725 * Getter for contact instance
727 * @return Contact instance
729 public Contact getContact () {
734 * Setter for contact instance
736 * @param contact Contact instance
738 public void setContact (final Contact contact) {
739 this.contact = contact;
743 * Getter for contactCountry instance
745 * @return Country instance
747 public Country getContactCountry () {
748 return this.contactCountry;
752 * Setter for contactCountry instance
754 * @param contactCountry Country instance
756 public void setContactCountry (final Country contactCountry) {
757 this.contactCountry = contactCountry;
761 * Getter for contact id
765 public Long getContactId () {
766 return this.contactId;
770 * Setter for contact id
772 * @param contactId Contact id
774 public void setContactId (final Long contactId) {
775 this.contactId = contactId;
779 public String getControllerType () {
780 return "admin"; //NOI18N
784 * Getter for email address
786 * @return Email address
788 public String getEmailAddress () {
789 return this.emailAddress;
793 * Setter for email address
795 * @param emailAddress Email address
797 public void setEmailAddress (final String emailAddress) {
798 this.emailAddress = emailAddress;
804 * @return the familyName
806 public String getFamilyName () {
807 return this.familyName;
813 * @param familyName the familyName to set
815 public void setFamilyName (final String familyName) {
816 this.familyName = familyName;
820 * Getter for fax number's area code
822 * @return Fax number's area code
824 public Integer getFaxAreaCode () {
825 return this.faxAreaCode;
829 * Setter for fax number's area code
831 * @param faxAreaCode Fax number's area code
833 public void setFaxAreaCode (final Integer faxAreaCode) {
834 this.faxAreaCode = faxAreaCode;
838 * Getter for fax's country instance
840 * @return Fax' country instance
842 public Country getFaxCountry () {
843 return this.faxCountry;
847 * Setter for fax's country instance
849 * @param faxCountry Fax' country instance
851 public void setFaxCountry (final Country faxCountry) {
852 this.faxCountry = faxCountry;
860 public Long getFaxId () {
867 * @param faxId Fax id
869 public void setFaxId (final Long faxId) {
874 * Getter for fax number
878 public Long getFaxNumber () {
879 return this.faxNumber;
883 * Setter for fax number
885 * @param faxNumber Fax number
887 public void setFaxNumber (final Long faxNumber) {
888 this.faxNumber = faxNumber;
892 * Getter for first name
896 public String getFirstName () {
897 return this.firstName;
901 * Setter for first name
903 * @param firstName First name
905 public void setFirstName (final String firstName) {
906 this.firstName = firstName;
910 * Getter for house number
912 * @return House number
914 public Short getHouseNumber () {
915 return this.houseNumber;
919 * Setter for house number
921 * @param houseNumber House number
923 public void setHouseNumber (final Short houseNumber) {
924 this.houseNumber = houseNumber;
928 * Getter for house number extension. Example: 123a, 'a' is the extension
929 * and 123 is the house number.
931 * @return House number extension
933 public String getHouseNumberExtension () {
934 return this.houseNumberExtension;
938 * Setter for house number extension
940 * @param houseNumberExtension House number extension
942 public void setHouseNumberExtension (final String houseNumberExtension) {
943 this.houseNumberExtension = houseNumberExtension;
947 * Getter for land-line number's area code
949 * @return Land-line number's area code
951 public Integer getLandLineAreaCode () {
952 return this.landLineAreaCode;
956 * Setter for land-line number's area code
958 * @param landLineAreaCode Land-line number's area code
960 public void setLandLineAreaCode (final Integer landLineAreaCode) {
961 this.landLineAreaCode = landLineAreaCode;
965 * Getter for land-line number's country instance
967 * @return Land-line number's country instance
969 public Country getLandLineCountry () {
970 return this.landLineCountry;
974 * Setter for land-line number's country instance
976 * @param landLineCountry Land-line number's country instance
978 public void setLandLineCountry (final Country landLineCountry) {
979 this.landLineCountry = landLineCountry;
983 * Getter for land-line id
985 * @return Land-line id
987 public Long getLandLineId () {
988 return this.landLineId;
992 * Setter for land-line id
994 * @param landLineId Land-line id
996 public void setLandLineId (final Long landLineId) {
997 this.landLineId = landLineId;
1001 * Getter for land-line number
1003 * @return Land-line number
1005 public Long getLandLineNumber () {
1006 return this.landLineNumber;
1010 * Setter for land-line number
1012 * @param landLineNumber Land-line number
1014 public void setLandLineNumber (final Long landLineNumber) {
1015 this.landLineNumber = landLineNumber;
1019 * Getter for mobile id
1023 public Long getMobileId () {
1024 return this.mobileId;
1028 * Setter for mobile id
1030 * @param mobileId Mobile id
1032 public void setMobileId (final Long mobileId) {
1033 this.mobileId = mobileId;
1037 * Getter for mobile number
1039 * @return Mobile number
1041 public Long getMobileNumber () {
1042 return this.mobileNumber;
1046 * Setter for mobile number
1048 * @param mobileNumber Mobile number
1050 public void setMobileNumber (final Long mobileNumber) {
1051 this.mobileNumber = mobileNumber;
1055 * Getter for mobile number's carrier
1057 * @return Mobile number's carrier
1059 public MobileProvider getMobileProvider () {
1060 return this.mobileProvider;
1064 * Setter for mobile number's carrier prefix
1066 * @param mobileProvider Mobile number's carrier prefix
1068 public void setMobileProvider (final MobileProvider mobileProvider) {
1069 this.mobileProvider = mobileProvider;
1073 * Getter for personal title
1075 * @return Personal title
1077 public PersonalTitle getPersonalTitle () {
1078 return this.personalTitle;
1082 * Setter for personal title
1084 * @param personalTitle Personal title
1086 public void setPersonalTitle (final PersonalTitle personalTitle) {
1087 this.personalTitle = personalTitle;
1091 * Getter for street name
1093 * @return Street name
1095 public String getStreet () {
1100 * Setter for street name
1102 * @param street Street name
1104 public void setStreet (final String street) {
1105 this.street = street;
1109 * Getter for ZIP code
1113 public Integer getZipCode () {
1114 return this.zipCode;
1118 * Setter for ZIP code
1120 * @param zipCode ZIP code
1122 public void setZipCode (final Integer zipCode) {
1123 this.zipCode = zipCode;
1127 public void validateContactData () {
1128 if (this.getPersonalTitle() == null) {
1130 throw new NullPointerException("contactController.personalTitle is null"); //NOI18N
1131 } else if (this.getFirstName() == null) {
1133 throw new NullPointerException("contactController.firstName is null"); //NOI18N
1134 } else if (this.getFirstName().isEmpty()) {
1136 throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1137 } else if (this.getFamilyName() == null) {
1139 throw new NullPointerException("contactController.familyName is null"); //NOI18N
1140 } else if (this.getFamilyName().isEmpty()) {
1142 throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1143 } else if (this.getEmailAddress() == null) {
1145 throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1146 } else if (this.getEmailAddress().isEmpty()) {
1148 throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1155 private void clear () {
1157 this.setContact(null);
1160 this.setAcademicTitle(null);
1161 this.setFirstName(null);
1162 this.setFamilyName(null);
1163 this.setStreet(null);
1164 this.setHouseNumber(null);
1165 this.setHouseNumberExtension(null);
1166 this.setZipCode(null);
1168 this.setContactCountry(null);
1171 this.setEmailAddress(null);
1172 this.setLandLineCountry(null);
1173 this.setLandLineAreaCode(null);
1174 this.setLandLineNumber(null);
1175 this.setMobileProvider(null);
1176 this.setMobileNumber(null);
1177 this.setFaxCountry(null);
1178 this.setFaxAreaCode(null);
1179 this.setFaxNumber(null);
1182 this.setBirthday(null);
1183 this.setComment(null);
1187 * Updates all data in contact instance.
1189 * @param contact Contact instance
1191 private void updateContactData (final Contact contact) {
1192 // Contact instance should be valid
1193 if (null == contact) {
1195 throw new NullPointerException("contact is null"); //NOI18N
1196 } else if (contact.getContactId() == null) {
1198 throw new NullPointerException("contact.contactId is null"); //NOI18N
1199 } else if (contact.getContactId() < 1) {
1201 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1204 // Update all fields
1205 contact.setContactPersonalTitle(this.getPersonalTitle());
1206 contact.setContactTitle(this.getAcademicTitle());
1207 contact.setContactFirstName(this.getFirstName());
1208 contact.setContactFamilyName(this.getFamilyName());
1209 contact.setContactStreet(this.getStreet());
1210 contact.setContactHouseNumber(this.getHouseNumber());
1211 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1212 contact.setContactZipCode(this.getZipCode());
1213 contact.setContactCity(this.getCity());
1214 contact.setContactCountry(this.getContactCountry());
1216 // Update contact's cmobile number
1217 this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1219 // Update contact's land-line number
1220 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1222 // Update contact's fax number
1223 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());