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