private void sendEMail(TradeRqmtRec trr) throws SQLException {

    if (_TRADER_NOTIFY_STATUS.equalsIgnoreCase(trr.getNextStatusCode())) {

      String fromName = "OpsManager";
      String fromAddress = "*****@*****.**";
      String emailAddress = dao.getTraderEmailAddr(trr);
      String subject = "Confirmation Pending: " + trr.getTradeId();
      String body =
          "There is a new confirmation waiting for your approval.\n"
              + "Trade Id: "
              + trr.getTradeId()
              + "\n"
              + "Counterparty: "
              + trr.getCptySn()
              + "\n"
              + "Commodity: "
              + trr.getCdtyGroupCode()
              + "\n"
              + "To approve the trade go to: "
              + traderWebUrl;

      if (!"SEMPRA.PROD".equalsIgnoreCase(this.database)) {
        body = body + "\n Original email address = " + emailAddress;
        emailAddress = "*****@*****.**";
      }

      if (emailAddress != null) {
        NotifyUtil.sendMail(emailAddress, subject, body);
      }
    }
  }
  private CreditLogRec updateCreditMarginInVault(
      String tradingSystem, long tradeId, int version, String tokenStatus)
      throws IOException, NamingException, BadLocationException, SQLException {

    CreditLogRec clr = new CreditLogRec();
    clr.setTradeId(tradeId);
    clr.setProcessFlag("N");
    clr.setCmt("No Record Found");
    TradeRqmtRec trr = dao.getTradeConfirmId(tradingSystem, tradeId, version);
    if (trr.getTradeRqmtConfirmId() > 0) {
      String creditMarginToken = "";
      if ("Y".equalsIgnoreCase(tokenStatus)) {
        creditMarginToken = getCreditMarginToken(tradingSystem, tradeId, version);
      }
      Logger.getLogger(CreditMarginProcessor.class)
          .info("Trade Id = " + tradeId + "; Token = " + creditMarginToken);
      ContractRequest cr = new ContractRequest();
      cr.setTradeRqmtConfirmId(trr.getTradeRqmtConfirmId());
      ContractResponse response = confirmation.getContractFromVault(cr, dbUserName);
      // update the vault only if the contract in the vault
      if (response.getContract() != null & !"".equalsIgnoreCase(response.getContract())) {
        String marginInsertedContract =
            rtfInserter.insertMarginToken(
                response.getContract(), creditMarginToken, marginToken, clr);
        storeContractInVault(trr, marginInsertedContract);
        if ("CRDT".equalsIgnoreCase(trr.getCurrentStatus())) {
          dao.updateTradeRqmtStatus(trr);
          sendEMail(trr);
        }
        clr.setProcessFlag("Y");
      } else {
        clr.setCmt("No Contract Found in the Vault");
      }

    } else {
      Logger.getLogger(this.getClass())
          .info("No Rqmt confirm id found in db for the trade " + tradeId);
    }
    return clr;
  }
  public void processCreditMarginNotification(
      String tradingSystem, long tradeId, int version, String msg)
      throws IOException, NamingException, BadLocationException, SQLException {

    if (confirmation == null) {
      createContractEJB();
    }
    String tradeStatus = "";
    tradeStatus = getStatusFromCredit(tradingSystem, tradeId, version);
    CreditLogRec clr = updateCreditMarginInVault(tradingSystem, tradeId, version, tradeStatus);
    clr.setMsg(msg);
    dao.insertIntoLog(clr);
  }