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 java.text.MessageFormat;
20 import javax.annotation.PostConstruct;
21 import javax.enterprise.context.SessionScoped;
22 import javax.faces.view.facelets.FaceletException;
23 import javax.inject.Named;
24 import javax.naming.Context;
25 import javax.naming.InitialContext;
26 import javax.naming.NamingException;
27 import org.mxchange.jcore.model.contact.gender.Gender;
28 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
29 import org.mxchange.jshopcore.model.customer.Customer;
30 import org.mxchange.jshopcore.model.customer.CustomerSessionBeanRemote;
31 import org.mxchange.jshopcore.model.customer.ShopCustomer;
34 * A customer bean which hides the customer instance
36 * @author Roland Haeder<roland@mxchange.org>
38 @Named("customerController")
40 public class CustomerWebBean extends BaseFrameworkBean implements CustomerWebController {
44 private static final long serialVersionUID = 542_145_347_916L;
47 * Remote customer bean
49 private final CustomerSessionBeanRemote customerBean;
51 /////////////////////// Properties /////////////////////
55 private String cellphoneNumber;
65 private String comment;
70 private String companyName;
75 private String countryCode;
80 private String emailAddress;
85 private Gender gender;
90 private String familyName;
95 private String faxNumber;
100 private String firstName;
105 private Long 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!");
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();
151 customer.setGender(this.getGender());
152 customer.setFirstName(this.getFirstName());
153 customer.setFamilyName(this.getFamilyName());
154 customer.setCompanyName(this.getCompanyName());
155 customer.setStreet(this.getStreet());
156 customer.setHouseNumber(this.getHouseNumber());
157 customer.setZipCode(this.getZipCode());
158 customer.setCity(this.getCity());
159 customer.setPhoneNumber(this.getPhoneNumber());
160 customer.setFaxNumber(this.getFaxNumber());
161 customer.setCellphoneNumber(this.getCellphoneNumber());
164 this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
171 public void init () throws RuntimeException {
172 // Call super init first
177 public Gender getGender () {
182 public void setGender (final Gender gender) {
183 this.gender = gender;
187 public String getCompanyName () {
188 return this.companyName;
192 public void setCompanyName (final String companyName) {
193 this.companyName = companyName;
197 public String getFirstName () {
198 return this.firstName;
202 public void setFirstName (final String firstName) {
203 this.firstName = firstName;
207 public String getFamilyName () {
208 return this.familyName;
212 public void setFamilyName (final String familyName) {
213 this.familyName = familyName;
217 public String getStreet () {
222 public void setStreet (final String street) {
223 this.street = street;
227 public Long getHouseNumber () {
228 return this.houseNumber;
232 public void setHouseNumber (final Long houseNumber) {
233 this.houseNumber = houseNumber;
237 public Long getZipCode () {
242 public void setZipCode (final Long zipCode) {
243 this.zipCode = zipCode;
247 public String getCity () {
252 public void setCity (final String city) {
257 public String getCountryCode () {
258 return this.countryCode;
262 public void setCountryCode (final String countryCode) {
263 this.countryCode = countryCode;
267 public String getEmailAddress () {
268 return this.emailAddress;
272 public void setEmailAddress (final String emailAddress) {
273 this.emailAddress = emailAddress;
277 public String getPhoneNumber () {
278 return this.phoneNumber;
282 public void setPhoneNumber (final String phoneNumber) {
283 this.phoneNumber = phoneNumber;
287 public String getFaxNumber () {
288 return this.faxNumber;
292 public void setFaxNumber (final String faxNumber) {
293 this.faxNumber = faxNumber;
297 public String getCellphoneNumber () {
298 return this.cellphoneNumber;
302 public void setCellphoneNumber (final String cellphoneNumber) {
303 this.cellphoneNumber = cellphoneNumber;
307 public boolean isRequiredPersonalDataSet () {
308 return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));