int startat = startATparam.intValue();
int endat = EndAtparam.intValue();
int begainindex = Math.max(startat - 100, 1);
int endindex = endat + 100;
RuleList DL = new RuleList();
DL.setSortMember(sortmem);
CVDal cvdl = new CVDal(dataSource);
if (searchString == null)
{
searchString = "";
}
String appendStr = "";
if (searchString.startsWith("SIMPLE :"))
{
searchString = searchString.substring(8);
appendStr = " WHERE emailrules.ruleid like '%" + searchString + "%' OR rulename like '%" + searchString + "%' OR description like '%" + searchString + "%' OR enabledstatus like '%" + searchString + "%' ";
}
if ((null != searchString) && (searchString.startsWith("ADVANCE:")))
{
int searchIndex = (searchString.toUpperCase()).indexOf("WHERE");
appendStr = " AND "+ searchString.substring((searchIndex+5),searchString.length())+" ";
}
if (sorttype == 'A')
{
String str = "Select ruleid , rulename, description , enabledstatus from emailrules ,emailaccount where emailrules.accountid=emailaccount.accountid and emailaccount.owner="+userId+" " + appendStr + " ORDER BY " + sortmem + " LIMIT " + (begainindex - 1) + " , " + (endindex + 1) + ";";
cvdl.setSqlQuery(str);
}
else
{
String str1 = "Select ruleid , rulename, description , enabledstatus from emailrules ,emailaccount where emailrules.accountid=emailaccount.accountid and emailaccount.owner="+userId+" " + appendStr + " ORDER BY " + sortmem + " DESC LIMIT " + (begainindex - 1) + " , " + (endindex + 1) + ";";
cvdl.setSqlQuery(str1);
}
Collection v = cvdl.executeQuery();
cvdl.clearParameters();
cvdl.destroy();
Iterator it = v.iterator();
TimeZone tz = TimeZone.getTimeZone("IST");
int i = 0;
while (it.hasNext())
{
i++;
HashMap hm = (HashMap) it.next();
int RuleID = ((Long) hm.get("ruleid")).intValue();
IntMember intmem = new IntMember("RuleID", RuleID, 10, "", 'T', true, 10);
StringMember one = new StringMember("RuleName", (String) hm.get("rulename"), 10, "", 'T', true);
StringMember two = new StringMember("Description", (String) hm.get("description"), 10, "", 'T', false);
StringMember three = new StringMember("EnabledStatus", (String) hm.get("enabledstatus"), 10, "", 'T', false);
//BooleanMember three= new BooleanMember( "Enabled", true ,10 , "" , 'T' , false ,20 );
RuleListElement ele = new RuleListElement(RuleID);
ele.put("RuleID", intmem);
ele.put("RuleName", one);
ele.put("Description", two);
ele.put("EnabledStatus", three);
//added by Sameer for generating fixed length sort key from i
StringBuffer sb = new StringBuffer("00000000000");
sb.setLength(11);
String str = (new Integer(i)).toString();
sb.replace((sb.length() - str.length()), (sb.length()), str);
String newOrd = sb.toString();
DL.put(newOrd, ele);
DL.setTotalNoOfRecords(DL.size());
DL.setListType("Rule");
DL.setBeginIndex(begainindex);
DL.setEndIndex(endindex);
}
return DL;
}