]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with customer:
authorRoland Häder <roland@mxchange.org>
Mon, 25 Apr 2016 16:19:28 +0000 (18:19 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 27 Apr 2016 20:05:40 +0000 (22:05 +0200)
- injected administrative contact controller
- added unfinished implementation of addCustomer()
- added private isCustomerDataSet()
- localContact was wrong here
- personal data is now together (better overview)
- added createContactInstance()

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java
src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java

index 30bce3d5ea0ff77d4bcca4b73bb77998288243ab..8e19458f970f7511c2977909beef2b5ad451d5da 100644 (file)
@@ -30,15 +30,19 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 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.add.AdminAddedContactEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminContactUpdatedEvent;
 import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
 import org.mxchange.jcountry.data.Country;
+import org.mxchange.jphone.phonenumbers.cellphone.CellphoneNumber;
 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.phonenumbers.fax.FaxNumber;
 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.helper.PizzaAdminWebRequestController;
 
@@ -322,6 +326,97 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ
                System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
        }
 
+       @Override
+       public Contact createContactInstance () {
+               // User message
+               //this.getLogger().logTrace("createContactInstance: CALLED!");
+
+               // Generate phone number
+               DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
+               DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
+               DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+
+               // Create new instance
+               Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
+
+               // Add all others
+               contact.setContactBirthday(this.getBirthday());
+               contact.setContactStreet(this.getStreet());
+               contact.setContactHouseNumber(this.getHouseNumber());
+               contact.setContactZipCode(this.getZipCode());
+               contact.setContactCity(this.getCity());
+               contact.setContactCountry(this.getCountry());
+               contact.setContactEmailAddress(this.getEmailAddress());
+               contact.setContactBirthday(this.getBirthday());
+               contact.setContactComment(this.getComment());
+
+               // Set ownContact
+               contact.setContactOwnContact(Boolean.TRUE);
+
+               // Don't set null or wrong references
+               if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
+                       // Now the number must be given
+                       if (phone.getPhoneAreaCode() == null) {
+                               // Is null
+                               throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
+                       } else if (phone.getPhoneAreaCode() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+                       } else if (phone.getPhoneNumber() == null) {
+                               // Is null
+                               throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
+                       } else if (phone.getPhoneNumber() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+                       }
+
+                       // Set phone number
+                       contact.setContactLandLineNumber(phone);
+               }
+
+               // Don't set null or wrong references
+               if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
+                       // Now the number must be given
+                       if (fax.getPhoneAreaCode() == null) {
+                               // Is null
+                               throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
+                       } else if (fax.getPhoneAreaCode() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
+                       } else if (fax.getPhoneNumber() == null) {
+                               // Is null
+                               throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
+                       } else if (fax.getPhoneNumber() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
+                       }
+
+                       // Set fax number
+                       contact.setContactFaxNumber(fax);
+               }
+
+               // Is the provider set?
+               if ((cellphone instanceof DialableCellphoneNumber) && (this.getCellphoneCarrier() instanceof MobileProvider) && (this.getCellphoneNumber() != null) && (this.getCellphoneNumber() > 0)) {
+                       // Is the number set?
+                       if (cellphone.getPhoneNumber() == null) {
+                               // Is null
+                               throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N
+                       } else if (cellphone.getPhoneNumber() < 1) {
+                               // Abort here
+                               throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N
+                       }
+
+                       // Set cellphone number
+                       contact.setContactCellphoneNumber(cellphone);
+               }
+
+               // Trace message
+               //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact));
+
+               // Return it
+               return contact;
+       }
+
        @Override
        public Date getBirthday () {
                return this.birthday;
index 3ca70436567cca063e7e12eec2192c6691bdd471..72b67b5dbf1b5913bf8cc6fe260d365718b6f885 100644 (file)
@@ -30,6 +30,13 @@ import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
  */
 public interface PizzaAdminContactWebRequestController extends Serializable {
 
+       /**
+        * Creates an instance from contact data
+        * <p>
+        * @return New contact instance
+        */
+       Contact createContactInstance ();
+
        /**
         * Copies given contact's data to this controller
         * <p>
index 9765921d1d78ac97ae1d2afbfede80bbd995fb92..0de36a385f6145b3eb9dc8b1f05442cc9a517981 100644 (file)
@@ -374,9 +374,6 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl
                // Required personal data must be set
                assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
 
-               // Create new contact instance
-               Contact localContact = new UserContact();
-
                // Generate phone number
                DialableLandLineNumber phone = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
                DialableCellphoneNumber cellphone = new CellphoneNumber(this.getCellphoneCarrier(), this.getCellphoneNumber());
@@ -390,6 +387,11 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl
                contact.setContactCity(this.getCity());
                contact.setContactCountry(this.getCountry());
                contact.setContactEmailAddress(this.getEmailAddress());
+               contact.setContactBirthday(this.getBirthday());
+               contact.setContactComment(this.getComment());
+
+               // Set ownContact
+               contact.setContactOwnContact(Boolean.TRUE);
 
                // Don't set null or wrong references
                if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) {
@@ -448,17 +450,11 @@ public class PizzaContactWebSessionBean implements PizzaContactWebSessionControl
                        contact.setContactCellphoneNumber(cellphone);
                }
 
-               contact.setContactBirthday(this.getBirthday());
-               contact.setContactComment(this.getComment());
-
-               // Created timestamp and ownContact
-               contact.setContactOwnContact(Boolean.TRUE);
-
                // Trace message
                //this.getLogger().logTrace(MessageFormat.format("createContactInstance: localContact={0} - EXIT!", localContact));
 
                // Return it
-               return localContact;
+               return contact;
        }
 
        @Override
index 9536ebecaea6ce7f4aecc7e7f072600a3e4a868f..bde39ab1fe2ea60d133c9e7945682a5d6baffa62 100644 (file)
@@ -21,11 +21,16 @@ import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
 import javax.faces.view.facelets.FaceletException;
+import javax.inject.Inject;
 import javax.inject.Named;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.gender.Gender;
 import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
+import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
 import org.mxchange.pizzaapplication.model.customer.PizzaAdminCustomerSessionBeanRemote;
 
 /**
@@ -42,6 +47,12 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe
         */
        private static final long serialVersionUID = 12_487_062_487_527_913L;
 
+       /**
+        * Administrative contact controller (for personal data)
+        */
+       @Inject
+       private PizzaAdminContactWebRequestController adminContactController;
+
        /**
         * Administrative customer EJB
         */
@@ -69,6 +80,24 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe
                }
        }
 
+       @Override
+       public String addCustomer () {
+               // Are at least some fields added?
+               if (!this.isCustomerDataSet()) {
+                       // Not all customer data is set
+                       throw new FaceletException("PLease provide minimum personal data: gender, first_name, family_name");
+               }
+
+               // Get contact instance
+               Contact contact = this.adminContactController.createContactInstance();
+
+               // Ask the EJB for a free customer number
+               String customerNumber = this.adminCustomerBean.createCustomerNumber();
+
+               // Create new customer instance
+               Customer customer = new PizzaCustomer(CustomerAccountStatus.CONFIRMED, contact, customerNumber);
+       }
+
        @Override
        public List<Customer> allCustomers () {
                // Return it
@@ -89,4 +118,18 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe
                this.customerList = this.adminCustomerBean.allCustomers();
        }
 
+       /**
+        * Checks whether ther minimum customer data is set
+        * <p>
+        * @return Whether minimum data is set
+        */
+       private boolean isCustomerDataSet () {
+               // Check all
+               return ((this.adminContactController.getGender() instanceof Gender) &&
+                               (this.adminContactController.getFirstName() != null) &&
+                               (!this.adminContactController.getFirstName().isEmpty()) &&
+                               (this.adminContactController.getFamilyName() != null) &&
+                               (!this.adminContactController.getFamilyName().isEmpty()));
+       }
+
 }
index daddfd88ddb521507f8211722762c0c3bb529848..9aa71b0e8b443186b04dd79e3d5b6b0f050b9d11 100644 (file)
@@ -41,4 +41,12 @@ public interface PizzaAdminCustomerWebRequestController extends Serializable {
         */
        boolean hasCustomers ();
 
+       /**
+        * Adds customer to database if not already added. This method should return
+        * a redirect outcome on success.
+        * <p>
+        * @return Redirect outcome
+        */
+       String addCustomer ();
+
 }