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.Contact;
28 import org.mxchange.jcore.model.contact.CustomerContact;
29 import org.mxchange.jcore.model.contact.gender.Gender;
30 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
31 import org.mxchange.jshopcore.model.customer.Customer;
32 import org.mxchange.jshopcore.model.customer.CustomerSessionBeanRemote;
33 import org.mxchange.jshopcore.model.customer.ShopCustomer;
36 * A customer bean which hides the customer instance
38 * @author Roland Haeder<roland@mxchange.org>
40 @Named("customerController")
42 public class CustomerWebBean extends BaseFrameworkBean implements CustomerWebController {
46 private static final long serialVersionUID = 542_145_347_916L;
49 * Remote customer bean
51 private final CustomerSessionBeanRemote customerBean;
53 /////////////////////// Properties /////////////////////
57 private String cellphoneNumber;
67 private String comment;
72 private String companyName;
77 private String countryCode;
82 private String emailAddress;
87 private Gender gender;
92 private String familyName;
97 private String faxNumber;
102 private String firstName;
107 private Long houseNumber;
112 private String phoneNumber;
117 private String street;
122 private Long zipCode;
125 * Default constructor
127 public CustomerWebBean () {
128 // Set gender to UNKNOWN
129 this.gender = Gender.UNKNOWN;
133 // Get initial context
134 Context context = new InitialContext();
137 this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer");
138 } catch (final NamingException e) {
140 throw new FaceletException(e);
145 public Customer createCustomerInstance () {
147 this.getLogger().logTrace("createInstance: CALLED!");
148 // Required personal data must be set
149 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
151 // Create new customer instance
152 Customer customer = new ShopCustomer();
154 // Create new contact
155 Contact contact = new CustomerContact();
156 contact.setGender(this.getGender());
157 contact.setFirstName(this.getFirstName());
158 contact.setFamilyName(this.getFamilyName());
159 contact.setCompanyName(this.getCompanyName());
160 contact.setStreet(this.getStreet());
161 contact.setHouseNumber(this.getHouseNumber());
162 contact.setZipCode(this.getZipCode());
163 contact.setCity(this.getCity());
164 contact.setPhoneNumber(this.getPhoneNumber());
165 contact.setFaxNumber(this.getFaxNumber());
166 contact.setCellphoneNumber(this.getCellphoneNumber());
168 // Set contact in customer
169 customer.setContact(contact);
172 this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
179 public void init () throws RuntimeException {
180 // Call super init first
185 public Gender getGender () {
190 public void setGender (final Gender gender) {
191 this.gender = gender;
195 public String getCompanyName () {
196 return this.companyName;
200 public void setCompanyName (final String companyName) {
201 this.companyName = companyName;
205 public String getFirstName () {
206 return this.firstName;
210 public void setFirstName (final String firstName) {
211 this.firstName = firstName;
215 public String getFamilyName () {
216 return this.familyName;
220 public void setFamilyName (final String familyName) {
221 this.familyName = familyName;
225 public String getStreet () {
230 public void setStreet (final String street) {
231 this.street = street;
235 public Long getHouseNumber () {
236 return this.houseNumber;
240 public void setHouseNumber (final Long houseNumber) {
241 this.houseNumber = houseNumber;
245 public Long getZipCode () {
250 public void setZipCode (final Long zipCode) {
251 this.zipCode = zipCode;
255 public String getCity () {
260 public void setCity (final String city) {
265 public String getCountryCode () {
266 return this.countryCode;
270 public void setCountryCode (final String countryCode) {
271 this.countryCode = countryCode;
275 public String getEmailAddress () {
276 return this.emailAddress;
280 public void setEmailAddress (final String emailAddress) {
281 this.emailAddress = emailAddress;
285 public String getPhoneNumber () {
286 return this.phoneNumber;
290 public void setPhoneNumber (final String phoneNumber) {
291 this.phoneNumber = phoneNumber;
295 public String getFaxNumber () {
296 return this.faxNumber;
300 public void setFaxNumber (final String faxNumber) {
301 this.faxNumber = faxNumber;
305 public String getCellphoneNumber () {
306 return this.cellphoneNumber;
310 public void setCellphoneNumber (final String cellphoneNumber) {
311 this.cellphoneNumber = cellphoneNumber;
315 public boolean isRequiredPersonalDataSet () {
316 return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));