From a1d657f75d14660f06bf81db56111f83def8c0c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 6 Aug 2017 21:37:03 +0200 Subject: [PATCH] Continued a bit with fixing: - added missing method isRequiredPersonalDataSet() to administrative contact controller - removed more methods from interfaces which are for JSF views only - moved JNDI lookup into PostConstruct-annotated method, still not really fixing it as this will be invoked on construction of bean instances (in web container). This later really needs to be rewritten to a service-locator approach - added observer method afterCustomerCreatedEvent() which will wait for events being fired when a customer instance has been created - JSF views should normally not have HTML declaration, but Mojarra has a long outstanding bug that will not render doctype when the declaration is in the "master" template (see WEB-INF/templates/base.tpl) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../PizzaAdminContactWebRequestBean.java | 18 ++- ...PizzaAdminContactWebRequestController.java | 7 + .../PizzaAdminCustomerWebRequestBean.java | 114 +++++++++------ ...izzaAdminCustomerWebRequestController.java | 18 --- web/WEB-INF/web.xml | 2 +- web/admin/customer/admin_customer_list.xhtml | 2 +- web/basket.xhtml | 132 +++++++++--------- web/customer/checkout.xhtml | 112 +++++++-------- web/customer/checkout2.xhtml | 92 ++++++------ web/customer/checkout_done.xhtml | 46 +++--- web/customer/empty_basket.xhtml | 105 +++++++------- 11 files changed, 326 insertions(+), 322 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java index 1045da40..1637ecc1 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestBean.java @@ -1081,6 +1081,18 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme return isRequired; } + @Override + public boolean isRequiredPersonalDataSet () { + return ((this.getPersonalTitle() != null) && + (this.getFirstName() != null) && + (this.getFamilyName() != null) && + (this.getStreet() != null) && + (this.getHouseNumber() != null) && + (this.getZipCode() != null) && + (this.getCity() != null) && + (this.getEmailAddress() != null)); + } + @Override public void validateContactData () { if (this.getPersonalTitle() == null) { @@ -1142,9 +1154,9 @@ public class PizzaAdminContactWebRequestBean extends BasePizzaController impleme /** * Checks whether the given contact is found *

- * @param contact Contact inastance - * - * @return Wether contact has been found + * @param contact Contact instance + *

+ * @return Whether contact has been found */ private boolean isSameContactFound (final Contact contact) { // Default is not found diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java index edbff61e..2daa988f 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaAdminContactWebRequestController.java @@ -66,4 +66,11 @@ public interface PizzaAdminContactWebRequestController extends Serializable { @Deprecated boolean isPersonalTitleRequired (); + /** + * Checks whether all required personal data is set + *

+ * @return Whether the required personal data is set + */ + boolean isRequiredPersonalDataSet (); + } diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java index 6ab779f7..f998d3db 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java @@ -20,6 +20,7 @@ import java.text.MessageFormat; 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; @@ -28,10 +29,10 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.jcontacts.contact.Contact; -import org.mxchange.jcontacts.contact.title.PersonalTitle; import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException; import org.mxchange.jcustomercore.events.customer.added.AdminAddedCustomerEvent; import org.mxchange.jcustomercore.events.customer.added.ObservableAdminAddedCustomerEvent; +import org.mxchange.jcustomercore.events.customer.created.ObservableCreatedCustomerEvent; import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException; import org.mxchange.jcustomercore.model.customer.Customer; import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus; @@ -72,6 +73,11 @@ public class PizzaAdminCustomerWebRequestBean extends BasePizzaController implem @Inject private PizzaWebRequestHelperController beanHelper; + /** + * Contact instance + */ + private Contact contact; + /** * An event being fired when an administrator has added a new customer */ @@ -89,56 +95,50 @@ public class PizzaAdminCustomerWebRequestBean extends BasePizzaController implem * Default constructor */ public PizzaAdminCustomerWebRequestBean () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.adminCustomerBean = (PizzaAdminCustomerSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/admincustomer!org.mxchange.pizzaapplication.model.customer.PizzaAdminCustomerSessionBeanRemote"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } } - @Override + /** + * Adds customer to database if not already added. This method should return + * a redirect outcome on success. + *

+ * @return Redirect outcome + */ public String addCustomer () { // Are at least some fields added? - if ((this.beanHelper.getContact() == null) && (!this.isCustomerDataSet())) { + if ((this.getContact() == null) && (!this.isCustomerDataSet())) { // Not all customer data is set throw new FaceletException("Please provide minimum personal data: gender, first_name, family_name"); //NOI18N } // Init contact - Contact contact; + Contact customerContact; // Is the contact set in helper? - if (this.beanHelper.getContact() instanceof Contact) { + if (this.getContact() instanceof Contact) { // Get from helper - contact = this.beanHelper.getContact(); + customerContact = this.getContact(); } else { // Get new contact instance - contact = this.adminContactController.createContactInstance(); + customerContact = this.adminContactController.createContactInstance(); } // Ask the EJB for a free customer number String customerNumber = this.adminCustomerBean.createCustomerNumber(); // Create new customer instance - Customer customer = new PizzaCustomer(CustomerAccountStatus.CONFIRMED, contact, customerNumber); + Customer customer = new PizzaCustomer(CustomerAccountStatus.CONFIRMED, customerContact, customerNumber); // Init instance Customer updatedCustomer; try { // Add/link customer and return updated - if (this.beanHelper.getContact() instanceof Contact) { + if (this.getContact() instanceof Contact) { // Link customer updatedCustomer = this.adminCustomerBean.linkCustomer(customer); // Remove contact instance - this.beanHelper.setContact(null); + this.setContact(null); } else { // Add new customer instance updatedCustomer = this.adminCustomerBean.addCustomer(customer); @@ -155,37 +155,73 @@ public class PizzaAdminCustomerWebRequestBean extends BasePizzaController implem return "admin_list_customer"; //NOI18N } - @Override - public void copyCustomerToController (final Customer customer) { - // Parameters must be valid - if (null == customer) { + /** + * Observes an even when a customer has been created + *

+ * @param event Event being fired + */ + public void afterCustomerCreatedEvent (final @Observes ObservableCreatedCustomerEvent event) { + // The event instance must be valid + if (null == event) { + // Throw NPE again + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getCreatedCustomer() == null) { // Throw NPE - throw new NullPointerException("customer is null"); //NOI18N - } else if (customer.getCustomerId() == null) { + throw new NullPointerException("event.createdCustomer is null"); //NOI18N + } else if (event.getCreatedCustomer().getCustomerId() == null) { // Throw again ... - throw new NullPointerException("customer.customerId is null"); //NOI18N - } else if (customer.getCustomerId() < 1) { + throw new NullPointerException("event.createdCustomer.customerId is null"); //NOI18N + } else if (event.getCreatedCustomer().getCustomerId() < 1) { // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("customer.customerId={0} is not valid", customer.getCustomerId())); //NOI18N - } else if (customer.getCustomerContact() == null) { + throw new IllegalArgumentException(MessageFormat.format("event.createdCustomer.customerId={0} is not valid", event.getCreatedCustomer().getCustomerId())); //NOI18N + } else if (event.getCreatedCustomer().getCustomerContact() == null) { // Throw NPE again - throw new NullPointerException("customer.customerContact is null"); //NOI18N - } else if (customer.getCustomerContact().getContactId() == null) { + throw new NullPointerException("event.createdCustomer.customerContact is null"); //NOI18N + } else if (event.getCreatedCustomer().getCustomerContact().getContactId() == null) { // .. and again - throw new NullPointerException("customer.customerContact.contactId is null"); //NOI18N - } else if (customer.getCustomerContact().getContactId() < 1) { + throw new NullPointerException("event.createdCustomer.customerContact.contactId is null"); //NOI18N + } else if (event.getCreatedCustomer().getCustomerContact().getContactId() < 1) { // Invalid id - throw new IllegalArgumentException(MessageFormat.format("customer.customerContact.contactId={0} is not valid", customer.getCustomerContact().getContactId())); //NOI18N + throw new IllegalArgumentException(MessageFormat.format("event.createdCustomer.customerContact.contactId={0} is not valid", event.getCreatedCustomer().getCustomerContact().getContactId())); //NOI18N } // @TODO Set all data } + /** + * Getter for contact instance + *

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

+ * @param contact Contact instance + */ + public void setContact (final Contact contact) { + this.contact = contact; + } + /** * Post-initialization of this class */ @PostConstruct public void init () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.adminCustomerBean = (PizzaAdminCustomerSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/admincustomer!org.mxchange.pizzaapplication.model.customer.PizzaAdminCustomerSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } } /** @@ -195,11 +231,7 @@ public class PizzaAdminCustomerWebRequestBean extends BasePizzaController implem */ private boolean isCustomerDataSet () { // Check all - return ((this.adminContactController.getPersonalTitle() instanceof PersonalTitle) && - (this.adminContactController.getFirstName() != null) && - (!this.adminContactController.getFirstName().isEmpty()) && - (this.adminContactController.getFamilyName() != null) && - (!this.adminContactController.getFamilyName().isEmpty())); + return this.adminContactController.isRequiredPersonalDataSet(); } } diff --git a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java index c4c91232..e2796530 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java @@ -17,30 +17,12 @@ package org.mxchange.pizzaapplication.beans.customer; import java.io.Serializable; -import javax.ejb.Local; -import org.mxchange.jcustomercore.model.customer.Customer; /** * An interface for user beans *

* @author Roland Häder */ -@Local public interface PizzaAdminCustomerWebRequestController extends Serializable { - /** - * Copies given customer to this controller - *

- * @param customer Customer instance to copy - */ - void copyCustomerToController (final Customer customer); - - /** - * Adds customer to database if not already added. This method should return - * a redirect outcome on success. - *

- * @return Redirect outcome - */ - String addCustomer (); - } diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index 16b8c5c0..0e5f62a3 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -48,7 +48,7 @@ true - Wether the personal title is required for using the general contact controller. + Whether the personal title is required for using the general contact controller. is_feature_general_personal_title_enabled true diff --git a/web/admin/customer/admin_customer_list.xhtml b/web/admin/customer/admin_customer_list.xhtml index 4dce8ecb..3fb4f11b 100644 --- a/web/admin/customer/admin_customer_list.xhtml +++ b/web/admin/customer/admin_customer_list.xhtml @@ -98,7 +98,7 @@

- + diff --git a/web/basket.xhtml b/web/basket.xhtml index 11877d77..6bc12722 100644 --- a/web/basket.xhtml +++ b/web/basket.xhtml @@ -1,83 +1,77 @@ - - + + + + - - - - + + + - - - + + + + + + - - - - - - + + + + + + + + + +
- + + + - - - - - - +
+
-
- - - - - -
-
+ + + + - - - - + + - - + + + + + + - - - - - - + + + + - - - - - -
- - - -
-
-
+
+ + + +
+ + - + -
- -
-
-
- +
+ +
+ +
diff --git a/web/customer/checkout.xhtml b/web/customer/checkout.xhtml index fa95d5db..283801a1 100644 --- a/web/customer/checkout.xhtml +++ b/web/customer/checkout.xhtml @@ -1,72 +1,66 @@ - - + + + + - - - - + + + - - - + +
+ - -
- + +
- +
+
+
-
-
- -
+
+
    +
  • +
    + +
    -
    -
      -
    • -
      - -
      +
      + + + +
      +
    • -
      - - - -
      - +
    • +
      + +
      -
    • -
      - -
      +
      + + + +
      +
    • -
      - - - -
      - +
    • +
      + +
      -
    • -
      - -
      - -
      - -
      -
    • -
    -
    +
    + +
    +
  • +
- - - +
+ + diff --git a/web/customer/checkout2.xhtml b/web/customer/checkout2.xhtml index fa688bc2..3a019542 100644 --- a/web/customer/checkout2.xhtml +++ b/web/customer/checkout2.xhtml @@ -1,58 +1,52 @@ - - - - - - - - - - - - - -
- - - + + + + + + + + + + +
+ + + +
+ +
+
+
-
-
- -
- -
- -
-
- -
+
+ +
+
+ +
- + -
- - Derzeit ist nur eine Bezahlung gegen Rechnung möglich. -
+
+ + Derzeit ist nur eine Bezahlung gegen Rechnung möglich. +
- + - + - -
+
+
- - - +
+ + diff --git a/web/customer/checkout_done.xhtml b/web/customer/checkout_done.xhtml index 16565893..879562b7 100644 --- a/web/customer/checkout_done.xhtml +++ b/web/customer/checkout_done.xhtml @@ -1,29 +1,23 @@ - - + + + + - - - - + + + - - - - - - - Rechnung abrufen: - - - - - - - + + + Rechnung abrufen: + + + + + + diff --git a/web/customer/empty_basket.xhtml b/web/customer/empty_basket.xhtml index d2735a71..b7d53cd6 100644 --- a/web/customer/empty_basket.xhtml +++ b/web/customer/empty_basket.xhtml @@ -1,63 +1,58 @@ - - - - - - - - - - - - - - - -
-
- -
+ + + + + + + + + + + + + +
+
+ +
+ +
+ + + -
- - - - -
-
- -
- -
- - - -
+
+
+
-
-
- +
+ + + +
+
-
- -
+
+ +
- +
+ +
+ + - +
+
- -
-
- + + + -- 2.39.5