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