From ba688644b7ce06a99fdabd6df35eaefbbd834127 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 22 Apr 2016 15:54:24 +0200 Subject: [PATCH] Continued with rewriting: - rewrote to ContactUtils.updateFooNumber() - added missing attributes for above functions - added check for contactId against null - fixed converter (must be ContactConverter) + instance from helper --- ...AddressbookAdminContactWebRequestBean.java | 46 +++++++++-------- .../AddressbookContactWebSessionBean.java | 51 +++++++++---------- web/admin/contact/admin_contact_edit.xhtml | 4 +- 3 files changed, 50 insertions(+), 51 deletions(-) diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java index 554d404b..415ba6cc 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookAdminContactWebRequestBean.java @@ -42,7 +42,7 @@ import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; /** - * A user bean (controller) + * An administrative user bean (controller) *

* @author Roland Haeder */ @@ -158,6 +158,21 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo */ private Short houseNumber; + /** + * Whether a cellphone entry has been unlinked + */ + private boolean isCellphoneUnlinked; + + /** + * Whether a fax entry has been unlinked + */ + private boolean isFaxUnlinked; + + /** + * Whether a land-line number has been unlinked + */ + private boolean isLandLineUnlinked; + /** * Land-line id number */ @@ -236,7 +251,7 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo this.updateContactData(contact); // Call EJB for updating contact data - Contact updatedContact = this.contactBean.updateContactPersonalData(contact); + Contact updatedContact = this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); // Fire event this.updatedContactEvent.fire(new AdminContactUpdatedEvent(updatedContact)); @@ -251,6 +266,9 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo if (null == contact) { // Throw NPE again throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw NPE again + throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N } else if (contact.getContactId() < 1) { // Not valid throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N @@ -554,27 +572,13 @@ public class AddressbookAdminContactWebRequestBean implements AddressbookAdminCo contact.setContactCountry(this.getCountry()); // Update contact's cellphone number - ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber()); + this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber()); - // Is there a phone number? - if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Debug message - System.out.println(MessageFormat.format("updateContactData: phoneId={0}", contact.getContactLandLineNumber().getPhoneId())); //NOI18N + // Update contact's land-line number + this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); - // Yes, then update as well - contact.getContactLandLineNumber().setPhoneAreaCode(this.getPhoneAreaCode()); - contact.getContactLandLineNumber().setPhoneNumber(this.getPhoneNumber()); - } - - // Is there a fax number? - if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Debug message - System.out.println(MessageFormat.format("updateContactData: faxId={0}", contact.getContactFaxNumber().getPhoneId())); //NOI18N - - // Yes, then update as well - contact.getContactFaxNumber().setPhoneAreaCode(this.getFaxAreaCode()); - contact.getContactFaxNumber().setPhoneNumber(this.getFaxNumber()); - } + // Update contact's fax number + this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); } } diff --git a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java index 66295f55..3f584aa6 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebSessionBean.java @@ -35,6 +35,7 @@ import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; import org.mxchange.jcontacts.contact.UserContact; import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jcontacts.contact.utils.ContactUtils; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; @@ -153,6 +154,21 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe */ private Short houseNumber; + /** + * Whether a cellphone entry has been unlinked + */ + private boolean isCellphoneUnlinked; + + /** + * Whether a fax entry has been unlinked + */ + private boolean isFaxUnlinked; + + /** + * Whether a land-line number has been unlinked + */ + private boolean isLandLineUnlinked; + /** * Login bean (controller) */ @@ -477,38 +493,17 @@ public class AddressbookContactWebSessionBean implements AddressbookContactWebSe contact.setContactCity(this.getCity()); contact.setContactCountry(this.getCountry()); - // Is there a phone number? - if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Debug message - System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: phoneId={0}", contact.getContactLandLineNumber().getPhoneId())); //NOI18N - - // Yes, then update as well - contact.getContactLandLineNumber().setPhoneAreaCode(this.getPhoneAreaCode()); - contact.getContactLandLineNumber().setPhoneNumber(this.getPhoneNumber()); - } + // Update contact's cellphone number + this.isCellphoneUnlinked = ContactUtils.updateCellPhoneNumber(contact, this.getCellphoneCarrier(), this.getCellphoneNumber()); - // Is there a fax number? - if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Debug message - System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: faxId={0}", contact.getContactFaxNumber().getPhoneId())); //NOI18N + // Update contact's land-line number + this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); - // Yes, then update as well - contact.getContactFaxNumber().setPhoneAreaCode(this.getFaxAreaCode()); - contact.getContactFaxNumber().setPhoneNumber(this.getFaxNumber()); - } - - // Is there a cellphone number? - if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) { - // Debug message - System.out.println(MessageFormat.format("ContactWebBean:doChangePersonalData: cellPhoneId={0}", contact.getContactCellphoneNumber().getPhoneId())); //NOI18N - - // Yes, then update as well - contact.getContactCellphoneNumber().setCellphoneProvider(this.getCellphoneCarrier()); - contact.getContactCellphoneNumber().setPhoneNumber(this.getCellphoneNumber()); - } + // Update contact's fax number + this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); // Send it to the EJB - this.contactBean.updateContactPersonalData(contact); + this.contactBean.updateContactData(contact, this.isCellphoneUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); // All fine return "contact_data_saved"; //NOI18N diff --git a/web/admin/contact/admin_contact_edit.xhtml b/web/admin/contact/admin_contact_edit.xhtml index 1df661ec..386f9ea2 100644 --- a/web/admin/contact/admin_contact_edit.xhtml +++ b/web/admin/contact/admin_contact_edit.xhtml @@ -9,7 +9,7 @@ > - + @@ -23,7 +23,7 @@ - +

#{msg.ADMIN_EDIT_CONTACT_TITLE} -- 2.39.5