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