]> git.mxchange.org Git - jjobs-war.git/blob - src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / helper / JobsWebRequestHelperBean.java
1 /*
2  * Copyright (C) 2016 - 2018 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.context.RequestScoped;
21 import javax.enterprise.event.Event;
22 import javax.enterprise.inject.Any;
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.jjobs.beans.BaseJobsBean;
34 import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController;
35 import org.mxchange.jjobs.beans.user.JobsUserWebRequestController;
36 import org.mxchange.jjobs.model.receipt.BillableReceipt;
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.fax.DialableFaxNumber;
44 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
45 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
46 import org.mxchange.jproduct.model.product.Product;
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 import org.mxchange.jcontactsbusiness.model.employee.Employable;
51
52 /**
53  * A general helper for beans
54  * <p>
55  * @author Roland Häder<roland@mxchange.org>
56  */
57 @Named ("beanHelper")
58 @RequestScoped
59 public class JobsWebRequestHelperBean extends BaseJobsBean implements JobsWebRequestHelperController {
60
61         /**
62          * Serial number
63          */
64         private static final long serialVersionUID = 17_258_793_567_145_701L;
65
66         /**
67          * Contact instance
68          */
69         private Contact contact;
70
71         /**
72          * Event for when a contact instance was created
73          */
74         @Any
75         @Inject
76         private Event<ObservableCreatedContactEvent> contactCreatedEvent;
77
78         /**
79          * Fax number
80          */
81         private DialableFaxNumber faxNumber;
82
83         /**
84          * Event for when a fax number instance was created
85          */
86         @Any
87         @Inject
88         private Event<ObservableCreatedFaxNumberEvent> faxNumberCreatedEvent;
89
90         /**
91          * Land-line number
92          */
93         private DialableLandLineNumber landLineNumber;
94
95         /**
96          * Event for when a land-line number instance was created
97          */
98         @Any
99         @Inject
100         private Event<ObservableCreatedLandLineNumberEvent> landLineNumberCreatedEvent;
101
102         /**
103          * Localization controller
104          */
105         @Inject
106         private JobsLocalizationSessionController localizationController;
107
108         /**
109          * Mobile number
110          */
111         private DialableMobileNumber mobileNumber;
112
113         /**
114          * Event for when a mobile number instance was created
115          */
116         @Any
117         @Inject
118         private Event<ObservableCreatedMobileNumberEvent> mobileNumberCreatedEvent;
119
120         /**
121          * User instance
122          */
123         private User user;
124
125         /**
126          * Regular user controller
127          */
128         @Inject
129         private JobsUserWebRequestController userController;
130
131         /**
132          * Event for when a user instance was created
133          */
134         @Any
135         @Inject
136         private Event<ObservableCreatedUserEvent> userCreatedEvent;
137
138         /**
139          * Default constructor
140          */
141         public JobsWebRequestHelperBean () {
142                 // Call super constructor
143                 super();
144         }
145
146         /**
147          * Getter for contact instance
148          * <p>
149          * @return Contact instance
150          */
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.userController.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         public DialableFaxNumber getFaxNumber () {
204                 return this.faxNumber;
205         }
206
207         /**
208          * Setter for dialable fax number
209          * <p>
210          * @param faxNumber Dialable fax number
211          */
212         public void setFaxNumber (final DialableFaxNumber faxNumber) {
213                 this.faxNumber = faxNumber;
214         }
215
216         /**
217          * Getter for dialable land-line number
218          * <p>
219          * @return Dialable land-line number
220          */
221         public DialableLandLineNumber getLandLineNumber () {
222                 return this.landLineNumber;
223         }
224
225         /**
226          * Setter for dialable land-line number
227          * <p>
228          * @param landLineNumber Dialable land-line number
229          */
230         public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
231                 this.landLineNumber = landLineNumber;
232         }
233
234         /**
235          * Getter for dialable mobile number
236          * <p>
237          * @return Dialable mobile number
238          */
239         public DialableMobileNumber getMobileNumber () {
240                 return this.mobileNumber;
241         }
242
243         /**
244          * Setter for dialable mobile number
245          * <p>
246          * @param mobileNumber Dialable mobile number
247          */
248         public void setMobileNumber (final DialableMobileNumber mobileNumber) {
249                 this.mobileNumber = mobileNumber;
250         }
251
252         /**
253          * Getter for user instance
254          * <p>
255          * @return User instance
256          */
257         public User getUser () {
258                 return this.user;
259         }
260
261         /**
262          * Setter for user instance
263          * <p>
264          * @param user User instance
265          */
266         public void setUser (final User user) {
267                 this.user = user;
268         }
269
270         /**
271          * Notifies other controllers (backing beans) if a contact id has been
272          * successfully converted to a Contact instance.
273          */
274         public void notifyControllerContactConverted () {
275                 // Validate contact instance
276                 if (this.getContact() == null) {
277                         // Throw NPE
278                         throw new NullPointerException("this.contact is null"); //NOI18N
279                 } else if (this.getContact().getContactId() == null) {
280                         // Throw NPE again
281                         throw new NullPointerException("this.contact.contactId is null"); //NOI18N
282                 } else if (this.getContact().getContactId() < 1) {
283                         // Not valid
284                         throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
285                 }
286
287                 // Set all phone instances
288                 this.setPhoneInstances(this.getContact());
289
290                 // Set all fields: user
291                 this.contactCreatedEvent.fire(new CreatedContactEvent(this.getContact()));
292         }
293
294         /**
295          * Notifies other controllers (backing beans) if a phone id has been
296          * successfully converted to a DialableFaxNumber instance.
297          */
298         public void notifyControllerFaxNumberConverted () {
299                 // Validate fax instance
300                 if (this.getFaxNumber() == null) {
301                         // Throw NPE
302                         throw new NullPointerException("this.faxNumber is null"); //NOI18N
303                 } else if (this.getFaxNumber().getPhoneId() == null) {
304                         // Throw again
305                         throw new NullPointerException("this.faxNumber.phoneId is null"); //NOI18N
306                 } else if (this.getFaxNumber().getPhoneId() < 1) {
307                         // Invalid id number
308                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneId={0} is not valid", this.getFaxNumber().getPhoneId())); //NOI18N
309                 } else if (this.getFaxNumber().getPhoneAreaCode() == null) {
310                         // Throw again
311                         throw new NullPointerException("this.faxNumber.phoneAreaCode is null"); //NOI18N
312                 } else if (this.getFaxNumber().getPhoneAreaCode() < 1) {
313                         // Invalid id number
314                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
315                 } else if (this.getFaxNumber().getPhoneCountry() == null) {
316                         // Throw NPE again
317                         throw new NullPointerException("this.faxNumber.phoneCountry is null"); //NOI18N
318                 } else if (this.getFaxNumber().getPhoneCountry().getCountryId() == null) {
319                         // ... throw again
320                         throw new NullPointerException("this.faxNumber.phoneCountry.countryId is null"); //NOI18N
321                 } else if (this.getFaxNumber().getPhoneCountry().getCountryId() < 1) {
322                         // Invalid id
323                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneCountry.countryId={0} is invalid", this.getFaxNumber().getPhoneCountry().getCountryId())); //NOI18N
324                 } else if (this.getFaxNumber().getPhoneNumber() == null) {
325                         // Throw NPE again ...
326                         throw new NullPointerException("this.faxNumber.phoneNumber is null"); //NOI18N
327                 } else if (this.getFaxNumber().getPhoneNumber() < 1) {
328                         // Invalid id number
329                         throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneNumber={0} is not valid", this.getFaxNumber().getPhoneNumber())); //NOI18N
330                 }
331
332                 // Fire event
333                 this.faxNumberCreatedEvent.fire(new CreatedFaxNumberEvent(this.getFaxNumber()));
334         }
335
336         /**
337          * Notifies other controllers (backing beans) if a phone id has been
338          * successfully converted to a DialableLandLineNumber instance.
339          */
340         public void notifyControllerLandLineNumberConverted () {
341                 // Validate land-line instance
342                 if (this.getLandLineNumber() == null) {
343                         // Throw NPE
344                         throw new NullPointerException("this.landLineNumber is null"); //NOI18N
345                 } else if (this.getLandLineNumber().getPhoneId() == null) {
346                         // Throw again
347                         throw new NullPointerException("this.landLineNumber.phoneId is null"); //NOI18N
348                 } else if (this.getLandLineNumber().getPhoneId() < 1) {
349                         // Invalid id number
350                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneId={0} is not valid", this.getLandLineNumber().getPhoneId())); //NOI18N
351                 } else if (this.getLandLineNumber().getPhoneAreaCode() == null) {
352                         // Throw again
353                         throw new NullPointerException("this.landLineNumber.phoneAreaCode is null"); //NOI18N
354                 } else if (this.getLandLineNumber().getPhoneAreaCode() < 1) {
355                         // Invalid id number
356                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
357                 } else if (this.getLandLineNumber().getPhoneCountry() == null) {
358                         // Throw NPE again
359                         throw new NullPointerException("this.landLineNumber.phoneCountry is null"); //NOI18N
360                 } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() == null) {
361                         // ... throw again
362                         throw new NullPointerException("this.landLineNumber.phoneCountry.countryId is null"); //NOI18N
363                 } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() < 1) {
364                         // Invalid id
365                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneCountry.countryId={0} is invalid", this.getLandLineNumber().getPhoneCountry().getCountryId())); //NOI18N
366                 } else if (this.getLandLineNumber().getPhoneNumber() == null) {
367                         // Throw NPE again ...
368                         throw new NullPointerException("this.landLineNumber.phoneNumber is null"); //NOI18N
369                 } else if (this.getLandLineNumber().getPhoneNumber() < 1) {
370                         // Invalid id number
371                         throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneNumber={0} is not valid", this.getLandLineNumber().getPhoneNumber())); //NOI18N
372                 }
373
374                 // Fire event
375                 this.landLineNumberCreatedEvent.fire(new CreatedLandLineNumberEvent(this.getLandLineNumber()));
376         }
377
378         /**
379          * Notifies other controllers (backing beans) if a phone id has been
380          * successfully converted to a DialableMobileNumber instance.
381          */
382         public void notifyControllerMobileNumberConverted () {
383                 // Validate mobile instance
384                 if (this.getMobileNumber() == null) {
385                         // Throw NPE
386                         throw new NullPointerException("this.mobileNumber is null"); //NOI18N
387                 } else if (this.getMobileNumber().getPhoneId() == null) {
388                         // Throw again
389                         throw new NullPointerException("this.mobileNumber.phoneId is null"); //NOI18N
390                 } else if (this.getMobileNumber().getPhoneId() < 1) {
391                         // Invalid id number
392                         throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneId={0} is not valid", this.getMobileNumber().getPhoneId())); //NOI18N
393                 } else if (this.getMobileNumber().getMobileProvider() == null) {
394                         // Throw NPE again
395                         throw new NullPointerException("this.mobileNumber.mobileProvider is null"); //NOI18N
396                 } else if (this.getMobileNumber().getMobileProvider().getProviderId() == null) {
397                         // ... throw again
398                         throw new NullPointerException("this.mobileNumber.mobileProvider.providerId is null"); //NOI18N
399                 } else if (this.getMobileNumber().getMobileProvider().getProviderId() < 1) {
400                         // Invalid id
401                         throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileProvider.providerId={0} is invalid", this.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
402                 } else if (this.getMobileNumber().getPhoneNumber() == null) {
403                         // Throw NPE again ...
404                         throw new NullPointerException("this.mobileNumber.phoneNumber is null"); //NOI18N
405                 } else if (this.getMobileNumber().getPhoneNumber() < 1) {
406                         // Invalid id number
407                         throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneNumber={0} is not valid", this.getMobileNumber().getPhoneNumber())); //NOI18N
408                 }
409
410                 // Fire event
411                 this.mobileNumberCreatedEvent.fire(new CreatedMobileNumberEvent(this.getMobileNumber()));
412         }
413
414         /**
415          * Notifies other controllers (backing beans) if a user id has been
416          * successfully converted to a User instance.
417          */
418         public void notifyControllerUserConverted () {
419                 // Validate user instance
420                 if (this.getUser() == null) {
421                         // Throw NPE
422                         throw new NullPointerException("this.user is null"); //NOI18N
423                 } else if (this.getUser().getUserId() == null) {
424                         // Throw NPE again
425                         throw new NullPointerException("this.user.userId is null"); //NOI18N
426                 } else if (this.getUser().getUserId() < 1) {
427                         // Not valid
428                         throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
429                 }
430
431                 // Get contact
432                 final Contact userContact = this.getUser().getUserContact();
433
434                 // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
435                 this.setContact(userContact);
436
437                 // Set all phone instances
438                 this.setPhoneInstances(userContact);
439
440                 // Fire event
441                 this.userCreatedEvent.fire(new CreatedUserEvent(this.getUser()));
442         }
443
444         /**
445          * Renders data of basic company data
446          * <p>
447          * @param basicData Basic company data instance
448          * <p>
449          * @return Basic company data as string
450          */
451         public String renderBasicData (final BasicData basicData) {
452                 // Default is empty string, so let's get started
453                 final StringBuilder sb = new StringBuilder(30);
454
455                 // Is basic company data set?
456                 if (basicData instanceof BasicData) {
457                         // Add company name
458                         sb.append(basicData.getCompanyName()); //NOI18N
459
460                         // Is email address set?
461                         if (basicData.getCompanyEmailAddress() != null) {
462                                 // Add it
463                                 sb.append(", ").append(basicData.getCompanyEmailAddress()); //NOI18N
464                         }
465
466                         // Is tax number set?
467                         if (basicData.getCompanyTaxNumber() != null) {
468                                 // Add it
469                                 sb.append(", ").append(basicData.getCompanyTaxNumber()); //NOI18N
470                         }
471                 }
472
473                 // Return it
474                 return sb.toString();
475         }
476
477         /**
478          * Returns the branch office's full address. If null is provided, an empty
479          * string is returned.
480          * <p>
481          * @param branchOffice Branch office instance
482          * <p>
483          * @return Branch office's address
484          */
485         public String renderBranchOffice (final BranchOffice branchOffice) {
486                 // Default is empty string, so let's get started
487                 final StringBuilder sb = new StringBuilder(30);
488
489                 // Is a branch office instance given?
490                 if (branchOffice instanceof BranchOffice) {
491                         // This should not happen:
492                         assert (branchOffice.getBranchCompany() instanceof BasicData) : "branchOffice.branchCompany is null"; //NOI18N
493
494                         // Yes, then append all data
495                         sb.append(branchOffice.getBranchCompany().getCompanyName());
496                         sb.append(", "); //NOI18N
497                         sb.append(branchOffice.getBranchStreet());
498                         sb.append(" "); //NOI18N
499                         sb.append(branchOffice.getBranchHouseNumber());
500                         sb.append(", "); //NOI18N
501                         sb.append(branchOffice.getBranchCountry().getCountryCode());
502                         sb.append(" "); //NOI18N
503                         sb.append(branchOffice.getBranchZipCode());
504                         sb.append(" "); //NOI18N
505                         sb.append(branchOffice.getBranchCity());
506                 }
507
508                 // Return it
509                 return sb.toString();
510         }
511
512         /**
513          * Returns the contact's personal title, family name and name. If null is
514          * provided, an empty string is returned.
515          * <p>
516          * @param contact Contact instance
517          * <p>
518          * @return Contact's full name
519          */
520         public String renderContact (final Contact contact) {
521                 // Default is empty string, so let's get started
522                 final StringBuilder sb = new StringBuilder(20);
523
524                 // Is contact set?
525                 if (contact instanceof Contact) {
526                         // Then create name
527                         sb.append(this.getMessageFromBundle(contact.getContactPersonalTitle().getMessageKey()));
528                         sb.append(" "); //NOI18N
529                         sb.append(contact.getContactFirstName());
530                         sb.append(" "); //NOI18N
531                         sb.append(contact.getContactFamilyName());
532                 }
533
534                 // Return it
535                 return sb.toString();
536         }
537
538         /**
539          * Returns the department's name and name of assigned company. If null is
540          * provided, an empty string is returned.
541          * <p>
542          * @param department Department instance
543          * <p>
544          * @return Department's full name
545          */
546         public String renderDepartment (final Department department) {
547                 // Default is empty string, so let's get started
548                 final StringBuilder sb = new StringBuilder(10);
549
550                 // Is a department set?
551                 if (department instanceof Department) {
552                         // Then create name
553                         sb.append(this.getMessageFromBundle(department.getDepartmentI18nKey()));
554                         sb.append(" ("); //NOI18N
555                         sb.append(department.getDepartmentCompany().getCompanyName());
556                         sb.append(")"); //NOI18N
557                 }
558
559                 // Return it
560                 return sb.toString();
561         }
562
563         /**
564          * Returns the employee's number, personal title, family name and name if
565          * available. If null is provided, an empty string is returned.
566          * <p>
567          * @param employee Employable instance
568  <p>
569          * @return Contact's full name
570          */
571         public String renderEmployee (final Employable employee) {
572                 // Default is empty string, so let's get started
573                 final StringBuilder sb = new StringBuilder(20);
574
575                 // Is employee set?
576                 if (employee instanceof Employable) {
577                         // Then create name
578                         sb.append(employee.getEmployeeNumber());
579
580                         // Is a department found?
581                         if (employee.getEmployeeDepartment() instanceof Department) {
582                                 // Then add it's name to it
583                                 sb.append(" ("); //NOI18N
584                                 sb.append(this.renderDepartment(employee.getEmployeeDepartment()));
585                                 sb.append(")"); //NOI18N
586                         }
587
588                         // Is contact data found?
589                         if (employee.getEmployeePersonalData() instanceof Contact) {
590                                 // Yes, then render it
591                                 final String contactName = this.renderContact(employee.getEmployeePersonalData());
592
593                                 // Is it given?
594                                 if (contactName != null) {
595                                         // Then add it
596                                         sb.append(" ("); //NOI18N
597                                         sb.append(contactName);
598                                         sb.append(")"); //NOI18N
599                                 }
600                         }
601                 }
602
603                 // Return it
604                 return sb.toString();
605         }
606
607         /**
608          * Returns the product name and price. If null is provided, an empty string
609          * is returned.
610          * <p>
611          * @param product Product instance
612          * <p>
613          * @return Product name
614          */
615         public String renderGenericProduct (final Product product) {
616                 // Default is empty string, so let's get started
617                 final StringBuilder sb = new StringBuilder(10);
618
619                 // Is a product set?
620                 if (product instanceof Product) {
621                         // Add name and price
622                         sb.append(this.getMessageFromBundle(product.getProductI18nKey()));
623                         sb.append(" ("); //NOI18N
624                         sb.append(this.localizationController.formatCurrency(product.getProductGrossPrice()));
625                         sb.append(" "); //NOI18N
626                         sb.append(product.getProductCurrencyCode());
627                         sb.append(")"); //NOI18N
628                 }
629
630                 // Return it
631                 return sb.toString();
632         }
633
634         /**
635          * Returns the headquarter address. If null is provided, an empty string is
636          * returned.
637          * <p>
638          * @param headquarter Headquarter instance
639          * <p>
640          * @return Headquarter address
641          */
642         public String renderHeadquarter (final Headquarter headquarter) {
643                 // Default is empty string, so let's get started
644                 final StringBuilder sb = new StringBuilder(10);
645
646                 // Is a headquarter set?
647                 if (headquarter instanceof Headquarter) {
648                         // Then create name
649                         sb.append(headquarter.getHeadquarterStreet());
650                         sb.append(" "); //NOI18N
651                         sb.append(headquarter.getHeadquarterHouseNumber());
652
653                         // Is store/suite number set?
654                         if (headquarter.getHeadquarterStore() instanceof Short) {
655                                 sb.append(" ("); //NOI18N
656                                 sb.append(this.getMessageFromBundle("DATA_STORE")); //NOI18N
657                                 sb.append(" "); //NOI18N
658                                 sb.append(headquarter.getHeadquarterStore());
659                                 sb.append(", "); //NOI18N
660                                 sb.append(this.getMessageFromBundle("DATA_SUITE_NUMBER")); //NOI18N
661                                 sb.append(" "); //NOI18N
662                                 sb.append(headquarter.getHeadquarterSuiteNumber());
663                                 sb.append(")"); //NOI18N
664                         }
665
666                         // Continue with country, ZIP code and city
667                         sb.append(", "); //NOI18N
668                         sb.append(headquarter.getHeadquarterCountry().getCountryCode());
669                         sb.append(" "); //NOI18N
670                         sb.append(headquarter.getHeadquarterZipCode());
671                         sb.append(" "); //NOI18N
672                         sb.append(headquarter.getHeadquarterCity());
673                 }
674
675                 // Return it
676                 return sb.toString();
677         }
678
679         /**
680          * Returns the product name and price. If null is provided, an empty string
681          * is returned.
682          * <p>
683          * @param product Product instance
684          * <p>
685          * @return Product name
686          */
687         public String renderProduct (final Product product) {
688                 // Default is empty string, so let's get started
689                 final StringBuilder sb = new StringBuilder(10);
690
691                 // Is a product set?
692                 if (product instanceof Product) {
693                         // Add name and price
694                         sb.append(product.getProductTitle());
695                         sb.append(" ("); //NOI18N
696                         sb.append(this.localizationController.formatCurrency(product.getProductPrice()));
697                         sb.append(")"); //NOI18N
698                 }
699
700                 // Return it
701                 return sb.toString();
702         }
703
704         /**
705          * Returns the receipt. If null is provided, an empty string
706          * is returned.
707          * <p>
708          * @param receipt Receipt instance
709          * <p>
710          * @return Product name
711          */
712         public String renderReceipt (final BillableReceipt receipt) {
713                 // Default is empty string, so let's get started
714                 final StringBuilder sb = new StringBuilder(10);
715
716                 // Is receipt set?
717                 if (receipt instanceof BillableReceipt) {
718                         // Add relevant data
719                         sb.append(this.getMessageFromBundle("RECEIPT_ISSUED")).append(" "); //NOI18N
720                         sb.append(this.getMessageFromBundle(receipt.getReceiptPaymentType().getI18nKey()));
721
722                         // Is receipt number included?
723                         if (receipt.getReceiptNumber() !=null) {
724                                 // Append it
725                                 sb.append(", ").append(this.getMessageFromBundle("RECEIPT_NUMBER")).append(" "); //NOI18N
726                                 sb.append(receipt.getReceiptNumber());
727                         }
728
729                         // Add company (over branch office)
730                         sb.append(" ("); //NOI18N
731                         sb.append(receipt.getReceiptBranchOffice().getBranchCompany().getCompanyName());
732                         sb.append(")"); //NOI18N
733                 }
734
735                 // Return it
736                 return sb.toString();
737         }
738
739         /**
740          * Set's all given contact's phone instances: land-line, mobile and
741          * faxNumber
742          * <p>
743          * @param contact Contact to set phone instances for
744          */
745         private void setPhoneInstances (final Contact contact) {
746                 // The contact must be valid
747                 if (null == contact) {
748                         // Throw NPE
749                         throw new NullPointerException("contact is null"); //NOI18N
750                 } else if (contact.getContactId() == null) {
751                         // Throw again ...
752                         throw new NullPointerException("contact.contactId is null"); //NOI18N
753                 } else if (contact.getContactId() < 1) {
754                         // Not valid
755                         throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
756                 }
757
758                 // Is mobile set?
759                 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
760                         // Yes, then set it in admin controller
761                         this.setMobileNumber(contact.getContactMobileNumber());
762                 }
763
764                 // Is land-line set?
765                 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
766                         // Yes, then set it in admin controller
767                         this.setLandLineNumber(contact.getContactLandLineNumber());
768                 }
769
770                 // Is faxNumber set?
771                 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
772                         // Yes, then set it in admin controller
773                         this.setFaxNumber(contact.getContactFaxNumber());
774                 }
775         }
776
777 }