Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
19   90   8   6.33
8   45   0.42   3
3     2.67  
1    
 
 
  ReportDownloadController       Line # 34 19 8 0% 0.0
 
No Tests
 
1    /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10    * the Free Software Foundation; either version 2 of the License, or
11    * (at your option) any later version.
12    *
13    * This program is distributed in the hope that it will be useful,
14    * but WITHOUT ANY WARRANTY; without even the implied warranty of
15    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16    * GNU General Public License for more details.
17    */
18   
19    package org.itracker.web.servlets;
20   
21    import java.io.IOException;
22   
23    import javax.servlet.ServletConfig;
24    import javax.servlet.ServletException;
25    import javax.servlet.ServletOutputStream;
26    import javax.servlet.http.HttpServletRequest;
27    import javax.servlet.http.HttpServletResponse;
28   
29    import org.apache.log4j.Logger;
30    import org.itracker.model.Report;
31    import org.itracker.services.ReportService;
32   
33   
 
34    public class ReportDownloadController extends GenericController {
35   
36    private static final Logger logger = Logger.getLogger(ReportDownloadController.class);
37    /**
38    *
39    */
40    private static final long serialVersionUID = 1L;
41   
 
42  0 toggle public ReportDownloadController() {
43    }
44   
 
45  0 toggle public void init(ServletConfig config) {
46   
47    }
48   
 
49  0 toggle public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
50  0 if(! isLoggedInWithRedirect(request, response)) {
51  0 return;
52    }
53   
54    // TODO: the 2-3 lines are most propably not used; commented, task added
55    // Commented more not used lines, but added a task for testing.
56    // HttpSession session = request.getSession();
57    // UserModel user = (UserModel) session.getAttribute("user");
58    // User user = (session == null ? null : (User) session.getAttribute(Constants.USER_KEY));
59   
60  0 try {
61  0 ReportService reportService = getITrackerServices(getServletContext()).getReportService();
62   
63  0 Integer reportId = null;
64  0 Report report = null;
65   
66  0 try {
67  0 reportId = new Integer((request.getParameter("id") == null ? "-1" : (request.getParameter("id"))));
68  0 report = reportService.getReportDAO().findByPrimaryKey(reportId);
69    } catch(NumberFormatException nfe) {
70  0 if (logger.isDebugEnabled()) {
71  0 logger.debug("Invalid reportId " + request.getParameter("id") + " specified.");
72    }
73    }
74   
75  0 if(report == null) {
76  0 forward("/error.jsp", request, response);
77  0 return;
78    }
79   
80  0 response.setHeader("Content-Disposition", "attachment; filename=report" + report.getId() + "\"");
81  0 ServletOutputStream out = response.getOutputStream();
82    //out.write(reportService.getReportFile(reportId));
83  0 out.close();
84    } catch(IOException ioe) {
85  0 logger.info("Unable to display report.", ioe);
86    }
87   
88  0 return;
89    }
90    }