1 37 38 package com.sun.j2ee.blueprints.opc.workflowmanager.handlers; 39 40 import javax.jms.*; 41 42 import com.sun.j2ee.blueprints.opc.invoice.*; 43 import com.sun.j2ee.blueprints.opc.*; 44 import com.sun.j2ee.blueprints.processmanager.ejb.*; 45 import com.sun.j2ee.blueprints.servicelocator.*; 46 import com.sun.j2ee.blueprints.servicelocator.ejb.*; 47 import com.sun.j2ee.blueprints.opc.purchaseorder.ejb.*; 48 import com.sun.j2ee.blueprints.opc.utils.*; 49 import com.sun.j2ee.blueprints.opc.JNDINames; 50 import com.sun.j2ee.blueprints.opc.mailer.*; 51 52 57 public class InvoiceHandler { 58 59 private ProcessManagerLocal processManager; 60 private ServiceLocator sl; 61 62 public InvoiceHandler() throws HandlerException { 63 try{ 64 sl = new ServiceLocator(); 65 ProcessManagerLocalHome pmHome = 66 (ProcessManagerLocalHome)sl.getLocalHome(JNDINames.PM_EJB); 67 processManager = pmHome.create(); 68 } catch (Exception exe) { 69 System.err.println(exe); 70 throw new HandlerException("OPC Exception creating InvoiceHandler"); 71 } 72 } 73 74 public void handle(Message message) throws HandlerException { 75 Invoice invoice = null; 76 String inv = null; 77 String opcPoID = null; 78 79 try { 81 if(message instanceof TextMessage){ 82 TextMessage txtMsg = (TextMessage) message; 83 inv = txtMsg.getText(); 84 } 85 if(inv != null){ 86 invoice = Invoice.fromXML(inv); 87 String supplierID = invoice.getSupplierId(); 88 opcPoID = invoice.getOpcPoId(); 89 String invStat = invoice.getStatus(); 90 if(supplierID.equals(JNDINames.ACTIVITY_INVOICE)) 91 processManager.updateActivityOrderStatus(opcPoID, invStat); 92 if(supplierID.equals(JNDINames.LODGING_INVOICE)) 93 processManager.updateLodgingOrderStatus(opcPoID, invStat); 94 if(supplierID.equals(JNDINames.AIRLINE_INVOICE)) 95 processManager.updateAirlineOrderStatus(opcPoID, invStat); 96 } 97 } catch (XMLException exe) { 98 System.err.println(exe); 99 try{ 101 107 processManager.updateStatus(opcPoID,OrderStatusNames.INVOICE_XML_ERROR); 108 processManager.updateOrderErrorStatus(opcPoID, true); 109 } catch(Exception xe){ 110 System.err.println(xe); 111 } 112 } catch (Exception exe) { 113 System.err.println(exe); 114 throw new HandlerException("OPC Exception handling invoice"); 115 } 116 } 117 118 public void sendOrderCompletedMail(String orderID) throws HandlerException{ 119 boolean sendMail = sl.getBoolean(JNDINames.SEND_MAIL); 120 try{ 121 if(sendMail){ 123 PurchaseOrderLocalHome poHome = 124 (PurchaseOrderLocalHome)sl.getLocalHome(JNDINames.PO_EJB); 125 PurchaseOrderLocal poLocal = poHome.findByPrimaryKey(orderID); 126 String msg = "Your order (# " + orderID + " ) has been completed."; 127 msg += " Thank you for shopping with us and we hope to see you again soon"; 128 Mail mail = new Mail(poLocal.getEmailId(), 129 " Your Adventure Builder order has been completed ", msg); 130 String xmlMail = mail.toXML(); 131 JMSUtils.sendMessage(JNDINames.CRM_MDB_QUEUE, 132 JNDINames.DOC_TYPE, JNDINames.MAIL_DOCUMENT, xmlMail); 133 } 134 } catch (Exception exe) { 135 System.err.println(exe); 136 throw new HandlerException("OPC Exception sending mail"); 137 } 138 139 } 140 } 141 | Popular Tags |