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