📄 usermanagementhelper.java
字号:
/*
* @author : Umesh Kulkarni
* @version 1.0
*
* Development Environment : Oracle9i JDeveloper
*
* Name of the File : UserManagementHelper.java
*
* Creation / Modification History
* Umesh 26-Apr-2002 Created
*
*/
package oracle.otnsamples.ibfbs.usermanagement.helper;
// Import Required Packages
import javax.servlet.http.HttpServletRequest; // Servlet Packages
// EJB Classes
import javax.ejb.CreateException;
import java.rmi.RemoteException;
// JNDI Classes
import javax.naming.InitialContext;
import javax.naming.NamingException;
// Utility Classes
import java.util.HashMap;
import java.util.Collection;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
// TradeManagement Classes
import oracle.otnsamples.ibfbs.trademanagement.exception.TradeManagementEventException;
// UserManagement Classes
import oracle.otnsamples.ibfbs.usermanagement.ejb.UserManagementSessionRemote;
import oracle.otnsamples.ibfbs.usermanagement.ejb.UserManagementSessionHomeRemote;
import oracle.otnsamples.ibfbs.usermanagement.exception.UserManagementEventException;
import oracle.otnsamples.ibfbs.usermanagement.exception.ApplicationError;
import oracle.otnsamples.ibfbs.usermanagement.ejb.ContactInfo;
import oracle.otnsamples.ibfbs.usermanagement.ejb.AccountInfo;
import oracle.otnsamples.ibfbs.usermanagement.ejb.TimerInfo;
import oracle.otnsamples.ibfbs.usermanagement.ejb.PreferencesInfo;
import oracle.otnsamples.ibfbs.usermanagement.ejb.AlertsInfo;
// Admin Classes
import oracle.otnsamples.ibfbs.admin.ejb.MailService;
import oracle.otnsamples.ibfbs.admin.ejb.MailServiceHome;
import oracle.otnsamples.ibfbs.trademanagement.helper.StockRateHelper;
/**
* This Class is a helper Class used in User Management Functionality
* such as creation of new user account, customizing preferences, customizing
* alerts etc. In an MVC (Model-View-Controller) Architecture, this class lies
* in the Model Layer helping to carry out the business functionality.
*
* For carrying out the User Management Functionality, this class takes the help
* of the 'UserManagementSessionFacadeBean' - Session Bean. This Class
* accesses the enterprise data only through this session facade bean and never
* accesses the underlying entity beans.
*
* @see oracle.otnsamples.ibfbs.usermanagement.ejb.UserManagementSessionFacadeBean.java
*
*/
public class UserManagementHelper {
// Declare Handler to 'UserManagementSessionFacadeBean'
// remote interface
/** Reference to Remote Interface */
UserManagementSessionRemote rmr = null;
/**
* Constructor of this Class. Initializes the values of remote interface and
* home interface to 'UserManagementSessionFacadeBean'.
*
* Note that this helper class carries out all the UserManagement Functionality
* using the Services Provided by 'UserManagementSessionFacadeBean'.
* @since 1.0
*/
public UserManagementHelper() {
try {
InitialContext ic = new InitialContext();
// Initialize the Home Interface for 'UserManagementSessionFacadeBean'
UserManagementSessionHomeRemote rmrh = (UserManagementSessionHomeRemote)
ic.lookup("java:comp/env/ejb/UserManagementSessionHomeRemote");
// Initialize Remote Interface
rmr = rmrh.create();
} catch (RemoteException ne) { // Trap Remote Errors
ne.printStackTrace();
} catch (CreateException ce) { // Trap Errors when Remote Interface is created
ce.printStackTrace();
} catch (NamingException ce) { // Trap Errors When Look Up Errors Happen
ce.printStackTrace();
}
}
/**
* Method to Check Password and appropriately redirect the User to proper page.
* If the logged in User is Admin then user is directed to a page where
* he/she can upload market data and upload market news.
*
* If the logged in User is Individual User of the FBS, then he/she is
* directed to a page where he/she can manage portoflio.
*
* If the logged in User is of Organization Type, then the user is directed
* to a page where user can upload account information for ESOP accounts.
*
* Note that ESOP Stands for Employee Stock Options Plan
*
* @param req req Servlet Request Object
* @return Account Number of the User
* @exception ApplicationError When Password is incorrect or
* account number is invalid.
* @exception TradeManagementEventException When Populating Stock Rates
* @since 1.0
*/
public Integer checkPassword(HttpServletRequest req)
throws ApplicationError, UserManagementEventException,
TradeManagementEventException {
Integer accountNo = new Integer(-1);
String password = null;
try {
// Get the Account Number and password entered by the User
accountNo = new Integer(req.getParameter("AccountNumber").trim());
password = req.getParameter("Password").trim();
if (accountNo == null)
throw new ApplicationError("Account Number can not be null.");
if (password == null)
throw new ApplicationError("Password can not be null.");
// Check if the account no and password are valid.
if (rmr.validUser(accountNo, password)) {
// If Valid User, set the Account No as a attribute in the HTTP Session
// so that it can be accessed by other pages.
req.getSession().setAttribute("LOGIN.RESPONSE", accountNo);
// Get the Contact Info
ContactInfo cInfo = getContactInfo(accountNo);
// Set the User Name as attribute so that it can be
// accessed on every page
req.getSession().setAttribute("USERNAME.RESPONSE",
cInfo.getFirstName() + " "
+ cInfo.getLastName());
// Get the Account Info and User Type of the logged in User
AccountInfo aInfo = getAccountInfo(accountNo);
String userType = aInfo.getUserType();
String role = null;
String eventName = null;
// Based on the User Type of the logged user, assign various roles
if (userType.equals("I")) {
role = "USER";
// Populate Preferences for the User
HashMap hm = populatePreferences(req);
// Set Preferences as attribute of the HTTP Session
req.getSession().setAttribute("PREFS.RESPONSE", hm);
populateNews(req);
populateStockRates(req);
} else {
if (userType.equals("C")) {
role = "CORP";
eventName = "CORPLOGIN";
} else {
if (userType.equals("A")) {
role = "ADMIN";
eventName = "CONFIGUPLOAD";
}
}
}
// Set the Role in HTTP Session so that it can be acccessed in other pages
req.getSession().setAttribute("ROLE", role);
if (eventName != null) {
req.setAttribute("EVENTNAME", eventName);
}
} else { // Password is not Correct
throw new ApplicationError("Password Incorrect. Please provide correct password !!");
}
} catch (RemoteException re) { // Trap Remote Errors
throw new ApplicationError(
"You Entered Invalid Account No. Please check your account number. ");
} catch(NumberFormatException ex) {
throw new ApplicationError(
"You Entered Invalid Account No. Please check your account number. ");
}
return accountNo;
}
/**
* Method to populate the Admin Timer Information for TradeDetails reporting.
* The timer information obtained by calling the remote method
* getAdminTimerInfo is set in the session attribute ADMINTIMERINFO.RESPONSE.
*
* @param req Servlet Request Object
* @exception UserManagementEventException If exception occurs while
* accessing the remote method
* @since 1.0
*/
public void populateAdminTimerInfo(HttpServletRequest req)
throws UserManagementEventException {
Collection timerInfo = new ArrayList();
try {
// Get the Timer Info
TimerInfo ti = rmr.getAdminTimerInfo();
timerInfo.add(ti);
} catch(RemoteException ex) {
throw new UserManagementEventException("Remote Exception while " +
" Populating Admin TimerInfo : "
+ ex.toString());
}
// Set the Stock Rates as attribute of HTTP Session
req.getSession().setAttribute("ADMINTIMERINFO.RESPONSE", timerInfo);
return;
}
/**
* This method configures Timer values. The interval to schedule
* the timer is taken from the request object.
*
* @param req HttpServletRequest containing timer interval
* @return Integer status of configuration 0 - Success, -1 failure
* @exception ApplicationError if request contains invalid parameters or
* updating the admin timer is not successful
* @exception UserManagementEventException If exception occurs while
* accessing the remote method
* @since 1.0
*/
public Integer configReportInterval(HttpServletRequest req)
throws ApplicationError, UserManagementEventException {
Collection timerInfo = new ArrayList();
int status = 0;
int hour = Integer.parseInt(req.getParameter("TIMERHOURS"));
int mins = Integer.parseInt(req.getParameter("TIMERMINS"));
String retMessage = "";
// Minimum interval should be 15 minutes
if ((hour <= 0) && (mins < 15)) {
throw new ApplicationError(" Minimum interval should be 15 minutes ");
} else {
// Construct Timer Information Value Object using the updated information
TimerInfo ti = new TimerInfo( new Integer(hour), new Integer(mins) );
try {
// Call the remote method to update the admin timer values
retMessage = rmr.updateAdminAccount(ti);
timerInfo.add(ti); // Add the Timer Information to the collection
// Set the collection in the session attribute
req.getSession().setAttribute("ADMINTIMERINFO.RESPONSE", timerInfo);
} catch(RemoteException ex) {
throw new UserManagementEventException("Remote Exception while " +
" updating Admin TimerInfo : "
+ ex.toString());
}
}
if (retMessage.equals("NOSUCCESS")) {
throw new ApplicationError(" Updating Timer Information was not successful ");
}
req.setAttribute("InfoMessage", "Admin Timer Info configured successfully");
return new Integer(status);
}
/**
* Method which changes the password of a particular User. This method
* assumes that the validation of User entered password is done by the JSP.
* The validation includes whether both the passwords match or not.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -