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.CustomerContact;
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 {
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 public CustomerWebBean () {
125 // Set gender to UNKNOWN
126 this.gender = Gender.UNKNOWN;
130 // Get initial context
131 Context context = new InitialContext();
134 this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer");
135 } catch (final NamingException e) {
137 throw new FaceletException(e);
142 public Customer createCustomerInstance () {
144 //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();
152 // Create new contact
153 Contact contact = new CustomerContact();
154 contact.setGender(this.getGender());
155 contact.setFirstName(this.getFirstName());
156 contact.setFamilyName(this.getFamilyName());
157 contact.setCompanyName(this.getCompanyName());
158 contact.setStreet(this.getStreet());
159 contact.setHouseNumber(this.getHouseNumber());
160 contact.setZipCode(this.getZipCode());
161 contact.setCity(this.getCity());
162 contact.setPhoneNumber(this.getPhoneNumber());
163 contact.setFaxNumber(this.getFaxNumber());
164 contact.setCellphoneNumber(this.getCellphoneNumber());
166 // Set contact in customer
167 customer.setContact(contact);
170 //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
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));