/*
- * Copyright (C) 2016 Roland Haeder
+ * Copyright (C) 2016 - 2024 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
import javax.faces.FacesException;
import javax.inject.Inject;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
-import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.jshopcore.events.ObservableCheckoutCompletedEvent;
+import org.mxchange.jshopcore.events.ShopCheckoutCompletedEvent;
import org.mxchange.jshopcore.model.basket.AddableBasketItem;
import org.mxchange.jshopcore.wrapper.CheckoutWrapper;
import org.mxchange.jshopcore.wrapper.WrapableCheckout;
+import org.mxchange.pizzaapplication.beans.BasePizzaBean;
import org.mxchange.pizzaapplication.beans.basket.PizzaBasketWebSessionController;
+import org.mxchange.pizzaapplication.beans.contact.PizzaContactWebRequestController;
import org.mxchange.pizzaapplication.beans.customer.PizzaCustomerWebSessionController;
-import org.mxchange.pizzaapplication.beans.receipt.PizzaReceiptWebSessionController;
+import org.mxchange.pizzaapplication.beans.helper.PizzaWebRequestHelperController;
+import org.mxchange.pizzaapplication.beans.receipt.PizzaReceiptWebRequestController;
/**
* Checkout controller
* <p>
- * @author Roland Haeder<roland@mxchange.org>
+ * @author Roland Hรคder<roland@mxchange.org>
*/
@Named ("checkoutController")
@SessionScoped
-public class PizzaCheckoutWebSessionBean implements PizzaCheckoutWebSessionController {
+public class PizzaCheckoutWebSessionBean extends BasePizzaBean implements PizzaCheckoutWebSessionController {
/**
* Serial number
*/
private static final long serialVersionUID = 51_987_348_347_183L;
- ////////////////////// Bean injections ///////////////////////
/**
* Basket bean
*/
@Inject
private PizzaBasketWebSessionController basketController;
+ /**
+ * Bean helper instance
+ */
+ @Inject
+ private PizzaWebRequestHelperController beanHelper;
+
+ /**
+ * Event fired when a checkout was completed by the user
+ */
+ @Inject
+ @Any
+ private Event<ObservableCheckoutCompletedEvent> checkoutCompletedEvent;
+
/**
* Connection
*/
private Connection connection;
/**
- * Customer instance
+ * Contact controller
*/
- private Customer customer;
+ @Inject
+ private PizzaContactWebRequestController contactController;
/**
* Customer bean
* Receipt bean
*/
@Inject
- private PizzaReceiptWebSessionController receiptController;
+ private PizzaReceiptWebRequestController receiptController;
/**
* Session instance
this.session.close();
this.connection.close();
} catch (final JMSException ex) {
- // TODO: Continue to throw is fine?
+ // @TODO: Continue to throw is fine?
throw new FacesException(ex);
}
}
@Override
public String doCheckout () {
- // Trace message
- //this.getLogger().logTrace("doCheckout: CALLED!");
-
// Are the beans set?
if (null == this.basketController) {
// Abort here
}
// Are at least the required fields set?
- if (!this.customerController.isRequiredPersonalDataSet()) {
- // Trace message
- //this.getLogger().logTrace("doCheckout: Not all required fields are set, returning checkout2 ... - EXIT!");
-
+ if (!this.contactController.isRequiredPersonalDataSet()) {
// Not set, should not happen
return "checkout2"; //NOI18N
} else if (this.basketController.isEmpty()) {
- // Trace message
- //this.getLogger().logTrace("doCheckout: basket is empty, returning empty_basket ... - EXIT!");
-
// Nothing to order
return "empty_basket"; //NOI18N
}
// Create customer instance
this.setCustomer(this.customerController.createCustomerInstance());
- // Debug message
- //this.getLogger().logDebug(MessageFormat.format("doCheckout: customer={0}", this.getCustomer()));
// Get ordered list
List<AddableBasketItem> list = this.basketController.allItems();
- // Debug message
- //this.getLogger().logTrace(MessageFormat.format("doCheckout: list={0}", list));
// Construct container
WrapableCheckout wrapper = new CheckoutWrapper();
- wrapper.setCustomer(this.getCustomer());
+ wrapper.setCustomer(this.beanHelper.getCustomer());
wrapper.setList(list);
try {
// Send message
this.messageProducer.send(this.message);
} catch (final JMSException ex) {
- // TODO: Log exception?
+ // @TODO: Log exception?
// Not working
return "jms_failed"; //NOI18N
}
- // Clear basket
- this.basketController.clear();
-
- // Set customer in receipt controller for verification
- this.receiptController.setCustomer(this.getCustomer());
+ // Fire event
+ this.checkoutCompletedEvent.fire(new ShopCheckoutCompletedEvent(wrapper));
// All fine
return "checkout_done"; //NOI18N
}
- @Override
- public Customer getCustomer () {
- return this.customer;
- }
-
- @Override
- public void setCustomer (final Customer customer) {
- this.customer = customer;
- }
-
/**
* Initialization of this bean
*/
throw new FacesException(e);
}
}
+
}