2 * Copyright (C) 2016 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.pizzaapplication.beans.customer;
19 import javax.enterprise.context.SessionScoped;
20 import javax.faces.view.facelets.FaceletException;
21 import javax.inject.Named;
22 import javax.naming.Context;
23 import javax.naming.InitialContext;
24 import javax.naming.NamingException;
25 import org.mxchange.jcontacts.contact.Contact;
26 import org.mxchange.jcontacts.contact.UserContact;
27 import org.mxchange.jcontacts.contact.gender.Gender;
28 import org.mxchange.jcountry.data.Country;
29 import org.mxchange.jcustomercore.model.customer.Customer;
30 import org.mxchange.jcustomercore.model.customer.CustomerSessionBeanRemote;
31 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
32 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
33 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
34 import org.mxchange.jshopcore.model.customer.ShopCustomer;
37 * A customer bean which hides the customer instance
39 * @author Roland Haeder<roland@mxchange.org>
41 @Named ("customerController")
43 public class PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionController {
48 private static final long serialVersionUID = 542_145_347_916L;
50 /////////////////////// Properties /////////////////////
54 private DialableCellphoneNumber cellphoneNumber;
64 private String comment;
69 private Country country;
72 * Remote customer bean
74 private CustomerSessionBeanRemote customerBean;
79 private String emailAddress;
84 private String familyName;
89 private DialableFaxNumber faxNumber;
94 private String firstName;
99 private Gender gender;
104 private Short houseNumber;
109 private DialableLandLineNumber phoneNumber;
114 private String street;
119 private Integer zipCode;
122 * Default constructor
124 public PizzaCustomerWebSessionBean () {
125 // Set gender to UNKNOWN
126 this.gender = Gender.UNKNOWN;
130 // Get initial context
131 Context context = new InitialContext();
134 this.customerBean = (CustomerSessionBeanRemote) context.lookup("java:global/jshop-ejb/shop_customer!org.mxchange.jcustomercore.model.customer.CustomerSessionBeanRemote"); //NOI18N
135 } catch (final NamingException e) {
137 throw new FaceletException(e);
142 public Customer createCustomerInstance () {
144 //this.getLogger().logTrace("createInstance: CALLED!");
146 // Required personal data must be set
147 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
149 // Create new customer instance
150 Customer customer = new ShopCustomer();
152 // Create new contact
153 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
154 contact.setContactStreet(this.getStreet());
155 contact.setContactHouseNumber(this.getHouseNumber());
156 contact.setContactZipCode(this.getZipCode());
157 contact.setContactCity(this.getCity());
158 contact.setContactCountry(this.getCountry());
159 contact.setContactLandLineNumber(this.getPhoneNumber());
160 contact.setContactFaxNumber(this.getFaxNumber());
161 contact.setContactCellphoneNumber(this.getCellphoneNumber());
163 // Set contact in customer
164 customer.setContact(contact);
167 //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
173 public DialableCellphoneNumber getCellphoneNumber () {
174 return this.cellphoneNumber;
178 public void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) {
179 this.cellphoneNumber = cellphoneNumber;
183 public String getCity () {
188 public void setCity (final String city) {
193 public Country getCountry () {
198 public void setCountry (final Country country) {
199 this.country = country;
203 public String getEmailAddress () {
204 return this.emailAddress;
208 public void setEmailAddress (final String emailAddress) {
209 this.emailAddress = emailAddress;
213 public String getFamilyName () {
214 return this.familyName;
218 public void setFamilyName (final String familyName) {
219 this.familyName = familyName;
223 public DialableFaxNumber getFaxNumber () {
224 return this.faxNumber;
228 public void setFaxNumber (final DialableFaxNumber faxNumber) {
229 this.faxNumber = faxNumber;
233 public String getFirstName () {
234 return this.firstName;
238 public void setFirstName (final String firstName) {
239 this.firstName = firstName;
243 public Gender getGender () {
248 public void setGender (final Gender gender) {
249 this.gender = gender;
253 public Short getHouseNumber () {
254 return this.houseNumber;
258 public void setHouseNumber (final Short houseNumber) {
259 this.houseNumber = houseNumber;
263 public DialableLandLineNumber getPhoneNumber () {
264 return this.phoneNumber;
268 public void setPhoneNumber (final DialableLandLineNumber phoneNumber) {
269 this.phoneNumber = phoneNumber;
273 public String getStreet () {
278 public void setStreet (final String street) {
279 this.street = street;
283 public Integer getZipCode () {
288 public void setZipCode (final Integer zipCode) {
289 this.zipCode = zipCode;
293 public boolean isRequiredPersonalDataSet () {
294 return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));