From: Roland Häder Date: Thu, 18 Aug 2016 13:43:04 +0000 (+0200) Subject: Continued with add/link forms: (please cherry-pick) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=82c903ac18f2044e2c7b9cb4acf397dcbaeb32d8;p=jjobs-war.git Continued with add/link forms: (please cherry-pick) - implemented doLinkAdd(Fax|LandLine|Mobile)Number() which fire events when the number has been linked/added - removed field mobileNumber as it is redundant to phoneNumber - form_contact_data needs mobileNumber as all 3 are being asked there - renamed countryPhoneCode -> phoneCountry as this is more accurate - added missing i18n strings Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestBean.java index fcbed56e..6b20fd0f 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestBean.java @@ -30,18 +30,33 @@ import javax.naming.NamingException; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.fax.linked.AdminFaxNumberLinkedEvent; +import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent; import org.mxchange.jcontacts.events.fax.unlinked.AdminFaxNumberUnlinkedEvent; import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.landline.linked.AdminLandLineNumberLinkedEvent; +import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent; import org.mxchange.jcontacts.events.landline.unlinked.AdminLandLineNumberUnlinkedEvent; import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent; +import org.mxchange.jcontacts.events.mobile.linked.AdminMobileNumberLinkedEvent; import org.mxchange.jcontacts.events.mobile.unlinked.AdminMobileNumberUnlinkedEvent; import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent; import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote; +import org.mxchange.jcountry.data.Country; import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.helper.JobsWebRequestController; +import org.mxchange.jjobs.beans.phone.JobsAdminPhoneWebRequestController; import org.mxchange.jphone.exceptions.FaxNumberNotLinkedException; import org.mxchange.jphone.exceptions.LandLineNumberNotLinkedException; import org.mxchange.jphone.exceptions.MobileNumberNotLinkedException; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.fax.FaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.landline.LandLineNumber; +import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.phonenumbers.mobile.MobileNumber; +import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; /** @@ -58,11 +73,32 @@ public class JobsAdminContactPhoneWebRequestBean extends BaseJobsController impl */ private static final long serialVersionUID = 542_145_347_916L; + /** + * Event being fired when a fax number has been linked + */ + private Event adminLinkedFaxNumberEvent; + + /** + * Event being fired when a land-line number has been linked + */ + private Event adminLinkedLandLineNumberEvent; + + /** + * Event being fired when a mobile number has been linked + */ + private Event adminLinkedMobileNumberEvent; + /** * Administrative EJB for phone number */ private AdminContactsPhoneSessionBeanRemote adminPhoneBean; + /** + * Administrative phone controller + */ + @Inject + private JobsAdminPhoneWebRequestController adminPhoneController; + /** * Admin helper instance */ @@ -170,6 +206,167 @@ public class JobsAdminContactPhoneWebRequestBean extends BaseJobsController impl this.clear(); } + @Override + public String doLinkAddFaxNumber (final Contact contact) { + // Is all data properly set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw it again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Is not valid + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N + } else if ((this.adminPhoneController.getChoosenFaxNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) { + // All fields are empty + throw new NullPointerException("choosenFaxNumber, mobileProvider and phoneNumer are null"); //NOI18N + } else if ((this.adminPhoneController.getChoosenFaxNumber() instanceof DialableFaxNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) { + // All fields are set + throw new IllegalStateException("choosenFaxNumber, mobileProvider and phoneNumer are all set"); //NOI18N + } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) { + // No country selected + this.showFacesMessage("form_add_contact_fax:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N + return ""; //NOI18N + } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) { + // No area code entered + this.showFacesMessage("form_add_contact_fax:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N + return ""; //NOI18N + } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) { + // No phone number entered + this.showFacesMessage("form_add_contact_fax:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N + return ""; //NOI18N + } + + // Init instances + Contact updatedContact; + DialableFaxNumber faxNumber = this.adminPhoneController.getChoosenFaxNumber(); + + // All fine so far, then which was choosen? + if (faxNumber instanceof DialableFaxNumber) { + // User has choosen number + updatedContact = this.adminPhoneBean.linkExistingFaxNumberWithContact(contact, faxNumber); + } else { + // Create new instance + faxNumber = new FaxNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber()); + + // Link it, too + updatedContact = this.adminPhoneBean.linkNewFaxNumberWithContact(contact, faxNumber); + } + + // Fire event + this.adminLinkedFaxNumberEvent.fire(new AdminFaxNumberLinkedEvent(updatedContact, faxNumber)); + + // Return to contact profile + return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N + } + + @Override + public String doLinkAddLandLineNumber (final Contact contact) { + // Is all data properly set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw it again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Is not valid + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N + } else if ((this.adminPhoneController.getChoosenLandLineNumber() == null) && (this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) { + // All fields are empty + throw new NullPointerException("choosenLandLineNumber, mobileProvider and phoneNumer are null"); //NOI18N + } else if ((this.adminPhoneController.getChoosenLandLineNumber() instanceof DialableLandLineNumber) && (this.adminPhoneController.getPhoneCountry() instanceof Country) && (this.adminPhoneController.getPhoneAreaCode() instanceof Integer) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) { + // All fields are set + throw new IllegalStateException("choosenLandLineNumber, mobileProvider and phoneNumer are all set"); //NOI18N + } else if ((this.adminPhoneController.getPhoneCountry() == null) && ((this.adminPhoneController.getPhoneAreaCode() instanceof Integer) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) { + // No country selected + this.showFacesMessage("form_add_contact_landLine:phoneCountry", "ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED"); //NOI18N + return ""; //NOI18N + } else if (((this.adminPhoneController.getPhoneAreaCode() == null) || (this.adminPhoneController.getPhoneAreaCode() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneNumber() instanceof Long))) { + // No area code entered + this.showFacesMessage("form_add_contact_landLine:phoneAreaCode", "ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED"); //NOI18N + return ""; //NOI18N + } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && ((this.adminPhoneController.getPhoneCountry() instanceof Country) || (this.adminPhoneController.getPhoneAreaCode() instanceof Integer))) { + // No phone number entered + this.showFacesMessage("form_add_contact_landLine:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N + return ""; //NOI18N + } + + // Init instance + Contact updatedContact; + DialableLandLineNumber landLineNumber = this.adminPhoneController.getChoosenLandLineNumber(); + + // All fine so far, then which was choosen? + if (landLineNumber instanceof DialableLandLineNumber) { + // User has choosen number + updatedContact = this.adminPhoneBean.linkExistingLandLineNumberWithContact(contact, landLineNumber); + } else { + // Create new instance + landLineNumber = new LandLineNumber(this.adminPhoneController.getPhoneCountry(), this.adminPhoneController.getPhoneAreaCode(), this.adminPhoneController.getPhoneNumber()); + + // Link it, too + updatedContact = this.adminPhoneBean.linkNewLandLineNumberWithContact(contact, landLineNumber); + } + + // Fire event + this.adminLinkedLandLineNumberEvent.fire(new AdminLandLineNumberLinkedEvent(updatedContact, landLineNumber)); + + // Return to contact profile + return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N + } + + @Override + public String doLinkAddMobileNumber (final Contact contact) { + // Is all data properly set? + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); //NOI18N + } else if (contact.getContactId() == null) { + // Throw it again + throw new NullPointerException("contact.contactId is null"); //NOI18N + } else if (contact.getContactId() < 1) { + // Is not valid + throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N + } else if ((this.adminPhoneController.getChoosenMobileNumber() == null) && (this.adminPhoneController.getMobileProvider() == null) && ((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1))) { + // All fields are empty + throw new NullPointerException("choosenMobileNumber, mobileProvider and phoneNumer are null"); //NOI18N + } else if ((this.adminPhoneController.getChoosenMobileNumber() instanceof DialableMobileNumber) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) { + // All fields are set + throw new IllegalStateException("choosenMobileNumber, mobileProvider and phoneNumer are all set"); //NOI18N + } else if ((this.adminPhoneController.getMobileProvider() == null) && (this.adminPhoneController.getPhoneNumber() instanceof Long)) { + // No mobile provider selected + this.showFacesMessage("form_add_contact_mobile:phoneCountry", "ERROR_ADMIN_NO_PHONE_MOBILE_PROVIDER_SELECTED"); //NOI18N + return ""; //NOI18N + } else if (((this.adminPhoneController.getPhoneNumber() == null) || (this.adminPhoneController.getPhoneNumber() < 1)) && (this.adminPhoneController.getMobileProvider() instanceof MobileProvider)) { + // No phone number entered + this.showFacesMessage("form_add_contact_mobile:phoneNumber", "ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED"); //NOI18N + return ""; //NOI18N + } + + // Init instance + Contact updatedContact; + DialableMobileNumber mobileNumber = this.adminPhoneController.getChoosenMobileNumber(); + + // All fine so far, then which was choosen? + if (mobileNumber instanceof DialableMobileNumber) { + // User has choosen number + updatedContact = this.adminPhoneBean.linkExistingMobileNumberWithContact(contact, mobileNumber); + } else { + // Create new instance + mobileNumber = new MobileNumber(this.adminPhoneController.getMobileProvider(), this.adminPhoneController.getPhoneNumber()); + + // Link it, too + updatedContact = this.adminPhoneBean.linkNewMobileNumberWithContact(contact, mobileNumber); + } + + // Fire event + this.adminLinkedMobileNumberEvent.fire(new AdminMobileNumberLinkedEvent(updatedContact, mobileNumber)); + + // Return to contact profile + return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N + } + @Override public String unlinkFaxContactData () { // Is all data set diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestController.java index e72aad95..04d483a8 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestController.java @@ -19,6 +19,7 @@ package org.mxchange.jjobs.beans.contact.phone; import java.io.Serializable; import javax.ejb.Local; +import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; @@ -74,4 +75,35 @@ public interface JobsAdminContactPhoneWebRequestController extends Serializable */ void afterAdminUpdatedContactDataEvent (final AdminUpdatedContactEvent event); + /** + * Links given contact instance with setted fax number or entered data. If + * both is set, a proper exception is thrown as this is an invalid state. + *

+ * @param contact Contact instance to link with existing/new data + *

+ * @return Redirect outcome + */ + String doLinkAddFaxNumber (final Contact contact); + + /** + * Links given contact instance with setted land-line number or entered + * data. If both is set, a proper exception is thrown as this is an invalid + * state. + *

+ * @param contact Contact instance to link with existing/new data + *

+ * @return Redirect outcome + */ + String doLinkAddLandLineNumber (final Contact contact); + + /** + * Links given contact instance with setted mobile or entered data. If both + * is set, a proper exception is thrown as this is an invalid state. + *

+ * @param contact Contact instance to link with existing/new data + *

+ * @return Redirect outcome + */ + String doLinkAddMobileNumber (final Contact contact); + } diff --git a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java index e1de16d8..462d12f9 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java @@ -87,11 +87,6 @@ public class JobsAdminPhoneWebRequestBean extends BaseJobsController implements */ private DialableMobileNumber choosenMobileNumber; - /** - * (Entered) mobile number - */ - private Long mobileNumber; - /** * Event being fired when an administrator has deleted mobile number */ @@ -341,16 +336,6 @@ public class JobsAdminPhoneWebRequestBean extends BaseJobsController implements this.choosenMobileNumber = choosenMobileNumber; } - @Override - public Long getMobileNumber () { - return this.mobileNumber; - } - - @Override - public void setMobileNumber (final Long mobileNumber) { - this.mobileNumber = mobileNumber; - } - @Override public MobileProvider getMobileProvider () { return this.mobileProvider; diff --git a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestController.java b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestController.java index 5c6d95f0..278b72e9 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestController.java @@ -125,20 +125,6 @@ public interface JobsAdminPhoneWebRequestController extends Serializable { */ void setChoosenMobileNumber (final DialableMobileNumber choosenMobileNumber); - /** - * Getter for mobile number - *

- * @return Mobile number - */ - Long getMobileNumber (); - - /** - * Setter for mobile number - *

- * @param mobileNumber Mobile number - */ - void setMobileNumber (final Long mobileNumber); - /** * Getter for phone area code *

diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index a96f3ea1..0750393d 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -703,3 +703,6 @@ ADMIN_EDIT_LAND_LINE_NUMBER=Festnetznummer \u00e4ndern: ADMIN_EDIT_FAX_NUMBER=Faxnummer \u00e4ndern: BUTTON_ADMIN_EDIT_LAND_LINE_NUMBER=Festnetznummer ab\u00e4ndern BUTTON_ADMIN_EDIT_FAX_NUMBER=Faxnummer ab\u00e4ndern +ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED=Keine Landesvorwahl ausgew\u00e4hlt. +ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED=Keine Ortsvorwahl eingegeben. +ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED=Keine Rufnummer eingegeben. diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 66f9531e..1679ced8 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -703,3 +703,6 @@ ADMIN_EDIT_LAND_LINE_NUMBER=Change land-line number: ADMIN_EDIT_FAX_NUMBER=Change fax number: BUTTON_ADMIN_EDIT_LAND_LINE_NUMBER=Change land-line number BUTTON_ADMIN_EDIT_FAX_NUMBER=Change fax number +ERROR_ADMIN_NO_PHONE_COUNTRY_SELECTED=No country dial prefix selected. +ERROR_ADMIN_NO_PHONE_AREA_CODE_ENTERED=No city (area) dial prefix entered. +ERROR_ADMIN_NO_PHONE_NUMBER_ENTERED=No call number entered. diff --git a/web/WEB-INF/templates/contact/form_contact_data.tpl b/web/WEB-INF/templates/contact/form_contact_data.tpl index 264bac94..ed8551ad 100644 --- a/web/WEB-INF/templates/contact/form_contact_data.tpl +++ b/web/WEB-INF/templates/contact/form_contact_data.tpl @@ -266,9 +266,19 @@

- - - + + + + + + + + + + + + +
diff --git a/web/WEB-INF/templates/input_fields/fax_input_fields.tpl b/web/WEB-INF/templates/input_fields/fax_input_fields.tpl index 27e3a4d3..99df5007 100644 --- a/web/WEB-INF/templates/input_fields/fax_input_fields.tpl +++ b/web/WEB-INF/templates/input_fields/fax_input_fields.tpl @@ -6,10 +6,10 @@ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> - + - + diff --git a/web/WEB-INF/templates/input_fields/mobile_input_fields.tpl b/web/WEB-INF/templates/input_fields/mobile_input_fields.tpl index b515e622..02d81bd4 100644 --- a/web/WEB-INF/templates/input_fields/mobile_input_fields.tpl +++ b/web/WEB-INF/templates/input_fields/mobile_input_fields.tpl @@ -12,7 +12,7 @@ - +