From 9641a385a1ebefa3c8627dd61f6b2696adc9a97e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 27 Apr 2016 10:54:32 +0200 Subject: [PATCH] Refactured a lot: - administrative controller are request-scoped, therefor their "cached" lists are never cached for a longer time. So all lists has to be moved to general controllers - added new general customer bean for above refacturing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../localization/bundle_de_DE.properties | 4 + .../localization/bundle_en_US.properties | 4 + .../PizzaAdminContactWebRequestBean.java | 2 +- .../PizzaAdminCustomerWebRequestBean.java | 22 +- ...izzaAdminCustomerWebRequestController.java | 16 - .../customer/PizzaCustomerWebSessionBean.java | 297 ++++++------------ .../PizzaCustomerWebSessionController.java | 188 +---------- .../PizzaAdminWebRequestController.java | 10 + .../helper/PizzaAdminWebRequestHelper.java | 70 ++++- .../user/PizzaAdminUserWebRequestBean.java | 131 +------- .../PizzaAdminUserWebRequestController.java | 37 --- .../beans/user/PizzaUserWebSessionBean.java | 134 +++++++- .../user/PizzaUserWebSessionController.java | 35 ++- web/admin/contact/admin_contact_list.xhtml | 6 + web/admin/customer/admin_customer_list.xhtml | 8 +- web/admin/user/admin_user_list.xhtml | 18 +- 16 files changed, 375 insertions(+), 607 deletions(-) diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index 3058b5b1..61aa8863 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -337,3 +337,7 @@ ADMIN_SELECT_CUSTOMER_CONTACT=Kontakt zum Verkn\u00fcpfen ausw\u00e4hlen: ADMIN_CONTACT_CREATED=Erstellt: ADMIN_ADD_CONTACT_TITLE=Neue Kontaktdaten hinzuf\u00fcgen BUTTON_ADMIN_ADD_CONTACT=Kontaktdaten hinzuf\u00fcgen +CONTACT_IS_UNUSED=Nicht verlinkt +CONTACT_IS_USER_CUSTOMER=Benutzer und Kunde +CONTACT_IS_USER=Ist Benutzer +CONTACT_IS_CUSTOMER=Ist Kunde diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 92aef369..5aaa3a61 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -338,3 +338,7 @@ ADMIN_SELECT_CUSTOMER_CONTACT=Select contact for linking: ADMIN_CONTACT_CREATED=Created: ADMIN_ADD_CONTACT_TITLE=Add new contact data BUTTON_ADMIN_ADD_CONTACT=Add contact data +CONTACT_IS_UNUSED=Not linked +CONTACT_IS_USER_CUSTOMER=User and customer +CONTACT_IS_USER=Is a user +CONTACT_IS_CUSTOMER=Is a customer diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java index 94246d5e..43079c27 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java @@ -113,7 +113,7 @@ public class PizzaAdminContactWebRequestBean implements PizzaAdminContactWebRequ * General contact controller */ @Inject - private RateCalcContactWebSessionController contactController; + private PizzaContactWebSessionController contactController; /** * Contact id diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java index 2a7a49b1..7c9bbd62 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java @@ -16,8 +16,6 @@ */ package org.mxchange.pizzaapplication.beans.customer; -import java.util.Collections; -import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; @@ -72,9 +70,10 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe private Event customerAddedEvent; /** - * A list of all customers + * General customer controller */ - private List customerList; + @Inject + private PizzaCustomerWebSessionController customerController; /** * Default constructor @@ -122,7 +121,7 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe } // Add customer to list - this.customerList.add(updatedCustomer); + this.customerController.addCustomer(updatedCustomer); // Fire event this.customerAddedEvent.fire(new CustomerAdminAddedEvent(updatedCustomer)); @@ -131,24 +130,11 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe return "admin_list_customer"; //NOI18N } - @Override - public List allCustomers () { - // Return it - return Collections.unmodifiableList(this.customerList); - } - - @Override - public boolean hasCustomers () { - return (!this.allCustomers().isEmpty()); - } - /** * Post-initialization of this class */ @PostConstruct public void init () { - // Initialize customer list - this.customerList = this.adminCustomerBean.allCustomers(); } /** diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java index 9aa71b0e..3bdcd59a 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java @@ -17,8 +17,6 @@ package org.mxchange.pizzaapplication.beans.customer; import java.io.Serializable; -import java.util.List; -import org.mxchange.jcustomercore.model.customer.Customer; /** * An interface for user beans @@ -27,20 +25,6 @@ import org.mxchange.jcustomercore.model.customer.Customer; */ public interface PizzaAdminCustomerWebRequestController extends Serializable { - /** - * All customer - *

- * @return A list of all customer profiles - */ - List allCustomers (); - - /** - * Checks whether customers are registered - *

- * @return Whether customers are registered - */ - boolean hasCustomers (); - /** * Adds customer to database if not already added. This method should return * a redirect outcome on success. diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java index 71aa303b..a82e358c 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionBean.java @@ -16,22 +16,26 @@ */ package org.mxchange.pizzaapplication.beans.customer; +import java.text.MessageFormat; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; +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.contact.Contact; -import org.mxchange.jcontacts.contact.UserContact; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcountry.data.Country; +import org.mxchange.jcustomercore.events.AdminAddedCustomerEvent; import org.mxchange.jcustomercore.model.customer.Customer; -import org.mxchange.jcustomercore.model.customer.CustomerSessionBeanRemote; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jshopcore.model.customer.ShopCustomer; +import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController; +import org.mxchange.pizzaapplication.model.customer.PizzaAdminCustomerSessionBeanRemote; /** * A customer bean which hides the customer instance @@ -45,93 +49,42 @@ public class PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionContr /** * Serial number */ - private static final long serialVersionUID = 542_145_347_916L; + private static final long serialVersionUID = 12_487_062_487_527_913L; - /////////////////////// Properties ///////////////////// /** - * Cellphone number + * Administrative contact controller (for personal data) */ - private DialableCellphoneNumber cellphoneNumber; + @Inject + private PizzaAdminContactWebRequestController adminContactController; /** - * City + * Administrative customer EJB */ - private String city; + private PizzaAdminCustomerSessionBeanRemote adminCustomerBean; /** - * Optional comments + * An event being fired when an administrator has added a new customer */ - private String comment; + @Inject + @Any + private Event customerAddedEvent; /** - * Country code + * A list of all customers */ - private Country country; - - /** - * Remote customer bean - */ - private CustomerSessionBeanRemote customerBean; - - /** - * Email address - */ - private String emailAddress; - - /** - * Family name - */ - private String familyName; - - /** - * Fax number - */ - private DialableFaxNumber faxNumber; - - /** - * First name - */ - private String firstName; - - /** - * Gender instance - */ - private Gender gender; - - /** - * House number - */ - private Short houseNumber; - - /** - * Phone number - */ - private DialableLandLineNumber phoneNumber; - - /** - * Street - */ - private String street; - - /** - * ZIP code - */ - private Integer zipCode; + private List customerList; /** * Default constructor */ public PizzaCustomerWebSessionBean () { - // Set gender to UNKNOWN - this.gender = Gender.UNKNOWN; - // Try it try { // Get initial context Context context = new InitialContext(); // Try to lookup - this.customerBean = (CustomerSessionBeanRemote) context.lookup("java:global/jshop-ejb/shop_customer!org.mxchange.jcustomercore.model.customer.CustomerSessionBeanRemote"); //NOI18N + this.adminCustomerBean = (PizzaAdminCustomerSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/admincustomer!de.chotime.jratecalc.model.customer.PizzaAdminCustomerSessionBeanRemote"); //NOI18N } catch (final NamingException e) { // Throw again throw new FaceletException(e); @@ -139,159 +92,87 @@ public class PizzaCustomerWebSessionBean implements PizzaCustomerWebSessionContr } @Override - public Customer createCustomerInstance () { - // Trace message - //this.getLogger().logTrace("createInstance: CALLED!"); - - // Required personal data must be set - assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N - - // Create new customer instance - Customer customer = new ShopCustomer(); - - // Create new contact - Contact contact = new UserContact(this.getGender(), this.getFirstName(), this.getFamilyName()); - contact.setContactStreet(this.getStreet()); - contact.setContactHouseNumber(this.getHouseNumber()); - contact.setContactZipCode(this.getZipCode()); - contact.setContactCity(this.getCity()); - contact.setContactCountry(this.getCountry()); - contact.setContactLandLineNumber(this.getPhoneNumber()); - contact.setContactFaxNumber(this.getFaxNumber()); - contact.setContactCellphoneNumber(this.getCellphoneNumber()); - - // Set contact in customer - customer.setCustomerContact(contact); - - // Trace message - //this.getLogger().logTrace(MessageFormat.format("createInstance: customer={0} - EXIT!", customer)); - // Return it - return customer; - } - - @Override - public DialableCellphoneNumber getCellphoneNumber () { - return this.cellphoneNumber; - } - - @Override - public void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - - @Override - public String getCity () { - return this.city; - } - - @Override - public void setCity (final String city) { - this.city = city; - } - - @Override - public Country getCountry () { - return this.country; - } - - @Override - public void setCountry (final Country country) { - this.country = country; - } - - @Override - public String getEmailAddress () { - return this.emailAddress; - } - - @Override - public void setEmailAddress (final String emailAddress) { - this.emailAddress = emailAddress; - } - - @Override - public String getFamilyName () { - return this.familyName; - } - - @Override - public void setFamilyName (final String familyName) { - this.familyName = familyName; - } - - @Override - public DialableFaxNumber getFaxNumber () { - return this.faxNumber; - } - - @Override - public void setFaxNumber (final DialableFaxNumber faxNumber) { - this.faxNumber = faxNumber; - } - - @Override - public String getFirstName () { - return this.firstName; - } - - @Override - public void setFirstName (final String firstName) { - this.firstName = firstName; - } - - @Override - public Gender getGender () { - return this.gender; - } + public void addCustomer (final Customer customer) { + // The contact must be valid + if (null == customer) { + // Throw NPE + throw new NullPointerException("customer is null"); //NOI18N + } else if (customer.getCustomerId() == null) { + // Throw again ... + throw new NullPointerException("customer.customerId is null"); //NOI18N + } else if (customer.getCustomerId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("customer.customerId={0} is not valid", customer.getCustomerId())); //NOI18N + } else if (customer.getCustomerContact() == null) { + // Throw NPE + throw new NullPointerException("customer.customerContact is null"); //NOI18N + } else if (customer.getCustomerContact().getContactId() == null) { + // Throw again ... + throw new NullPointerException("customer.customerContact.contactId is null"); //NOI18N + } else if (customer.getCustomerContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("customer.customerContact.contactId={0} is not valid", customer.getCustomerContact().getContactId())); //NOI18N + } - @Override - public void setGender (final Gender gender) { - this.gender = gender; + // Add to list + this.customerList.add(customer); } @Override - public Short getHouseNumber () { - return this.houseNumber; + public List allCustomers () { + // Return it + return Collections.unmodifiableList(this.customerList); } @Override - public void setHouseNumber (final Short houseNumber) { - this.houseNumber = houseNumber; + public boolean hasCustomers () { + return (!this.allCustomers().isEmpty()); } - @Override - public DialableLandLineNumber getPhoneNumber () { - return this.phoneNumber; + /** + * Post-initialization of this class + */ + @PostConstruct + public void init () { + // Initialize customer list + this.customerList = this.adminCustomerBean.allCustomers(); } @Override - public void setPhoneNumber (final DialableLandLineNumber phoneNumber) { - this.phoneNumber = phoneNumber; - } + public boolean isContactFound (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 + } - @Override - public String getStreet () { - return this.street; - } + // Default is not found + boolean isFound = false; - @Override - public void setStreet (final String street) { - this.street = street; - } + // Get iterator + Iterator iterator = this.allCustomers().iterator(); - @Override - public Integer getZipCode () { - return this.zipCode; - } + // Loop through all entries + while (iterator.hasNext()) { + // Get customer + Customer next = iterator.next(); - @Override - public void setZipCode (final Integer zipCode) { - this.zipCode = zipCode; - } + // Compare both objects + if (Objects.equals(contact, next.getCustomerContact())) { + // Found it + isFound = true; + break; + } + } - @Override - public boolean isRequiredPersonalDataSet () { - return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null)); + // Return status + return isFound; } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java index d7a2e479..098f529b 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaCustomerWebSessionController.java @@ -17,12 +17,9 @@ package org.mxchange.pizzaapplication.beans.customer; import java.io.Serializable; -import org.mxchange.jcontacts.contact.gender.Gender; -import org.mxchange.jcountry.data.Country; +import java.util.List; +import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jcustomercore.model.customer.Customer; -import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; /** * An interface for customer beans @@ -32,185 +29,34 @@ import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; public interface PizzaCustomerWebSessionController extends Serializable { /** - * Creates an instance from all properties + * Adds customer instance to list. The customer should be an updated + * instance (with id number). *

- * @return A Customer instance + * @param customer Customer instance */ - Customer createCustomerInstance (); + void addCustomer (final Customer customer); /** - * Cellphone number + * Checks whether the given contact is a customer *

- * @return the cellphoneNumber + * @param contact Contact to check + * + * @return Whether the contact is a customer */ - DialableCellphoneNumber getCellphoneNumber (); + boolean isContactFound (final Contact contact); /** - * Cellphone number + * All customer *

- * @param cellphoneNumber the cellphoneNumber to set + * @return A list of all customer profiles */ - void setCellphoneNumber (final DialableCellphoneNumber cellphoneNumber); + List allCustomers (); /** - * City + * Checks whether customers are registered *

- * @return the city + * @return Whether customers are registered */ - String getCity (); - - /** - * City - *

- * @param city the city to set - */ - void setCity (final String city); - - /** - * Getter for country instance - *

- * @return Country instance - */ - Country getCountry (); - - /** - * Setter for country instance - *

- * @param country Country instance - */ - void setCountry (final Country country); - - /** - * Email address - *

- * @return the emailAddress - */ - String getEmailAddress (); - - /** - * Email address - *

- * @param emailAddress the emailAddress to set - */ - void setEmailAddress (final String emailAddress); - - /** - * Family name - *

- * @return the familyName - */ - String getFamilyName (); - - /** - * Family name - *

- * @param familyName the familyName to set - */ - void setFamilyName (final String familyName); - - /** - * Fax number - *

- * @return the faxNumber - */ - DialableFaxNumber getFaxNumber (); - - /** - * Fax number - *

- * @param faxNumber the faxNumber to set - */ - void setFaxNumber (final DialableFaxNumber faxNumber); - - /** - * First name - *

- * @return the first name - */ - String getFirstName (); - - /** - * First name - *

- * @param firstName the first name to set - */ - void setFirstName (final String firstName); - - /** - * Gender of the contact - *

- * @return the gender - */ - Gender getGender (); - - /** - * Gender of the contact - *

- * @param gender the gender to set - */ - void setGender (final Gender gender); - - /** - * House number - *

- * @return the houseNumber - */ - Short getHouseNumber (); - - /** - * House number - *

- * @param houseNumber the houseNumber to set - */ - void setHouseNumber (final Short houseNumber); - - /** - * Phone number - *

- * @return the phoneNumber - */ - DialableLandLineNumber getPhoneNumber (); - - /** - * Phone number - *

- * @param phoneNumber the phoneNumber to set - */ - void setPhoneNumber (final DialableLandLineNumber phoneNumber); - - /** - * Street - *

- * @return the street - */ - String getStreet (); - - /** - * Street - *

- * @param street the street to set - */ - void setStreet (final String street); - - /** - * ZIP code - *

- * @return the zipCode - */ - Integer getZipCode (); - - /** - * ZIP code - *

- * @param zipCode the zipCode to set - */ - void setZipCode (final Integer zipCode); - - /** - * Checks whether all required personal data is set - *

- * @return Whether the required personal data is set - */ - boolean isRequiredPersonalDataSet (); + boolean hasCustomers (); } diff --git a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java index 1ff3f0b6..d867fd8a 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java @@ -46,6 +46,16 @@ public interface PizzaAdminWebRequestController extends Serializable { */ void copyUserToController (); + /** + * Returns a message key depending on if this contact is a user and/or a + * contact. If this contact is unused, a default key is returned. + *

+ * @param contact Contact instance to check + *

+ * @return Message key + */ + String getUserCustomerUsageMessageKey (final Contact contact); + /** * Getter for contact instance *

diff --git a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java index 6d538c23..98f3d284 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java +++ b/src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java @@ -23,7 +23,10 @@ import javax.inject.Named; import org.mxchange.jcontacts.contact.Contact; 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.user.PizzaAdminUserWebRequestController; +import org.mxchange.pizzaapplication.beans.user.PizzaUserWebSessionController; /** * A general helper for administrative beans @@ -40,13 +43,19 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle private static final long serialVersionUID = 17_258_793_567_145_701L; /** - * Admin contact controller + * Administrative contact controller */ @Inject private PizzaAdminContactWebRequestController adminContactController; /** - * Admin user controller + * Administrative user controller + */ + @Inject + private PizzaAdminCustomerWebRequestController adminCustomerController; + + /** + * Administrative user controller */ @Inject private PizzaAdminUserWebRequestController adminUserController; @@ -56,11 +65,23 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle */ private Contact contact; + /** + * General user controller + */ + @Inject + private PizzaCustomerWebSessionController customerController; + /** * User instance */ private User user; + /** + * General user controller + */ + @Inject + private PizzaUserWebSessionController userController; + /** * Default constructor */ @@ -70,7 +91,7 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle @Override public void copyContactToController () { // Log message - System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - CALLED!"); //NOI18N // Validate user instance if (this.getContact() == null) { @@ -88,13 +109,13 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle this.adminContactController.copyContactToController(this.getContact()); // Log message - System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N } @Override public void copyUserToController () { // Log message - System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - CALLED!"); //NOI18N // Validate user instance if (this.getUser() == null) { @@ -112,7 +133,7 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle this.adminUserController.setUserName(this.getUser().getUserName()); // Log message - System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N + //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyUserToController - EXIT!"); //NOI18N } @Override @@ -135,4 +156,41 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle this.user = user; } + @Override + public String getUserCustomerUsageMessageKey (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_CUSTOMER"; //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; + } + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java index 6000c201..088d747a 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestBean.java @@ -17,14 +17,10 @@ package org.mxchange.pizzaapplication.beans.user; import java.text.MessageFormat; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; import java.util.Objects; import javax.annotation.PostConstruct; 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; @@ -38,10 +34,8 @@ import org.mxchange.jusercore.events.user.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.AdminUserAddedEvent; import org.mxchange.jusercore.events.user.update.AdminUpdatedUserDataEvent; import org.mxchange.jusercore.events.user.update.AdminUserDataUpdatedEvent; -import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; -import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.exceptions.UserPasswordRepeatMismatchException; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; @@ -103,11 +97,6 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon @Inject private PizzaUserWebSessionController userController; - /** - * A list of all user profiles - */ - private List userList; - /** * User name */ @@ -169,13 +158,13 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon } else if (this.contactController.getFamilyName().isEmpty()) { // ... and again throw new IllegalArgumentException("contactController.familyName is empty"); //NOI18N //NOI18N - } else if (this.contactController.getEmailAddress()== null) { + } else if (this.contactController.getEmailAddress() == null) { // ... and again throw new NullPointerException("contactController.emailAddress is null"); } else if (this.contactController.getEmailAddress().isEmpty()) { // ... and again throw new IllegalArgumentException("contactController.emailAddress is empty"); //NOI18N //NOI18N - } else if (this.contactController.getEmailAddressRepeat()== null) { + } else if (this.contactController.getEmailAddressRepeat() == null) { // ... and again throw new NullPointerException("contactController.emailAddressRepeat is null"); } else if (this.contactController.getEmailAddressRepeat().isEmpty()) { @@ -248,7 +237,7 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon // Add new contact updatedUser = this.userBean.addUser(user); } - } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) { + } catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) { // Throw again throw new FaceletException(ex); } @@ -256,9 +245,6 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon // Fire event this.addedUserEvent.fire(new AdminUserAddedEvent(updatedUser)); - // Add user to local list - this.userList.add(updatedUser); - // Clear contact instance this.contactController.clear(); @@ -266,33 +252,6 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon return "admin_list_user"; //NOI18N } - @Override - public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) { - // Check parameter - 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) { - // ... and again - throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N - } else if (event.getUpdatedUser().getUserId() < 1) { - // Invalid value - throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N - } - - // All fine, so update list - this.updateList(event.getUpdatedUser()); - } - - @Override - public List allUsers () { - // Return it - return Collections.unmodifiableList(this.userList); - } - @Override public String changeUserData () { // Get user instance @@ -351,7 +310,7 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon User updatedUser = this.userBean.updateUserData(user); // Update list - this.updateList(updatedUser); + this.userController.updateList(updatedUser); // Fire event this.updatedUserDataEvent.fire(new AdminUserDataUpdatedEvent(updatedUser)); @@ -390,55 +349,11 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon this.userPasswordRepeat = userPasswordRepeat; } - @Override - public boolean hasUsers () { - return (!this.allUsers().isEmpty()); - } - /** * Post-initialization of this class */ @PostConstruct public void init () { - // Initialize user list - this.userList = this.userBean.allUsers(); - } - - @Override - public User lookupUserById (final Long userId) throws UserNotFoundException { - // Parameter must be valid - if (null == userId) { - // Throw NPE - throw new NullPointerException("userId is null"); //NOI18N - } else if (userId < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N - } - - // Init variable - User user = null; - - // Try to lookup it in visible user list - for (final Iterator iterator = this.userList.iterator(); iterator.hasNext();) { - // Get next user - User next = iterator.next(); - - // Is the user id found? - if (Objects.equals(next.getUserId(), userId)) { - // Copy to other variable - user = next; - break; - } - } - - // Is it still null? - if (null == user) { - // Not visible for the current user - throw new UserNotFoundException(userId); - } - - // Return it - return user; } /** @@ -450,42 +365,4 @@ public class PizzaAdminUserWebRequestBean implements PizzaAdminUserWebRequestCon return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat()))); } - /** - * Updates list with given user instance - *

- * @param user User instance - */ - private void updateList (final User user) { - // The user should be valid - if (null == user) { - // Throw NPE - throw new NullPointerException("user 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 - Iterator iterator = this.userList.iterator(); - - // Look whole list - while (iterator.hasNext()) { - // Get next element - User next = iterator.next(); - - // Is the same user id? - if (Objects.equals(user.getUserId(), next.getUserId())) { - // Found it, so remove it - this.userList.remove(next); - break; - } - } - - // Re-add item - this.userList.add(user); - } - } diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java index 9d787b11..9026a24d 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaAdminUserWebRequestController.java @@ -17,10 +17,6 @@ package org.mxchange.pizzaapplication.beans.user; import java.io.Serializable; -import java.util.List; -import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; -import org.mxchange.jusercore.exceptions.UserNotFoundException; -import org.mxchange.jusercore.model.user.User; /** * An interface for user beans @@ -29,39 +25,6 @@ import org.mxchange.jusercore.model.user.User; */ public interface PizzaAdminUserWebRequestController extends Serializable { - /** - * Listens to fired event when user updated personal data - *

- * @param event Event being fired - */ - void afterUserUpdatedPersonalData (final UpdatedUserPersonalDataEvent event); - - /** - * Tries to lookup user by given id number. If the user is not found or the - * account status is not CONFIRMED proper exceptions are thrown. - *

- * @param userId User id - *

- * @return User instance - *

- * @throws UserNotFoundException If the user is not found - */ - User lookupUserById (final Long userId) throws UserNotFoundException; - - /** - * All users - *

- * @return A list of all public user profiles - */ - List allUsers (); - - /** - * Checks whether users are registered - *

- * @return Whether users are registered - */ - boolean hasUsers (); - /** * 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, diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java index 42a83a3a..ce8c1b74 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionBean.java @@ -16,8 +16,6 @@ */ package org.mxchange.pizzaapplication.beans.user; -import de.chotime.jratecalc.beans.contact.RateCalcContactWebSessionController; -import de.chotime.jratecalc.beans.login.RateCalcUserLoginWebSessionController; import java.text.MessageFormat; import java.util.Collections; import java.util.Iterator; @@ -45,13 +43,13 @@ import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; import org.mxchange.jusercore.events.user.update.UserUpdatedPersonalDataEvent; import org.mxchange.jusercore.exceptions.UserNotFoundException; +import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.UserSessionBeanRemote; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; -import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebSessionController; -import org.mxchange.jusercore.exceptions.UserPasswordMismatchException; +import org.mxchange.pizzaapplication.beans.login.PizzaUserLoginWebSessionController; /** * A user bean (controller) @@ -71,7 +69,7 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { * Administrative user controller */ @Inject - private RateCalcAdminUserWebRequestController adminController; + private PizzaAdminUserWebRequestController adminController; /** * Remote user bean @@ -112,6 +110,11 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { */ private Long userId; + /** + * A list of all user profiles + */ + private List userList; + /** * User name */ @@ -200,6 +203,9 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { // Set user id again this.setUserId(registeredUser.getUserId()); + // Add user to local list + this.userList.add(registeredUser); + // Is the account public? if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) { // Also add it to this list @@ -241,6 +247,9 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { // Remove this contact from selectable list assert(this.selectableContacts.remove(event.getAddedUser().getUserContact())) : "contact was not removed"; //NOI18N + + // Add user to local list + this.userList.add(event.getAddedUser()); } @Override @@ -273,6 +282,12 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { System.out.println(MessageFormat.format("UserWebBean:afterUserLogin: this.visibleUserList.size()={0} - EXIT!", this.visibleUserList.size())); //NOI18N } + @Override + public List allUsers () { + // Return it + return Collections.unmodifiableList(this.userList); + } + @Override public List allVisibleUsers () { // Return it @@ -397,6 +412,11 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { this.userProfileMode = userProfileMode; } + @Override + public boolean hasUsers () { + return (!this.allUsers().isEmpty()); + } + /** * Post-initialization of this class */ @@ -413,9 +433,8 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { // Initialize user list this.visibleUserList = this.userBean.allPublicUsers(); } - - // Get all users - List allUsers = this.adminController.allUsers(); + // Initialize user list + this.userList = this.userBean.allUsers(); // Get all contacts List allContacts = this.contactBean.getAllContacts(); @@ -429,7 +448,7 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { Contact next = iterator.next(); // Get iterator - Iterator userIterator = allUsers.iterator(); + Iterator userIterator = this.userList.iterator(); // Loop through all users while (userIterator.hasNext()) { @@ -449,6 +468,64 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { this.selectableContacts = allContacts; } + @Override + public boolean isContactFound (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 is not found + boolean isFound = false; + + // Get iterator + Iterator iterator = this.allUsers().iterator(); + + // Loop through all entries + while (iterator.hasNext()) { + // Get user + User next = iterator.next(); + + // Compare both objects + if (Objects.equals(contact, next.getUserContact())) { + // Found it + isFound = true; + break; + } + } + + // Return status + return isFound; + } + + @Override + public void afterUserUpdatedPersonalData (@Observes final UpdatedUserPersonalDataEvent event) { + // Check parameter + 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) { + // ... and again + throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N + } else if (event.getUpdatedUser().getUserId() < 1) { + // Invalid value + throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N + } + + // All fine, so update list + this.updateList(event.getUpdatedUser()); + } + @Override public boolean isRequiredChangePersonalDataSet () { return ((this.getUserProfileMode() != null) && @@ -547,6 +624,45 @@ public class PizzaUserWebSessionBean implements PizzaUserWebSessionController { this.contactController.addEmailAddress(user.getUserContact().getContactEmailAddress()); } + /** + * Updates list with given user instance + *

+ * @param user User instance + */ + @Override + public void updateList (final User user) { + // The user should be valid + if (null == user) { + // Throw NPE + throw new NullPointerException("user 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 + Iterator iterator = this.userList.iterator(); + + // Look whole list + while (iterator.hasNext()) { + // Get next element + User next = iterator.next(); + + // Is the same user id? + if (Objects.equals(user.getUserId(), next.getUserId())) { + // Found it, so remove it + this.userList.remove(next); + break; + } + } + + // Re-add item + this.userList.add(user); + } + /** * Clears this bean */ diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java index 19fef777..aecd5490 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebSessionController.java @@ -22,6 +22,7 @@ import org.mxchange.jcontacts.contact.Contact; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; +import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent; import org.mxchange.jusercore.exceptions.UserNotFoundException; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; @@ -38,6 +39,38 @@ public interface PizzaUserWebSessionController extends Serializable { */ public static final Integer MINIMUM_PASSWORD_LENGTH = 5; + /** + * All users + *

+ * @return A list of all public user profiles + */ + List allUsers (); + + /** + * Checks whether users are registered + *

+ * @return Whether users are registered + */ + boolean hasUsers (); + + /** + * Checks whether the given contact is a user + *

+ * @param contact Contact to check + *

+ * @return Whether the contact is a user + */ + boolean isContactFound (final Contact contact); + + /** + * Listens to fired event when user updated personal data + *

+ * @param event Event being fired + */ + void afterUserUpdatedPersonalData (final UpdatedUserPersonalDataEvent event); + + void updateList (final User user); + /** * Returns a list of all selectable contacts for user creation. Contacts * from already existing users are excluded in this list. @@ -63,7 +96,7 @@ public interface PizzaUserWebSessionController extends Serializable { *

* @param event Event being fired */ - void afterAdminAddedUserEvent(final AdminAddedUserEvent event); + void afterAdminAddedUserEvent (final AdminAddedUserEvent event); /** * Event observer for new user registrations diff --git a/web/admin/contact/admin_contact_list.xhtml b/web/admin/contact/admin_contact_list.xhtml index 1cdec6f3..1284bea1 100644 --- a/web/admin/contact/admin_contact_list.xhtml +++ b/web/admin/contact/admin_contact_list.xhtml @@ -43,6 +43,12 @@ + + #{msg.ADMIN_CONTACT_USER_CUSTOMER_USAGE} + + + + #{msg.ADMIN_CONTACT_CREATED} diff --git a/web/admin/customer/admin_customer_list.xhtml b/web/admin/customer/admin_customer_list.xhtml index 018692d4..6289a989 100644 --- a/web/admin/customer/admin_customer_list.xhtml +++ b/web/admin/customer/admin_customer_list.xhtml @@ -16,7 +16,7 @@ - + #{msg.ADMIN_LIST_CUSTOMER_ID} @@ -32,19 +32,19 @@ - #{msg.ADMIN_LIST_CUSTOMER_GENDER} + #{msg.ADMIN_CONTACT_GENDER} - #{msg.ADMIN_LIST_CUSTOMER_FIRST_NAME} + #{msg.ADMIN_CONTACT_FIRST_NAME} - #{msg.ADMIN_LIST_CUSTOMER_FAMILY_NAME} + #{msg.ADMIN_CONTACT_FAMILY_NAME} diff --git a/web/admin/user/admin_user_list.xhtml b/web/admin/user/admin_user_list.xhtml index c0168f1d..11ead762 100644 --- a/web/admin/user/admin_user_list.xhtml +++ b/web/admin/user/admin_user_list.xhtml @@ -16,9 +16,9 @@ - + - #{msg.ADMIN_LIST_USER_ID} + #{msg.ADMIN_USER_ID} @@ -26,43 +26,43 @@ - #{msg.ADMIN_LIST_USER_NAME} + #{msg.ADMIN_USER_NAME} - #{msg.ADMIN_LIST_USER_GENDER} + #{msg.ADMIN_CONTACT_GENDER} - #{msg.ADMIN_LIST_USER_FIRST_NAME} + #{msg.ADMIN_CONTACT_FIRST_NAME} - #{msg.ADMIN_LIST_USER_FAMILY_NAME} + #{msg.ADMIN_CONTACT_FAMILY_NAME} - #{msg.ADMIN_LIST_USER_ACCOUNT_STATUS} + #{msg.ADMIN_USER_ACCOUNT_STATUS} - #{msg.ADMIN_LIST_USER_PROFILE_MODE} + #{msg.ADMIN_USER_PROFILE_MODE} - #{msg.ADMIN_LIST_USER_CREATED} + #{msg.ADMIN_USER_CREATED} -- 2.39.5