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