2 * Copyright (C) 2016, 2017 Roland Häder
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;
21 import java.util.Iterator;
22 import javax.annotation.PostConstruct;
23 import javax.enterprise.context.RequestScoped;
24 import javax.enterprise.event.Event;
25 import javax.enterprise.event.Observes;
26 import javax.enterprise.inject.Any;
27 import javax.faces.context.FacesContext;
28 import javax.faces.view.facelets.FaceletException;
29 import javax.inject.Inject;
30 import javax.inject.Named;
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33 import javax.naming.NamingException;
34 import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote;
35 import org.mxchange.jcontacts.contact.Contact;
36 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
37 import org.mxchange.jcontacts.contact.ContactUtils;
38 import org.mxchange.jcontacts.contact.UserContact;
39 import org.mxchange.jcontacts.contact.title.PersonalTitle;
40 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
42 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
43 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
44 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
45 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
46 import org.mxchange.jcountry.data.Country;
47 import org.mxchange.jjobs.beans.BaseJobsController;
48 import org.mxchange.jjobs.beans.helper.JobsWebRequestHelperController;
49 import org.mxchange.jphone.phonenumbers.DialableNumber;
50 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
51 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
52 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
53 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
54 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
55 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
56 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
59 * An administrative user controller (bean)
61 * @author Roland Häder<roland@mxchange.org>
63 @Named ("adminContactController")
65 public class JobsAdminContactWebRequestBean extends BaseJobsController implements JobsAdminContactWebRequestController {
70 private static final long serialVersionUID = 542_145_347_916L;
73 * Academic academicTitle
75 private String academicTitle;
78 * An event fired when the administrator has added a new contact
82 private Event<ObservableAdminAddedContactEvent> addedContactEvent;
85 * Administrative contact EJB
87 private AdminContactSessionBeanRemote adminContactBean;
90 * Bean helper instance
93 private JobsWebRequestHelperController beanHelper;
98 private Date birthday;
108 private String comment;
111 * Remote contact bean
113 private ContactSessionBeanRemote contactBean;
116 * General contact controller
119 private JobsContactWebSessionController contactController;
124 private Country contactCountry;
129 private Long contactId;
134 private String emailAddress;
139 private String familyName;
142 * Fax number's area code
144 private Integer faxAreaCode;
147 * Country instance for fax number
149 private Country faxCountry;
159 private Long faxNumber;
164 private String firstName;
169 private Short houseNumber;
172 * House number extension
174 private String houseNumberExtension;
177 * Whether a fax entry has been unlinked
179 private boolean isFaxUnlinked;
182 * Whether a land-line number has been unlinked
184 private boolean isLandLineUnlinked;
187 * Whether a cmobile entry has been unlinked
189 private boolean isMobileNumberUnlinked;
192 * Phone number area code
194 private Integer landLineAreaCode;
197 * Country instance for phone number
199 private Country landLineCountry;
202 * Land-line id number
204 private Long landLineId;
209 private Long landLineNumber;
214 private Long mobileId;
219 private Long mobileNumber;
222 * Mobile number's provider
224 private MobileProvider mobileProvider;
227 * PersonalTitle instance
229 private PersonalTitle personalTitle;
234 private String street;
237 * An event fired when the administrator has updated contact data
241 private Event<ObservableAdminUpdatedContactEvent> updatedContactEvent;
246 private Integer zipCode;
249 * Default constructor
251 public JobsAdminContactWebRequestBean () {
252 // Call super constructor
257 * Adds contact data to database and redirects on success. If the contact is
258 * already found, a proper exception is thrown.
260 * @return Redirect outcome
262 public String addContact () {
263 // Are all minimum fields set?
264 if (this.getPersonalTitle() == null) {
266 throw new NullPointerException("personalTitle is null"); //NOI18N
267 } else if (this.getFirstName() == null) {
269 throw new NullPointerException("firstName is null"); //NOI18N
270 } else if (this.getFirstName().isEmpty()) {
272 throw new IllegalStateException("firstName is empty"); //NOI18N
273 } else if (this.getFamilyName() == null) {
275 throw new NullPointerException("familyName is null"); //NOI18N
276 } else if (this.getFamilyName().isEmpty()) {
278 throw new IllegalStateException("familyName is empty"); //NOI18N
281 // Create new contact instance
282 Contact contact = this.createContactInstance();
284 // Default is not same contact
285 if (this.isSameContactFound(contact)) {
286 // Already registered
287 throw new FaceletException(new ContactAlreadyAddedException(contact));
291 Contact updatedContact;
296 updatedContact = this.adminContactBean.addContact(contact);
297 } catch (final ContactAlreadyAddedException ex) {
299 throw new FaceletException(ex);
303 this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
309 return "admin_list_contact"; //NOI18N
313 * Observer for events being fired when a bean helper has successfully
314 * created a contact instance.
316 * @param event Event being fired
318 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
320 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
322 // The event instance must be valid
325 throw new NullPointerException("event is null"); //NOI18N
326 } else if (event.getCreatedContact() == null) {
328 throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
329 } else if (event.getCreatedContact().getContactId() == null) {
331 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
332 } else if (event.getCreatedContact().getContactId() < 1) {
334 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
337 // Get contact instance from event
338 Contact contact = event.getCreatedContact();
340 // Set all fields: contact
341 this.setContactId(contact.getContactId());
342 this.setAcademicTitle(contact.getContactTitle());
343 this.setBirthday(contact.getContactBirthday());
344 this.setCity(contact.getContactCity());
345 this.setComment(contact.getContactComment());
346 this.setContactCountry(contact.getContactCountry());
347 this.setEmailAddress(contact.getContactEmailAddress());
348 this.setFamilyName(contact.getContactFamilyName());
349 this.setFirstName(contact.getContactFirstName());
350 this.setPersonalTitle(contact.getContactPersonalTitle());
351 this.setHouseNumber(contact.getContactHouseNumber());
352 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
353 this.setStreet(contact.getContactStreet());
354 this.setZipCode(contact.getContactZipCode());
356 // Is the cell phone set?
357 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
359 this.setMobileId(contact.getContactMobileNumber().getPhoneId());
360 this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
361 this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
365 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
367 this.setFaxId(contact.getContactFaxNumber().getPhoneId());
368 this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
369 this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
370 this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
373 // Is the land-line number set?
374 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
376 this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
377 this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
378 this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
379 this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
383 //* NOISY-DEBUG: */ System.out.println("AdminContactController::afterCreatedContactEvent(): EXIT!"); //NOI18N
387 public Contact createContactInstance () {
388 // Are all minimum fields set?
389 if (this.getPersonalTitle() == null) {
391 throw new NullPointerException("personalTitle is null"); //NOI18N
392 } else if (this.getFirstName() == null) {
394 throw new NullPointerException("firstName is null"); //NOI18N
395 } else if (this.getFirstName().isEmpty()) {
397 throw new IllegalStateException("firstName is empty"); //NOI18N
398 } else if (this.getFamilyName() == null) {
400 throw new NullPointerException("familyName is null"); //NOI18N
401 } else if (this.getFamilyName().isEmpty()) {
403 throw new IllegalStateException("familyName is empty"); //NOI18N
406 // Generate phone number
407 DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
408 DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
409 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
411 // Create new instance
412 Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
414 // Is contact id set?
415 if (this.getContactId() instanceof Long) {
417 contact.setContactId(this.getContactId());
421 contact.setContactTitle(this.getAcademicTitle());
422 contact.setContactBirthday(this.getBirthday());
423 contact.setContactStreet(this.getStreet());
424 contact.setContactHouseNumber(this.getHouseNumber());
425 contact.setContactZipCode(this.getZipCode());
426 contact.setContactCity(this.getCity());
427 contact.setContactCountry(this.getContactCountry());
428 contact.setContactEmailAddress(this.getEmailAddress());
429 contact.setContactBirthday(this.getBirthday());
430 contact.setContactComment(this.getComment());
433 contact.setContactOwnContact(Boolean.TRUE);
435 // Don't set null or wrong references
436 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
437 // Now the number must be given
438 if (landLine.getPhoneAreaCode() == null) {
440 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
441 } else if (landLine.getPhoneAreaCode() < 1) {
443 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
444 } else if (landLine.getPhoneNumber() == null) {
446 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
447 } else if (landLine.getPhoneNumber() < 1) {
449 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
453 contact.setContactLandLineNumber(landLine);
456 // Don't set null or wrong references
457 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
458 // Now the number must be given
459 if (fax.getPhoneAreaCode() == null) {
461 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
462 } else if (fax.getPhoneAreaCode() < 1) {
464 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
465 } else if (fax.getPhoneNumber() == null) {
467 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
468 } else if (fax.getPhoneNumber() < 1) {
470 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
474 contact.setContactFaxNumber(fax);
477 // Is the provider set?
478 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
479 // Is the number set?
480 if (mobile.getPhoneNumber() == null) {
482 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
483 } else if (mobile.getPhoneNumber() < 1) {
485 throw new IllegalArgumentException("cmobile.phoneNumber is zero or below."); //NOI18N
488 // Set cmobile number
489 contact.setContactMobileNumber(mobile);
497 * Edits currently loaded contact's data in database.
499 * @return Redirect outcome
501 public String editContactData () {
502 // Get contact instance
503 Contact contact = this.createContactInstance();
505 // Check if contact instance is in helper and valid
506 if (null == contact) {
508 throw new NullPointerException("beanHelper.contact is null"); //NOI18N
509 } else if (contact.getContactId() == null) {
511 throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
512 } else if (contact.getContactId() < 1) {
514 throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
517 // Update all data in contact
518 this.updateContactData(contact);
520 // Call EJB for updating contact data
521 Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
524 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
529 // Return to contact list (for now)
530 return "admin_list_contact"; //NOI18N
534 * Returns a text representation of given mobile number or null if not set.
536 * @param mobileNumber Mobile number
538 * @return Text representation or null
540 public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
542 if (null == mobileNumber) {
548 String number = String.format(
550 mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
551 mobileNumber.getMobileProvider().getProviderDialPrefix(),
552 mobileNumber.getPhoneNumber()
560 * Returns a text representation of given land-line or fax number or null if
563 * @param phoneNumber Land-line or fax number
565 * @return Text representation or null
567 public String generatePhoneNumber (final DialableNumber phoneNumber) {
569 if (null == phoneNumber) {
575 String number = String.format(
577 phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
578 phoneNumber.getPhoneAreaCode(),
579 phoneNumber.getPhoneNumber()
587 * Getter for academic title
589 * @return Academic title
591 public String getAcademicTitle () {
592 return this.academicTitle;
596 * Setter for academic title
598 * @param academicTitle Academic title
600 public void setAcademicTitle (final String academicTitle) {
601 this.academicTitle = academicTitle;
605 * Getter for birth day
609 @SuppressWarnings ("ReturnOfDateField")
610 public Date getBirthday () {
611 return this.birthday;
615 * Setter for birth day
617 * @param birthday Birth day
619 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
620 public void setBirthday (final Date birthday) {
621 this.birthday = birthday;
625 * Getter for city name
629 public String getCity () {
634 * Setter for city name
636 * @param city City name
638 public void setCity (final String city) {
643 * Getter for comments
647 public String getComment () {
654 * @param comment Comments
656 public void setComment (final String comment) {
657 this.comment = comment;
661 * Getter for contactCountry instance
663 * @return Country instance
665 public Country getContactCountry () {
666 return this.contactCountry;
670 * Setter for contactCountry instance
672 * @param contactCountry Country instance
674 public void setContactCountry (final Country contactCountry) {
675 this.contactCountry = contactCountry;
679 * Getter for contact id
683 public Long getContactId () {
684 return this.contactId;
688 * Setter for contact id
690 * @param contactId Contact id
692 public void setContactId (final Long contactId) {
693 this.contactId = contactId;
697 public String getControllerType () {
698 return "admin"; //NOI18N
703 public void setControllerType (final String controllerType) {
704 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
708 * Getter for email address
710 * @return Email address
712 public String getEmailAddress () {
713 return this.emailAddress;
717 * Setter for email address
719 * @param emailAddress Email address
721 public void setEmailAddress (final String emailAddress) {
722 this.emailAddress = emailAddress;
728 * @return the familyName
730 public String getFamilyName () {
731 return this.familyName;
737 * @param familyName the familyName to set
739 public void setFamilyName (final String familyName) {
740 this.familyName = familyName;
744 * Getter for fax number's area code
746 * @return Fax number's area code
748 public Integer getFaxAreaCode () {
749 return this.faxAreaCode;
753 * Setter for fax number's area code
755 * @param faxAreaCode Fax number's area code
757 public void setFaxAreaCode (final Integer faxAreaCode) {
758 this.faxAreaCode = faxAreaCode;
762 * Getter for fax's country instance
764 * @return Fax' country instance
766 public Country getFaxCountry () {
767 return this.faxCountry;
771 * Setter for fax's country instance
773 * @param faxCountry Fax' country instance
775 public void setFaxCountry (final Country faxCountry) {
776 this.faxCountry = faxCountry;
784 public Long getFaxId () {
791 * @param faxId Fax id
793 public void setFaxId (final Long faxId) {
798 * Getter for fax number
802 public Long getFaxNumber () {
803 return this.faxNumber;
807 * Setter for fax number
809 * @param faxNumber Fax number
811 public void setFaxNumber (final Long faxNumber) {
812 this.faxNumber = faxNumber;
816 * Getter for first name
820 public String getFirstName () {
821 return this.firstName;
825 * Setter for first name
827 * @param firstName First name
829 public void setFirstName (final String firstName) {
830 this.firstName = firstName;
834 * Getter for house number
836 * @return House number
838 public Short getHouseNumber () {
839 return this.houseNumber;
843 * Setter for house number
845 * @param houseNumber House number
847 public void setHouseNumber (final Short houseNumber) {
848 this.houseNumber = houseNumber;
852 * Getter for house number extension. Example: 123a, 'a' is the extension
853 * and 123 is the house number.
855 * @return House number extension
857 public String getHouseNumberExtension () {
858 return this.houseNumberExtension;
862 * Setter for house number extension
864 * @param houseNumberExtension House number extension
866 public void setHouseNumberExtension (final String houseNumberExtension) {
867 this.houseNumberExtension = houseNumberExtension;
871 * Getter for land-line number's area code
873 * @return Land-line number's area code
875 public Integer getLandLineAreaCode () {
876 return this.landLineAreaCode;
880 * Setter for land-line number's area code
882 * @param landLineAreaCode Land-line number's area code
884 public void setLandLineAreaCode (final Integer landLineAreaCode) {
885 this.landLineAreaCode = landLineAreaCode;
889 * Getter for land-line number's country instance
891 * @return Land-line number's country instance
893 public Country getLandLineCountry () {
894 return this.landLineCountry;
898 * Setter for land-line number's country instance
900 * @param landLineCountry Land-line number's country instance
902 public void setLandLineCountry (final Country landLineCountry) {
903 this.landLineCountry = landLineCountry;
907 * Getter for land-line id
909 * @return Land-line id
911 public Long getLandLineId () {
912 return this.landLineId;
916 * Setter for land-line id
918 * @param landLineId Land-line id
920 public void setLandLineId (final Long landLineId) {
921 this.landLineId = landLineId;
925 * Getter for land-line number
927 * @return Land-line number
929 public Long getLandLineNumber () {
930 return this.landLineNumber;
934 * Setter for land-line number
936 * @param landLineNumber Land-line number
938 public void setLandLineNumber (final Long landLineNumber) {
939 this.landLineNumber = landLineNumber;
943 * Getter for mobile id
947 public Long getMobileId () {
948 return this.mobileId;
952 * Setter for mobile id
954 * @param mobileId Mobile id
956 public void setMobileId (final Long mobileId) {
957 this.mobileId = mobileId;
961 * Getter for mobile number
963 * @return Mobile number
965 public Long getMobileNumber () {
966 return this.mobileNumber;
970 * Setter for mobile number
972 * @param mobileNumber Mobile number
974 public void setMobileNumber (final Long mobileNumber) {
975 this.mobileNumber = mobileNumber;
979 * Getter for mobile number's carrier
981 * @return Mobile number's carrier
983 public MobileProvider getMobileProvider () {
984 return this.mobileProvider;
988 * Setter for mobile number's carrier prefix
990 * @param mobileProvider Mobile number's carrier prefix
992 public void setMobileProvider (final MobileProvider mobileProvider) {
993 this.mobileProvider = mobileProvider;
997 * Getter for personal title
999 * @return Personal title
1001 public PersonalTitle getPersonalTitle () {
1002 return this.personalTitle;
1006 * Setter for personal title
1008 * @param personalTitle Personal title
1010 public void setPersonalTitle (final PersonalTitle personalTitle) {
1011 this.personalTitle = personalTitle;
1015 * Getter for street name
1017 * @return Street name
1019 public String getStreet () {
1024 * Setter for street name
1026 * @param street Street name
1028 public void setStreet (final String street) {
1029 this.street = street;
1033 * Getter for ZIP code
1037 public Integer getZipCode () {
1038 return this.zipCode;
1042 * Setter for ZIP code
1044 * @param zipCode ZIP code
1046 public void setZipCode (final Integer zipCode) {
1047 this.zipCode = zipCode;
1051 * Post-initialization of this class
1054 public void init () {
1057 // Get initial context
1058 Context context = new InitialContext();
1061 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
1063 // Try to lookup (administative)
1064 this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
1065 } catch (final NamingException e) {
1067 throw new FaceletException(e);
1073 public boolean isPersonalTitleRequired () {
1074 // Get context parameter
1075 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_personal_title_enabled"); //NOI18N
1078 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
1085 public void validateContactData () {
1086 if (this.getPersonalTitle() == null) {
1088 throw new NullPointerException("contactController.gender is null"); //NOI18N
1089 } else if (this.getFirstName() == null) {
1091 throw new NullPointerException("contactController.firstName is null"); //NOI18N
1092 } else if (this.getFirstName().isEmpty()) {
1094 throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1095 } else if (this.getFamilyName() == null) {
1097 throw new NullPointerException("contactController.familyName is null"); //NOI18N
1098 } else if (this.getFamilyName().isEmpty()) {
1100 throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1101 } else if (this.getEmailAddress() == null) {
1103 throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1104 } else if (this.getEmailAddress().isEmpty()) {
1106 throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1113 private void clear () {
1116 this.setAcademicTitle(null);
1117 this.setFirstName(null);
1118 this.setFamilyName(null);
1119 this.setStreet(null);
1120 this.setHouseNumber(null);
1121 this.setHouseNumberExtension(null);
1122 this.setZipCode(null);
1124 this.setContactCountry(null);
1127 this.setEmailAddress(null);
1128 this.setLandLineCountry(null);
1129 this.setLandLineAreaCode(null);
1130 this.setLandLineNumber(null);
1131 this.setMobileProvider(null);
1132 this.setMobileNumber(null);
1133 this.setFaxCountry(null);
1134 this.setFaxAreaCode(null);
1135 this.setFaxNumber(null);
1138 this.setBirthday(null);
1139 this.setComment(null);
1143 * Checks whether the given contact is found
1145 * @param contact Contact instance
1147 * @return Whether contact has been found
1149 private boolean isSameContactFound (final Contact contact) {
1150 // Default is not found
1151 boolean IsFound = false;
1154 Iterator<Contact> iterator = this.contactController.allContacts().iterator();
1157 while (iterator.hasNext()) {
1159 Contact next = iterator.next();
1162 if (ContactUtils.isSameContact(contact, next)) {
1163 // Yes, then abort loop
1174 * Updates all data in contact instance.
1176 * @param contact Contact instance
1178 private void updateContactData (final Contact contact) {
1179 // Contact instance should be valid
1180 if (null == contact) {
1182 throw new NullPointerException("contact is null"); //NOI18N
1183 } else if (contact.getContactId() == null) {
1185 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1186 } else if (contact.getContactId() < 1) {
1188 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1191 // Update all fields
1192 contact.setContactPersonalTitle(this.getPersonalTitle());
1193 contact.setContactTitle(this.getAcademicTitle());
1194 contact.setContactFirstName(this.getFirstName());
1195 contact.setContactFamilyName(this.getFamilyName());
1196 contact.setContactStreet(this.getStreet());
1197 contact.setContactHouseNumber(this.getHouseNumber());
1198 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1199 contact.setContactZipCode(this.getZipCode());
1200 contact.setContactCity(this.getCity());
1201 contact.setContactCountry(this.getContactCountry());
1203 // Update contact's cmobile number
1204 this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1206 // Update contact's land-line number
1207 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1209 // Update contact's fax number
1210 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());