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.inject.Named;
23 import javax.naming.Context;
24 import javax.naming.InitialContext;
25 import javax.naming.NamingException;
26 import org.mxchange.jcore.model.contact.gender.Gender;
27 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
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 extends BaseFrameworkBean implements CustomerWebController {
43 private static final long serialVersionUID = 542_145_347_916L;
46 * Remote customer bean
48 private final CustomerSessionBeanRemote customerBean;
50 /////////////////////// Properties /////////////////////
54 private String cellphoneNumber;
64 private String comment;
69 private String companyName;
74 private String countryCode;
79 private String emailAddress;
84 private Gender gender;
89 private String familyName;
94 private String faxNumber;
99 private String firstName;
104 private Long houseNumber;
109 private String phoneNumber;
114 private String street;
119 private Long zipCode;
122 * Default constructor
124 * @throws javax.naming.NamingException If something happens?
126 public CustomerWebBean () throws NamingException {
127 // Get initial context
128 Context context = new InitialContext();
130 // Set gender to UNKNOWN
131 this.gender = Gender.UNKNOWN;
134 this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer");
138 public Customer createInstance () {
140 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();
146 customer.setGender(this.getGender());
147 customer.setFirstName(this.getFirstName());
148 customer.setFamilyName(this.getFamilyName());
149 customer.setCompanyName(this.getCompanyName());
150 customer.setStreet(this.getStreet());
151 customer.setHouseNumber(this.getHouseNumber());
152 customer.setZipCode(this.getZipCode());
153 customer.setCity(this.getCity());
154 customer.setPhoneNumber(this.getPhoneNumber());
155 customer.setFaxNumber(this.getFaxNumber());
156 customer.setCellphoneNumber(this.getCellphoneNumber());
159 this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
166 public void init () throws RuntimeException {
167 // Call super init first
172 public Gender getGender () {
177 public void setGender (final Gender gender) {
178 this.gender = gender;
182 public String getCompanyName () {
183 return this.companyName;
187 public void setCompanyName (final String companyName) {
188 this.companyName = companyName;
192 public String getFirstName () {
193 return this.firstName;
197 public void setFirstName (final String firstName) {
198 this.firstName = firstName;
202 public String getFamilyName () {
203 return this.familyName;
207 public void setFamilyName (final String familyName) {
208 this.familyName = familyName;
212 public String getStreet () {
217 public void setStreet (final String street) {
218 this.street = street;
222 public Long getHouseNumber () {
223 return this.houseNumber;
227 public void setHouseNumber (final Long houseNumber) {
228 this.houseNumber = houseNumber;
232 public Long getZipCode () {
237 public void setZipCode (final Long zipCode) {
238 this.zipCode = zipCode;
242 public String getCity () {
247 public void setCity (final String city) {
252 public String getCountryCode () {
253 return this.countryCode;
257 public void setCountryCode (final String countryCode) {
258 this.countryCode = countryCode;
262 public String getEmailAddress () {
263 return this.emailAddress;
267 public void setEmailAddress (final String emailAddress) {
268 this.emailAddress = emailAddress;
272 public String getPhoneNumber () {
273 return this.phoneNumber;
277 public void setPhoneNumber (final String phoneNumber) {
278 this.phoneNumber = phoneNumber;
282 public String getFaxNumber () {
283 return this.faxNumber;
287 public void setFaxNumber (final String faxNumber) {
288 this.faxNumber = faxNumber;
292 public String getCellphoneNumber () {
293 return this.cellphoneNumber;
297 public void setCellphoneNumber (final String cellphoneNumber) {
298 this.cellphoneNumber = cellphoneNumber;
302 public boolean isRequiredPersonalDataSet () {
303 return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));