package com.eforce.baby.auth.delegates;
import java.util.ArrayList;
import org.apache.log4j.Logger;
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.dao.DistributionGroupDAO;
import com.eforce.baby.auth.vo.DistributionGroupVO;
public class DistributionGroupBD extends BaseDelegate
{
private Logger log = (Logger)Logger.getInstance(this.getClass().getName());
/**
* @param dsName
* @param dbType
* @return ArrayList
* @throws DAOException
* @throws BusinessException
*/
public ArrayList findGroupsForDistribution(String dsName,String dbType) throws DAOException, BusinessException
{
DistributionGroupDAO dao = (DistributionGroupDAO) DAOFactory.getInstance().
getDAO(IConstants.CLASS_DIST_GROUP_DAO);
ArrayList list = null;
list = dao.findGroupsForDistribution(dsName,dbType);
return list;
}
/**
* Called when Distribution Group Report is created
* @param dsName
* @param dbType
* @param distGroupVO
* @throws DAOException
* @throws BusinessException
*/
public void createDistGroup(String dsName, String dbType, DistributionGroupVO distGroupVO) throws DAOException, BusinessException
{
DistributionGroupDAO dao = (DistributionGroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.DistributionGroupDAO");
dao.createDistGroup(dsName,dbType,distGroupVO);
}
/**
* Called when 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 getDistributionGroupByName(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 distGroupData = new ReportResultsVO();
//fetch report results
DistributionGroupDAO dao = (DistributionGroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.DistributionGroupDAO");
distGroupData = dao.findDistributionGroupByName(dsName, dbType, page, sort,userId,profileRepId);
distGroupData = super.getDataForDisplay(distGroupData, linkCol);
// set report specific header keys and their default value keys
distGroupData.addColumnInfo(1, IConstants.HEADER_KEY_DISTGROUP, IConstants.DEFAULT_DATA_KEY_NR);
distGroupData.addColumnInfo(2, IConstants.HEADER_KEY_USERID, IConstants.DEFAULT_DATA_KEY_NR);
distGroupData.addColumnInfo(3, IConstants.HEADER_KEY_FIRSTNAME, IConstants.DEFAULT_DATA_KEY_NR);
distGroupData.addColumnInfo(4, IConstants.HEADER_KEY_LASTNAME, IConstants.DEFAULT_DATA_KEY_NR);
distGroupData.addColumnInfo(5, IConstants.HEADER_KEY_EMAIL, IConstants.DEFAULT_DATA_KEY_NR);
return distGroupData;
}
/**
* Called when report is viewed
* @param dsName
* @param dbType
* @param reportID
* @return DistributionGroupVO
* @throws DAOException
* @throws BusinessException
*/
public DistributionGroupVO getDistGroup(String dsName, String dbType, String reportID) throws DAOException, BusinessException
{
DistributionGroupVO distGroupVO = null;
DistributionGroupDAO dao = (DistributionGroupDAO)DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.DistributionGroupDAO");
distGroupVO = dao.findDistGroup(dsName, dbType, reportID);
return distGroupVO;
}
/**
* Called when DistributionGroup Report is updated
* @param dsName
* @param dbType
* @param distGroupVO
* @throws DAOException
* @throws BusinessException
*/
public void updateDistGroup(String dsName, String dbType, DistributionGroupVO distGroupVO) throws DAOException, BusinessException
{
DistributionGroupDAO dao = (DistributionGroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.DistributionGroupDAO");
dao.updateDistGroup(dsName,dbType,distGroupVO);
}
/**
* Called when DistributionGroup Report is deleted
* @param dsName
* @param dbType
* @param id
* @throws DAOException
* @throws BusinessException
*/
public void delete(String dsName, String dbType, String id) throws DAOException, BusinessException
{
DistributionGroupDAO dao = (DistributionGroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.DistributionGroupDAO");
dao.delete(dsName,dbType,id);
}
/**
* 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 DistGroupBD.search()");
log.debug("dsName: [" + dsName + "] " + "dbType: [" + dbType + "] " + "SearchVO: [" + searchVO + "]");
ReportResultsVO distGroupData = new ReportResultsVO();
DistributionGroupDAO dao = (DistributionGroupDAO) DAOFactory.getInstance().getDAO("com.eteam.ems.auth.dao.DistributionGroupDAO");
distGroupData = dao.searchReportResult(dsName, dbType, searchVO, userId, null);
int i=1;
if(searchVO.getSearchBy().equals(IConstants.SEARCH_DIST_GROUP_BY_NAME))
{
distGroupData.addColumnInfo(i++, IConstants.HEADER_KEY_BLANK_SPACE, IConstants.DEFAULT_DATA_KEY_BLANKSPACE);
distGroupData.addColumnInfo(i++, IConstants.HEADER_KEY_DISTGROUP, IConstants.DEFAULT_DATA_KEY_NR);
distGroupData.addColumnInfo(i++, IConstants.HEADER_KEY_USERID, IConstants.DEFAULT_DATA_KEY_NR);
distGroupData.addColumnInfo(i++, IConstants.HEADER_KEY_FIRSTNAME, IConstants.DEFAULT_DATA_KEY_NR);
distGroupData.addColumnInfo(i++, IConstants.HEADER_KEY_LASTNAME, IConstants.DEFAULT_DATA_KEY_NR);
distGroupData.addColumnInfo(i++, IConstants.HEADER_KEY_EMAIL, IConstants.DEFAULT_DATA_KEY_NR);
}
else
{
log.debug("No Search By found");
}
return distGroupData;
}
}