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