package com.eforce.baby.auth.delegates;
import org.apache.log4j.Logger;
import com.eteam.ems.common.dao.DAOException;
import com.eteam.ems.common.delegates.BaseDelegate;
import com.eteam.ems.common.factory.DAOFactory;
import com.eteam.ems.auth.vo.GroupVO;
import com.eteam.ems.auth.dao.GroupDAO;
import com.eteam.ems.reports.vo.ReportResultsVO;
import com.eteam.ems.utils.IConstants;
import com.eteam.ems.common.delegates.BusinessException;
import com.eteam.ems.common.vo.PageInfoVO;
import com.eteam.ems.common.vo.SearchVO;
import com.eteam.ems.common.vo.SortInfoVO;
public class GroupBD extends BaseDelegate
{
private Logger log = (Logger) Logger.getInstance(this.getClass().getName());
public GroupBD(){}
/**
* Called when the listing sorted by name
* @param dsName
* @param dbType
* @param linkCol
* @param page
* @param sort
* @param userId
* @param profileRepId
* @return ReportResultsVO
* @throws DAOException
* @throws BusinessException
*/
public ReportResultsVO getGroupByName(String dsName, String dbType, String linkCol, PageInfoVO page, SortInfoVO sort, String userId, String profileRepId ) throws DAOException, BusinessException
{
log.debug("dsName: [" + dsName + "] " + "dbType: [" + dbType + "] " + "linkCol: [" + linkCol + "]" + "startPos: [" + page.getStartPosition() + "] " + "rowCount: [" + page.getCount() + "]");
ReportResultsVO reportData = new ReportResultsVO();
//fetch report results
GroupDAO dao = (GroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.GroupDAO");
reportData = dao.findGroupByName(dsName, dbType, page, sort,userId,profileRepId);
reportData = super.getDataForDisplay(reportData, linkCol);
// set report specific header keys and their default value keys
reportData.addColumnInfo(1, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
reportData.addColumnInfo(2, IConstants.HEADER_KEY_ROLE, IConstants.DEFAULT_DATA_KEY_NR);
return reportData;
}
/**
* Called when listing sorted by role
* @param dsName
* @param dbType
* @param linkCol
* @param page
* @param sort
* @param userId
* @param profileRepId
* @return ReportResultsVO
* @throws DAOException
* @throws BusinessException
*/
public ReportResultsVO getGroupByRole(String dsName, String dbType, String linkCol, PageInfoVO page, SortInfoVO sort, String userId, String profileRepId ) throws DAOException, BusinessException
{
log.debug("dsName: [" + dsName + "] " + "dbType: [" + dbType + "] " + "linkCol: [" + linkCol + "]" + "startPos: [" + page.getStartPosition() + "] " + "rowCount: [" + page.getCount() + "]");
ReportResultsVO reportData = new ReportResultsVO();
//fetch report results
GroupDAO dao = (GroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.GroupDAO");
reportData = dao.findGroupByRole(dsName, dbType, page, sort,userId,profileRepId);
reportData = super.getDataForDisplay(reportData, linkCol);
// set report specific header keys and their default value keys
reportData.addColumnInfo(1, IConstants.HEADER_KEY_ROLE, IConstants.DEFAULT_DATA_KEY_NR);
reportData.addColumnInfo(2, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
reportData.addColumnInfo(3, IConstants.HEADER_KEY_BLANK_SPACE, IConstants.HEADER_KEY_BLANK_SPACE);
return reportData;
}
/**
* Called when Group Report is viewed
* @param dsName
* @param dbType
* @param groupID
* @return GroupVO
* @throws DAOException
* @throws BusinessException
*/
public GroupVO findGroup( String dsName, String dbType, String groupID) throws DAOException, BusinessException
{
GroupVO groupVO = null;
GroupDAO dao = (GroupDAO) DAOFactory.getInstance().
getDAO("com.eteam.ems.auth.dao.GroupDAO");
groupVO = dao.findGroup(dsName, dbType, groupID);
return groupVO;
}
/**
* Called when Group Report is created
* @param dsName
* @param dbType
* @param groupVO
* @throws DAOException
* @throws BusinessException
*/
public void createGroup(String dsName, String dbType, GroupVO groupVO) throws DAOException, BusinessException
{
GroupDAO dao = (GroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.GroupDAO");
dao.createGroup(dsName,dbType,groupVO);
}
/*
* Called when Administration Group Report is opened for update.
* This is a delegator method - delegating the request to the DAO class
* @param dsName
* @param dbType
* @param groupVO
* @throws DAOException
* @throws BusinessException
*/
public void updateGroup( String dsName, String dbType, GroupVO groupVO)
throws DAOException, BusinessException
{
GroupDAO dao = (GroupDAO) DAOFactory.getInstance().
getDAO("com.eteam.ems.auth.dao.GroupDAO");
dao.updateGroup(dsName,dbType,groupVO);
}
/**
* Called when search is selected
* @param dsName
* @param dbType
* @param searchVO
* @param userId
* @param profileRepId
* @return ReportResultsVO
* @throws DAOException
* @throws BusinessException
*/
public ReportResultsVO search(String dsName, String dbType, SearchVO searchVO, String userId, String profileRepId) throws BusinessException, DAOException
{
log.debug("Calling GroupBD.search()");
log.debug("dsName: [" + dsName + "] " + "dbType: [" + dbType + "] " + "SearchVO: [" + searchVO + "]");
ReportResultsVO groupData = new ReportResultsVO();
GroupDAO dao = (GroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.GroupDAO");
groupData = dao.searchReportResult(dsName, dbType, searchVO, userId, null);
int i=1;
if(searchVO.getSearchBy().equals(IConstants.SEARCH_GROUP_BY_NAME))
{
groupData.addColumnInfo(i++, IConstants.HEADER_KEY_BLANK_SPACE, IConstants.DEFAULT_DATA_KEY_BLANKSPACE);
groupData.addColumnInfo(i++, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
groupData.addColumnInfo(i++, IConstants.HEADER_KEY_ROLE, IConstants.DEFAULT_DATA_KEY_NR);
}
else if(searchVO.getSearchBy().equals(IConstants.SEARCH_GROUP_BY_ROLE))
{
groupData.addColumnInfo(i++, IConstants.HEADER_KEY_BLANK_SPACE, IConstants.DEFAULT_DATA_KEY_BLANKSPACE);
groupData.addColumnInfo(i++, IConstants.HEADER_KEY_ROLE, IConstants.DEFAULT_DATA_KEY_NR);
groupData.addColumnInfo(i++, IConstants.HEADER_KEY_GROUP, IConstants.DEFAULT_DATA_KEY_NR);
groupData.addColumnInfo(i++, IConstants.HEADER_KEY_BLANK_SPACE, IConstants.HEADER_KEY_BLANK_SPACE);
}
else
{
log.debug("No Search By found");
}
return groupData;
}
/**
* Called when a Group is deleted
* @param dsName
* @param dbType
* @param id
* @throws DAOException
* @throws BusinessException
*/
public void delete(String dsName, String dbType, String id) throws DAOException, BusinessException
{
GroupDAO dao = (GroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.GroupDAO");
dao.delete(dsName,dbType,id);
}
}