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;
68 * Remote customer bean
70 private final CustomerSessionBeanRemote customerBean;
75 private String emailAddress;
80 private String familyName;
85 private String faxNumber;
90 private String firstName;
95 private Gender gender;
100 private Short houseNumber;
105 private String phoneNumber;
110 private String street;
115 private Integer zipCode;
118 * Default constructor
120 public CustomerWebBean () {
121 // Set gender to UNKNOWN
122 this.gender = Gender.UNKNOWN;
126 // Get initial context
127 Context context = new InitialContext();
130 this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer");
131 } catch (final NamingException e) {
133 throw new FaceletException(e);
138 public Customer createCustomerInstance () {
140 //this.getLogger().logTrace("createInstance: CALLED!");
142 // Required personal data must be set
143 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
145 // Create new customer instance
146 Customer customer = new ShopCustomer();
148 // Create new contact
149 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
150 contact.setStreet(this.getStreet());
151 contact.setHouseNumber(this.getHouseNumber());
152 contact.setZipCode(this.getZipCode());
153 contact.setCity(this.getCity());
154 contact.setPhoneNumber(this.getPhoneNumber());
155 contact.setFaxNumber(this.getFaxNumber());
156 contact.setCellphoneNumber(this.getCellphoneNumber());
158 // Set contact in customer
159 customer.setContact(contact);
162 //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
168 public String getCellphoneNumber () {
169 return this.cellphoneNumber;
173 public void setCellphoneNumber (final String cellphoneNumber) {
174 this.cellphoneNumber = cellphoneNumber;
178 public String getCity () {
183 public void setCity (final String city) {
188 public String getCountryCode () {
189 return this.countryCode;
193 public void setCountryCode (final String countryCode) {
194 this.countryCode = countryCode;
198 public String getEmailAddress () {
199 return this.emailAddress;
203 public void setEmailAddress (final String emailAddress) {
204 this.emailAddress = emailAddress;
208 public String getFamilyName () {
209 return this.familyName;
213 public void setFamilyName (final String familyName) {
214 this.familyName = familyName;
218 public String getFaxNumber () {
219 return this.faxNumber;
223 public void setFaxNumber (final String faxNumber) {
224 this.faxNumber = faxNumber;
228 public String getFirstName () {
229 return this.firstName;
233 public void setFirstName (final String firstName) {
234 this.firstName = firstName;
238 public Gender getGender () {
243 public void setGender (final Gender gender) {
244 this.gender = gender;
248 public Short getHouseNumber () {
249 return this.houseNumber;
253 public void setHouseNumber (final Short houseNumber) {
254 this.houseNumber = houseNumber;
258 public String getPhoneNumber () {
259 return this.phoneNumber;
263 public void setPhoneNumber (final String phoneNumber) {
264 this.phoneNumber = phoneNumber;
268 public String getStreet () {
273 public void setStreet (final String street) {
274 this.street = street;
278 public Integer getZipCode () {
283 public void setZipCode (final Integer zipCode) {
284 this.zipCode = zipCode;
288 public boolean isRequiredPersonalDataSet () {
289 return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));