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