]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/customer/CustomerWebBean.java
559d9f189b5a93c9f73ce1c725d4e97af61d7afc
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / customer / CustomerWebBean.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.pizzaapplication.beans.customer;
18
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.jcontacts.contact.Contact;
26 import org.mxchange.jcontacts.contact.UserContact;
27 import org.mxchange.jcontacts.contact.gender.Gender;
28 import org.mxchange.jcountry.data.Country;
29 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
30 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
31 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
32 import org.mxchange.jshopcore.model.customer.Customer;
33 import org.mxchange.jshopcore.model.customer.CustomerSessionBeanRemote;
34 import org.mxchange.jshopcore.model.customer.ShopCustomer;
35
36 /**
37  * A customer bean which hides the customer instance
38  * <p>
39  * @author Roland Haeder<roland@mxchange.org>
40  */
41 @Named ("customerController")
42 @SessionScoped
43 public class CustomerWebBean implements CustomerWebController {
44
45         /**
46          * Serial number
47          */
48         private static final long serialVersionUID = 542_145_347_916L;
49
50         /////////////////////// Properties /////////////////////
51         /**
52          * Cellphone number
53          */
54         private DialableCellphoneNumber cellphoneNumber;
55
56         /**
57          * City
58          */
59         private String city;
60
61         /**
62          * Optional comments
63          */
64         private String comment;
65
66         /**
67          * Country code
68          */
69         private Country country;
70
71         /**
72          * Remote customer bean
73          */
74         private final CustomerSessionBeanRemote customerBean;
75
76         /**
77          * Email address
78          */
79         private String emailAddress;
80
81         /**
82          * Family name
83          */
84         private String familyName;
85
86         /**
87          * Fax number
88          */
89         private DialableFaxNumber faxNumber;
90
91         /**
92          * First name
93          */
94         private String firstName;
95
96         /**
97          * Gender instance
98          */
99         private Gender gender;
100
101         /**
102          * House number
103          */
104         private Short houseNumber;
105
106         /**
107          * Phone number
108          */
109         private DialableLandLineNumber phoneNumber;
110
111         /**
112          * Street
113          */
114         private String street;
115
116         /**
117          * ZIP code
118          */
119         private Integer zipCode;
120
121         /**
122          * Default constructor
123          */
124         public CustomerWebBean () {
125                 // Set gender to UNKNOWN
126                 this.gender = Gender.UNKNOWN;
127
128                 // Try it
129                 try {
130                         // Get initial context
131                         Context context = new InitialContext();
132
133                         // Try to lookup
134                         this.customerBean = (CustomerSessionBeanRemote) context.lookup("ejb/stateless-customer");
135                 } catch (final NamingException e) {
136                         // Throw again
137                         throw new FaceletException(e);
138                 }
139         }
140
141         @Override
142         public Customer createCustomerInstance () {
143                 // Trace message
144                 //this.getLogger().logTrace("createInstance: CALLED!");
145
146                 // Required personal data must be set
147                 assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
148
149                 // Create new customer instance
150                 Customer customer = new ShopCustomer();
151
152                 // Create new contact
153                 Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName());
154                 contact.setStreet(this.getStreet());
155                 contact.setHouseNumber(this.getHouseNumber());
156                 contact.setZipCode(this.getZipCode());
157                 contact.setCity(this.getCity());
158                 contact.setCountry(this.getCountry());
159                 contact.setPhoneNumber(this.getPhoneNumber());
160                 contact.setFaxNumber(this.getFaxNumber());
161                 contact.setCellphoneNumber(this.getCellphoneNumber());
162
163                 // Set contact in customer
164                 customer.setContact(contact);
165
166                 // Trace message
167                 //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
168                 // Return it
169                 return customer;
170         }
171
172         @Override
173         public DialableCellphoneNumber getCellphoneNumber () {
174                 return this.cellphoneNumber;
175         }
176
177         @Override
178         public void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) {
179                 this.cellphoneNumber = cellphoneNumber;
180         }
181
182         @Override
183         public String getCity () {
184                 return this.city;
185         }
186
187         @Override
188         public void setCity (final String city) {
189                 this.city = city;
190         }
191
192         @Override
193         public Country getCountry () {
194                 return this.country;
195         }
196
197         @Override
198         public void setCountry (final Country country) {
199                 this.country = country;
200         }
201
202         @Override
203         public String getEmailAddress () {
204                 return this.emailAddress;
205         }
206
207         @Override
208         public void setEmailAddress (final String emailAddress) {
209                 this.emailAddress = emailAddress;
210         }
211
212         @Override
213         public String getFamilyName () {
214                 return this.familyName;
215         }
216
217         @Override
218         public void setFamilyName (final String familyName) {
219                 this.familyName = familyName;
220         }
221
222         @Override
223         public DialableFaxNumber getFaxNumber () {
224                 return this.faxNumber;
225         }
226
227         @Override
228         public void setFaxNumber (final DialableFaxNumber faxNumber) {
229                 this.faxNumber = faxNumber;
230         }
231
232         @Override
233         public String getFirstName () {
234                 return this.firstName;
235         }
236
237         @Override
238         public void setFirstName (final String firstName) {
239                 this.firstName = firstName;
240         }
241
242         @Override
243         public Gender getGender () {
244                 return this.gender;
245         }
246
247         @Override
248         public void setGender (final Gender gender) {
249                 this.gender = gender;
250         }
251
252         @Override
253         public Short getHouseNumber () {
254                 return this.houseNumber;
255         }
256
257         @Override
258         public void setHouseNumber (final Short houseNumber) {
259                 this.houseNumber = houseNumber;
260         }
261
262         @Override
263         public DialableLandLineNumber getPhoneNumber () {
264                 return this.phoneNumber;
265         }
266
267         @Override
268         public void setPhoneNumber (final DialableLandLineNumber phoneNumber) {
269                 this.phoneNumber = phoneNumber;
270         }
271
272         @Override
273         public String getStreet () {
274                 return this.street;
275         }
276
277         @Override
278         public void setStreet (final String street) {
279                 this.street = street;
280         }
281
282         @Override
283         public Integer getZipCode () {
284                 return this.zipCode;
285         }
286
287         @Override
288         public void setZipCode (final Integer zipCode) {
289                 this.zipCode = zipCode;
290         }
291
292         @Override
293         public boolean isRequiredPersonalDataSet () {
294                 return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));
295         }
296 }