1 37 38 package com.sun.j2ee.blueprints.opc.workflowmanager.handlers; 39 40 import java.rmi.*; 41 42 import javax.jms.*; 43 import javax.ejb.*; 44 45 import com.sun.j2ee.blueprints.opc.purchaseorder.*; 46 import com.sun.j2ee.blueprints.opc.orderreceiver.*; 47 import com.sun.j2ee.blueprints.opc.JNDINames; 48 import com.sun.j2ee.blueprints.processmanager.ejb.*; 49 import com.sun.j2ee.blueprints.servicelocator.*; 50 import com.sun.j2ee.blueprints.servicelocator.ejb.*; 51 import com.sun.j2ee.blueprints.opc.financial.*; 52 import com.sun.j2ee.blueprints.opc.utils.*; 53 import com.sun.j2ee.blueprints.opc.mailer.*; 54 55 63 public class POHandler { 64 65 private ProcessManagerLocal processManager; 66 private ServiceLocator sl; 67 private POReceiver poReceiver; 68 private CreditCardVerifier cardVerifier; 69 70 public POHandler()throws HandlerException { 71 try{ 72 sl = new ServiceLocator(); 73 cardVerifier = new CreditCardVerifier(); 74 poReceiver = new POReceiver(); 75 ProcessManagerLocalHome pmHome = (ProcessManagerLocalHome)sl.getLocalHome(JNDINames.PM_EJB); 76 processManager = pmHome.create(); 77 } catch (Exception exe) { 78 System.err.println(exe); 79 throw new HandlerException("OPC Exception creating POHandler"); 80 } 81 } 82 83 public void handle(Message message) throws HandlerException { 84 85 PurchaseOrder po = null; 86 String poID = null; 87 String emailID = null; 88 boolean sendMail = sl.getBoolean(JNDINames.SEND_MAIL); 89 90 try { 92 if(message instanceof ObjectMessage){ 93 ObjectMessage objMsg = (ObjectMessage) message; 94 po = (PurchaseOrder)objMsg.getObject(); 95 } 96 if(po != null){ 97 poID = po.getPoId(); 98 emailID = po.getEmailId(); 99 poReceiver.persistPO(po); 101 String lodgOrderStatus = po.getLodging() == null 102 ? OrderStatusNames.COMPLETED 103 : OrderStatusNames.PENDING; 104 String actyOrderStatus = po.getActivities().length == 0 105 ? OrderStatusNames.COMPLETED 106 : OrderStatusNames.PENDING; 107 String airlineOrderStatus = (po.getDepartureFlightInfo() == null) 108 && (po.getReturnFlightInfo() == null) 109 ? OrderStatusNames.COMPLETED 110 : OrderStatusNames.PENDING; 111 processManager.createManager(poID, OrderStatusNames.PENDING, 112 actyOrderStatus, airlineOrderStatus, 113 lodgOrderStatus); 114 115 String creditCardXML = po.getCreditCard().toXML(); 117 boolean ccStatus = cardVerifier.verifyCreditCard(creditCardXML); 118 119 if (ccStatus){ 122 processManager.updateStatus(poID, OrderStatusNames.APPROVED); 123 if(sendMail){ 125 String subject = "Your Adventure Builder order has been approved"; 126 String msg = "Your order (# " + poID + " ) has been approved."; 127 msg += " Thank you for shopping with us and we hope to see you again soon"; 128 sendMail(emailID, subject, msg); 129 } 130 if (JMSUtils.sendMessage(JNDINames.ORDER_FILLER_MDB_QUEUE, 132 JNDINames.DOC_TYPE, JNDINames.PO_DOCUMENT, 133 (Object )po) == false){ 134 processManager.updateStatus(poID, OrderStatusNames.ORDER_FILLER_ERROR); 135 processManager.updateOrderErrorStatus(poID, true); 136 } else { 137 processManager.updateStatus(poID, OrderStatusNames.SUBMITTED); 138 } 139 } else { 140 processManager.updateStatus(poID, OrderStatusNames.DENIED); 141 if(sendMail){ 143 String subject = "Your Adventure Builder order has been denied"; 144 String msg = "Your order (# " + poID + " ) has been denied. "; 145 msg += " Thank you for shopping with us and we hope to see you again soon"; 146 sendMail(emailID, subject, msg); 147 } 148 } 149 } 150 } catch (CreateException ce) { 151 if(sendMail){ 153 String subject = "Problems processing your Adventure Builder order"; 154 String msg = "We had problems processing your Adventure Builder order."; 155 msg += " Please resubmit the order"; 156 sendMail(emailID, subject, msg); 157 } 158 } catch (RemoteException re) { 159 try{ 161 processManager.updateStatus(poID,OrderStatusNames.PAYMENT_PROCESSING_ERROR); 162 processManager.updateOrderErrorStatus(poID, true); 163 } catch(FinderException fe){ 164 System.err.println(fe); 165 } 166 } catch (Exception exe) { 167 System.err.println(exe); 168 throw new HandlerException("OPC Exception handling PO"); 169 } 170 } 171 172 private void sendMail(String emailID, String subject, String msg){ 173 Mail mail = new Mail(emailID, subject, msg); 174 String xmlMail = mail.toXML(); 175 JMSUtils.sendMessage(JNDINames.CRM_MDB_QUEUE, 176 JNDINames.DOC_TYPE, JNDINames.MAIL_DOCUMENT, 177 xmlMail); 178 } 179 } 180 | Popular Tags |