*/
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
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
*/
-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 ();
+@Named ("customerController")
+@SessionScoped
+public class CustomerWebBean implements CustomerWebController {
/**
- * Street
- *
- * @param street the street to set
- */
- public void setStreet (final String street);
-
- /**
- * House number
- *
- * @return the houseNumber
+ * Serial number
*/
- public Long getHouseNumber ();
+ private static final long serialVersionUID = 542_145_347_916L;
+ /////////////////////// Properties /////////////////////
/**
- * House number
- *
- * @param houseNumber the houseNumber to set
- */
- public void setHouseNumber (final Long houseNumber);
-
- /**
- * ZIP code
- *
- * @return the zipCode
- */
- public Long getZipCode ();
-
- /**
- * 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 ();
+ private String emailAddress;
/**
- * Phone number
- *
- * @param phoneNumber the phoneNumber to set
- */
- public void setPhoneNumber (final String phoneNumber);
-
- /**
- * 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);
-
- /**
- * Cellphone number
- *
- * @return the cellphoneNumber
*/
- public String getCellphoneNumber ();
+ private String faxNumber;
/**
- * Cellphone number
- *
- * @param cellphoneNumber the cellphoneNumber to set
- */
- public void setCellphoneNumber (final String cellphoneNumber);
-
- /**
- * Birth day
- *
- * @return the birthday
+ * First name
*/
- public String getBirthday ();
+ private String firstName;
/**
- * Birth day
- *
- * @param birthday the birthday to set
+ * Gender instance
*/
- public void setBirthday (final String birthday);
+ private Gender gender;
/**
- * Comments
- *
- * @return the comment
+ * House number
*/
- public String getComment ();
+ private Short houseNumber;
/**
- * Comments
- *
- * @param comment the comment to set
+ * Phone number
*/
- public void setComment (final String comment);
+ private String phoneNumber;
/**
- * Checks whether the contact is user's own data
- *
- * @return Own data?
+ * Street
*/
- public boolean isOwnContact ();
+ private String street;
/**
- * Shows the contact to the user
- *
- * @param client Client instance to call back
+ * ZIP code
*/
- public void show (final Client client);
+ 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));
+ }
}