]> git.mxchange.org Git - pizzaservice-war.git/blob
79dbe719e1048f08ad489d58e422ebee2c547397
[pizzaservice-war.git] /
1 /*
2  * Copyright (C) 2016 - 2022 Free Software Foundation
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.phone;
18
19 import java.text.MessageFormat;
20 import java.util.Calendar;
21 import javax.ejb.EJB;
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;
59
60 /**
61  * An administrative contact phone controller (bean)
62  * <p>
63  * @author Roland Häder<roland@mxchange.org>
64  */
65 @Named ("adminContactPhoneController")
66 @RequestScoped
67 public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaBean implements PizzaAdminContactPhoneWebRequestController {
68
69         /**
70          * Call-stack instance (5 may show BeanELResolver.getValue as caller)
71          */
72         private static final short THREAD_STACK = 5;
73
74         /**
75          * Serial number
76          */
77         private static final long serialVersionUID = 542_145_354_001L;
78
79         /**
80          * Administrative EJB for phone number
81          */
82         @EJB (lookup = "java:global/pizzaservice-ejb/adminContactPhone!org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote")
83         private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean;
84
85         /**
86          * Event being fired when a fax number has been linked
87          */
88         @Inject
89         @Any
90         private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
91
92         /**
93          * Event being fired when a land-line number has been linked
94          */
95         @Inject
96         @Any
97         private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
98
99         /**
100          * Event being fired when a mobile number has been linked
101          */
102         @Inject
103         @Any
104         private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
105
106         /**
107          * Administrative phone controller
108          */
109         @Inject
110         private PizzaAdminPhoneWebRequestController adminPhoneController;
111
112         /**
113          * Contact instance
114          */
115         private Contact contact;
116
117         /**
118          * Area code (city dial prefix) for fax number
119          */
120         private Integer faxAreaCode;
121
122         /**
123          * Country (for dial prefix) for fax number
124          */
125         private Country faxCountry;
126
127         /**
128          * Fax number
129          */
130         private Long faxNumber;
131
132         /**
133          * Event being fired when a fax number has been unlinked
134          */
135         @Inject
136         @Any
137         private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
138
139         /**
140          * Area code (city dial prefix) for land-line number
141          */
142         private Integer landLineAreaCode;
143
144         /**
145          * Country (for dial prefix) for land-line number
146          */
147         private Country landLineCountry;
148
149         /**
150          * Land-line number
151          */
152         private Long landLineNumber;
153
154         /**
155          * Event being fired when a land-line number has been unlinked
156          */
157         @Inject
158         @Any
159         private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
160
161         /**
162          * Mobile number
163          */
164         private Long mobileNumber;
165
166         /**
167          * Event being fired when admin unlinks mobile from contact
168          */
169         @Inject
170         @Any
171         private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
172
173         /**
174          * Mobile provider
175          */
176         private MobileProvider mobileProvider;
177
178         /**
179          * When fax number has been created
180          */
181         private Calendar phoneEntryCreated;
182
183         /**
184          * When fax number has been updated
185          */
186         private Calendar phoneEntryUpdated;
187
188         /**
189          * Phone id (primary key)
190          */
191         private Long phoneId;
192
193         /**
194          * Default constructor
195          */
196         public PizzaAdminContactPhoneWebRequestBean () {
197                 // Call super constructor
198                 super();
199
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));
202         }
203
204         /**
205          * Observes events being fired when an administrator has added a new
206          * contact.
207          * <p>
208          * @param event Event being fired
209          */
210         public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
211                 // The event must be valid
212                 if (null == event) {
213                         // Throw NPE
214                         throw new NullPointerException("event is null"); //NOI18N
215                 } else if (event.getAddedContact() == null) {
216                         // Throw again ...
217                         throw new NullPointerException("event.addedContact is null"); //NOI18N
218                 } else if (event.getAddedContact().getContactId() == null) {
219                         // ... and again
220                         throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
221                 } else if (event.getAddedContact().getContactId() < 1) {
222                         // Not valid
223                         throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
224                 }
225
226                 // Clear this bean
227                 this.clear();
228         }
229
230         /**
231          * Event observer for newly added users by administrator
232          * <p>
233          * @param event Event being fired
234          */
235         public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
236                 // event should not be null
237                 if (null == event) {
238                         // Throw NPE
239                         throw new NullPointerException("event is null"); //NOI18N
240                 } else if (event.getAddedUser() == null) {
241                         // Throw NPE again
242                         throw new NullPointerException("event.addedUser is null"); //NOI18N
243                 } else if (event.getAddedUser().getUserId() == null) {
244                         // userId is null
245                         throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
246                 } else if (event.getAddedUser().getUserId() < 1) {
247                         // Not avalid id
248                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
249                 }
250
251                 // Clear all data
252                 this.clear();
253         }
254
255         /**
256          * Event observer for updated contact data by administrators
257          * <p>
258          * @param event Updated contact data event
259          */
260         public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
261                 // event should not be null
262                 if (null == event) {
263                         // Throw NPE
264                         throw new NullPointerException("event is null"); //NOI18N
265                 } else if (event.getUpdatedContact() == null) {
266                         // Throw NPE again
267                         throw new NullPointerException("event.updatedContact is null"); //NOI18N
268                 } else if (event.getUpdatedContact().getContactId() == null) {
269                         // userId is null
270                         throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
271                 } else if (event.getUpdatedContact().getContactId() < 1) {
272                         // Not avalid id
273                         throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
274                 }
275
276                 // Clear all data
277                 this.clear();
278         }
279
280         /**
281          * Observer for events being fired when a bean helper has successfully
282          * created a contact instance.
283          * <p>
284          * @param event Event being fired
285          */
286         public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
287                 // Log message
288                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
289
290                 // The event instance must be valid
291                 if (null == event) {
292                         // Throw NPE again
293                         throw new NullPointerException("event is null"); //NOI18N
294                 } else if (event.getCreatedContact() == null) {
295                         // Throw NPE again
296                         throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
297                 } else if (event.getCreatedContact().getContactId() == null) {
298                         // Throw NPE again
299                         throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
300                 } else if (event.getCreatedContact().getContactId() < 1) {
301                         // Not valid
302                         throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
303                 }
304
305                 // Set it here
306                 this.setContact(event.getCreatedContact());
307         }
308
309         /**
310          * Observes events being fired when a bean helper has successfully created a
311          * fax number instance.
312          * <p>
313          * @param event Event being fired
314          */
315         public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
316                 // The event instance must be valid
317                 if (null == event) {
318                         // Throw NPE
319                         throw new NullPointerException("event is null"); //NOI18N
320                 } else if (event.getFaxNumber() == null) {
321                         // Throw NPE again
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
329                 }
330
331                 // Get fax number from event
332                 final DialableFaxNumber number = event.getFaxNumber();
333
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());
341         }
342
343         /**
344          * Observes events being fired when a bean helper has successfully created a
345          * land-line number instance.
346          * <p>
347          * @param event Event being fired
348          */
349         public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
350                 // The event instance must be valid
351                 if (null == event) {
352                         // Throw NPE
353                         throw new NullPointerException("event is null"); //NOI18N
354                 } else if (event.getLandLineNumber() == null) {
355                         // Throw NPE again
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
363                 }
364
365                 // Get fax number from event
366                 final DialableLandLineNumber number = event.getLandLineNumber();
367
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());
375         }
376
377         /**
378          * Observes events being fired when a bean helper has successfully created a
379          * mobile number instance.
380          * <p>
381          * @param event Event being fired
382          */
383         public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
384                 // The event instance must be valid
385                 if (null == event) {
386                         // Throw NPE
387                         throw new NullPointerException("event is null"); //NOI18N
388                 } else if (event.getMobileNumber() == null) {
389                         // Throw NPE again
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
397                 }
398
399                 // Get fax number from event
400                 final DialableMobileNumber number = event.getMobileNumber();
401
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());
408         }
409
410         /**
411          * Links fax number to contact from bean helper as "main fax number".
412          * <p>
413          * @return Redirect outcome
414          */
415         public String doLinkMainFaxNumber () {
416                 // Get contact from helper
417                 final Contact targetContact = this.getContact();
418
419                 // Is all data properly set?
420                 if (null == targetContact) {
421                         // Throw NPE
422                         throw new NullPointerException("targetContact is null"); //NOI18N
423                 } else if (targetContact.getContactId() == null) {
424                         // Throw it again
425                         throw new NullPointerException("targetContact.contactId is null"); //NOI18N
426                 } else if (targetContact.getContactId() < 1) {
427                         // Is not valid
428                         throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
429                 } else if (this.getFaxCountry() == null) {
430                         // Throw NPE again
431                         throw new NullPointerException("this.faxCountry is null"); //NOI18N
432                 } else if (this.getFaxCountry().getCountryId() == null) {
433                         // Throw NPE again
434                         throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
435                 } else if (this.getFaxCountry().getCountryId() < 1) {
436                         // Invalid id number
437                         throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
438                 } else if (this.getFaxAreaCode() == null) {
439                         // Throw NPE again
440                         throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
441                 } else if (this.getFaxAreaCode() < 1) {
442                         // Invalid id number
443                         throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
444                 } else if (this.getFaxNumber() == null) {
445                         // Throw NPE again
446                         throw new NullPointerException("this.faxNumber is null"); //NOI18N
447                 } else if (this.getFaxNumber() < 1) {
448                         // Invalid id number
449                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
450                 }
451
452                 // Init instances
453                 final Contact updatedContact;
454                 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
455
456                 // Try it again
457                 try {
458                         // Link it, too
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
463                         return ""; //NOI18N
464                 }
465
466                 // Fire event
467                 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
468
469                 // Return to contact profile
470                 return "admin_show_contact"; //NOI18N
471         }
472
473         /**
474          * Links land-line number to contact from bean helper as "main land-line
475          * number".
476          * <p>
477          * @return Redirect outcome
478          */
479         public String doLinkMainLandLineNumber () {
480                 // Get contact from helper
481                 final Contact targetContact = this.getContact();
482
483                 // Is all data properly set?
484                 if (null == targetContact) {
485                         // Throw NPE
486                         throw new NullPointerException("targetContact is null"); //NOI18N
487                 } else if (targetContact.getContactId() == null) {
488                         // Throw it again
489                         throw new NullPointerException("targetContact.contactId is null"); //NOI18N
490                 } else if (targetContact.getContactId() < 1) {
491                         // Is not valid
492                         throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
493                 } else if (this.getLandLineCountry() == null) {
494                         // Throw NPE again
495                         throw new NullPointerException("this.landLineCountry is null"); //NOI18N
496                 } else if (this.getLandLineCountry().getCountryId() == null) {
497                         // Throw NPE again
498                         throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
499                 } else if (this.getLandLineCountry().getCountryId() < 1) {
500                         // Invalid id number
501                         throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
502                 } else if (this.getLandLineAreaCode() == null) {
503                         // Throw NPE again
504                         throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
505                 } else if (this.getLandLineAreaCode() < 1) {
506                         // Invalid id number
507                         throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
508                 } else if (this.getLandLineNumber() == null) {
509                         // Throw NPE again
510                         throw new NullPointerException("this.landLineNumber is null"); //NOI18N
511                 } else if (this.getLandLineNumber() < 1) {
512                         // Invalid id number
513                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
514                 }
515
516                 // Init instance
517                 final Contact updatedContact;
518                 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
519
520                 // Try it again
521                 try {
522                         // Link it, too
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
527                         return ""; //NOI18N
528                 }
529
530                 // Fire event
531                 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
532
533                 // Return to contact profile
534                 return "admin_show_contact"; //NOI18N
535         }
536
537         /**
538          * Links mobile number to contact from bean helper as "main mobile number".
539          * <p>
540          * @return Redirect outcome
541          */
542         public String doLinkMainMobileNumber () {
543                 // Get contact from helper
544                 final Contact targetContact = this.getContact();
545
546                 // Is all data properly set?
547                 if (null == targetContact) {
548                         // Throw NPE
549                         throw new NullPointerException("targetContact is null"); //NOI18N
550                 } else if (targetContact.getContactId() == null) {
551                         // Throw it again
552                         throw new NullPointerException("targetContact.contactId is null"); //NOI18N
553                 } else if (targetContact.getContactId() < 1) {
554                         // Is not valid
555                         throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
556                 } else if (this.getMobileProvider() == null) {
557                         // Throw NPE
558                         throw new NullPointerException("this.mobileProvider is null"); //NOI18N
559                 } else if (this.getMobileProvider().getProviderId() == null) {
560                         // Throw NPE
561                         throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
562                 } else if (this.getMobileProvider().getProviderId() < 1) {
563                         // Throw NPE
564                         throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N
565                 } else if (this.getMobileNumber() == null) {
566                         // Throw NPE again
567                         throw new NullPointerException("this.mobileNumber is null"); //NOI18N
568                 } else if (this.getMobileNumber() < 1) {
569                         // Invalid id number
570                         throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N
571                 }
572
573                 // Init instance
574                 final Contact updatedContact;
575                 final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
576
577                 // Try it again
578                 try {
579                         // Link it, too
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
584                         return ""; //NOI18N
585                 }
586
587                 // Fire event
588                 this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number));
589
590                 // Return to contact profile
591                 return "admin_show_contact"; //NOI18N
592         }
593
594         /**
595          * Getter for contact instance
596          * <p>
597          * @return Contact instance
598          */
599         public Contact getContact () {
600                 return this.contact;
601         }
602
603         /**
604          * Setter for contact instance
605          * <p>
606          * @param contact Contact instance
607          */
608         public void setContact (final Contact contact) {
609                 this.contact = contact;
610         }
611
612         /**
613          * Getter for fax area code
614          * <p>
615          * @return Fax area code
616          */
617         public Integer getFaxAreaCode () {
618                 return this.faxAreaCode;
619         }
620
621         /**
622          * Setter for fax area code
623          * <p>
624          * @param faxAreaCode Fax area code
625          */
626         public void setFaxAreaCode (final Integer faxAreaCode) {
627                 this.faxAreaCode = faxAreaCode;
628         }
629
630         /**
631          * Getter for fax numbers country
632          * <p>
633          * @return Fax numbers country
634          */
635         public Country getFaxCountry () {
636                 return this.faxCountry;
637         }
638
639         /**
640          * Setter for fax numbers country
641          * <p>
642          * @param faxCountry Fax numbers country
643          */
644         public void setFaxCountry (final Country faxCountry) {
645                 this.faxCountry = faxCountry;
646         }
647
648         /**
649          * Getter for fax number
650          * <p>
651          * @return Fax number
652          */
653         public Long getFaxNumber () {
654                 return this.faxNumber;
655         }
656
657         /**
658          * Setter for fax number
659          * <p>
660          * @param faxNumber Fax number
661          */
662         public void setFaxNumber (final Long faxNumber) {
663                 this.faxNumber = faxNumber;
664         }
665
666         /**
667          * Getter for land-line area code
668          * <p>
669          * @return Land-line area code
670          */
671         public Integer getLandLineAreaCode () {
672                 return this.landLineAreaCode;
673         }
674
675         /**
676          * Setter for land-line area code
677          * <p>
678          * @param landLineAreaCode Land-line area code
679          */
680         public void setLandLineAreaCode (final Integer landLineAreaCode) {
681                 this.landLineAreaCode = landLineAreaCode;
682         }
683
684         /**
685          * Getter for land-line country
686          * <p>
687          * @return Land-line country
688          */
689         public Country getLandLineCountry () {
690                 return this.landLineCountry;
691         }
692
693         /**
694          * Setter for land-line country
695          * <p>
696          * @param landLineCountry Land-line country
697          */
698         public void setLandLineCountry (final Country landLineCountry) {
699                 this.landLineCountry = landLineCountry;
700         }
701
702         /**
703          * Getter for land-line number
704          * <p>
705          * @return Land-line number
706          */
707         public Long getLandLineNumber () {
708                 return this.landLineNumber;
709         }
710
711         /**
712          * Setter for land-line number
713          * <p>
714          * @param landLineNumber Land-line number
715          */
716         public void setLandLineNumber (final Long landLineNumber) {
717                 this.landLineNumber = landLineNumber;
718         }
719
720         /**
721          * Getter for mobile number
722          * <p>
723          * @return Mobile number
724          */
725         public Long getMobileNumber () {
726                 return this.mobileNumber;
727         }
728
729         /**
730          * Setter for mobile number
731          * <p>
732          * @param mobileNumber Mobile number
733          */
734         public void setMobileNumber (final Long mobileNumber) {
735                 this.mobileNumber = mobileNumber;
736         }
737
738         /**
739          * Getter for mobile provider
740          * <p>
741          * @return Mobile provider
742          */
743         public MobileProvider getMobileProvider () {
744                 return this.mobileProvider;
745         }
746
747         /**
748          * Setter for mobile provider
749          * <p>
750          * @param mobileProvider Mobile provider
751          */
752         public void setMobileProvider (final MobileProvider mobileProvider) {
753                 this.mobileProvider = mobileProvider;
754         }
755
756         /**
757          * Setter for phone id
758          * <p>
759          * @return Phone id
760          */
761         public Long getPhoneId () {
762                 return this.phoneId;
763         }
764
765         /**
766          * Getter for phone id
767          * <p>
768          * @param phoneId Phone id
769          */
770         public void setPhoneId (final Long phoneId) {
771                 this.phoneId = phoneId;
772         }
773
774         /**
775          * Unlinks fax data with current contact
776          * <p>
777          * @return Redirect outcome
778          */
779         public String unlinkFaxContactData () {
780                 // Create fax number instance
781                 final DialableFaxNumber number = this.createFaxNumber();
782
783                 // Is all data set
784                 if (number == null) {
785                         // Not set, throw NPE
786                         throw new NullPointerException("number is null"); //NOI18N
787                 } else if (number.getPhoneId() == null) {
788                         // Throw NPE again
789                         throw new NullPointerException("number.phoneId is null"); //NOI18N
790                 } else if (number.getPhoneId() < 1) {
791                         // Invalid number
792                         throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
793                 } else if (number.getPhoneNumber() == null) {
794                         // Throw NPE again
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) {
803                         // ... and again ...
804                         throw new NullPointerException("this.contact.contactId is null"); //NOI18N
805                 } else if (this.getContact().getContactId() < 1) {
806                         // Invalid id number
807                         throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
808                 }
809
810                 // Init contact instance
811                 final Contact updatedContact;
812
813                 try {
814                         // Unlink it and return contact without fax instance
815                         updatedContact = this.adminContactPhoneBean.unlinkFaxDataFromContact(this.getContact(), number);
816                 } catch (final PhoneNumberNotLinkedException ex) {
817                         // Did not work
818                         this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
819                         return ""; //NOI18N
820                 }
821
822                 // Fire event
823                 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, number));
824
825                 // All fine here
826                 return "admin_show_contact"; //NOI18N
827         }
828
829         /**
830          * Unlinks land-line data with current contact
831          * <p>
832          * @return Redirect outcome
833          */
834         public String unlinkLandLineContactData () {
835                 // Create fax number instance
836                 final DialableLandLineNumber number = this.createLandLineNumber();
837
838                 // Is all data set
839                 if (number == null) {
840                         // Not set, throw NPE
841                         throw new NullPointerException("number is null"); //NOI18N
842                 } else if (number.getPhoneId() == null) {
843                         // Throw NPE again
844                         throw new NullPointerException("number.phoneId is null"); //NOI18N
845                 } else if (number.getPhoneId() < 1) {
846                         // Invalid number
847                         throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
848                 } else if (number.getPhoneNumber() == null) {
849                         // Throw NPE again
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) {
858                         // ... and again ...
859                         throw new NullPointerException("this.contact.contactId is null"); //NOI18N
860                 } else if (this.getContact().getContactId() < 1) {
861                         // Invalid id number
862                         throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
863                 }
864
865                 // Init contact instance
866                 final Contact updatedContact;
867
868                 try {
869                         // Unlink it and return contact without landLine instance
870                         updatedContact = this.adminContactPhoneBean.unlinkLandLineDataFromContact(this.getContact(), number);
871                 } catch (final PhoneNumberNotLinkedException ex) {
872                         // Did not work
873                         this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
874                         return ""; //NOI18N
875                 }
876
877                 // Fire event
878                 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, number));
879
880                 // All fine here
881                 return "admin_show_contact"; //NOI18N
882         }
883
884         /**
885          * Unlinks mobile data with current contact
886          * <p>
887          * @return Redirect outcome
888          */
889         public String unlinkMobileContactData () {
890                 // Create fax number instance
891                 final DialableMobileNumber number = this.createMobileNumber();
892
893                 // Is all data set
894                 if (number == null) {
895                         // Not set, throw NPE
896                         throw new NullPointerException("number is null"); //NOI18N
897                 } else if (number.getPhoneId() == null) {
898                         // Throw NPE again
899                         throw new NullPointerException("number.phoneId is null"); //NOI18N
900                 } else if (number.getPhoneId() < 1) {
901                         // Invalid number
902                         throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
903                 } else if (number.getMobileProvider() == null) {
904                         // Throw NPE
905                         throw new NullPointerException("number.mobileProvider is null"); //NOI18N
906                 } else if (number.getMobileProvider().getProviderId() == null) {
907                         // ... throw again
908                         throw new NullPointerException("number.mobileProvider.providerId is null"); //NOI18N
909                 } else if (number.getMobileProvider().getProviderId() < 1) {
910                         // Id not valid
911                         throw new IllegalArgumentException(MessageFormat.format("number.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
912                 } else if (number.getPhoneNumber() == null) {
913                         // Throw NPE again
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) {
922                         // ... and again ...
923                         throw new NullPointerException("this.contact.contactId is null"); //NOI18N
924                 } else if (this.getContact().getContactId() < 1) {
925                         // Invalid id number
926                         throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
927                 }
928
929                 // Init contact instance
930                 final Contact updatedContact;
931
932                 try {
933                         // Unlink it and return contact without mobile instance
934                         updatedContact = this.adminContactPhoneBean.unlinkMobileDataFromContact(this.getContact(), number);
935                 } catch (final PhoneNumberNotLinkedException ex) {
936                         // Did not work
937                         this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N
938                         return ""; //NOI18N
939                 }
940
941                 // Fire event
942                 this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, number));
943
944                 // All fine here
945                 return "admin_show_contact"; //NOI18N
946         }
947
948         /**
949          * Clears this bean
950          */
951         private void clear () {
952                 // Clear all data
953         }
954
955         /**
956          * Creates an instance of a DialableFaxNumber class
957          * <p>
958          * @return DialableFaxNumber class
959          */
960         private DialableFaxNumber createFaxNumber () {
961                 // Instanciate it
962                 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
963
964                 // Set all other fields
965                 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
966                 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
967
968                 // Is id number there?
969                 if (this.getPhoneId() instanceof Long) {
970                         // Set it
971                         number.setPhoneId(this.getPhoneId());
972                 }
973
974                 // Return it
975                 return number;
976         }
977
978         /**
979          * Returns an instance of a DialableLandLineNumber from all fields stored in
980          * this bean.
981          * <p>
982          * @return An instance of a DialableLandLineNumber class
983          */
984         private DialableLandLineNumber createLandLineNumber () {
985                 // Initialize it
986                 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
987
988                 // Add all other data
989                 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
990                 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
991
992                 // Is id number set?
993                 if (this.getPhoneId() instanceof Long) {
994                         // Set it
995                         number.setPhoneId(this.getPhoneId());
996                 }
997
998                 // Return it
999                 return number;
1000         }
1001
1002         /**
1003          * Returns an instance of a DialableMobileNumber from all fields stored in
1004          * this bean.
1005          * <p>
1006          * @return An instance of a DialableMobileNumber class
1007          */
1008         private DialableMobileNumber createMobileNumber () {
1009                 // Initialize it
1010                 final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
1011
1012                 // Add all other data
1013                 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
1014                 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
1015
1016                 // Is id number set?
1017                 if (this.getPhoneId() instanceof Long) {
1018                         // Set it
1019                         number.setPhoneId(this.getPhoneId());
1020                 }
1021
1022                 // Return it
1023                 return number;
1024         }
1025
1026         /**
1027          * Getter for phone entry created
1028          * <p>
1029          * @param faxNumberEntryCreated Phone entry created
1030          */
1031         @SuppressWarnings ("ReturnOfDateField")
1032         private Calendar getPhoneEntryCreated () {
1033                 return this.phoneEntryCreated;
1034         }
1035
1036         /**
1037          * Setter for phone entry created
1038          * <p>
1039          * @param phoneEntryCreated Phone entry created
1040          */
1041         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1042         private void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
1043                 this.phoneEntryCreated = phoneEntryCreated;
1044         }
1045
1046         /**
1047          * Getter for phone entry updated
1048          * <p>
1049          * @return Phone entry updated
1050          */
1051         @SuppressWarnings ("ReturnOfDateField")
1052         private Calendar getPhoneEntryUpdated () {
1053                 return this.phoneEntryUpdated;
1054         }
1055
1056         /**
1057          * Setter for phone entry updated
1058          * <p>
1059          * @param phoneEntryUpdated Phone entry updated
1060          */
1061         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
1062         private void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
1063                 this.phoneEntryUpdated = phoneEntryUpdated;
1064         }
1065
1066 }