usermanagementhelper.java
来自「Oracle的J2EE Sample」· Java 代码 · 共 1,235 行 · 第 1/4 页
JAVA
1,235 行
public String changePreferenceInfo(HttpServletRequest req)
throws UserManagementEventException {
// Get the Symbol for which Preferences Need to be changed
String symbol = req.getParameter("SYMBOL").toUpperCase();
// Get the Account Number
Integer accountNo =
(Integer) req.getSession().getAttribute("LOGIN.RESPONSE");
String retMessage = "NOSUCCESS";
// Check Whether the Preference corresponding to given Symbol
// need not be deleted
if (req.getParameter("DELFLAG").equals("NO")) {
// Initialize a new PreferencesInfo Value Object
PreferencesInfo pInfo = new PreferencesInfo(symbol,
req.getParameter("PREFTYPE"));
try {
// Using UserManagementSessionFacadeBean, change PreferencesInfo
retMessage = rmr.changePreferencesInfo(accountNo, pInfo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while changing preferences info : "
+ re.toString());
}
} else {
// If this preference need to be deleted
if (req.getParameter("DELFLAG").equals("YES")) {
try {
// Using UserManagementSessionFacadeBean,
// delete Preferences corresponding to this symbol
retMessage = rmr.deletePreference(accountNo, symbol);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while deleting preferences : " + re.toString());
}
}
}
// Populate Preferences Again so that the recent changes
// becomes visible immediately
HashMap hm = populatePreferences(req);
req.getSession().setAttribute("PREFS.RESPONSE", hm);
if (retMessage.equals("SUCCESS")) {
return retMessage;
} else {
throw new UserManagementEventException(
"Exception while changing preferences info : " + retMessage);
}
}
/**
* Method to add a new Alert Setting for a user account.
*
* @param req Servlet Request Object
* @return Status of the operation
* @exception UserManagementEventException Exception raised when
* Adding a new Alert using Session Facade Bean
* @exception ApplicationError Raised when Symbol is invalid or
* preference for the symbol already exists.
* @since 1.0
*/
public String addAlert(HttpServletRequest req)
throws ApplicationError, UserManagementEventException {
// Get the Account Number
Integer accountNo =
(Integer) req.getSession().getAttribute("LOGIN.RESPONSE");
String symbol = req.getParameter("SYMBOL").toUpperCase();
Integer minLimit = new Integer(req.getParameter("MINLIMIT"));
Integer maxLimit = new Integer(req.getParameter("MAXLIMIT"));
if (symbol == null)
throw new ApplicationError("Symbol Can not be null");
// Initialize a new AlertInfo Value Object
AlertsInfo alertInfo = new AlertsInfo(symbol,minLimit,maxLimit);
String retMessage = "NOSUCCESS";
try {
// Using the UserManagementSessionFacadeBean,
// add alert to the existing alerts
retMessage = rmr.addAlert(accountNo, alertInfo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while adding alerts : " + re.toString());
}
// Populate Alerts so that the recently added alert gets added to this list
HashMap hm = populateAlerts(req);
req.getSession().setAttribute("ALERTS.RESPONSE", hm);
if (retMessage.equals("SUCCESS")) {
return retMessage;
} else {
if (retMessage.indexOf("Improper")!= -1) {
throw new ApplicationError("You supplied invalid symbol value. Please provide valid Symbol.");
} else {
throw new ApplicationError("Alert for given symbol already exists. Instead update the alert setting.");
}
}
}
/**
* Method to add a new Preference Setting for a user account.
*
* @param req Servlet Request Object
* @return Status of the operation
* @exception UserManagementEventException Exception raised when
* Adding a Preference using Session Facade Bean
* @exception ApplicationError Raised when Symbol is invalid or
* preference for the symbol already exists.
* @since 1.0
*/
public String addPreference(HttpServletRequest req)
throws ApplicationError, UserManagementEventException {
// Get the Accout Number
Integer accountNo =
(Integer) req.getSession().getAttribute("LOGIN.RESPONSE");
String symbol = req.getParameter("SYMBOL").toUpperCase();
String prefType = req.getParameter("PREFTYPE");
if (symbol == null)
throw new ApplicationError("Symbol Can not be null");
// Initialize a new PreferencesInfo Value Object for adding it to the
// existing list of Preferences.
PreferencesInfo preferencesInfo = new PreferencesInfo(symbol,prefType);
String retMessage = "NOSUCCESS";
try {
// Add the Preference
retMessage = rmr.addPreferences(accountNo, preferencesInfo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while adding preferences : " + re.toString());
}
// Populate the preferences so that recent addition of
// preference is visible immediately
HashMap hm = populatePreferences(req);
req.getSession().setAttribute("PREFS.RESPONSE", hm);
if (retMessage.equals("SUCCESS")) {
return retMessage;
} else {
if (retMessage.indexOf("Improper")!= -1) {
throw new ApplicationError("You supplied invalid symbol value. Please provide valid Symbol.");
} else {
throw new ApplicationError("Preference for given symbol already exists. Instead update the preference setting.");
}
}
}
/**
* Method to Sign Up a new User to this FBS. This method creates a new user
* account and passes the AccountNumber back to the calling method.
*
* @param req Servlet Request Object
* Using this object, we can get all the User Information entered
* by the user in the SignUp form.
* @return account Number of created account.
* @exception UserManagementEventException Exception raised when
* Creating a New Account using Session Facade Bean
* @since 1.0
*/
public Integer signUp(HttpServletRequest req)
throws UserManagementEventException {
Integer accountNo = new Integer(0);
// Initialize Contact Info Value Object
ContactInfo contactInfo = new ContactInfo(req.getParameter("FIRSTNAME"),
req.getParameter("LASTNAME"),
req.getParameter("ORGANIZATION"),
req.getParameter("ADDRESS"),
req.getParameter("CITY"),
req.getParameter("STATE"),
req.getParameter("COUNTRY"),
req.getParameter("PHONE"),
req.getParameter("EMAIL"),
req.getParameter("MOBILEEMAIL"));
Integer linesPerPage = new Integer(0);
if (!req.getParameter("LINESPERPAGE").equals(""))
linesPerPage = Integer.decode(req.getParameter("LINESPERPAGE"));
// Initialize Account Info Value Object
AccountInfo accountInfo =
new AccountInfo(req.getParameter("PASSWORD1"),
req.getParameter("USERTYPE"),
req.getParameter("ALERTMODE"), 25000,
linesPerPage);
try {
// Using UserManagementSessionFacadeBean, create a new account
accountNo = rmr.createNewAccount(contactInfo, accountInfo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException("Remote Exception while sign up : "
+ re.toString());
}
return accountNo; // Return the account number of created account
}
/**
* Method to SignUp a Corporate User.
* @param email Email Address of the Corporate User
* @return Account Number of the created account
* @since 1.0
*/
public Integer signUpCorporateUser(String email) {
Integer accountNo = new Integer(0);
// Initialize a new Contact Info Value Object
ContactInfo contactInfo = new ContactInfo(" ", " ", " ", " ", " ", " ",
" ", " ", email, " ");
// Initialize a new Account Info Value Object
AccountInfo accountInfo = new AccountInfo("welcome", "I", "E", 25000,
new Integer(5));
try {
// Create a New Account
accountNo = rmr.createNewAccount(contactInfo, accountInfo);
} catch (RemoteException ex) { // Trap Remote Errors
System.out.println("Error While Signing Up A Corporate User " + ex);
}
return accountNo;
}
/**
* Method to populate Profile (Contact Info and Account Info) for a
* particular user. After user logged in successfully, his/her
* Account Number is set as LOGIN.RESPONSE attribute.
*
* @param req Servlet Request Object
* @return A HashMap data structure containing two objects namely
* ContactInfo Value Object and AccountInfo Value Object
* @exception UserManagementEventException Exception raised when
* Populating Profile Information using Session Facade Bean
* @since 1.0
*/
public HashMap populateProfile(HttpServletRequest req)
throws UserManagementEventException {
HashMap hm = new HashMap();
try {
Integer accountNo =
(Integer) req.getSession().getAttribute("LOGIN.RESPONSE");
// Get the Contact Info and store in a Hash Map
hm.put("CONTACTINFO", getContactInfo(accountNo));
// Get the Account Info and store in a Hash Map
hm.put("ACCOUNTINFO", rmr.getAccountInfo(accountNo));
} catch(RemoteException ex) {
throw new UserManagementEventException("Remote Exception while Populating Profile : "
+ ex.toString());
}
return hm;
}
/**
* Method to populate Preferences and Alerts(PreferencesInfo and AlertsInfo)
* for a particular user. After user logged in successfully, his/her
* Account Number is set as LOGIN.RESPONSE attribute.
*
* @param req Servlet Request Object
* @return A HashMap data structure containing two collections namely
* (a) Collection of PreferencesInfo Value Object
* (b) Collection of AlertsInfo Value Object
* @exception UserManagementEventException Exception raised when
* getting either Preferences Info or Alerts Information
* @since 1.0
*/
public HashMap populatePreferencesAlerts(HttpServletRequest req)
throws UserManagementEventException {
HashMap hm = new HashMap();
Integer accountNo =
(Integer) req.getSession().getAttribute("LOGIN.RESPONSE");
// Get a list of preferences as a collection of PreferencesInfo
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?