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