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