2 * Copyright (C) 2016 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.addressbook.beans.contact;
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;
39 * A user bean (controller)
41 * @author Roland Haeder<roland@mxchange.org>
43 @Named ("adminContactController")
45 public class AddressbookAdminContactWebRequestBean implements AddressbookAdminContactWebRequestController {
50 private static final long serialVersionUID = 542_145_347_916L;
53 * An event fired when the administrator has added a new user
57 private Event<AdminAddedUserEvent> addedUserEvent;
62 private Date birthday;
65 * Cellphone number's carrier
67 private MobileProvider cellphoneCarrier;
72 private Long cellphoneId;
77 private Long cellphoneNumber;
87 private String comment;
92 private final ContactSessionBeanRemote contactBean;
97 private Long contactId;
102 private Country country;
107 private String emailAddress;
112 private String familyName;
115 * Fax number's area code
117 private Integer faxAreaCode;
120 * Country instance for fax number
122 private Country faxCountry;
132 private Long faxNumber;
137 private String firstName;
142 private Gender gender;
147 private Short houseNumber;
150 * Land-line id number
152 private Long landLineId;
155 * Phone number area code
157 private Integer phoneAreaCode;
160 * Country instance for phone number
162 private Country phoneCountry;
167 private Long phoneNumber;
172 private String street;
177 private Integer zipCode;
180 * Default constructor
182 public AddressbookAdminContactWebRequestBean () {
183 // Set gender to UNKNOWN
184 this.gender = Gender.UNKNOWN;
188 // Get initial context
189 Context context = new InitialContext();
192 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
193 } catch (final NamingException e) {
195 throw new FaceletException(e);
200 public void copyContactToController (final Contact contact) {
201 // The contact instance must be valid
202 if (null == contact) {
204 throw new NullPointerException("this.user.userContact is null");
205 } else if (contact.getContactId() < 1) {
207 throw new IllegalStateException(MessageFormat.format("this.user.userContact.contactId={0} is not valid.", contact.getContactId()));
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());
224 // ... cellphone data
225 this.setCellphoneId(contact.getContactCellphoneNumber().getPhoneId());
226 this.setCellphoneCarrier(contact.getContactCellphoneNumber().getCellphoneProvider());
227 this.setCellphoneNumber(contact.getContactCellphoneNumber().getPhoneNumber());
230 this.setFaxId(contact.getContactFaxNumber().getPhoneId());
231 this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
232 this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
233 this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
236 this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
237 this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
238 this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
239 this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
243 public Date getBirthday () {
244 return this.birthday;
248 public void setBirthday (final Date birthday) {
249 this.birthday = birthday;
253 public MobileProvider getCellphoneCarrier () {
254 return this.cellphoneCarrier;
258 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
259 this.cellphoneCarrier = cellphoneCarrier;
263 public Long getCellphoneId () {
264 return this.cellphoneId;
268 public void setCellphoneId (final Long cellphoneId) {
269 this.cellphoneId = cellphoneId;
273 public Long getCellphoneNumber () {
274 return this.cellphoneNumber;
278 public void setCellphoneNumber (Long cellphoneNumber) {
279 this.cellphoneNumber = cellphoneNumber;
283 public String getCity () {
288 public void setCity (final String city) {
293 public String getComment () {
298 public void setComment (final String comment) {
299 this.comment = comment;
303 public Long getContactId () {
304 return this.contactId;
308 public void setContactId (final Long contactId) {
309 this.contactId = contactId;
313 public Country getCountry () {
318 public void setCountry (final Country country) {
319 this.country = country;
323 public String getEmailAddress () {
324 return this.emailAddress;
328 public void setEmailAddress (final String emailAddress) {
329 this.emailAddress = emailAddress;
333 public String getFamilyName () {
334 return this.familyName;
338 public void setFamilyName (final String familyName) {
339 this.familyName = familyName;
343 public Integer getFaxAreaCode () {
344 return this.faxAreaCode;
348 public void setFaxAreaCode (final Integer faxAreaCode) {
349 this.faxAreaCode = faxAreaCode;
353 public Country getFaxCountry () {
354 return this.faxCountry;
358 public void setFaxCountry (final Country faxCountry) {
359 this.faxCountry = faxCountry;
363 public Long getFaxId () {
368 public void setFaxId (final Long faxId) {
373 public Long getFaxNumber () {
374 return this.faxNumber;
378 public void setFaxNumber (final Long faxNumber) {
379 this.faxNumber = faxNumber;
383 public String getFirstName () {
384 return this.firstName;
388 public void setFirstName (final String firstName) {
389 this.firstName = firstName;
393 public Gender getGender () {
398 public void setGender (final Gender gender) {
399 this.gender = gender;
403 public Short getHouseNumber () {
404 return this.houseNumber;
408 public void setHouseNumber (final Short houseNumber) {
409 this.houseNumber = houseNumber;
413 public Long getLandLineId () {
414 return this.landLineId;
418 public void setLandLineId (final Long landLineId) {
419 this.landLineId = landLineId;
423 public Integer getPhoneAreaCode () {
424 return this.phoneAreaCode;
428 public void setPhoneAreaCode (final Integer phoneAreaCode) {
429 this.phoneAreaCode = phoneAreaCode;
433 public Country getPhoneCountry () {
434 return this.phoneCountry;
438 public void setPhoneCountry (final Country phoneCountry) {
439 this.phoneCountry = phoneCountry;
443 public Long getPhoneNumber () {
444 return this.phoneNumber;
448 public void setPhoneNumber (final Long phoneNumber) {
449 this.phoneNumber = phoneNumber;
453 public String getStreet () {
458 public void setStreet (final String street) {
459 this.street = street;
463 public Integer getZipCode () {
468 public void setZipCode (final Integer zipCode) {
469 this.zipCode = zipCode;
473 * Post-initialization of this class
476 public void init () {