]> git.mxchange.org Git - jjobs-war.git/blob - src/java/org/mxchange/jjobs/beans/helper/JobsWebViewHelperBean.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / helper / JobsWebViewHelperBean.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.jjobs.beans.helper;
18
19 import java.text.MessageFormat;
20 import javax.enterprise.event.Event;
21 import javax.enterprise.inject.Any;
22 import javax.faces.view.ViewScoped;
23 import javax.inject.Inject;
24 import javax.inject.Named;
25 import org.mxchange.jcontacts.events.contact.created.CreatedContactEvent;
26 import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
27 import org.mxchange.jcontacts.model.contact.Contact;
28 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
29 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
30 import org.mxchange.jcontactsbusiness.model.department.Department;
31 import org.mxchange.jcontactsbusiness.model.employee.Employable;
32 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
33 import org.mxchange.jcountry.model.data.Country;
34 import org.mxchange.jjobs.beans.BaseJobsBean;
35 import org.mxchange.jjobs.beans.contact.list.JobsContactListWebViewController;
36 import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
37 import org.mxchange.jphone.events.fax.created.CreatedFaxNumberEvent;
38 import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
39 import org.mxchange.jphone.events.landline.created.CreatedLandLineNumberEvent;
40 import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
41 import org.mxchange.jphone.events.mobile.created.CreatedMobileNumberEvent;
42 import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
43 import org.mxchange.jphone.model.phonenumbers.DialableNumber;
44 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
45 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
46 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
47 import org.mxchange.jusercore.events.user.created.CreatedUserEvent;
48 import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
49 import org.mxchange.jusercore.model.user.User;
50
51 /**
52  * A general helper for beans
53  * <p>
54  * @author Roland Häder<roland@mxchange.org>
55  */
56 @Named ("beanHelper")
57 @ViewScoped
58 public class JobsWebViewHelperBean extends BaseJobsBean implements JobsWebViewHelperController {
59
60         /**
61          * Serial number
62          */
63         private static final long serialVersionUID = 17_258_793_567_145_701L;
64
65         /**
66          * Contact instance
67          */
68         private Contact contact;
69
70         /**
71          * Event for when a contact instance was created
72          */
73         @Any
74         @Inject
75         private Event<ObservableCreatedContactEvent> contactCreatedEvent;
76
77         /**
78          * Regular user controller
79          */
80         @Inject
81         private JobsContactListWebViewController contactListController;
82
83         /**
84          * Fax number
85          */
86         private DialableFaxNumber faxNumber;
87
88         /**
89          * Event for when a fax number instance was created
90          */
91         @Any
92         @Inject
93         private Event<ObservableCreatedFaxNumberEvent> faxNumberCreatedEvent;
94
95         /**
96          * Land-line number
97          */
98         private DialableLandLineNumber landLineNumber;
99
100         /**
101          * Event for when a land-line number instance was created
102          */
103         @Any
104         @Inject
105         private Event<ObservableCreatedLandLineNumberEvent> landLineNumberCreatedEvent;
106
107         /**
108          * Localization controller
109          */
110         @Inject
111         private JobsLocalizationSessionController localizationController;
112
113         /**
114          * Mobile number
115          */
116         private DialableMobileNumber mobileNumber;
117
118         /**
119          * Event for when a mobile number instance was created
120          */
121         @Any
122         @Inject
123         private Event<ObservableCreatedMobileNumberEvent> mobileNumberCreatedEvent;
124
125         /**
126          * User instance
127          */
128         private User user;
129
130         /**
131          * Event for when a user instance was created
132          */
133         @Any
134         @Inject
135         private Event<ObservableCreatedUserEvent> userCreatedEvent;
136
137         /**
138          * Default constructor
139          */
140         public JobsWebViewHelperBean () {
141                 // Call super constructor
142                 super();
143         }
144
145         /**
146          * Getter for contact instance
147          * <p>
148          * @return Contact instance
149          */
150         public Contact getContact () {
151                 return this.contact;
152         }
153
154         /**
155          * Setter for contact instance
156          * <p>
157          * @param contact Contact instance
158          */
159         public void setContact (final Contact contact) {
160                 this.contact = contact;
161         }
162
163         /**
164          * Returns a message key depending on if this contact is a user and/or a
165          * contact. If this contact is unused, a default key is returned.
166          * <p>
167          * @param contact Contact instance to check
168          * <p>
169          * @return Message key
170          */
171         public String getContactUsageMessageKey (final Contact contact) {
172                 // The contact must be valid
173                 if (null == contact) {
174                         // Throw NPE
175                         throw new NullPointerException("contact is null"); //NOI18N
176                 } else if (contact.getContactId() == null) {
177                         // Throw again ...
178                         throw new NullPointerException("contact.contactId is null"); //NOI18N
179                 } else if (contact.getContactId() < 1) {
180                         // Not valid
181                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
182                 }
183
184                 // Default key is "unused"
185                 String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
186
187                 // Check user first
188                 if (this.contactListController.isContactFound(contact)) {
189                         // Only user
190                         messageKey = "CONTACT_IS_USER"; //NOI18N
191                 }
192
193                 // Return message key
194                 return messageKey;
195         }
196
197         /**
198          * Getter for dialable fax number
199          * <p>
200          * @return Dialable fax number
201          */
202         public DialableFaxNumber getFaxNumber () {
203                 return this.faxNumber;
204         }
205
206         /**
207          * Setter for dialable fax number
208          * <p>
209          * @param faxNumber Dialable fax number
210          */
211         public void setFaxNumber (final DialableFaxNumber faxNumber) {
212                 this.faxNumber = faxNumber;
213         }
214
215         /**
216          * Getter for dialable land-line number
217          * <p>
218          * @return Dialable land-line number
219          */
220         public DialableLandLineNumber getLandLineNumber () {
221                 return this.landLineNumber;
222         }
223
224         /**
225          * Setter for dialable land-line number
226          * <p>
227          * @param landLineNumber Dialable land-line number
228          */
229         public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
230                 this.landLineNumber = landLineNumber;
231         }
232
233         /**
234          * Getter for dialable mobile number
235          * <p>
236          * @return Dialable mobile number
237          */
238         public DialableMobileNumber getMobileNumber () {
239                 return this.mobileNumber;
240         }
241
242         /**
243          * Setter for dialable mobile number
244          * <p>
245          * @param mobileNumber Dialable mobile number
246          */
247         public void setMobileNumber (final DialableMobileNumber mobileNumber) {
248                 this.mobileNumber = mobileNumber;
249         }
250
251         /**
252          * Getter for user instance
253          * <p>
254          * @return User instance
255          */
256         public User getUser () {
257                 return this.user;
258         }
259
260         /**
261          * Setter for user instance
262          * <p>
263          * @param user User instance
264          */
265         public void setUser (final User user) {
266                 this.user = user;
267         }
268
269         /**
270          * Notifies other controllers (backing beans) if a contact id has been
271          * successfully converted to a Contact instance.
272          */
273         public void notifyControllerContactConverted () {
274                 // Validate contact instance
275                 if (this.getContact() == null) {
276                         // Throw NPE
277                         throw new NullPointerException("this.contact is null"); //NOI18N
278                 } else if (this.getContact().getContactId() == null) {
279                         // Throw NPE again
280                         throw new NullPointerException("this.contact.contactId is null"); //NOI18N
281                 } else if (this.getContact().getContactId() < 1) {
282                         // Not valid
283                         throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
284                 }
285
286                 // Set all phone instances
287                 this.setPhoneInstances(this.getContact());
288
289                 // Set all fields: user
290                 this.contactCreatedEvent.fire(new CreatedContactEvent(this.getContact()));
291         }
292
293         /**
294          * Notifies other controllers (backing beans) if a phone id has been
295          * successfully converted to a DialableFaxNumber instance.
296          */
297         public void notifyControllerFaxNumberConverted () {
298                 // Validate fax instance
299                 if (this.getFaxNumber() == null) {
300                         // Throw NPE
301                         throw new NullPointerException("this.faxNumber is null"); //NOI18N
302                 } else if (this.getFaxNumber().getPhoneId() == null) {
303                         // Throw again
304                         throw new NullPointerException("this.faxNumber.phoneId is null"); //NOI18N
305                 } else if (this.getFaxNumber().getPhoneId() < 1) {
306                         // Invalid id number
307                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneId={0} is not valid", this.getFaxNumber().getPhoneId())); //NOI18N
308                 } else if (this.getFaxNumber().getPhoneAreaCode() == null) {
309                         // Throw again
310                         throw new NullPointerException("this.faxNumber.phoneAreaCode is null"); //NOI18N
311                 } else if (this.getFaxNumber().getPhoneAreaCode() < 1) {
312                         // Invalid id number
313                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
314                 } else if (this.getFaxNumber().getPhoneCountry() == null) {
315                         // Throw NPE again
316                         throw new NullPointerException("this.faxNumber.phoneCountry is null"); //NOI18N
317                 } else if (this.getFaxNumber().getPhoneCountry().getCountryId() == null) {
318                         // ... throw again
319                         throw new NullPointerException("this.faxNumber.phoneCountry.countryId is null"); //NOI18N
320                 } else if (this.getFaxNumber().getPhoneCountry().getCountryId() < 1) {
321                         // Invalid id
322                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneCountry.countryId={0} is invalid", this.getFaxNumber().getPhoneCountry().getCountryId())); //NOI18N
323                 } else if (this.getFaxNumber().getPhoneNumber() == null) {
324                         // Throw NPE again ...
325                         throw new NullPointerException("this.faxNumber.phoneNumber is null"); //NOI18N
326                 } else if (this.getFaxNumber().getPhoneNumber() < 1) {
327                         // Invalid id number
328                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneNumber={0} is not valid", this.getFaxNumber().getPhoneNumber())); //NOI18N
329                 }
330
331                 // Fire event
332                 this.faxNumberCreatedEvent.fire(new CreatedFaxNumberEvent(this.getFaxNumber()));
333         }
334
335         /**
336          * Notifies other controllers (backing beans) if a phone id has been
337          * successfully converted to a DialableLandLineNumber instance.
338          */
339         public void notifyControllerLandLineNumberConverted () {
340                 // Validate land-line instance
341                 if (this.getLandLineNumber() == null) {
342                         // Throw NPE
343                         throw new NullPointerException("this.landLineNumber is null"); //NOI18N
344                 } else if (this.getLandLineNumber().getPhoneId() == null) {
345                         // Throw again
346                         throw new NullPointerException("this.landLineNumber.phoneId is null"); //NOI18N
347                 } else if (this.getLandLineNumber().getPhoneId() < 1) {
348                         // Invalid id number
349                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneId={0} is not valid", this.getLandLineNumber().getPhoneId())); //NOI18N
350                 } else if (this.getLandLineNumber().getPhoneAreaCode() == null) {
351                         // Throw again
352                         throw new NullPointerException("this.landLineNumber.phoneAreaCode is null"); //NOI18N
353                 } else if (this.getLandLineNumber().getPhoneAreaCode() < 1) {
354                         // Invalid id number
355                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
356                 } else if (this.getLandLineNumber().getPhoneCountry() == null) {
357                         // Throw NPE again
358                         throw new NullPointerException("this.landLineNumber.phoneCountry is null"); //NOI18N
359                 } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() == null) {
360                         // ... throw again
361                         throw new NullPointerException("this.landLineNumber.phoneCountry.countryId is null"); //NOI18N
362                 } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() < 1) {
363                         // Invalid id
364                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneCountry.countryId={0} is invalid", this.getLandLineNumber().getPhoneCountry().getCountryId())); //NOI18N
365                 } else if (this.getLandLineNumber().getPhoneNumber() == null) {
366                         // Throw NPE again ...
367                         throw new NullPointerException("this.landLineNumber.phoneNumber is null"); //NOI18N
368                 } else if (this.getLandLineNumber().getPhoneNumber() < 1) {
369                         // Invalid id number
370                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneNumber={0} is not valid", this.getLandLineNumber().getPhoneNumber())); //NOI18N
371                 }
372
373                 // Fire event
374                 this.landLineNumberCreatedEvent.fire(new CreatedLandLineNumberEvent(this.getLandLineNumber()));
375         }
376
377         /**
378          * Notifies other controllers (backing beans) if a phone id has been
379          * successfully converted to a DialableMobileNumber instance.
380          */
381         public void notifyControllerMobileNumberConverted () {
382                 // Validate mobile instance
383                 if (this.getMobileNumber() == null) {
384                         // Throw NPE
385                         throw new NullPointerException("this.mobileNumber is null"); //NOI18N
386                 } else if (this.getMobileNumber().getMobileId() == null) {
387                         // Throw again
388                         throw new NullPointerException("this.mobileNumber.mobileId is null"); //NOI18N
389                 } else if (this.getMobileNumber().getMobileId() < 1) {
390                         // Invalid id number
391                         throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileId={0} is not valid", this.getMobileNumber().getMobileId())); //NOI18N
392                 } else if (this.getMobileNumber().getMobileProvider() == null) {
393                         // Throw NPE again
394                         throw new NullPointerException("this.mobileNumber.mobileProvider is null"); //NOI18N
395                 } else if (this.getMobileNumber().getMobileProvider().getProviderId() == null) {
396                         // ... throw again
397                         throw new NullPointerException("this.mobileNumber.mobileProvider.providerId is null"); //NOI18N
398                 } else if (this.getMobileNumber().getMobileProvider().getProviderId() < 1) {
399                         // Invalid id
400                         throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileProvider.providerId={0} is invalid", this.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
401                 } else if (this.getMobileNumber().getMobileNumber() == null) {
402                         // Throw NPE again ...
403                         throw new NullPointerException("this.mobileNumber.mobileNumber is null"); //NOI18N
404                 } else if (this.getMobileNumber().getMobileNumber() < 1) {
405                         // Invalid id number
406                         throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileNumber={0} is not valid", this.getMobileNumber().getMobileNumber())); //NOI18N
407                 }
408
409                 // Fire event
410                 this.mobileNumberCreatedEvent.fire(new CreatedMobileNumberEvent(this.getMobileNumber()));
411         }
412
413         /**
414          * Notifies other controllers (backing beans) if a user id has been
415          * successfully converted to a User instance.
416          */
417         public void notifyControllerUserConverted () {
418                 // Validate user instance
419                 if (this.getUser() == null) {
420                         // Throw NPE
421                         throw new NullPointerException("this.user is null"); //NOI18N
422                 } else if (this.getUser().getUserId() == null) {
423                         // Throw NPE again
424                         throw new NullPointerException("this.user.userId is null"); //NOI18N
425                 } else if (this.getUser().getUserId() < 1) {
426                         // Not valid
427                         throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
428                 }
429
430                 // Get contact
431                 final Contact userContact = this.getUser().getUserContact();
432
433                 // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
434                 this.setContact(userContact);
435
436                 // Set all phone instances
437                 this.setPhoneInstances(userContact);
438
439                 // Fire event
440                 this.userCreatedEvent.fire(new CreatedUserEvent(this.getUser()));
441         }
442
443         /**
444          * Renders data of basic company data
445          * <p>
446          * @param basicData        Basic company data instance
447          * @param useShortName     Whether to use short name or long name of company
448          * @param showEmailAddress Whether render email address
449          * <p>
450          * @return Basic company data as string
451          */
452         public String renderBasicData (final BasicData basicData, final boolean useShortName, final boolean showEmailAddress) {
453                 // Default is empty string, so let's get started
454                 final StringBuilder sb = new StringBuilder(30);
455
456                 // Is basic company data set?
457                 if (basicData instanceof BasicData) {
458                         // Short or long name?
459                         if (useShortName) {
460                                 // Add company's long name
461                                 sb.append(basicData.getCompanyShortName()); //NOI18N
462                         } else {
463                                 // Add company's long name
464                                 sb.append(basicData.getCompanyName()); //NOI18N
465                         }
466
467                         // Is email address set?
468                         if (showEmailAddress && basicData.getCompanyEmailAddress() != null) {
469                                 // Add it
470                                 sb.append(", ").append(basicData.getCompanyEmailAddress()); //NOI18N
471                         }
472
473                         // Is tax number set?
474                         if (basicData.getCompanyTaxNumber() != null) {
475                                 // Add it
476                                 sb.append(", ").append(basicData.getCompanyTaxNumber()); //NOI18N
477                         }
478                 }
479
480                 // Return it
481                 return sb.toString();
482         }
483
484         /**
485          * Returns the branch office's full address. If null is provided, an empty
486          * string is returned.
487          * <p>
488          * @param branchOffice     Branch office instance
489          * @param showEmailAddress Whether render email address
490          * <p>
491          * @return Branch office's address
492          */
493         public String renderBranchOffice (final BranchOffice branchOffice, final boolean showEmailAddress) {
494                 // Default is empty string, so let's get started
495                 final StringBuilder sb = new StringBuilder(30);
496
497                 // Is a branch office instance given?
498                 if (branchOffice instanceof BranchOffice) {
499                         // This should not happen:
500                         if (branchOffice.getBranchId() == null) {
501                                 // Throw NPE
502                                 throw new NullPointerException("branchOffice.branchId is null"); //NOI18N
503                         } else if (branchOffice.getBranchId() < 1) {
504                                 // Throw IAE
505                                 throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is invalid.", branchOffice.getBranchId())); //NOI18N
506                         } else if (branchOffice.getBranchCompany() == null) {
507                                 // Throw NPE
508                                 throw new NullPointerException("branchOffice.branchCompany is null"); //NOI18N
509                         } else if (branchOffice.getBranchCountry() == null) {
510                                 // Throw NPE again
511                                 throw new NullPointerException("branchOffice.branchCountry is null"); //NOI18N
512                         }
513
514                         // Yes, then append all data
515                         sb.append(this.renderBasicData(branchOffice.getBranchCompany(), true, showEmailAddress));
516                         sb.append(", "); //NOI18N
517                         sb.append(branchOffice.getBranchStreet());
518                         sb.append(" "); //NOI18N
519                         sb.append(branchOffice.getBranchHouseNumber());
520                         sb.append(", "); //NOI18N
521                         sb.append(branchOffice.getBranchCountry().getCountryCode());
522                         sb.append(" "); //NOI18N
523                         sb.append(branchOffice.getBranchZipCode());
524                         sb.append(" "); //NOI18N
525                         sb.append(branchOffice.getBranchCity());
526                 }
527
528                 // Return it
529                 return sb.toString();
530         }
531
532         /**
533          * Returns the contact's personal title, family name and name. If null is
534          * provided, an empty string is returned.
535          * <p>
536          * @param contact Contact instance
537          * <p>
538          * @return Contact's full name
539          */
540         public String renderContact (final Contact contact) {
541                 // Default is empty string, so let's get started
542                 final StringBuilder sb = new StringBuilder(20);
543
544                 // Is contact set?
545                 if (contact instanceof Contact) {
546                         // Then create name
547                         sb.append(this.getMessageFromBundle(contact.getContactPersonalTitle().getMessageKey()));
548                         sb.append(" "); //NOI18N
549                         sb.append(contact.getContactFirstName());
550                         sb.append(" "); //NOI18N
551                         sb.append(contact.getContactFamilyName());
552                 }
553
554                 // Return it
555                 return sb.toString();
556         }
557
558         /**
559          * Returns the text representation of given country. If null is provided, an
560          * empty string is returned.
561          * <p>
562          * @param country Country instance
563          * <p>
564          * @return Country's text representation
565          */
566         public String renderCountry (final Country country) {
567                 // Default is empty string, so let's get started
568                 final StringBuilder sb = new StringBuilder(20);
569
570                 // Is a country given?
571                 if (country instanceof Country) {
572                         // Yes, then render it
573                         sb.append(this.getMessageFromBundle(country.getCountryI18nKey()));
574                         sb.append(" ("); //NOI18N
575                         sb.append(country.getCountryCode());
576                         sb.append(")"); //NOI18N
577                 }
578
579                 // Return it
580                 return sb.toString();
581         }
582
583         /**
584          * Returns the department's name and name of assigned company. If null is
585          * provided, an empty string is returned.
586          * <p>
587          * @param department       Department instance
588          * @param showEmailAddress Whether to render email address
589          * <p>
590          * @return Department's full name
591          */
592         public String renderDepartment (final Department department, final boolean showEmailAddress) {
593                 // Default is empty string, so let's get started
594                 final StringBuilder sb = new StringBuilder(10);
595
596                 // Is a department set?
597                 if (department instanceof Department) {
598                         // Then create name
599                         sb.append(this.getMessageFromBundle(department.getDepartmentI18nKey()));
600                         sb.append(" ("); //NOI18N
601                         sb.append(this.renderBasicData(department.getDepartmentCompany(), true, showEmailAddress));
602                         sb.append(")"); //NOI18N
603                 }
604
605                 // Return it
606                 return sb.toString();
607         }
608
609         /**
610          * Returns the employee's number, personal title, family name and name if
611          * available. If null is provided, an empty string is returned.
612          * <p>
613          * @param employee         Employable instance
614          * @param showEmailAddress Whether to show email address of employee
615          * <p>
616          * @return A string representing an employee
617          */
618         public String renderEmployee (final Employable employee, final boolean showEmailAddress) {
619                 // Default is empty string, so let's get started
620                 final StringBuilder sb = new StringBuilder(20);
621
622                 // Is employee set?
623                 if (employee instanceof Employable) {
624                         // Is the number given?
625                         if (employee.getEmployeeNumber() != null) {
626                                 // Then create name
627                                 sb.append(employee.getEmployeeNumber());
628                         }
629
630                         // Is contact data found?
631                         if (employee.getEmployeePersonalData() instanceof Contact) {
632                                 // Yes, then render it
633                                 final String contactName = this.renderContact(employee.getEmployeePersonalData());
634
635                                 // Is it given?
636                                 if (contactName != null && !contactName.isEmpty()) {
637                                         // Only add braces when employee number is given
638                                         if (employee.getEmployeeNumber() != null) {
639                                                 sb.append(" ("); //NOI18N
640                                         }
641
642                                         // Then add it
643                                         sb.append(contactName);
644
645                                         // Only add braces when employee number is given
646                                         if (employee.getEmployeeNumber() != null) {
647                                                 sb.append(")"); //NOI18N
648                                         }
649                                 }
650                         }
651
652                         // Is a department found?
653                         if (employee.getEmployeeDepartment() instanceof Department) {
654                                 // Only add braces when employee number is given
655                                 if (employee.getEmployeeNumber() != null || employee.getEmployeePersonalData() instanceof Contact) {
656                                         sb.append(" ("); //NOI18N
657                                 }
658
659                                 // Add department name
660                                 sb.append(this.renderDepartment(employee.getEmployeeDepartment(), showEmailAddress));
661
662                                 // Only add braces when employee number is given
663                                 if (employee.getEmployeeNumber() != null || employee.getEmployeePersonalData() instanceof Contact) {
664                                         sb.append(")"); //NOI18N
665                                 }
666                         }
667                 }
668
669                 // Return it
670                 return sb.toString();
671         }
672
673         /**
674          * Returns the headquarter address. If null is provided, an empty string is
675          * returned.
676          * <p>
677          * @param headquarter Headquarter instance
678          * <p>
679          * @return Headquarter address
680          */
681         public String renderHeadquarter (final Headquarter headquarter) {
682                 // Default is empty string, so let's get started
683                 final StringBuilder sb = new StringBuilder(10);
684
685                 // Is a headquarter set?
686                 if (headquarter instanceof Headquarter) {
687                         // Then create name
688                         sb.append(headquarter.getHeadquarterStreet());
689                         sb.append(" "); //NOI18N
690                         sb.append(headquarter.getHeadquarterHouseNumber());
691
692                         // Is store/suite number set?
693                         if (headquarter.getHeadquarterStore() instanceof Short) {
694                                 sb.append(" ("); //NOI18N
695                                 sb.append(this.getMessageFromBundle("DATA_STORE")); //NOI18N
696                                 sb.append(" "); //NOI18N
697                                 sb.append(headquarter.getHeadquarterStore());
698                                 sb.append(", "); //NOI18N
699                                 sb.append(this.getMessageFromBundle("DATA_SUITE_NUMBER")); //NOI18N
700                                 sb.append(" "); //NOI18N
701                                 sb.append(headquarter.getHeadquarterSuiteNumber());
702                                 sb.append(")"); //NOI18N
703                         }
704
705                         // Continue with country, ZIP code and city
706                         sb.append(", "); //NOI18N
707                         sb.append(headquarter.getHeadquarterCountry().getCountryCode());
708                         sb.append(" "); //NOI18N
709                         sb.append(headquarter.getHeadquarterZipCode());
710                         sb.append(" "); //NOI18N
711                         sb.append(headquarter.getHeadquarterCity());
712                 }
713
714                 // Return it
715                 return sb.toString();
716         }
717
718         /**
719          * Renders given mobile number (land-line and fax number). If null is
720          * provided, an empty string is returned.
721          * <p>
722          * @param mobileNumber Mobile number to render
723          * <p>
724          * @return Mobile number
725          */
726         public String renderMobileNumber (final DialableMobileNumber mobileNumber) {
727                 // Default is empty string, so let's get started
728                 final StringBuilder sb = new StringBuilder(20);
729
730                 // Is a phone number given?
731                 if (mobileNumber instanceof DialableMobileNumber) {
732                         // Yes, then render it
733                         sb.append(mobileNumber.getMobileProvider().getProviderCountry().getCountryAbroadDialPrefix());
734                         sb.append(mobileNumber.getMobileProvider().getProviderCountry().getCountryPhoneCode());
735                         sb.append(" ("); //NOI18N
736                         sb.append(mobileNumber.getMobileProvider().getProviderDialPrefix());
737                         sb.append(") "); //NOI18N
738                         sb.append(mobileNumber.getMobileNumber());
739                 }
740
741                 // Return it
742                 return sb.toString();
743         }
744
745         /**
746          * Renders given phone number (land-line and fax number). If null is
747          * provided, an empty string is returned.
748          * <p>
749          * @param number Phone number to render
750          * <p>
751          * @return Phone number
752          * <p>
753          * @throws IllegalArgumentException If a mobile number is provided
754          */
755         public String renderPhoneNumber (final DialableNumber number) {
756                 // Validate parameter
757                 if (number instanceof DialableMobileNumber) {
758                         // Not allowed here
759                         throw new IllegalArgumentException("Mobile numbers cannot be rendered with this method. Please use renderMobileNumber() instead."); //NOI18N
760                 }
761
762                 // Default is empty string, so let's get started
763                 final StringBuilder sb = new StringBuilder(20);
764
765                 // Is a phone number given?
766                 if (number instanceof DialableNumber) {
767                         // Yes, then render it
768                         sb.append(number.getPhoneCountry().getCountryAbroadDialPrefix());
769                         sb.append(number.getPhoneCountry().getCountryPhoneCode());
770                         sb.append(" ("); //NOI18N
771                         sb.append(number.getPhoneAreaCode());
772                         sb.append(") "); //NOI18N
773                         sb.append(number.getPhoneNumber());
774                 }
775
776                 // Return it
777                 return sb.toString();
778         }
779
780         /**
781          * Returns the user's personal title, family name and name. If null is
782          * provided, an empty string is returned.
783          * <p>
784          * @param user User instance
785          * <p>
786          * @return User's full name
787          */
788         public String renderUser (final User user) {
789                 // Default is empty string, so let's get started
790                 final StringBuilder sb = new StringBuilder(20);
791
792                 // Is user given?
793                 if (user instanceof User) {
794                         // Add user name first
795                         sb.append(user.getUserName());
796                         sb.append(" ("); //NOI18N
797
798                         // Add contact data
799                         sb.append(this.renderContact(user.getUserContact()));
800
801                         // Close brace
802                         sb.append(")"); //NOI18N
803                 }
804
805                 // Return it
806                 return sb.toString();
807         }
808
809         /**
810          * Set's all given contact's phone instances: land-line, mobile and
811          * faxNumber
812          * <p>
813          * @param contact Contact to set phone instances for
814          */
815         private void setPhoneInstances (final Contact contact) {
816                 // The contact must be valid
817                 if (null == contact) {
818                         // Throw NPE
819                         throw new NullPointerException("contact is null"); //NOI18N
820                 } else if (contact.getContactId() == null) {
821                         // Throw again ...
822                         throw new NullPointerException("contact.contactId is null"); //NOI18N
823                 } else if (contact.getContactId() < 1) {
824                         // Not valid
825                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
826                 }
827
828                 // Is mobile set?
829                 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
830                         // Yes, then set it in admin controller
831                         this.setMobileNumber(contact.getContactMobileNumber());
832                 }
833
834                 // Is land-line set?
835                 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
836                         // Yes, then set it in admin controller
837                         this.setLandLineNumber(contact.getContactLandLineNumber());
838                 }
839
840                 // Is faxNumber set?
841                 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
842                         // Yes, then set it in admin controller
843                         this.setFaxNumber(contact.getContactFaxNumber());
844                 }
845         }
846
847 }