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