From 373ba806e6fd2caa62e330c73b64997bb851fd50 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 15 Sep 2015 15:28:10 +0200 Subject: [PATCH] =?utf8?q?Continued:=20-=20added=20"checkout=20bean"=20for?= =?utf8?q?=20handling=20the=20"guest=20checkout"=20(no=20registration)=20-?= =?utf8?q?=20other=20improvements=20-=20updated=20jshop-core.jar=20Signed-?= =?utf8?q?off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/jshop-core.jar | Bin 26726 -> 29304 bytes .../beans/basket/BasketWebBean.java | 7 + .../beans/basket/BasketWebController.java | 5 + .../beans/checkout/CheckoutWebBean.java | 384 ++++++++++++++++++ .../beans/checkout/CheckoutWebController.java | 188 +++++++++ .../beans/controller/ShopWebBean.java | 2 +- web/customer/checkout2.xhtml | 2 +- 7 files changed, 586 insertions(+), 2 deletions(-) create mode 100644 src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebBean.java create mode 100644 src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebController.java diff --git a/lib/jshop-core.jar b/lib/jshop-core.jar index 88013336b02c1d795fa399a67766638609d6b5a4..ffdfed6b8336dff31017701d431501ef76f74c2c 100644 GIT binary patch delta 4334 zcmbtXdu*Fm6+id0ozHf@*pB1GN$kdX$4=5XujbLTc{OdGThpdZw{CejuIr{vn=FsD zWh+@WI$qNXy9jOBU<`slLMlwAFeXt|JPM35HlYDRXmo;26Wdq^f2wY-4cr~@FD*{b_=l!X919&9nqFAcpd2dr z=Uny1YWSE2yJ48WSk_ajK{Yg~aE}J}!Wj*=L%Rkahh;?9;69qH!2SH%mO_51G&e(q zQyL7w{Tft46+h{&aaO|v8hiq7)u019H8@KcBe0o2<*nc^yS20jHTWd7N3OYt+4fCn zNd|?WgM280VjP#CGbm6BcG3;!UNQICatR;DCeWjLn{lOvpD8Hn@*~ZH@_;lw_`wRb z_y^FC1JGu5P>+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qowvxN_;SJ6 z&m-IuBZ@qV&pG_bJ#*rUJh*Q*+%k^x>rL5)W->BYb&C`HYW4Z@-|c{SWQNJDEqCn_ zwYBr@EIGNg%qlO9q-azj_P81 zk;o%w?YB2>bNb?0z!jVNok}!nDQ7!fvsvj~i<>U(^hi)!Q*8gg3=mIr3c>PJ;;8ij zP(HN|835P&_pE!k7sS(*0k~>U1NJ$JDHQX_XfF%})UTas(+YP{+SC>cs7JhPDi@ar z75cL2cq*Cu*DCmHx&J$rNK9iu6`jb_=w{4_Dcz)^NALS`65$eduBSUG)<1eTA3w)u zf_O4nkCw|Yj#RjWvkd(ET>wu z(~=QGbwiqCR%0&xJ#5h5VV?3PY5KU?O|_A1T0UZ!HjM<-+K4n=o0m%;jTl>GG-}2c zgUu9esTakQAr|irsK+{3RYBW#=Sx+BRpDil@`T4i;chpzj_N_tH;X*K=n+1{#3K%z qso$wYGby7+doCLds24V*;7*$8%bwP=G%H)U2Kk@MpH9mrvHBmMtKgRa diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java index 09f4e10c..213cc924 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java @@ -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; diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java index 46d5b40c..5421d9a1 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java @@ -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 index 00000000..21d2738f --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebBean.java @@ -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 . + */ +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 + */ +@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 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 index 00000000..cd2f6efa --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/beans/checkout/CheckoutWebController.java @@ -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 . + */ +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 + */ +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); +} diff --git a/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebBean.java index 8b7deb7f..faef17d7 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/controller/ShopWebBean.java @@ -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 */ diff --git a/web/customer/checkout2.xhtml b/web/customer/checkout2.xhtml index d0dc5a07..6fd5a2ef 100644 --- a/web/customer/checkout2.xhtml +++ b/web/customer/checkout2.xhtml @@ -46,7 +46,7 @@ -- 2.39.5