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