]> 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.model.contact.Contact;
41 import org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote;
42 import org.mxchange.jcountry.model.data.Country;
43 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
44 import org.mxchange.jfinancials.beans.phone.FinancialsAdminPhoneWebRequestController;
45 import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
46 import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
47 import org.mxchange.jphone.exceptions.phone.PhoneNumberAlreadyLinkedException;
48 import org.mxchange.jphone.exceptions.phone.PhoneNumberNotLinkedException;
49 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
50 import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
51 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
52 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
53 import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
54
55 /**
56  * An administrative contact phone controller (bean)
57  * <p>
58  * @author Roland Häder<roland@mxchange.org>
59  */
60 @Named ("adminContactPhoneController")
61 @RequestScoped
62 public class FinancialsAdminContactPhoneWebRequestBean extends BaseFinancialsBean implements FinancialsAdminContactPhoneWebRequestController {
63
64         /**
65          * Call-stack instance (5 may show BeanELResolver.getValue as caller)
66          */
67         private static final short THREAD_STACK = 5;
68
69         /**
70          * Serial number
71          */
72         private static final long serialVersionUID = 542_145_347_916L;
73
74         /**
75          * Administrative EJB for phone number
76          */
77         @EJB (lookup = "java:global/jfinancials-ejb/adminContactPhone!org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote")
78         private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean;
79
80         /**
81          * Event being fired when a fax number has been linked
82          */
83         @Inject
84         @Any
85         private Event<ObservableAdminLinkedFaxNumberEvent> adminLinkedFaxNumberEvent;
86
87         /**
88          * Event being fired when a land-line number has been linked
89          */
90         @Inject
91         @Any
92         private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
93
94         /**
95          * Administrative phone controller
96          */
97         @Inject
98         private FinancialsAdminPhoneWebRequestController adminPhoneController;
99
100         /**
101          * Contact instance
102          */
103         private Contact contact;
104
105         /**
106          * Area code (city dial prefix) for fax number
107          */
108         private Integer faxAreaCode;
109
110         /**
111          * Country (for dial prefix) for fax number
112          */
113         private Country faxCountry;
114
115         /**
116          * Fax number
117          */
118         private Long faxNumber;
119
120         /**
121          * Event being fired when a fax number has been unlinked
122          */
123         @Inject
124         @Any
125         private Event<ObservableAdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
126
127         /**
128          * Area code (city dial prefix) for land-line number
129          */
130         private Integer landLineAreaCode;
131
132         /**
133          * Country (for dial prefix) for land-line number
134          */
135         private Country landLineCountry;
136
137         /**
138          * Land-line number
139          */
140         private Long landLineNumber;
141
142         /**
143          * Event being fired when a land-line number has been unlinked
144          */
145         @Inject
146         @Any
147         private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
148
149         /**
150          * When phone number has been created
151          */
152         private Date phoneEntryCreated;
153
154         /**
155          * When phone number has been updated
156          */
157         private Date phoneEntryUpdated;
158
159         /**
160          * Phone id (primary key)
161          */
162         private Long phoneId;
163
164         /**
165          * Default constructor
166          */
167         public FinancialsAdminContactPhoneWebRequestBean () {
168                 // Call super constructor
169                 super();
170
171                 // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName());
172                 // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller));
173         }
174
175         /**
176          * Observes events being fired when an administrator has added a new
177          * contact.
178          * <p>
179          * @param event Event being fired
180          */
181         public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) {
182                 // The event must be valid
183                 if (null == event) {
184                         // Throw NPE
185                         throw new NullPointerException("event is null"); //NOI18N
186                 } else if (event.getAddedContact() == null) {
187                         // Throw again ...
188                         throw new NullPointerException("event.addedContact is null"); //NOI18N
189                 } else if (event.getAddedContact().getContactId() == null) {
190                         // ... and again
191                         throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N
192                 } else if (event.getAddedContact().getContactId() < 1) {
193                         // Not valid
194                         throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N
195                 }
196
197                 // Clear this bean
198                 this.clear();
199         }
200
201         /**
202          * Event observer for newly added users by administrator
203          * <p>
204          * @param event Event being fired
205          */
206         public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
207                 // Event and contained entity instance should not be null
208                 if (null == event) {
209                         // Throw NPE
210                         throw new NullPointerException("event is null"); //NOI18N
211                 } else if (event.getAddedUser() == null) {
212                         // Throw NPE again
213                         throw new NullPointerException("event.addedUser is null"); //NOI18N
214                 } else if (event.getAddedUser().getUserId() == null) {
215                         // userId is null
216                         throw new NullPointerException("event.addedUser.userId is null"); //NOI18N
217                 } else if (event.getAddedUser().getUserId() < 1) {
218                         // Not avalid id
219                         throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N
220                 }
221
222                 // Clear all data
223                 this.clear();
224         }
225
226         /**
227          * Event observer for updated contact data by administrators
228          * <p>
229          * @param event Updated contact data event
230          */
231         public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
232                 // Event and contained entity instance should not be null
233                 if (null == event) {
234                         // Throw NPE
235                         throw new NullPointerException("event is null"); //NOI18N
236                 } else if (event.getUpdatedContact() == null) {
237                         // Throw NPE again
238                         throw new NullPointerException("event.updatedContact is null"); //NOI18N
239                 } else if (event.getUpdatedContact().getContactId() == null) {
240                         // userId is null
241                         throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N
242                 } else if (event.getUpdatedContact().getContactId() < 1) {
243                         // Not avalid id
244                         throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
245                 }
246
247                 // Clear all data
248                 this.clear();
249         }
250
251         /**
252          * Observer for events being fired when a bean helper has successfully
253          * created a contact instance.
254          * <p>
255          * @param event Event being fired
256          */
257         public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) {
258                 // Log message
259                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N
260
261                 // The event instance must be valid
262                 if (null == event) {
263                         // Throw NPE again
264                         throw new NullPointerException("event is null"); //NOI18N
265                 } else if (event.getCreatedContact() == null) {
266                         // Throw NPE again
267                         throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
268                 } else if (event.getCreatedContact().getContactId() == null) {
269                         // Throw NPE again
270                         throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
271                 } else if (event.getCreatedContact().getContactId() < 1) {
272                         // Not valid
273                         throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N
274                 }
275
276                 // Set it here
277                 this.setContact(event.getCreatedContact());
278         }
279
280         /**
281          * Observes events being fired when a bean helper has successfully created a
282          * fax number instance.
283          * <p>
284          * @param event Event being fired
285          */
286         public void afterCreatedFaxNumberEvent (@Observes final ObservableCreatedFaxNumberEvent event) {
287                 // The event instance must be valid
288                 if (null == event) {
289                         // Throw NPE
290                         throw new NullPointerException("event is null"); //NOI18N
291                 } else if (event.getFaxNumber() == null) {
292                         // Throw NPE again
293                         throw new NullPointerException("event.faxNumber is null"); //NOI18N
294                 } else if (event.getFaxNumber().getPhoneId() == null) {
295                         // Throw NPE yet again
296                         throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
297                 } else if (event.getFaxNumber().getPhoneId() < 1) {
298                         // Throw NPE yet again
299                         throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
300                 }
301
302                 // Get fax number from event
303                 final DialableFaxNumber number = event.getFaxNumber();
304
305                 // Copy all data to this bean
306                 this.setPhoneId(number.getPhoneId());
307                 this.setFaxCountry(number.getPhoneCountry());
308                 this.setFaxAreaCode(number.getPhoneAreaCode());
309                 this.setFaxNumber(number.getPhoneNumber());
310                 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
311                 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
312         }
313
314         /**
315          * Observes events being fired when a bean helper has successfully created a
316          * land-line number instance.
317          * <p>
318          * @param event Event being fired
319          */
320         public void afterCreatedLandLineNumberEvent (@Observes final ObservableCreatedLandLineNumberEvent event) {
321                 // The event instance must be valid
322                 if (null == event) {
323                         // Throw NPE
324                         throw new NullPointerException("event is null"); //NOI18N
325                 } else if (event.getLandLineNumber() == null) {
326                         // Throw NPE again
327                         throw new NullPointerException("event.landLineNumber is null"); //NOI18N
328                 } else if (event.getLandLineNumber().getPhoneId() == null) {
329                         // Throw NPE yet again
330                         throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
331                 } else if (event.getLandLineNumber().getPhoneId() < 1) {
332                         // Throw NPE yet again
333                         throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getLandLineNumber().getPhoneId())); //NOI18N
334                 }
335
336                 // Get fax number from event
337                 final DialableLandLineNumber number = event.getLandLineNumber();
338
339                 // Copy all data to this bean
340                 this.setPhoneId(number.getPhoneId());
341                 this.setLandLineCountry(number.getPhoneCountry());
342                 this.setLandLineAreaCode(number.getPhoneAreaCode());
343                 this.setLandLineNumber(number.getPhoneNumber());
344                 this.setPhoneEntryCreated(number.getPhoneEntryCreated());
345                 this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
346         }
347
348         /**
349          * Links fax number to contact from bean helper as "main fax number".
350          * <p>
351          * @return Redirect outcome
352          */
353         public String doLinkMainFaxNumber () {
354                 // Get contact from helper
355                 final Contact targetContact = this.getContact();
356
357                 // Is all data properly set?
358                 if (null == targetContact) {
359                         // Throw NPE
360                         throw new NullPointerException("targetContact is null"); //NOI18N
361                 } else if (targetContact.getContactId() == null) {
362                         // Throw it again
363                         throw new NullPointerException("targetContact.contactId is null"); //NOI18N
364                 } else if (targetContact.getContactId() < 1) {
365                         // Is not valid
366                         throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
367                 } else if (this.getFaxCountry() == null) {
368                         // Throw NPE again
369                         throw new NullPointerException("this.faxCountry is null"); //NOI18N
370                 } else if (this.getFaxCountry().getCountryId() == null) {
371                         // Throw NPE again
372                         throw new NullPointerException("this.faxCountry.countryId is null"); //NOI18N
373                 } else if (this.getFaxCountry().getCountryId() < 1) {
374                         // Invalid id number
375                         throw new IllegalArgumentException(MessageFormat.format("this.faxCountry.countryId={0} is not valid.", this.getFaxCountry().getCountryId())); //NOI18N
376                 } else if (this.getFaxAreaCode() == null) {
377                         // Throw NPE again
378                         throw new NullPointerException("this.faxAreaCode is null"); //NOI18N
379                 } else if (this.getFaxAreaCode() < 1) {
380                         // Invalid id number
381                         throw new IllegalArgumentException(MessageFormat.format("this.faxAreaCode={0} is invalid", this.getFaxAreaCode())); //NOI18N
382                 } else if (this.getFaxNumber() == null) {
383                         // Throw NPE again
384                         throw new NullPointerException("this.faxNumber is null"); //NOI18N
385                 } else if (this.getFaxNumber() < 1) {
386                         // Invalid id number
387                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber={0} is invalid", this.getFaxNumber())); //NOI18N
388                 }
389
390                 // Init instances
391                 final Contact updatedContact;
392                 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
393
394                 // Try it again
395                 try {
396                         // Link it, too
397                         updatedContact = this.adminContactPhoneBean.linkNewFaxNumberWithContact(targetContact, number);
398                 } catch (final PhoneNumberAlreadyLinkedException ex) {
399                         // Throw again as cause
400                         this.showFacesMessage("form_add_contact_fax:faxNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
401                         return ""; //NOI18N
402                 }
403
404                 // Fire event
405                 this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, number));
406
407                 // Return to contact profile
408                 return "admin_show_contact"; //NOI18N
409         }
410
411         /**
412          * Links land-line number to contact from bean helper as "main land-line
413          * number".
414          * <p>
415          * @return Redirect outcome
416          */
417         public String doLinkMainLandLineNumber () {
418                 // Get contact from helper
419                 final Contact targetContact = this.getContact();
420
421                 // Is all data properly set?
422                 if (null == targetContact) {
423                         // Throw NPE
424                         throw new NullPointerException("targetContact is null"); //NOI18N
425                 } else if (targetContact.getContactId() == null) {
426                         // Throw it again
427                         throw new NullPointerException("targetContact.contactId is null"); //NOI18N
428                 } else if (targetContact.getContactId() < 1) {
429                         // Is not valid
430                         throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N
431                 } else if (this.getLandLineCountry() == null) {
432                         // Throw NPE again
433                         throw new NullPointerException("this.landLineCountry is null"); //NOI18N
434                 } else if (this.getLandLineCountry().getCountryId() == null) {
435                         // Throw NPE again
436                         throw new NullPointerException("this.landLineCountry.countryId is null"); //NOI18N
437                 } else if (this.getLandLineCountry().getCountryId() < 1) {
438                         // Invalid id number
439                         throw new IllegalArgumentException(MessageFormat.format("this.landLineCountry.countryId={0} is not valid.", this.getLandLineCountry().getCountryId())); //NOI18N
440                 } else if (this.getLandLineAreaCode() == null) {
441                         // Throw NPE again
442                         throw new NullPointerException("this.landLineAreaCode is null"); //NOI18N
443                 } else if (this.getLandLineAreaCode() < 1) {
444                         // Invalid id number
445                         throw new IllegalArgumentException(MessageFormat.format("this.landLineAreaCode={0} is invalid", this.getLandLineAreaCode())); //NOI18N
446                 } else if (this.getLandLineNumber() == null) {
447                         // Throw NPE again
448                         throw new NullPointerException("this.landLineNumber is null"); //NOI18N
449                 } else if (this.getLandLineNumber() < 1) {
450                         // Invalid id number
451                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber={0} is invalid", this.getLandLineNumber())); //NOI18N
452                 }
453
454                 // Init instance
455                 final Contact updatedContact;
456                 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
457
458                 // Try it again
459                 try {
460                         // Link it, too
461                         updatedContact = this.adminContactPhoneBean.linkNewLandLineNumberWithContact(targetContact, number);
462                 } catch (final PhoneNumberAlreadyLinkedException ex) {
463                         // Throw again as cause
464                         this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
465                         return ""; //NOI18N
466                 }
467
468                 // Fire event
469                 this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, number));
470
471                 // Return to contact profile
472                 return "admin_show_contact"; //NOI18N
473         }
474
475         /**
476          * Getter for contact instance
477          * <p>
478          * @return Contact instance
479          */
480         public Contact getContact () {
481                 return this.contact;
482         }
483
484         /**
485          * Setter for contact instance
486          * <p>
487          * @param contact Contact instance
488          */
489         public void setContact (final Contact contact) {
490                 this.contact = contact;
491         }
492
493         /**
494          * Getter for fax area code
495          * <p>
496          * @return Fax area code
497          */
498         public Integer getFaxAreaCode () {
499                 return this.faxAreaCode;
500         }
501
502         /**
503          * Setter for fax area code
504          * <p>
505          * @param faxAreaCode Fax area code
506          */
507         public void setFaxAreaCode (final Integer faxAreaCode) {
508                 this.faxAreaCode = faxAreaCode;
509         }
510
511         /**
512          * Getter for fax numbers country
513          * <p>
514          * @return Fax numbers country
515          */
516         public Country getFaxCountry () {
517                 return this.faxCountry;
518         }
519
520         /**
521          * Setter for fax numbers country
522          * <p>
523          * @param faxCountry Fax numbers country
524          */
525         public void setFaxCountry (final Country faxCountry) {
526                 this.faxCountry = faxCountry;
527         }
528
529         /**
530          * Getter for fax number
531          * <p>
532          * @return Fax number
533          */
534         public Long getFaxNumber () {
535                 return this.faxNumber;
536         }
537
538         /**
539          * Setter for fax number
540          * <p>
541          * @param faxNumber Fax number
542          */
543         public void setFaxNumber (final Long faxNumber) {
544                 this.faxNumber = faxNumber;
545         }
546
547         /**
548          * Getter for land-line area code
549          * <p>
550          * @return Land-line area code
551          */
552         public Integer getLandLineAreaCode () {
553                 return this.landLineAreaCode;
554         }
555
556         /**
557          * Setter for land-line area code
558          * <p>
559          * @param landLineAreaCode Land-line area code
560          */
561         public void setLandLineAreaCode (final Integer landLineAreaCode) {
562                 this.landLineAreaCode = landLineAreaCode;
563         }
564
565         /**
566          * Getter for land-line country
567          * <p>
568          * @return Land-line country
569          */
570         public Country getLandLineCountry () {
571                 return this.landLineCountry;
572         }
573
574         /**
575          * Setter for land-line country
576          * <p>
577          * @param landLineCountry Land-line country
578          */
579         public void setLandLineCountry (final Country landLineCountry) {
580                 this.landLineCountry = landLineCountry;
581         }
582
583         /**
584          * Getter for land-line number
585          * <p>
586          * @return Land-line number
587          */
588         public Long getLandLineNumber () {
589                 return this.landLineNumber;
590         }
591
592         /**
593          * Setter for land-line number
594          * <p>
595          * @param landLineNumber Land-line number
596          */
597         public void setLandLineNumber (final Long landLineNumber) {
598                 this.landLineNumber = landLineNumber;
599         }
600
601         /**
602          * Setter for phone id
603          * <p>
604          * @return Phone id
605          */
606         public Long getPhoneId () {
607                 return this.phoneId;
608         }
609
610         /**
611          * Getter for phone id
612          * <p>
613          * @param phoneId Phone id
614          */
615         public void setPhoneId (final Long phoneId) {
616                 this.phoneId = phoneId;
617         }
618
619         /**
620          * Unlinks fax data with current contact
621          * <p>
622          * @return Redirect outcome
623          */
624         public String unlinkFaxContactData () {
625                 // Create fax number instance
626                 final DialableFaxNumber number = this.createFaxNumber();
627
628                 // Is all data set
629                 if (number == null) {
630                         // Not set, throw NPE
631                         throw new NullPointerException("number is null"); //NOI18N
632                 } else if (number.getPhoneId() == null) {
633                         // Throw NPE again
634                         throw new NullPointerException("number.phoneId is null"); //NOI18N
635                 } else if (number.getPhoneId() < 1) {
636                         // Invalid number
637                         throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
638                 } else if (number.getPhoneNumber() == null) {
639                         // Throw NPE again
640                         throw new NullPointerException("number.phoneNumber is null"); //NOI18N
641                 } else if (number.getPhoneNumber() < 1) {
642                         // Throw it again ...
643                         throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
644                 } else if (this.getContact() == null) {
645                         // ... and throw again
646                         throw new NullPointerException("this.contact is null"); //NOI18N
647                 } else if (this.getContact().getContactId() == null) {
648                         // ... and again ...
649                         throw new NullPointerException("this.contact.contactId is null"); //NOI18N
650                 } else if (this.getContact().getContactId() < 1) {
651                         // Invalid id number
652                         throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
653                 }
654
655                 // Init contact instance
656                 final Contact updatedContact;
657
658                 try {
659                         // Unlink it and return contact without fax instance
660                         updatedContact = this.adminContactPhoneBean.unlinkFaxDataFromContact(this.getContact(), number);
661                 } catch (final PhoneNumberNotLinkedException ex) {
662                         // Did not work
663                         this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
664                         return ""; //NOI18N
665                 }
666
667                 // Fire event
668                 this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, number));
669
670                 // All fine here
671                 return "admin_show_contact"; //NOI18N
672         }
673
674         /**
675          * Unlinks land-line data with current contact
676          * <p>
677          * @return Redirect outcome
678          */
679         public String unlinkLandLineContactData () {
680                 // Create fax number instance
681                 final DialableLandLineNumber number = this.createLandLineNumber();
682
683                 // Is all data set
684                 if (number == null) {
685                         // Not set, throw NPE
686                         throw new NullPointerException("number is null"); //NOI18N
687                 } else if (number.getPhoneId() == null) {
688                         // Throw NPE again
689                         throw new NullPointerException("number.phoneId is null"); //NOI18N
690                 } else if (number.getPhoneId() < 1) {
691                         // Invalid number
692                         throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
693                 } else if (number.getPhoneNumber() == null) {
694                         // Throw NPE again
695                         throw new NullPointerException("number.phoneNumber is null"); //NOI18N
696                 } else if (number.getPhoneNumber() < 1) {
697                         // Throw it again ...
698                         throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
699                 } else if (this.getContact() == null) {
700                         // ... and throw again
701                         throw new NullPointerException("this.contact is null"); //NOI18N
702                 } else if (this.getContact().getContactId() == null) {
703                         // ... and again ...
704                         throw new NullPointerException("this.contact.contactId is null"); //NOI18N
705                 } else if (this.getContact().getContactId() < 1) {
706                         // Invalid id number
707                         throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N
708                 }
709
710                 // Init contact instance
711                 final Contact updatedContact;
712
713                 try {
714                         // Unlink it and return contact without landLine instance
715                         updatedContact = this.adminContactPhoneBean.unlinkLandLineDataFromContact(this.getContact(), number);
716                 } catch (final PhoneNumberNotLinkedException ex) {
717                         // Did not work
718                         this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
719                         return ""; //NOI18N
720                 }
721
722                 // Fire event
723                 this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, number));
724
725                 // All fine here
726                 return "admin_show_contact"; //NOI18N
727         }
728
729         /**
730          * Clears this bean
731          */
732         private void clear () {
733                 // Clear all data
734         }
735
736         /**
737          * Creates an instance of a DialableFaxNumber class
738          * <p>
739          * @return DialableFaxNumber class
740          */
741         private DialableFaxNumber createFaxNumber () {
742                 // Instanciate it
743                 final DialableFaxNumber number = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
744
745                 // Set all other fields
746                 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
747                 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
748                 number.setPhoneId(this.getPhoneId());
749
750                 // Return it
751                 return number;
752         }
753
754         /**
755          * Returns an instance of a DialableLandLineNumber from all fields stored in
756          * this bean.
757          * <p>
758          * @return An instance of a DialableLandLineNumber class
759          */
760         private DialableLandLineNumber createLandLineNumber () {
761                 // Initialize it
762                 final DialableLandLineNumber number = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
763
764                 // Add all other data
765                 number.setPhoneEntryCreated(this.getPhoneEntryCreated());
766                 number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
767                 number.setPhoneId(this.getPhoneId());
768
769                 // Return it
770                 return number;
771         }
772
773         /**
774          * Getter for phone entry created
775          * <p>
776          * @return Phone entry created
777          */
778         @SuppressWarnings ("ReturnOfDateField")
779         private Date getPhoneEntryCreated () {
780                 return this.phoneEntryCreated;
781         }
782
783         /**
784          * Setter for phone entry created
785          * <p>
786          * @param phoneEntryCreated Phone entry created
787          */
788         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
789         private void setPhoneEntryCreated (final Date phoneEntryCreated) {
790                 this.phoneEntryCreated = phoneEntryCreated;
791         }
792
793         /**
794          * Getter for phone entry updated
795          * <p>
796          * @return Phone entry updated
797          */
798         @SuppressWarnings ("ReturnOfDateField")
799         private Date getPhoneEntryUpdated () {
800                 return this.phoneEntryUpdated;
801         }
802
803         /**
804          * Setter for phone entry updated
805          * <p>
806          * @param phoneEntryUpdated Phone entry updated
807          */
808         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
809         private void setPhoneEntryUpdated (final Date phoneEntryUpdated) {
810                 this.phoneEntryUpdated = phoneEntryUpdated;
811         }
812
813 }