From: Roland Häder Date: Mon, 25 Apr 2016 16:19:28 +0000 (+0200) Subject: Continued with customer: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2b3a9035147c2f9b97a54a41ee0851d8dec3e6ca;p=pizzaservice-war.git Continued with customer: - 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 --- diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java index 30bce3d5..8e19458f 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java @@ -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; diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java index 3ca70436..72b67b5d 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java @@ -30,6 +30,13 @@ import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; */ public interface PizzaAdminContactWebRequestController extends Serializable { + /** + * Creates an instance from contact data + *

+ * @return New contact instance + */ + Contact createContactInstance (); + /** * Copies given contact's data to this controller *

diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java index 9765921d..0de36a38 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java @@ -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 diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java index 9536ebec..bde39ab1 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java @@ -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 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 + *

+ * @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())); + } + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java index daddfd88..9aa71b0e 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java @@ -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. + *

+ * @return Redirect outcome + */ + String addCustomer (); + }