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