* @param info A HashMap with information about the list.
* @return An Email list with the correct properties.
*/
public EmailList getEmailList(int userId, HashMap info)
{
EmailList emailList = new EmailList();
CVDal cvdl = new CVDal(dataSource);
try
{
Integer startATparam = (Integer) info.get("startATparam");
Integer EndAtparam = (Integer) info.get("EndAtparam");
String searchString = (String) info.get("searchString");
String sortmem = (String) info.get("sortmem");
Character chr = (Character) info.get("sortType");
boolean adminUserFlag = ((Boolean) info.get("adminUserFlag")).booleanValue();
char sorttype = chr.charValue();
int startat = startATparam.intValue();
int endat = EndAtparam.intValue();
int beginindex = Math.max(startat - 100, 1);
int endindex = endat + 100;
emailList.setSortMember(sortmem);
Integer folderID = (Integer)info.get("folderid");
Collection v = null;
if (sortmem.equals("From")){
sortmem = "emailmessage.mailfrom";
}
if (sortmem.equals("To")){
sortmem = "emailmessage.replyto";
}
if (sortmem.equals("Received")){
sortmem = "emailmessage.messagedate";
}
String appendStr = "";
String sortStr = "";
if (sorttype != 'A'){
sortStr = " DESC ";
}
String privateString = "";
System.out.println(adminUserFlag+"adminUserFlag");
if(!adminUserFlag){
privateString = " AND (emailmessage.private ='NO' OR emailmessage.owner="+userId+" ) ";
}
System.out.println(privateString+"privateString");
String folderString = "";
if (folderID.intValue() != 0){
folderString = " AND es.emailfolder=" + folderID.intValue();
}
String strSQL = "SELECT emailmessage.messageid, emailmessage.messagedate, emailmessage.mailfrom, emailmessage.replyto, emailmessage.subject, emailmessage.size, " +
"emailmessage.Priority, emailmessage.messageRead AS readstatus, es.folderID AS EmailFolder, " +
"COUNT(at.attachmentid) AS noofattachments " +
"FROM emailmessage LEFT JOIN emailmessagefolder es ON (emailmessage.messageid=es.messageID) " +
"LEFT JOIN attachment at ON (emailmessage.messageID=at.messageid) " +
"WHERE emailmessage.locallyDeleted = 'NO' "+privateString+" AND (emailmessage.MovedToFolder=" + folderID.intValue() +
" OR emailmessage.MovedToFolder=0) AND es.folderid=" + folderID.intValue() + " GROUP BY emailmessage.messageid " +
"ORDER BY " + sortmem + sortStr + " ";
if ((null != searchString) && (searchString.startsWith("ADVANCE:")))
{
int searchIndex = (searchString.toUpperCase()).indexOf("WHERE");
strSQL = "SELECT emailmessage.messageid, emailmessage.messagedate, emailmessage.mailfrom, emailmessage.replyto, emailmessage.subject, emailmessage.size, " +
"emailmessage.Priority, emailmessage.messageRead AS readstatus, es.folderID AS EmailFolder, " +
"COUNT(at.attachmentid) AS noofattachments " +
"FROM emailmessage LEFT JOIN emailmessagefolder es ON (emailmessage.messageid=es.messageID) " +
"LEFT JOIN attachment at ON (emailmessage.messageID=at.messageid) " +
"WHERE emailmessage.locallyDeleted = 'NO' "+privateString+" AND "+ searchString.substring((searchIndex+5),searchString.length())+" GROUP BY emailmessage.messageid " +
"ORDER BY " + sortmem + sortStr + " ";
}
if ((null != searchString) && (searchString.startsWith("SIMPLE :")))
{
searchString = searchString.substring(8);
appendStr = " where 1=1 AND (emailmessage.messageid like '%" + searchString + "%' OR emailmessage.messagedate like '%" + searchString + "%' OR emailmessage.mailfrom like '%" + searchString + "%' OR emailmessage.subject like '%h%' OR emailmessage.size like '%" + searchString + "%') and ";
strSQL = strSQL.replaceFirst("where ", appendStr);
}
// ATTENTION!!!!! THE FOLLOWING CODE IS A **HACK* IN ORDER
// TO GET RELATED INFO EMAIL HISTORY TO WORK!!! THIS IS NO
// WAY THE BEST METHOD FOR COMPLETING THIS FUNCTIONALITY,
// BUT TIME AND RESOURCES NECESSITATE THIS TYPE OF "GUERILLA"
// PROGRAMMING. PLEASE DO NOT ATTEMPT TO EXTEND THE FUNCTIONALITY
// OF THE FOLLOWING CODE; INSTEAD, SPEAK WITH YOUR PROJECT
// MANAGER AND TELL THEM THIS PIECE OF FUNCTIONALITY NEEDS
// TO BE RE-WRITTEN IN A MORE MANAGE-ABLE AND SCALABLE MANNER.
if ((searchString != null) && (searchString.startsWith("ADVANCED-RELATED:")))
{
searchString = searchString.substring(17);
strSQL = "SELECT emailmessage.messageid, emailmessage.messagedate, emailmessage.mailfrom, " +
"emailmessage.replyto, emailmessage.subject, emailmessage.size, emailmessage.Priority, " +
"emailmessage.messageRead AS readstatus, es.folderID AS EmailFolder, COUNT(at.attachmentid) AS noofattachments " +
"FROM emailmessagefolder es LEFT JOIN emailmessage ON " +
"(es.messageid=emailmessage.messageid) LEFT OUTER JOIN " +
"attachment at ON (emailmessage.messageid=at.messageid) WHERE " +
searchString + " AND emailmessage.locallyDeleted = 'NO' "+privateString+" AND (emailmessage.MovedToFolder=" + folderID.intValue() +
" OR emailmessage.MovedToFolder=0) GROUP BY emailmessage.messageid ORDER BY " +
sortmem + sortStr + " ";
//+ " LIMIT " + (beginindex - 1) + " ," + (endindex + 1);
}
// END REALLY BAD METHOD FOR ACHEIVING FUNCTIONALITY
cvdl.setSqlQuery(strSQL);
Collection col = cvdl.executeQuery();
Iterator it = col.iterator();
int i = 0;
while (it.hasNext())
{
i++;
HashMap hm = (HashMap)it.next();
int messageID = ((Long)hm.get("messageid")).intValue();
StringMember subject;
StringMember fromAddress;
StringMember toAddress;
StringMember messageSize;
StringMember attachmentNumber;
StringMember readIndication;
StringMember priority;
DateMember dateReceived;
IntMember intmem = new IntMember("messageid", messageID, 10, "URL", 'T', false, 10);
int emailFolderIDx = ((Long)hm.get("EmailFolder")).intValue();
IntMember emailFolderID = new IntMember("EmailFolder", emailFolderIDx, 10, "URL", 'T', false, 10);
if (hm.get("subject") != null)
{
subject = new StringMember("Subject", (String) hm.get("subject"), 10, "", 'T', true);
}else{
subject = new StringMember("Subject", "", 10, "", 'T', true);
}
if (hm.get("mailfrom") != null)
{
String formattedAddress = (String)hm.get("mailfrom");
formattedAddress = formattedAddress.replaceAll("<", "<");
formattedAddress = formattedAddress.replaceAll(">", ">");
fromAddress = new StringMember("From", formattedAddress, 10, "URL", 'T', true);
}else{
fromAddress = new StringMember("From", "", 10, "URL", 'T', true);
}
toAddress = new StringMember("To", getTOList(messageID), 10, "URL", 'T', true);
if (hm.get("messagedate") != null)
{
dateReceived = new DateMember("Received", (java.util.Date) hm.get("messagedate"), 10, "URL", 'T', false, 100, "EST");
}else{
dateReceived = new DateMember("Received", (new java.util.Date()), 10, "URL", 'T', false, 100, "EST");
}
/*
* Determine KB, MB, or GB for email size.
*/
if (hm.get("size") != null)
{
float size = ((Integer)hm.get("size")).floatValue();
DecimalFormat df = new DecimalFormat("###.#");
Integer s = new Integer((int)size);
String sizeStr = s.toString();
if (size > 1000000000)
{
size /= 1073741824; // 1GB
sizeStr = df.format(size) + "GB";
} else if (size > 1000000) {
size /= 1048576; // 1MB
sizeStr = df.format(size) + "MB";
} else if (size > 1000) {
size /= 1024; // 1KB
sizeStr = df.format(size) + "KB";
}
messageSize = new StringMember("Size", sizeStr, 10, "URL", 'T', false);
}else{
messageSize = new StringMember("Size", "1KB", 10, "URL", 'T', false);
}
if (hm.get("noofattachments") != null)
{
attachmentNumber = new StringMember("AttIndication", "" + ((Number)hm.get("noofattachments")).intValue(), 10, "URL", 'T', false);
}else{
attachmentNumber = new StringMember("AttIndication", "", 10, "URL", 'T', false);
}
if (hm.get("readstatus") != null)
{
readIndication = new StringMember("ReadIndication", (String) hm.get("readstatus"), 10, "URL", 'T', true);
}else{
readIndication = new StringMember("ReadIndication", "", 10, "URL", 'T', true);
}
if (hm.get("Priority") != null)
{
priority = new StringMember("Priority", (String) hm.get("Priority"), 10, "URL", 'T', true);
}else{
priority = new StringMember("Priority", "MEDIUM", 10, "URL", 'T', true);
}
EmailListElement ele = new EmailListElement(messageID);
ele.put("MessageID", intmem);
ele.put("Subject", subject);
ele.put("From", fromAddress);
ele.put("To", toAddress);
ele.put("Received", dateReceived);
ele.put("Size", messageSize);
ele.put("AttIndication", attachmentNumber);
ele.put("ReadIndication", readIndication);
ele.put("Priority", priority);
ele.put("EmailFolder", emailFolderID);
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();
emailList.put(newOrd, ele);
emailList.setTotalNoOfRecords(emailList.size());
emailList.setListType("Email");
emailList.setBeginIndex(beginindex);
emailList.setEndIndex(endindex);
} // end while(it.hasNext())
cvdl.clearParameters();
}catch(Exception e){
System.out.println("[Exception][EmailEJB.getEmailList] Exception Thrown: "+e);
e.printStackTrace();
}finally{
cvdl.destroy();
cvdl = null;
}
if (emailList == null)
{
emailList = new EmailList();
}
return emailList;
} // end getEmailList() method