]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
added title (e.g. Dr., Prof. etc)
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / contact / PizzaAdminContactWebRequestBean.java
index 6fc5064897b3c367595910398e9ce8c08b58cd9d..94487af0287326b34d95c2a6d7e2f0dac975638c 100644 (file)
@@ -40,6 +40,7 @@ import org.mxchange.jcontacts.events.contact.update.AdminContactUpdatedEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
 import org.mxchange.jcountry.data.Country;
+import org.mxchange.jphone.phonenumbers.DialableNumber;
 import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
@@ -48,7 +49,7 @@ import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.phonenumbers.landline.LandLineNumber;
 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
 import org.mxchange.pizzaapplication.beans.BasePizzaController;
-import org.mxchange.pizzaapplication.beans.helper.PizzaAdminWebRequestController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController;
 
 /**
  * Administrative user bean (controller)
@@ -75,7 +76,7 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
         * Admin helper instance
         */
        @Inject
-       private PizzaAdminWebRequestController adminHelper;
+       private PizzaWebRequestController beanHelper;
 
        /**
         * Birth day
@@ -213,6 +214,11 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
         */
        private String street;
 
+       /**
+        * Title
+        */
+       private String title;
+
        /**
         * An event fired when the administrator has updated contact data
         */
@@ -235,7 +241,7 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
                        Context context = new InitialContext();
 
                        // Try to lookup
-                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+                       this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
                } catch (final NamingException e) {
                        // Throw again
                        throw new FaceletException(e);
@@ -294,6 +300,7 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
 
                // Set all fields: contact
                this.setContactId(contact.getContactId());
+               this.setTitle(contact.getContactTitle());
                this.setBirthday(contact.getContactBirthday());
                this.setCity(contact.getContactCity());
                this.setComment(contact.getContactComment());
@@ -442,18 +449,18 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
        @Override
        public String editContactData () {
                // Get contact instance
-               Contact contact = this.adminHelper.getContact();
+               Contact contact = this.beanHelper.getContact();
 
                // Check if contact instance is in helper and valid
                if (null == contact) {
                        // Throw NPE
-                       throw new NullPointerException("adminHelper.contact is null"); //NOI18N
+                       throw new NullPointerException("beanHelper.contact is null"); //NOI18N
                } else if (contact.getContactId() == null) {
                        // Throw NPE again
-                       throw new NullPointerException("adminHelper.contact.contactId is null"); //NOI18N //NOI18N
+                       throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
                } else if (contact.getContactId() < 1) {
                        // Invalid id
-                       throw new IllegalStateException(MessageFormat.format("adminHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+                       throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
                }
 
                // Update all data in contact
@@ -472,6 +479,46 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
                return "admin_list_contact"; //NOI18N
        }
 
+       @Override
+       public String generateCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) {
+               // Is it null?
+               if (null == cellphoneNumber) {
+                       // Return null
+                       return null;
+               }
+
+               // Get all data
+               String number = String.format(
+                          "%s%d%d", //NOI18N
+                          cellphoneNumber.getCellphoneProvider().getProviderCountry().getCountryExternalDialPrefix(),
+                          cellphoneNumber.getCellphoneProvider().getProviderDialPrefix(),
+                          cellphoneNumber.getPhoneNumber()
+          );
+
+               // Return it
+               return number;
+       }
+
+       @Override
+       public String generatePhoneNumber (final DialableNumber phoneNumber) {
+               // Is it null?
+               if (null == phoneNumber) {
+                       // Return null
+                       return null;
+               }
+
+               // Generate it
+               String number = String.format(
+                          "%s%d%d", //NOI18N
+                          phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
+                          phoneNumber.getPhoneAreaCode(),
+                          phoneNumber.getPhoneNumber()
+          );
+
+               // Return it
+               return number;
+       }
+
        @Override
        @SuppressWarnings ("ReturnOfDateField")
        public Date getBirthday () {
@@ -694,6 +741,16 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
                this.street = street;
        }
 
+       @Override
+       public String getTitle () {
+               return this.title;
+       }
+
+       @Override
+       public void setTitle (final String title) {
+               this.title = title;
+       }
+
        @Override
        public Integer getZipCode () {
                return this.zipCode;
@@ -718,6 +775,7 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
                // Clear all data
                // - personal data
                this.setGender(Gender.UNKNOWN);
+               this.setTitle(null);
                this.setFirstName(null);
                this.setFamilyName(null);
                this.setStreet(null);
@@ -793,6 +851,7 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme
 
                // Update all fields
                contact.setContactGender(this.getGender());
+               contact.setContactTitle(this.getTitle());
                contact.setContactFirstName(this.getFirstName());
                contact.setContactFamilyName(this.getFamilyName());
                contact.setContactStreet(this.getStreet());