2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (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 General Public License for more details.
14 * You should have received a copy of the GNU 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.jshopcore.model.customer.Customer;
29 import org.mxchange.jshopcore.model.customer.CustomerSessionBeanRemote;
30 import org.mxchange.jshopcore.model.customer.ShopCustomer;
33 * A customer bean which hides the customer instance
35 * @author Roland Haeder<roland@mxchange.org>
37 @Named ("customerController")
39 public class CustomerWebBean implements CustomerWebController {
44 private static final long serialVersionUID = 542_145_347_916L;
46 /////////////////////// Properties /////////////////////
50 private String cellphoneNumber;
60 private String comment;
65 private String countryCode;
67 * Remote customer bean
69 private final CustomerSessionBeanRemote customerBean;
74 private String emailAddress;
79 private String familyName;
84 private String faxNumber;
89 private String firstName;
94 private Gender gender;
99 private Short houseNumber;
104 private String phoneNumber;
109 private String street;
114 private Integer zipCode;
117 * Default constructor
119 public CustomerWebBean () {
120 // Set gender to UNKNOWN
121 this.gender = Gender.UNKNOWN;
125 // Get initial context
126 Context context = new InitialContext();
129 this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer");
130 } catch (final NamingException e) {
132 throw new FaceletException(e);
137 public Customer createCustomerInstance () {
139 //this.getLogger().logTrace("createInstance: CALLED!");
141 // Required personal data must be set
142 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
144 // Create new customer instance
145 Customer customer = new ShopCustomer();
147 // Create new contact
148 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
149 contact.setStreet(this.getStreet());
150 contact.setHouseNumber(this.getHouseNumber());
151 contact.setZipCode(this.getZipCode());
152 contact.setCity(this.getCity());
153 contact.setPhoneNumber(this.getPhoneNumber());
154 contact.setFaxNumber(this.getFaxNumber());
155 contact.setCellphoneNumber(this.getCellphoneNumber());
157 // Set contact in customer
158 customer.setContact(contact);
161 //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
167 public String getCellphoneNumber () {
168 return this.cellphoneNumber;
172 public void setCellphoneNumber (final String cellphoneNumber) {
173 this.cellphoneNumber = cellphoneNumber;
177 public String getCity () {
182 public void setCity (final String city) {
187 public String getCountryCode () {
188 return this.countryCode;
192 public void setCountryCode (final String countryCode) {
193 this.countryCode = countryCode;
197 public String getEmailAddress () {
198 return this.emailAddress;
202 public void setEmailAddress (final String emailAddress) {
203 this.emailAddress = emailAddress;
207 public String getFamilyName () {
208 return this.familyName;
212 public void setFamilyName (final String familyName) {
213 this.familyName = familyName;
217 public String getFaxNumber () {
218 return this.faxNumber;
222 public void setFaxNumber (final String faxNumber) {
223 this.faxNumber = faxNumber;
227 public String getFirstName () {
228 return this.firstName;
232 public void setFirstName (final String firstName) {
233 this.firstName = firstName;
237 public Gender getGender () {
242 public void setGender (final Gender gender) {
243 this.gender = gender;
247 public Short getHouseNumber () {
248 return this.houseNumber;
252 public void setHouseNumber (final Short houseNumber) {
253 this.houseNumber = houseNumber;
257 public String getPhoneNumber () {
258 return this.phoneNumber;
262 public void setPhoneNumber (final String phoneNumber) {
263 this.phoneNumber = phoneNumber;
267 public String getStreet () {
272 public void setStreet (final String street) {
273 this.street = street;
277 public Integer getZipCode () {
282 public void setZipCode (final Integer zipCode) {
283 this.zipCode = zipCode;
287 public boolean isRequiredPersonalDataSet () {
288 return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));