]> git.mxchange.org Git - pizzaservice-war.git/blob - src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java
Continued a bit:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / beans / contact / PizzaAdminContactWebRequestBean.java
1 /*
2  * Copyright (C) 2016 Cho-Time GmbH
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (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 Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.pizzaapplication.beans.contact;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import javax.annotation.PostConstruct;
22 import javax.enterprise.context.RequestScoped;
23 import javax.enterprise.event.Event;
24 import javax.enterprise.inject.Any;
25 import javax.faces.view.facelets.FaceletException;
26 import javax.inject.Inject;
27 import javax.inject.Named;
28 import javax.naming.Context;
29 import javax.naming.InitialContext;
30 import javax.naming.NamingException;
31 import org.mxchange.jcontacts.contact.Contact;
32 import org.mxchange.jcontacts.contact.ContactSessionBeanRemote;
33 import org.mxchange.jcontacts.contact.gender.Gender;
34 import org.mxchange.jcontacts.events.contact.AdminAddedContactEvent;
35 import org.mxchange.jcountry.data.Country;
36 import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
37 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
38 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
39 import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
40
41 /**
42  * A user bean (controller)
43  * <p>
44  * @author Roland Haeder<roland@mxchange.org>
45  */
46 @Named ("adminContactController")
47 @RequestScoped
48 public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequestController {
49
50         /**
51          * Serial number
52          */
53         private static final long serialVersionUID = 542_145_347_916L;
54
55         /**
56          * An event fired when the administrator has added a new contact
57          */
58         @Inject
59         @Any
60         private Event<AdminAddedContactEvent> addedContactEvent;
61
62         /**
63          * Birth day
64          */
65         private Date birthday;
66
67         /**
68          * Cellphone number's carrier
69          */
70         private MobileProvider cellphoneCarrier;
71
72         /**
73          * Cellphone id number
74          */
75         private Long cellphoneId;
76
77         /**
78          * Cellphone number
79          */
80         private Long cellphoneNumber;
81
82         /**
83          * City
84          */
85         private String city;
86
87         /**
88          * Optional comments
89          */
90         private String comment;
91
92         /**
93          * Remote contact bean
94          */
95         private final ContactSessionBeanRemote contactBean;
96
97         /**
98          * Contact id
99          */
100         private Long contactId;
101
102         /**
103          * Country instance
104          */
105         private Country country;
106
107         /**
108          * Email address
109          */
110         private String emailAddress;
111
112         /**
113          * Family name
114          */
115         private String familyName;
116
117         /**
118          * Fax number's area code
119          */
120         private Integer faxAreaCode;
121
122         /**
123          * Country instance for fax number
124          */
125         private Country faxCountry;
126
127         /**
128          * Fax id number
129          */
130         private Long faxId;
131
132         /**
133          * Fax number
134          */
135         private Long faxNumber;
136
137         /**
138          * First name
139          */
140         private String firstName;
141
142         /**
143          * Gender instance
144          */
145         private Gender gender;
146
147         /**
148          * House number
149          */
150         private Short houseNumber;
151
152         /**
153          * Land-line id number
154          */
155         private Long landLineId;
156
157         /**
158          * Phone number area code
159          */
160         private Integer phoneAreaCode;
161
162         /**
163          * Country instance for phone number
164          */
165         private Country phoneCountry;
166
167         /**
168          * Phone number
169          */
170         private Long phoneNumber;
171
172         /**
173          * Street
174          */
175         private String street;
176
177         /**
178          * ZIP code
179          */
180         private Integer zipCode;
181
182         /**
183          * Default constructor
184          */
185         public PizzaAdminContactWebRequestBean () {
186                 // Set gender to UNKNOWN
187                 this.gender = Gender.UNKNOWN;
188
189                 // Try it
190                 try {
191                         // Get initial context
192                         Context context = new InitialContext();
193
194                         // Try to lookup
195                         this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
196                 } catch (final NamingException e) {
197                         // Throw again
198                         throw new FaceletException(e);
199                 }
200         }
201
202         @Override
203         public void copyContactToController (final Contact contact) {
204                 // Log message
205                 System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N
206
207                 // The contact instance must be valid
208                 if (null == contact) {
209                         // Throw NPE again
210                         throw new NullPointerException("this.user.userContact is null"); //NOI18N
211                 } else if (contact.getContactId() < 1) {
212                         // Not valid
213                         throw new IllegalStateException(MessageFormat.format("this.user.userContact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
214                 }
215
216                 // Set all fields: contact
217                 this.setContactId(contact.getContactId());
218                 this.setBirthday(contact.getContactBirthday());
219                 this.setCity(contact.getContactCity());
220                 this.setComment(contact.getContactComment());
221                 this.setCountry(contact.getContactCountry());
222                 this.setEmailAddress(contact.getContactEmailAddress());
223                 this.setFamilyName(contact.getContactFamilyName());
224                 this.setFirstName(contact.getContactFirstName());
225                 this.setGender(contact.getContactGender());
226                 this.setHouseNumber(contact.getContactHouseNumber());
227                 this.setStreet(contact.getContactStreet());
228                 this.setZipCode(contact.getContactZipCode());
229
230                 // Is the cell phone set?
231                 if (contact.getContactCellphoneNumber() instanceof DialableCellphoneNumber) {
232                         // ... cellphone data
233                         this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId());
234                         this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider());
235                         this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber());
236                 }
237
238                 // Is the fax set?
239                 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
240                         // ... fax data
241                         this.setFaxId(contact.getContactFaxNumber().getPhoneId());
242                         this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
243                         this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
244                         this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
245                 }
246
247                 // Is the land-line number set?
248                 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
249                         // .. land-line data
250                         this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
251                         this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
252                         this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
253                         this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
254                 }
255
256                 // Log message
257                 System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
258         }
259
260         @Override
261         public Date getBirthday () {
262                 return this.birthday;
263         }
264
265         @Override
266         public void setBirthday (final Date birthday) {
267                 this.birthday = birthday;
268         }
269
270         @Override
271         public MobileProvider getCellphoneCarrier () {
272                 return this.cellphoneCarrier;
273         }
274
275         @Override
276         public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
277                 this.cellphoneCarrier = cellphoneCarrier;
278         }
279
280         @Override
281         public Long getCellphoneId () {
282                 return this.cellphoneId;
283         }
284
285         @Override
286         public void setCellphoneId (final Long cellphoneId) {
287                 this.cellphoneId = cellphoneId;
288         }
289
290         @Override
291         public Long getCellphoneNumber () {
292                 return this.cellphoneNumber;
293         }
294
295         @Override
296         public void setCellphoneNumber (Long cellphoneNumber) {
297                 this.cellphoneNumber = cellphoneNumber;
298         }
299
300         @Override
301         public String getCity () {
302                 return this.city;
303         }
304
305         @Override
306         public void setCity (final String city) {
307                 this.city = city;
308         }
309
310         @Override
311         public String getComment () {
312                 return this.comment;
313         }
314
315         @Override
316         public void setComment (final String comment) {
317                 this.comment = comment;
318         }
319
320         @Override
321         public Long getContactId () {
322                 return this.contactId;
323         }
324
325         @Override
326         public void setContactId (final Long contactId) {
327                 this.contactId = contactId;
328         }
329
330         @Override
331         public Country getCountry () {
332                 return this.country;
333         }
334
335         @Override
336         public void setCountry (final Country country) {
337                 this.country = country;
338         }
339
340         @Override
341         public String getEmailAddress () {
342                 return this.emailAddress;
343         }
344
345         @Override
346         public void setEmailAddress (final String emailAddress) {
347                 this.emailAddress = emailAddress;
348         }
349
350         @Override
351         public String getFamilyName () {
352                 return this.familyName;
353         }
354
355         @Override
356         public void setFamilyName (final String familyName) {
357                 this.familyName = familyName;
358         }
359
360         @Override
361         public Integer getFaxAreaCode () {
362                 return this.faxAreaCode;
363         }
364
365         @Override
366         public void setFaxAreaCode (final Integer faxAreaCode) {
367                 this.faxAreaCode = faxAreaCode;
368         }
369
370         @Override
371         public Country getFaxCountry () {
372                 return this.faxCountry;
373         }
374
375         @Override
376         public void setFaxCountry (final Country faxCountry) {
377                 this.faxCountry = faxCountry;
378         }
379
380         @Override
381         public Long getFaxId () {
382                 return this.faxId;
383         }
384
385         @Override
386         public void setFaxId (final Long faxId) {
387                 this.faxId = faxId;
388         }
389
390         @Override
391         public Long getFaxNumber () {
392                 return this.faxNumber;
393         }
394
395         @Override
396         public void setFaxNumber (final Long faxNumber) {
397                 this.faxNumber = faxNumber;
398         }
399
400         @Override
401         public String getFirstName () {
402                 return this.firstName;
403         }
404
405         @Override
406         public void setFirstName (final String firstName) {
407                 this.firstName = firstName;
408         }
409
410         @Override
411         public Gender getGender () {
412                 return this.gender;
413         }
414
415         @Override
416         public void setGender (final Gender gender) {
417                 this.gender = gender;
418         }
419
420         @Override
421         public Short getHouseNumber () {
422                 return this.houseNumber;
423         }
424
425         @Override
426         public void setHouseNumber (final Short houseNumber) {
427                 this.houseNumber = houseNumber;
428         }
429
430         @Override
431         public Long getLandLineId () {
432                 return this.landLineId;
433         }
434
435         @Override
436         public void setLandLineId (final Long landLineId) {
437                 this.landLineId = landLineId;
438         }
439
440         @Override
441         public Integer getPhoneAreaCode () {
442                 return this.phoneAreaCode;
443         }
444
445         @Override
446         public void setPhoneAreaCode (final Integer phoneAreaCode) {
447                 this.phoneAreaCode = phoneAreaCode;
448         }
449
450         @Override
451         public Country getPhoneCountry () {
452                 return this.phoneCountry;
453         }
454
455         @Override
456         public void setPhoneCountry (final Country phoneCountry) {
457                 this.phoneCountry = phoneCountry;
458         }
459
460         @Override
461         public Long getPhoneNumber () {
462                 return this.phoneNumber;
463         }
464
465         @Override
466         public void setPhoneNumber (final Long phoneNumber) {
467                 this.phoneNumber = phoneNumber;
468         }
469
470         @Override
471         public String getStreet () {
472                 return this.street;
473         }
474
475         @Override
476         public void setStreet (final String street) {
477                 this.street = street;
478         }
479
480         @Override
481         public Integer getZipCode () {
482                 return this.zipCode;
483         }
484
485         @Override
486         public void setZipCode (final Integer zipCode) {
487                 this.zipCode = zipCode;
488         }
489
490         /**
491          * Post-initialization of this class
492          */
493         @PostConstruct
494         public void init () {
495         }
496
497         /**
498          * Clears this bean
499          */
500         private void clear () {
501                 // Clear all
502                 this.setContactId(null);
503                 this.setBirthday(null);
504                 this.setCellphoneCarrier(null);
505                 this.setCellphoneNumber(null);
506                 this.setCity(null);
507                 this.setComment(null);
508                 this.setCountry(null);
509                 this.setEmailAddress(null);
510                 this.setFamilyName(null);
511                 this.setFaxAreaCode(null);
512                 this.setFaxCountry(null);
513                 this.setFaxNumber(null);
514                 this.setFirstName(null);
515                 this.setGender(null);
516                 this.setHouseNumber(null);
517                 this.setPhoneAreaCode(null);
518                 this.setPhoneCountry(null);
519                 this.setPhoneNumber(null);
520                 this.setStreet(null);
521                 this.setZipCode(null);
522         }
523
524 }