2 * Copyright (C) 2016 - 2022 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.jfinancials.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.jcontacts.events.contact.add.AdminAddedContactEvent;
30 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
31 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
32 import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent;
33 import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
34 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
35 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
36 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
37 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
38 import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
39 import org.mxchange.jcontacts.model.contact.Contact;
40 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
41 import org.mxchange.jcontacts.model.contact.Contacts;
42 import org.mxchange.jcontacts.model.contact.UserContact;
43 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
44 import org.mxchange.jcountry.model.data.Country;
45 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
46 import org.mxchange.jfinancials.beans.contact.list.FinancialsContactListWebViewController;
47 import org.mxchange.jphone.model.phonenumbers.DialableNumber;
48 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
49 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
50 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
51 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
52 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
53 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
54 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
57 * An administrative user bean (controller)
59 * @author Roland Häder<roland@mxchange.org>
61 @Named ("adminContactController")
63 public class FinancialsAdminContactWebRequestBean extends BaseFinancialsBean implements FinancialsAdminContactWebRequestController {
68 private static final long serialVersionUID = 542_145_347_916L;
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/jfinancials-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/jfinancials-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 FinancialsContactListWebViewController 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 cmobile 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 FinancialsAdminContactWebRequestBean () {
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
410 // Generate phone number
411 DialableLandLineNumber landLine = null;
412 DialableMobileNumber mobile = null;
413 DialableFaxNumber fax = null;
415 // Are all fields set?
416 if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
418 landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
421 // Are all fields set?
422 if (this.getMobileProvider() instanceof MobileProvider && this.getMobileNumber() != null) {
423 // Initialize instance
424 mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
427 // Are all fields set?
428 if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
429 // Initialize instance
430 fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
433 // Create new instance
434 final Contact localContact = new UserContact(
435 this.getPersonalTitle(),
441 localContact.setContactBirthday(this.getBirthday());
442 localContact.setContactCity(this.getCity());
443 localContact.setContactComment(this.getComment());
444 localContact.setContactCountry(this.getContactCountry());
445 localContact.setContactEmailAddress(this.getEmailAddress());
446 localContact.setContactHouseNumber(this.getHouseNumber());
447 localContact.setContactId(this.getContactId());
448 localContact.setContactStreet(this.getStreet());
449 localContact.setContactTitle(this.getAcademicTitle());
450 localContact.setContactZipCode(this.getZipCode());
453 localContact.setContactOwnContact(Boolean.TRUE);
455 // Don't set null or wrong references
456 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
457 // Now the number must be given
458 if (landLine.getPhoneAreaCode() == null) {
460 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
461 } else if (landLine.getPhoneAreaCode() < 1) {
463 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
464 } else if (landLine.getPhoneNumber() == null) {
466 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
467 } else if (landLine.getPhoneNumber() < 1) {
469 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
473 localContact.setContactLandLineNumber(landLine);
476 // Don't set null or wrong references
477 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
478 // Now the number must be given
479 if (fax.getPhoneAreaCode() == null) {
481 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
482 } else if (fax.getPhoneAreaCode() < 1) {
484 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
485 } else if (fax.getPhoneNumber() == null) {
487 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
488 } else if (fax.getPhoneNumber() < 1) {
490 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
494 localContact.setContactFaxNumber(fax);
497 // Is the provider set?
498 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
499 // Is the number set?
500 if (mobile.getMobileNumber() == null) {
502 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
503 } else if (mobile.getMobileNumber() < 1) {
505 throw new IllegalArgumentException("cmobile.phoneNumber is zero or below."); //NOI18N
508 // Set cmobile number
509 localContact.setContactMobileNumber(mobile);
517 * Deletes currently chosen contact and returns to list view
521 public String deleteContactData () {
523 if (this.getContact() == null) {
525 throw new NullPointerException("this.contact is null");
526 } else if (this.getContact().getContactId() == null) {
528 throw new NullPointerException("this.contact.contactId is null");
529 } else if (this.getContact().getContactId() < 1) {
531 throw new NullPointerException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId()));
536 this.adminContactBean.deleteContactData(this.getContact());
537 } catch (final ContactNotFoundException ex) {
539 throw new FacesException(ex);
543 this.deletedContactEvent.fire(new AdminDeletedContactEvent(this.getContact()));
545 // Return to list view
546 return "admin_list_contacts";
550 * Edits currently loaded contact's data in database.
552 public void editContactData () {
553 // Get contact instance
554 final Contact createdContact = this.createContactInstance();
556 // Check if contact instance is in helper and valid
557 if (null == createdContact) {
559 throw new NullPointerException("beanHelper.contact is null"); //NOI18N
560 } else if (createdContact.getContactId() == null) {
562 throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N
563 } else if (createdContact.getContactId() < 1) {
565 throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", createdContact.getContactId())); //NOI18N
568 // Update all data in contact
569 this.updateContactData(createdContact);
571 // Init updated contact instance
572 final Contact updatedContact;
575 // Call EJB for updating contact data
576 updatedContact = this.contactBean.updateContactData(createdContact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
577 } catch (final ContactNotFoundException ex) {
579 throw new FacesException(ex);
583 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
590 * Returns a text representation of given mobile number or null if not set.
592 * @param mobileNumber Mobile number
594 * @return Text representation or null
596 public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
598 if (null == mobileNumber) {
604 final String number = String.format(
606 mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
607 mobileNumber.getMobileProvider().getProviderDialPrefix(),
608 mobileNumber.getMobileNumber()
616 * Returns a text representation of given land-line or fax number or null if
619 * @param phoneNumber Land-line or fax number
621 * @return Text representation or null
623 public String generatePhoneNumber (final DialableNumber phoneNumber) {
625 if (null == phoneNumber) {
631 final String number = String.format(
633 phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
634 phoneNumber.getPhoneAreaCode(),
635 phoneNumber.getPhoneNumber()
643 * Getter for academic title
645 * @return Academic title
647 public String getAcademicTitle () {
648 return this.academicTitle;
652 * Setter for academic title
654 * @param academicTitle Academic title
656 public void setAcademicTitle (final String academicTitle) {
657 this.academicTitle = academicTitle;
661 * Getter for birth day
665 @SuppressWarnings ("ReturnOfDateField")
666 public Date getBirthday () {
667 return this.birthday;
671 * Setter for birth day
673 * @param birthday Birth day
675 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
676 public void setBirthday (final Date birthday) {
677 this.birthday = birthday;
681 * Getter for city name
685 public String getCity () {
690 * Setter for city name
692 * @param city City name
694 public void setCity (final String city) {
699 * Getter for comments
703 public String getComment () {
710 * @param comment Comments
712 public void setComment (final String comment) {
713 this.comment = comment;
717 * Getter for contact instance
719 * @return Contact instance
721 public Contact getContact () {
726 * Setter for contact instance
728 * @param contact Contact instance
730 public void setContact (final Contact contact) {
731 this.contact = contact;
735 * Getter for contactCountry instance
737 * @return Country instance
739 public Country getContactCountry () {
740 return this.contactCountry;
744 * Setter for contactCountry instance
746 * @param contactCountry Country instance
748 public void setContactCountry (final Country contactCountry) {
749 this.contactCountry = contactCountry;
753 * Getter for contact id
757 public Long getContactId () {
758 return this.contactId;
762 * Setter for contact id
764 * @param contactId Contact id
766 public void setContactId (final Long contactId) {
767 this.contactId = contactId;
771 public String getControllerType () {
772 return "admin"; //NOI18N
776 * Getter for email address
778 * @return Email address
780 public String getEmailAddress () {
781 return this.emailAddress;
785 * Setter for email address
787 * @param emailAddress Email address
789 public void setEmailAddress (final String emailAddress) {
790 this.emailAddress = emailAddress;
796 * @return the familyName
798 public String getFamilyName () {
799 return this.familyName;
805 * @param familyName the familyName to set
807 public void setFamilyName (final String familyName) {
808 this.familyName = familyName;
812 * Getter for fax number's area code
814 * @return Fax number's area code
816 public Integer getFaxAreaCode () {
817 return this.faxAreaCode;
821 * Setter for fax number's area code
823 * @param faxAreaCode Fax number's area code
825 public void setFaxAreaCode (final Integer faxAreaCode) {
826 this.faxAreaCode = faxAreaCode;
830 * Getter for fax's country instance
832 * @return Fax' country instance
834 public Country getFaxCountry () {
835 return this.faxCountry;
839 * Setter for fax's country instance
841 * @param faxCountry Fax' country instance
843 public void setFaxCountry (final Country faxCountry) {
844 this.faxCountry = faxCountry;
852 public Long getFaxId () {
859 * @param faxId Fax id
861 public void setFaxId (final Long faxId) {
866 * Getter for fax number
870 public Long getFaxNumber () {
871 return this.faxNumber;
875 * Setter for fax number
877 * @param faxNumber Fax number
879 public void setFaxNumber (final Long faxNumber) {
880 this.faxNumber = faxNumber;
884 * Getter for first name
888 public String getFirstName () {
889 return this.firstName;
893 * Setter for first name
895 * @param firstName First name
897 public void setFirstName (final String firstName) {
898 this.firstName = firstName;
902 * Getter for house number
904 * @return House number
906 public Short getHouseNumber () {
907 return this.houseNumber;
911 * Setter for house number
913 * @param houseNumber House number
915 public void setHouseNumber (final Short houseNumber) {
916 this.houseNumber = houseNumber;
920 * Getter for house number extension. Example: 123a, 'a' is the extension
921 * and 123 is the house number.
923 * @return House number extension
925 public String getHouseNumberExtension () {
926 return this.houseNumberExtension;
930 * Setter for house number extension
932 * @param houseNumberExtension House number extension
934 public void setHouseNumberExtension (final String houseNumberExtension) {
935 this.houseNumberExtension = houseNumberExtension;
939 * Getter for land-line number's area code
941 * @return Land-line number's area code
943 public Integer getLandLineAreaCode () {
944 return this.landLineAreaCode;
948 * Setter for land-line number's area code
950 * @param landLineAreaCode Land-line number's area code
952 public void setLandLineAreaCode (final Integer landLineAreaCode) {
953 this.landLineAreaCode = landLineAreaCode;
957 * Getter for land-line number's country instance
959 * @return Land-line number's country instance
961 public Country getLandLineCountry () {
962 return this.landLineCountry;
966 * Setter for land-line number's country instance
968 * @param landLineCountry Land-line number's country instance
970 public void setLandLineCountry (final Country landLineCountry) {
971 this.landLineCountry = landLineCountry;
975 * Getter for land-line id
977 * @return Land-line id
979 public Long getLandLineId () {
980 return this.landLineId;
984 * Setter for land-line id
986 * @param landLineId Land-line id
988 public void setLandLineId (final Long landLineId) {
989 this.landLineId = landLineId;
993 * Getter for land-line number
995 * @return Land-line number
997 public Long getLandLineNumber () {
998 return this.landLineNumber;
1002 * Setter for land-line number
1004 * @param landLineNumber Land-line number
1006 public void setLandLineNumber (final Long landLineNumber) {
1007 this.landLineNumber = landLineNumber;
1011 * Getter for mobile id
1015 public Long getMobileId () {
1016 return this.mobileId;
1020 * Setter for mobile id
1022 * @param mobileId Mobile id
1024 public void setMobileId (final Long mobileId) {
1025 this.mobileId = mobileId;
1029 * Getter for mobile number
1031 * @return Mobile number
1033 public Long getMobileNumber () {
1034 return this.mobileNumber;
1038 * Setter for mobile number
1040 * @param mobileNumber Mobile number
1042 public void setMobileNumber (final Long mobileNumber) {
1043 this.mobileNumber = mobileNumber;
1047 * Getter for mobile number's carrier
1049 * @return Mobile number's carrier
1051 public MobileProvider getMobileProvider () {
1052 return this.mobileProvider;
1056 * Setter for mobile number's carrier prefix
1058 * @param mobileProvider Mobile number's carrier prefix
1060 public void setMobileProvider (final MobileProvider mobileProvider) {
1061 this.mobileProvider = mobileProvider;
1065 * Getter for personal title
1067 * @return Personal title
1069 public PersonalTitle getPersonalTitle () {
1070 return this.personalTitle;
1074 * Setter for personal title
1076 * @param personalTitle Personal title
1078 public void setPersonalTitle (final PersonalTitle personalTitle) {
1079 this.personalTitle = personalTitle;
1083 * Getter for street name
1085 * @return Street name
1087 public String getStreet () {
1092 * Setter for street name
1094 * @param street Street name
1096 public void setStreet (final String street) {
1097 this.street = street;
1101 * Getter for ZIP code
1105 public Integer getZipCode () {
1106 return this.zipCode;
1110 * Setter for ZIP code
1112 * @param zipCode ZIP code
1114 public void setZipCode (final Integer zipCode) {
1115 this.zipCode = zipCode;
1119 public void validateContactData () {
1120 if (this.getPersonalTitle() == null) {
1122 throw new NullPointerException("contactController.gender is null"); //NOI18N
1123 } else if (this.getFirstName() == null) {
1125 throw new NullPointerException("contactController.firstName is null"); //NOI18N
1126 } else if (this.getFirstName().isEmpty()) {
1128 throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1129 } else if (this.getFamilyName() == null) {
1131 throw new NullPointerException("contactController.familyName is null"); //NOI18N
1132 } else if (this.getFamilyName().isEmpty()) {
1134 throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1135 } else if (this.getEmailAddress() == null) {
1137 throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1138 } else if (this.getEmailAddress().isEmpty()) {
1140 throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1147 private void clear () {
1149 this.setContact(null);
1152 this.setAcademicTitle(null);
1153 this.setFirstName(null);
1154 this.setFamilyName(null);
1155 this.setStreet(null);
1156 this.setHouseNumber(null);
1157 this.setHouseNumberExtension(null);
1158 this.setZipCode(null);
1160 this.setContactCountry(null);
1163 this.setEmailAddress(null);
1164 this.setLandLineCountry(null);
1165 this.setLandLineAreaCode(null);
1166 this.setLandLineNumber(null);
1167 this.setMobileProvider(null);
1168 this.setMobileNumber(null);
1169 this.setFaxCountry(null);
1170 this.setFaxAreaCode(null);
1171 this.setFaxNumber(null);
1174 this.setBirthday(null);
1175 this.setComment(null);
1179 * Updates all data in contact instance.
1181 * @param contact Contact instance
1183 private void updateContactData (final Contact contact) {
1184 // Contact instance should be valid
1185 if (null == contact) {
1187 throw new NullPointerException("contact is null"); //NOI18N
1188 } else if (contact.getContactId() == null) {
1190 throw new NullPointerException("contact.contactId is null"); //NOI18N
1191 } else if (contact.getContactId() < 1) {
1193 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1196 // Update all fields
1197 contact.setContactPersonalTitle(this.getPersonalTitle());
1198 contact.setContactTitle(this.getAcademicTitle());
1199 contact.setContactFirstName(this.getFirstName());
1200 contact.setContactFamilyName(this.getFamilyName());
1201 contact.setContactStreet(this.getStreet());
1202 contact.setContactHouseNumber(this.getHouseNumber());
1203 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1204 contact.setContactZipCode(this.getZipCode());
1205 contact.setContactCity(this.getCity());
1206 contact.setContactCountry(this.getContactCountry());
1208 // Update contact's cmobile number
1209 this.isMobileNumberUnlinked = Contacts.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1211 // Update contact's land-line number
1212 this.isLandLineUnlinked = Contacts.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1214 // Update contact's fax number
1215 this.isFaxUnlinked = Contacts.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());