]> 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 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.gender.Gender;
28 import org.mxchange.jcoreee.beans.BaseFrameworkBean;
29 import org.mxchange.jshopcore.model.customer.Customer;
30 import org.mxchange.jshopcore.model.customer.CustomerSessionBeanRemote;
31 import org.mxchange.jshopcore.model.customer.ShopCustomer;
32
33 /**
34  * A customer bean which hides the customer instance
35  *
36  * @author Roland Haeder<roland@mxchange.org>
37  */
38 @Named("customerController")
39 @SessionScoped
40 public class CustomerWebBean extends BaseFrameworkBean implements CustomerWebController {
41         /**
42          * Serial number
43          */
44         private static final long serialVersionUID = 542_145_347_916L;
45
46         /**
47          * Remote customer bean
48          */
49         private final CustomerSessionBeanRemote customerBean;
50
51         /////////////////////// Properties /////////////////////
52         /**
53          * Cellphone number
54          */
55         private String cellphoneNumber;
56
57         /**
58          * City
59          */
60         private String city;
61
62         /**
63          * Optional comments
64          */
65         private String comment;
66
67         /**
68          * Company name
69          */
70         private String companyName;
71
72         /**
73          * Country code
74          */
75         private String countryCode;
76
77         /**
78          * Email address
79          */
80         private String emailAddress;
81
82         /**
83          * Gender instance
84          */
85         private Gender gender;
86
87         /**
88          * Family name
89          */
90         private String familyName;
91
92         /**
93          * Fax number
94          */
95         private String faxNumber;
96
97         /**
98          * First name
99          */
100         private String firstName;
101
102         /**
103          * House number
104          */
105         private Long 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 createInstance () {
144                 // Trace message
145                 this.getLogger().logTrace("createInstance: CALLED!");
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                 customer.setGender(this.getGender());
152                 customer.setFirstName(this.getFirstName());
153                 customer.setFamilyName(this.getFamilyName());
154                 customer.setCompanyName(this.getCompanyName());
155                 customer.setStreet(this.getStreet());
156                 customer.setHouseNumber(this.getHouseNumber());
157                 customer.setZipCode(this.getZipCode());
158                 customer.setCity(this.getCity());
159                 customer.setPhoneNumber(this.getPhoneNumber());
160                 customer.setFaxNumber(this.getFaxNumber());
161                 customer.setCellphoneNumber(this.getCellphoneNumber());
162
163                 // Trace message
164                 this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
165
166                 // Return it
167                 return customer;
168         }
169
170         @PostConstruct
171         public void init () throws RuntimeException {
172                 // Call super init first
173                 super.genericInit();
174         }
175
176         @Override
177         public Gender getGender () {
178                 return this.gender;
179         }
180
181         @Override
182         public void setGender (final Gender gender) {
183                 this.gender = gender;
184         }
185
186         @Override
187         public String getCompanyName () {
188                 return this.companyName;
189         }
190
191         @Override
192         public void setCompanyName (final String companyName) {
193                 this.companyName = companyName;
194         }
195
196         @Override
197         public String getFirstName () {
198                 return this.firstName;
199         }
200
201         @Override
202         public void setFirstName (final String firstName) {
203                 this.firstName = firstName;
204         }
205
206         @Override
207         public String getFamilyName () {
208                 return this.familyName;
209         }
210
211         @Override
212         public void setFamilyName (final String familyName) {
213                 this.familyName = familyName;
214         }
215
216         @Override
217         public String getStreet () {
218                 return this.street;
219         }
220
221         @Override
222         public void setStreet (final String street) {
223                 this.street = street;
224         }
225
226         @Override
227         public Long getHouseNumber () {
228                 return this.houseNumber;
229         }
230
231         @Override
232         public void setHouseNumber (final Long houseNumber) {
233                 this.houseNumber = houseNumber;
234         }
235
236         @Override
237         public Long getZipCode () {
238                 return this.zipCode;
239         }
240
241         @Override
242         public void setZipCode (final Long zipCode) {
243                 this.zipCode = zipCode;
244         }
245
246         @Override
247         public String getCity () {
248                 return this.city;
249         }
250
251         @Override
252         public void setCity (final String city) {
253                 this.city = city;
254         }
255
256         @Override
257         public String getCountryCode () {
258                 return this.countryCode;
259         }
260
261         @Override
262         public void setCountryCode (final String countryCode) {
263                 this.countryCode = countryCode;
264         }
265
266         @Override
267         public String getEmailAddress () {
268                 return this.emailAddress;
269         }
270
271         @Override
272         public void setEmailAddress (final String emailAddress) {
273                 this.emailAddress = emailAddress;
274         }
275
276         @Override
277         public String getPhoneNumber () {
278                 return this.phoneNumber;
279         }
280
281         @Override
282         public void setPhoneNumber (final String phoneNumber) {
283                 this.phoneNumber = phoneNumber;
284         }
285
286         @Override
287         public String getFaxNumber () {
288                 return this.faxNumber;
289         }
290
291         @Override
292         public void setFaxNumber (final String faxNumber) {
293                 this.faxNumber = faxNumber;
294         }
295
296         @Override
297         public String getCellphoneNumber () {
298                 return this.cellphoneNumber;
299         }
300
301         @Override
302         public void setCellphoneNumber (final String cellphoneNumber) {
303                 this.cellphoneNumber = cellphoneNumber;
304         }
305
306         @Override
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));
309         }
310 }