/**
*
*
*
*
*
* @author Niadri Roy
* @version 1.0, 07/08/2004
* @since EEMS architecture refresh
*/
package com.eforce.baby.auth.delegates;
import org.apache.log4j.Logger;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import com.eforce.baby.EEMSException;
import com.eforce.baby.auth.vo.SessionUserVO;
import com.eforce.baby.auth.vo.UserPrivilegeList;
import com.eforce.baby.auth.vo.UserVO;
import com.eforce.baby.auth.dao.UserDAO;
import com.eforce.baby.common.dao.DAOException;
import com.eforce.baby.common.delegates.BaseDelegate;
import com.eforce.baby.common.delegates.BusinessException;
import com.eforce.baby.common.factory.DAOFactory;
import com.eforce.baby.common.vo.PageInfoVO;
import com.eforce.baby.common.vo.SearchVO;
import com.eforce.baby.common.vo.SortInfoVO;
import com.eforce.baby.reports.vo.ReportResultsVO;
import com.eforce.baby.utils.IConstants;
import com.eforce.baby.auth.handler.EEMSCallbackHandler;
public class UserBD extends BaseDelegate
{
private Logger log = (Logger)Logger.getInstance(this.getClass().getName());
/**
* This is called when a user is created
* @param dsName
* @param dbType
* @param userVO
* @throws EEMSException
*/
public void createUser( String dsName, String dbType, UserVO userVO) throws EEMSException
{
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
try
{
dao.createUser(dsName,dbType,userVO);
}
catch (DAOException e)
{
log.error("ERROR in createUser ",e);
BusinessException be=new BusinessException(e.getMessage());
be.setMessageKey(e.getMessageKey());
throw be;
}
}
/**
* This is called when User by Name listing to be displayed
* @param dsName
* @param dbType
* @param linkCol
* @param startPos
* @param rowCount
* @return
*/
public ReportResultsVO getUserByName(String dsName, String dbType, String linkCol, PageInfoVO page, SortInfoVO sort, String userId, String profileRepId ) throws DAOException
{
log.debug("dsName: [" + dsName + "] " + "dbType: [" + dbType + "] " + "linkCol: [" + linkCol + "]" + "startPos: [" + page.getStartPosition() + "] " + "rowCount: [" + page.getCount() + "]");
ReportResultsVO userData = new ReportResultsVO();
try
{
//fetch report results
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
userData = dao.findUserByName(dsName, dbType, page, sort, userId,profileRepId);
userData = super.getDataForDisplay(userData, linkCol);
//set report specific header keys and their default value keys
userData.addColumnInfo(1, IConstants.HEADER_KEY_USERID, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(2, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(3, IConstants.HEADER_KEY_FIRSTNAME, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(4, IConstants.HEADER_KEY_LASTNAME, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(5, IConstants.HEADER_KEY_EMAIL, IConstants.DEFAULT_DATA_KEY_NR);
}
catch(DAOException e)
{
log.error("ERROE", e);
}
return userData;
}
/**
* This is called when User by Group list to be displayed
* @param dsName
* @param dbType
* @param linkCol
* @param startPos
* @param rowCount
* @return
*/
public ReportResultsVO getUserByGroup(String dsName, String dbType, String linkCol, PageInfoVO page, SortInfoVO sort, String userId, String profileRepId ) throws DAOException
{
log.debug("dsName: [" + dsName + "] " + "dbType: [" + dbType + "] " + "linkCol: [" + linkCol + "]" + "startPos: [" + page.getStartPosition() + "] " + "rowCount: [" + page.getCount() + "]");
ReportResultsVO userData = new ReportResultsVO();
try
{
//fetch report results
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
userData = dao.findUserByGroup(dsName, dbType, page, sort,userId,profileRepId);
userData = super.getDataForDisplay(userData, linkCol);
// set report specific header keys and their default value keys
userData.addColumnInfo(1, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(2, IConstants.HEADER_KEY_USERID, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(3, IConstants.HEADER_KEY_FIRSTNAME, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(4, IConstants.HEADER_KEY_LASTNAME, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(5, IConstants.HEADER_KEY_EMAIL, IConstants.DEFAULT_DATA_KEY_NR);
}
catch(DAOException e)
{
log.error("ERROE", e);
}
return userData;
}
/**
* This is called when user opened in view mode
* @param dsName
* @param dbType
* @param reportID
* @return
* @throws DAOException
*/
public UserVO findUser(String dsName, String dbType, String reportID) throws DAOException
{
UserVO userVO = null;
UserDAO dao = (UserDAO) DAOFactory.getInstance().
getDAO("com.eteam.ems.auth.dao.UserDAO");
try
{
log.debug("calling dao.findUser");
userVO = dao.findUser(dsName, dbType, reportID);
log.debug("returning dao.findUser");
}
catch (DAOException e)
{
throw e;
}
catch(Exception e1)
{
e1.printStackTrace();
}
return userVO;
}
public boolean authenticate(String dsName, String dbType, String userLogin, String password) throws LoginException
{
boolean flag = true;
// create callback handler
EEMSCallbackHandler handler = new EEMSCallbackHandler();
// set values required for login
handler.setDatasourceName(dsName);
handler.setDatabaseType(dbType);
handler.setUserLogin(userLogin);
handler.setPassword(password);
// create LoginContext
LoginContext lcontext = new LoginContext(IConstants.EEMS_LOGIN_MODULE, handler);
try
{
lcontext.login();
}
catch(LoginException e)
{
flag = false;
throw e;
}
return flag;
}
public SessionUserVO findUserSessionInfo(String dsName, String dbType, String userLogin) throws DAOException
{
SessionUserVO userSess = null;
try
{
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
userSess = dao.findUserSessionInfo(dsName, dbType, userLogin);
}
catch(DAOException se)
{
throw se;
}
return userSess;
}
public UserPrivilegeList findUserPrivileges(String dsName, String dbType, String userLogin) throws DAOException
{
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
return dao.findUserPrivileges(dsName, dbType, userLogin);
}
/**
* This is called to update a user
* @param dsName
* @param dbType
* @param userVO
*/
public void updateUser(String dsName, String dbType, UserVO userVO) throws EEMSException
{
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
try
{
dao.updateUser(dsName,dbType,userVO);
}
catch (DAOException e)
{
log.error("ERROR in createUser ",e);
BusinessException be=new BusinessException(e.getMessage());
be.setMessageKey(e.getMessageKey());
throw be;
}
}
/**
* This is called when search is selected
* @param dsName
* @param dbType
* @param searchVO
* @param userId
* @param profileRepId
* @return
* @throws BusinessException
* @throws DAOException
*/
public ReportResultsVO search(String dsName, String dbType, SearchVO searchVO, String userId, String profileRepId) throws BusinessException, DAOException
{
log.debug("Calling UserBD.search()");
log.debug("dsName: [" + dsName + "] " + "dbType: [" + dbType + "] " + "SearchVO: [" + searchVO + "]");
ReportResultsVO userData = new ReportResultsVO();
try
{
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
userData = dao.searchReportResult(dsName, dbType, searchVO, userId, null);
int i=1;
if(searchVO.getSearchBy().equals(IConstants.SEARCH_USER_BY_NAME))
{
userData.addColumnInfo(i++, IConstants.HEADER_KEY_BLANK_SPACE, IConstants.DEFAULT_DATA_KEY_BLANKSPACE);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_USERID, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_FIRSTNAME, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_LASTNAME, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_EMAIL, IConstants.DEFAULT_DATA_KEY_NR);
}
else if(searchVO.getSearchBy().equals(IConstants.SEARCH_USER_BY_GROUP))
{
userData.addColumnInfo(i++, IConstants.HEADER_KEY_BLANK_SPACE, IConstants.DEFAULT_DATA_KEY_BLANKSPACE);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_USERID, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_FIRSTNAME, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_LASTNAME, IConstants.DEFAULT_DATA_KEY_NR);
userData.addColumnInfo(i++, IConstants.HEADER_KEY_EMAIL, IConstants.DEFAULT_DATA_KEY_NR);
}
else
{
log.debug("No Search By found");
}
}
catch(DAOException e)
{
log.error("ERROR in search USER ",e);
BusinessException be=new BusinessException(e.getMessage());
be.setMessageKey(e.getMessageKey());
throw be;
}
return userData;
}
/**
* This is called when user is deleted
* @param dsName
* @param dbType
* @param id
* @throws BusinessException
*/
public void delete(String dsName, String dbType, String id) throws BusinessException
{
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
try
{
dao.delete(dsName,dbType,id);
}
catch (DAOException e)
{
log.error("ERROR in deleteUser ",e);
BusinessException be=new BusinessException(e.getMessage());
be.setMessageKey(e.getMessageKey());
throw be;
}
}
/**
* This is called to have the userid from the data store against one userloginid
* @param dsName
* @param dbType
* @param userLoginID
* @return
* @throws DAOException
*/
public String findUserID(String dsName,String dbType,String userLoginID) throws DAOException
{
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
return dao.findUserID(dsName,dbType,userLoginID);
}
/**
* This is called to find out "ForceProfile" value from Data Dictionary
* @param dsName
* @param dbType
* @return
* @throws DAOException
*/
public String findProfileEnabled(String dsName,String dbType) throws DAOException
{
UserDAO dao = (UserDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.UserDAO");
return dao.findForceProfileEnabled(dsName,dbType);
}
}