📄 usermanagementhelper.java
字号:
* @param req req Servlet Request Object
* @return Status of the operation
* @exception UserManagementEventException When changing Password
* using Session Facade Bean
* @exception ApplicationError User Error when changing Password
* @since 1.0
*/
public String changePassword(HttpServletRequest req)
throws UserManagementEventException, ApplicationError {
// Get the New Password Entered by the User
String newPassword = (String) req.getParameter("NEWPASSWORD");
String oldPassword = (String) req.getParameter("OLDPASSWORD");
String newPassword1 = (String) req.getParameter("NEWPASSWORD1");
String message = null;
if (newPassword == null)
throw new ApplicationError("New Password can not be null");
if (oldPassword == null)
throw new ApplicationError("Old Password can not be null");
if (newPassword1 == null)
throw new ApplicationError("Second New Password can not be null");
if (!newPassword.equals(newPassword1))
throw new ApplicationError("Both the new passwords must be the same");
// Variable for holding Account Number
Integer accountNo = new Integer(-1);
try {
accountNo = (Integer) req.getSession().getAttribute("LOGIN.RESPONSE");
// Ask the Session Facade Bean to change the password
message = rmr.changePassword(accountNo, newPassword, oldPassword);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Error while changing password. " + re.toString());
} catch (NumberFormatException ex) {
throw new ApplicationError(
"Account Number Provided is wrong. Error While Changing Password : ");
}
if (!message.equals("SUCCESS"))
throw new ApplicationError("Error while changing password. " +
"You provided wrong value of Old Password. Password is not changed ");
return message;
}
/**
* Method to get the Contact Information for a user account.
*
* @param accountNo Account Number of the logged user
* @return ContactInfo Value Object encapsulating contact information
* @exception UserManagementEventException When Getting Contact Information
* using Session Facade Bean
* @since 1.0
*/
public ContactInfo getContactInfo(Integer accountNo)
throws UserManagementEventException {
// Fetch the Contact Information using Session Facade Bean
try {
return rmr.getContactInfo(accountNo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while getting contact info : " + re.toString());
}
}
/**
* Method to set the Contact Information for a user account.
*
* @param accountNumber Account Number of the logged user
* @param contactInfo Value Object encapsulating Contact Information
* for the logged user
* @return Status of the Operation
* @exception UserManagementEventException Exception raised when Setting
* Contact Information using Session Facade Bean
* @since 1.0
*/
public String setContactInfo(Integer accountNumber, ContactInfo contactInfo)
throws UserManagementEventException {
// Set the Contact Information using Session Facade Bean
try {
return rmr.setContactInfo(accountNumber, contactInfo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while setting contact info : " + re.toString());
}
}
/**
* Method to Update User's Profile. User's profile includes
* Account Information and Contact Information of the user.
*
* @param req Servlet Request Object
* @return Status of this Operation
* @exception UserManagementEventException Exception raised when updating
* User Profile Using Session Facade Bean
* @since 1.0
*/
public String updateProfile(HttpServletRequest req)
throws UserManagementEventException {
// Get the Account Number
Integer accountNo =
(Integer) req.getSession().getAttribute("LOGIN.RESPONSE");
// Construct Contact Information Value Object using the updated information
ContactInfo contactInfo = new ContactInfo(req.getParameter("FIRSTNAME"),
req.getParameter("LASTNAME"),
req.getParameter("ORGANIZATION"),
req.getParameter("ADDRESSFIELD"),
req.getParameter("CITY"),
req.getParameter("STATE"),
req.getParameter("COUNTRY"),
req.getParameter("PHONE"),
req.getParameter("EMAIL"),
req.getParameter("MOBILEEMAIL"));
// Construct Account Information Value Object using the updated information
AccountInfo accountInfo =
new AccountInfo("", "", req.getParameter("ALERTMODE"), 0,
new Integer(req.getParameter("LINESPERPAGE")));
// Set the User Name as attribute so that it can be accessed on every page
req.getSession().setAttribute("USERNAME.RESPONSE",
contactInfo.getFirstName() + " "
+ contactInfo.getLastName());
// Set Contact Information and Account Information to Update Profile
return this.setContactInfo(accountNo, contactInfo)
+ this.setAccountInfo(accountNo, accountInfo);
}
/**
* Method to get the Account Information for a user account.
*
* @param accountNo Account Number of the logged user
* @return AccountInfo Value Object encapsulating account information
* @exception UserManagementEventException Exception raised when
* getting Account Information using Session Facade Bean
* @since 1.0
*/
public AccountInfo getAccountInfo(Integer accountNo)
throws UserManagementEventException {
// Fetch the Account Information using Session Facade Bean
try {
return rmr.getAccountInfo(accountNo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while getting account info : " + re.toString());
}
}
/**
* Method to set the Account Information for a user account.
*
* @param accountNo Account Number of the logged user
* @param AccountInfo Account Information Value Object encapsulating
* Account Information of the logged user
* @return Status of the Operation
* @exception UserManagementEventException Exception raised when
* Setting Account Information using Session Facade Bean
* @since 1.0
*/
public String setAccountInfo(Integer accountNumber, AccountInfo accountInfo)
throws UserManagementEventException {
try {
// Set the Account Information using Session Facade Bean
return rmr.setAccountInfo(accountNumber, accountInfo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while setting account info : " + re.toString());
}
}
/**
* Method to get the Preferences Information for a user account. Note that
* the Preferences Information is returned as a Collection of
* PreferencesInfo Class.
*
* @param accountNo Account Number of the logged user
* @return Collection of PreferencesInfo Object.
* PreferencesInfo is a Value Object used to reduce the network traffic.
* @exception UserManagementEventException Exception raised when
* getting Preferences Information using Session Facade Bean
* @since 1.0
*/
public Collection getPreferencesInfo(Integer accountNo)
throws UserManagementEventException {
try {
// Fetch Preferences by calling method in 'UserManagementSessionFacadeBean'
return rmr.getPreferences(accountNo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while getting preferences info : " + re.toString());
}
}
/**
* Method to get the Alerts Information for a user account. Note that the
* Alerts Information is returned as a Collection of AlertsInfo Class.
* AlertsInfo is a Value Object used to reduce the network traffic.
*
* @param accountNo Account Number of the logged user
* @return Collection of AlertsInfo Object.
* @exception UserManagementEventException Exception raised when
* getting Alerts Information using Session Facade Bean
* @since 1.0
*/
public Collection getAlertsInfo(Integer accountNo)
throws UserManagementEventException {
// Fetch the Alerts Information by taking the help
// of 'UserManagementSessionFacadeBean'
try {
return rmr.getAlerts(accountNo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while getting alerts info : " + re.toString());
}
}
/**
* Method to change the Alerts Information for a user account.
*
* @param req Servlet Request Object
* @return Status of the operation
* @exception UserManagementEventException Exception raised when
* Changing Alert Information using Session Facade Bean
* @since 1.0
*/
public String changeAlertInfo(HttpServletRequest req)
throws UserManagementEventException {
// Get the Account No
Integer accountNo =
(Integer) req.getSession().getAttribute("LOGIN.RESPONSE");
// Get the SYMBOL
String symbol = req.getParameter("SYMBOL").toUpperCase();
String retMessage = "NOSUCCESS";
// Check Whether the Alert corresponding to given Symbol Need not be deleted
if (req.getParameter("DELFLAG").equals("NO")) {
// Initialize a new AlertInfo Value Object
AlertsInfo aInfo =
new AlertsInfo(symbol, new Integer(req.getParameter("MINLIMIT")),
new Integer(req.getParameter("MAXLIMIT")));
// Change the Alert Information
try {
retMessage = rmr.changeAlertInfo(accountNo, aInfo);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while changing alerts info : " + re.toString());
}
} else {
// If this alert has to be deleted
if (req.getParameter("DELFLAG").equals("YES")) {
try {
// Using the Session facade bean, delete this alert
retMessage = rmr.deleteAlert(accountNo, symbol);
} catch (RemoteException re) { // Trap Remote Errors
throw new UserManagementEventException(
"Remote Exception while deleting alerts info : " + re.toString());
}
}
}
// After Changing the Alert Information, we need to populate this
// information again so that the effect can be shown immediately
HashMap hm = populateAlerts(req);
req.getSession().setAttribute("ALERTS.RESPONSE", hm);
if (retMessage.equals("SUCCESS")) {
return retMessage;
} else {
throw new UserManagementEventException(
"Exception while changing alert info : " + retMessage);
}
}
/**
* Method to change the Preferences Information for a user account.
*
* @param req Servlet Request Object
* @return Status of the operation
* @exception UserManagementEventException Exception raised when
* Changing Preferences Information using Session Facade Bean
* @since 1.0
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -