2 * Copyright (C) 2016 - 2020 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.jjobs.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.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;
57 * An administrative user controller (bean)
59 * @author Roland Häder<roland@mxchange.org>
61 @Named ("adminContactController")
63 public class JobsAdminContactWebRequestBean extends BaseJobsBean implements JobsAdminContactWebRequestController {
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/jjobs-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/jjobs-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
112 private ContactSessionBeanRemote contactBean;
115 * General contact controller
118 private JobsContactWebRequestController contactController;
123 private Country contactCountry;
128 private Long contactId;
131 * An instance of a contact list controller
134 private JobsContactListWebViewController contactListController;
137 * Event being fired when an administrator has deleted a contact
141 private Event<ObservableAdminDeletedContactEvent> deletedContactEvent;
146 private String emailAddress;
151 private String familyName;
154 * Fax number's area code
156 private Integer faxAreaCode;
159 * Country instance for fax number
161 private Country faxCountry;
171 private Long faxNumber;
176 private String firstName;
181 private Short houseNumber;
184 * House number extension
186 private String houseNumberExtension;
189 * Whether a fax entry has been unlinked
191 private boolean isFaxUnlinked;
194 * Whether a land-line number has been unlinked
196 private boolean isLandLineUnlinked;
199 * Whether a cmobile entry has been unlinked
201 private boolean isMobileNumberUnlinked;
204 * Phone number area code
206 private Integer landLineAreaCode;
209 * Country instance for phone number
211 private Country landLineCountry;
214 * Land-line id number
216 private Long landLineId;
221 private Long landLineNumber;
226 private Long mobileId;
231 private Long mobileNumber;
234 * Mobile number's provider
236 private MobileProvider mobileProvider;
239 * PersonalTitle instance
241 private PersonalTitle personalTitle;
246 private String street;
249 * An event fired when the administrator has updated contact data
253 private Event<ObservableAdminUpdatedContactEvent> updatedContactEvent;
258 private Integer zipCode;
261 * Default constructor
263 public JobsAdminContactWebRequestBean () {
264 // Call super constructor
269 * Adds contact data to database and redirects on success. If the contact is
270 * already found, a proper exception is thrown.
272 public void addContact () {
273 // Are all minimum fields set?
274 if (this.getPersonalTitle() == null) {
276 throw new NullPointerException("personalTitle is null"); //NOI18N
277 } else if (this.getFirstName() == null) {
279 throw new NullPointerException("firstName is null"); //NOI18N
280 } else if (this.getFirstName().isEmpty()) {
282 throw new IllegalStateException("firstName is empty"); //NOI18N
283 } else if (this.getFamilyName() == null) {
285 throw new NullPointerException("familyName is null"); //NOI18N
286 } else if (this.getFamilyName().isEmpty()) {
288 throw new IllegalStateException("familyName is empty"); //NOI18N
291 // Create new contact instance
292 final Contact createdContact = this.createContactInstance();
294 // Default is not same contact
295 if (this.contactListController.isContactFound(createdContact)) {
296 // Already registered
297 throw new FacesException(new ContactAlreadyAddedException(createdContact));
301 final Contact updatedContact;
306 updatedContact = this.adminContactBean.addContact(createdContact);
307 } catch (final ContactAlreadyAddedException ex) {
309 throw new FacesException(ex);
313 this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
320 * Observer for events being fired when a bean helper has successfully
321 * created a contact instance.
323 * @param event Event being fired
325 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
327 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
329 // The event instance must be valid
332 throw new NullPointerException("event is null"); //NOI18N
333 } else if (event.getCreatedContact() == null) {
335 throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
336 } else if (event.getCreatedContact().getContactId() == null) {
338 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
339 } else if (event.getCreatedContact().getContactId() < 1) {
341 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
344 // Set contact for e.g. delete method
345 this.setContact(event.getCreatedContact());
347 // Get contact instance from event
348 final Contact createdContact = event.getCreatedContact();
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());
366 // Is the cell phone set?
367 if (createdContact.getContactMobileNumber() instanceof DialableMobileNumber) {
369 this.setMobileId(createdContact.getContactMobileNumber().getMobileId());
370 this.setMobileProvider(createdContact.getContactMobileNumber().getMobileProvider());
371 this.setMobileNumber(createdContact.getContactMobileNumber().getMobileNumber());
375 if (createdContact.getContactFaxNumber() instanceof DialableFaxNumber) {
377 this.setFaxId(createdContact.getContactFaxNumber().getPhoneId());
378 this.setFaxAreaCode(createdContact.getContactFaxNumber().getPhoneAreaCode());
379 this.setFaxCountry(createdContact.getContactFaxNumber().getPhoneCountry());
380 this.setFaxNumber(createdContact.getContactFaxNumber().getPhoneNumber());
383 // Is the land-line number set?
384 if (createdContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
386 this.setLandLineId(createdContact.getContactLandLineNumber().getPhoneId());
387 this.setLandLineAreaCode(createdContact.getContactLandLineNumber().getPhoneAreaCode());
388 this.setLandLineCountry(createdContact.getContactLandLineNumber().getPhoneCountry());
389 this.setLandLineNumber(createdContact.getContactLandLineNumber().getPhoneNumber());
393 //* NOISY-DEBUG: */ System.out.println("AdminContactController::afterCreatedContactEvent(): EXIT!"); //NOI18N
397 public Contact createContactInstance () {
398 // Are all minimum fields set?
399 if (this.getPersonalTitle() == null) {
401 throw new NullPointerException("personalTitle is null"); //NOI18N
402 } else if (this.getFirstName() == null) {
404 throw new NullPointerException("firstName is null"); //NOI18N
405 } else if (this.getFirstName().isEmpty()) {
407 throw new IllegalStateException("firstName is empty"); //NOI18N
408 } else if (this.getFamilyName() == null) {
410 throw new NullPointerException("familyName is null"); //NOI18N
411 } else if (this.getFamilyName().isEmpty()) {
413 throw new IllegalStateException("familyName is empty"); //NOI18N
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());
421 // Create new instance
422 final Contact localContact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
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());
438 localContact.setContactOwnContact(Boolean.TRUE);
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) {
445 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
446 } else if (landLine.getPhoneAreaCode() < 1) {
448 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
449 } else if (landLine.getPhoneNumber() == null) {
451 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
452 } else if (landLine.getPhoneNumber() < 1) {
454 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
458 localContact.setContactLandLineNumber(landLine);
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) {
466 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
467 } else if (fax.getPhoneAreaCode() < 1) {
469 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
470 } else if (fax.getPhoneNumber() == null) {
472 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
473 } else if (fax.getPhoneNumber() < 1) {
475 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
479 localContact.setContactFaxNumber(fax);
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) {
487 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
488 } else if (mobile.getMobileNumber() < 1) {
490 throw new IllegalArgumentException("cmobile.phoneNumber is zero or below."); //NOI18N
493 // Set cmobile number
494 localContact.setContactMobileNumber(mobile);
502 * Deletes currently chosen contact and returns to list view
506 public String deleteContactData () {
508 if (this.getContact() == null) {
510 throw new NullPointerException("this.contact is null");
511 } else if (this.getContact().getContactId() == null) {
513 throw new NullPointerException("this.contact.contactId is null");
514 } else if (this.getContact().getContactId() < 1) {
516 throw new NullPointerException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId()));
521 this.adminContactBean.deleteContactData(this.getContact());
522 } catch (final ContactNotFoundException ex) {
524 throw new FacesException(ex);
528 this.deletedContactEvent.fire(new AdminDeletedContactEvent(this.getContact()));
530 // Return to list view
531 return "admin_list_contact";
535 * Edits currently loaded contact's data in database.
537 public void editContactData () {
538 // Get contact instance
539 final Contact createdContact = this.createContactInstance();
541 // Check if contact instance is in helper and valid
542 if (null == createdContact) {
544 throw new NullPointerException("beanHelper.contact is null"); //NOI18N
545 } else if (createdContact.getContactId() == null) {
547 throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
548 } else if (createdContact.getContactId() < 1) {
550 throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", createdContact.getContactId())); //NOI18N
553 // Update all data in contact
554 this.updateContactData(createdContact);
556 // Call EJB for updating contact data
557 final Contact updatedContact = this.contactBean.updateContactData(createdContact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
560 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
567 * Returns a text representation of given mobile number or null if not set.
569 * @param mobileNumber Mobile number
571 * @return Text representation or null
573 public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
575 if (null == mobileNumber) {
581 final String number = String.format(
583 mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
584 mobileNumber.getMobileProvider().getProviderDialPrefix(),
585 mobileNumber.getMobileNumber()
593 * Returns a text representation of given land-line or fax number or null if
596 * @param phoneNumber Land-line or fax number
598 * @return Text representation or null
600 public String generatePhoneNumber (final DialableNumber phoneNumber) {
602 if (null == phoneNumber) {
608 final String number = String.format(
610 phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
611 phoneNumber.getPhoneAreaCode(),
612 phoneNumber.getPhoneNumber()
620 * Getter for academic title
622 * @return Academic title
624 public String getAcademicTitle () {
625 return this.academicTitle;
629 * Setter for academic title
631 * @param academicTitle Academic title
633 public void setAcademicTitle (final String academicTitle) {
634 this.academicTitle = academicTitle;
638 * Getter for birth day
642 @SuppressWarnings ("ReturnOfDateField")
643 public Date getBirthday () {
644 return this.birthday;
648 * Setter for birth day
650 * @param birthday Birth day
652 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
653 public void setBirthday (final Date birthday) {
654 this.birthday = birthday;
658 * Getter for city name
662 public String getCity () {
667 * Setter for city name
669 * @param city City name
671 public void setCity (final String city) {
676 * Getter for comments
680 public String getComment () {
687 * @param comment Comments
689 public void setComment (final String comment) {
690 this.comment = comment;
694 * Getter for contact instance
696 * @return Contact instance
698 public Contact getContact () {
703 * Setter for contact instance
705 * @param contact Contact instance
707 public void setContact (final Contact contact) {
708 this.contact = contact;
712 * Getter for contactCountry instance
714 * @return Country instance
716 public Country getContactCountry () {
717 return this.contactCountry;
721 * Setter for contactCountry instance
723 * @param contactCountry Country instance
725 public void setContactCountry (final Country contactCountry) {
726 this.contactCountry = contactCountry;
730 * Getter for contact id
734 public Long getContactId () {
735 return this.contactId;
739 * Setter for contact id
741 * @param contactId Contact id
743 public void setContactId (final Long contactId) {
744 this.contactId = contactId;
748 public String getControllerType () {
749 return "admin"; //NOI18N
753 * Getter for email address
755 * @return Email address
757 public String getEmailAddress () {
758 return this.emailAddress;
762 * Setter for email address
764 * @param emailAddress Email address
766 public void setEmailAddress (final String emailAddress) {
767 this.emailAddress = emailAddress;
773 * @return the familyName
775 public String getFamilyName () {
776 return this.familyName;
782 * @param familyName the familyName to set
784 public void setFamilyName (final String familyName) {
785 this.familyName = familyName;
789 * Getter for fax number's area code
791 * @return Fax number's area code
793 public Integer getFaxAreaCode () {
794 return this.faxAreaCode;
798 * Setter for fax number's area code
800 * @param faxAreaCode Fax number's area code
802 public void setFaxAreaCode (final Integer faxAreaCode) {
803 this.faxAreaCode = faxAreaCode;
807 * Getter for fax's country instance
809 * @return Fax' country instance
811 public Country getFaxCountry () {
812 return this.faxCountry;
816 * Setter for fax's country instance
818 * @param faxCountry Fax' country instance
820 public void setFaxCountry (final Country faxCountry) {
821 this.faxCountry = faxCountry;
829 public Long getFaxId () {
836 * @param faxId Fax id
838 public void setFaxId (final Long faxId) {
843 * Getter for fax number
847 public Long getFaxNumber () {
848 return this.faxNumber;
852 * Setter for fax number
854 * @param faxNumber Fax number
856 public void setFaxNumber (final Long faxNumber) {
857 this.faxNumber = faxNumber;
861 * Getter for first name
865 public String getFirstName () {
866 return this.firstName;
870 * Setter for first name
872 * @param firstName First name
874 public void setFirstName (final String firstName) {
875 this.firstName = firstName;
879 * Getter for house number
881 * @return House number
883 public Short getHouseNumber () {
884 return this.houseNumber;
888 * Setter for house number
890 * @param houseNumber House number
892 public void setHouseNumber (final Short houseNumber) {
893 this.houseNumber = houseNumber;
897 * Getter for house number extension. Example: 123a, 'a' is the extension
898 * and 123 is the house number.
900 * @return House number extension
902 public String getHouseNumberExtension () {
903 return this.houseNumberExtension;
907 * Setter for house number extension
909 * @param houseNumberExtension House number extension
911 public void setHouseNumberExtension (final String houseNumberExtension) {
912 this.houseNumberExtension = houseNumberExtension;
916 * Getter for land-line number's area code
918 * @return Land-line number's area code
920 public Integer getLandLineAreaCode () {
921 return this.landLineAreaCode;
925 * Setter for land-line number's area code
927 * @param landLineAreaCode Land-line number's area code
929 public void setLandLineAreaCode (final Integer landLineAreaCode) {
930 this.landLineAreaCode = landLineAreaCode;
934 * Getter for land-line number's country instance
936 * @return Land-line number's country instance
938 public Country getLandLineCountry () {
939 return this.landLineCountry;
943 * Setter for land-line number's country instance
945 * @param landLineCountry Land-line number's country instance
947 public void setLandLineCountry (final Country landLineCountry) {
948 this.landLineCountry = landLineCountry;
952 * Getter for land-line id
954 * @return Land-line id
956 public Long getLandLineId () {
957 return this.landLineId;
961 * Setter for land-line id
963 * @param landLineId Land-line id
965 public void setLandLineId (final Long landLineId) {
966 this.landLineId = landLineId;
970 * Getter for land-line number
972 * @return Land-line number
974 public Long getLandLineNumber () {
975 return this.landLineNumber;
979 * Setter for land-line number
981 * @param landLineNumber Land-line number
983 public void setLandLineNumber (final Long landLineNumber) {
984 this.landLineNumber = landLineNumber;
988 * Getter for mobile id
992 public Long getMobileId () {
993 return this.mobileId;
997 * Setter for mobile id
999 * @param mobileId Mobile id
1001 public void setMobileId (final Long mobileId) {
1002 this.mobileId = mobileId;
1006 * Getter for mobile number
1008 * @return Mobile number
1010 public Long getMobileNumber () {
1011 return this.mobileNumber;
1015 * Setter for mobile number
1017 * @param mobileNumber Mobile number
1019 public void setMobileNumber (final Long mobileNumber) {
1020 this.mobileNumber = mobileNumber;
1024 * Getter for mobile number's carrier
1026 * @return Mobile number's carrier
1028 public MobileProvider getMobileProvider () {
1029 return this.mobileProvider;
1033 * Setter for mobile number's carrier prefix
1035 * @param mobileProvider Mobile number's carrier prefix
1037 public void setMobileProvider (final MobileProvider mobileProvider) {
1038 this.mobileProvider = mobileProvider;
1042 * Getter for personal title
1044 * @return Personal title
1046 public PersonalTitle getPersonalTitle () {
1047 return this.personalTitle;
1051 * Setter for personal title
1053 * @param personalTitle Personal title
1055 public void setPersonalTitle (final PersonalTitle personalTitle) {
1056 this.personalTitle = personalTitle;
1060 * Getter for street name
1062 * @return Street name
1064 public String getStreet () {
1069 * Setter for street name
1071 * @param street Street name
1073 public void setStreet (final String street) {
1074 this.street = street;
1078 * Getter for ZIP code
1082 public Integer getZipCode () {
1083 return this.zipCode;
1087 * Setter for ZIP code
1089 * @param zipCode ZIP code
1091 public void setZipCode (final Integer zipCode) {
1092 this.zipCode = zipCode;
1096 public void validateContactData () {
1097 if (this.getPersonalTitle() == null) {
1099 throw new NullPointerException("contactController.gender is null"); //NOI18N
1100 } else if (this.getFirstName() == null) {
1102 throw new NullPointerException("contactController.firstName is null"); //NOI18N
1103 } else if (this.getFirstName().isEmpty()) {
1105 throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1106 } else if (this.getFamilyName() == null) {
1108 throw new NullPointerException("contactController.familyName is null"); //NOI18N
1109 } else if (this.getFamilyName().isEmpty()) {
1111 throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1112 } else if (this.getEmailAddress() == null) {
1114 throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1115 } else if (this.getEmailAddress().isEmpty()) {
1117 throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1124 private void clear () {
1126 this.setContact(null);
1129 this.setAcademicTitle(null);
1130 this.setFirstName(null);
1131 this.setFamilyName(null);
1132 this.setStreet(null);
1133 this.setHouseNumber(null);
1134 this.setHouseNumberExtension(null);
1135 this.setZipCode(null);
1137 this.setContactCountry(null);
1140 this.setEmailAddress(null);
1141 this.setLandLineCountry(null);
1142 this.setLandLineAreaCode(null);
1143 this.setLandLineNumber(null);
1144 this.setMobileProvider(null);
1145 this.setMobileNumber(null);
1146 this.setFaxCountry(null);
1147 this.setFaxAreaCode(null);
1148 this.setFaxNumber(null);
1151 this.setBirthday(null);
1152 this.setComment(null);
1156 * Updates all data in contact instance.
1158 * @param contact Contact instance
1160 private void updateContactData (final Contact contact) {
1161 // Contact instance should be valid
1162 if (null == contact) {
1164 throw new NullPointerException("contact is null"); //NOI18N
1165 } else if (contact.getContactId() == null) {
1167 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1168 } else if (contact.getContactId() < 1) {
1170 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1173 // Update all fields
1174 contact.setContactPersonalTitle(this.getPersonalTitle());
1175 contact.setContactTitle(this.getAcademicTitle());
1176 contact.setContactFirstName(this.getFirstName());
1177 contact.setContactFamilyName(this.getFamilyName());
1178 contact.setContactStreet(this.getStreet());
1179 contact.setContactHouseNumber(this.getHouseNumber());
1180 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1181 contact.setContactZipCode(this.getZipCode());
1182 contact.setContactCity(this.getCity());
1183 contact.setContactCountry(this.getContactCountry());
1185 // Update contact's cmobile number
1186 this.isMobileNumberUnlinked = Contacts.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1188 // Update contact's land-line number
1189 this.isLandLineUnlinked = Contacts.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1191 // Update contact's fax number
1192 this.isFaxUnlinked = Contacts.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());