| 1 | |
package org.paneris.bibliomania; |
| 2 | |
|
| 3 | |
import java.util.Enumeration; |
| 4 | |
import java.util.Vector; |
| 5 | |
|
| 6 | |
import org.melati.Melati; |
| 7 | |
import org.melati.poem.Column; |
| 8 | |
import org.melati.poem.FieldSet; |
| 9 | |
import org.melati.poem.Table; |
| 10 | |
import org.melati.poem.TailoredQuery; |
| 11 | |
import org.melati.poem.util.EnumUtils; |
| 12 | |
import org.webmacro.servlet.WebContext; |
| 13 | |
|
| 14 | |
|
| 15 | 0 | public class DownloadList extends BibliomaniaServlet { |
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
private static final long serialVersionUID = 1L; |
| 21 | |
|
| 22 | |
protected String bibliomaniaHandle(Melati melati, WebContext context) |
| 23 | |
throws Exception { |
| 24 | 0 | BibliomaniaDatabase db = (BibliomaniaDatabase)melati.getDatabase(); |
| 25 | 0 | assertRegisteredUser(db); |
| 26 | 0 | String template = "DownloadList.wm"; |
| 27 | 0 | User user = (User)melati.getUser(); |
| 28 | 0 | Column[] columns = {db.getProductTable().getIdColumn(), |
| 29 | |
db.getProductTable().getNameColumn(), |
| 30 | |
db.getProductTable().getBookColumn()}; |
| 31 | 0 | Table[] tables = { db.getProductTable(), |
| 32 | |
db.getShopOrderItemTable() }; |
| 33 | 0 | Vector where = new Vector(); |
| 34 | 0 | where.add("shoporderitem.authorised = true"); |
| 35 | 0 | where.add("shoporderitem.\"user\" =" + user.getTroid()); |
| 36 | 0 | where.add("shoporderitem.product = product.id"); |
| 37 | 0 | where.add("product.download IS NOT NULL"); |
| 38 | 0 | String whereClause = EnumUtils.concatenated(" AND ", where.elements()); |
| 39 | 0 | TailoredQuery q = new TailoredQuery("DISTINCT", columns, tables, whereClause, "product.book, product.name"); |
| 40 | 0 | Vector purchases = new Vector(); |
| 41 | 0 | for (Enumeration e = q.selection(); e.hasMoreElements();) { |
| 42 | 0 | FieldSet fs = (FieldSet)e.nextElement(); |
| 43 | 0 | purchases.add(db.getProductTable().getProductObject((Integer)fs.get("product_id").getCooked())); |
| 44 | 0 | } |
| 45 | 0 | context.put("purchases", purchases); |
| 46 | 0 | return template; |
| 47 | |
} |
| 48 | |
|
| 49 | |
} |