X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fpizzaapplication%2Fbeans%2Fcustomer%2FCustomerWebBean.java;h=f61d35203afe94e67e56ea501d9a404587e15f9d;hb=ebebe1d437bc13032c5ff28130e8c3902b985e63;hp=13e9c27ac46393184202c9f063df49d3b7751afa;hpb=5268d45b0d65ad3de69ff51fa6f6257779973bc1;p=pizzaservice-war.git diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java index 13e9c27a..f61d3520 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java @@ -16,237 +16,276 @@ */ package org.mxchange.pizzaapplication.beans.customer; -import org.mxchange.jcore.client.Client; -import org.mxchange.jcore.contact.gender.Gender; -import org.mxchange.jshop.beans.FrameworkBean; +import javax.enterprise.context.SessionScoped; +import javax.faces.view.facelets.FaceletException; +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.UserContact; +import org.mxchange.jcontacts.contact.gender.Gender; +import org.mxchange.jshopcore.model.customer.Customer; +import org.mxchange.jshopcore.model.customer.CustomerSessionBeanRemote; +import org.mxchange.jshopcore.model.customer.ShopCustomer; /** - * An interface for customer beans - * - * @author Roland Haeder + * A customer bean which hides the customer instance + *

+ * @author Roland Haeder */ -public interface CustomerWebBean extends FrameworkBean { - /** - * Some "getter" for translated gender of the contact - * - * @return Translated / human-readable gender - */ - public String getTranslatedGender (); - - /** - * Gender of the contact - * - * @return the gender - */ - public Gender getGender (); - - /** - * Gender of the contact - * - * @param gender the gender to set - */ - public void setGender (final Gender gender); - - /** - * First name - * - * @return the first name - */ - public String getFirstName (); - - /** - * First name - * - * @param firstName the first name to set - */ - public void setFirstName (final String firstName); - - /** - * Family name - * - * @return the familyName - */ - public String getFamilyName (); - - /** - * Family name - * - * @param familyName the familyName to set - */ - public void setFamilyName (final String familyName); - - /** - * Companyname - * - * @return the companyName - */ - public String getCompanyName (); - - /** - * Companyname - * - * @param companyName the companyName to set - */ - public void setCompanyName (final String companyName); - - /** - * Street - * - * @return the street - */ - public String getStreet (); - - /** - * Street - * - * @param street the street to set - */ - public void setStreet (final String street); - - /** - * House number - * - * @return the houseNumber - */ - public Long getHouseNumber (); +@Named ("customerController") +@SessionScoped +public class CustomerWebBean implements CustomerWebController { /** - * House number - * - * @param houseNumber the houseNumber to set - */ - public void setHouseNumber (final Long houseNumber); - - /** - * ZIP code - * - * @return the zipCode + * Serial number */ - public Long getZipCode (); + private static final long serialVersionUID = 542_145_347_916L; + /////////////////////// Properties ///////////////////// /** - * ZIP code - * - * @param zipCode the zipCode to set - */ - public void setZipCode (final Long zipCode); - - /** - * City - * - * @return the city + * Cellphone number */ - public String getCity (); + private String cellphoneNumber; /** * City - * - * @param city the city to set */ - public void setCity (final String city); + private String city; /** - * Country code - * - * @return the countryCode + * Optional comments */ - public String getCountryCode (); + private String comment; /** * Country code - * - * @param countryCode the countryCode to set */ - public void setCountryCode (final String countryCode); + private String countryCode; /** - * Email address - * - * @return the emailAddress + * Remote customer bean */ - public String getEmailAddress (); + private final CustomerSessionBeanRemote customerBean; /** * Email address - * - * @param emailAddress the emailAddress to set - */ - public void setEmailAddress (final String emailAddress); - - /** - * Phone number - * - * @return the phoneNumber - */ - public String getPhoneNumber (); - - /** - * Phone number - * - * @param phoneNumber the phoneNumber to set */ - public void setPhoneNumber (final String phoneNumber); + private String emailAddress; /** - * Fax number - * - * @return the faxNumber + * Family name */ - public String getFaxNumber (); + private String familyName; /** * Fax number - * - * @param faxNumber the faxNumber to set */ - public void setFaxNumber (final String faxNumber); + private String faxNumber; /** - * Cellphone number - * - * @return the cellphoneNumber - */ - public String getCellphoneNumber (); - - /** - * Cellphone number - * - * @param cellphoneNumber the cellphoneNumber to set + * First name */ - public void setCellphoneNumber (final String cellphoneNumber); + private String firstName; /** - * Birth day - * - * @return the birthday + * Gender instance */ - public String getBirthday (); + private Gender gender; /** - * Birth day - * - * @param birthday the birthday to set + * House number */ - public void setBirthday (final String birthday); + private Short houseNumber; /** - * Comments - * - * @return the comment + * Phone number */ - public String getComment (); + private String phoneNumber; /** - * Comments - * - * @param comment the comment to set + * Street */ - public void setComment (final String comment); + private String street; /** - * Checks whether the contact is user's own data - * - * @return Own data? + * ZIP code */ - public boolean isOwnContact (); + private Integer zipCode; + + /** + * Default constructor + */ + public CustomerWebBean () { + // Set gender to UNKNOWN + this.gender = Gender.UNKNOWN; + + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer"); + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public Customer createCustomerInstance () { + // Trace message + //this.getLogger().logTrace("createInstance: CALLED!"); + + // Required personal data must be set + assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N + + // Create new customer instance + Customer customer = new ShopCustomer(); + + // Create new contact + Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); + contact.setStreet(this.getStreet()); + contact.setHouseNumber(this.getHouseNumber()); + contact.setZipCode(this.getZipCode()); + contact.setCity(this.getCity()); + contact.setPhoneNumber(this.getPhoneNumber()); + contact.setFaxNumber(this.getFaxNumber()); + contact.setCellphoneNumber(this.getCellphoneNumber()); + + // Set contact in customer + customer.setContact(contact); + + // Trace message + //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer)); + // Return it + return customer; + } + + @Override + public String getCellphoneNumber () { + return this.cellphoneNumber; + } + + @Override + public void setCellphoneNumber (final String cellphoneNumber) { + this.cellphoneNumber = cellphoneNumber; + } + + @Override + public String getCity () { + return this.city; + } + + @Override + public void setCity (final String city) { + this.city = city; + } + + @Override + public String getCountryCode () { + return this.countryCode; + } + + @Override + public void setCountryCode (final String countryCode) { + this.countryCode = countryCode; + } + + @Override + public String getEmailAddress () { + return this.emailAddress; + } + + @Override + public void setEmailAddress (final String emailAddress) { + this.emailAddress = emailAddress; + } + + @Override + public String getFamilyName () { + return this.familyName; + } + + @Override + public void setFamilyName (final String familyName) { + this.familyName = familyName; + } + + @Override + public String getFaxNumber () { + return this.faxNumber; + } + + @Override + public void setFaxNumber (final String faxNumber) { + this.faxNumber = faxNumber; + } + + @Override + public String getFirstName () { + return this.firstName; + } + + @Override + public void setFirstName (final String firstName) { + this.firstName = firstName; + } + + @Override + public Gender getGender () { + return this.gender; + } + + @Override + public void setGender (final Gender gender) { + this.gender = gender; + } + + @Override + public Short getHouseNumber () { + return this.houseNumber; + } + + @Override + public void setHouseNumber (final Short houseNumber) { + this.houseNumber = houseNumber; + } + + @Override + public String getPhoneNumber () { + return this.phoneNumber; + } + + @Override + public void setPhoneNumber (final String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + @Override + public String getStreet () { + return this.street; + } + + @Override + public void setStreet (final String street) { + this.street = street; + } + + @Override + public Integer getZipCode () { + return this.zipCode; + } + + @Override + public void setZipCode (final Integer zipCode) { + this.zipCode = zipCode; + } + + @Override + public boolean isRequiredPersonalDataSet () { + return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null)); + } }