From 94d204235cf894eff47a73f4cb31ac19eb2f62c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 20 Apr 2017 17:53:23 +0200 Subject: [PATCH] Please cherry-pick: - removed event-observing methods from interfaces as they should not be called from other beans, but only invoked when the specific event has been fired. - remember these guide-lines: 1) Use interface for type-hinting objects, not direct class name. 2) All methods in interface are considered as callable (by you) 3) If you still need public methods (like it is needed for @PostConstruct or @Observes) don't add that method to interface. 4) This way, the interface is clean and simple (KISS), no exceptions (of, course thrown ...)! MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../checkout/PizzaCheckoutWebSessionBean.java | 4 +- .../PizzaConfirmationLinkWebRequestBean.java | 4 +- .../PizzaAdminContactWebRequestBean.java | 4 +- .../contact/PizzaContactWebSessionBean.java | 483 +++++++++----- .../PizzaContactWebSessionController.java | 83 +-- .../PizzaAdminContactPhoneWebRequestBean.java | 577 +++++++++++++++++ ...AdminContactPhoneWebRequestController.java | 84 +++ .../PizzaContactPhoneWebSessionBean.java | 232 +++++-- ...PizzaContactPhoneWebSessionController.java | 32 +- .../PizzaCountryWebApplicationBean.java | 11 +- .../PizzaCountryWebApplicationController.java | 9 - .../PizzaAdminCustomerWebRequestBean.java | 4 +- .../beans/helper/PizzaWebRequestHelper.java | 276 -------- .../helper/PizzaWebRequestHelperBean.java | 442 +++++++++++++ ...a => PizzaWebRequestHelperController.java} | 62 +- .../PizzaLocalizationSessionBean.java | 12 +- .../PizzaLocalizationSessionController.java | 16 - .../login/PizzaUserLoginWebSessionBean.java | 107 +-- .../PizzaUserLoginWebSessionController.java | 19 +- .../PizzaMobileProviderWebRequestBean.java | 9 +- ...zzaMobileProviderWebRequestController.java | 9 - .../phone/PizzaAdminPhoneWebRequestBean.java | 569 +++++++++++++++- .../PizzaAdminPhoneWebRequestController.java | 170 ++++- .../phone/PizzaPhoneWebApplicationBean.java | 610 ++++++++++++++++++ .../PizzaPhoneWebApplicationController.java | 171 +++++ .../receipt/PizzaReceiptWebSessionBean.java | 4 +- .../PizzaUserRegisterWebSessionBean.java | 4 +- .../user/PizzaAdminUserWebRequestBean.java | 193 ++++-- .../PizzaAdminUserWebRequestController.java | 47 +- .../beans/user/PizzaUserWebSessionBean.java | 367 +++++++---- .../user/PizzaUserWebSessionController.java | 76 +-- .../PizzaUserPasswordWebRequestBean.java | 4 +- ...PizzaUserPasswordWebRequestController.java | 24 +- .../contact/PizzaContactConverter.java | 12 - .../country/PizzaCountryConverter.java | 9 - .../mobile/PizzaMobileConverter.java | 6 - .../PizzaMobileProviderConverter.java | 9 - .../converter/user/PizzaUserConverter.java | 12 - .../birthday/PizzaBirthdayValidator.java | 5 - .../validator/user/PizzaUserIdValidator.java | 16 +- 40 files changed, 3735 insertions(+), 1052 deletions(-) create mode 100644 src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestBean.java create mode 100644 src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestController.java delete mode 100644 src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelper.java create mode 100644 src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperBean.java rename src/java/org/mxchange/pizzaapplication/beans/helper/{PizzaWebRequestController.java => PizzaWebRequestHelperController.java} (60%) create mode 100644 src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebApplicationBean.java create mode 100644 src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebApplicationController.java diff --git a/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java index 00e948cd..c74825db 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/checkout/PizzaCheckoutWebSessionBean.java @@ -44,7 +44,7 @@ import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.pizzaapplication.beans.basket.PizzaBasketWebSessionController; import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController; -import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; import org.mxchange.pizzaapplication.beans.receipt.PizzaReceiptWebSessionController; /** @@ -72,7 +72,7 @@ public class PizzaCheckoutWebSessionBean extends BasePizzaController implements * Bean helper instance */ @Inject - private PizzaWebRequestController beanHelper; + private PizzaWebRequestHelperController beanHelper; /** * Event fired when a checkout was completed by the user diff --git a/src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestBean.java index 614c3053..00bd6614 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/confirmlink/PizzaConfirmationLinkWebRequestBean.java @@ -37,9 +37,9 @@ import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.UserSessionBeanRemote; import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.pizzaapplication.beans.BasePizzaController; -import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController; import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; /** * A web request bean for confirmation link handling @@ -59,7 +59,7 @@ public class PizzaConfirmationLinkWebRequestBean extends BasePizzaController imp * Bean helper instance */ @Inject - private PizzaWebRequestController beanHelper; + private PizzaWebRequestHelperController beanHelper; /** * Confirmation key diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java index 339e8ef1..49dd1660 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java @@ -49,9 +49,9 @@ import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; import org.mxchange.jphone.phonenumbers.mobile.MobileNumber; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; import org.mxchange.pizzaapplication.beans.BasePizzaController; -import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController; import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; /** * Administrative user bean (controller) @@ -83,7 +83,7 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme * Bean helper instance */ @Inject - private PizzaWebRequestController beanHelper; + private PizzaWebRequestHelperController beanHelper; /** * Birth day diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java index 0be55879..e225c437 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionBean.java @@ -37,8 +37,13 @@ import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; import org.mxchange.jcontacts.contact.UserContact; import org.mxchange.jcontacts.contact.gender.Gender; import org.mxchange.jcontacts.contact.utils.ContactUtils; +import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent; +import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; +import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent; import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; @@ -46,18 +51,15 @@ 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.exceptions.UserPasswordMismatchException; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.pizzaapplication.beans.BasePizzaController; -import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; -import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent; import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent; import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent; -import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; -import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jusercore.model.user.User; +import org.mxchange.pizzaapplication.beans.BasePizzaController; +import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; +import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; /** * A general contact bean (controller) @@ -78,16 +80,6 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P */ private Date birthday; - /** - * Mobile number's carrier - */ - private MobileProvider cellphoneCarrier; - - /** - * Mobile number - */ - private Long cellphoneNumber; - /** * City */ @@ -106,7 +98,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P /** * Contact list */ - private final List contactList; + private final List contacts; /** * Country instance @@ -119,14 +111,14 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P private String emailAddress; /** - * Email address list + * Email address repeated */ - private final List emailAddressList; + private String emailAddressRepeat; /** - * Email address repeated + * Email address list */ - private String emailAddressRepeat; + private final List emailAddresses; /** * Family name @@ -168,11 +160,6 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P */ private String houseNumberExtension; - /** - * Whether a cellphone entry has been unlinked - */ - private boolean isMobileUnlinked; - /** * Whether a fax entry has been unlinked */ @@ -184,19 +171,34 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P private boolean isLandLineUnlinked; /** - * Phone number area code + * Whether a mobile entry has been unlinked */ - private Integer phoneAreaCode; + private boolean isMobileUnlinked; /** - * Country instance for phone number + * Land-line number area code */ - private Country phoneCountry; + private Integer landLineAreaCode; /** - * Phone number + * Country instance for land-line number */ - private Long phoneNumber; + private Country landLineCountry; + + /** + * Land-line number + */ + private Long landLineNumber; + + /** + * Mobile number + */ + private Long mobileNumber; + + /** + * Mobile provider + */ + private MobileProvider mobileProvider; /** * A list of all selectable contacts @@ -220,7 +222,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P private PizzaUserWebSessionController userController; /** - * Login bean (controller) + * Login controller (bean) */ @Inject private PizzaUserLoginWebSessionController userLoginController; @@ -240,22 +242,24 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P Context context = new InitialContext(); // Try to lookup - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N + this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); } // Init lists/maps - this.contactList = new LinkedList<>(); - this.emailAddressList = new LinkedList<>(); + this.contacts = new LinkedList<>(); + this.emailAddresses = new LinkedList<>(); } - @Override - public void afterAdminAddedContact (@Observes final ObservableAdminAddedContactEvent event) { - // Trace message - /* NOISY-DEBUG: */ System.out.println(MessageFormat.format("contactController.afterAdminAddedContact(): event={0} - CALLED!", event)); //NOI18N - + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { // The event must be valid if (null == event) { // Throw NPE @@ -268,7 +272,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N } else if (event.getAddedContact().getContactId() < 1) { // Not valid - throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N } // Clear this bean @@ -281,7 +285,11 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.selectableContacts.add(event.getAddedContact()); } - @Override + /** + * Event observer for newly added users by adminstrator + *

+ * @param event Event being fired + */ public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { // event should not be null if (null == event) { @@ -302,8 +310,42 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.clear(); } - @Override - public void afterAdminLinkedUser (@Observes final ObservableAdminLinkedUserEvent event) { + /** + * Event observer for deleted contact instance by administrator + *

+ * @param event Event being fired + */ + public void afterAdminDeletedContactEvent (@Observes final ObservableAdminDeletedContactEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getDeletedContact() == null) { + // Throw NPE again + throw new NullPointerException("event.deletedContact is null"); //NOI18N + } else if (event.getDeletedContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.deletedContact.contactId is null"); //NOI18N + } else if (event.getDeletedContact().getContactId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedContact(), event.getDeletedContact().getContactId())); //NOI18N + } + + // Remove from both lists + this.contacts.remove(event.getDeletedContact()); + this.selectableContacts.remove(event.getDeletedContact()); + + // Clear all data + this.clear(); + } + + /** + * Observes events being fired when an administrator has linked a new user + * with existing contact data. + *

+ * @param event Event being fired + */ + public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -329,7 +371,11 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.clear(); } - @Override + /** + * Event observer for updated contact data by administrators + *

+ * @param event Updated contact data event + */ public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) { // event should not be null if (null == event) { @@ -350,11 +396,15 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.uniqueAddContact(event.getUpdatedContact()); // Add email address to list - this.emailAddressList.add(event.getUpdatedContact().getContactEmailAddress()); + this.emailAddresses.add(event.getUpdatedContact().getContactEmailAddress()); } - @Override - public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) { + /** + * Event observer for new user registrations + *

+ * @param event User registration event + */ + public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -376,9 +426,6 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // Copy all data from registered->user this.copyContact(registeredContact); - // Add contact instance only once - this.uniqueAddContact(registeredContact); - // Add user name and email address this.addUserNameEmailAddress(registeredContact); @@ -386,7 +433,39 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.clear(); } - @Override + /** + * Event observer for unlinked mobile contact by administrators + *

+ * @param event Unlinked mobile contact event + */ + public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N + } + + // Remove it from list + this.removeFromContacts(event.getUnlinkedMobileNumber()); + + // Clear all data + this.clear(); + } + + /** + * Event observer when user confirmed account. + *

+ * @param event Event being fired + */ public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) { // event should not be null if (null == event) { @@ -407,7 +486,11 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.uniqueAddContact(event.getConfirmedUser().getUserContact()); } - @Override + /** + * Event observer for logged-in user + *

+ * @param event Event instance + */ public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) { // event should not be null if (null == event) { @@ -431,18 +514,12 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P @Override @SuppressWarnings ("ReturnOfCollectionOrArrayField") public List allContacts () { - // Debug message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactController.allContacts: contactList.size()={0} - EXIT!", this.contactList.size())); - // Return un-modified list - return this.contactList; + return this.contacts; } @Override public Contact createContactInstance () { - // User message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: CALLED!", this.getClass().getSimpleName())); - // Is all required data set? if (!this.isRequiredPersonalDataSet()) { // No, then abort here @@ -450,9 +527,9 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P } // Generate phone number - DialableLandLineNumber landLineNumber = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); - DialableMobileNumber mobileNumber = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); - DialableFaxNumber faxNumber = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); + DialableLandLineNumber phone = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber()); + DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); + DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); // Create new contact Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); @@ -466,69 +543,63 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P contact.setContactBirthday(this.getBirthday()); contact.setContactComment(this.getComment()); - // Debug message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: this.emailAddress={1}", this.getClass().getSimpleName(), this.getEmailAddress())); - // Don't set null or wrong references - if ((landLineNumber instanceof DialableLandLineNumber) && (landLineNumber.getPhoneCountry() instanceof Country) && (this.getPhoneAreaCode() != null) && (this.getPhoneNumber() != null) && (this.getPhoneAreaCode() > 0) && (this.getPhoneNumber() > 0)) { + if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) { // Now the number must be given - if (landLineNumber.getPhoneAreaCode() == null) { + if (phone.getPhoneAreaCode() == null) { // Is null throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N - } else if (landLineNumber.getPhoneAreaCode() < 1) { + } else if (phone.getPhoneAreaCode() < 1) { // Abort here throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N - } else if (landLineNumber.getPhoneNumber() == null) { + } else if (phone.getPhoneNumber() == null) { // Is null throw new NullPointerException("phone.phoneNumber is null"); //NOI18N - } else if (landLineNumber.getPhoneNumber() < 1) { + } else if (phone.getPhoneNumber() < 1) { // Abort here throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N } // Set phone number - contact.setContactLandLineNumber(landLineNumber); + contact.setContactLandLineNumber(phone); } // Don't set null or wrong references - if ((faxNumber instanceof DialableFaxNumber) && (faxNumber.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) { + if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) { // Now the number must be given - if (faxNumber.getPhoneAreaCode() == null) { + if (fax.getPhoneAreaCode() == null) { // Is null throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N - } else if (faxNumber.getPhoneAreaCode() < 1) { + } else if (fax.getPhoneAreaCode() < 1) { // Abort here throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N - } else if (faxNumber.getPhoneNumber() == null) { + } else if (fax.getPhoneNumber() == null) { // Is null throw new NullPointerException("fax.phoneNumber is null"); //NOI18N - } else if (faxNumber.getPhoneNumber() < 1) { + } else if (fax.getPhoneNumber() < 1) { // Abort here throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N } // Set fax number - contact.setContactFaxNumber(faxNumber); + contact.setContactFaxNumber(fax); } // Is the provider set? - if ((mobileNumber instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) { + if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) { // Is the number set? - if (mobileNumber.getPhoneNumber() == null) { + if (mobile.getPhoneNumber() == null) { // Is null - throw new NullPointerException("cellphone.phoneNumber is null"); //NOI18N - } else if (mobileNumber.getPhoneNumber() < 1) { + throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N + } else if (mobile.getPhoneNumber() < 1) { // Abort here - throw new IllegalArgumentException("cellphone.phoneNumber is zero or below."); //NOI18N + throw new IllegalArgumentException("mobileNumber.phoneNumber is zero or below."); //NOI18N } - // Set cellphone number - contact.setContactMobileNumber(mobileNumber); + // Set mobile number + contact.setContactMobileNumber(mobile); } - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("{0}.createContactInstance: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); - // Return it return contact; } @@ -544,7 +615,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P throw new FaceletException("Not all required fields are set."); //NOI18N } else if (!this.userLoginController.ifCurrentPasswordMatches()) { // Password not matching - this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N + this.showFacesMessage("form_login_change_personal:currentPassword", "ERROR_USER_CURRENT_PASSWORD_MISMATCHING"); //NOI18N return ""; //NOI18N } @@ -567,11 +638,11 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P contact.setContactCity(this.getCity()); contact.setContactCountry(this.getCountry()); - // Update contact's cellphone number + // Update contact's mobile number this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber()); // Update contact's land-line number - this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber()); + this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber()); // Update contact's fax number this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber()); @@ -580,7 +651,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked); // All fine - return "contact_data_saved"; //NOI18N + return "user_contact_data_saved"; //NOI18N } @Override @@ -595,26 +666,6 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.birthday = birthday; } - @Override - public MobileProvider getMobileProvider () { - return this.cellphoneCarrier; - } - - @Override - public void setMobileProvider (final MobileProvider mobileProvider) { - this.cellphoneCarrier = mobileProvider; - } - - @Override - public Long getMobileNumber () { - return this.cellphoneNumber; - } - - @Override - public void setMobileNumber (Long cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - @Override public String getCity () { return this.city; @@ -757,33 +808,53 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P } @Override - public Integer getPhoneAreaCode () { - return this.phoneAreaCode; + public Integer getLandLineAreaCode () { + return this.landLineAreaCode; } @Override - public void setPhoneAreaCode (final Integer phoneAreaCode) { - this.phoneAreaCode = phoneAreaCode; + public void setLandLineAreaCode (final Integer landLineAreaCode) { + this.landLineAreaCode = landLineAreaCode; } @Override - public Country getPhoneCountry () { - return this.phoneCountry; + public Country getLandLineCountry () { + return this.landLineCountry; } @Override - public void setPhoneCountry (final Country phoneCountry) { - this.phoneCountry = phoneCountry; + public void setLandLineCountry (final Country landLineCountry) { + this.landLineCountry = landLineCountry; } @Override - public Long getPhoneNumber () { - return this.phoneNumber; + public Long getLandLineNumber () { + return this.landLineNumber; } @Override - public void setPhoneNumber (final Long phoneNumber) { - this.phoneNumber = phoneNumber; + public void setLandLineNumber (final Long landLineNumber) { + this.landLineNumber = landLineNumber; + } + + @Override + public Long getMobileNumber () { + return this.mobileNumber; + } + + @Override + public void setMobileNumber (Long mobileNumber) { + this.mobileNumber = mobileNumber; + } + + @Override + public MobileProvider getMobileProvider () { + return this.mobileProvider; + } + + @Override + public void setMobileProvider (final MobileProvider mobileProvider) { + this.mobileProvider = mobileProvider; } @Override @@ -822,17 +893,17 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P @PostConstruct public void init () { // Get full email address list for reducing EJB calls - this.emailAddressList.addAll(this.contactBean.getEmailAddressList()); + this.emailAddresses.addAll(this.contactBean.getEmailAddressList()); + + // Get all contacts + List allContacts = this.contactBean.getAllContacts(); // Get full contact list - this.contactList.addAll(this.contactBean.getAllContacts()); + this.contacts.addAll(allContacts); // Get all users List allUsers = this.userController.allUsers(); - // Get all contacts - List allContacts = this.contactBean.getAllContacts(); - // Get iterator Iterator iterator = allContacts.iterator(); @@ -877,7 +948,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P } // Determine it - return ((this.emailAddressList instanceof List) && (this.emailAddressList.contains(contact.getContactEmailAddress()))); + return ((this.emailAddresses instanceof List) && (this.emailAddresses.contains(contact.getContactEmailAddress()))); } @Override @@ -918,7 +989,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.clear(); // Try to lookup it in visible user list - for (final Iterator iterator = this.contactList.iterator(); iterator.hasNext();) { + for (final Iterator iterator = this.contacts.iterator(); iterator.hasNext();) { // Get next user Contact next = iterator.next(); @@ -943,6 +1014,34 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P return localContact; } + /** + * Event observer when a list with unused mobile numbers is being created + *

+ * @param event Event being fired + */ + public void removeMobileNumberFromListEvent (@Observes final AdminRemoveMobileNumberFromListEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getMobileNumberList() == null) { + // Throw NPE again + throw new NullPointerException("event.mobileList is null"); //NOI18N + } else if (event.getMobileNumberList().isEmpty()) { + // List is empty, no need to check + return; + } + + // Check all entries + for (final Contact contact : this.contacts) { + // Is the mobile instance set and in list? + if ((contact.getContactMobileNumber() instanceof DialableMobileNumber) && (event.getMobileNumberList().contains(contact.getContactMobileNumber()))) { + // Found it, so remvoe it from list + event.getMobileNumberList().remove(contact.getContactMobileNumber()); + } + } + } + @Override public List selectableContacts () { return Collections.unmodifiableList(this.selectableContacts); @@ -973,13 +1072,13 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P */ private void addUserNameEmailAddress (final Contact contact) { // Make sure the entry is not added yet - if (this.emailAddressList.contains(contact.getContactEmailAddress())) { + if (this.emailAddresses.contains(contact.getContactEmailAddress())) { // Already added throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N } // Add email addres - this.emailAddressList.add(contact.getContactEmailAddress()); + this.emailAddresses.add(contact.getContactEmailAddress()); } /** @@ -1002,9 +1101,9 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P // - contact data this.setEmailAddress(null); this.setEmailAddressRepeat(null); - this.setPhoneAreaCode(null); - this.setPhoneCountry(null); - this.setPhoneNumber(null); + this.setLandLineAreaCode(null); + this.setLandLineCountry(null); + this.setLandLineNumber(null); this.setMobileProvider(null); this.setMobileNumber(null); this.setFaxAreaCode(null); @@ -1050,21 +1149,21 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P this.setBirthday(contact.getContactBirthday()); this.setComment(contact.getContactComment()); - // Get cellphone, phone and fax instance - DialableMobileNumber cellphone = contact.getContactMobileNumber(); + // Get mobile, phone and fax instance + DialableMobileNumber mobile = contact.getContactMobileNumber(); DialableFaxNumber fax = contact.getContactFaxNumber(); DialableLandLineNumber phone = contact.getContactLandLineNumber(); // - contact data if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) { - this.setPhoneCountry(phone.getPhoneCountry()); - this.setPhoneAreaCode(phone.getPhoneAreaCode()); - this.setPhoneNumber(phone.getPhoneNumber()); + this.setLandLineCountry(phone.getPhoneCountry()); + this.setLandLineAreaCode(phone.getPhoneAreaCode()); + this.setLandLineNumber(phone.getPhoneNumber()); } - if ((cellphone instanceof DialableMobileNumber) && (cellphone.getMobileProvider() instanceof MobileProvider)) { - this.setMobileProvider(cellphone.getMobileProvider()); - this.setMobileNumber(cellphone.getPhoneNumber()); + if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) { + this.setMobileProvider(mobile.getMobileProvider()); + this.setMobileNumber(mobile.getPhoneNumber()); } if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) { @@ -1093,13 +1192,97 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P } // Remove from general list - if (!this.contactList.remove(contact)) { + if (!this.contacts.remove(contact)) { // Did not remove contact throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N } // Remove from other lists - this.emailAddressList.remove(contact.getContactEmailAddress()); + this.emailAddresses.remove(contact.getContactEmailAddress()); + } + + /** + * Removes given fax number from all contacts + *

+ * @param faxNumber Fax number to remove + */ + private void removeFromContacts (final DialableFaxNumber faxNumber) { + // Is it valid? + if (null == faxNumber) { + // Throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Is the number set? + if (Objects.equals(contact.getContactFaxNumber(), faxNumber)) { + // Found it + contact.setContactFaxNumber(null); + } + } + } + + /** + * Removes given land-line number from all contacts + *

+ * @param landLineNumber Land-line number to remove + */ + private void removeFromContacts (final DialableLandLineNumber landLineNumber) { + // Is it valid? + if (null == landLineNumber) { + // Throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Is the number set? + if (Objects.equals(contact.getContactLandLineNumber(), landLineNumber)) { + // Found it + contact.setContactLandLineNumber(null); + } + } + } + + /** + * Removes given mobile number from all contacts + *

+ * @param mobileNumber Mobile number to remove + */ + private void removeFromContacts (final DialableMobileNumber mobileNumber) { + // Is it valid? + if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getPhoneId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N + } + + // Loop through all contacts + for (final Contact contact : this.contacts) { + // Is the number set? + if (Objects.equals(contact.getContactMobileNumber(), mobileNumber)) { + // Unset it + contact.setContactMobileNumber(null); + } + } } /** @@ -1122,7 +1305,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P } // Get iterator from list - Iterator iterator = this.contactList.iterator(); + Iterator iterator = this.contacts.iterator(); // "Walk" through all entries while (iterator.hasNext()) { @@ -1138,7 +1321,7 @@ public class PizzaContactWebSessionBean extends BasePizzaController implements P } // Add contact to list - this.contactList.add(contact); + this.contacts.add(contact); } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java index 694c502a..02642faf 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebSessionController.java @@ -25,13 +25,6 @@ import org.mxchange.jcontacts.contact.gender.Gender; import org.mxchange.jcontacts.exceptions.ContactNotFoundException; import org.mxchange.jcountry.data.Country; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; -import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent; -import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent; -import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; -import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; -import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent; -import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; -import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; /** * An interface for user beans @@ -41,11 +34,6 @@ import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContac @Local public interface PizzaContactWebSessionController extends Serializable { - /** - * Minimum password length - */ - public static final Integer MINIMUM_PASSWORD_LENGTH = 5; - /** * Returns a list of all found contacts *

@@ -53,20 +41,6 @@ public interface PizzaContactWebSessionController extends Serializable { */ List allContacts (); - /** - * Event observer for newly added users by adminstrator - *

- * @param event Event being fired - */ - void afterAdminAddedUserEvent (final ObservableAdminAddedUserEvent event); - - /** - * Event observer when user confirmed account. - *

- * @param event Event being fired - */ - void afterUserConfirmedAccount (final ObservableUserConfirmedAccountEvent event); - /** * Updates all data from bean in given contact instance *

@@ -86,43 +60,6 @@ public interface PizzaContactWebSessionController extends Serializable { */ Contact lookupContactById (final Long contactId) throws ContactNotFoundException; - /** - * Event observer for new user registrations - *

- * @param event User registration event - */ - void afterRegistrationEvent (final ObservableUserRegisteredEvent event); - - /** - * Observes events being fired when an administrator has added a new - * contact. - *

- * @param event Event being fired - */ - void afterAdminAddedContact (final ObservableAdminAddedContactEvent event); - - /** - * Observes events being fired when an administrator has linked a new user - * with existing contact data. - *

- * @param event Event being fired - */ - void afterAdminLinkedUser (final ObservableAdminLinkedUserEvent event); - - /** - * Event observer for updated contact data by administrators - *

- * @param event Updated contact data event - */ - void afterAdminUpdatedContactDataEvent (final ObservableAdminUpdatedContactEvent event); - - /** - * Event observer for logged-in user - *

- * @param event Event instance - */ - void afterUserLoginEvent (final ObservableUserLoggedInEvent event); - /** * Creates an instance from all properties *

@@ -145,16 +82,16 @@ public interface PizzaContactWebSessionController extends Serializable { void setBirthday (final Date birthday); /** - * Getter for mobile number's provider + * Getter for mobile provider *

- * @return Mobile number's provider + * @return Mobile provider */ MobileProvider getMobileProvider (); /** - * Setter for mobile number's provider + * Setter for mobile provider *

- * @param mobileProvider Mobile number's provider + * @param mobileProvider Mobile provider */ void setMobileProvider (final MobileProvider mobileProvider); @@ -360,42 +297,42 @@ public interface PizzaContactWebSessionController extends Serializable { *

* @return Phone number's area code */ - Integer getPhoneAreaCode (); + Integer getLandLineAreaCode (); /** * Setter for phone number's area code *

* @param phoneAreaCode Phone number's area code */ - void setPhoneAreaCode (final Integer phoneAreaCode); + void setLandLineAreaCode (final Integer phoneAreaCode); /** * Getter for phone number's country instance *

* @return Phone number's country instance */ - Country getPhoneCountry (); + Country getLandLineCountry (); /** * Setter for phone number's country instance *

* @param phoneCountry Phone number's country instance */ - void setPhoneCountry (final Country phoneCountry); + void setLandLineCountry (final Country phoneCountry); /** * Getter for phone number *

* @return Phone number */ - Long getPhoneNumber (); + Long getLandLineNumber (); /** * Setter for phone number *

* @param phoneNumber Phone number */ - void setPhoneNumber (final Long phoneNumber); + void setLandLineNumber (final Long phoneNumber); /** * Street diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestBean.java new file mode 100644 index 00000000..9bd5bb24 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestBean.java @@ -0,0 +1,577 @@ +/* + * Copyright (C) 2016 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.contact.phone; + +import java.text.MessageFormat; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.event.Observes; +import javax.enterprise.inject.Any; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.landline.linked.AdminLinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent; +import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent; +import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent; +import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent; +import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote; +import org.mxchange.jcountry.data.Country; +import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException; +import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException; +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.ObservableAdminAddedUserEvent; +import org.mxchange.pizzaapplication.beans.BasePizzaController; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; +import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController; + +/** + * An administrative contact phone controller (bean) + *

+ * @author Roland Häder + */ +@Named ("adminContactPhoneController") +@RequestScoped +public class PizzaAdminContactPhoneWebRequestBean extends BasePizzaController implements PizzaAdminContactPhoneWebRequestController { + + /** + * Call-stack instance (5 may show BeanELResolver.getValue as caller) + */ + private static final short THREAD_STACK = 5; + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_916L; + + /** + * Event being fired when a fax number has been linked + */ + @Inject + @Any + private Event adminLinkedFaxNumberEvent; + + /** + * Event being fired when a land-line number has been linked + */ + @Inject + @Any + private Event adminLinkedLandLineNumberEvent; + + /** + * Event being fired when a mobile number has been linked + */ + @Inject + @Any + private Event adminLinkedMobileNumberEvent; + + /** + * Administrative EJB for phone number + */ + private AdminContactsPhoneSessionBeanRemote adminPhoneBean; + + /** + * Administrative phone controller + */ + @Inject + private PizzaAdminPhoneWebRequestController adminPhoneController; + + /** + * Bean helper + */ + @Inject + private PizzaWebRequestHelperController beanHelper; + + /** + * Event being fired when a fax number has been unlinked + */ + @Inject + @Any + private Event faxNumberUnlinkedEvent; + + /** + * Event being fired when a land-line number has been unlinked + */ + @Inject + @Any + private Event landLineNumberUnlinkedEvent; + + /** + * Event being fired when admin unlinks mobile from contact + */ + @Inject + @Any + private Event mobileNumberUnlinkedEvent; + + /** + * Default constructor + */ + public PizzaAdminContactPhoneWebRequestBean () { + // 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)); + + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup the beans + this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminContactPhone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedContact() == null) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N + } + + // Clear this bean + this.clear(); + } + + /** + * Event observer for newly added users by administrator + *

+ * @param event Event being fired + */ + public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + } + + // Clear all data + this.clear(); + } + + /** + * Event observer for updated contact data by administrators + *

+ * @param event Updated contact data event + */ + public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedContact() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedContact is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N + } + + // Clear all data + 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(); + + // Try it again + try { + // 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); + } + } catch (final PhoneNumberAlreadyLinkedException ex) { + // Throw again as cause + this.showFacesMessage("form_add_contact_fax:phoneNumber", ex); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.adminLinkedFaxNumberEvent.fire(new AdminLinkedFaxNumberEvent(updatedContact, faxNumber)); + + // Return to contact profile + return "admin_show_contact"; //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(); + + // Try it again + try { + // 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); + } + } catch (final PhoneNumberAlreadyLinkedException ex) { + // Throw again as cause + this.showFacesMessage("form_add_contact_landLine:phoneNumber", ex); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.adminLinkedLandLineNumberEvent.fire(new AdminLinkedLandLineNumberEvent(updatedContact, landLineNumber)); + + // Return to contact profile + return "admin_show_contact"; //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(); + + // Try it again + try { + // 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); + } + } catch (final PhoneNumberAlreadyLinkedException ex) { + // Throw again as cause + this.showFacesMessage("form_add_contact_mobile:phoneNumber", ex); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, mobileNumber)); + + // Return to contact profile + return "admin_show_contact"; //NOI18N + } + + @Override + public String unlinkFaxContactData () { + // Is all data set + if (this.beanHelper.getFaxNumber() == null) { + // Not set, throw NPE + throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N + } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N + } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N + } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N + } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) { + // Throw it again ... + throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N + } else if (this.beanHelper.getContact() == null) { + // ... and throw again + throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N + } else if (this.beanHelper.getContact().getContactId() == null) { + // ... and again ... + throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N + } else if (this.beanHelper.getContact().getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N + } + + // Init contact instance + Contact updatedContact; + + try { + // Unlink it and return contact without fax instance + updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber()); + } catch (final PhoneNumberNotLinkedException ex) { + // Did not work + this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.faxNumberUnlinkedEvent.fire(new AdminUnlinkedFaxNumberEvent(updatedContact, this.beanHelper.getFaxNumber())); + + // All fine here + return "admin_show_contact"; //NOI18N + } + + @Override + public String unlinkLandLineContactData () { + // Is all data set + if (this.beanHelper.getLandLineNumber() == null) { + // Not set, throw NPE + throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N + } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N + } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N + } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N + } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) { + // Throw it again ... + throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N + } else if (this.beanHelper.getContact() == null) { + // ... and throw again + throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N + } else if (this.beanHelper.getContact().getContactId() == null) { + // ... and again ... + throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N + } else if (this.beanHelper.getContact().getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N + } + + // Init contact instance + Contact updatedContact; + + try { + // Unlink it and return contact without landLine instance + updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber()); + } catch (final PhoneNumberNotLinkedException ex) { + // Did not work + this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.landLineNumberUnlinkedEvent.fire(new AdminUnlinkedLandLineNumberEvent(updatedContact, this.beanHelper.getLandLineNumber())); + + // All fine here + return "admin_show_contact"; //NOI18N + } + + @Override + public String unlinkMobileContactData () { + // Is all data set + if (this.beanHelper.getMobileNumber() == null) { + // Not set, throw NPE + throw new NullPointerException("this.beanHelper.mobileNumber is null"); //NOI18N + } else if (this.beanHelper.getMobileNumber().getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("this.beanHelper.mobileNumber.phoneId is null"); //NOI18N + } else if (this.beanHelper.getMobileNumber().getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.phoneId={0} is not valid", this.beanHelper.getMobileNumber().getPhoneId())); //NOI18N + } else if (this.beanHelper.getMobileNumber().getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider is null"); //NOI18N + } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("this.beanHelper.mobileNumber.mobileProvider.providerId is null"); //NOI18N + } else if (this.beanHelper.getMobileNumber().getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.mobileNumber.mobileProvider.providerId={0} is not valid.", this.beanHelper.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N + } else if (this.beanHelper.getMobileNumber().getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("this.beanHelper.mobileNumber.phoneNumber is null"); //NOI18N + } else if (this.beanHelper.getMobileNumber().getPhoneNumber() < 1) { + // Throw it again ... + throw new NullPointerException(MessageFormat.format("this.beanHelper.mobileNumber.phoneNumber={0} is not valid.", this.beanHelper.getMobileNumber().getPhoneNumber())); //NOI18N + } else if (this.beanHelper.getContact() == null) { + // ... and throw again + throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N + } else if (this.beanHelper.getContact().getContactId() == null) { + // ... and again ... + throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N + } else if (this.beanHelper.getContact().getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N + } + + // Init contact instance + Contact updatedContact; + + try { + // Unlink it and return contact without mobile instance + updatedContact = this.adminPhoneBean.unlinkMobileDataFromContact(this.beanHelper.getContact(), this.beanHelper.getMobileNumber()); + } catch (final PhoneNumberNotLinkedException ex) { + // Did not work + this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, this.beanHelper.getMobileNumber())); + + // All fine here + return "admin_show_contact"; //NOI18N + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all data + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestController.java new file mode 100644 index 00000000..b46cd55a --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaAdminContactPhoneWebRequestController.java @@ -0,0 +1,84 @@ + +/* + * Copyright (C) 2016 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.contact.phone; + +import java.io.Serializable; +import javax.ejb.Local; +import org.mxchange.jcontacts.contact.Contact; + +/** + * An interface for user beans + *

+ * @author Roland Häder + */ +@Local +public interface PizzaAdminContactPhoneWebRequestController extends Serializable { + + /** + * Unlinks fax data with current contact + *

+ * @return Redirect outcome + */ + String unlinkFaxContactData (); + + /** + * Unlinks land-line data with current contact + *

+ * @return Redirect outcome + */ + String unlinkLandLineContactData (); + + /** + * Unlinks mobile data with current contact + *

+ * @return Redirect outcome + */ + String unlinkMobileContactData (); + + /** + * Links given contact instance with set 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 set 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 set 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/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionBean.java index ac4ab7c3..cf6c4791 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionBean.java @@ -24,20 +24,22 @@ import java.util.Map; import java.util.Objects; import javax.enterprise.context.SessionScoped; import javax.enterprise.event.Observes; -import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote; -import org.mxchange.pizzaapplication.beans.BasePizzaController; -import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; -import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController; -import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent; +import org.mxchange.jphone.phonenumbers.DialableNumber; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; +import org.mxchange.pizzaapplication.beans.BasePizzaController; +import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; /** * A general contact bean (controller) @@ -54,15 +56,10 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme private static final long serialVersionUID = 542_145_347_916L; /** - * Remote EJB for phone number (administrative) - */ - private AdminPhoneSessionBeanRemote adminPhoneBean; - - /** - * Administrative phone controller + * Bean helper */ @Inject - private PizzaAdminPhoneWebRequestController adminPhoneController; + private PizzaWebRequestHelperController beanHelper; /** * General contact controller @@ -71,33 +68,27 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme private PizzaContactWebSessionController contactController; /** - * "Cache" for contact lists, mostly only one is assigned. So this cache - * shouldn't grow beyond control. + * "Cache" for contact's mobile, land-line and fax numbers. Currently one + * per each type is supported. Maybe later this will change into a OneToMany + * relationship (one contact, many numbers). */ - private final Map> contacts; + private final Map> contacts; /** * Default constructor */ public PizzaContactPhoneWebSessionBean () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup the beans - this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminphone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } - // Init lists/maps this.contacts = new HashMap<>(10); } - @Override - public void afterAdminAddedContact (@Observes final ObservableAdminAddedContactEvent event) { + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { // The event must be valid if (null == event) { // Throw NPE @@ -110,14 +101,18 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N } else if (event.getAddedContact().getContactId() < 1) { // Not valid - throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N } // Clear this bean this.clear(); } - @Override + /** + * Event observer for newly added users by administrator + *

+ * @param event Event being fired + */ public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { // event should not be null if (null == event) { @@ -138,7 +133,95 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme this.clear(); } - @Override + /** + * Event observer for unlinked fax contact by administrators + *

+ * @param event Unlinked fax contact event + */ + public void afterAdminUnlinkedFaxContactDataEvent (@Observes final ObservableAdminUnlinkedFaxNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlinkedFaxNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N + } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N + } + + // Remove it from list + this.contacts.remove(event.getUnlinkedFaxNumber()); + + // Clear all data + this.clear(); + } + + /** + * Event observer for unlinked land-line contact by administrators + *

+ * @param event Unlinked land-line contact event + */ + public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final ObservableAdminUnlinkedLandLineNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlinkedLandLineNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N + } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N + } + + // Remove it from list + this.contacts.remove(event.getUnlinkedLandLineNumber()); + + // Clear all data + this.clear(); + } + + /** + * Event observer for unlinked mobile contact by administrators + *

+ * @param event Unlinked mobile contact event + */ + public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N + } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N + } + + // Remove it from list + this.contacts.remove(event.getUnlinkedMobileNumber()); + + // Clear all data + this.clear(); + } + + /** + * Event observer for updated contact data by administrators + *

+ * @param event Updated contact data event + */ public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) { // event should not be null if (null == event) { @@ -154,32 +237,95 @@ public class PizzaContactPhoneWebSessionBean extends BasePizzaController impleme // Not avalid id throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N } + + // Clear all data + this.clear(); + } + + @Override + public List allFaxNumberContacts () { + // Get id + DialableFaxNumber faxNumber = this.beanHelper.getFaxNumber(); + + // Is cache there? + if (this.contacts.containsKey(faxNumber)) { + // Return cached version + return this.contacts.get(faxNumber); + } else { + // Ask bean + List list = new LinkedList<>(); + + // "Walk" through all contacts + for (final Contact contact : this.contactController.allContacts()) { + // Is mobile instance the same? + if (Objects.equals(contact.getContactFaxNumber(), this.beanHelper.getFaxNumber())) { + // Found one + list.add(contact); + } + } + + // Store result in cache + this.contacts.put(faxNumber, list); + + // Return now-cached list + return list; + } + } + + @Override + public List allLandLineNumberContacts () { + // Get id + DialableLandLineNumber landLineNumber = this.beanHelper.getLandLineNumber(); + + // Is cache there? + if (this.contacts.containsKey(landLineNumber)) { + // Return cached version + return this.contacts.get(landLineNumber); + } else { + // Ask bean + List list = new LinkedList<>(); + + // "Walk" through all contacts + for (final Contact contact : this.contactController.allContacts()) { + // Is mobile instance the same? + if (Objects.equals(contact.getContactLandLineNumber(), this.beanHelper.getLandLineNumber())) { + // Found one + list.add(contact); + } + } + + // Store result in cache + this.contacts.put(landLineNumber, list); + + // Return now-cached list + return list; + } } @Override - public List allMobileContacts () { + public List allMobileNumberContacts () { // Get id - Long phoneId = this.adminPhoneController.getMobileNumber().getPhoneId(); + DialableMobileNumber mobileNumber = this.beanHelper.getMobileNumber(); // Is cache there? - if (this.contacts.containsKey(phoneId)) { + if (this.contacts.containsKey(mobileNumber)) { // Return cached version - return this.contacts.get(phoneId); + return this.contacts.get(mobileNumber); } else { // Ask bean List list = new LinkedList<>(); // "Walk" through all contacts for (final Contact contact : this.contactController.allContacts()) { - // Is cellphone instance the same? - if (Objects.equals(contact.getContactMobileNumber(), this.adminPhoneController.getMobileNumber())) { + // Is mobile instance the same? + if (Objects.equals(contact.getContactMobileNumber(), this.beanHelper.getMobileNumber())) { // Found one list.add(contact); } } // Store result in cache - this.contacts.put(phoneId, list); + this.contacts.put(mobileNumber, list); // Return now-cached list return list; diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionController.java index 72c59e85..bc6b176e 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebSessionController.java @@ -20,9 +20,6 @@ import java.io.Serializable; import java.util.List; import javax.ejb.Local; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; -import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; -import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; /** * An interface for user beans @@ -33,37 +30,24 @@ import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContac public interface PizzaContactPhoneWebSessionController extends Serializable { /** - * Minimum password length - */ - public static final Integer MINIMUM_PASSWORD_LENGTH = 5; - - /** - * Getter for all contacts having current cellphone instance linked + * Getter for all contacts having current fax number linked *

* @return List of all linked contacts */ - List allMobileContacts (); + List allFaxNumberContacts (); /** - * Event observer for newly added users by adminstrator + * Getter for all contacts having current land-line number linked *

- * @param event Event being fired - */ - void afterAdminAddedUserEvent (final ObservableAdminAddedUserEvent event); - - /** - * Observes events being fired when an administrator has added a new - * contact. - *

- * @param event Event being fired + * @return List of all linked contacts */ - void afterAdminAddedContact (final ObservableAdminAddedContactEvent event); + List allLandLineNumberContacts (); /** - * Event observer for updated contact data by administrators + * Getter for all contacts having current mobile number linked *

- * @param event Updated contact data event + * @return List of all linked contacts */ - void afterAdminUpdatedContactDataEvent (final ObservableAdminUpdatedContactEvent event); + List allMobileNumberContacts (); } diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java index be3a6513..c95c39c3 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationBean.java @@ -28,8 +28,8 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcountry.data.Country; import org.mxchange.jcountry.data.CountrySingletonBeanRemote; -import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent; +import org.mxchange.pizzaapplication.beans.BasePizzaController; /** * A country bean @@ -72,8 +72,13 @@ public class PizzaCountryWebApplicationBean extends BasePizzaController implemen } } - @Override - public void afterAdminAddedCountry (@Observes final ObservableAdminAddedCountryEvent event) { + /** + * Observing method when the event is fired that an administrator added a + * new country + *

+ * @param event Event instance + */ + public void afterAdminAddedCountryEvent (@Observes final ObservableAdminAddedCountryEvent event) { // Is all valid? if (null == event) { // Throw NPE diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationController.java index 742b876b..d3107741 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebApplicationController.java @@ -19,7 +19,6 @@ package org.mxchange.pizzaapplication.beans.country; import java.io.Serializable; import java.util.List; import org.mxchange.jcountry.data.Country; -import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent; /** * An interface for country beans @@ -35,12 +34,4 @@ public interface PizzaCountryWebApplicationController extends Serializable { */ List allCountries (); - /** - * Observing method when the event is fired that an administrator added a - * new country - *

- * @param event Event instance - */ - void afterAdminAddedCountry (final ObservableAdminAddedCountryEvent event); - } diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java index 3fe8acbd..196e610a 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java @@ -38,8 +38,8 @@ import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController; import org.mxchange.pizzaapplication.model.customer.PizzaAdminCustomerSessionBeanRemote; import org.mxchange.pizzaapplication.model.customer.PizzaCustomer; -import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController; import org.mxchange.jcustomercore.events.customer.added.ObservableAdminAddedCustomerEvent; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; /** * Administrative customer bean (controller) @@ -70,7 +70,7 @@ public class PizzaAdminCustomerWebRequestBean extends BasePizzaController implem * Bean helper instance */ @Inject - private PizzaWebRequestController adminHelper; + private PizzaWebRequestHelperController adminHelper; /** * An event being fired when an administrator has added a new customer diff --git a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelper.java b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelper.java deleted file mode 100644 index 82fd2019..00000000 --- a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelper.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (C) 2016 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.pizzaapplication.beans.helper; - -import java.text.MessageFormat; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcustomercore.model.customer.Customer; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController; -import org.mxchange.pizzaapplication.beans.customer.PizzaAdminCustomerWebRequestController; -import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController; -import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController; -import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; - -/** - * A general helper for beans - *

- * @author Roland Häder - */ -@Named ("beanHelper") -@RequestScoped -public class PizzaWebRequestHelper implements PizzaWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 17_258_793_567_145_701L; - - /** - * Administrative contact controller - */ - @Inject - private PizzaAdminContactWebRequestController adminContactController; - - /** - * Administrative user controller - */ - @Inject - private PizzaAdminCustomerWebRequestController adminCustomerController; - - /** - * Administrative phone controller - */ - @Inject - private PizzaAdminPhoneWebRequestController adminPhoneController; - - /** - * Contact instance - */ - private Contact contact; - - /** - * Contact instance - */ - private Customer customer; - - /** - * General user controller - */ - @Inject - private PizzaCustomerWebSessionController customerController; - - /** - * User instance - */ - private User user; - - /** - * Regular user controller - */ - @Inject - private PizzaUserWebSessionController userController; - - /** - * Default constructor - */ - public PizzaWebRequestHelper () { - } - - @Override - public void copyContactToController () { - // Validate user instance - if (this.getContact() == null) { - // Throw NPE - throw new NullPointerException("this.contact is null"); //NOI18N - } else if (this.getContact().getContactId() == null) { - // Throw NPE again - throw new NullPointerException("this.contact.contactId is null"); //NOI18N - } else if (this.getContact().getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N - } - - // Set all phone instances - this.setPhoneInstances(this.getContact()); - - // Set all fields: user - this.adminContactController.copyContactToController(this.getContact()); - } - - @Override - public void copyCustomerToController () { - // Log message - //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyCustomerToController - CALLED!"); //NOI18N - - // Validate user instance - if (this.getCustomer() == null) { - // Throw NPE - throw new NullPointerException("this.customer is null"); //NOI18N - } else if (this.getCustomer().getCustomerId() == null) { - // Throw NPE again - throw new NullPointerException("this.customer.customerId is null"); //NOI18N - } else if (this.getCustomer().getCustomerId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("this.customer.customerId={0} is not valid.", this.getCustomer().getCustomerId())); //NOI18N - } - - // Set all fields: user - this.adminCustomerController.copyCustomerToController(this.getCustomer()); - - // Log message - //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyCustomerToController - EXIT!"); //NOI18N - } - - @Override - public void copyUserToController () { - // Validate user instance - if (this.getUser() == null) { - // Throw NPE - throw new NullPointerException("this.user is null"); //NOI18N - } else if (this.getUser().getUserId() == null) { - // Throw NPE again - throw new NullPointerException("this.user.userId is null"); //NOI18N - } else if (this.getUser().getUserId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N - } - - // Get contact - Contact userContact = this.getUser().getUserContact(); - - // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs. - this.setContact(userContact); - - // Set all phone instances - this.setPhoneInstances(userContact); - - // Set all fields: user - this.userController.setUserName(this.getUser().getUserName()); - } - - @Override - public Contact getContact () { - return this.contact; - } - - @Override - public void setContact (final Contact contact) { - this.contact = contact; - } - - @Override - 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/customer - boolean isUserContact = this.userController.isContactFound(contact); - boolean isCustomerContact = this.customerController.isContactFound(contact); - - // Check user first - if (isUserContact && isCustomerContact) { - // Is both - messageKey = "CONTACT_IS_USER_USER"; //NOI18N - } else if (isUserContact) { - // Only user - messageKey = "CONTACT_IS_USER"; //NOI18N - } else if (isCustomerContact) { - // Only customer - messageKey = "CONTACT_IS_USER"; //NOI18N - } - - // Return message key - return messageKey; - } - - @Override - public Customer getCustomer () { - return this.customer; - } - - @Override - public void setCustomer (final Customer customer) { - this.customer = customer; - } - - @Override - public User getUser () { - return this.user; - } - - @Override - public void setUser (final User user) { - this.user = user; - } - - /** - * Set's all given contact's phone instances: land-line, cellphone and fax - *

- * @param contact Contact to set phone instances for - */ - private void setPhoneInstances (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 - } - - // Is cellphone set? - if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { - // Yes, then set it in admin controller - this.adminPhoneController.setMobileNumber(contact.getContactMobileNumber()); - } - - // Is land-line set? - if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { - // Yes, then set it in admin controller - this.adminPhoneController.setLandLineNumber(contact.getContactLandLineNumber()); - } - - // Is fax set? - if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { - // Yes, then set it in admin controller - this.adminPhoneController.setFaxNumber(contact.getContactFaxNumber()); - } - } - -} diff --git a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperBean.java b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperBean.java new file mode 100644 index 00000000..a60e0980 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperBean.java @@ -0,0 +1,442 @@ +/* + * Copyright (C) 2016 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.helper; + +import java.text.MessageFormat; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcustomercore.model.customer.Customer; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jusercore.model.user.User; +import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController; +import org.mxchange.pizzaapplication.beans.customer.PizzaAdminCustomerWebRequestController; +import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController; +import org.mxchange.pizzaapplication.beans.phone.PizzaAdminPhoneWebRequestController; +import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; + +/** + * A general helper for beans + *

+ * @author Roland Häder + */ +@Named ("beanHelper") +@RequestScoped +public class PizzaWebRequestHelperBean implements PizzaWebRequestHelperController { + + /** + * Call-stack instance (5 may show BeanELResolver.getValue as caller) + */ + private static final short THREAD_STACK = 5; + + /** + * Serial number + */ + private static final long serialVersionUID = 17_258_793_567_145_701L; + + /** + * Administrative contact controller + */ + @Inject + private PizzaAdminContactWebRequestController adminContactController; + + /** + * Administrative user controller + */ + @Inject + private PizzaAdminCustomerWebRequestController adminCustomerController; + + /** + * Administrative phone controller + */ + @Inject + private PizzaAdminPhoneWebRequestController adminPhoneController; + + /** + * Contact instance + */ + private Contact contact; + + /** + * Contact instance + */ + private Customer customer; + + /** + * General user controller + */ + @Inject + private PizzaCustomerWebSessionController customerController; + + /** + * Fax number + */ + private DialableFaxNumber faxNumber; + + /** + * Land-line number + */ + private DialableLandLineNumber landLineNumber; + + /** + * Mobile number + */ + private DialableMobileNumber mobileNumber; + + /** + * User instance + */ + private User user; + + /** + * Regular user controller + */ + @Inject + private PizzaUserWebSessionController userController; + + /** + * Default constructor + */ + public PizzaWebRequestHelperBean () { + // 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)); + } + + @Override + public void copyContactToController () { + // Validate user instance + if (this.getContact() == null) { + // Throw NPE + throw new NullPointerException("this.contact is null"); //NOI18N + } else if (this.getContact().getContactId() == null) { + // Throw NPE again + throw new NullPointerException("this.contact.contactId is null"); //NOI18N + } else if (this.getContact().getContactId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N + } + + // Set all phone instances + this.setPhoneInstances(this.getContact()); + + // Set all fields: user + this.adminContactController.copyContactToController(this.getContact()); + } + + @Override + public void copyCustomerToController () { + // Validate user instance + if (this.getCustomer() == null) { + // Throw NPE + throw new NullPointerException("this.customer is null"); //NOI18N + } else if (this.getCustomer().getCustomerId() == null) { + // Throw NPE again + throw new NullPointerException("this.customer.customerId is null"); //NOI18N + } else if (this.getCustomer().getCustomerId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("this.customer.customerId={0} is not valid.", this.getCustomer().getCustomerId())); //NOI18N + } + + // Set all fields: user + this.adminCustomerController.copyCustomerToController(this.getCustomer()); + } + + @Override + public void copyFaxNumberToController () { + // Validate fax instance + if (this.getFaxNumber() == null) { + // Throw NPE + throw new NullPointerException("this.faxNumber is null"); + } else if (this.getFaxNumber().getPhoneId() == null) { + // Throw again + throw new NullPointerException("this.faxNumber.phoneId is null"); + } else if (this.getFaxNumber().getPhoneId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneId={0} is not valid", this.getFaxNumber().getPhoneId())); + } else if (this.getFaxNumber().getPhoneAreaCode() == null) { + // Throw again + throw new NullPointerException("this.faxNumber.phoneAreaCode is null"); + } else if (this.getFaxNumber().getPhoneAreaCode() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); + } else if (this.getFaxNumber().getPhoneCountry() == null) { + // Throw NPE again + throw new NullPointerException("this.faxNumber.phoneCountry is null"); + } else if (this.getFaxNumber().getPhoneCountry().getCountryId() == null) { + // ... throw again + throw new NullPointerException("this.faxNumber.phoneCountry.countryId is null"); + } else if (this.getFaxNumber().getPhoneCountry().getCountryId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneCountry.countryId={0} is invalid", this.getFaxNumber().getPhoneCountry().getCountryId())); + } else if (this.getFaxNumber().getPhoneNumber() == null) { + // Throw NPE again ... + throw new NullPointerException("this.faxNumber.phoneNumber is null"); + } else if (this.getFaxNumber().getPhoneNumber() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneNumber={0} is not valid", this.getFaxNumber().getPhoneNumber())); + } + + // Copy all (changeable) data fields to admin controller + this.adminPhoneController.setPhoneAreaCode(this.getFaxNumber().getPhoneAreaCode()); + this.adminPhoneController.setPhoneCountry(this.getFaxNumber().getPhoneCountry()); + this.adminPhoneController.setPhoneNumber(this.getFaxNumber().getPhoneNumber()); + } + + @Override + public void copyLandLineNumberToController () { + // Validate land-line instance + if (this.getLandLineNumber() == null) { + // Throw NPE + throw new NullPointerException("this.landLineNumber is null"); + } else if (this.getLandLineNumber().getPhoneId() == null) { + // Throw again + throw new NullPointerException("this.landLineNumber.phoneId is null"); + } else if (this.getLandLineNumber().getPhoneId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneId={0} is not valid", this.getLandLineNumber().getPhoneId())); + } else if (this.getLandLineNumber().getPhoneAreaCode() == null) { + // Throw again + throw new NullPointerException("this.landLineNumber.phoneAreaCode is null"); + } else if (this.getLandLineNumber().getPhoneAreaCode() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); + } else if (this.getLandLineNumber().getPhoneCountry() == null) { + // Throw NPE again + throw new NullPointerException("this.landLineNumber.phoneCountry is null"); + } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() == null) { + // ... throw again + throw new NullPointerException("this.landLineNumber.phoneCountry.countryId is null"); + } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneCountry.countryId={0} is invalid", this.getLandLineNumber().getPhoneCountry().getCountryId())); + } else if (this.getLandLineNumber().getPhoneNumber() == null) { + // Throw NPE again ... + throw new NullPointerException("this.landLineNumber.phoneNumber is null"); + } else if (this.getLandLineNumber().getPhoneNumber() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneNumber={0} is not valid", this.getLandLineNumber().getPhoneNumber())); + } + + // Copy all (changeable) data fields to admin controller + this.adminPhoneController.setPhoneAreaCode(this.getLandLineNumber().getPhoneAreaCode()); + this.adminPhoneController.setPhoneCountry(this.getLandLineNumber().getPhoneCountry()); + this.adminPhoneController.setPhoneNumber(this.getLandLineNumber().getPhoneNumber()); + } + + @Override + public void copyMobileNumberToController () { + // Validate mobile instance + if (this.getMobileNumber() == null) { + // Throw NPE + throw new NullPointerException("this.mobileNumber is null"); + } else if (this.getMobileNumber().getPhoneId() == null) { + // Throw again + throw new NullPointerException("this.mobileNumber.phoneId is null"); + } else if (this.getMobileNumber().getPhoneId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneId={0} is not valid", this.getMobileNumber().getPhoneId())); + } else if (this.getMobileNumber().getMobileProvider() == null) { + // Throw NPE again + throw new NullPointerException("this.mobileNumber.mobileProvider is null"); + } else if (this.getMobileNumber().getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("this.mobileNumber.mobileProvider.providerId is null"); + } else if (this.getMobileNumber().getMobileProvider().getProviderId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileProvider.providerId={0} is invalid", this.getMobileNumber().getMobileProvider().getProviderId())); + } else if (this.getMobileNumber().getPhoneNumber() == null) { + // Throw NPE again ... + throw new NullPointerException("this.mobileNumber.phoneNumber is null"); + } else if (this.getMobileNumber().getPhoneNumber() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneNumber={0} is not valid", this.getMobileNumber().getPhoneNumber())); + } + + // Copy all (changeable) data fields to admin controller + this.adminPhoneController.setMobileProvider(this.getMobileNumber().getMobileProvider()); + this.adminPhoneController.setPhoneNumber(this.getMobileNumber().getPhoneNumber()); + } + + @Override + public void copyUserToController () { + // Validate user instance + if (this.getUser() == null) { + // Throw NPE + throw new NullPointerException("this.user is null"); //NOI18N + } else if (this.getUser().getUserId() == null) { + // Throw NPE again + throw new NullPointerException("this.user.userId is null"); //NOI18N + } else if (this.getUser().getUserId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N + } + + // Get contact + Contact userContact = this.getUser().getUserContact(); + + // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs. + this.setContact(userContact); + + // Set all phone instances + this.setPhoneInstances(userContact); + + // Set all fields: user + this.userController.setUserName(this.getUser().getUserName()); + } + + @Override + public Contact getContact () { + // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName()); + // System.out.println(MessageFormat.format("{0}: Returning this.contact={1}, caller: {2}", this.getClass().getSimpleName(), this.contact, caller)); + return this.contact; + } + + @Override + 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; + } + + @Override + 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/customer + boolean isUserContact = this.userController.isContactFound(contact); + boolean isCustomerContact = this.customerController.isContactFound(contact); + + // Check user first + if (isUserContact && isCustomerContact) { + // Is both + messageKey = "CONTACT_IS_CUSTOMER_USER"; //NOI18N + } else if (isUserContact) { + // Only user + messageKey = "CONTACT_IS_USER"; //NOI18N + } else if (isCustomerContact) { + // Only customer + messageKey = "CONTACT_IS_CUSTOMER"; //NOI18N + } + + // Return message key + return messageKey; + } + + @Override + public Customer getCustomer () { + return this.customer; + } + + @Override + public void setCustomer (final Customer customer) { + this.customer = customer; + } + + @Override + public DialableFaxNumber getFaxNumber () { + return this.faxNumber; + } + + @Override + public void setFaxNumber (final DialableFaxNumber faxNumber) { + this.faxNumber = faxNumber; + } + + @Override + public DialableLandLineNumber getLandLineNumber () { + return this.landLineNumber; + } + + @Override + public void setLandLineNumber (final DialableLandLineNumber landLineNumber) { + this.landLineNumber = landLineNumber; + } + + @Override + public DialableMobileNumber getMobileNumber () { + return this.mobileNumber; + } + + @Override + public void setMobileNumber (final DialableMobileNumber mobileNumber) { + this.mobileNumber = mobileNumber; + } + + @Override + public User getUser () { + return this.user; + } + + @Override + public void setUser (final User user) { + this.user = user; + } + + /** + * Set's all given contact's phone instances: land-line, cellphone and fax + *

+ * @param contact Contact to set phone instances for + */ + private void setPhoneInstances (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 + } + + // Is cellphone set? + if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { + // Yes, then set it in admin controller + this.adminPhoneController.setMobileNumber(contact.getContactMobileNumber()); + } + + // Is land-line set? + if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { + // Yes, then set it in admin controller + this.adminPhoneController.setLandLineNumber(contact.getContactLandLineNumber()); + } + + // Is fax set? + if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { + // Yes, then set it in admin controller + this.adminPhoneController.setFaxNumber(contact.getContactFaxNumber()); + } + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperController.java similarity index 60% rename from src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestController.java rename to src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperController.java index dffcfe4b..e8f4ad0b 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaWebRequestHelperController.java @@ -19,6 +19,9 @@ package org.mxchange.pizzaapplication.beans.helper; import java.io.Serializable; import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcustomercore.model.customer.Customer; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; import org.mxchange.jusercore.model.user.User; /** @@ -26,7 +29,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface PizzaWebRequestController extends Serializable { +public interface PizzaWebRequestHelperController extends Serializable { /** * Getter for user instance @@ -95,4 +98,61 @@ public interface PizzaWebRequestController extends Serializable { */ void copyCustomerToController (); + /** + * Copies currently set fax number's data to admin phone controller + */ + void copyFaxNumberToController (); + + /** + * Copies currently set land-line number's data to admin phone controller + */ + void copyLandLineNumberToController (); + + /** + * Copies currently set mobile number's data to admin phone controller + */ + void copyMobileNumberToController (); + + /** + * Getter for dialable mobile number + *

+ * @return Dialable mobile number + */ + DialableMobileNumber getMobileNumber (); + + /** + * Setter for dialable mobile number + *

+ * @param mobileNumber Dialable mobile number + */ + void setMobileNumber (final DialableMobileNumber mobileNumber); + + /** + * Getter for dialable land-line number + *

+ * @return Dialable land-line number + */ + DialableLandLineNumber getLandLineNumber (); + + /** + * Setter for dialable land-line number + *

+ * @param landLine Dialable land-line number + */ + void setLandLineNumber (final DialableLandLineNumber landLine); + + /** + * Getter for dialable fax number + *

+ * @return Dialable fax number + */ + DialableFaxNumber getFaxNumber (); + + /** + * Setter for dialable fax number + *

+ * @param faxNumber Dialable fax number + */ + void setFaxNumber (final DialableFaxNumber faxNumber); + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java index 0d17007c..0daa95fc 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionBean.java @@ -49,7 +49,11 @@ public class PizzaLocalizationSessionBean extends BasePizzaController implements */ private Locale locale; - @Override + /** + * Event observer for logged-in user + *

+ * @param event Event instance + */ public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) { // event should not be null if (null == event) { @@ -73,7 +77,11 @@ public class PizzaLocalizationSessionBean extends BasePizzaController implements } } - @Override + /** + * Event observer for logged-out user + *

+ * @param event Event instance + */ public void afterUserLogoutEvent (@Observes final ObservableUserLogoutEvent event) { // event should not be null if (null == event) { diff --git a/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionController.java index 60831384..03a7de73 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/localization/PizzaLocalizationSessionController.java @@ -18,8 +18,6 @@ package org.mxchange.pizzaapplication.beans.localization; import java.io.Serializable; import java.util.Locale; -import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent; -import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent; /** * An interface for localization change beans @@ -28,20 +26,6 @@ import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent; */ public interface PizzaLocalizationSessionController extends Serializable { - /** - * Event observer for logged-in user - *

- * @param event Event instance - */ - void afterUserLoginEvent (final ObservableUserLoggedInEvent event); - - /** - * Event observer for logged-out user - *

- * @param event Event instance - */ - void afterUserLogoutEvent (final ObservableUserLogoutEvent event); - /** * Getter for locale *

diff --git a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java index 31046265..87151350 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionBean.java @@ -33,8 +33,11 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jusercore.container.login.LoginContainer; import org.mxchange.jusercore.container.login.UserLoginContainer; +import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; +import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent; import org.mxchange.jusercore.events.logout.UserLogoutEvent; +import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.jusercore.exceptions.UserStatusLockedException; @@ -48,9 +51,6 @@ import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; -import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent; -import org.mxchange.jusercore.events.logout.ObservableUserLogoutEvent; -import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent; /** * A web bean for user registration @@ -64,12 +64,12 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements /** * Path name for guest base template */ - private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest"; //NOI18N + private static final String GUEST_BASE_TEMPLATE_NAME = "guest/guest"; /** * Path name for logged-in user base template */ - private static final String USER_BASE_TEMPLATE_NAME = "login/user/user"; //NOI18N + private static final String USER_BASE_TEMPLATE_NAME = "login/user/user"; /** * Serial number @@ -83,14 +83,21 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements private String baseTemplatePathName; /** - * Current password + * Logged-in user instance */ - private String currentPassword; + private User loggedInUser; /** - * Logged-in user instance + * Remote register session bean */ - private User loggedInUser; + private UserLoginSessionBeanRemote loginBean; + + /** + * Event fired when user has logged in + */ + @Inject + @Any + private Event loginEvent; /** * User controller @@ -99,14 +106,14 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements private PizzaUserWebSessionController userController; /** - * Flag whether the user has logged-in, set only from inside + * Current password */ - private boolean userLoggedIn; + private String userCurrentPassword; /** - * EJB for user-login + * Flag whether the user has logged-in, set only from inside */ - private UserLoginSessionBeanRemote userLoginBean; + private boolean userLoggedIn; /** * Event fired when user has logged in @@ -141,10 +148,10 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements Context context = new InitialContext(); // Try to lookup - this.userLoginBean = (UserLoginSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/login!org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote"); //NOI18N + this.loginBean = (UserLoginSessionBeanRemote) context.lookup("java:global/jjobs-ejb/login!org.mxchange.jusercore.model.login.UserLoginSessionBeanRemote"); //NOI18N // Also find this - this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote"); //NOI18N + this.userPasswordHistoryBean = (UserPasswordHistorySessionBeanRemote) context.lookup("java:global/jjobs-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote"); //NOI18N // Defaul template is guest this.baseTemplatePathName = GUEST_BASE_TEMPLATE_NAME; @@ -154,7 +161,12 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements } } - @Override + /** + * Method being call after user's password has been updated (and history + * entry has been created). + *

+ * @param event Event being observed + */ public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) { // Check parameter if (null == event) { @@ -203,7 +215,7 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements try { // Call bean - User confirmedUser = this.userLoginBean.validateUserAccountStatus(container); + User confirmedUser = this.loginBean.validateUserAccountStatus(container); // All fine here so set it here this.setLoggedInUser(confirmedUser); @@ -221,20 +233,38 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements this.clear(); // All fine - return "login"; //NOI18N - } catch (final UserNotFoundException | UserStatusLockedException | UserStatusUnconfirmedException ex) { + return "login_user"; //NOI18N + } catch (final UserNotFoundException ex) { // Show JSF message - this.showFacesMessage("form_user_login:userName", ex); //NOI18N + this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND"); //NOI18N + return ""; //NOI18N + } catch (final UserStatusLockedException ex) { + this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED"); //NOI18N + return ""; //NOI18N + } catch (final UserStatusUnconfirmedException ex) { + this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED"); //NOI18N return ""; //NOI18N } catch (final UserPasswordMismatchException ex) { // Show JSF message - this.showFacesMessage("form_user_login:userPassword", ex); //NOI18N + this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH"); //NOI18N return ""; //NOI18N } } @Override public String doUserLogout () { + // Is loggedInUser set? + if (this.getLoggedInUser() == null) { + // Throw NPE + throw new NullPointerException("this.loggedInUser is null"); //NOI18N + } else if (this.getLoggedInUser().getUserId() == null) { + // Throw again + throw new NullPointerException("this.loggedInUser.userId is null"); //NOI18N + } else if (this.getLoggedInUser().getUserId() < 1) { + // Invalid user id + throw new IllegalStateException(MessageFormat.format("this.loggedInUser.userId={0} is not valid.", this.getLoggedInUser().getUserId())); //NOI18N + } + // Fire event this.userLogoutEvent.fire(new UserLogoutEvent(this.getLoggedInUser())); @@ -243,9 +273,10 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements // Unset any user instances this.setLoggedInUser(null); + this.setBaseTemplatePathName(GUEST_BASE_TEMPLATE_NAME); //NOI18N // Redirect to index - return "index?faces-redirect=true"; //NOI18N + return "index"; //NOI18N } @Override @@ -259,23 +290,23 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements } @Override - public String getCurrentPassword () { - return this.currentPassword; + public User getLoggedInUser () { + return this.loggedInUser; } @Override - public void setCurrentPassword (final String currentPassword) { - this.currentPassword = currentPassword; + public void setLoggedInUser (final User loggedInUser) { + this.loggedInUser = loggedInUser; } @Override - public User getLoggedInUser () { - return this.loggedInUser; + public String getUserCurrentPassword () { + return this.userCurrentPassword; } @Override - public void setLoggedInUser (final User loggedInUser) { - this.loggedInUser = loggedInUser; + public void setUserCurrentPassword (final String userCurrentPassword) { + this.userCurrentPassword = userCurrentPassword; } @Override @@ -286,16 +317,16 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements @Override public boolean ifCurrentPasswordMatches () { // The current password must be set and not empty - if (this.getCurrentPassword() == null) { + if (this.getUserCurrentPassword() == null) { // Is not set - throw new NullPointerException("this.currentPassword is null"); //NOI18N - } else if (this.getCurrentPassword().isEmpty()) { + throw new NullPointerException("this.userCurrentPassword is null"); //NOI18N + } else if (this.getUserCurrentPassword().isEmpty()) { // Is set empty - throw new IllegalStateException("this.currentPassword is empty."); //NOI18N + throw new IllegalStateException("this.userCurrentPassword is empty."); //NOI18N } // Create "container" - LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getCurrentPassword()); + LoginContainer container = new UserLoginContainer(this.getLoggedInUser(), this.getUserCurrentPassword()); // Now check if it matches return UserUtils.ifPasswordMatches(container, this.getLoggedInUser()); @@ -303,7 +334,7 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements @Override public boolean ifUserMustChangePassword () { - return (this.isUserLoggedIn() && this.getLoggedInUser().getUserMustChangePassword()); + return ((this.isUserLoggedIn()) && (Objects.equals(this.getLoggedInUser().getUserMustChangePassword(), Boolean.TRUE))); } @Override @@ -315,7 +346,7 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements } // Check logged-in first, then invisibility - return this.getLoggedInUser().getUserProfileMode().equals(ProfileMode.INVISIBLE); + return Objects.equals(this.getLoggedInUser().getUserProfileMode(), ProfileMode.INVISIBLE); } @Override @@ -361,7 +392,7 @@ public class PizzaUserLoginWebSessionBean extends BasePizzaController implements */ private void clear () { // Clear all fields - this.setCurrentPassword(null); + this.setUserCurrentPassword(null); } /** diff --git a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java index 09b1c856..4468ecd8 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/login/PizzaUserLoginWebSessionController.java @@ -21,7 +21,6 @@ import java.util.List; import javax.ejb.Local; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.password_history.PasswordHistory; -import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent; /** * An interface for registration web controllers @@ -31,14 +30,6 @@ import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserP @Local public interface PizzaUserLoginWebSessionController extends Serializable { - /** - * Method being call after user's password has been updated (and history - * entry has been created). - *

- * @param event Event being observed - */ - void afterUserUpdatedPasswordEvent (final ObservableUpdatedUserPasswordEvent event); - /** * Checks whether given clear-text password is in user's password history. *

@@ -49,14 +40,14 @@ public interface PizzaUserLoginWebSessionController extends Serializable { boolean isPasswordInHistory (final String userPassword); /** - * Getter for template type + * Getter for base template type *

* @return Template type */ String getBaseTemplatePathName (); /** - * Setter for template type + * Setter for base template type *

* @param baseTemplatePathName Template type */ @@ -122,16 +113,16 @@ public interface PizzaUserLoginWebSessionController extends Serializable { /** * Setter for current password (clear text) *

- * @param currentPassword Current password + * @param userCurrentPassword Current password */ - void setCurrentPassword (final String currentPassword); + void setUserCurrentPassword (final String userCurrentPassword); /** * Getter for current password (clear text) *

* @return Current password */ - String getCurrentPassword (); + String getUserCurrentPassword (); /** * Checks whether the (previously entered) current password matches with diff --git a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java index df08cd82..0b222f1d 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java @@ -72,8 +72,13 @@ public class PizzaMobileProviderWebRequestBean extends BasePizzaController imple } } - @Override - public void afterAdminAddedMobileProvider (@Observes final AdminAddedMobileProviderEvent event) { + /** + * Observes events being fired after the administrator has added a new + * mobile provider + *

+ * @param event Event being fired + */ + public void afterAdminAddedMobileProviderEvent (@Observes final AdminAddedMobileProviderEvent event) { // Is all valid? if (null == event) { // Throw NPE diff --git a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestController.java index d4965e61..c2a8f29b 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestController.java @@ -18,7 +18,6 @@ package org.mxchange.pizzaapplication.beans.mobileprovider; import java.io.Serializable; import java.util.List; -import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; /** @@ -35,12 +34,4 @@ public interface PizzaMobileProviderWebRequestController extends Serializable { */ List allMobileProviders (); - /** - * Observes events being fired after the administrator has added a new - * mobile provider - *

- * @param event Event being fired - */ - void afterAdminAddedMobileProvider (final AdminAddedMobileProviderEvent event); - } diff --git a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminPhoneWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminPhoneWebRequestBean.java index 713beee9..6d22e7bd 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminPhoneWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminPhoneWebRequestBean.java @@ -16,17 +16,44 @@ */ package org.mxchange.pizzaapplication.beans.phone; +import java.text.MessageFormat; +import java.util.List; +import java.util.Objects; import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; import javax.inject.Named; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; -import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote; -import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jcountry.data.Country; +import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent; +import org.mxchange.jphone.events.fax.deleted.AdminFaxNumberDeletedEvent; +import org.mxchange.jphone.events.fax.removed.AdminFaxNumberRemovedFromListEvent; +import org.mxchange.jphone.events.fax.removed.AdminRemoveFaxNumberFromListEvent; +import org.mxchange.jphone.events.fax.updated.AdminFaxNumberUpdatedEvent; +import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent; +import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent; +import org.mxchange.jphone.events.landline.deleted.AdminLandLineNumberDeletedEvent; +import org.mxchange.jphone.events.landline.removed.AdminLandLineNumberRemovedFromListEvent; +import org.mxchange.jphone.events.landline.removed.AdminRemoveLandLineNumberFromListEvent; +import org.mxchange.jphone.events.landline.updated.AdminLandLineNumberUpdatedEvent; +import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent; +import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent; +import org.mxchange.jphone.events.mobile.deleted.AdminMobileNumberDeletedEvent; +import org.mxchange.jphone.events.mobile.remove.AdminMobileNumberRemovedFromListEvent; +import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent; +import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent; +import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent; 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.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote; import org.mxchange.pizzaapplication.beans.BasePizzaController; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; /** * Administrative bean (controller) for phone numbers @@ -37,6 +64,11 @@ import org.mxchange.pizzaapplication.beans.BasePizzaController; @RequestScoped public class PizzaAdminPhoneWebRequestBean extends BasePizzaController implements PizzaAdminPhoneWebRequestController { + /** + * Call-stack position + */ + private static final short THREAD_STACK = 5; + /** * Serial number */ @@ -45,34 +77,134 @@ public class PizzaAdminPhoneWebRequestBean extends BasePizzaController implement /** * Remote EJB for phone number (administrative) */ - private AdminContactsPhoneSessionBeanRemote adminPhoneBean; + private AdminPhoneSessionBeanRemote adminPhoneBean; + + /** + * Bean helper + */ + @Inject + private PizzaWebRequestHelperController beanHelper; + + /** + * Choosen fax number + */ + private DialableFaxNumber choosenFaxNumber; + + /** + * Choosen land-line number + */ + private DialableLandLineNumber choosenLandLineNumber; + + /** + * Choosen mobile number + */ + private DialableMobileNumber choosenMobileNumber; + + /** + * Event being fired when an administrator has deleted fax number + */ + @Inject + @Any + private Event faxNumberDeletedEvent; + + /** + * Event being fired when an administrator has updated fax number + */ + @Inject + @Any + private Event faxNumberUpdatedEvent; + + /** + * Event being fired when an administrator has deleted land-line number + */ + @Inject + @Any + private Event landLineNumberDeletedEvent; + + /** + * Event being fired when an administrator has updated fax number + */ + @Inject + @Any + private Event landLineNumberUpdatedEvent; + + /** + * Event being fired when an administrator has deleted mobile number + */ + @Inject + @Any + private Event mobileNumberDeletedEvent; + + /** + * Event being fired when an administrator has updated land-line number + */ + @Inject + @Any + private Event mobileNumberUpdatedEvent; + + /** + * Mobile provider + */ + private MobileProvider mobileProvider; + + /** + * Area code (city dial prefix) + */ + private Integer phoneAreaCode; + + /** + * Generic hone controller + */ + @Inject + private PizzaPhoneWebApplicationController phoneController; + + /** + * Country (for dial prefix) + */ + private Country phoneCountry; + + /** + * Phone number + */ + private Long phoneNumber; /** - * Cell phone number + * Event being fired when a list of all unsed fax numbers is being created. */ - private DialableMobileNumber cellPhone; + @Inject + @Any + private Event removeLinkedFaxNumbersEvent; /** - * Fax number + * Event being fired when a list of all unsed land-line numbers is being + * created. */ - private DialableFaxNumber fax; + @Inject + @Any + private Event removeLinkedLandLineNumbersEvent; /** - * Land-line number + * Event being fired when a list of all unsed mobile numbers is being + * created. */ - private DialableLandLineNumber landLine; + @Inject + @Any + private Event removeLinkedMobileNumbersEvent; /** * Default constructor */ public PizzaAdminPhoneWebRequestBean () { + // 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)); + // Try it try { // Get initial context Context context = new InitialContext(); // Try to lookup the beans - this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N + this.adminPhoneBean = (AdminPhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminPhone!org.mxchange.jphone.phonenumbers.phone.AdminPhoneSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw it again throw new FaceletException(e); @@ -80,33 +212,426 @@ public class PizzaAdminPhoneWebRequestBean extends BasePizzaController implement } @Override - public DialableMobileNumber getMobileNumber () { - return this.cellPhone; + public List allNonLinkedFaxNumbers () { + // Get list of all mobile numbers + List list = this.phoneController.allFaxNumbers(); + + // Visit all controllers to reduce the list + this.removeLinkedFaxNumbersEvent.fire(new AdminFaxNumberRemovedFromListEvent(list)); + + // Return it + return list; + } + + @Override + public List allNonLinkedLandLineNumbers () { + // Get list of all mobile numbers + List list = this.phoneController.allLandLineNumbers(); + + // Visit all controllers to reduce the list + this.removeLinkedLandLineNumbersEvent.fire(new AdminLandLineNumberRemovedFromListEvent(list)); + + // Return it + return list; + } + + @Override + public List allNonLinkedMobileNumbers () { + // Get list of all mobile numbers + List list = this.phoneController.allMobileNumbers(); + + // Visit all controllers to reduce the list + this.removeLinkedMobileNumbersEvent.fire(new AdminMobileNumberRemovedFromListEvent(list)); + + // Return it + return list; + } + + @Override + public String deleteFaxData (final DialableFaxNumber faxNumber) { + // Is all data set + if (faxNumber == null) { + // Not set, throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } else if (faxNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (faxNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N + } else if (faxNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N + } else if (faxNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N + } + + // Call EJB + this.adminPhoneBean.deleteFaxData(faxNumber); + + // Fire event + this.faxNumberDeletedEvent.fire(new AdminFaxNumberDeletedEvent(faxNumber)); + + // All fine, redirect + return "admin_list_fax"; //NOI18N + } + + @Override + public String deleteLandLineData (final DialableLandLineNumber landLineNumber) { + // Is all data set + if (landLineNumber == null) { + // Not set, throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } else if (landLineNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N + } else if (landLineNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N + } + + // Call EJB + this.adminPhoneBean.deleteLandLineData(landLineNumber); + + // Fire event + this.landLineNumberDeletedEvent.fire(new AdminLandLineNumberDeletedEvent(landLineNumber)); + + // All fine, redirect + return "admin_list_landline"; //NOI18N + } + + @Override + public String deleteMobileData (final DialableMobileNumber mobileNumber) { + // Is all data set + if (mobileNumber == null) { + // Not set, throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N + } else if (mobileNumber.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N + } else if (mobileNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N + } + + // Call EJB + this.adminPhoneBean.deleteMobileData(mobileNumber); + + // Fire event + this.mobileNumberDeletedEvent.fire(new AdminMobileNumberDeletedEvent(mobileNumber)); + + // All fine, redirect + return "admin_list_mobile"; //NOI18N + } + + @Override + public String editFaxData (final DialableFaxNumber faxNumber) { + // Is all data set + if (faxNumber == null) { + // Not set, throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } else if (faxNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (faxNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N + } else if (faxNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N + } else if (faxNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N + } + + // Is the mobile provider and number the same? + if ((Objects.equals(this.getPhoneCountry(), faxNumber.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), faxNumber.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), faxNumber.getPhoneNumber()))) { + // Show message + this.showFacesMessage("form_edit_fax:faxNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N + + // No difference in both together, no need to edit + return ""; //NOI18N + } + + // Set all data + faxNumber.setPhoneCountry(this.getPhoneCountry()); + faxNumber.setPhoneAreaCode(this.getPhoneAreaCode()); + faxNumber.setPhoneNumber(this.getPhoneNumber()); + + // Send to bean + DialableFaxNumber updatedNumber = this.adminPhoneBean.updateFaxData(faxNumber); + + // Fire event + this.faxNumberUpdatedEvent.fire(new AdminFaxNumberUpdatedEvent(updatedNumber)); + + // All fine, redirect + return "admin_show_fax"; //NOI18N + } + + @Override + public String editLandLineData (final DialableLandLineNumber landLineNumber) { + // Is all data set + if (landLineNumber == null) { + // Not set, throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } else if (landLineNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N + } else if (landLineNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N + } + + // Is the mobile provider and number the same? + if ((Objects.equals(this.getPhoneCountry(), landLineNumber.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), landLineNumber.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), landLineNumber.getPhoneNumber()))) { + // Show message + this.showFacesMessage("form_edit_landline:landLineNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N + + // No difference in both together, no need to edit + return ""; //NOI18N + } + + // Set all data + landLineNumber.setPhoneCountry(this.getPhoneCountry()); + landLineNumber.setPhoneAreaCode(this.getPhoneAreaCode()); + landLineNumber.setPhoneNumber(this.getPhoneNumber()); + + // Send to bean + DialableLandLineNumber updatedNumber = this.adminPhoneBean.updateLandLineData(landLineNumber); + + // Fire event + this.landLineNumberUpdatedEvent.fire(new AdminLandLineNumberUpdatedEvent(updatedNumber)); + + // All fine, redirect + return "admin_show_landline"; //NOI18N + } + + @Override + public String editMobileData (final DialableMobileNumber mobileNumber) { + // Is all data set + if (mobileNumber == null) { + // Not set, throw NPE + throw new NullPointerException("mobileNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N + } else if (mobileNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", mobileNumber.getPhoneId())); //NOI18N + } else if (mobileNumber.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N + } else if (mobileNumber.getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", mobileNumber.getMobileProvider().getProviderId())); //NOI18N + } else if (mobileNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N + } else if (mobileNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", mobileNumber.getPhoneNumber())); //NOI18N + } else if (this.getMobileProvider() == null) { + // Not provided + this.showFacesMessage("form_edit_mobile:mobileProvider", "ERROR_ADMIN_NO_MOBILE_PROVIDER_SELECTED"); //NOI18N + return ""; //NOI18N + } else if (this.getMobileProvider().getProviderId() == null) { + // Throw NPE again ... + throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N + } else if (this.getMobileProvider().getProviderId() < 0) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.mobileProvider.providerId={0} is not valid.", this.getMobileProvider().getProviderId())); //NOI18N + } else if (this.getPhoneNumber() == null) { + // Not provided + this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_EMPTY_MOBILE_NUMBER"); //NOI18N + return ""; //NOI18N + } + + // Is the mobile provider and number the same? + if ((Objects.equals(this.getMobileProvider(), mobileNumber.getMobileProvider())) && (Objects.equals(this.getPhoneNumber(), mobileNumber.getPhoneNumber()))) { + // Show message + this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N + + // No difference in both together, no need to edit + return ""; //NOI18N + } + + // Set all data + mobileNumber.setMobileProvider(this.getMobileProvider()); + mobileNumber.setPhoneNumber(this.getPhoneNumber()); + + // Send to bean + DialableMobileNumber updatedNumber = this.adminPhoneBean.updateMobileData(mobileNumber); + + // Fire event + this.mobileNumberUpdatedEvent.fire(new AdminMobileNumberUpdatedEvent(updatedNumber)); + + // All fine, redirect + return "admin_show_mobile"; //NOI18N + } + + @Override + public DialableFaxNumber getChoosenFaxNumber () { + // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName()); + // System.out.println(MessageFormat.format("{0}: Returning this.choosenFaxNumber={1}, caller: {2}", this.getClass().getSimpleName(), this.choosenFaxNumber, caller)); + return this.choosenFaxNumber; + } + + @Override + public void setFaxNumber (final DialableFaxNumber choosenFaxNumber) { + // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName()); + // System.out.println(MessageFormat.format("{0}: Settin choosenFaxNumber={1}, previous: this.choosenFaxNumber={2}, caller: {3}", this.getClass().getSimpleName(), choosenFaxNumber, this.choosenFaxNumber, caller)); + this.choosenFaxNumber = choosenFaxNumber; + } + + @Override + public DialableLandLineNumber getChoosenLandLineNumber () { + return this.choosenLandLineNumber; + } + + @Override + public void setLandLineNumber (final DialableLandLineNumber choosenLandLineNumber) { + this.choosenLandLineNumber = choosenLandLineNumber; + } + + @Override + public DialableMobileNumber getChoosenMobileNumber () { + return this.choosenMobileNumber; + } + + @Override + public void setMobileNumber (final DialableMobileNumber choosenMobileNumber) { + this.choosenMobileNumber = choosenMobileNumber; + } + + @Override + public MobileProvider getMobileProvider () { + return this.mobileProvider; + } + + @Override + public void setMobileProvider (final MobileProvider mobileProvider) { + this.mobileProvider = mobileProvider; + } + + @Override + public Integer getPhoneAreaCode () { + return this.phoneAreaCode; } @Override - public void setMobileNumber (final DialableMobileNumber cellPhone) { - this.cellPhone = cellPhone; + public void setPhoneAreaCode (final Integer phoneAreaCode) { + this.phoneAreaCode = phoneAreaCode; } @Override - public DialableFaxNumber getFaxNumber () { - return this.fax; + public Country getPhoneCountry () { + return this.phoneCountry; } @Override - public void setFaxNumber (final DialableFaxNumber fax) { - this.fax = fax; + public void setPhoneCountry (final Country phoneCountry) { + this.phoneCountry = phoneCountry; } @Override - public DialableLandLineNumber getLandLineNumber () { - return this.landLine; + public Long getPhoneNumber () { + return this.phoneNumber; } @Override - public void setLandLineNumber (final DialableLandLineNumber landLine) { - this.landLine = landLine; + public void setPhoneNumber (final Long phoneNumber) { + this.phoneNumber = phoneNumber; } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminPhoneWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminPhoneWebRequestController.java index 21de51cc..adbd7420 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminPhoneWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaAdminPhoneWebRequestController.java @@ -17,10 +17,13 @@ package org.mxchange.pizzaapplication.beans.phone; import java.io.Serializable; +import java.util.List; import javax.ejb.Local; +import org.mxchange.jcountry.data.Country; 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.phonenumbers.mobileprovider.MobileProvider; /** * An interface for a request web controller (bean) for administrative phone @@ -32,45 +35,176 @@ import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; public interface PizzaAdminPhoneWebRequestController extends Serializable { /** - * Getter for dialable mobile number instance + * Returns a list of all unused ("non-linked") mobile numbers *

- * @return Dialable mobile number instance + * @return List with all unused mobile numbers */ - DialableMobileNumber getMobileNumber (); + List allNonLinkedMobileNumbers (); /** - * Setter for dialable land-line number instance + * Returns a list of all unused ("non-linked") land-line numbers *

- * @param landLine Dialable land-line number instance + * @return List with all unused land-line numbers */ - void setLandLineNumber (final DialableLandLineNumber landLine); + List allNonLinkedFaxNumbers (); /** - * Getter for dialable land-line number instance + * Returns a list of all unused ("non-linked") land-line numbers *

- * @return Dialable land-line number instance + * @return List with all unused land-line numbers */ - DialableLandLineNumber getLandLineNumber (); + List allNonLinkedLandLineNumbers (); /** - * Setter for dialable fax number instance + * Deletes given fax entry data *

- * @param fax Dialable fax number instance + * @param faxNumber Fax number to delete + *

+ * @return Redirect outcome + */ + String deleteFaxData (final DialableFaxNumber faxNumber); + + /** + * Changes fax entry data + *

+ * @param faxNumber Fax number to change data + *

+ * @return Redirect outcome + */ + String editFaxData (final DialableFaxNumber faxNumber); + + /** + * Deletes given land-line entry data + *

+ * @param landLineNumber Land-line number to delete + *

+ * @return Redirect outcome + */ + String deleteLandLineData (final DialableLandLineNumber landLineNumber); + + /** + * Changes land-line entry data + *

+ * @param landLineNumber Land-line number to change data + *

+ * @return Redirect outcome + */ + String editLandLineData (final DialableLandLineNumber landLineNumber); + + /** + * Deletes given mobile entry data + *

+ * @param mobileNumber Mobile number to delete + *

+ * @return Redirect outcome + */ + String deleteMobileData (final DialableMobileNumber mobileNumber); + + /** + * Changes mobile entry data + *

+ * @param mobileNumber Mobile number to change data + *

+ * @return Redirect outcome + */ + String editMobileData (final DialableMobileNumber mobileNumber); + + /** + * Getter for mobile provider + *

+ * @return Mobile provider + */ + MobileProvider getMobileProvider (); + + /** + * Setter for mobile provider + *

+ * @param mobileProvider Mobile provider + */ + void setMobileProvider (final MobileProvider mobileProvider); + + /** + * Getter for choosen fax number + *

+ * @return Choosen fax number + */ + DialableFaxNumber getChoosenFaxNumber (); + + /** + * Setter for choosen fax number + *

+ * @param choosenFaxNumber Choosen fax number + */ + void setFaxNumber (final DialableFaxNumber choosenFaxNumber); + + /** + * Getter for choosen land-line number + *

+ * @return Choosen land-line number + */ + DialableLandLineNumber getChoosenLandLineNumber (); + + /** + * Setter for choosen land-line number + *

+ * @param choosenLandLineNumber Choosen land-line number + */ + void setLandLineNumber (final DialableLandLineNumber choosenLandLineNumber); + + /** + * Getter for choosen mobile number + *

+ * @return Choosen mobile number + */ + DialableMobileNumber getChoosenMobileNumber (); + + /** + * Setter for choosen mobile number + *

+ * @param choosenMobileNumber Choosen mobile number + */ + void setMobileNumber (final DialableMobileNumber choosenMobileNumber); + + /** + * Getter for phone area code + *

+ * @return Phone area code + */ + Integer getPhoneAreaCode (); + + /** + * Setter for phone area code + *

+ * @param phoneAreaCode Phone area code + */ + void setPhoneAreaCode (final Integer phoneAreaCode); + + /** + * Getter for phone country (for dial prefix) + *

+ * @return Phone country + */ + Country getPhoneCountry (); + + /** + * Setter for phone country (for dial prefix) + *

+ * @param phoneCountry Phone country */ - void setFaxNumber (final DialableFaxNumber fax); + void setPhoneCountry (final Country phoneCountry); /** - * Getter for dialable fax number instance + * Getter for dial number without prefix *

- * @return Dialable fax number instance + * @return Dial number without prefix */ - DialableFaxNumber getFaxNumber (); + Long getPhoneNumber (); /** - * Setter for dialable mobile number instance + * Setter for dial number without prefix *

- * @param mobileNumber Dialable mobile number instance + * @param phoneNumber Dial number without prefix */ - void setMobileNumber (final DialableMobileNumber mobileNumber); + void setPhoneNumber (final Long phoneNumber); } diff --git a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebApplicationBean.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebApplicationBean.java new file mode 100644 index 00000000..76d9e8e9 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebApplicationBean.java @@ -0,0 +1,610 @@ +/* + * Copyright (C) 2016 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.phone; + +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import javax.annotation.PostConstruct; +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.event.Observes; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcontacts.contact.Contact; +import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent; +import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent; +import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent; +import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent; +import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent; +import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent; +import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent; +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.phonenumbers.phone.PhoneSessionBeanRemote; +import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; +import org.mxchange.pizzaapplication.beans.BasePizzaController; + +/** + * Regular controller (bean) for phone numbers + *

+ * @author Roland Häder + */ +@Named ("phoneController") +@ApplicationScoped +public class PizzaPhoneWebApplicationBean extends BasePizzaController implements PizzaPhoneWebApplicationController { + + /** + * Serial number + */ + private static final long serialVersionUID = 491_058_674_675_690_105L; + + /** + * All fax numbers + */ + private final List faxNumbers; + + /** + * All land-line numbers + */ + private final List landLineNumbers; + + /** + * All mobile numbers + */ + private final List mobileNumbers; + + /** + * General EJB for phone numbers + */ + private PhoneSessionBeanRemote phoneBean; + + /** + * Default constructor + */ + public PizzaPhoneWebApplicationBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup the beans + this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jjobs-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw it again + throw new FaceletException(e); + } + + // Init all lists + this.mobileNumbers = new LinkedList<>(); + this.faxNumbers = new LinkedList<>(); + this.landLineNumbers = new LinkedList<>(); + } + + @Override + public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedContact() == null) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N + } + + // Update contact's mobile, land-line and fax number + this.updateContactPhoneNumbers(event.getAddedContact()); + + // Clear this bean + this.clear(); + } + + @Override + public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + } + + // Update contact's mobile, land-line and fax number + this.updateContactPhoneNumbers(event.getAddedUser().getUserContact()); + + // Clear all data + this.clear(); + } + + @Override + public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getDeletedFaxNumber()== null) { + // Throw NPE again + throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N + } else if (event.getDeletedFaxNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N + } else if (event.getDeletedFaxNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N + } + + // Update contact's mobile, land-line and fax number + this.allFaxNumbers().remove(event.getDeletedFaxNumber()); + + // Clear all data + this.clear(); + } + + @Override + public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getDeletedLandLineNumber()== null) { + // Throw NPE again + throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N + } else if (event.getDeletedLandLineNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N + } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N + } + + // Update contact's mobile, land-line and fax number + this.allLandLineNumbers().remove(event.getDeletedLandLineNumber()); + + // Clear all data + this.clear(); + } + + @Override + public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getDeletedMobileNumber()== null) { + // Throw NPE again + throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N + } else if (event.getDeletedMobileNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.deletedMobileNumber.phoneId is null"); //NOI18N + } else if (event.getDeletedMobileNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getPhoneId())); //NOI18N + } + + // Update contact's mobile, land-line and fax number + this.allMobileNumbers().remove(event.getDeletedMobileNumber()); + + // Clear all data + this.clear(); + } + + @Override + public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) { + // Is the event fine? + if (event == null) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getContact() == null) { + // Throw again ... + throw new NullPointerException("event.contact is null"); + } else if (event.getContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactId is null"); + } else if (event.getContact().getContactId() < 1) { + // Throw again ... + throw new NullPointerException("event.contact.contactId="+ event.getContact().getContactId() + " is invalid"); + } else if (event.getContact().getContactFaxNumber() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactFaxNumber is null"); + } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null"); + } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) { + // Throw again ... + throw new NullPointerException("event.contact.contactFaxNumber.phoneId="+event.getContact().getContactFaxNumber().getPhoneId() + " is invalid"); + } else if (event.getLinkedFaxNumber() == null) { + // Throw again ... + throw new NullPointerException("event.linkedFaxNumer is null"); + } + + // Is the id number in linked number not set? + if (event.getLinkedFaxNumber().getPhoneId() == null) { + // Then it is a new number, so add it from contact as there the id number has been set + this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber()); + } + } + + @Override + public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) { + // Is the event fine? + if (event == null) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getContact() == null) { + // Throw again ... + throw new NullPointerException("event.contact is null"); + } else if (event.getContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactId is null"); + } else if (event.getContact().getContactId() < 1) { + // Throw again ... + throw new NullPointerException("event.contact.contactId="+ event.getContact().getContactId() + " is invalid"); + } else if (event.getContact().getContactLandLineNumber() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactLandLineNumber is null"); + } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null"); + } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) { + // Throw again ... + throw new NullPointerException("event.contact.contactLandLineNumber.phoneId="+event.getContact().getContactLandLineNumber().getPhoneId() + " is invalid"); + } else if (event.getLinkedLandLineNumber() == null) { + // Throw again ... + throw new NullPointerException("event.linkedLandLineNumer is null"); + } + + // Is the id number in linked number not set? + if (event.getLinkedLandLineNumber().getPhoneId() == null) { + // Then it is a new number, so add it from contact as there the id number has been set + this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber()); + } + } + + @Override + public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) { + // Is the event fine? + if (event == null) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getContact() == null) { + // Throw again ... + throw new NullPointerException("event.contact is null"); + } else if (event.getContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactId is null"); + } else if (event.getContact().getContactId() < 1) { + // Throw again ... + throw new NullPointerException("event.contact.contactId="+ event.getContact().getContactId() + " is invalid"); + } else if (event.getContact().getContactMobileNumber() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactMobileNumber is null"); + } else if (event.getContact().getContactMobileNumber().getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("event.contact.contactMobileNumber.phoneId is null"); + } else if (event.getContact().getContactMobileNumber().getPhoneId() < 1) { + // Throw again ... + throw new NullPointerException("event.contact.contactMobileNumber.phoneId="+event.getContact().getContactMobileNumber().getPhoneId() + " is invalid"); + } else if (event.getLinkedMobileNumber() == null) { + // Throw again ... + throw new NullPointerException("event.linkedMobileNumer is null"); + } + + // Is the id number in linked number not set? + if (event.getLinkedMobileNumber().getPhoneId() == null) { + // Then it is a new number, so add it from contact as there the id number has been set + this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber()); + } + } + + @Override + public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedContact() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedContact is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N + } + + // Update contact's mobile, land-line and fax number + this.updateContactPhoneNumbers(event.getUpdatedContact()); + + // Clear all data + this.clear(); + } + + @Override + public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedFaxNumber()== null) { + // Throw NPE again + throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N + } else if (event.getUpdatedFaxNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N + } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N + } + + // Uniquely add it + this.uniqueAddFaxNumber(event.getUpdatedFaxNumber()); + + // Clear it + this.clear(); + } + + @Override + public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedLandLineNumber()== null) { + // Throw NPE again + throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N + } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N + } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N + } + + // Uniquely add it + this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber()); + + // Clear it + this.clear(); + } + + @Override + public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedMobileNumber()== null) { + // Throw NPE again + throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N + } else if (event.getUpdatedMobileNumber().getPhoneId() == null) { + // userId is null + throw new NullPointerException("event.updatedMobileNumber.phoneId is null"); //NOI18N + } else if (event.getUpdatedMobileNumber().getPhoneId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getPhoneId())); //NOI18N + } + + // Uniquely add it + this.uniqueAddMobileNumber(event.getUpdatedMobileNumber()); + + // Clear it + this.clear(); + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List allFaxNumbers () { + return this.faxNumbers; + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List allLandLineNumbers () { + return this.landLineNumbers; + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List allMobileNumbers () { + return this.mobileNumbers; + } + + /** + * Post-construction method + */ + @PostConstruct + public void init () { + // All phone numbers + this.allMobileNumbers().addAll(this.phoneBean.allMobileNumbers()); + this.allFaxNumbers().addAll(this.phoneBean.allFaxNumbers()); + this.allLandLineNumbers().addAll(this.phoneBean.allLandLineNumbers()); + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all data + } + + /** + * Uniquely add given fax number to this bean's list. First remove the old + * instance (by id number), then re-add it again. + *

+ * @param faxNumber number to add + */ + private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) { + // Make sure the parameter is valid + if (null == faxNumber) { + // Throw NPE + throw new NullPointerException("faxNumber is null"); + } else if (faxNumber.getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("faxNumber.phoneId is null"); + } else if (faxNumber.getPhoneId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId())); + } + + // First remove it + if (!this.allFaxNumbers().remove(faxNumber)) { + // Did not work, try by id number + for (final DialableFaxNumber fax : this.allFaxNumbers()) { + // Is id number the same? + if (Objects.equals(fax.getPhoneId(), faxNumber.getPhoneId())) { + // Found it + this.allFaxNumbers().remove(fax); + break; + } + } + } + + // ... then add it + this.allFaxNumbers().add(faxNumber); + } + + /** + * Uniquely add given land-line number to this bean's list. First remove the + * old instance (by id number), then re-add it again. + *

+ * @param landLineNumber Land-line number to add + */ + private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) { + // Make sure the parameter is valid + if (null == landLineNumber) { + // Throw NPE + throw new NullPointerException("landLineNumber is null"); + } else if (landLineNumber.getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("landLineNumber.phoneId is null"); + } else if (landLineNumber.getPhoneId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId())); + } + + // First remove it + if (!this.allLandLineNumbers().remove(landLineNumber)) { + // Did not work, try by id number + for (final DialableLandLineNumber landLine : this.allLandLineNumbers()) { + // Is id number the same? + if (Objects.equals(landLine.getPhoneId(), landLineNumber.getPhoneId())) { + // Found it + this.allLandLineNumbers().remove(landLine); + break; + } + } + } + + // ... then add it + this.allLandLineNumbers().add(landLineNumber); + } + + /** + * Uniquely add given mobile number to this bean's list. First remove the + * old instance (by id number), then re-add it again. + *

+ * @param mobileNumber Mobile number to add + */ + private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) { + // Make sure the parameter is valid + if (null == mobileNumber) { + // Throw NPE + throw new NullPointerException("mobileNumber is null"); + } else if (mobileNumber.getPhoneId() == null) { + // Throw again ... + throw new NullPointerException("mobileNumber.phoneId is null"); + } else if (mobileNumber.getPhoneId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid.", mobileNumber.getPhoneId())); + } + + // First remove it by object + if (!this.allMobileNumbers().remove(mobileNumber)) { + // Did not work, try by id number + for (final DialableMobileNumber cell : this.allMobileNumbers()) { + // Is id number the same? + if (Objects.equals(cell.getPhoneId(), mobileNumber.getPhoneId())) { + // Found it + this.allMobileNumbers().remove(cell); + break; + } + } + } + + // ... then add it + this.allMobileNumbers().add(mobileNumber); + } + + /** + * Updates given contact's mobile, land-line and fax number + *

+ * @param contact Contact instance + */ + private void updateContactPhoneNumbers (final Contact contact) { + // Parameter must be valid + if (null == contact) { + // Throw NPE + throw new NullPointerException("contact is null"); + } else if (contact.getContactId() == null) { + // Throw again + throw new NullPointerException("contact.contactId is null"); + } else if (contact.getContactId() < 1) { + // Id number is not valid + } + + // Is mobile set? + if (contact.getContactMobileNumber() instanceof DialableMobileNumber) { + // Unique-add it + this.uniqueAddMobileNumber(contact.getContactMobileNumber()); + } + + // Is land-line set? + if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) { + // Unique-add it + this.uniqueAddLandLineNumber(contact.getContactLandLineNumber()); + } + + // Is fax set? + if (contact.getContactFaxNumber() instanceof DialableFaxNumber) { + // Unique-add it + this.uniqueAddFaxNumber(contact.getContactFaxNumber()); + } + } + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebApplicationController.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebApplicationController.java new file mode 100644 index 00000000..1e3bc02e --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebApplicationController.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2016 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.pizzaapplication.beans.phone; + +import java.io.Serializable; +import java.util.List; +import javax.ejb.Local; +import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent; +import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent; +import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent; +import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent; +import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent; +import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; +import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent; +import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent; +import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent; + +/** + * An interface for a request web controller (bean) for administrative phone + * number purposes. + *

+ * @author Roland Häder + */ +@Local +public interface PizzaPhoneWebApplicationController extends Serializable { + + /** + * Event observer for newly added users by adminstrator + *

+ * @param event Event being fired + */ + void afterAdminAddedUserEvent (final ObservableAdminAddedUserEvent event); + + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + void afterAdminAddedContactEvent (final ObservableAdminAddedContactEvent event); + + /** + * Observes events being fired when an administrator has deleted a fax + * number + *

+ * @param event Event being fired + */ + void afterAdminDeletedFaxNumberEvent (final AdminDeletedFaxNumberEvent event); + + /** + * Observes events being fired when an administrator has deleted a land-line + * number + *

+ * @param event Event being fired + */ + void afterAdminDeletedLandLineNumberEvent (final AdminDeletedLandLineNumberEvent event); + + /** + * Observes events being fired when an administrator has deleted a mobile + * number + *

+ * @param event Event being fired + */ + void afterAdminDeletedMobileNumberEvent (final AdminDeletedMobileNumberEvent event); + + /** + * Observes events being fired when an administrator has a linked a fax + * number + *

+ * @param event Event being fired + */ + void afterAdminLinkedFaxNumberEvent (final ObservableAdminLinkedFaxNumberEvent event); + + /** + * Observes events being fired when an administrator has a linked a + * land-line number + *

+ * @param event Event being fired + */ + void afterAdminLinkedLandLineNumberEvent (final ObservableAdminLinkedLandLineNumberEvent event); + + /** + * Observes events being fired when an administrator has a linked a mobile + * number + *

+ * @param event Event being fired + */ + void afterAdminLinkedMobileNumberEvent (final ObservableAdminLinkedMobileNumberEvent event); + + /** + * Observes events being fired when an administrator has updated a fax + * number. + *

+ * @param event Event being fired + */ + void afterAdminUpdatedFaxNumberEvent (final AdminUpdatedFaxNumberEvent event); + + /** + * Observes events being fired when an administrator has updated a land-line + * number. + *

+ * @param event Event being fired + */ + void afterAdminUpdatedLandLineNumberEvent (final AdminUpdatedLandLineNumberEvent event); + + /** + * Observes events being fired when an administrator has updated a mobile + * number. + *

+ * @param event Event being fired + */ + void afterAdminUpdatedMobileNumberEvent (final AdminUpdatedMobileNumberEvent event); + + /** + * Event observer for updated contact data by administrators + *

+ * @param event Updated contact data event + */ + void afterAdminUpdatedContactDataEvent (final ObservableAdminUpdatedContactEvent event); + + /** + * Returns a list of all mobile numbers. For performance reasons, the + * controller (bean) should be application-scoped as from user to user + * nothing changes. And the controller's post-construct method should load + * all numbers and cache it in the controller. + *

+ * @return List of all mobile numbers + */ + List allMobileNumbers (); + + /** + * Returns a list of all fax numbers. For performance reasons, the + * controller (bean) should be application-scoped as from user to user + * nothing changes. And the controller's post-construct method should load + * all numbers and cache it in the controller. + *

+ * @return List of all fax numbers + */ + List allFaxNumbers (); + + /** + * Returns a list of all land-line numbers. For performance reasons, the + * controller (bean) should be application-scoped as from user to user + * nothing changes. And the controller's post-construct method should load + * all numbers and cache it in the controller. + *

+ * @return List of all land-line numbers + */ + List allLandLineNumbers (); + +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/receipt/PizzaReceiptWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/receipt/PizzaReceiptWebSessionBean.java index f02eeb04..1e8582c1 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/receipt/PizzaReceiptWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/receipt/PizzaReceiptWebSessionBean.java @@ -25,7 +25,7 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jshopcore.model.receipt.ReceiptBeanRemote; import org.mxchange.pizzaapplication.beans.BasePizzaController; -import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; /** * Checkout controller @@ -45,7 +45,7 @@ public class PizzaReceiptWebSessionBean extends BasePizzaController implements P * Bean helper instance */ @Inject - private PizzaWebRequestController beanHelper; + private PizzaWebRequestHelperController beanHelper; /** * Remote bean instance diff --git a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java index 59b97c94..a37036b5 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/register/PizzaUserRegisterWebSessionBean.java @@ -77,7 +77,7 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme private PizzaFeaturesWebApplicationController featureController; /** - * Reemote register session bean + * Remote register session bean */ private UserRegistrationSessionBeanRemote registerBean; @@ -221,7 +221,7 @@ public class PizzaUserRegisterWebSessionBean extends BasePizzaController impleme } // Now only redirect to next page as the JSF does it - return "register_page2"; //NOI18N + return "user_register_page2"; //NOI18N } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java index 30a3ca99..ecea11a9 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java @@ -35,8 +35,14 @@ import org.mxchange.jusercore.container.login.UserLoginContainer; import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; +import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent; +import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent; import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent; +import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; +import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent; +import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent; +import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent; import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent; import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent; import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; @@ -56,7 +62,8 @@ import org.mxchange.jusercore.model.user.status.UserAccountStatus; import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController; import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; -import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestController; +import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController; +import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController; /** * Administrative user bean (controller) @@ -91,10 +98,10 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements private final AdminUserSessionBeanRemote adminUserBean; /** - * Bean helper instance + * Bean helper */ @Inject - private PizzaWebRequestController beanHelper; + private PizzaWebRequestHelperController beanHelper; /** * Regular contact controller @@ -102,6 +109,19 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements @Inject private PizzaContactWebSessionController contactController; + /** + * Event being fired when admin has deleted user + */ + @Inject + @Any + private Event deleteUserEvent; + + /** + * Localization controller + */ + @Inject + private PizzaLocalizationSessionController localizationController; + /** * An event fired when the administrator has updated a new user */ @@ -120,6 +140,11 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements @Inject private PizzaUserWebSessionController userController; + /** + * Delete reason + */ + private String userDeleteReason; + /** * An event fired when the administrator has linked a user with existing * contact data. @@ -133,6 +158,13 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements */ private String userLockReason; + /** + * Event being fired when an administrator has locked a user + */ + @Inject + @Any + private Event userLockedEvent; + /** * Flag whether user must change password after login */ @@ -144,15 +176,22 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements private String userName; /** - * User password (unencrypted from web form) + * User password (clear-text from web form) */ private String userPassword; /** - * User password repeated (unencrypted from web form) + * User password repeated (clear-text from web form) */ private String userPasswordRepeat; + /** + * Event being fired when admin unlocks an account + */ + @Inject + @Any + private Event userUnlockedEvent; + /** * Default constructor */ @@ -163,8 +202,8 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements Context context = new InitialContext(); // Try to lookup - this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N - this.adminUserBean = (AdminUserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote"); //NOI18N + this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N + this.adminUserBean = (AdminUserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/adminUser!org.mxchange.jusercore.model.user.AdminUserSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); @@ -173,9 +212,6 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements @Override public String addUser () { - // Create new user instance - User user = new LoginUser(); - // As the form cannot validate the data (required="true"), check it here if (this.getUserName() == null) { // Throw NPE @@ -190,8 +226,8 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements throw new NullPointerException("contactController.gender is null"); //NOI18N } else if (this.contactController.getFirstName() == null) { // ... and again - throw new NullPointerException("contactController.firstName is null"); //NOI18N //NOI18N - } else if (this.contactController.getFirstName().isEmpty()) { + throw new NullPointerException("contactController.firstName is null"); //NOI18N + } else if (this.adminContactController.getFirstName().isEmpty()) { // ... and again throw new IllegalArgumentException("contactController.firstName is empty"); //NOI18N } else if (this.adminContactController.getFamilyName() == null) { @@ -199,27 +235,22 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements throw new NullPointerException("contactController.familyName is null"); //NOI18N } else if (this.contactController.getFamilyName().isEmpty()) { // ... and again - throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N //NOI18N - } else if (this.contactController.getEmailAddress() == null) { + throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N + } else if (this.adminContactController.getEmailAddress() == null) { // ... and again throw new NullPointerException("contactController.emailAddress is null"); //NOI18N } else if (this.adminContactController.getEmailAddress().isEmpty()) { // ... and again - throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N //NOI18N - } else if (this.contactController.getEmailAddressRepeat() == null) { - // ... and again - throw new NullPointerException("contactController.emailAddressRepeat is null"); - } else if (this.contactController.getEmailAddressRepeat().isEmpty()) { - // ... and again - throw new IllegalArgumentException("contactController.emailAddressRepeat is empty"); //NOI18N //NOI18N - } else if (!Objects.equals(this.contactController.getEmailAddress(), this.contactController.getEmailAddressRepeat())) { - // Is not same email address - throw new IllegalArgumentException("Both entered email addresses don't match."); + throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N } } + // Create new user instance + User user = new LoginUser(); + // Set user name, CONFIRMED and INVISIBLE user.setUserName(this.getUserName()); + user.setUserMustChangePassword(this.getUserMustChangePassword()); user.setUserAccountStatus(UserAccountStatus.CONFIRMED); user.setUserProfileMode(ProfileMode.INVISIBLE); @@ -248,7 +279,14 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements throw new FaceletException(new UserNameAlreadyRegisteredException(user)); } else if ((this.beanHelper.getContact() == null) && (this.contactController.isEmailAddressRegistered(user.getUserContact()))) { // Email address is already used - throw new FaceletException(new EmailAddressAlreadyRegisteredException(user)); + this.showFacesMessage("admin_add_user:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N + + // Always clear password + this.setUserPassword(null); + this.setUserPasswordRepeat(null); + + // Skip it + return ""; //NOI18N } else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) { // Empty password entered, then generate one password = UserUtils.createRandomPassword(PizzaUserWebSessionController.MINIMUM_PASSWORD_LENGTH); @@ -290,6 +328,9 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements throw new FaceletException(ex); } + // Clear helper + this.beanHelper.setContact(null); + // Clear this bean this.clear(); @@ -297,8 +338,12 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements return "admin_list_user"; //NOI18N } - @Override - public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) { + /** + * Event observer for new user registrations + *

+ * @param event User registration event + */ + public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -318,11 +363,39 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements User registeredUser = event.getRegisteredUser(); // @TODO Nothing to do with the user here? - // Clear all data this.clear(); } + @Override + public String deleteUserData (final User user) { + // Is the user instance valid and CONFIRMED? + if (null == user) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + // Throw again + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N + } + + try { + // All fine, delete it + this.adminUserBean.deleteUser(user, this.getUserDeleteReason()); + } catch (final UserNotFoundException ex) { + // Should not happen, so throw again + throw new FaceletException(ex); + } + + // Fire event + this.deleteUserEvent.fire(new AdminDeletedUserEvent(user, this.getUserDeleteReason())); + + // Redirect + return "admin_list_user"; //NOI18N + } + @Override public String editUserData () { // Get user instance @@ -337,10 +410,10 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements throw new NullPointerException("beanHelper.user is null"); //NOI18N } else if (user.getUserId() == null) { // Throw NPE again - throw new NullPointerException("beanHelper.user.userId is null"); //NOI18N //NOI18N + throw new NullPointerException("beanHelper.user.userId is null"); //NOI18N } else if (user.getUserId() < 1) { // Invalid id - throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", user.getUserId())); //NOI18N //NOI18N + throw new IllegalStateException(MessageFormat.format("beanHelper.user.userId={0} is invalid", user.getUserId())); //NOI18N } else if (this.getUserName() == null) { // Not all required fields are set throw new NullPointerException("this.userName is null"); //NOI18N @@ -348,20 +421,30 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements // Not all required fields are set throw new IllegalArgumentException("this.userName is empty"); //NOI18N } else if (((!this.getUserPassword().isEmpty()) || (!this.getUserPasswordRepeat().isEmpty())) && (!this.isSamePasswordEntered())) { - // Not same password entered + // Clear password fields this.setUserPassword(null); this.setUserPasswordRepeat(null); - // Throw exception - throw new FaceletException("Not same password entered"); //NOI18N - } else if (this.userBean.ifUserNameExists(this.getUserName())) { + // Not same password entered + this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_PASSWORD_REPEAT_DIFFERENT"); //NOI18N + return ""; //NOI18N + } else if ((!Objects.equals(user.getUserName(), this.getUserName())) && (this.userBean.ifUserNameExists(this.getUserName()))) { + // Clear all fields + this.clear(); + // User name already exists - throw new FaceletException(new UserNameAlreadyRegisteredException(this.getUserName())); + this.showFacesMessage("form_edit_user:userName", "ADMIN_USER_NAME_ALREADY_EXISTS"); //NOI18N + return ""; //NOI18N } else if (this.isSamePasswordEntered()) { // Same password entered, create container - if (UserUtils.ifPasswordMatches(new UserLoginContainer(user, this.getUserPassword()))) { + if ((Objects.equals(user.getUserMustChangePassword(), this.getUserMustChangePassword())) && (UserUtils.ifPasswordMatches(new UserLoginContainer(user, this.getUserPassword())))) { + // Clear password fields + this.setUserPassword(null); + this.setUserPasswordRepeat(null); + // Same password entered - throw new FaceletException("Same password as stored entered."); //NOI18N + this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_ENTERED_SAME_AS_OLD_PASSWORD"); //NOI18N + return ""; //NOI18N } // Encrypt password @@ -388,6 +471,16 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements return "admin_list_user"; //NOI18N } + @Override + public String getUserDeleteReason () { + return this.userDeleteReason; + } + + @Override + public void setUserDeleteReason (final String userDeleteReason) { + this.userDeleteReason = userDeleteReason; + } + @Override public String getUserLockReason () { return this.userLockReason; @@ -464,19 +557,28 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements throw new IllegalArgumentException("this.userLockReason is empty"); //NOI18N } + // Init updated user instance + User updatedUser; + try { // Get base URL String baseUrl = FacesUtils.generateBaseUrl(); // Call EJB to lock account - this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl); + updatedUser = this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl); } catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) { // Throw again throw new FaceletException(ex); } + // Fire event + this.userLockedEvent.fire(new AdminLockedUserEvent(updatedUser)); + + // Clear bean + this.clear(); + // Should go fine at this point, redirect to user profile - return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N + return "admin_show_user"; //NOI18N } @Override @@ -499,19 +601,28 @@ public class PizzaAdminUserWebRequestBean extends BasePizzaController implements throw new FaceletException(new UserStatusUnconfirmedException(user)); } + // Init updated user instance + User updatedUser; + try { // Get base URL String baseUrl = FacesUtils.generateBaseUrl(); // Call EJB to unlock account - this.adminUserBean.unlockUserAccount(user, baseUrl); + updatedUser = this.adminUserBean.unlockUserAccount(user, baseUrl); } catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) { // Throw again throw new FaceletException(ex); } + // Fire event + this.userUnlockedEvent.fire(new AdminUnlockedUserEvent(updatedUser)); + + // Clear bean + this.clear(); + // Should go fine at this point, redirect to user profile - return "admin_show_user?faces-redirect=true&includeViewParams=true"; //NOI18N + return "admin_show_user"; //NOI18N } /** diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java index db6a137d..7fca58bc 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java @@ -18,7 +18,6 @@ package org.mxchange.pizzaapplication.beans.user; import java.io.Serializable; import org.mxchange.jusercore.model.user.User; -import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; /** * An interface for user beans @@ -27,13 +26,6 @@ import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; */ public interface PizzaAdminUserWebRequestController extends Serializable { - /** - * Event observer for new user registrations - *

- * @param event User registration event - */ - void afterRegistrationEvent (final ObservableUserRegisteredEvent event); - /** * Adds user instance to database by preparing a complete user instance and * sending it to the EJB. The data set in the controller is being verified, @@ -43,6 +35,15 @@ public interface PizzaAdminUserWebRequestController extends Serializable { */ String addUser (); + /** + * Deletes given user account + *

+ * @param user User instance to delete + *

+ * @return Redirect outcome + */ + String deleteUserData (final User user); + /** * Edits currently loaded user's data in database. *

@@ -85,30 +86,30 @@ public interface PizzaAdminUserWebRequestController extends Serializable { void setUserName (final String userName); /** - * Getter for unencrypted user password + * Getter for clear-text user password *

- * @return Unencrypted user password + * @return Clear-text user password */ String getUserPassword (); /** - * Setter for unencrypted user password + * Setter for clear-text user password *

- * @param userPassword Unencrypted user password + * @param userPassword Clear-text user password */ void setUserPassword (final String userPassword); /** - * Getter for unencrypted user password repeated + * Getter for clear-text user password repeated *

- * @return Unencrypted user password repeated + * @return Clear-text user password repeated */ String getUserPasswordRepeat (); /** - * Setter for unencrypted user password repeated + * Setter for clear-text user password repeated *

- * @param userPasswordRepeat Unencrypted user password repeated + * @param userPasswordRepeat Clear-text user password repeated */ void setUserPasswordRepeat (final String userPasswordRepeat); @@ -140,4 +141,18 @@ public interface PizzaAdminUserWebRequestController extends Serializable { */ void setUserLockReason (final String userLockReason); + /** + * Getter for user delete reason + *

+ * @return User delete reason + */ + String getUserDeleteReason (); + + /** + * Setter for user delete reason + *

+ * @param userDeleteReason User delete reason + */ + void setUserDeleteReason (final String userDeleteReason); + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java index d5df16c5..2d0cd6f3 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java @@ -33,7 +33,17 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.ContactSessionBeanRemote; +import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent; +import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent; +import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; +import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; +import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent; +import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent; +import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent; +import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent; +import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent; +import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent; +import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent; import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException; import org.mxchange.jusercore.exceptions.UserNotFoundException; @@ -46,15 +56,7 @@ import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.pizzaapplication.beans.BasePizzaController; import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; import org.mxchange.pizzaapplication.beans.features.PizzaFeaturesWebApplicationController; -import org.mxchange.pizzaapplication.beans.localization.PizzaLocalizationSessionController; import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; -import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent; -import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent; -import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; -import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; -import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent; -import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent; -import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent; /** * A user bean (controller) @@ -70,11 +72,6 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz */ private static final long serialVersionUID = 542_145_347_916L; - /** - * Contact EJB - */ - private ContactSessionBeanRemote contactBean; - /** * General contact controller */ @@ -87,12 +84,6 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz @Inject private PizzaFeaturesWebApplicationController featureController; - /** - * Localization controller - */ - @Inject - private PizzaLocalizationSessionController localizationController; - /** * Event being fired when user updated personal data */ @@ -116,7 +107,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz private List userList; /** - * Login bean (controller) + * Login controller (bean) */ @Inject private PizzaUserLoginWebSessionController userLoginController; @@ -132,12 +123,12 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz private List userNameList; /** - * User password (unencrypted from web form) + * User password (clear-text from web form) */ private String userPassword; /** - * User password repeated (unencrypted from web form) + * User password repeated (clear-text from web form) */ private String userPasswordRepeat; @@ -164,21 +155,19 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz Context context = new InitialContext(); // Try to lookup - this.userBean = (UserSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N - - // Try to lookup - this.contactBean = (ContactSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N + this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jrecruiter-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); } } - @Override + /** + * Event observer for newly added users by administrator + *

+ * @param event Event being fired + */ public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminAddedUserEvent: event={0} - CALLED!", event)); //NOI18N - // event should not be null if (null == event) { // Throw NPE @@ -194,105 +183,159 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N } - // Add user uniquely - this.uniqueAddUser(event.getAddedUser()); + // Update user list + this.updateList(event.getAddedUser()); // Clear all data this.clear(); // Set user id again this.setUserId(event.getAddedUser().getUserId()); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminAddedUserEvent: EXIT!"); //NOI18N } - @Override - public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterAdminUpdatedUserEvent: event={0} - CALLED!", event)); //NOI18N - + /** + * Event observer for deleted user accounts (by administrator) + *

+ * @param event Event being fired + */ + public void afterAdminDeletedUserEvent (final ObservableAdminDeletedUserEvent event) { // event should not be null if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getUpdatedUser() == null) { + } else if (event.getDeletedUser() == null) { // Throw NPE again - throw new NullPointerException("event.updatedUser is null"); //NOI18N - } else if (event.getUpdatedUser().getUserId() == null) { + throw new NullPointerException("event.deletedUser is null"); //NOI18N + } else if (event.getDeletedUser().getUserId() == null) { // userId is null - throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N - } else if (event.getUpdatedUser().getUserId() < 1) { + throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N + } else if (event.getDeletedUser().getUserId() < 1) { // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N } - // Update list - this.updateList(event.getUpdatedUser()); + // Update user list + this.removeFromList(event.getDeletedUser()); // Clear all data this.clear(); - - // Trace message - //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterAdminUpdatedUserEvent: EXIT!"); //NOI18N } - @Override - public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: event={0} - CALLED!", event)); //NOI18N - + /** + * Event observer for linked users with existing contact data + *

+ * @param event Event being fired + */ + public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) { // event should not be null if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getRegisteredUser() == null) { + } else if (event.getLinkedUser() == null) { // Throw NPE again - throw new NullPointerException("event.registeredUser is null"); //NOI18N - } else if (event.getRegisteredUser().getUserId() == null) { + throw new NullPointerException("event.linkedUser is null"); //NOI18N + } else if (event.getLinkedUser().getUserId() == null) { // userId is null - throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N - } else if (event.getRegisteredUser().getUserId() < 1) { + throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N + } else if (event.getLinkedUser().getUserId() < 1) { // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N } - // Get user instance - User registeredUser = event.getRegisteredUser(); - - // Debug message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterRegistration: registeredUser={0}", registeredUser)); //NOI18N - - // Copy all data from registered->user - this.copyUser(registeredUser); + // Update user list + this.updateList(event.getLinkedUser()); // Clear all data this.clear(); - // Add user uniquely - this.uniqueAddUser(registeredUser); - - // Add user name - this.addUserName(registeredUser); + // Set user id again + this.setUserId(event.getLinkedUser().getUserId()); + } - // Is the account public? - if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) { - // Also add it to this list - this.visibleUserList.add(registeredUser); + /** + * Event observer for locked users + *

+ * @param event Event being fired + */ + public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLockedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.lockedUser is null"); //NOI18N + } else if (event.getLockedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N + } else if (event.getLockedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N } - // Set user id again - this.setUserId(registeredUser.getUserId()); + // Update user list + this.updateList(event.getLockedUser()); + } - // Trace message - //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N + /** + * Event observer for unlocked users + *

+ * @param event Event being fired + */ + public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUnlockedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.unlockedUser is null"); //NOI18N + } else if (event.getUnlockedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N + } else if (event.getUnlockedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N + } + + // Update user list + this.updateList(event.getUnlockedUser()); } - @Override - public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("ContactWebBean:afterAdminUpdatedContactDataEvent: event={0} - CALLED!", event)); //NOI18N + /** + * Event observer for updated user data by administrator + *

+ * @param event Event being updated + */ + public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedUser is null"); //NOI18N + } else if (event.getUpdatedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N + } else if (event.getUpdatedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N + } + + // Update user list + this.updateList(event.getUpdatedUser()); + + // Clear all data + this.clear(); + } + /** + * Event observer when user confirmed account. + *

+ * @param event Event being fired + */ + public void afterUserConfirmedAccountEvent (@Observes final ObservableUserConfirmedAccountEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -308,15 +351,16 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N } - // Add user uniquely - this.uniqueAddUser(event.getConfirmedUser()); + // Update user list + this.updateList(event.getConfirmedUser()); } - @Override + /** + * Event observer for logged-in user + *

+ * @param event Event instance + */ public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) { - // Trace message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: event={0} - CALLED!", event)); //NOI18N - // event should not be null if (null == event) { // Throw NPE @@ -345,7 +389,58 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz } } - @Override + /** + * Event observer for new user registrations + *

+ * @param event User registration event + */ + public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getRegisteredUser() == null) { + // Throw NPE again + throw new NullPointerException("event.registeredUser is null"); //NOI18N + } else if (event.getRegisteredUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N + } else if (event.getRegisteredUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N + } + + // Get user instance + User registeredUser = event.getRegisteredUser(); + + // Copy all data from registered->user + this.copyUser(registeredUser); + + // Clear all data + this.clear(); + + // Update user list + this.updateList(registeredUser); + + // Add user name + this.addUserName(registeredUser); + + // Is the account public? + if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) { + // Also add it to this list + this.visibleUserList.add(registeredUser); + } + + // Set user id again + this.setUserId(registeredUser.getUserId()); + } + + /** + * Method being call after user's password has been updated (and history + * entry has been created). + *

+ * @param event Event being observed + */ public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) { // Check parameter if (null == event) { @@ -362,12 +457,16 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N } - // All fine, so update list + // Update user list this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser()); } - @Override - public void afterUserUpdatedPersonalData (@Observes final ObservableUpdatedUserPersonalDataEvent event) { + /** + * Listens to fired event when user updated personal data + *

+ * @param event Event being fired + */ + public void afterUserUpdatedPersonalDataEvent (@Observes final ObservableUpdatedUserPersonalDataEvent event) { // Check parameter if (null == event) { // Throw NPE @@ -383,7 +482,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N } - // All fine, so update list + // Update user list this.updateList(event.getUpdatedUser()); } @@ -429,8 +528,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz this.setUserPasswordRepeat(randomPassword); } - // Set local, user name and mode - user.setUserLocale(this.localizationController.getLocale()); + // Set user name and mode user.setUserName(this.getUserName()); user.setUserProfileMode(this.getUserProfileMode()); @@ -492,7 +590,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz } else if (!this.userLoginController.ifCurrentPasswordMatches()) { // Password not matching throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); - } else if (!this.featureController.isFeatureEnabled("edit_user_data")) { + } else if (!this.featureController.isFeatureEnabled("change_user_personal_data")) { // Editing is not allowed throw new IllegalStateException("User tried to edit personal data."); //NOI18N } @@ -521,7 +619,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz this.updatedPersonalDataEvent.fire(new UpdatedUserPersonalDataEvent(updatedUser)); // All fine - return "contact_data_saved"; //NOI18N + return "user_contact_data_saved"; //NOI18N } @Override @@ -701,7 +799,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz @Override public boolean isVisibleUserFound () { - return ((this.visibleUserList instanceof List) && (!this.visibleUserList.isEmpty())); + return ((this.visibleUserList instanceof List) && (this.visibleUserList.size() > 0)); } @Override @@ -729,7 +827,7 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getUserId())); //NOI18N } else if (next.getUserContact().getContactEmailAddress() == null) { // Email address should be set - throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N //NOI18N + throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getUserId())); //NOI18N } // Is the email address found? @@ -844,39 +942,29 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz } /** - * Uniquely adds given user instance to user list. First an existing - * instance will be removed, then the given instance is being added. + * Removes user from all lists *

- * @param user User instance to add + * @param user User to remove */ - private void uniqueAddUser (final User user) { - // Make sure the instance is valid + private void removeFromList (final User user) { + // The user should be valid if (null == user) { // Throw NPE throw new NullPointerException("user is null"); //NOI18N - } else if (user.getUserContact() == null) { - // Throw again ... - throw new NullPointerException("user.userContact is null"); //NOI18N + } else if (user.getUserId() == null) { + // ... again NPE + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N } - // Get iterator from list - Iterator iterator = this.userList.iterator(); - - // "Walk" through all entries - while (iterator.hasNext()) { - // Get next element - User next = iterator.next(); + // Remove it from lists + this.userList.remove(user); + this.visibleUserList.remove(user); - // Is id number the same? - if (Objects.equals(user.getUserId(), next.getUserId())) { - // Found entry, so remove it and abort - this.userList.remove(next); - break; - } - } - - // Add contact to list - this.userList.add(user); + // Remove name from list + this.userNameList.remove(user.getUserName()); } /** @@ -895,25 +983,34 @@ public class PizzaUserWebSessionBean extends BasePizzaController implements Pizz } else if (user.getUserId() < 1) { // Invalid id throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N + } else if (user.getUserContact() == null) { + // Throw again ... + throw new NullPointerException("user.userContact is null"); //NOI18N + } else if (user.getUserContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("user.userContact.contactId is null"); //NOI18N + } else if (user.getUserContact().getContactId() < 1) { + // Throw again ... + throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N } - // Get iterator + // Get iterator from list Iterator iterator = this.userList.iterator(); - // Look whole list + // "Walk" through all entries while (iterator.hasNext()) { // Get next element User next = iterator.next(); - // Is the same user id? + // Is user id number the same? if (Objects.equals(user.getUserId(), next.getUserId())) { - // Found it, so remove it + // Found entry, so remove it and abort this.userList.remove(next); break; } } - // Re-add item + // Re-add user this.userList.add(user); } diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java index 1e09ec69..c2bf77d6 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java @@ -23,13 +23,6 @@ import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; -import org.mxchange.jusercore.events.confirmation.ObservableUserConfirmedAccountEvent; -import org.mxchange.jusercore.events.login.ObservableUserLoggedInEvent; -import org.mxchange.jusercore.events.registration.ObservableUserRegisteredEvent; -import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; -import org.mxchange.jusercore.events.user.password_change.ObservableUpdatedUserPasswordEvent; -import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent; -import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent; /** * An interface for user beans @@ -43,56 +36,6 @@ public interface PizzaUserWebSessionController extends Serializable { */ public static final Integer MINIMUM_PASSWORD_LENGTH = 5; - /** - * Event observer for newly added users by adminstrator - *

- * @param event Event being fired - */ - void afterAdminAddedUserEvent (final ObservableAdminAddedUserEvent event); - - /** - * Event observer for updated user data by administrator - *

- * @param event Event being updated - */ - void afterAdminUpdatedUserDataEvent (final ObservableAdminUpdatedUserDataEvent event); - - /** - * Event observer when user confirmed account. - *

- * @param event Event being fired - */ - void afterUserConfirmedAccount (final ObservableUserConfirmedAccountEvent event); - - /** - * Method being call after user's password has been updated (and history - * entry has been created). - *

- * @param event Event being observed - */ - void afterUserUpdatedPasswordEvent (final ObservableUpdatedUserPasswordEvent event); - - /** - * Listens to fired event when user updated personal data - *

- * @param event Event being fired - */ - void afterUserUpdatedPersonalData (final ObservableUpdatedUserPersonalDataEvent event); - - /** - * Event observer for new user registrations - *

- * @param event User registration event - */ - void afterRegistrationEvent (final ObservableUserRegisteredEvent event); - - /** - * Event observer for logged-in user - *

- * @param event Event instance - */ - void afterUserLoginEvent (final ObservableUserLoggedInEvent event); - /** * All users *

@@ -153,7 +96,8 @@ public interface PizzaUserWebSessionController extends Serializable { *

* @return User instance *

- * @throws UserEmailAddressNotFoundException If the user's email address is not found + * @throws UserEmailAddressNotFoundException If the user's email address is + * not found */ User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException; @@ -202,30 +146,30 @@ public interface PizzaUserWebSessionController extends Serializable { void setUserName (final String userName); /** - * Getter for unencrypted user password + * Getter for clear-text user password *

- * @return Unencrypted user password + * @return Clear-text user password */ String getUserPassword (); /** - * Setter for unencrypted user password + * Setter for clear-text user password *

- * @param userPassword Unencrypted user password + * @param userPassword Clear-text user password */ void setUserPassword (final String userPassword); /** - * Getter for unencrypted user password repeated + * Getter for clear-text user password repeated *

- * @return Unencrypted user password repeated + * @return Clear-text user password repeated */ String getUserPasswordRepeat (); /** - * Setter for unencrypted user password repeated + * Setter for clear-text user password repeated *

- * @param userPasswordRepeat Unencrypted user password repeated + * @param userPasswordRepeat Clear-text user password repeated */ void setUserPasswordRepeat (final String userPasswordRepeat); diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java index 197a49d5..619b91b5 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestBean.java @@ -78,12 +78,12 @@ public class PizzaUserPasswordWebRequestBean extends BasePizzaController impleme private PizzaUserLoginWebSessionController userLoginController; /** - * User password (unencrypted from web form) + * User password (clear-text from web form) */ private String userPassword; /** - * User password repeated (unencrypted from web form) + * User password repeated (clear-text from web form) */ private String userPasswordRepeat; diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestController.java index e38ade0f..b6e1feb8 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/password/PizzaUserPasswordWebRequestController.java @@ -28,44 +28,44 @@ import javax.ejb.Local; public interface PizzaUserPasswordWebRequestController extends Serializable { /** - * Getter for unencrypted user password + * Getter for clear-text user password *

- * @return Unencrypted user password + * @return Clear-text user password */ String getUserPassword (); /** - * Setter for unencrypted user password + * Setter for clear-text user password *

- * @param userPassword Unencrypted user password + * @param userPassword Clear-text user password */ void setUserPassword (final String userPassword); /** - * Getter for current unencrypted user password + * Getter for current clear-text user password *

- * @return Current unencrypted user password + * @return Current clear-text user password */ String getUserCurrentPassword (); /** - * Setter for current unencrypted user password + * Setter for current clear-text user password *

- * @param userCurrentPassword Current unencrypted user password + * @param userCurrentPassword Current clear-text user password */ void setUserCurrentPassword (final String userCurrentPassword); /** - * Getter for unencrypted user password repeated + * Getter for clear-text user password repeated *

- * @return Unencrypted user password repeated + * @return Clear-text user password repeated */ String getUserPasswordRepeat (); /** - * Setter for unencrypted user password repeated + * Setter for clear-text user password repeated *

- * @param userPasswordRepeat Unencrypted user password repeated + * @param userPasswordRepeat Clear-text user password repeated */ void setUserPasswordRepeat (final String userPasswordRepeat); diff --git a/src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java b/src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java index ffd9ef35..d623a329 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java @@ -61,9 +61,6 @@ public class PizzaContactConverter implements Converter { @Override public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N - // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -80,14 +77,8 @@ public class PizzaContactConverter implements Converter { // Try to parse the value as long Long contactId = Long.valueOf(submittedValue); - // Debug message - // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: contactId{0}", contactId)); //NOI18N - // Try to get user instance from it contact = this.contactBean.findContactById(contactId); - - // Debug message - // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: contact={0}", contact)); //NOI18N } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); @@ -96,9 +87,6 @@ public class PizzaContactConverter implements Converter { // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N } - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: contact={0} - EXIT!", contact)); //NOI18N - // Return it return contact; } diff --git a/src/java/org/mxchange/pizzaapplication/converter/country/PizzaCountryConverter.java b/src/java/org/mxchange/pizzaapplication/converter/country/PizzaCountryConverter.java index c5cec811..985bc63d 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/country/PizzaCountryConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/country/PizzaCountryConverter.java @@ -62,9 +62,6 @@ public class PizzaCountryConverter implements Converter { @Override public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2},this.countryBean={3} - CALLED!", context, component, submittedValue, this.countryBean)); //NOI18N - // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -88,9 +85,6 @@ public class PizzaCountryConverter implements Converter { // Category id should not be below 1 assert (countryId > 0) : "countryId is smaller than one: " + countryId; //NOI18N - // Debug message - // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: countryId={0}", countryId)); //NOI18N - // Try to find it for (final Country cntry : countryList) { // Is the id the same? (null-safe) @@ -105,9 +99,6 @@ public class PizzaCountryConverter implements Converter { throw new ConverterException(ex); } - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: country={0} - EXIT!", country)); //NOI18N - // Return it return country; } diff --git a/src/java/org/mxchange/pizzaapplication/converter/mobile/PizzaMobileConverter.java b/src/java/org/mxchange/pizzaapplication/converter/mobile/PizzaMobileConverter.java index d7ea6212..ad1115a8 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/mobile/PizzaMobileConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/mobile/PizzaMobileConverter.java @@ -62,9 +62,6 @@ public class PizzaMobileConverter implements Converter { @Override public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N - // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -97,9 +94,6 @@ public class PizzaMobileConverter implements Converter { // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N } - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: mobile={0} - EXIT!", mobile)); //NOI18N - // Return it return mobile; } diff --git a/src/java/org/mxchange/pizzaapplication/converter/mobileprovider/PizzaMobileProviderConverter.java b/src/java/org/mxchange/pizzaapplication/converter/mobileprovider/PizzaMobileProviderConverter.java index 28dbba03..58112ed7 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/mobileprovider/PizzaMobileProviderConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/mobileprovider/PizzaMobileProviderConverter.java @@ -62,9 +62,6 @@ public class PizzaMobileProviderConverter implements Converter { @Override public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N - // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -88,9 +85,6 @@ public class PizzaMobileProviderConverter implements Converter { // Category id should not be below 1 assert (providerId > 0) : "providerId is smaller than one: " + providerId; //NOI18N - // Debug message - // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: providerId={0}", providerId)); //NOI18N - // Try to find it for (final MobileProvider prov : providerList) { // Is the id the same? (null-safe) @@ -105,9 +99,6 @@ public class PizzaMobileProviderConverter implements Converter { // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logException(ex); } - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: provider={0} - EXIT!", provider)); //NOI18N - // Return it return provider; } diff --git a/src/java/org/mxchange/pizzaapplication/converter/user/PizzaUserConverter.java b/src/java/org/mxchange/pizzaapplication/converter/user/PizzaUserConverter.java index 2854e1ad..be55edfc 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/user/PizzaUserConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/user/PizzaUserConverter.java @@ -61,9 +61,6 @@ public class PizzaUserConverter implements Converter { @Override public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", context, component, submittedValue)); //NOI18N - // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -80,14 +77,8 @@ public class PizzaUserConverter implements Converter { // Try to parse the value as long Long userId = Long.valueOf(submittedValue); - // Debug message - // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: userId{0}", userId)); //NOI18N - // Try to get user instance from it user = this.userBean.findUserById(userId); - - // Debug message - // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: user={0}", user)); //NOI18N } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); @@ -96,9 +87,6 @@ public class PizzaUserConverter implements Converter { // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N } - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: user={0} - EXIT!", user)); //NOI18N - // Return it return user; } diff --git a/src/java/org/mxchange/pizzaapplication/validator/birthday/PizzaBirthdayValidator.java b/src/java/org/mxchange/pizzaapplication/validator/birthday/PizzaBirthdayValidator.java index 08e8da72..014be0eb 100644 --- a/src/java/org/mxchange/pizzaapplication/validator/birthday/PizzaBirthdayValidator.java +++ b/src/java/org/mxchange/pizzaapplication/validator/birthday/PizzaBirthdayValidator.java @@ -58,9 +58,6 @@ public class PizzaBirthdayValidator extends BaseDateValidator implements Validat @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N - // All accepted, required fields String[] requiredFields = {"birthday", "contactBirthday"}; //NOI18N @@ -71,8 +68,6 @@ public class PizzaBirthdayValidator extends BaseDateValidator implements Validat Date birthday = (Date) value; // @TODO Finish this, e.g. load maximum,minimum birthday from properties file - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N } } diff --git a/src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java b/src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java index 90f859b7..5114f0cf 100644 --- a/src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java +++ b/src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java @@ -80,10 +80,7 @@ public class PizzaUserIdValidator extends BaseLongValidator implements Validator *

* @param event User registration event */ - public void afterRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) { - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("UserIdValidator:afterRegistrationEvent: event={0} - CALLED!", event)); //NOI18N - + public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) { // event should not be null if (null == event) { // Throw NPE @@ -102,21 +99,13 @@ public class PizzaUserIdValidator extends BaseLongValidator implements Validator // Get user instance User registeredUser = event.getRegisteredUser(); - // Debug message - // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("UserIdValidator:afterRegistrationEvent: registeredUser={0}", registeredUser)); //NOI18N - // Update cache PizzaUserIdValidator.cachedStatus.add(registeredUser.getUserId()); - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace("UserIdValidator:afterRegistrationEvent: EXIT!"); //NOI18N } @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N - // All accepted, required fields String[] requiredFields = {"userId"}; //NOI18N @@ -146,9 +135,6 @@ public class PizzaUserIdValidator extends BaseLongValidator implements Validator // Add to cache if valid PizzaUserIdValidator.cachedStatus.add(userId); - - // Trace message - // NOISY-DEBUG: this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N } } -- 2.39.5