📄 trademanagementhelper.java
字号:
aInfo = umh.getAccountInfo(accountNo);
} catch(Exception ex) {
throw new TradeManagementEventException(
"Exception while getting Account information: " + ex.toString());
}
return aInfo;
}
/**
* This method is registered in control.xml and will be called in the
* controller servlet using Reflection to get the values required to be
* displayed in the JSP invoked by the client. This method calls the
* methods in the same class to get the Trade Details and Account Information.
* This then creates a Hashmap of the retrieved values and returns it to the
* calling JSP where it is displayed.
*
* @param req HttpServletRequest
* @return The Hashmap containing the Portfolio Information,
* Portfolio Valuation Information and User Account Information
* @exception TradeManagementEventException
* @since 1.0
*/
public HashMap populateTradeDetails(HttpServletRequest req)
throws TradeManagementEventException {
HashMap hm = new HashMap();
// The User Account Number is retrieved from the session attribute
Integer acctNo = (Integer)req.getSession().getAttribute("LOGIN.RESPONSE");
// Access the method of the Session Bean and set the values in the Hashmap
AccountInfo acInfo = (AccountInfo)getAccountInfo(acctNo);
String recordNum = req.getParameter("RECORDNUM");
if (recordNum == null) recordNum = "1";
hm.put("ACCOUNTINFO", acInfo);
hm.put("TRADEDETAILSINFO",
getTradeDetailsInfo(acctNo, recordNum,
acInfo.getLinesPerPage().intValue()));
return hm;
}
/**
* This method is called when the user buys stock using the application.
* The User Account Number is obtained from the session of the user's request.
* The Symbol and Quantity traded are obtained from the request parameters.
* StockSymbolHelper is used to check if the symbol is traded here.
* UserManagementHelper is used to get the Contact Information of the
* logged in user. This method calls the method in
* TradeManagementSessionFacadeBean to carry out the buy transaction.
*
* @param req HttpServletRequest
* @exception ApplicationError When an application specific error
* message needs to be thrown and handled
* @exception TradeManagementEventException
* @since 1.0
*/
public void buyStock(HttpServletRequest req)
throws ApplicationError, TradeManagementEventException {
String retMessage = "FAILURE";
// Get user account number from the session of user's request
Integer accountNo = (Integer)req.getSession().getAttribute("LOGIN.RESPONSE");
// Get the quantity from the request parameters
String qty = req.getParameter("QUANTITY").trim();
if ((qty == null) || (qty == "")) {
throw new ApplicationError("Quantity should be entered");
}
Integer quantity = null;
try {
quantity = new Integer(qty.trim());
} catch (NumberFormatException nfe) {
throw new ApplicationError("Quantity should be a number");
}
if (quantity.intValue() <= 0) {
throw new ApplicationError("Quantity should be greater than zero");
}
// Get the symbol from the request parameters
String symbol = req.getParameter("SYMBOL").trim().toUpperCase();
if ((symbol == null) || (symbol == "")) {
throw new ApplicationError("Symbol should be entered");
}
boolean isTraded = false;
try {
// Get the isTraded flag from the StockSymbolHelper
isTraded = ssh.isTradedHere(symbol);
} catch(AdminHelperException ex) {
throw new TradeManagementEventException(
"Exception while getting isTraded flag: " + ex.toString());
}
ContactInfo cInfo = null;
try {
// Get the Contact Information of the User, email id is required!
cInfo = umh.getContactInfo(accountNo);
} catch(Exception ex) {
throw new TradeManagementEventException(
"Exception while getting User's Contact Info : " + ex.toString());
}
Date sysDate = new Date(); // Current Date
try {
// Call the method in TradeManagementSessionFacadeBean
// to carry out the buy transaction
retMessage = rmr.buyStock(accountNo, quantity, symbol,
isTraded, cInfo.getEmail(), connHash,
DateFormatter.getStringFromDate(sysDate,
"yyyy.MM.dd hh:mm:ss a zzz"));
} catch(SQLException re) {
throw new TradeManagementEventException(
"SQL Exception while calling buy stock : " + re.toString());
} catch(RemoteException re) {
throw new TradeManagementEventException(
"Remote Exception while calling buy stock : " + re.toString());
}
if (retMessage.equals("SUCCESS")) {
StringBuffer sb = new StringBuffer();
sb.append("Transaction completed. ");
sb.append(quantity);
sb.append(" stocks of '");
sb.append(symbol);
sb.append("' added to your Portfolio ");
req.setAttribute("InfoMessage", sb.toString());
} else {
throw new ApplicationError(retMessage);
}
}
/**
* This method is used by the AdminHelper to transfer stocks from a corporate
* to an individual. StockSymbolHelper is used to check if the symbol is
* traded here. UserManagementHelper is used to get the Contact Information
* of the logged in user. This method calls the method in
* TradeManagementSessionFacadeBean to carry out the transfer of stocks to
* the input Account Number.
*
* @param toAccountNumber Account Number to which Stocks are transfered
* @param symbol Stock Symbol
* @param qty Quantity
* @param price Price
* @return An integer indicating success or failure,
* 0 indicates success and -1 indicates failure
* @exception TradeManagementEventException
* @since 1.0
*/
public Integer corporateTransfer(Integer toAccountNumber, String symbol,
Integer qty, Float price)
throws ApplicationError, TradeManagementEventException {
Integer nextTradeId = new Integer("0");
boolean isTraded = false;
try {
// Get the isTraded flag from the StockSymbolHelper
isTraded = ssh.isTradedHere(symbol);
} catch(AdminHelperException ex) {
throw new TradeManagementEventException(
"Exception while getting isTraded flag: " + ex.toString());
}
ContactInfo cInfo = null;
try {
// Get the Contact Information of the User, email id is required!
cInfo = umh.getContactInfo(toAccountNumber);
} catch(Exception ex) {
throw new TradeManagementEventException(
"Exception while getting User's Contact Info : " + ex.toString());
}
Date sysDate = new Date(); // Current Date
try {
// Call the method in TradeManagementSessionFacadeBean
// to carry out the corporate transfer
nextTradeId = rmr.corporateTransfer(toAccountNumber, symbol, qty, price,
isTraded, cInfo.getEmail(), connHash,
DateFormatter.getStringFromDate(
sysDate, "yyyy.MM.dd hh:mm:ss a zzz"));
} catch(RemoteException re) {
throw new TradeManagementEventException(
"Remote Exception while calling corporate transfer : " + re.toString());
}
return nextTradeId;
}
/**
* This method is used when the user sells stock using the application.
* The User Account Number is obtained from the session of the user's request.
* The Sell Quantity, Line Numbers, Symbols, Trade Id are obtained from the
* request parameters. StockSymbolHelper is used to check if the symbol is
* traded here. UserManagementHelper is used to get the Contact Information
* of the logged in user. This method calls the method in
* TradeManagementSessionFacadeBean to carry out the sell transaction of stocks.
*
* @param req HttpServletRequest
* @return The return message is a string which contains details
* about the failure or success of the sell transactions.
* @exception TradeManagementEventException
* @since 1.0
*/
public String sellStock(HttpServletRequest req)
throws ApplicationError, TradeManagementEventException {
Integer accountNo = (Integer)req.getSession().getAttribute("LOGIN.RESPONSE");
String[] qtyValues = req.getParameterValues("SELLQTY");
String[] lineNos = req.getParameterValues("LINENO");
String[] symbols = req.getParameterValues("SYMBOL");
String[] tradeId = req.getParameterValues("TRADEID");
Date sysDate = new Date();
String retMessage = "FAILURE";
String isTradedFlag[] = new String[lineNos.length];
try {
for(int i = 0;i < lineNos.length;i++) {
// Get the isTraded flag for the symbol from StockSymbolHelper
boolean isTraded = ssh.isTradedHere(symbols[i]);
// Set the isTradedFlag array to 'Y' or 'N'
// depending on whether isTraded is 'true' or 'false'
if (isTraded) {
isTradedFlag[i] = new String("Y");
} else {
isTradedFlag[i] = new String("N");
}
}
} catch(AdminHelperException ex) {
throw new TradeManagementEventException(
"Exception while getting isTraded flag: " + ex.toString());
}
ContactInfo cInfo = null;
try {
// Get the Contact Information of the User, email id is required!
cInfo = umh.getContactInfo(accountNo);
} catch(Exception ex) {
throw new TradeManagementEventException(
"Exception while getting User's Contact Info : " + ex.toString());
}
try {
// Call the method in TradeManagementSessionFacadeBean
// to carry out the sell transactions
retMessage =
rmr.sellStock(accountNo, qtyValues, lineNos, symbols,
tradeId, isTradedFlag, cInfo.getEmail(), connHash,
DateFormatter.getStringFromDate(sysDate,
"yyyy.MM.dd hh:mm:ss a zzz"));
} catch(SQLException re) {
throw new TradeManagementEventException(
"SQL Exception while calling sell stock : " + re.toString());
} catch(RemoteException re) {
throw new TradeManagementEventException(
"Remote Exception while calling sell stock : " + re.toString());
}
return retMessage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -