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.jcore.model.contact.Contact;
26 import org.mxchange.jcore.model.contact.UserContact;
27 import org.mxchange.jcore.model.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;
47 /////////////////////// Properties /////////////////////
51 private String cellphoneNumber;
61 private String comment;
66 private String companyName;
71 private String countryCode;
73 * Remote customer bean
75 private final CustomerSessionBeanRemote customerBean;
80 private String emailAddress;
85 private String familyName;
90 private String faxNumber;
95 private String firstName;
100 private Gender gender;
105 private Short houseNumber;
110 private String phoneNumber;
115 private String street;
120 private Long zipCode;
123 * Default constructor
125 public CustomerWebBean () {
126 // Set gender to UNKNOWN
127 this.gender = Gender.UNKNOWN;
131 // Get initial context
132 Context context = new InitialContext();
135 this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer");
136 } catch (final NamingException e) {
138 throw new FaceletException(e);
143 public Customer createCustomerInstance () {
145 //this.getLogger().logTrace("createInstance: CALLED!");
147 // Required personal data must be set
148 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
150 // Create new customer instance
151 Customer customer = new ShopCustomer();
153 // Create new contact
154 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName(), this.getCompanyName());
155 contact.setStreet(this.getStreet());
156 contact.setHouseNumber(this.getHouseNumber());
157 contact.setZipCode(this.getZipCode());
158 contact.setCity(this.getCity());
159 contact.setPhoneNumber(this.getPhoneNumber());
160 contact.setFaxNumber(this.getFaxNumber());
161 contact.setCellphoneNumber(this.getCellphoneNumber());
163 // Set contact in customer
164 customer.setContact(contact);
167 //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
174 public String getCellphoneNumber () {
175 return this.cellphoneNumber;
179 public void setCellphoneNumber (final String cellphoneNumber) {
180 this.cellphoneNumber = cellphoneNumber;
184 public String getCity () {
189 public void setCity (final String city) {
194 public String getCompanyName () {
195 return this.companyName;
199 public void setCompanyName (final String companyName) {
200 this.companyName = companyName;
204 public String getCountryCode () {
205 return this.countryCode;
209 public void setCountryCode (final String countryCode) {
210 this.countryCode = countryCode;
214 public String getEmailAddress () {
215 return this.emailAddress;
219 public void setEmailAddress (final String emailAddress) {
220 this.emailAddress = emailAddress;
224 public String getFamilyName () {
225 return this.familyName;
229 public void setFamilyName (final String familyName) {
230 this.familyName = familyName;
234 public String getFaxNumber () {
235 return this.faxNumber;
239 public void setFaxNumber (final String faxNumber) {
240 this.faxNumber = faxNumber;
244 public String getFirstName () {
245 return this.firstName;
249 public void setFirstName (final String firstName) {
250 this.firstName = firstName;
254 public Gender getGender () {
259 public void setGender (final Gender gender) {
260 this.gender = gender;
264 public Short getHouseNumber () {
265 return this.houseNumber;
269 public void setHouseNumber (final Short houseNumber) {
270 this.houseNumber = houseNumber;
274 public String getPhoneNumber () {
275 return this.phoneNumber;
279 public void setPhoneNumber (final String phoneNumber) {
280 this.phoneNumber = phoneNumber;
284 public String getStreet () {
289 public void setStreet (final String street) {
290 this.street = street;
294 public Long getZipCode () {
299 public void setZipCode (final Long zipCode) {
300 this.zipCode = zipCode;
304 public boolean isRequiredPersonalDataSet () {
305 return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));