2 * Copyright (C) 2016 - 2022 Free Software Foundation
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.phone;
19 import java.text.MessageFormat;
20 import java.util.Calendar;
22 import javax.enterprise.context.RequestScoped;
23 import javax.enterprise.event.Event;
24 import javax.enterprise.event.Observes;
25 import javax.enterprise.inject.Any;
26 import javax.inject.Inject;
27 import javax.inject.Named;
28 import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
29 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
30 import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
31 import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
32 import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
33 import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
34 import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
35 import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent;
36 import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
37 import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
38 import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
39 import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent;
40 import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
41 import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
42 import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
43 import org.mxchange.jcontacts.model.contact.Contact;
44 import org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote;
45 import org.mxchange.jcountry.model.data.Country;
46 import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
47 import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
48 import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
49 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
50 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
51 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
52 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
53 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
54 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
55 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
56 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
57 import org.mxchange.pizzaapplication.beans.BasePizzaBean;
58 import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController;
61 * An administrative contact phone controller (bean)
63 * @author Roland Häder<roland@mxchange.org>
65 @Named ("adminContactPhoneController")
67 public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaBean implements PizzaAdminContactPhoneWebRequestController {
70 * Call-stack instance (5 may show BeanELResolver.getValue as caller)
72 private static final short THREAD_STACK = 5;
77 private static final long serialVersionUID = 542_145_354_001L;
80 * Administrative EJB for phone number
82 @EJB (lookup = "java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote")
83 private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean;
86 * Event being fired when a fax number has been linked
90 private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
93 * Event being fired when a land-line number has been linked
97 private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
100 * Event being fired when a mobile number has been linked
104 private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
107 * Administrative phone controller
110 private PizzaAdminPhoneWebRequestController adminPhoneController;
115 private Contact contact;
118 * Area code (city dial prefix) for fax number
120 private Integer faxAreaCode;
123 * Country (for dial prefix) for fax number
125 private Country faxCountry;
130 private Long faxNumber;
133 * Event being fired when a fax number has been unlinked
137 private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
140 * Area code (city dial prefix) for land-line number
142 private Integer landLineAreaCode;
145 * Country (for dial prefix) for land-line number
147 private Country landLineCountry;
152 private Long landLineNumber;
155 * Event being fired when a land-line number has been unlinked
159 private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
164 private Long mobileNumber;
167 * Event being fired when admin unlinks mobile from contact
171 private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
176 private MobileProvider mobileProvider;
179 * When fax number has been created
181 private Calendar phoneEntryCreated;
184 * When fax number has been updated
186 private Calendar phoneEntryUpdated;
189 * Phone id (primary key)
191 private Long phoneId;
194 * Default constructor
196 public PizzaAdminContactPhoneWebRequestBean () {
197 // Call super constructor
200 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
201 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
205 * Observes events being fired when an administrator has added a new
208 * @param event Event being fired
210 public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
211 // The event must be valid
214 throw new NullPointerException("event is null"); //NOI18N
215 } else if (event.getAddedContact() == null) {
217 throw new NullPointerException("event.addedContact is null"); //NOI18N
218 } else if (event.getAddedContact().getContactId() == null) {
220 throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
221 } else if (event.getAddedContact().getContactId() < 1) {
223 throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
231 * Event observer for newly added users by administrator
233 * @param event Event being fired
235 public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
236 // event should not be null
239 throw new NullPointerException("event is null"); //NOI18N
240 } else if (event.getAddedUser() == null) {
242 throw new NullPointerException("event.addedUser is null"); //NOI18N
243 } else if (event.getAddedUser().getUserId() == null) {
245 throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
246 } else if (event.getAddedUser().getUserId() < 1) {
248 throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
256 * Event observer for updated contact data by administrators
258 * @param event Updated contact data event
260 public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
261 // event should not be null
264 throw new NullPointerException("event is null"); //NOI18N
265 } else if (event.getUpdatedContact() == null) {
267 throw new NullPointerException("event.updatedContact is null"); //NOI18N
268 } else if (event.getUpdatedContact().getContactId() == null) {
270 throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
271 } else if (event.getUpdatedContact().getContactId() < 1) {
273 throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
281 * Observer for events being fired when a bean helper has successfully
282 * created a contact instance.
284 * @param event Event being fired
286 public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
288 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
290 // The event instance must be valid
293 throw new NullPointerException("event is null"); //NOI18N
294 } else if (event.getCreatedContact() == null) {
296 throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
297 } else if (event.getCreatedContact().getContactId() == null) {
299 throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
300 } else if (event.getCreatedContact().getContactId() < 1) {
302 throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
306 this.setContact(event.getCreatedContact());
310 * Observes events being fired when a bean helper has successfully created a
311 * fax number instance.
313 * @param event Event being fired
315 public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
316 // The event instance must be valid
319 throw new NullPointerException("event is null"); //NOI18N
320 } else if (event.getFaxNumber() == null) {
322 throw new NullPointerException("event.faxNumber is null"); //NOI18N
323 } else if (event.getFaxNumber().getPhoneId() == null) {
324 // Throw NPE yet again
325 throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
326 } else if (event.getFaxNumber().getPhoneId() < 1) {
327 // Throw NPE yet again
328 throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
331 // Get fax number from event
332 final DialableFaxNumber number = event.getFaxNumber();
334 // Copy all data to this bean
335 this.setPhoneId(number.getPhoneId());
336 this.setFaxCountry(number.getPhoneCountry());
337 this.setFaxAreaCode(number.getPhoneAreaCode());
338 this.setFaxNumber(number.getPhoneNumber());
339 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
340 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
344 * Observes events being fired when a bean helper has successfully created a
345 * land-line number instance.
347 * @param event Event being fired
349 public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
350 // The event instance must be valid
353 throw new NullPointerException("event is null"); //NOI18N
354 } else if (event.getLandLineNumber() == null) {
356 throw new NullPointerException("event.landLineNumber is null"); //NOI18N
357 } else if (event.getLandLineNumber().getPhoneId() == null) {
358 // Throw NPE yet again
359 throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
360 } else if (event.getLandLineNumber().getPhoneId() < 1) {
361 // Throw NPE yet again
362 throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
365 // Get fax number from event
366 final DialableLandLineNumber number = event.getLandLineNumber();
368 // Copy all data to this bean
369 this.setPhoneId(number.getPhoneId());
370 this.setLandLineCountry(number.getPhoneCountry());
371 this.setLandLineAreaCode(number.getPhoneAreaCode());
372 this.setLandLineNumber(number.getPhoneNumber());
373 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
374 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
378 * Observes events being fired when a bean helper has successfully created a
379 * mobile number instance.
381 * @param event Event being fired
383 public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
384 // The event instance must be valid
387 throw new NullPointerException("event is null"); //NOI18N
388 } else if (event.getMobileNumber() == null) {
390 throw new NullPointerException("event.mobileNumber is null"); //NOI18N
391 } else if (event.getMobileNumber().getPhoneId() == null) {
392 // Throw NPE yet again
393 throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
394 } else if (event.getMobileNumber().getPhoneId() < 1) {
395 // Throw NPE yet again
396 throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
399 // Get fax number from event
400 final DialableMobileNumber number = event.getMobileNumber();
402 // Copy all data to this bean
403 this.setPhoneId(number.getPhoneId());
404 this.setMobileProvider(number.getMobileProvider());
405 this.setMobileNumber(number.getPhoneNumber());
406 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
407 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
411 * Links fax number to contact from bean helper as "main fax number".
413 * @return Redirect outcome
415 public String doLinkMainFaxNumber () {
416 // Get contact from helper
417 final Contact targetContact = this.getContact();
419 // Is all data properly set?
420 if (null == targetContact) {
422 throw new NullPointerException("targetContact is null"); //NOI18N
423 } else if (targetContact.getContactId() == null) {
425 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
426 } else if (targetContact.getContactId() < 1) {
428 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
429 } else if (this.getFaxCountry() == null) {
431 throw new NullPointerException("this.faxCountry is null"); //NOI18N
432 } else if (this.getFaxCountry().getCountryId() == null) {
434 throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
435 } else if (this.getFaxCountry().getCountryId() < 1) {
437 throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
438 } else if (this.getFaxAreaCode() == null) {
440 throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
441 } else if (this.getFaxAreaCode() < 1) {
443 throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
444 } else if (this.getFaxNumber() == null) {
446 throw new NullPointerException("this.faxNumber is null"); //NOI18N
447 } else if (this.getFaxNumber() < 1) {
449 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
453 final Contact updatedContact;
454 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
459 updatedContact = this.adminContactPhoneBean.linkNewFaxNumberWithContact(targetContact, number);
460 } catch (final PhoneNumberAlreadyLinkedException ex) {
461 // Throw again as cause
462 this.showFacesMessage("form_add_contact_fax:faxNumber", ex); //NOI18N
467 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
469 // Return to contact profile
470 return "admin_show_contact"; //NOI18N
474 * Links land-line number to contact from bean helper as "main land-line
477 * @return Redirect outcome
479 public String doLinkMainLandLineNumber () {
480 // Get contact from helper
481 final Contact targetContact = this.getContact();
483 // Is all data properly set?
484 if (null == targetContact) {
486 throw new NullPointerException("targetContact is null"); //NOI18N
487 } else if (targetContact.getContactId() == null) {
489 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
490 } else if (targetContact.getContactId() < 1) {
492 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
493 } else if (this.getLandLineCountry() == null) {
495 throw new NullPointerException("this.landLineCountry is null"); //NOI18N
496 } else if (this.getLandLineCountry().getCountryId() == null) {
498 throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
499 } else if (this.getLandLineCountry().getCountryId() < 1) {
501 throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
502 } else if (this.getLandLineAreaCode() == null) {
504 throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
505 } else if (this.getLandLineAreaCode() < 1) {
507 throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
508 } else if (this.getLandLineNumber() == null) {
510 throw new NullPointerException("this.landLineNumber is null"); //NOI18N
511 } else if (this.getLandLineNumber() < 1) {
513 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
517 final Contact updatedContact;
518 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
523 updatedContact = this.adminContactPhoneBean.linkNewLandLineNumberWithContact(targetContact, number);
524 } catch (final PhoneNumberAlreadyLinkedException ex) {
525 // Throw again as cause
526 this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex); //NOI18N
531 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
533 // Return to contact profile
534 return "admin_show_contact"; //NOI18N
538 * Links mobile number to contact from bean helper as "main mobile number".
540 * @return Redirect outcome
542 public String doLinkMainMobileNumber () {
543 // Get contact from helper
544 final Contact targetContact = this.getContact();
546 // Is all data properly set?
547 if (null == targetContact) {
549 throw new NullPointerException("targetContact is null"); //NOI18N
550 } else if (targetContact.getContactId() == null) {
552 throw new NullPointerException("targetContact.contactId is null"); //NOI18N
553 } else if (targetContact.getContactId() < 1) {
555 throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
556 } else if (this.getMobileProvider() == null) {
558 throw new NullPointerException("this.mobileProvider is null"); //NOI18N
559 } else if (this.getMobileProvider().getProviderId() == null) {
561 throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
562 } else if (this.getMobileProvider().getProviderId() < 1) {
564 throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N
565 } else if (this.getMobileNumber() == null) {
567 throw new NullPointerException("this.mobileNumber is null"); //NOI18N
568 } else if (this.getMobileNumber() < 1) {
570 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N
574 final Contact updatedContact;
575 final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
580 updatedContact = this.adminContactPhoneBean.linkNewMobileNumberWithContact(targetContact, number);
581 } catch (final PhoneNumberAlreadyLinkedException ex) {
582 // Throw again as cause
583 this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex); //NOI18N
588 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number));
590 // Return to contact profile
591 return "admin_show_contact"; //NOI18N
595 * Getter for contact instance
597 * @return Contact instance
599 public Contact getContact () {
604 * Setter for contact instance
606 * @param contact Contact instance
608 public void setContact (final Contact contact) {
609 this.contact = contact;
613 * Getter for fax area code
615 * @return Fax area code
617 public Integer getFaxAreaCode () {
618 return this.faxAreaCode;
622 * Setter for fax area code
624 * @param faxAreaCode Fax area code
626 public void setFaxAreaCode (final Integer faxAreaCode) {
627 this.faxAreaCode = faxAreaCode;
631 * Getter for fax numbers country
633 * @return Fax numbers country
635 public Country getFaxCountry () {
636 return this.faxCountry;
640 * Setter for fax numbers country
642 * @param faxCountry Fax numbers country
644 public void setFaxCountry (final Country faxCountry) {
645 this.faxCountry = faxCountry;
649 * Getter for fax number
653 public Long getFaxNumber () {
654 return this.faxNumber;
658 * Setter for fax number
660 * @param faxNumber Fax number
662 public void setFaxNumber (final Long faxNumber) {
663 this.faxNumber = faxNumber;
667 * Getter for land-line area code
669 * @return Land-line area code
671 public Integer getLandLineAreaCode () {
672 return this.landLineAreaCode;
676 * Setter for land-line area code
678 * @param landLineAreaCode Land-line area code
680 public void setLandLineAreaCode (final Integer landLineAreaCode) {
681 this.landLineAreaCode = landLineAreaCode;
685 * Getter for land-line country
687 * @return Land-line country
689 public Country getLandLineCountry () {
690 return this.landLineCountry;
694 * Setter for land-line country
696 * @param landLineCountry Land-line country
698 public void setLandLineCountry (final Country landLineCountry) {
699 this.landLineCountry = landLineCountry;
703 * Getter for land-line number
705 * @return Land-line number
707 public Long getLandLineNumber () {
708 return this.landLineNumber;
712 * Setter for land-line number
714 * @param landLineNumber Land-line number
716 public void setLandLineNumber (final Long landLineNumber) {
717 this.landLineNumber = landLineNumber;
721 * Getter for mobile number
723 * @return Mobile number
725 public Long getMobileNumber () {
726 return this.mobileNumber;
730 * Setter for mobile number
732 * @param mobileNumber Mobile number
734 public void setMobileNumber (final Long mobileNumber) {
735 this.mobileNumber = mobileNumber;
739 * Getter for mobile provider
741 * @return Mobile provider
743 public MobileProvider getMobileProvider () {
744 return this.mobileProvider;
748 * Setter for mobile provider
750 * @param mobileProvider Mobile provider
752 public void setMobileProvider (final MobileProvider mobileProvider) {
753 this.mobileProvider = mobileProvider;
757 * Setter for phone id
761 public Long getPhoneId () {
766 * Getter for phone id
768 * @param phoneId Phone id
770 public void setPhoneId (final Long phoneId) {
771 this.phoneId = phoneId;
775 * Unlinks fax data with current contact
777 * @return Redirect outcome
779 public String unlinkFaxContactData () {
780 // Create fax number instance
781 final DialableFaxNumber number = this.createFaxNumber();
784 if (number == null) {
785 // Not set, throw NPE
786 throw new NullPointerException("number is null"); //NOI18N
787 } else if (number.getPhoneId() == null) {
789 throw new NullPointerException("number.phoneId is null"); //NOI18N
790 } else if (number.getPhoneId() < 1) {
792 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
793 } else if (number.getPhoneNumber() == null) {
795 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
796 } else if (number.getPhoneNumber() < 1) {
797 // Throw it again ...
798 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
799 } else if (this.getContact() == null) {
800 // ... and throw again
801 throw new NullPointerException("this.contact is null"); //NOI18N
802 } else if (this.getContact().getContactId() == null) {
804 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
805 } else if (this.getContact().getContactId() < 1) {
807 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
810 // Init contact instance
811 final Contact updatedContact;
814 // Unlink it and return contact without fax instance
815 updatedContact = this.adminContactPhoneBean.unlinkFaxDataFromContact(this.getContact(), number);
816 } catch (final PhoneNumberNotLinkedException ex) {
818 this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
823 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, number));
826 return "admin_show_contact"; //NOI18N
830 * Unlinks land-line data with current contact
832 * @return Redirect outcome
834 public String unlinkLandLineContactData () {
835 // Create fax number instance
836 final DialableLandLineNumber number = this.createLandLineNumber();
839 if (number == null) {
840 // Not set, throw NPE
841 throw new NullPointerException("number is null"); //NOI18N
842 } else if (number.getPhoneId() == null) {
844 throw new NullPointerException("number.phoneId is null"); //NOI18N
845 } else if (number.getPhoneId() < 1) {
847 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
848 } else if (number.getPhoneNumber() == null) {
850 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
851 } else if (number.getPhoneNumber() < 1) {
852 // Throw it again ...
853 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
854 } else if (this.getContact() == null) {
855 // ... and throw again
856 throw new NullPointerException("this.contact is null"); //NOI18N
857 } else if (this.getContact().getContactId() == null) {
859 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
860 } else if (this.getContact().getContactId() < 1) {
862 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
865 // Init contact instance
866 final Contact updatedContact;
869 // Unlink it and return contact without landLine instance
870 updatedContact = this.adminContactPhoneBean.unlinkLandLineDataFromContact(this.getContact(), number);
871 } catch (final PhoneNumberNotLinkedException ex) {
873 this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
878 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, number));
881 return "admin_show_contact"; //NOI18N
885 * Unlinks mobile data with current contact
887 * @return Redirect outcome
889 public String unlinkMobileContactData () {
890 // Create fax number instance
891 final DialableMobileNumber number = this.createMobileNumber();
894 if (number == null) {
895 // Not set, throw NPE
896 throw new NullPointerException("number is null"); //NOI18N
897 } else if (number.getPhoneId() == null) {
899 throw new NullPointerException("number.phoneId is null"); //NOI18N
900 } else if (number.getPhoneId() < 1) {
902 throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
903 } else if (number.getMobileProvider() == null) {
905 throw new NullPointerException("number.mobileProvider is null"); //NOI18N
906 } else if (number.getMobileProvider().getProviderId() == null) {
908 throw new NullPointerException("number.mobileProvider.providerId is null"); //NOI18N
909 } else if (number.getMobileProvider().getProviderId() < 1) {
911 throw new IllegalArgumentException(MessageFormat.format("number.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
912 } else if (number.getPhoneNumber() == null) {
914 throw new NullPointerException("number.phoneNumber is null"); //NOI18N
915 } else if (number.getPhoneNumber() < 1) {
916 // Throw it again ...
917 throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
918 } else if (this.getContact() == null) {
919 // ... and throw again
920 throw new NullPointerException("this.contact is null"); //NOI18N
921 } else if (this.getContact().getContactId() == null) {
923 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
924 } else if (this.getContact().getContactId() < 1) {
926 throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
929 // Init contact instance
930 final Contact updatedContact;
933 // Unlink it and return contact without mobile instance
934 updatedContact = this.adminContactPhoneBean.unlinkMobileDataFromContact(this.getContact(), number);
935 } catch (final PhoneNumberNotLinkedException ex) {
937 this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
942 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, number));
945 return "admin_show_contact"; //NOI18N
951 private void clear () {
956 * Creates an instance of a DialableFaxNumber class
958 * @return DialableFaxNumber class
960 private DialableFaxNumber createFaxNumber () {
962 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
964 // Set all other fields
965 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
966 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
968 // Is id number there?
969 if (this.getPhoneId() instanceof Long) {
971 number.setPhoneId(this.getPhoneId());
979 * Returns an instance of a DialableLandLineNumber from all fields stored in
982 * @return An instance of a DialableLandLineNumber class
984 private DialableLandLineNumber createLandLineNumber () {
986 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
988 // Add all other data
989 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
990 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
993 if (this.getPhoneId() instanceof Long) {
995 number.setPhoneId(this.getPhoneId());
1003 * Returns an instance of a DialableMobileNumber from all fields stored in
1006 * @return An instance of a DialableMobileNumber class
1008 private DialableMobileNumber createMobileNumber () {
1010 final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
1012 // Add all other data
1013 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
1014 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
1016 // Is id number set?
1017 if (this.getPhoneId() instanceof Long) {
1019 number.setPhoneId(this.getPhoneId());
1027 * Getter for phone entry created
1029 * @param faxNumberEntryCreated Phone entry created
1031 @SuppressWarnings ("ReturnOfDateField")
1032 private Calendar getPhoneEntryCreated () {
1033 return this.phoneEntryCreated;
1037 * Setter for phone entry created
1039 * @param phoneEntryCreated Phone entry created
1041 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1042 private void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
1043 this.phoneEntryCreated = phoneEntryCreated;
1047 * Getter for phone entry updated
1049 * @return Phone entry updated
1051 @SuppressWarnings ("ReturnOfDateField")
1052 private Calendar getPhoneEntryUpdated () {
1053 return this.phoneEntryUpdated;
1057 * Setter for phone entry updated
1059 * @param phoneEntryUpdated Phone entry updated
1061 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1062 private void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
1063 this.phoneEntryUpdated = phoneEntryUpdated;