1 64 65 package com.jcorporate.expresso.ext.report; 66 67 import com.jcorporate.expresso.core.db.DBConnection; 68 import com.jcorporate.expresso.core.db.DBConnectionPool; 69 import com.jcorporate.expresso.core.db.DBException; 70 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 71 import com.jcorporate.expresso.core.security.User; 72 import com.jcorporate.expresso.core.security.UserInfo; 73 import com.jcorporate.expresso.ext.dbobj.DownloadLog; 74 import com.jcorporate.expresso.services.html.HtmlException; 75 import com.jcorporate.expresso.services.html.ReportPage; 76 77 import java.io.PrintWriter ; 78 import java.util.Enumeration ; 79 80 81 86 public class DownloadUsers 87 extends ReportPage { 88 private static final String thisClass = DownloadUsers.class.getName() + "."; 89 90 93 public DownloadUsers() 94 throws HtmlException { 95 super(); 96 setTitle("Multiple Download Users"); 97 addParam("CountMin", "Download Count Minimum", "N", "0"); 98 addParam("CountMax", "Download Count Maximum", "N", "999999999"); 99 addParam("FileNumber", "File Number (blank for all)", "N", ""); 100 } 101 102 108 public void display(PrintWriter out) 109 throws HtmlException { 110 String myName = (thisClass + "display(PrintWriter)"); 111 DBConnectionPool myPool = null; 112 DBConnection myConnection = null; 113 114 115 try { 116 myPool = DBConnectionPool.getInstance(this.getDataContext()); 117 myConnection = myPool.getConnection("Multiple Download Users " + 118 "Report"); 119 120 int minCount = 0; 121 int maxCount = 0; 122 123 try { 124 minCount = new Integer (getParam("CountMin")).intValue(); 125 maxCount = new Integer (getParam("CountMax")).intValue(); 126 } catch (NumberFormatException ne) { 127 throw new HtmlException(myName + ":Could not convert " + 128 "min and max parameters to numbers."); 129 } 130 131 132 User userList = new User(); 133 userList.setDataContext(this.getDBName()); 134 135 UserInfo oneUser = null; 136 DownloadLog dl = new DownloadLog(SecuredDBObject.SYSTEM_ACCOUNT); 137 dl.setDataContext(this.getDataContext()); 138 addLine("Users who have downloaded at least " + 139 getParam("CountMin") + " times, and no more than " + 140 getParam("CountMax") + " times."); 141 142 if (getParam("FileNumber") != null) { 143 addLine("Downloads of File Number " + getParam("FileNumber") + 144 " only."); 145 } else { 146 addLine("Downloads of Any File Number"); 147 } 148 149 startTable("Users", "User ID|Login Name|EMail|Download Count"); 150 151 for (Enumeration e = userList.getAllUsers().elements(); 152 e.hasMoreElements();) { 153 oneUser = (UserInfo) e.nextElement(); 154 dl.clear(); 155 156 if (!getParam("FileNumber").equals("")) { 157 dl.setField(DownloadLog.FLD_FILE_NUMBER, getParam("FileNumber")); 158 } 159 160 dl.setField(DownloadLog.FLD_EXP_UID, oneUser.getUid()); 161 162 int number = dl.count(); 163 164 if ((number >= minCount) && (number <= maxCount)) { 165 addRow(oneUser.getUid() + "|" + 166 oneUser.getLoginName() + "|" + 167 oneUser.getEmail() + "|" + number); 168 } 169 170 } 171 172 173 endTable(); 174 } catch (DBException de) { 175 throw new HtmlException(myName + ":Database Exception:" + 176 de.getMessage()); 177 } finally { 178 myPool.release(myConnection); 179 } 180 181 super.display(out); 182 } 183 184 185 } 186 187 | Popular Tags |