KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > ext > report > DownloadUsers


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

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 JavaDoc;
78 import java.util.Enumeration JavaDoc;
79
80
81 /**
82  * A list of users who have downloaded a certain number of times
83  *
84  * @author Michael Nash
85  */

86 public class DownloadUsers
87         extends ReportPage {
88     private static final String JavaDoc thisClass = DownloadUsers.class.getName() + ".";
89
90     /**
91      * Constructor
92      */

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     } /* DownloadUsers() */
101
102     /**
103      * Display the report
104      *
105      * @param out Destination for the report
106      * @throws HtmlException If a problem occurs building the HTML
107      */

108     public void display(PrintWriter JavaDoc out)
109             throws HtmlException {
110         String JavaDoc myName = (thisClass + "display(PrintWriter)");
111         DBConnectionPool myPool = null;
112         DBConnection myConnection = null;
113
114         /* connect to the database */
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 JavaDoc(getParam("CountMin")).intValue();
125                 maxCount = new Integer JavaDoc(getParam("CountMax")).intValue();
126             } catch (NumberFormatException JavaDoc ne) {
127                 throw new HtmlException(myName + ":Could not convert " +
128                         "min and max parameters to numbers.");
129             }
130
131             /* read all the sites and add 'em to the page */
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 JavaDoc 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                 } /* if within the limits */
169
170             } /* for each site */
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     } /* display(PrintWriter) */
183
184
185 } /* DownloadUsers */
186
187 /* DownloadUsers */
Popular Tags