]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Tue, 15 Sep 2015 13:28:10 +0000 (15:28 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 15 Sep 2015 13:28:10 +0000 (15:28 +0200)
- added "checkout bean" for handling the "guest checkout" (no registration)
- other improvements
- updated jshop-core.jar
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/jshop-core.jar
src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java
src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java
src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebBean.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebController.java [new file with mode: 0644]
src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebBean.java
web/customer/checkout2.xhtml

index 88013336b02c1d795fa399a67766638609d6b5a4..ffdfed6b8336dff31017701d431501ef76f74c2c 100644 (file)
Binary files a/lib/jshop-core.jar and b/lib/jshop-core.jar differ
index 09f4e10c3d3ac1c0794def5d795488ea6dfbc402..213cc9246f4fdfd403cc5d09b8c925427e76ca40 100644 (file)
@@ -195,6 +195,13 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                return targetPage;
        }
 
+       @Override
+       public void clear () {
+               // @TODO Also clear EJB
+               // Deligate to basket instance
+               this.basket.clear();
+       }
+
        @Override
        public Long getAmount () {
                return this.amount;
index 46d5b40c92177bff99ffdaa034491be8d4371687..5421d9a16745f1707b857c54541b61d8e5472d29 100644 (file)
@@ -28,6 +28,11 @@ import org.mxchange.jshopcore.model.product.Product;
  */
 public interface BasketWebController extends Serializable {
 
+       /**
+        * Clears this basket instance
+        */
+       public void clear ();
+
        /**
         * Checks whether the basket is empty
         *
diff --git a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebBean.java
new file mode 100644 (file)
index 0000000..21d2738
--- /dev/null
@@ -0,0 +1,384 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.checkout;
+
+import java.util.List;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.SessionScoped;
+import javax.faces.FacesException;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcore.model.contact.gender.Gender;
+import org.mxchange.jcoreee.beans.BaseFrameworkBean;
+import org.mxchange.jshopcore.model.basket.AddableBasketItem;
+import org.mxchange.jshopcore.model.customer.Customer;
+import org.mxchange.jshopcore.model.customer.ShopCustomer;
+import org.mxchange.jshopcore.wrapper.CheckoutWrapper;
+import org.mxchange.jshopcore.wrapper.WrapableCheckout;
+import org.mxchange.pizzaapplication.beans.basket.BasketWebController;
+
+/**
+ * Checkout controller
+ *
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("checkoutController")
+@SessionScoped
+public class CheckoutWebBean extends BaseFrameworkBean implements CheckoutWebController {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 51_987_348_347_183L;
+
+       /**
+        * Connection
+        */
+       private Connection connection;
+
+       /**
+        * Message producer
+        */
+       private MessageProducer messageProducer;
+
+       /**
+        * Queue instance
+        */
+       private Queue queue;
+
+       /**
+        * Session instance
+        */
+       private Session session;
+
+       /**
+        * Object message
+        */
+       private ObjectMessage message;
+
+       ////////////////////// Bean injections ///////////////////////
+       /**
+        * Basket bean
+        */
+       @Inject
+       private BasketWebController basketController;
+
+       /////////////////////// Properties /////////////////////
+       /**
+        * Gender
+        */
+       private Gender gender;
+
+       /**
+        * First name
+        */
+       private String firstName;
+
+       /**
+        * Family name
+        */
+       private String familyName;
+
+       /**
+        * Company name
+        */
+       private String companyName;
+
+       /**
+        * Street
+        */
+       private String street;
+
+       /**
+        * House number
+        */
+       private Long houseNumber;
+
+       /**
+        * ZIP code
+        */
+       private Long zipCode;
+
+       /**
+        * City
+        */
+       private String city;
+
+       /**
+        * Phone number
+        */
+       private String phoneNumber;
+
+       /**
+        * Fax number
+        */
+       private String faxNumber;
+
+       /**
+        * Cellphone number
+        */
+       private String cellphoneNumber;
+
+       @Override
+       public String doCheckout () {
+               // Is the bean set?
+               if (this.basketController != null) {
+                       // Abort here
+                       throw new NullPointerException("basketController is null");
+               }
+
+               // Are at least the required fields set?
+               if (!this.isRequiredPersonalDataSet()) {
+                       // Not set, should not happen
+                       return "checkout2";
+               } else if (this.basketController.isEmpty()) {
+                       // Nothing to order
+                       return "empty_basket";
+               }
+
+               // Create customer instance
+               Customer customer = this.createCustomer();
+
+               // Get ordered list
+               List<AddableBasketItem> list = this.basketController.allItems();
+
+               // Construct container
+               WrapableCheckout wrapper = new CheckoutWrapper();
+               wrapper.setCustomer(customer);
+               wrapper.setList(list);
+
+               try {
+                       // Construct object message
+                       this.message.setObject(wrapper);
+
+                       // Send message
+                       this.messageProducer.send(this.message);
+               } catch (final JMSException ex) {
+                       // TODO: Log exception?
+                       // Not working
+                       return "jms_failed";
+               }
+
+               // Clear basket
+               this.basketController.clear();
+
+               // All fine
+               return "checkout_done";
+       }
+
+       @Override
+       public String getCellphoneNumber () {
+               return this.cellphoneNumber;
+       }
+
+       @Override
+       public void setCellphoneNumber (final String cellphoneNumber) {
+               this.cellphoneNumber = cellphoneNumber;
+       }
+
+       @Override
+       public String getCity () {
+               return this.city;
+       }
+
+       @Override
+       public void setCity (final String city) {
+               this.city = city;
+       }
+
+       @Override
+       public String getCompanyName () {
+               return this.companyName;
+       }
+
+       @Override
+       public void setCompanyName (final String companyName) {
+               this.companyName = companyName;
+       }
+
+       @Override
+       public String getFamilyName () {
+               return this.familyName;
+       }
+
+       @Override
+       public void setFamilyName (final String familyName) {
+               this.familyName = familyName;
+       }
+
+       @Override
+       public String getFaxNumber () {
+               return this.faxNumber;
+       }
+
+       @Override
+       public void setFaxNumber (final String 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;
+       }
+
+       @Override
+       public void setGender (final Gender gender) {
+               this.gender = gender;
+       }
+
+       @Override
+       public Long getHouseNumber () {
+               return this.houseNumber;
+       }
+
+       @Override
+       public void setHouseNumber (final Long houseNumber) {
+               this.houseNumber = houseNumber;
+       }
+
+       @Override
+       public String getPhoneNumber () {
+               return this.phoneNumber;
+       }
+
+       @Override
+       public void setPhoneNumber (final String phoneNumber) {
+               this.phoneNumber = phoneNumber;
+       }
+
+       @Override
+       public String getStreet () {
+               return this.street;
+       }
+
+       @Override
+       public void setStreet (final String street) {
+               this.street = street;
+       }
+
+       @Override
+       public Long getZipCode () {
+               return this.zipCode;
+       }
+
+       @Override
+       public void setZipCode (final Long zipCode) {
+               this.zipCode = zipCode;
+       }
+
+       @PostConstruct
+       public void init () {
+               // Call super init for getting resource bundle
+               super.genericInit();
+
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Get factory from JMS resource
+                       QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup("jms/shopConnectionFactory"); //NOI18N
+
+                       // Lookup queue
+                       this.queue = (Queue) context.lookup("jms/shopCheckoutQueue"); //NOI18N
+
+                       // Create connection
+                       this.connection = connectionFactory.createConnection();
+
+                       // Init session instance
+                       this.session = this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+                       // And message producer
+                       this.messageProducer = session.createProducer(queue);
+               } catch (final NamingException | JMSException e) {
+                       // Continued to throw
+                       throw new FacesException(e);
+               }
+       }
+
+       /**
+        * Destructor
+        */
+       @PreDestroy
+       public void destroy () {
+               try {
+                       // Try to close all
+                       this.messageProducer.close();
+                       this.session.close();
+                       this.connection.close();
+               } catch (final JMSException ex) {
+                       // TODO: Continue to throw is fine?
+                       throw new FacesException(ex);
+               }
+       }
+
+       /**
+        * Creates a full customer instance
+        *
+        * @return Customer instance
+        */
+       private Customer createCustomer () {
+               // Required personal data must be set
+               assert (this.isRequiredPersonalDataSet()) : "not all personal data is set";
+
+               // Create new customer instance
+               Customer customer = new ShopCustomer();
+               customer.setGender(this.getGender());
+               customer.setFirstName(this.getFirstName());
+               customer.setFamilyName(this.getFamilyName());
+               customer.setCompanyName(this.getCompanyName());
+               customer.setStreet(this.getStreet());
+               customer.setHouseNumber(this.getHouseNumber());
+               customer.setZipCode(this.getZipCode());
+               customer.setCity(this.getCity());
+               customer.setPhoneNumber(this.getPhoneNumber());
+               customer.setFaxNumber(this.getFaxNumber());
+               customer.setCellphoneNumber(this.getCellphoneNumber());
+
+               // Return it
+               return customer;
+       }
+
+       /**
+        * Checks if the required personal data is set
+        *
+        * @return Whether the required personal data is set
+        */
+       private boolean isRequiredPersonalDataSet () {
+               return ((this.getGender() != null) && (this.getFirstName() != null) && (this.getFamilyName() != null) && (this.getStreet() != null) && (this.getHouseNumber() != null) && (this.getZipCode() != null) && (this.getCity() != null));
+       }
+}
diff --git a/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebController.java b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebController.java
new file mode 100644 (file)
index 0000000..cd2f6ef
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.beans.checkout;
+
+import java.io.Serializable;
+import org.mxchange.jcore.model.contact.gender.Gender;
+
+/**
+ * An interface for the shop
+ *
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface CheckoutWebController extends Serializable {
+       /**
+        * Runs the actual checkout and returns a proper page redirection target.
+        * 
+        * @return Page redirection target
+        */
+       public String doCheckout ();
+
+       /**
+        * Getter for cellphone number
+        *
+        * @return Cellphone number
+        */
+       public String getCellphoneNumber ();
+
+       /**
+        * Setter for cellphone number
+        *
+        * @param cellphoneNumber Cellphone number
+        */
+       public void setCellphoneNumber (final String cellphoneNumber);
+
+       /**
+        * Getter for city
+        *
+        * @return Cellphone number
+        */
+       public String getCity ();
+
+       /**
+        * Setter for city
+        *
+        * @param city City
+        */
+       public void setCity (final String city);
+
+       /**
+        * Getter for company name
+        *
+        * @return City
+        */
+       public String getCompanyName ();
+
+       /**
+        * Setter for company name
+        *
+        * @param companyName Company name
+        */
+       public void setCompanyName (final String companyName);
+
+       /**
+        * Getter for family name
+        *
+        * @return Company name
+        */
+       public String getFamilyName ();
+
+       /**
+        * Setter for family name
+        *
+        * @param familyName Family name
+        */
+       public void setFamilyName (final String familyName);
+
+       /**
+        * Getter for fax number
+        *
+        * @return Family name
+        */
+       public String getFaxNumber ();
+
+       /**
+        * Setter for fax number
+        *
+        * @param faxNumber First name
+        */
+       public void setFaxNumber (final String faxNumber);
+
+       /**
+        * Getter for first name
+        *
+        * @return First name
+        */
+       public String getFirstName ();
+
+       /**
+        * Setter for first name
+        *
+        * @param firstName Gender
+        */
+       public void setFirstName (final String firstName);
+
+       /**
+        * Getter for gender
+        *
+        * @return Gender
+        */
+       public Gender getGender ();
+
+       /**
+        * Setter for gender
+        *
+        * @param gender Gender
+        */
+       public void setGender (final Gender gender);
+
+       /**
+        * Getter for house number
+        *
+        * @return House number
+        */
+       public Long getHouseNumber ();
+
+       /**
+        * Setter for house number
+        *
+        * @param houseNumber House number
+        */
+       public void setHouseNumber (final Long houseNumber);
+
+       /**
+        * Getter for phone number
+        *
+        * @return Phone number
+        */
+       public String getPhoneNumber ();
+
+       /**
+        * Setter for phone number
+        *
+        * @param phoneNumber Phone number
+        */
+       public void setPhoneNumber (final String phoneNumber);
+
+       /**
+        * Getter for street
+        *
+        * @return Street
+        */
+       public String getStreet ();
+
+       /**
+        * Setter for street
+        *
+        * @param street Street
+        */
+       public void setStreet (final String street);
+
+       /**
+        * Getter for ZIP code
+        *
+        * @return ZIP code
+        */
+       public Long getZipCode ();
+
+       /**
+        * Setter for ZIP code
+        *
+        * @param zipCode ZIP code
+        */
+       public void setZipCode (final Long zipCode);
+}
index 8b7deb7f6b16237ff6d5dbb7a9d11722f55c9e65..faef17d7b09f001ad30be562779475bc40381807 100644 (file)
@@ -34,7 +34,7 @@ import org.mxchange.jshopcore.model.product.Product;
 import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote;
 
 /**
- * Main application class
+ * General shop controller
  *
  * @author Roland Haeder<roland@mxchange.org>
  */
index d0dc5a073b5fb63fa3528d91aabbfeba0718ed06..6fd5a2ef5f650df21273f7e55c175f241efeceae 100644 (file)
@@ -46,7 +46,7 @@
 
                                                        <div class="table_footer">
                                                                <h:commandButton class="reset" type="reset" value="#{msg.BUTTON_RESET_FORM}" />
-                                                               <h:commandButton class="submit" type="submit" id="checkout" value="#{msg.BUTTON_COMPLETE_ORDER}" action="#{controller.doCheckout()}" />
+                                                               <h:commandButton class="submit" type="submit" id="checkout" value="#{msg.BUTTON_COMPLETE_ORDER}" action="#{checkoutController.doCheckout()}" />
                                                        </div>
                                                </div>
                                        </h:form>