]> 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.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;
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          * Serial number
42          */
43         private static final long serialVersionUID = 542_145_347_916L;
44
45         /**
46          * Remote customer bean
47          */
48         private final CustomerSessionBeanRemote customerBean;
49
50         /////////////////////// Properties /////////////////////
51         /**
52          * Cellphone number
53          */
54         private String cellphoneNumber;
55
56         /**
57          * City
58          */
59         private String city;
60
61         /**
62          * Optional comments
63          */
64         private String comment;
65
66         /**
67          * Company name
68          */
69         private String companyName;
70
71         /**
72          * Country code
73          */
74         private String countryCode;
75
76         /**
77          * Email address
78          */
79         private String emailAddress;
80
81         /**
82          * Gender instance
83          */
84         private Gender gender;
85
86         /**
87          * Family name
88          */
89         private String familyName;
90
91         /**
92          * Fax number
93          */
94         private String faxNumber;
95
96         /**
97          * First name
98          */
99         private String firstName;
100
101         /**
102          * House number
103          */
104         private Long houseNumber;
105
106         /**
107          * Phone number
108          */
109         private String phoneNumber;
110
111         /**
112          * Street
113          */
114         private String street;
115
116         /**
117          * ZIP code
118          */
119         private Long 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 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());
165
166                 // Set contact in customer
167                 customer.setContact(contact);
168
169                 // Trace message
170                 //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer));
171
172                 // Return it
173                 return customer;
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 }