]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with rewriting:
authorRoland Haeder <roland@mxchange.org>
Fri, 22 Apr 2016 13:54:24 +0000 (15:54 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 23 Apr 2016 11:07:56 +0000 (13:07 +0200)
- rewrote to ContactUtils.updateFooNumber()
- added missing attributes for above functions
- added check for contactId against null
- fixed converter (must be ContactConverter) + instance from helper

src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java
web/admin/contact/admin_contact_edit.xhtml

index d9857c7ab09a1a33edd0b2c3b71cf71855c9ac1d..4c6d703f58d29c569e177b6351086ec8a90f3998 100644 (file)
@@ -43,7 +43,7 @@ import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
 import org.mxchange.pizzaapplication.beans.helper.PizzaAdminWebRequestController;
 
 /**
- * A user bean (controller)
+ * An administrative user bean (controller)
  * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
@@ -159,6 +159,21 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ
         */
        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
         */
@@ -237,7 +252,7 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ
                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));
@@ -255,6 +270,9 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ
                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
@@ -570,27 +588,13 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ
                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());
        }
 
 }
index 2ca7817a8ea0d4f9be9d3a059c622a00a17e6d37..9765921d1d78ac97ae1d2afbfede80bbd995fb92 100644 (file)
@@ -34,6 +34,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 PizzaContactWebSessionBean implements PizzaContactWebSessionControl
         */
        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 PizzaContactWebSessionBean implements PizzaContactWebSessionControl
                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
index 1df661ecc4d9664bd7db15933883a771e840fb18..386f9ea267e5fe06595ae8a3e3b130370511393d 100644 (file)
@@ -9,7 +9,7 @@
        >
 
        <f:metadata>
-               <f:viewParam name="contactId" value="#{adminHelper.contact}" converter="UserConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CONTACT_ID_NOT_SET}" />
+               <f:viewParam name="contactId" value="#{adminHelper.contact}" converter="ContactConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CONTACT_ID_NOT_SET}" />
                <f:viewAction action="#{adminHelper.copyContactToController()}" />
        </f:metadata>
 
@@ -23,7 +23,7 @@
                <ui:define name="content">
                        <h:outputText styleClass="errors" value="#{msg.ERROR_CONTACT_ID_NOT_FOUND}" rendered="#{empty adminHelper.contact}" />
 
-                       <h:form id="admin_edit_user" rendered="#{not empty adminHelper.user}">
+                       <h:form id="admin_edit_user" rendered="#{not empty adminHelper.contact}">
                                <div class="table">
                                        <div class="table_header">
                                                #{msg.ADMIN_EDIT_CONTACT_TITLE}