2 * Copyright (C) 2016 - 2024 Free Software Foundation
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.
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.
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/>.
17 package org.mxchange.jjobs.beans.helper;
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;
52 * A general helper for beans
54 * @author Roland Häder<roland@mxchange.org>
58 public class JobsWebViewHelperBean extends BaseJobsBean implements JobsWebViewHelperController {
63 private static final long serialVersionUID = 17_258_793_567_145_701L;
68 private Contact contact;
71 * Event for when a contact instance was created
75 private Event<ObservableCreatedContactEvent> contactCreatedEvent;
78 * Regular user controller
81 private JobsContactListWebViewController contactListController;
86 private DialableFaxNumber faxNumber;
89 * Event for when a fax number instance was created
93 private Event<ObservableCreatedFaxNumberEvent> faxNumberCreatedEvent;
98 private DialableLandLineNumber landLineNumber;
101 * Event for when a land-line number instance was created
105 private Event<ObservableCreatedLandLineNumberEvent> landLineNumberCreatedEvent;
108 * Localization controller
111 private JobsLocalizationSessionController localizationController;
116 private DialableMobileNumber mobileNumber;
119 * Event for when a mobile number instance was created
123 private Event<ObservableCreatedMobileNumberEvent> mobileNumberCreatedEvent;
131 * Event for when a user instance was created
135 private Event<ObservableCreatedUserEvent> userCreatedEvent;
138 * Default constructor
140 public JobsWebViewHelperBean () {
141 // Call super constructor
146 * Getter for contact instance
148 * @return Contact instance
151 public Contact getContact () {
156 * Setter for contact instance
158 * @param contact Contact instance
160 public void setContact (final Contact contact) {
161 this.contact = contact;
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.
168 * @param contact Contact instance to check
170 * @return Message key
172 public String getContactUsageMessageKey (final Contact contact) {
173 // The contact must be valid
174 if (null == contact) {
176 throw new NullPointerException("contact is null"); //NOI18N
177 } else if (contact.getContactId() == null) {
179 throw new NullPointerException("contact.contactId is null"); //NOI18N
180 } else if (contact.getContactId() < 1) {
182 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
185 // Default key is "unused"
186 String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
189 if (this.contactListController.isContactFound(contact)) {
191 messageKey = "CONTACT_IS_USER"; //NOI18N
194 // Return message key
199 * Getter for dialable fax number
201 * @return Dialable fax number
204 public DialableFaxNumber getFaxNumber () {
205 return this.faxNumber;
209 * Setter for dialable fax number
211 * @param faxNumber Dialable fax number
213 public void setFaxNumber (final DialableFaxNumber faxNumber) {
214 this.faxNumber = faxNumber;
218 * Getter for dialable land-line number
220 * @return Dialable land-line number
223 public DialableLandLineNumber getLandLineNumber () {
224 return this.landLineNumber;
228 * Setter for dialable land-line number
230 * @param landLineNumber Dialable land-line number
232 public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
233 this.landLineNumber = landLineNumber;
237 * Getter for dialable mobile number
239 * @return Dialable mobile number
242 public DialableMobileNumber getMobileNumber () {
243 return this.mobileNumber;
247 * Setter for dialable mobile number
249 * @param mobileNumber Dialable mobile number
251 public void setMobileNumber (final DialableMobileNumber mobileNumber) {
252 this.mobileNumber = mobileNumber;
256 * Getter for user instance
258 * @return User instance
261 public User getUser () {
266 * Setter for user instance
268 * @param user User instance
270 public void setUser (final User user) {
275 * Notifies other controllers (backing beans) if a contact id has been
276 * successfully converted to a Contact instance.
278 public void notifyControllerContactConverted () {
279 // Validate contact instance
280 if (this.getContact() == null) {
282 throw new NullPointerException("this.contact is null"); //NOI18N
283 } else if (this.getContact().getContactId() == null) {
285 throw new NullPointerException("this.contact.contactId is null"); //NOI18N
286 } else if (this.getContact().getContactId() < 1) {
288 throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
291 // Set all phone instances
292 this.setPhoneInstances(this.getContact());
294 // Set all fields: user
295 this.contactCreatedEvent.fire(new CreatedContactEvent(this.getContact()));
299 * Notifies other controllers (backing beans) if a phone id has been
300 * successfully converted to a DialableFaxNumber instance.
302 public void notifyControllerFaxNumberConverted () {
303 // Validate fax instance
304 if (this.getFaxNumber() == null) {
306 throw new NullPointerException("this.faxNumber is null"); //NOI18N
307 } else if (this.getFaxNumber().getPhoneId() == null) {
309 throw new NullPointerException("this.faxNumber.phoneId is null"); //NOI18N
310 } else if (this.getFaxNumber().getPhoneId() < 1) {
312 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneId={0} is not valid", this.getFaxNumber().getPhoneId())); //NOI18N
313 } else if (this.getFaxNumber().getPhoneAreaCode() == null) {
315 throw new NullPointerException("this.faxNumber.phoneAreaCode is null"); //NOI18N
316 } else if (this.getFaxNumber().getPhoneAreaCode() < 1) {
318 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
319 } else if (this.getFaxNumber().getPhoneCountry() == null) {
321 throw new NullPointerException("this.faxNumber.phoneCountry is null"); //NOI18N
322 } else if (this.getFaxNumber().getPhoneCountry().getCountryId() == null) {
324 throw new NullPointerException("this.faxNumber.phoneCountry.countryId is null"); //NOI18N
325 } else if (this.getFaxNumber().getPhoneCountry().getCountryId() < 1) {
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) {
333 throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneNumber={0} is not valid", this.getFaxNumber().getPhoneNumber())); //NOI18N
337 this.faxNumberCreatedEvent.fire(new CreatedFaxNumberEvent(this.getFaxNumber()));
341 * Notifies other controllers (backing beans) if a phone id has been
342 * successfully converted to a DialableLandLineNumber instance.
344 public void notifyControllerLandLineNumberConverted () {
345 // Validate land-line instance
346 if (this.getLandLineNumber() == null) {
348 throw new NullPointerException("this.landLineNumber is null"); //NOI18N
349 } else if (this.getLandLineNumber().getPhoneId() == null) {
351 throw new NullPointerException("this.landLineNumber.phoneId is null"); //NOI18N
352 } else if (this.getLandLineNumber().getPhoneId() < 1) {
354 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneId={0} is not valid", this.getLandLineNumber().getPhoneId())); //NOI18N
355 } else if (this.getLandLineNumber().getPhoneAreaCode() == null) {
357 throw new NullPointerException("this.landLineNumber.phoneAreaCode is null"); //NOI18N
358 } else if (this.getLandLineNumber().getPhoneAreaCode() < 1) {
360 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
361 } else if (this.getLandLineNumber().getPhoneCountry() == null) {
363 throw new NullPointerException("this.landLineNumber.phoneCountry is null"); //NOI18N
364 } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() == null) {
366 throw new NullPointerException("this.landLineNumber.phoneCountry.countryId is null"); //NOI18N
367 } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() < 1) {
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) {
375 throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneNumber={0} is not valid", this.getLandLineNumber().getPhoneNumber())); //NOI18N
379 this.landLineNumberCreatedEvent.fire(new CreatedLandLineNumberEvent(this.getLandLineNumber()));
383 * Notifies other controllers (backing beans) if a phone id has been
384 * successfully converted to a DialableMobileNumber instance.
386 public void notifyControllerMobileNumberConverted () {
387 // Validate mobile instance
388 if (this.getMobileNumber() == null) {
390 throw new NullPointerException("this.mobileNumber is null"); //NOI18N
391 } else if (this.getMobileNumber().getMobileId() == null) {
393 throw new NullPointerException("this.mobileNumber.mobileId is null"); //NOI18N
394 } else if (this.getMobileNumber().getMobileId() < 1) {
396 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileId={0} is not valid", this.getMobileNumber().getMobileId())); //NOI18N
397 } else if (this.getMobileNumber().getMobileProvider() == null) {
399 throw new NullPointerException("this.mobileNumber.mobileProvider is null"); //NOI18N
400 } else if (this.getMobileNumber().getMobileProvider().getProviderId() == null) {
402 throw new NullPointerException("this.mobileNumber.mobileProvider.providerId is null"); //NOI18N
403 } else if (this.getMobileNumber().getMobileProvider().getProviderId() < 1) {
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) {
411 throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileNumber={0} is not valid", this.getMobileNumber().getMobileNumber())); //NOI18N
415 this.mobileNumberCreatedEvent.fire(new CreatedMobileNumberEvent(this.getMobileNumber()));
419 * Notifies other controllers (backing beans) if a user id has been
420 * successfully converted to a User instance.
422 public void notifyControllerUserConverted () {
423 // Validate user instance
424 if (this.getUser() == null) {
426 throw new NullPointerException("this.user is null"); //NOI18N
427 } else if (this.getUser().getUserId() == null) {
429 throw new NullPointerException("this.user.userId is null"); //NOI18N
430 } else if (this.getUser().getUserId() < 1) {
432 throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
436 final Contact userContact = this.getUser().getUserContact();
438 // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
439 this.setContact(userContact);
441 // Set all phone instances
442 this.setPhoneInstances(userContact);
445 this.userCreatedEvent.fire(new CreatedUserEvent(this.getUser()));
449 * Renders data of basic company data
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
455 * @return Basic company data as string
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);
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
468 // Add company's long name
469 sb.append(basicData.getCompanyName()); //NOI18N
472 // Is email address set?
473 if (showEmailAddress && basicData.getCompanyEmailAddress() != null) {
475 sb.append(", ").append(basicData.getCompanyEmailAddress()); //NOI18N
478 // Is tax number set?
479 if (basicData.getCompanyTaxNumber() != null) {
481 sb.append(", ").append(basicData.getCompanyTaxNumber()); //NOI18N
486 return sb.toString();
490 * Returns the branch office's full address. If null is provided, an empty
491 * string is returned.
493 * @param branchOffice Branch office instance
494 * @param showEmailAddress Whether render email address
496 * @return Branch office's address
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);
502 // Is a branch office instance given?
503 if (branchOffice instanceof BranchOffice) {
504 // This should not happen:
505 if (branchOffice.getBranchId() == null) {
507 throw new NullPointerException("branchOffice.branchId is null"); //NOI18N
508 } else if (branchOffice.getBranchId() < 1) {
510 throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is invalid.", branchOffice.getBranchId())); //NOI18N
511 } else if (branchOffice.getBranchCompany() == null) {
513 throw new NullPointerException("branchOffice.branchCompany is null"); //NOI18N
514 } else if (branchOffice.getBranchCountry() == null) {
516 throw new NullPointerException("branchOffice.branchCountry is null"); //NOI18N
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());
534 return sb.toString();
538 * Returns the contact's personal title, family name and name. If null is
539 * provided, an empty string is returned.
541 * @param contact Contact instance
543 * @return Contact's full name
545 public String renderContact (final Contact contact) {
546 // Default is empty string, so let's get started
547 final StringBuilder sb = new StringBuilder(20);
550 if (contact instanceof Contact) {
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());
560 return sb.toString();
564 * Returns the text representation of given country. If null is provided, an
565 * empty string is returned.
567 * @param country Country instance
569 * @return Country's text representation
571 public String renderCountry (final Country country) {
572 // Default is empty string, so let's get started
573 final StringBuilder sb = new StringBuilder(20);
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
585 return sb.toString();
589 * Returns the department's name and name of assigned company. If null is
590 * provided, an empty string is returned.
592 * @param department Department instance
593 * @param showEmailAddress Whether to render email address
595 * @return Department's full name
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);
601 // Is a department set?
602 if (department instanceof Department) {
604 sb.append(this.getMessageFromBundle(department.getDepartmentI18nKey()));
605 sb.append(" ("); //NOI18N
606 sb.append(this.renderBasicData(department.getDepartmentCompany(), true, showEmailAddress));
607 sb.append(")"); //NOI18N
611 return sb.toString();
615 * Returns the employee's number, personal title, family name and name if
616 * available. If null is provided, an empty string is returned.
618 * @param employee Employable instance
619 * @param showEmailAddress Whether to show email address of employee
621 * @return A string representing an employee
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);
628 if (employee instanceof Employable) {
629 // Is the number given?
630 if (employee.getEmployeeNumber() != null) {
632 sb.append(employee.getEmployeeNumber());
635 // Is contact data found?
636 if (employee.getEmployeePersonalData() instanceof Contact) {
637 // Yes, then render it
638 final String contactName = this.renderContact(employee.getEmployeePersonalData());
641 if (contactName != null && !contactName.isEmpty()) {
642 // Only add braces when employee number is given
643 if (employee.getEmployeeNumber() != null) {
644 sb.append(" ("); //NOI18N
648 sb.append(contactName);
650 // Only add braces when employee number is given
651 if (employee.getEmployeeNumber() != null) {
652 sb.append(")"); //NOI18N
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
664 // Add department name
665 sb.append(this.renderDepartment(employee.getEmployeeDepartment(), showEmailAddress));
667 // Only add braces when employee number is given
668 if (employee.getEmployeeNumber() != null || employee.getEmployeePersonalData() instanceof Contact) {
669 sb.append(")"); //NOI18N
675 return sb.toString();
679 * Returns the headquarter address. If null is provided, an empty string is
682 * @param headquarter Headquarter instance
684 * @return Headquarter address
686 public String renderHeadquarter (final Headquarter headquarter) {
687 // Default is empty string, so let's get started
688 final StringBuilder sb = new StringBuilder(10);
690 // Is a headquarter set?
691 if (headquarter instanceof Headquarter) {
693 sb.append(headquarter.getHeadquarterStreet());
694 sb.append(" "); //NOI18N
695 sb.append(headquarter.getHeadquarterHouseNumber());
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
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());
720 return sb.toString();
724 * Renders given mobile number (land-line and fax number). If null is
725 * provided, an empty string is returned.
727 * @param mobileNumber Mobile number to render
729 * @return Mobile number
731 public String renderMobileNumber (final DialableMobileNumber mobileNumber) {
732 // Default is empty string, so let's get started
733 final StringBuilder sb = new StringBuilder(20);
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());
747 return sb.toString();
751 * Renders given phone number (land-line and fax number). If null is
752 * provided, an empty string is returned.
754 * @param number Phone number to render
756 * @return Phone number
758 * @throws IllegalArgumentException If a mobile number is provided
760 public String renderPhoneNumber (final DialableNumber number) {
761 // Validate parameter
762 if (number instanceof DialableMobileNumber) {
764 throw new IllegalArgumentException("Mobile numbers cannot be rendered with this method. Please use renderMobileNumber() instead."); //NOI18N
767 // Default is empty string, so let's get started
768 final StringBuilder sb = new StringBuilder(20);
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());
782 return sb.toString();
786 * Returns the user's personal title, family name and name. If null is
787 * provided, an empty string is returned.
789 * @param user User instance
791 * @return User's full name
793 public String renderUser (final User user) {
794 // Default is empty string, so let's get started
795 final StringBuilder sb = new StringBuilder(20);
798 if (user instanceof User) {
799 // Add user name first
800 sb.append(user.getUserName());
801 sb.append(" ("); //NOI18N
804 sb.append(this.renderContact(user.getUserContact()));
807 sb.append(")"); //NOI18N
811 return sb.toString();
815 * Set's all given contact's phone instances: land-line, mobile and
818 * @param contact Contact to set phone instances for
820 private void setPhoneInstances (final Contact contact) {
821 // The contact must be valid
822 if (null == contact) {
824 throw new NullPointerException("contact is null"); //NOI18N
825 } else if (contact.getContactId() == null) {
827 throw new NullPointerException("contact.contactId is null"); //NOI18N
828 } else if (contact.getContactId() < 1) {
830 throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
834 if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
835 // Yes, then set it in admin controller
836 this.setMobileNumber(contact.getContactMobileNumber());
840 if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
841 // Yes, then set it in admin controller
842 this.setLandLineNumber(contact.getContactLandLineNumber());
846 if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
847 // Yes, then set it in admin controller
848 this.setFaxNumber(contact.getContactFaxNumber());