]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with customer:
authorRoland Häder <roland@mxchange.org>
Thu, 28 Apr 2016 09:15:29 +0000 (11:15 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 28 Apr 2016 17:43:32 +0000 (19:43 +0200)
- added converter for customerId <-> Customer object
- used this in administrative customer pages
- added method copyCustomerToController()
- added getter/setter for customer in helper bean
- some messages fixed (copy-paste)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestBean.java
src/java/org/mxchange/pizzaapplication/beans/customer/PizzaAdminCustomerWebRequestController.java
src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestController.java
src/java/org/mxchange/pizzaapplication/beans/helper/PizzaAdminWebRequestHelper.java
src/java/org/mxchange/pizzaapplication/converter/contact/PizzaContactConverter.java
src/java/org/mxchange/pizzaapplication/converter/customer/PizzaCustomerConverter.java [new file with mode: 0644]
web/admin/customer/admin_customer_delete.xhtml
web/admin/customer/admin_customer_edit.xhtml
web/admin/customer/admin_customer_show.xhtml

index d530b3e4827db05cf352a5d0bafa33521fa8b163..a8bc117cdf417e4cd66b6184b23b5ef88b5ae874 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.pizzaapplication.beans.customer;
 
+import java.text.MessageFormat;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Event;
@@ -153,6 +154,32 @@ public class PizzaAdminCustomerWebRequestBean implements PizzaAdminCustomerWebRe
                return "admin_list_customer"; //NOI18N
        }
 
+       @Override
+       public void copyCustomerToController (final Customer customer) {
+               // Parameters must be valid
+               if (null == customer) {
+                       // Throw NPE
+                       throw new NullPointerException("customer is null");
+               } else if (customer.getCustomerId() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("customer.customerId is null");
+               } else if (customer.getCustomerId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("customer.customerId={0} is not valid", customer.getCustomerId()));
+               } else if (customer.getCustomerContact() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("customer.customerContact is null");
+               } else if (customer.getCustomerContact().getContactId() == null) {
+                       // .. and again
+                       throw new NullPointerException("customer.customerContact.contactId is null");
+               } else if (customer.getCustomerContact().getContactId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("customer.customerContact.contactId={0} is not valid", customer.getCustomerContact().getContactId()));
+               }
+
+               // @TODO Set all data
+       }
+
        /**
         * Post-initialization of this class
         */
index 3bdcd59a443b406d8a5e00dcaa6539f25989e46e..b068b4151cba07acb01cd13ba1047b85ff7380cb 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.pizzaapplication.beans.customer;
 
 import java.io.Serializable;
+import org.mxchange.jcustomercore.model.customer.Customer;
 
 /**
  * An interface for user beans
@@ -25,6 +26,8 @@ import java.io.Serializable;
  */
 public interface PizzaAdminCustomerWebRequestController extends Serializable {
 
+       public void copyCustomerToController (Customer customer);
+
        /**
         * Adds customer to database if not already added. This method should return
         * a redirect outcome on success.
index d867fd8ae8e52ad47e2c0a7e39883feaec30e874..a89e620583f1607533d837d0ded765fda36cf941 100644 (file)
@@ -18,6 +18,7 @@ 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.jusercore.model.user.User;
 
 /**
@@ -70,9 +71,28 @@ public interface PizzaAdminWebRequestController extends Serializable {
         */
        void setContact (final Contact contact);
 
+       /**
+        * Getter for customer instance
+        * <p>
+        * @return Customer instance
+        */
+       Customer getCustomer ();
+
+       /**
+        * Setter for customer instance
+        * <p>
+        * @param customer Contact instance
+        */
+       void setCustomer (final Customer customer);
+
        /**
         * Copies currently set contact instance's data to adminContactController
         */
        void copyContactToController ();
 
+       /**
+        * Copies currently set customer instance's data to adminCustomerController
+        */
+       void copyCustomerToController ();
+
 }
index 98f3d284ead74afd02169dcd51256c99c46f9996..b9aac7befafb95d10ee39f9fc2c0288633e14862 100644 (file)
@@ -21,6 +21,7 @@ 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.jusercore.model.user.User;
 import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
 import org.mxchange.pizzaapplication.beans.customer.PizzaAdminCustomerWebRequestController;
@@ -65,6 +66,11 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle
         */
        private Contact contact;
 
+       /**
+        * Contact instance
+        */
+       private Customer customer;
+
        /**
         * General user controller
         */
@@ -112,6 +118,30 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle
                //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
        }
 
+       @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 () {
                // Log message
@@ -146,6 +176,16 @@ public class PizzaAdminWebRequestHelper implements PizzaAdminWebRequestControlle
                this.contact = contact;
        }
 
+       @Override
+       public Customer getCustomer () {
+               return this.customer;
+       }
+
+       @Override
+       public void setCustomer (final Customer customer) {
+               this.customer = customer;
+       }
+
        @Override
        public User getUser () {
                return this.user;
index 5e4df62d64ed88a0ac620935376dbc25cd633589..c0ae8ce1ff078d6561b457b9c96eb1bc17268df5 100644 (file)
@@ -98,7 +98,7 @@ public class PizzaContactConverter implements Converter {
                        contact = this.contactBean.findContactById(contactId);
 
                        // Debug message
-                       // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: user={0}", user)); //NOI18N
+                       // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: contact={0}", contact)); //NOI18N
                } catch (final NumberFormatException ex) {
                        // Throw again
                        throw new ConverterException(ex);
diff --git a/src/java/org/mxchange/pizzaapplication/converter/customer/PizzaCustomerConverter.java b/src/java/org/mxchange/pizzaapplication/converter/customer/PizzaCustomerConverter.java
new file mode 100644 (file)
index 0000000..6ecb2bd
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.converter.customer;
+
+import java.text.MessageFormat;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.FacesConverter;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+import org.mxchange.jcustomercore.exceptions.CustomerNotFoundException;
+import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.pizzaapplication.model.customer.PizzaCustomerSessionBeanRemote;
+
+/**
+ * Converter for customer id <-> valid customer instance
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@FacesConverter (value = "CustomerConverter")
+public class PizzaCustomerConverter implements Converter {
+
+       /**
+        * User EJB
+        */
+       private PizzaCustomerSessionBeanRemote customerBean;
+
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Initialization of this converter
+        */
+       public PizzaCustomerConverter () {
+               // Try to get it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+
+                       // ... and user controller
+                       this.customerBean = (PizzaCustomerSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/customer!de.chotime.jratecalc.model.customer.PizzaCustomerSessionBeanRemote"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw it
+                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+               }
+       }
+
+       @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
+                       this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
+
+                       // Return null
+                       return null;
+               }
+
+               // Init instance
+               Customer customer = null;
+
+               try {
+                       // Try to parse the value as long
+                       Long customerId = Long.valueOf(submittedValue);
+
+                       // Debug message
+                       // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: customerId{0}", customerId)); //NOI18N
+
+                       // Try to get user instance from it
+                       customer = this.customerBean.findCustomerById(customerId);
+
+                       // Debug message
+                       // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: customer={0}", customer)); //NOI18N
+               } catch (final NumberFormatException ex) {
+                       // Throw again
+                       throw new ConverterException(ex);
+               } catch (final CustomerNotFoundException ex) {
+                       // Debug message
+                       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 customer;
+       }
+
+       @Override
+       public String getAsString (final FacesContext context, final UIComponent component, final Object value) {
+               // Is the object null?
+               if ((null == value) || ((String.valueOf(value)).isEmpty())) {
+                       // Is null
+                       return ""; //NOI18N
+               } else if (!(value instanceof Customer)) {
+                       // Not same interface
+                       throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement Customer.", value)); //NOI18N
+               }
+
+               // Return category id
+               return String.valueOf(((Customer) value).getCustomerId());
+       }
+
+}
index 2339a9e98bb635fdf22835ddfea147e287cdeca2..8dcdbfb181cf38f7859ccb2affdcf8dd52d06b08 100644 (file)
@@ -8,6 +8,11 @@
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        >
 
+       <f:metadata>
+               <f:viewParam name="customerId" value="#{adminHelper.customer}" converter="CustomerConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CUSTOMER_ID_NOT_SET}" />
+               <f:viewAction action="#{adminHelper.copyCustomerToController()}" />
+       </f:metadata>
+
        <ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
                <ui:define name="admin_title">#{msg.PAGE_TITLE_ADMIN_DELETE_CUSTOMER}</ui:define>
 
index 9d920d040044cdbea935df89c6265c1755d96e58..e70fe72d154c349592c56ae6ffeeebf7ea0e174e 100644 (file)
@@ -8,6 +8,11 @@
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        >
 
+       <f:metadata>
+               <f:viewParam name="customerId" value="#{adminHelper.customer}" converter="CustomerConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CUSTOMER_ID_NOT_SET}" />
+               <f:viewAction action="#{adminHelper.copyCustomerToController()}" />
+       </f:metadata>
+
        <ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
                <ui:define name="admin_title">#{msg.PAGE_TITLE_ADMIN_EDIT_CUSTOMER}</ui:define>
 
index 8936287809859319f8b7f7e434b6cae780904f52..61a68401e3e3a1c374dd5ab69836b268de9ec306 100644 (file)
@@ -8,6 +8,11 @@
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        >
 
+       <f:metadata>
+               <f:viewParam name="customerId" value="#{adminHelper.customer}" converter="CustomerConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CUSTOMER_ID_NOT_SET}" />
+               <f:viewAction action="#{adminHelper.copyCustomerToController()}" />
+       </f:metadata>
+
        <ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
                <ui:define name="admin_title">#{msg.PAGE_TITLE_ADMIN_SHOW_CUSTOMER}</ui:define>