Methods Summary |
---|
private void | cancelOrder(xpetstore.domain.order.ejb.Order order)
order.changeStatus( OrderStatus.CANCELLED );
notifyCustomer( order );
|
private void | notifyCustomer(xpetstore.domain.order.ejb.Order order)
Customer customer = order.getCustomer( );
if ( customer == null)
{
Debug.print( "No customer to notify" );
return;
}
String to = customer.getEmail( );
String subject = "[Petstore] Order Confirmation";
String body = toHtml( order );
JMSUtil.sendToJMSQueue( JNDINames.QUEUE_MAIL, new Email( to, subject, body ), false );
|
public void | onMessage(javax.jms.Message recvMsg)This method expect a javax.jms.ObjectMessage that
contains the orderUId as the message object
Integer orderUId = null;
Order order = null;
try
{
Debug.print( "OrderProcessorMDB.onMessage(" + recvMsg + ")" );
/* Get the order to proceed */
ObjectMessage msg = ( ObjectMessage ) recvMsg;
orderUId = ( Integer ) msg.getObject( );
order = manager.find( Order.class, orderUId );
/* Proceed the order */
proceedPayment( order );
proceedOrder( order );
}
catch ( CreditCardException c )
{
try
{
cancelOrder( order );
}
catch ( Exception e )
{
Debug.print( "Unable to cancel the order[" + orderUId + "]", e );
}
}
catch ( Exception e )
{
Debug.print( "Unable to proceed the order[" + orderUId + "]", e );
}
|
private void | proceedOrder(xpetstore.domain.order.ejb.Order order)
order.changeStatus( OrderStatus.TO_DELIVER );
notifyCustomer( order );
|
private void | proceedPayment(xpetstore.domain.order.ejb.Order order)
|
private java.lang.String | toHtml(xpetstore.domain.order.ejb.Order order)
StringBuffer buff = new StringBuffer( );
/* Id/Status */
buff.append( "<table border='1' width='100%'>" );
buff.append( "<tr><td width='10%'><b>Order ID:</b></td><td>" + order.getOrderUId( ) + "</td></tr>" );
buff.append( "<tr><td width='10%'><b>Status:</b></td><td>" + order.getStatus( ) + "</td></tr>" );
buff.append( "</table>" );
/* Shipping/Bill address Address */
buff.append( "<table border='1' width='100%'><tr>" );
buff.append( "<td width='10%' valign='top'><b>Address:</b></td>" );
buff.append( "<td>" );
buff.append( order.getStreet1( ) + "<br>" );
buff.append( order.getStreet2( ) + "<br>" );
buff.append( order.getCity( ) + "," + order.getState( ) + "<br>" );
buff.append( order.getZipcode( ) + "<br>" );
buff.append( order.getCountry( ) );
buff.append( "</td>" );
buff.append( "</tr></table>" );
/* Items */
Collection orderItems = order.getOrderItems( );
buff.append( "<table border='1' width='100%'>" );
buff.append( "<tr>" );
buff.append( "<th bgcolor='#c0c0c0'>ID</td>" );
buff.append( "<th bgcolor='#c0c0c0'>Description</th>" );
buff.append( "<th bgcolor='#c0c0c0'>Unit Price</th>" );
buff.append( "<th bgcolor='#c0c0c0'>Quantity</th>" );
buff.append( "<th bgcolor='#c0c0c0'> </th>" );
buff.append( "</tr>" );
for ( Iterator it = orderItems.iterator( ); it.hasNext( ); )
{
OrderItem orderItem = ( OrderItem ) it.next( );
buff.append( toHtml( orderItem ) );
}
buff.append( "<tr>" );
buff.append( "<td colspan=4 align=right bgcolor='#c0c0c0'>TOTAL:</td>" );
buff.append( "<td bgcolor='#c0c0c0'><b>" + order.calculateTotal( ) + "<b></td>" );
buff.append( "</tr>" );
buff.append( "</table>" );
return buff.toString( );
|
private java.lang.String | toHtml(xpetstore.domain.order.ejb.OrderItem orderItem)
StringBuffer buff = new StringBuffer( );
buff.append( "<tr>" );
buff.append( "<td>" + orderItem.getItem( ).getItemId( ) + "</td>>" );
buff.append( "<td>" + orderItem.getItem( ).getDescription( ) + "<br>" );
buff.append( "<td>" + orderItem + "</td>" );
buff.append( "<td>" + orderItem + "</td>" );
buff.append( "<td>" + orderItem.calculateSubTotal( ) + "</td>" );
buff.append( "</tr>" );
return buff.toString( );
|