package com.eforce.baby.auth.delegates;
import org.apache.log4j.Logger;
import com.eforce.baby.auth.dao.RoleDAO;
import com.eforce.baby.auth.vo.RoleVO;
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;
public class RoleBD extends BaseDelegate
{
public RoleBD(){}
private Logger log = (Logger)Logger.getInstance(this.getClass().getName());
/**
* This is called when role by name listing to be displayed
* @param dsName
* @param dbType
* @param linkCol
* @param startPos
* @param rowCount
* @return
*/
public ReportResultsVO getRoleByName(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 roleData = new ReportResultsVO();
try
{
//fetch report results
RoleDAO dao = (RoleDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.RoleDAO");
roleData = dao.findRoleByName(dsName, dbType, page, sort,userId,profileRepId);
roleData = super.getDataForDisplay(roleData, linkCol);
// set report specific header keys and their default value keys
roleData.addColumnInfo(1, IConstants.HEADER_KEY_ROLE, IConstants.DEFAULT_DATA_KEY_NR);
roleData.addColumnInfo(2, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
}
catch(DAOException e)
{
log.error("ERROE", e);
}
return roleData;
}
/**
* This is called to create role
* @param dsName
* @param dbType
* @param roleVO
*/
public void createDistGroup(String dsName, String dbType, RoleVO roleVO) throws BusinessException, DAOException
{
RoleDAO dao = (RoleDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.RoleDAO");
dao.createRole(dsName,dbType,roleVO);
}
/**
* This is called to view role
* @param dsName
* @param dbType
* @param string
* @return
*/
public RoleVO getRole(String dsName, String dbType, String roleID) throws BusinessException
{
RoleVO roleVO = null;
RoleDAO dao = (RoleDAO)DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.RoleDAO");
try
{
log.debug("calling dao.findRole");
roleVO = dao.findRole(dsName, dbType, roleID);
log.debug("returning dao.findRole");
}
catch (DAOException e)
{
BusinessException be=new BusinessException(e.getMessage());
be.setMessageKey(e.getMessageKey());
throw be;
}
return roleVO;
}
/**
* This is called to update role
* @param dsName
* @param dbType
* @param roleVO
*/
public void updateRole(String dsName, String dbType, RoleVO roleVO) throws BusinessException, DAOException
{
RoleDAO dao = (RoleDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.RoleDAO");
dao.updateRole(dsName,dbType,roleVO);
}
/**
* 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 RoleBD.search()");
log.debug("dsName: [" + dsName + "] " + "dbType: [" + dbType + "] " + "SearchVO: [" + searchVO + "]");
ReportResultsVO roleData = new ReportResultsVO();
try
{
RoleDAO dao = (RoleDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.RoleDAO");
roleData = dao.searchReportResult(dsName, dbType, searchVO, userId, null);
int i=1;
if(searchVO.getSearchBy().equals(IConstants.SEARCH_ROLE))
{
roleData.addColumnInfo(i++, IConstants.HEADER_KEY_BLANK_SPACE, IConstants.DEFAULT_DATA_KEY_BLANKSPACE);
roleData.addColumnInfo(i++, IConstants.HEADER_KEY_ROLE, IConstants.DEFAULT_DATA_KEY_NR);
roleData.addColumnInfo(i++, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
}
else
{
log.debug("No Search By found");
}
}
catch(DAOException e)
{
log.error("ERROR in search ROLE ",e);
BusinessException be=new BusinessException(e.getMessage());
be.setMessageKey(e.getMessageKey());
throw be;
}
return roleData;
}
/**
* This is called to delete a role
* @param dsName
* @param dbType
* @param string
*/
public void delete(String dsName, String dbType, String id) throws BusinessException
{
RoleDAO dao = (RoleDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.RoleDAO");
try
{
dao.delete(dsName,dbType,id);
}
catch (DAOException e)
{
log.error("ERROR in deleteRole ",e);
BusinessException be=new BusinessException(e.getMessage());
be.setMessageKey(e.getMessageKey());
throw be;
}
}
}