package com.tec.fms.components.search;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.documentum.web.common.ArgumentList;
import com.documentum.web.form.Form;
import com.documentum.web.form.IReturnListener;
import com.documentum.web.form.control.Link;
import com.documentum.web.form.control.databound.DataProvider;
import com.documentum.web.form.control.databound.Datagrid;
import com.documentum.web.form.control.databound.TableResultSet;
import com.documentum.web.formext.component.Component;
import com.tec.fms.common.IConstants;
import com.tec.fms.common.utils.FMSUtils;
import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfLogger;
import com.documentum.fc.common.IDfTime;
public class SearchResultsFeedback extends Component implements IReturnListener
{
private static final long serialVersionUID = 1L;
private String strFeedbackQuery = null;
private String strAppendedQuery = null;
private Datagrid resultsGrid = null;
private DataProvider provider = null;
private List columnList = null;
public static final String inputdate ="inputdate";
public static final String inputby ="inputby";
public static final String approveddate = "approveddate";
public static final String responsedate = "respdate";
public static final String LBL_STATUS = "Status";
public static final String LBL_FBID = "FB-ID";
public static final String LBL_TYPE = "Type";
public static final String LBL_BRAND = "Brand";
public static final String LBL_PRODUCT_NM = "Product Name";
public static final String LBL_REQUISITION = "Requisition";
public static final String LBL_INPUT_BY = "Input By";
public static final String LBL_INPUT_DT = "Input Date";
public static final String LBL_RESPONDED_BY = "Responded By";
public static final String LBL_RESPONDED_ON = "Responded On";
public static final String LBL_APPROVED_ON = "Approved On";
public static final String EXCEL_DATA = "Excel Data";
private static final String orderByClause= " ORDER BY feedback_id desc, r_creation_date desc";
private static final String arrHeaders []= new String[]
{
IConstants.feedback_id,
IConstants.fb_overview,
inputdate,
inputby,
approveddate,
IConstants.fb_latest_status,
IConstants.fb_type ,
IConstants.fb_brand ,
IConstants.fb_product ,
IConstants.performer_name,
responsedate
};
private TableResultSet tabResultSet = null;
private Logger logger = DfLogger.getLogger(this);
/* (non-Javadoc)
* @see com.documentum.web.formext.component.Component#onInit(com.documentum.web.common.ArgumentList)
*/
public void onInit(ArgumentList args)
{
logger.debug("onInit : Begin");
super.onInit(args);
try
{
strAppendedQuery = args.get("appendedQuery");
strFeedbackQuery = args.get("feedbackQuery");
executeSearchQuery();
}
catch(Exception exp)
{
logger.error(exp);
}
logger.debug("onInit : End");
}
/**
*
*/
private void executeSearchQuery()
{
logger.debug("executeSearchQuery : Begin");
IDfCollection resultSet = null;
// for Feedback object
String strFbId = null;
String strRequisition = null;
String strInputBy = null;
String strApprovedBy = null;
IDfTime dtInput = null;
String strStatus = null;
// For response object
String strType = null;
String strBrand = null;
String strProd = null;
String strRespondedBy = null;
IDfTime dtResponse = null;
IDfTime dtApproval = null;
if(null != strFeedbackQuery)
{
// execute the query
resultSet = FMSUtils.executeQuery(getDfSession(), strFeedbackQuery);
Object arrRows[] = null;
List arrList = new ArrayList();
StringBuffer strBufAppendedQuery = null;
try
{
if(null != resultSet)
{
while(resultSet.next())
{
strBufAppendedQuery = new StringBuffer();
IDfCollection responseSet = null;
String strTemp = null;
arrRows = new Object[11];
strFbId = resultSet.getString(IConstants.feedback_id);
strRequisition = resultSet.getString(IConstants.fb_overview);
dtInput = resultSet.getTime(inputdate);
strInputBy = resultSet.getString(inputby);
strApprovedBy = resultSet.getString(approveddate);
strStatus = resultSet.getString(IConstants.fb_latest_status);
arrRows[0] = strFbId;
arrRows[1] = strRequisition;
arrRows[2] = dtInput;
arrRows[3] = strInputBy;
arrRows[4] = strApprovedBy;
arrRows[5] = strStatus;
strTemp = strBufAppendedQuery.append(strAppendedQuery)
.append(" and feedback_id = '"+strFbId+"'")
.append(orderByClause).toString();
responseSet = FMSUtils.executeQuery(getDfSession(), strTemp);
System.out.println("Check->>>>>>>>> "+strTemp);
try
{
if(null != responseSet)
{
while(responseSet.next())
{
strType = resultSet.getString(IConstants.fb_type);
arrRows[6] = strType;
strBrand = resultSet.getString(IConstants.fb_brand);
arrRows[7] = strBrand;
strProd = resultSet.getString(IConstants.fb_product);
arrRows[8] = strProd;
strRespondedBy = resultSet.getString(IConstants.performer_name);
arrRows[9] = strRespondedBy;
dtResponse = resultSet.getTime(responsedate);
arrRows[10] = dtResponse;
break;
}
}
}
catch(DfException e)
{
e.printStackTrace();
logger.error(e);
}
finally
{
if(null != responseSet)
{
try {
responseSet.close();
} catch (DfException e) {
e.printStackTrace();
logger.error(e);
}
}
}
arrList.add(arrRows);
}
tabResultSet = new TableResultSet(arrList,arrHeaders);
showResults();
}
}
catch (DfException e)
{
e.printStackTrace();
logger.error(e);
}
finally
{
if(null != resultSet)
{
try {
resultSet.close();
} catch (DfException e) {
e.printStackTrace();
logger.error(e);
}
}
}
}
logger.debug("executeSearchQuery : End");
}
/**
*
*/
private void showResults()
{
logger.debug("showResults : Begin");
try
{
/* Populate the table resultset and set data into data grid */
resultsGrid = (Datagrid)getControl(IConstants.resultsDataGrid , Datagrid.class);
provider = resultsGrid.getDataProvider();
provider.setScrollableResultSet(tabResultSet);
}
catch(Exception exp)
{
logger.error(exp);
}
logger.debug("showResults : End");
}
/**
* @param lnkFbId
* @param args
*/
public void launchDetailedView(Link lnkFbId, ArgumentList args)
{
try
{
// TO DO
setComponentNested("test", args, getContext(), this);
}
catch(Exception exp)
{
logger.error(exp);
}
logger.debug("launchDetailedView : End");
}
/* (non-Javadoc)
* @see com.documentum.web.form.IReturnListener#onReturn(com.documentum.web.form.Form, java.util.Map)
*/
public void onReturn(Form arg0, Map arg1)
{
logger.debug("onReturn : Begin");
System.out.println("on return********************");
}
public void launchHistoryComp(Link lnkFbId, ArgumentList args)
{
logger.debug("launchHistoryComp : Begin");
try
{
// TO DO
setComponentNested("test", args, getContext(), this);
}
catch(Exception exp)
{
logger.error(exp);
}
logger.debug("launchHistoryComp : End");
}
} |