X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fbeans%2Fhelper%2FJobsWebRequestHelperBean.java;h=ddeca5176ba6753db9ae215553e5302214ee4099;hb=13c1bb339440573e5ab36c9c04faef4a30f858b9;hp=d5f1bfab34d6559da964085a32ce74e3f7864af2;hpb=71af705cba00ac4cb88971049f9abe1e2c9f33e9;p=jjobs-war.git diff --git a/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java b/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java index d5f1bfab..ddeca517 100644 --- a/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java +++ b/src/java/org/mxchange/jjobs/beans/helper/JobsWebRequestHelperBean.java @@ -20,12 +20,15 @@ import java.text.MessageFormat; import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; import javax.enterprise.inject.Any; +import javax.faces.context.FacesContext; import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.events.contact.created.CreatedContactEvent; import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent; -import org.mxchange.jjobs.beans.BaseJobsController; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; +import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController; import org.mxchange.jjobs.beans.phone.JobsAdminPhoneWebRequestController; import org.mxchange.jjobs.beans.user.JobsAdminUserWebRequestController; @@ -36,9 +39,9 @@ import org.mxchange.jphone.events.landline.created.CreatedLandLineNumberEvent; import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent; import org.mxchange.jphone.events.mobile.created.CreatedMobileNumberEvent; import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; import org.mxchange.jusercore.events.user.created.CreatedUserEvent; import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent; import org.mxchange.jusercore.model.user.User; @@ -50,7 +53,7 @@ import org.mxchange.jusercore.model.user.User; */ @Named ("beanHelper") @RequestScoped -public class JobsWebRequestHelperBean extends BaseJobsController implements JobsWebRequestHelperController { +public class JobsWebRequestHelperBean extends BaseJobsBean implements JobsWebRequestHelperController { /** * Call-stack instance (5 may show BeanELResolver.getValue as caller) @@ -152,18 +155,139 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs public JobsWebRequestHelperBean () { // Call super constructor super(); + } - // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName()); - // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller)); + /** + * Getter for contact instance + *

+ * @return Contact instance + */ + public Contact getContact () { + return this.contact; } /** - * Copies currently set contact instances data to adminContactController + * Setter for contact instance + *

+ * @param contact Contact instance */ - public void copyContactToController () { + public void setContact (final Contact contact) { // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName()); - // System.out.println(MessageFormat.format("{0}.copyContactToController: CALLED, caller: {2}", this.getClass().getSimpleName(), this.contact, caller)); + // System.out.println(MessageFormat.format("{0}: Setting contact={1}, previous: {2}, caller: {3}", this.getClass().getSimpleName(), contact, this.contact, caller)); + this.contact = contact; + } + + /** + * Returns a message key depending on if this contact is a user and/or a + * contact. If this contact is unused, a default key is returned. + *

+ * @param contact Contact instance to check + *

+ * @return Message key + */ + public String getContactUsageMessageKey (final Contact contact) { + // The contact must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw again ... + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N + } + + // Default key is "unused" + String messageKey = "CONTACT_IS_UNUSED"; //NOI18N + + // Check user first + if (this.userController.isContactFound(contact)) { + // Only user + messageKey = "CONTACT_IS_USER"; //NOI18N + } + + // Return message key + return messageKey; + } + + /** + * Getter for dialable fax number + *

+ * @return Dialable fax number + */ + public DialableFaxNumber getFaxNumber () { + return this.faxNumber; + } + + /** + * Setter for dialable fax number + *

+ * @param faxNumber Dialable fax number + */ + public void setFaxNumber (final DialableFaxNumber faxNumber) { + this.faxNumber = faxNumber; + } + + /** + * Getter for dialable land-line number + *

+ * @return Dialable land-line number + */ + public DialableLandLineNumber getLandLineNumber () { + return this.landLineNumber; + } + + /** + * Setter for dialable land-line number + *

+ * @param landLineNumber Dialable land-line number + */ + public void setLandLineNumber (final DialableLandLineNumber landLineNumber) { + this.landLineNumber = landLineNumber; + } + + /** + * Getter for dialable mobile number + *

+ * @return Dialable mobile number + */ + public DialableMobileNumber getMobileNumber () { + return this.mobileNumber; + } + + /** + * Setter for dialable mobile number + *

+ * @param mobileNumber Dialable mobile number + */ + public void setMobileNumber (final DialableMobileNumber mobileNumber) { + this.mobileNumber = mobileNumber; + } + + /** + * Getter for user instance + *

+ * @return User instance + */ + public User getUser () { + return this.user; + } + + /** + * Setter for user instance + *

+ * @param user User instance + */ + public void setUser (final User user) { + this.user = user; + } + /** + * Notifies other controllers (backing beans) if a contact id has been + * successfully converted to a Contact instance. + */ + public void notifyControllerContactConverted () { // Validate contact instance if (this.getContact() == null) { // Throw NPE @@ -184,9 +308,10 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs } /** - * Copies currently set fax number's data to admin phone controller + * Notifies other controllers (backing beans) if a phone id has been + * successfully converted to a DialableFaxNumber instance. */ - public void copyFaxNumberToController () { + public void notifyControllerFaxNumberConverted () { // Validate fax instance if (this.getFaxNumber() == null) { // Throw NPE @@ -225,9 +350,10 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs } /** - * Copies currently set land-line number's data to admin phone controller + * Notifies other controllers (backing beans) if a phone id has been + * successfully converted to a DialableLandLineNumber instance. */ - public void copyLandLineNumberToController () { + public void notifyControllerLandLineNumberConverted () { // Validate land-line instance if (this.getLandLineNumber() == null) { // Throw NPE @@ -266,9 +392,10 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs } /** - * Copies currently set mobile number's data to admin phone controller + * Notifies other controllers (backing beans) if a phone id has been + * successfully converted to a DialableMobileNumber instance. */ - public void copyMobileNumberToController () { + public void notifyControllerMobileNumberConverted () { // Validate mobile instance if (this.getMobileNumber() == null) { // Throw NPE @@ -301,12 +428,10 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs } /** - * Copies currently set user instances data to adminUserController + * Notifies other controllers (backing beans) if a user id has been + * successfully converted to a User instance. */ - public void copyUserToController () { - // Log message - //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N - + public void notifyControllerUserConverted () { // Validate user instance if (this.getUser() == null) { // Throw NPE @@ -320,7 +445,7 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs } // Get contact - Contact userContact = this.getUser().getUserContact(); + final Contact userContact = this.getUser().getUserContact(); // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs. this.setContact(userContact); @@ -333,132 +458,55 @@ public class JobsWebRequestHelperBean extends BaseJobsController implements Jobs } /** - * Getter for contact instance - *

- * @return Contact instance - */ - public Contact getContact () { - return this.contact; - } - - /** - * Setter for contact instance - *

- * @param contact Contact instance - */ - public void setContact (final Contact contact) { - // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName()); - // System.out.println(MessageFormat.format("{0}: Setting contact={1}, previous: {2}, caller: {3}", this.getClass().getSimpleName(), contact, this.contact, caller)); - this.contact = contact; - } - - /** - * Returns a message key depending on if this contact is a user and/or a - * contact. If this contact is unused, a default key is returned. + * Returns the branch office's full address. If null is provided, an empty + * string is returned. *

- * @param contact Contact instance to check + * @param branchOffice Branch office instance *

- * @return Message key - */ - public String getContactUsageMessageKey (final Contact contact) { - // The contact must be valid - if (null == contact) { - // Throw NPE - throw new NullPointerException("contact is null"); //NOI18N - } else if (contact.getContactId() == null) { - // Throw again ... - throw new NullPointerException("contact.contactId is null"); //NOI18N - } else if (contact.getContactId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N + * @return Branch office's address + */ + public String renderBranchOffice (final BranchOffice branchOffice) { + // Default is empty string, so let's get started + final StringBuilder sb = new StringBuilder(30); + + // Is a branch office instance given? + if (branchOffice instanceof BranchOffice) { + // Yes, then append all data + sb.append(", "); + sb.append(branchOffice.getBranchStreet()); + sb.append(" "); + sb.append(branchOffice.getBranchHouseNumber()); + sb.append(", "); + sb.append(branchOffice.getBranchCountry().getCountryCode()); + sb.append(" "); + sb.append(branchOffice.getBranchZipCode()); + sb.append(branchOffice.getBranchCity()); } - // Default key is "unused" - String messageKey = "CONTACT_IS_UNUSED"; //NOI18N - - // Check user contact - boolean isUserContact = this.userController.isContactFound(contact); - - // Check user first - if (isUserContact) { - // Only user - messageKey = "CONTACT_IS_USER"; //NOI18N - } - - // Return message key - return messageKey; - } - - /** - * Getter for dialable fax number - *

- * @return Dialable fax number - */ - public DialableFaxNumber getFaxNumber () { - return this.faxNumber; - } - - /** - * Setter for dialable fax number - *

- * @param faxNumber Dialable fax number - */ - public void setFaxNumber (final DialableFaxNumber faxNumber) { - this.faxNumber = faxNumber; - } - - /** - * Getter for dialable land-line number - *

- * @return Dialable land-line number - */ - public DialableLandLineNumber getLandLineNumber () { - return this.landLineNumber; - } - - /** - * Setter for dialable land-line number - *

- * @param landLineNumber Dialable land-line number - */ - public void setLandLineNumber (final DialableLandLineNumber landLineNumber) { - this.landLineNumber = landLineNumber; + // Return it + return sb.toString(); } /** - * Getter for dialable mobile number + * Returns the contact's personal title, family name and name. If null is + * provided, an empty string is returned. *

- * @return Dialable mobile number - */ - public DialableMobileNumber getMobileNumber () { - return this.mobileNumber; - } - - /** - * Setter for dialable mobile number + * @param contact Contact instance *

- * @param mobileNumber Dialable mobile number + * @return Contact's name */ - public void setMobileNumber (final DialableMobileNumber mobileNumber) { - this.mobileNumber = mobileNumber; - } + public String renderContact (final Contact contact) { + // Default is empty string, so let's get started + final StringBuilder sb = new StringBuilder(20); - /** - * Getter for user instance - *

- * @return User instance - */ - public User getUser () { - return this.user; - } + // Is contact set? + if (contact instanceof Contact) { + // Then create name + sb.append(String.format(FacesContext.getCurrentInstance().getViewRoot().getLocale(), "{0} {1}, {2}", this.getMessageFromBundle(contact.getContactPersonalTitle().getMessageKey()), contact.getContactFamilyName(), contact.getContactFirstName())); //NOI18N + } - /** - * Setter for user instance - *

- * @param user User instance - */ - public void setUser (final User user) { - this.user = user; + // Return it + return sb.toString(); } /**