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.inject.Any;
26 import javax.faces.context.FacesContext;
27 import javax.faces.view.facelets.FaceletException;
28 import javax.inject.Inject;
29 import javax.inject.Named;
30 import javax.naming.Context;
31 import javax.naming.InitialContext;
32 import javax.naming.NamingException;
33 import org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote;
34 import org.mxchange.jcontacts.contact.Contact;
35 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
36 import org.mxchange.jcontacts.contact.ContactUtils;
37 import org.mxchange.jcontacts.contact.UserContact;
38 import org.mxchange.jcontacts.contact.title.PersonalTitle;
39 import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
40 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
41 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
42 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
43 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
44 import org.mxchange.jcountry.data.Country;
45 import org.mxchange.jjobs.beans.BaseJobsController;
46 import org.mxchange.jjobs.beans.helper.JobsWebRequestHelperController;
47 import org.mxchange.jphone.phonenumbers.DialableNumber;
48 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
49 import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
50 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
51 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
52 import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
53 import org.mxchange.jphone.phonenumbers.mobile.MobileNumber;
54 import org.mxchange.jphone.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 BaseJobsController 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 private AdminContactSessionBeanRemote adminContactBean;
88 * Bean helper instance
91 private JobsWebRequestHelperController beanHelper;
96 private Date birthday;
106 private String comment;
109 * Remote contact bean
111 private ContactSessionBeanRemote contactBean;
114 * General contact controller
117 private JobsContactWebSessionController contactController;
122 private Long contactId;
127 private Country contactCountry;
132 private String emailAddress;
137 private String familyName;
140 * Fax number's area code
142 private Integer faxAreaCode;
145 * Country instance for fax number
147 private Country faxCountry;
157 private Long faxNumber;
162 private String firstName;
167 private Short houseNumber;
170 * House number extension
172 private String houseNumberExtension;
175 * Whether a fax entry has been unlinked
177 private boolean isFaxUnlinked;
180 * Whether a land-line number has been unlinked
182 private boolean isLandLineUnlinked;
185 * Whether a cmobile entry has been unlinked
187 private boolean isMobileNumberUnlinked;
190 * Phone number area code
192 private Integer landLineAreaCode;
195 * Country instance for phone number
197 private Country landLineCountry;
200 * Land-line id number
202 private Long landLineId;
207 private Long landLineNumber;
212 private Long mobileId;
217 private Long mobileNumber;
220 * Mobile number's provider
222 private MobileProvider mobileProvider;
225 * PersonalTitle instance
227 private PersonalTitle personalTitle;
232 private String street;
235 * An event fired when the administrator has updated contact data
239 private Event<ObservableAdminUpdatedContactEvent> updatedContactEvent;
244 private Integer zipCode;
247 * Default constructor
249 public JobsAdminContactWebRequestBean () {
250 // Call super constructor
255 * Adds contact data to database and redirects on success. If the contact is
256 * already found, a proper exception is thrown.
258 * @return Redirect outcome
260 public String addContact () {
261 // Are all minimum fields set?
262 if (this.getPersonalTitle() == null) {
264 throw new NullPointerException("personalTitle is null"); //NOI18N
265 } else if (this.getFirstName() == null) {
267 throw new NullPointerException("firstName is null"); //NOI18N
268 } else if (this.getFirstName().isEmpty()) {
270 throw new IllegalStateException("firstName is empty"); //NOI18N
271 } else if (this.getFamilyName() == null) {
273 throw new NullPointerException("familyName is null"); //NOI18N
274 } else if (this.getFamilyName().isEmpty()) {
276 throw new IllegalStateException("familyName is empty"); //NOI18N
279 // Create new contact instance
280 Contact contact = this.createContactInstance();
282 // Default is not same contact
283 if (this.isSameContactFound(contact)) {
284 // Already registered
285 throw new FaceletException(new ContactAlreadyAddedException(contact));
289 Contact updatedContact;
294 updatedContact = this.adminContactBean.addContact(contact);
295 } catch (final ContactAlreadyAddedException ex) {
297 throw new FaceletException(ex);
301 this.addedContactEvent.fire(new AdminAddedContactEvent(updatedContact));
307 return "admin_list_contact"; //NOI18N
311 public void copyContactToController (final Contact contact) {
313 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N
315 // The contact instance must be valid
316 if (null == contact) {
318 throw new NullPointerException("contact is null"); //NOI18N
319 } else if (contact.getContactId() == null) {
321 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
322 } else if (contact.getContactId() < 1) {
324 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
327 // Set all fields: contact
328 this.setContactId(contact.getContactId());
329 this.setAcademicTitle(contact.getContactTitle());
330 this.setBirthday(contact.getContactBirthday());
331 this.setCity(contact.getContactCity());
332 this.setComment(contact.getContactComment());
333 this.setContactCountry(contact.getContactCountry());
334 this.setEmailAddress(contact.getContactEmailAddress());
335 this.setFamilyName(contact.getContactFamilyName());
336 this.setFirstName(contact.getContactFirstName());
337 this.setPersonalTitle(contact.getContactPersonalTitle());
338 this.setHouseNumber(contact.getContactHouseNumber());
339 this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
340 this.setStreet(contact.getContactStreet());
341 this.setZipCode(contact.getContactZipCode());
343 // Is the cell phone set?
344 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
346 this.setMobileId(contact.getContactMobileNumber().getPhoneId());
347 this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
348 this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
352 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
354 this.setFaxId(contact.getContactFaxNumber().getPhoneId());
355 this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
356 this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
357 this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
360 // Is the land-line number set?
361 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
363 this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
364 this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
365 this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
366 this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
370 //* NOISY-DEBUG: */ System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
374 public Contact createContactInstance () {
375 // Are all minimum fields set?
376 if (this.getPersonalTitle() == null) {
378 throw new NullPointerException("personalTitle is null"); //NOI18N
379 } else if (this.getFirstName() == null) {
381 throw new NullPointerException("firstName is null"); //NOI18N
382 } else if (this.getFirstName().isEmpty()) {
384 throw new IllegalStateException("firstName is empty"); //NOI18N
385 } else if (this.getFamilyName() == null) {
387 throw new NullPointerException("familyName is null"); //NOI18N
388 } else if (this.getFamilyName().isEmpty()) {
390 throw new IllegalStateException("familyName is empty"); //NOI18N
393 // Generate phone number
394 DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
395 DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
396 DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
398 // Create new instance
399 Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
402 contact.setContactTitle(this.getAcademicTitle());
403 contact.setContactBirthday(this.getBirthday());
404 contact.setContactStreet(this.getStreet());
405 contact.setContactHouseNumber(this.getHouseNumber());
406 contact.setContactZipCode(this.getZipCode());
407 contact.setContactCity(this.getCity());
408 contact.setContactCountry(this.getContactCountry());
409 contact.setContactEmailAddress(this.getEmailAddress());
410 contact.setContactBirthday(this.getBirthday());
411 contact.setContactComment(this.getComment());
414 contact.setContactOwnContact(Boolean.TRUE);
416 // Don't set null or wrong references
417 if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
418 // Now the number must be given
419 if (landLine.getPhoneAreaCode() == null) {
421 throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
422 } else if (landLine.getPhoneAreaCode() < 1) {
424 throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
425 } else if (landLine.getPhoneNumber() == null) {
427 throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
428 } else if (landLine.getPhoneNumber() < 1) {
430 throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
434 contact.setContactLandLineNumber(landLine);
437 // Don't set null or wrong references
438 if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
439 // Now the number must be given
440 if (fax.getPhoneAreaCode() == null) {
442 throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
443 } else if (fax.getPhoneAreaCode() < 1) {
445 throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
446 } else if (fax.getPhoneNumber() == null) {
448 throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
449 } else if (fax.getPhoneNumber() < 1) {
451 throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
455 contact.setContactFaxNumber(fax);
458 // Is the provider set?
459 if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
460 // Is the number set?
461 if (mobile.getPhoneNumber() == null) {
463 throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
464 } else if (mobile.getPhoneNumber() < 1) {
466 throw new IllegalArgumentException("cmobile.phoneNumber is zero or below."); //NOI18N
469 // Set cmobile number
470 contact.setContactMobileNumber(mobile);
478 * Edits currently loaded contact's data in database.
480 * @return Redirect outcome
482 public String editContactData () {
483 // Get contact instance
484 Contact contact = this.beanHelper.getContact();
486 // Check if contact instance is in helper and valid
487 if (null == contact) {
489 throw new NullPointerException("beanHelper.contact is null"); //NOI18N
490 } else if (contact.getContactId() == null) {
492 throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
493 } else if (contact.getContactId() < 1) {
495 throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
498 // Update all data in contact
499 this.updateContactData(contact);
501 // Call EJB for updating contact data
502 Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
505 this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
510 // Return to contact list (for now)
511 return "admin_list_contact"; //NOI18N
515 * Returns a text representation of given mobile number or null if not set.
517 * @param mobileNumber Mobile number
519 * @return Text representation or null
521 public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
523 if (null == mobileNumber) {
529 String number = String.format(
531 mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
532 mobileNumber.getMobileProvider().getProviderDialPrefix(),
533 mobileNumber.getPhoneNumber()
541 * Returns a text representation of given land-line or fax number or null if
544 * @param phoneNumber Land-line or fax number
546 * @return Text representation or null
548 public String generatePhoneNumber (final DialableNumber phoneNumber) {
550 if (null == phoneNumber) {
556 String number = String.format(
558 phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
559 phoneNumber.getPhoneAreaCode(),
560 phoneNumber.getPhoneNumber()
568 * Getter for academic title
570 * @return Academic title
572 public String getAcademicTitle () {
573 return this.academicTitle;
577 * Setter for academic title
579 * @param academicTitle Academic title
581 public void setAcademicTitle (final String academicTitle) {
582 this.academicTitle = academicTitle;
586 * Getter for birth day
590 @SuppressWarnings ("ReturnOfDateField")
591 public Date getBirthday () {
592 return this.birthday;
596 * Setter for birth day
598 * @param birthday Birth day
600 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
601 public void setBirthday (final Date birthday) {
602 this.birthday = birthday;
606 * Getter for city name
610 public String getCity () {
615 * Setter for city name
617 * @param city City name
619 public void setCity (final String city) {
624 * Getter for comments
628 public String getComment () {
635 * @param comment Comments
637 public void setComment (final String comment) {
638 this.comment = comment;
642 * Getter for contact id
646 public Long getContactId () {
647 return this.contactId;
651 * Setter for contact id
653 * @param contactId Contact id
655 public void setContactId (final Long contactId) {
656 this.contactId = contactId;
660 public String getControllerType () {
661 return "admin"; //NOI18N
666 public void setControllerType (final String controllerType) {
667 throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
671 * Getter for contactCountry instance
673 * @return Country instance
675 public Country getContactCountry () {
676 return this.contactCountry;
680 * Setter for contactCountry instance
682 * @param contactCountry Country instance
684 public void setContactCountry (final Country contactCountry) {
685 this.contactCountry = contactCountry;
689 * Getter for email address
691 * @return Email address
693 public String getEmailAddress () {
694 return this.emailAddress;
698 * Setter for email address
700 * @param emailAddress Email address
702 public void setEmailAddress (final String emailAddress) {
703 this.emailAddress = emailAddress;
709 * @return the familyName
711 public String getFamilyName () {
712 return this.familyName;
718 * @param familyName the familyName to set
720 public void setFamilyName (final String familyName) {
721 this.familyName = familyName;
725 * Getter for fax number's area code
727 * @return Fax number's area code
729 public Integer getFaxAreaCode () {
730 return this.faxAreaCode;
734 * Setter for fax number's area code
736 * @param faxAreaCode Fax number's area code
738 public void setFaxAreaCode (final Integer faxAreaCode) {
739 this.faxAreaCode = faxAreaCode;
743 * Getter for fax's country instance
745 * @return Fax' country instance
747 public Country getFaxCountry () {
748 return this.faxCountry;
752 * Setter for fax's country instance
754 * @param faxCountry Fax' country instance
756 public void setFaxCountry (final Country faxCountry) {
757 this.faxCountry = faxCountry;
765 public Long getFaxId () {
772 * @param faxId Fax id
774 public void setFaxId (final Long faxId) {
779 * Getter for fax number
783 public Long getFaxNumber () {
784 return this.faxNumber;
788 * Setter for fax number
790 * @param faxNumber Fax number
792 public void setFaxNumber (final Long faxNumber) {
793 this.faxNumber = faxNumber;
797 * Getter for first name
801 public String getFirstName () {
802 return this.firstName;
806 * Setter for first name
808 * @param firstName First name
810 public void setFirstName (final String firstName) {
811 this.firstName = firstName;
815 * Getter for house number
817 * @return House number
819 public Short getHouseNumber () {
820 return this.houseNumber;
824 * Setter for house number
826 * @param houseNumber House number
828 public void setHouseNumber (final Short houseNumber) {
829 this.houseNumber = houseNumber;
833 * Getter for house number extension. Example: 123a, 'a' is the extension
834 * and 123 is the house number.
836 * @return House number extension
838 public String getHouseNumberExtension () {
839 return this.houseNumberExtension;
843 * Setter for house number extension
845 * @param houseNumberExtension House number extension
847 public void setHouseNumberExtension (final String houseNumberExtension) {
848 this.houseNumberExtension = houseNumberExtension;
852 * Getter for land-line number's area code
854 * @return Land-line number's area code
856 public Integer getLandLineAreaCode () {
857 return this.landLineAreaCode;
861 * Setter for land-line number's area code
863 * @param landLineAreaCode Land-line number's area code
865 public void setLandLineAreaCode (final Integer landLineAreaCode) {
866 this.landLineAreaCode = landLineAreaCode;
870 * Getter for land-line number's country instance
872 * @return Land-line number's country instance
874 public Country getLandLineCountry () {
875 return this.landLineCountry;
879 * Setter for land-line number's country instance
881 * @param landLineCountry Land-line number's country instance
883 public void setLandLineCountry (final Country landLineCountry) {
884 this.landLineCountry = landLineCountry;
888 * Getter for land-line id
890 * @return Land-line id
892 public Long getLandLineId () {
893 return this.landLineId;
897 * Setter for land-line id
899 * @param landLineId Land-line id
901 public void setLandLineId (final Long landLineId) {
902 this.landLineId = landLineId;
906 * Getter for land-line number
908 * @return Land-line number
910 public Long getLandLineNumber () {
911 return this.landLineNumber;
915 * Setter for land-line number
917 * @param landLineNumber Land-line number
919 public void setLandLineNumber (final Long landLineNumber) {
920 this.landLineNumber = landLineNumber;
924 * Getter for mobile id
928 public Long getMobileId () {
929 return this.mobileId;
933 * Setter for mobile id
935 * @param mobileId Mobile id
937 public void setMobileId (final Long mobileId) {
938 this.mobileId = mobileId;
942 * Getter for mobile number
944 * @return Mobile number
946 public Long getMobileNumber () {
947 return this.mobileNumber;
951 * Setter for mobile number
953 * @param mobileNumber Mobile number
955 public void setMobileNumber (final Long mobileNumber) {
956 this.mobileNumber = mobileNumber;
960 * Getter for mobile number's carrier
962 * @return Mobile number's carrier
964 public MobileProvider getMobileProvider () {
965 return this.mobileProvider;
969 * Setter for mobile number's carrier prefix
971 * @param mobileProvider Mobile number's carrier prefix
973 public void setMobileProvider (final MobileProvider mobileProvider) {
974 this.mobileProvider = mobileProvider;
978 * Getter for personal title
980 * @return Personal title
982 public PersonalTitle getPersonalTitle () {
983 return this.personalTitle;
987 * Setter for personal title
989 * @param personalTitle Personal title
991 public void setPersonalTitle (final PersonalTitle personalTitle) {
992 this.personalTitle = personalTitle;
996 * Getter for street name
998 * @return Street name
1000 public String getStreet () {
1005 * Setter for street name
1007 * @param street Street name
1009 public void setStreet (final String street) {
1010 this.street = street;
1014 * Getter for ZIP code
1018 public Integer getZipCode () {
1019 return this.zipCode;
1023 * Setter for ZIP code
1025 * @param zipCode ZIP code
1027 public void setZipCode (final Integer zipCode) {
1028 this.zipCode = zipCode;
1032 * Post-initialization of this class
1035 public void init () {
1038 // Get initial context
1039 Context context = new InitialContext();
1042 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
1044 // Try to lookup (administative)
1045 this.adminContactBean = (AdminContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminContact!org.mxchange.jcontacts.contact.AdminContactSessionBeanRemote"); //NOI18N
1046 } catch (final NamingException e) {
1048 throw new FaceletException(e);
1054 public boolean isPersonalTitleRequired () {
1055 // Get context parameter
1056 String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_admin_personal_title_enabled"); //NOI18N
1059 boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
1066 public void validateContactData () {
1067 if (this.getPersonalTitle() == null) {
1069 throw new NullPointerException("contactController.gender is null"); //NOI18N
1070 } else if (this.getFirstName() == null) {
1072 throw new NullPointerException("contactController.firstName is null"); //NOI18N
1073 } else if (this.getFirstName().isEmpty()) {
1075 throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N
1076 } else if (this.getFamilyName() == null) {
1078 throw new NullPointerException("contactController.familyName is null"); //NOI18N
1079 } else if (this.getFamilyName().isEmpty()) {
1081 throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N
1082 } else if (this.getEmailAddress() == null) {
1084 throw new NullPointerException("contactController.emailAddress is null"); //NOI18N
1085 } else if (this.getEmailAddress().isEmpty()) {
1087 throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N
1094 private void clear () {
1097 this.setAcademicTitle(null);
1098 this.setFirstName(null);
1099 this.setFamilyName(null);
1100 this.setStreet(null);
1101 this.setHouseNumber(null);
1102 this.setHouseNumberExtension(null);
1103 this.setZipCode(null);
1105 this.setContactCountry(null);
1108 this.setEmailAddress(null);
1109 this.setLandLineCountry(null);
1110 this.setLandLineAreaCode(null);
1111 this.setLandLineNumber(null);
1112 this.setMobileProvider(null);
1113 this.setMobileNumber(null);
1114 this.setFaxCountry(null);
1115 this.setFaxAreaCode(null);
1116 this.setFaxNumber(null);
1119 this.setBirthday(null);
1120 this.setComment(null);
1124 * Checks whether the given contact is found
1126 * @param contact Contact inastance
1128 * @return Wether contact has been found
1130 private boolean isSameContactFound (final Contact contact) {
1131 // Default is not found
1132 boolean IsFound = false;
1135 Iterator<Contact> iterator = this.contactController.allContacts().iterator();
1138 while (iterator.hasNext()) {
1140 Contact next = iterator.next();
1143 if (ContactUtils.isSameContact(contact, next)) {
1144 // Yes, then abort loop
1155 * Updates all data in contact instance.
1157 * @param contact Contact instance
1159 private void updateContactData (final Contact contact) {
1160 // Contact instance should be valid
1161 if (null == contact) {
1163 throw new NullPointerException("contact is null"); //NOI18N
1164 } else if (contact.getContactId() == null) {
1166 throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
1167 } else if (contact.getContactId() < 1) {
1169 throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
1172 // Update all fields
1173 contact.setContactPersonalTitle(this.getPersonalTitle());
1174 contact.setContactTitle(this.getAcademicTitle());
1175 contact.setContactFirstName(this.getFirstName());
1176 contact.setContactFamilyName(this.getFamilyName());
1177 contact.setContactStreet(this.getStreet());
1178 contact.setContactHouseNumber(this.getHouseNumber());
1179 contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
1180 contact.setContactZipCode(this.getZipCode());
1181 contact.setContactCity(this.getCity());
1182 contact.setContactCountry(this.getContactCountry());
1184 // Update contact's cmobile number
1185 this.isMobileNumberUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
1187 // Update contact's land-line number
1188 this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
1190 // Update contact's fax number
1191 this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());