2 * Copyright (C) 2016 Cho-Time GmbH
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.pizzaapplication.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.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;
42 * A user bean (controller)
44 * @author Roland Haeder<roland@mxchange.org>
46 @Named ("adminContactController")
48 public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequestController {
53 private static final long serialVersionUID = 542_145_347_916L;
56 * An event fired when the administrator has added a new contact
60 private Event<AdminAddedContactEvent> addedContactEvent;
65 private Date birthday;
68 * Cellphone number's carrier
70 private MobileProvider cellphoneCarrier;
75 private Long cellphoneId;
80 private Long cellphoneNumber;
90 private String comment;
95 private final ContactSessionBeanRemote contactBean;
100 private Long contactId;
105 private Country country;
110 private String emailAddress;
115 private String familyName;
118 * Fax number's area code
120 private Integer faxAreaCode;
123 * Country instance for fax number
125 private Country faxCountry;
135 private Long faxNumber;
140 private String firstName;
145 private Gender gender;
150 private Short houseNumber;
153 * Land-line id number
155 private Long landLineId;
158 * Phone number area code
160 private Integer phoneAreaCode;
163 * Country instance for phone number
165 private Country phoneCountry;
170 private Long phoneNumber;
175 private String street;
180 private Integer zipCode;
183 * Default constructor
185 public PizzaAdminContactWebRequestBean () {
186 // Set gender to UNKNOWN
187 this.gender = Gender.UNKNOWN;
191 // Get initial context
192 Context context = new InitialContext();
195 this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/PizzaService-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
196 } catch (final NamingException e) {
198 throw new FaceletException(e);
203 public void copyContactToController (final Contact contact) {
205 System.out.println(MessageFormat.format("AdminContactController::copyContactToController(): contact={0} - CALLED!", contact)); //NOI18N
207 // The contact instance must be valid
208 if (null == contact) {
210 throw new NullPointerException("this.user.userContact is null"); //NOI18N
211 } else if (contact.getContactId() < 1) {
213 throw new IllegalStateException(MessageFormat.format("this.user.userContact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
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());
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());
239 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
241 this.setFaxId(contact.getContactFaxNumber().getPhoneId());
242 this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
243 this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
244 this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
247 // Is the land-line number set?
248 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
250 this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
251 this.setPhoneAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
252 this.setPhoneCountry(contact.getContactLandLineNumber().getPhoneCountry());
253 this.setPhoneNumber(contact.getContactLandLineNumber().getPhoneNumber());
257 System.out.println("AdminContactController::copyContactToController(): EXIT!"); //NOI18N
261 public Date getBirthday () {
262 return this.birthday;
266 public void setBirthday (final Date birthday) {
267 this.birthday = birthday;
271 public MobileProvider getCellphoneCarrier () {
272 return this.cellphoneCarrier;
276 public void setCellphoneCarrier (final MobileProvider cellphoneCarrier) {
277 this.cellphoneCarrier = cellphoneCarrier;
281 public Long getCellphoneId () {
282 return this.cellphoneId;
286 public void setCellphoneId (final Long cellphoneId) {
287 this.cellphoneId = cellphoneId;
291 public Long getCellphoneNumber () {
292 return this.cellphoneNumber;
296 public void setCellphoneNumber (Long cellphoneNumber) {
297 this.cellphoneNumber = cellphoneNumber;
301 public String getCity () {
306 public void setCity (final String city) {
311 public String getComment () {
316 public void setComment (final String comment) {
317 this.comment = comment;
321 public Long getContactId () {
322 return this.contactId;
326 public void setContactId (final Long contactId) {
327 this.contactId = contactId;
331 public Country getCountry () {
336 public void setCountry (final Country country) {
337 this.country = country;
341 public String getEmailAddress () {
342 return this.emailAddress;
346 public void setEmailAddress (final String emailAddress) {
347 this.emailAddress = emailAddress;
351 public String getFamilyName () {
352 return this.familyName;
356 public void setFamilyName (final String familyName) {
357 this.familyName = familyName;
361 public Integer getFaxAreaCode () {
362 return this.faxAreaCode;
366 public void setFaxAreaCode (final Integer faxAreaCode) {
367 this.faxAreaCode = faxAreaCode;
371 public Country getFaxCountry () {
372 return this.faxCountry;
376 public void setFaxCountry (final Country faxCountry) {
377 this.faxCountry = faxCountry;
381 public Long getFaxId () {
386 public void setFaxId (final Long faxId) {
391 public Long getFaxNumber () {
392 return this.faxNumber;
396 public void setFaxNumber (final Long faxNumber) {
397 this.faxNumber = faxNumber;
401 public String getFirstName () {
402 return this.firstName;
406 public void setFirstName (final String firstName) {
407 this.firstName = firstName;
411 public Gender getGender () {
416 public void setGender (final Gender gender) {
417 this.gender = gender;
421 public Short getHouseNumber () {
422 return this.houseNumber;
426 public void setHouseNumber (final Short houseNumber) {
427 this.houseNumber = houseNumber;
431 public Long getLandLineId () {
432 return this.landLineId;
436 public void setLandLineId (final Long landLineId) {
437 this.landLineId = landLineId;
441 public Integer getPhoneAreaCode () {
442 return this.phoneAreaCode;
446 public void setPhoneAreaCode (final Integer phoneAreaCode) {
447 this.phoneAreaCode = phoneAreaCode;
451 public Country getPhoneCountry () {
452 return this.phoneCountry;
456 public void setPhoneCountry (final Country phoneCountry) {
457 this.phoneCountry = phoneCountry;
461 public Long getPhoneNumber () {
462 return this.phoneNumber;
466 public void setPhoneNumber (final Long phoneNumber) {
467 this.phoneNumber = phoneNumber;
471 public String getStreet () {
476 public void setStreet (final String street) {
477 this.street = street;
481 public Integer getZipCode () {
486 public void setZipCode (final Integer zipCode) {
487 this.zipCode = zipCode;
491 * Post-initialization of this class
494 public void init () {
500 private void clear () {
502 this.setContactId(null);
503 this.setBirthday(null);
504 this.setCellphoneCarrier(null);
505 this.setCellphoneNumber(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);