]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/contact/JobsAdminContactWebRequestBean.java
No longer have templateType around + Gender.UNKNOWN is long time gone.
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / contact / JobsAdminContactWebRequestBean.java
index 41797abdaebc73e073cbf933a2a4670effff7051..ea6ad9664b990d3593b53259cfb0edd2c33814a4 100644 (file)
@@ -19,7 +19,6 @@ package org.mxchange.jjobs.beans.contact;
 import java.text.MessageFormat;
 import java.util.Date;
 import java.util.Iterator;
-import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
@@ -41,7 +40,9 @@ 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.jjobs.beans.helper.JobsAdminWebRequestController;
+import org.mxchange.jjobs.beans.BaseJobsController;
+import org.mxchange.jjobs.beans.helper.JobsWebRequestController;
+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;
@@ -57,7 +58,7 @@ import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
  */
 @Named ("adminContactController")
 @RequestScoped
-public class JobsAdminContactWebRequestBean implements JobsAdminContactWebRequestController {
+public class JobsAdminContactWebRequestBean extends BaseJobsController implements JobsAdminContactWebRequestController {
 
        /**
         * Serial number
@@ -75,7 +76,7 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
         * Admin helper instance
         */
        @Inject
-       private JobsAdminWebRequestController adminHelper;
+       private JobsWebRequestController beanHelper;
 
        /**
         * Birth day
@@ -213,6 +214,11 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
         */
        private String street;
 
+       /**
+        * Title
+        */
+       private String title;
+
        /**
         * An event fired when the administrator has updated contact data
         */
@@ -229,9 +235,6 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
         * Default constructor
         */
        public JobsAdminContactWebRequestBean () {
-               // Set gender to UNKNOWN
-               this.gender = Gender.UNKNOWN;
-
                // Try it
                try {
                        // Get initial context
@@ -289,15 +292,13 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
                // Fire event
                this.addedContactEvent.fire(new AdminContactAddedEvent(updatedContact));
 
+               // Clear this bean
+               this.clear();
+
                // Return outcome
                return "admin_list_contact"; //NOI18N
        }
 
-       @Override
-       public List<Contact> allContacts () {
-               return this.contactController.allContacts();
-       }
-
        @Override
        public void copyContactToController (final Contact contact) {
                // The contact instance must be valid
@@ -314,6 +315,7 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
 
                // Set all fields: contact
                this.setContactId(contact.getContactId());
+               this.setTitle(contact.getContactTitle());
                this.setBirthday(contact.getContactBirthday());
                this.setCity(contact.getContactCity());
                this.setComment(contact.getContactComment());
@@ -323,25 +325,32 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
                this.setFirstName(contact.getContactFirstName());
                this.setGender(contact.getContactGender());
                this.setHouseNumber(contact.getContactHouseNumber());
+               this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
                this.setStreet(contact.getContactStreet());
                this.setZipCode(contact.getContactZipCode());
 
                // ... cellphone data
-               this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId());
-               this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider());
-               this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber());
+               if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
+                       this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId());
+                       this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider());
+                       this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber());
+               }
 
                // ... fax data
-               this.setFaxId(contact.getContactFaxNumber().getPhoneId());
-               this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
-               this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
-               this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
+               if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+                       this.setFaxId(contact.getContactFaxNumber().getPhoneId());
+                       this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
+                       this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
+                       this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
+               }
 
                // .. land-line data
-               this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
-               this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
-               this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
-               this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
+               if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+                       this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
+                       this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
+                       this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
+                       this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
+               }
        }
 
        @Override
@@ -357,13 +366,13 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
                // 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
@@ -385,18 +394,18 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
        @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
@@ -415,6 +424,46 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
                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 () {
@@ -637,6 +686,16 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
                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;
@@ -647,11 +706,6 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
                this.zipCode = zipCode;
        }
 
-       @Override
-       public boolean hasContacts () {
-               return (!this.allContacts().isEmpty());
-       }
-
        /**
         * Post-initialization of this class
         */
@@ -665,11 +719,13 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
        private void clear () {
                // Clear all data
                // - personal data
-               this.setGender(Gender.UNKNOWN);
+               this.setGender(null);
+               this.setTitle(null);
                this.setFirstName(null);
                this.setFamilyName(null);
                this.setStreet(null);
                this.setHouseNumber(null);
+               this.setHouseNumberExtension(null);
                this.setZipCode(null);
                this.setCity(null);
                this.setCountry(null);
@@ -702,7 +758,7 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
                boolean IsFound = false;
 
                // Get iterator
-               Iterator<Contact> iterator = this.allContacts().iterator();
+               Iterator<Contact> iterator = this.contactController.allContacts().iterator();
 
                // Loop through all
                while (iterator.hasNext()) {
@@ -741,6 +797,7 @@ public class JobsAdminContactWebRequestBean implements JobsAdminContactWebReques
 
                // Update all fields
                contact.setContactGender(this.getGender());
+               contact.setContactTitle(this.getTitle());
                contact.setContactFirstName(this.getFirstName());
                contact.setContactFamilyName(this.getFamilyName());
                contact.setContactStreet(this.getStreet());