private CustomOrderBean createOrder(String orderType, String userID,
int holdingID, String symbol, double quantity,
CustomHoldingBean holding) throws DAOException {
CustomOrderBean order = null;
OrderDAO orderDAO = factory.getOrderDAO();
if (StockTraderUtility.ORDER_TYPE_SELL.equals(orderType)) {
// CHECKME holding is the argument
holding = orderDAO.getHolding(holdingID);
if (holding == null) {
throw new DAOException("No holding entry found for HoldingID<"
+ holdingID + ">");
}
order = orderDAO.createOrder(userID, holding.getQuoteID(),
StockTraderUtility.ORDER_TYPE_SELL, holding.getQuantity(),
holdingID);
} else if (StockTraderUtility.ORDER_TYPE_SELL_ENHANCED
.equals(orderType)) {
holding = orderDAO.getHolding(holdingID);
if (holding == null) {
throw new DAOException("No holding entry found for HoldingID<"
+ holdingID + ">");
}
if (quantity > holding.getQuantity()) {
order = orderDAO.createOrder(userID, holding.getQuoteID(),
StockTraderUtility.ORDER_TYPE_SELL, holding
.getQuantity(), holdingID);
} else {
order = orderDAO
.createOrder(userID, holding.getQuoteID(),
StockTraderUtility.ORDER_TYPE_SELL, quantity,
holdingID);
}
} else if (StockTraderUtility.ORDER_TYPE_BUY.equals(orderType)) {
order = orderDAO.createOrder(userID, symbol,
StockTraderUtility.ORDER_TYPE_BUY, quantity, -1);
} else {
throw new IllegalArgumentException("Invalid orderType<" + orderType
+ ">");
}