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.pizzaapplication.beans.contact;
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.Iterator;
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.view.facelets.FaceletException;
28 import javax.inject.Inject;
29 import javax.inject.Named;
30 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
31 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
32 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
33 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
34 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
35 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
36 import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
37 import org.mxchange.jcontacts.model.contact.Contact;
38 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
39 import org.mxchange.jcontacts.model.contact.UserContact;
40 import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
41 import org.mxchange.jcontacts.model.utils.ContactUtils;
42 import org.mxchange.jcountry.model.data.Country;
43 import org.mxchange.jphone.model.phonenumbers.DialableNumber;
44 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
45 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
46 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
47 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
48 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
49 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
50 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
51 import org.mxchange.pizzaapplication.beans.BasePizzaBean;
54 * Administrative user bean (controller)
56 * @author Roland Häder<roland@mxchange.org>
58 @Named ("adminContactController")
60 public class PizzaAdminContactWebRequestBean extends BasePizzaBean implements PizzaAdminContactWebRequestController {
65 private static final long serialVersionUID = 542_145_351_001L;
68 * Academic academicTitle
70 private String academicTitle;
73 * An event fired when the administrator has added a new contact
77 private Event<ObservableAdminAddedContactEvent> addedContactEvent;
80 * Administrative contact EJB
82 @EJB (lookup = "java:global/pizzaservice-ejb/adminContact!org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote")
83 private AdminContactSessionBeanRemote adminContactBean;
88 private Date birthday;
98 private String comment;
101 * EJB for general contact purposes
103 @EJB (lookup = "java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
104 private ContactSessionBeanRemote contactBean;
107 * General contact controller
110 private PizzaContactWebRequestController contactController;
115 private Country contactCountry;
120 private Long contactId;
125 private String emailAddress;
130 private String familyName;
133 * Fax number's area code
135 private Integer faxAreaCode;
138 * Country instance for fax number
140 private Country faxCountry;
150 private Long faxNumber;
155 private String firstName;
160 private Short houseNumber;
163 * House number extension
165 private String houseNumberExtension;
168 * Whether a fax entry has been unlinked
170 private boolean isFaxUnlinked;
173 * Whether a land-line number has been unlinked
175 private boolean isLandLineUnlinked;
178 * Whether a mobile entry has been unlinked
180 private boolean isMobileNumberUnlinked;
183 * Phone number area code
185 private Integer landLineAreaCode;
188 * Country instance for phone number
190 private Country landLineCountry;
193 * Land-line id number
195 private Long landLineId;
200 private Long landLineNumber;
205 private Long mobileId;
210 private Long mobileNumber;
213 * Mobile number's provider
215 private MobileProvider mobileProvider;
218 * PersonalTitle instance
220 private PersonalTitle personalTitle;
225 private String street;
228 * An event fired when the administrator has updated contact data
232 private Event<ObservableAdminUpdatedContactEvent> updatedContactEvent;
237 private Integer zipCode;
240 * Default constructor
242 public PizzaAdminContactWebRequestBean () {
243 // Call super constructor
248 * Adds contact data to database and redirects on success. If the contact is
249 * already found, a proper exception is thrown.
251 * @return Redirect outcome
253 public String addContact () {
254 // Are all minimum fields set?
255 if (this.getPersonalTitle() == null) {
257 throw new NullPointerException("personalTitle is null"); //NOI18N
258 } else if (this.getFirstName() == null) {
260 throw new NullPointerException("firstName is null"); //NOI18N
261 } else if (this.getFirstName().isEmpty()) {
263 throw new IllegalStateException("firstName is empty"); //NOI18N
264 } else if (this.getFamilyName() == null) {
266 throw new NullPointerException("familyName is null"); //NOI18N
267 } else if (this.getFamilyName().isEmpty()) {
269 throw new IllegalStateException("familyName is empty"); //NOI18N
272 // Create new contact instance
273 final Contact contact = this.createContactInstance();
275 // Default is not same contact
276 if (this.isSameContactFound(contact)) {
277 // Already registered
278 throw new FaceletException(new ContactAlreadyAddedException(contact));
282 final Contact updatedContact;
287 updatedContact = this.adminContactBean.addContact(contact);
288 } catch (final ContactAlreadyAddedException ex) {
290 throw new FaceletException(ex);
294 this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
300 return "admin_list_contact"; //NOI18N
304 * Observer for events being fired when a bean helper has successfully
305 * created a contact instance.
307 * @param event Event being fired
309 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
311 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
313 // The event instance must be valid
316 throw new NullPointerException("event is null"); //NOI18N
317 } else if (event.getCreatedContact() == null) {
319 throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
320 } else if (event.getCreatedContact().getContactId() == null) {
322 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
323 } else if (event.getCreatedContact().getContactId() < 1) {
325 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
328 // Get contact instance from event
329 final Contact contact = event.getCreatedContact();
331 // Set all fields: contact
332 this.setContactId(contact.getContactId());
333 this.setAcademicTitle(contact.getContactTitle());
334 this.setBirthday(contact.getContactBirthday());
335 this.setCity(contact.getContactCity());
336 this.setComment(contact.getContactComment());
337 this.setContactCountry(contact.getContactCountry());
338 this.setEmailAddress(contact.getContactEmailAddress());
339 this.setFamilyName(contact.getContactFamilyName());
340 this.setFirstName(contact.getContactFirstName());
341 this.setPersonalTitle(contact.getContactPersonalTitle());
342 this.setHouseNumber(contact.getContactHouseNumber());
343 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
344 this.setStreet(contact.getContactStreet());
345 this.setZipCode(contact.getContactZipCode());
347 // Is the cell phone set?
348 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
350 this.setMobileId(contact.getContactMobileNumber().getPhoneId());
351 this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
352 this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
356 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
358 this.setFaxId(contact.getContactFaxNumber().getPhoneId());
359 this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
360 this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
361 this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
364 // Is the land-line number set?
365 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
367 this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
368 this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
369 this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
370 this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
374 //* NOISY-DEBUG: */ System.out.println("AdminContactController::afterCreatedContactEvent(): EXIT!"); //NOI18N
378 public Contact createContactInstance () {
379 // Are all minimum fields set?
380 if (this.getPersonalTitle() == null) {
382 throw new NullPointerException("personalTitle is null"); //NOI18N
383 } else if (this.getFirstName() == null) {
385 throw new NullPointerException("firstName is null"); //NOI18N
386 } else if (this.getFirstName().isEmpty()) {
388 throw new IllegalStateException("firstName is empty"); //NOI18N
389 } else if (this.getFamilyName() == null) {
391 throw new NullPointerException("familyName is null"); //NOI18N
392 } else if (this.getFamilyName().isEmpty()) {
394 throw new IllegalStateException("familyName is empty"); //NOI18N
395 } else if (this.getContactCountry() == null) {
397 throw new NullPointerException("contactCountry is null"); //NOI18N
398 } else if (this.getContactCountry().getCountryId() == null) {
400 throw new NullPointerException("contactCountry.countryId is null"); //NOI18N
401 } else if (this.getContactCountry().getCountryId() < 1) {
403 throw new IllegalArgumentException(MessageFormat.format("contactCountry.countryId={0} is invalid", this.getContactCountry().getCountryId())); //NOI18N
406 // Generate phone number
407 final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
408 final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
409 final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
411 // Create new instance
412 final 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());
420 // Create new instance
421 final Contact localContact = new UserContact(
422 this.getPersonalTitle(),
424 this.getFamilyName(),
425 this.getContactCountry(),
428 this.getHouseNumber(),
429 this.getHouseNumberExtension(),
432 this.getEmailAddress(),
433 this.getAcademicTitle(),
438 // Add missing fields
439 localContact.setContactId(this.getContactId());
441 // Don't set null or wrong references
442 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
443 // Now the number must be given
444 if (landLine.getPhoneAreaCode() == null) {
446 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
447 } else if (landLine.getPhoneAreaCode() < 1) {
449 throw new IllegalStateException("phone.phoneAreaCode is zero or below."); //NOI18N
450 } else if (landLine.getPhoneNumber() == null) {
452 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
453 } else if (landLine.getPhoneNumber() < 1) {
455 throw new IllegalStateException("phone.phoneNumber is zero or below."); //NOI18N
459 contact.setContactLandLineNumber(landLine);
462 // Don't set null or wrong references
463 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
464 // Now the number must be given
465 if (fax.getPhoneAreaCode() == null) {
467 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
468 } else if (fax.getPhoneAreaCode() < 1) {
470 throw new IllegalStateException("fax.phoneAreaCode is zero or below."); //NOI18N
471 } else if (fax.getPhoneNumber() == null) {
473 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
474 } else if (fax.getPhoneNumber() < 1) {
476 throw new IllegalStateException("fax.phoneNumber is zero or below."); //NOI18N
480 contact.setContactFaxNumber(fax);
483 // Is the provider set?
484 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
485 // Is the number set?
486 if (mobile.getPhoneNumber() == null) {
488 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
489 } else if (mobile.getPhoneNumber() < 1) {
491 throw new IllegalStateException("cmobile.phoneNumber is zero or below."); //NOI18N
494 // Set cmobile number
495 contact.setContactMobileNumber(mobile);
503 * Edits currently loaded contact's data in database.
505 * @return Redirect outcome
507 public String editContactData () {
508 // Get contact instance
509 final Contact contact = this.createContactInstance();
511 // Check if contact instance is in helper and valid
512 if (null == contact) {
514 throw new NullPointerException("beanHelper.contact is null"); //NOI18N
515 } else if (contact.getContactId() == null) {
517 throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
518 } else if (contact.getContactId() < 1) {
520 throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
523 // Update all data in contact
524 this.updateContactData(contact);
526 // Call EJB for updating contact data
527 final Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
530 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
535 // Return to contact list (for now)
536 return "admin_list_contact"; //NOI18N
540 * Returns a text representation of given mobile number or null if not set.
542 * @param mobileNumber Mobile number
544 * @return Text representation or null
546 public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
548 if (null == mobileNumber) {
554 final String number = String.format(
556 mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
557 mobileNumber.getMobileProvider().getProviderDialPrefix(),
558 mobileNumber.getPhoneNumber()
566 * Returns a text representation of given land-line or fax number or null if
569 * @param phoneNumber Land-line or fax number
571 * @return Text representation or null
573 public String generatePhoneNumber (final DialableNumber phoneNumber) {
575 if (null == phoneNumber) {
581 final String number = String.format(
583 phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
584 phoneNumber.getPhoneAreaCode(),
585 phoneNumber.getPhoneNumber()
593 * Getter for academic title
595 * @return Academic title
597 public String getAcademicTitle () {
598 return this.academicTitle;
602 * Setter for academic title
604 * @param academicTitle Academic title
606 public void setAcademicTitle (final String academicTitle) {
607 this.academicTitle = academicTitle;
611 * Getter for birth day
615 @SuppressWarnings ("ReturnOfDateField")
616 public Date getBirthday () {
617 return this.birthday;
621 * Setter for birth day
623 * @param birthday Birth day
625 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
626 public void setBirthday (final Date birthday) {
627 this.birthday = birthday;
631 * Getter for city name
635 public String getCity () {
640 * Setter for city name
642 * @param city City name
644 public void setCity (final String city) {
649 * Getter for comments
653 public String getComment () {
660 * @param comment Comments
662 public void setComment (final String comment) {
663 this.comment = comment;
667 * Getter for contactCountry instance
669 * @return Country instance
671 public Country getContactCountry () {
672 return this.contactCountry;
676 * Setter for contactCountry instance
678 * @param contactCountry Country instance
680 public void setContactCountry (final Country contactCountry) {
681 this.contactCountry = contactCountry;
685 * Getter for contact id
689 public Long getContactId () {
690 return this.contactId;
694 * Setter for contact id
696 * @param contactId Contact id
698 public void setContactId (final Long contactId) {
699 this.contactId = contactId;
703 public String getControllerType () {
704 return "admin"; //NOI18N
709 public void setControllerType (final String controllerType) {
710 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
714 * Getter for email address
716 * @return Email address
718 public String getEmailAddress () {
719 return this.emailAddress;
723 * Setter for email address
725 * @param emailAddress Email address
727 public void setEmailAddress (final String emailAddress) {
728 this.emailAddress = emailAddress;
734 * @return the familyName
736 public String getFamilyName () {
737 return this.familyName;
743 * @param familyName the familyName to set
745 public void setFamilyName (final String familyName) {
746 this.familyName = familyName;
750 * Getter for fax number's area code
752 * @return Fax number's area code
754 public Integer getFaxAreaCode () {
755 return this.faxAreaCode;
759 * Setter for fax number's area code
761 * @param faxAreaCode Fax number's area code
763 public void setFaxAreaCode (final Integer faxAreaCode) {
764 this.faxAreaCode = faxAreaCode;
768 * Getter for fax's country instance
770 * @return Fax' country instance
772 public Country getFaxCountry () {
773 return this.faxCountry;
777 * Setter for fax's country instance
779 * @param faxCountry Fax' country instance
781 public void setFaxCountry (final Country faxCountry) {
782 this.faxCountry = faxCountry;
790 public Long getFaxId () {
797 * @param faxId Fax id
799 public void setFaxId (final Long faxId) {
804 * Getter for fax number
808 public Long getFaxNumber () {
809 return this.faxNumber;
813 * Setter for fax number
815 * @param faxNumber Fax number
817 public void setFaxNumber (final Long faxNumber) {
818 this.faxNumber = faxNumber;
822 * Getter for first name
826 public String getFirstName () {
827 return this.firstName;
831 * Setter for first name
833 * @param firstName First name
835 public void setFirstName (final String firstName) {
836 this.firstName = firstName;
840 * Getter for house number
842 * @return House number
844 public Short getHouseNumber () {
845 return this.houseNumber;
849 * Setter for house number
851 * @param houseNumber House number
853 public void setHouseNumber (final Short houseNumber) {
854 this.houseNumber = houseNumber;
858 * Getter for house number extension. Example: 123a, 'a' is the extension
859 * and 123 is the house number.
861 * @return House number extension
863 public String getHouseNumberExtension () {
864 return this.houseNumberExtension;
868 * Setter for house number extension
870 * @param houseNumberExtension House number extension
872 public void setHouseNumberExtension (final String houseNumberExtension) {
873 this.houseNumberExtension = houseNumberExtension;
877 * Getter for land-line number's area code
879 * @return Land-line number's area code
881 public Integer getLandLineAreaCode () {
882 return this.landLineAreaCode;
886 * Setter for land-line number's area code
888 * @param landLineAreaCode Land-line number's area code
890 public void setLandLineAreaCode (final Integer landLineAreaCode) {
891 this.landLineAreaCode = landLineAreaCode;
895 * Getter for land-line number's country instance
897 * @return Land-line number's country instance
899 public Country getLandLineCountry () {
900 return this.landLineCountry;
904 * Setter for land-line number's country instance
906 * @param landLineCountry Land-line number's country instance
908 public void setLandLineCountry (final Country landLineCountry) {
909 this.landLineCountry = landLineCountry;
913 * Getter for land-line id
915 * @return Land-line id
917 public Long getLandLineId () {
918 return this.landLineId;
922 * Setter for land-line id
924 * @param landLineId Land-line id
926 public void setLandLineId (final Long landLineId) {
927 this.landLineId = landLineId;
931 * Getter for land-line number
933 * @return Land-line number
935 public Long getLandLineNumber () {
936 return this.landLineNumber;
940 * Setter for land-line number
942 * @param landLineNumber Land-line number
944 public void setLandLineNumber (final Long landLineNumber) {
945 this.landLineNumber = landLineNumber;
949 * Getter for mobile id
953 public Long getMobileId () {
954 return this.mobileId;
958 * Setter for mobile id
960 * @param mobileId Mobile id
962 public void setMobileId (final Long mobileId) {
963 this.mobileId = mobileId;
967 * Getter for mobile number
969 * @return Mobile number
971 public Long getMobileNumber () {
972 return this.mobileNumber;
976 * Setter for mobile number
978 * @param mobileNumber Mobile number
980 public void setMobileNumber (final Long mobileNumber) {
981 this.mobileNumber = mobileNumber;
985 * Getter for mobile number's carrier
987 * @return Mobile number's carrier
989 public MobileProvider getMobileProvider () {
990 return this.mobileProvider;
994 * Setter for mobile number's carrier prefix
996 * @param mobileProvider Mobile number's carrier prefix
998 public void setMobileProvider (final MobileProvider mobileProvider) {
999 this.mobileProvider = mobileProvider;
1003 * Getter for personal title
1005 * @return Personal title
1007 public PersonalTitle getPersonalTitle () {
1008 return this.personalTitle;
1012 * Setter for personal title
1014 * @param personalTitle Personal title
1016 public void setPersonalTitle (final PersonalTitle personalTitle) {
1017 this.personalTitle = personalTitle;
1021 * Getter for street name
1023 * @return Street name
1025 public String getStreet () {
1030 * Setter for street name
1032 * @param street Street name
1034 public void setStreet (final String street) {
1035 this.street = street;
1039 * Getter for ZIP code
1043 public Integer getZipCode () {
1044 return this.zipCode;
1048 * Setter for ZIP code
1050 * @param zipCode ZIP code
1052 public void setZipCode (final Integer zipCode) {
1053 this.zipCode = zipCode;
1057 public boolean isRequiredPersonalDataSet () {
1058 return ((this.getPersonalTitle() != null) &&
1059 (this.getFirstName() != null) &&
1060 (this.getFamilyName() != null) &&
1061 (this.getStreet() != null) &&
1062 (this.getHouseNumber() != null) &&
1063 (this.getZipCode() != null) &&
1064 (this.getCity() != null) &&
1065 (this.getEmailAddress() != null));
1069 public void validateContactData () {
1070 if (this.getPersonalTitle() == null) {
1072 throw new NullPointerException("contactController.personalTitle is null"); //NOI18N
1073 } else if (this.getFirstName() == null) {
1075 throw new NullPointerException("contactController.firstName is null"); //NOI18N
1076 } else if (this.getFirstName().isEmpty()) {
1078 throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1079 } else if (this.getFamilyName() == null) {
1081 throw new NullPointerException("contactController.familyName is null"); //NOI18N
1082 } else if (this.getFamilyName().isEmpty()) {
1084 throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1085 } else if (this.getEmailAddress() == null) {
1087 throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1088 } else if (this.getEmailAddress().isEmpty()) {
1090 throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1097 private void clear () {
1100 this.setAcademicTitle(null);
1101 this.setFirstName(null);
1102 this.setFamilyName(null);
1103 this.setStreet(null);
1104 this.setHouseNumber(null);
1105 this.setHouseNumberExtension(null);
1106 this.setZipCode(null);
1108 this.setContactCountry(null);
1111 this.setEmailAddress(null);
1112 this.setLandLineCountry(null);
1113 this.setLandLineAreaCode(null);
1114 this.setLandLineNumber(null);
1115 this.setMobileProvider(null);
1116 this.setMobileNumber(null);
1117 this.setFaxCountry(null);
1118 this.setFaxAreaCode(null);
1119 this.setFaxNumber(null);
1122 this.setBirthday(null);
1123 this.setComment(null);
1127 * Checks whether the given contact is found
1129 * @param contact Contact instance
1131 * @return Whether contact has been found
1133 private boolean isSameContactFound (final Contact contact) {
1134 // Default is not found
1135 boolean IsFound = false;
1138 final Iterator<Contact> iterator = this.contactController.allContacts().iterator();
1141 while (iterator.hasNext()) {
1143 final Contact next = iterator.next();
1146 if (ContactUtils.isSameContact(contact, next)) {
1147 // Yes, then abort loop
1158 * Updates all data in contact instance.
1160 * @param contact Contact instance
1162 private void updateContactData (final Contact contact) {
1163 // Contact instance should be valid
1164 if (null == contact) {
1166 throw new NullPointerException("contact is null"); //NOI18N
1167 } else if (contact.getContactId() == null) {
1169 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1170 } else if (contact.getContactId() < 1) {
1172 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1175 // Update all fields
1176 contact.setContactPersonalTitle(this.getPersonalTitle());
1177 contact.setContactTitle(this.getAcademicTitle());
1178 contact.setContactFirstName(this.getFirstName());
1179 contact.setContactFamilyName(this.getFamilyName());
1180 contact.setContactStreet(this.getStreet());
1181 contact.setContactHouseNumber(this.getHouseNumber());
1182 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1183 contact.setContactZipCode(this.getZipCode());
1184 contact.setContactCity(this.getCity());
1185 contact.setContactCountry(this.getContactCountry());
1187 // Update contact's cmobile number
1188 this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1190 // Update contact's land-line number
1191 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1193 // Update contact's fax number
1194 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());