Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/ExportServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/ExportServlet.java,v diff -u -r1.18 -r1.19 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/ExportServlet.java 23 May 2007 04:20:46 -0000 1.18 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/ExportServlet.java 28 Sep 2007 01:00:39 -0000 1.19 @@ -76,8 +76,8 @@ if ( generateCharts ) { logger.debug("writing out chart to directoryName: " + directoryName); - writeOutChart(request, "pie", directoryName); - writeOutChart(request, "bar", directoryName); + writeOutChart(request, response, VoteChartGenerator.CHART_TYPE_PIE, directoryName); + writeOutChart(request, response, VoteChartGenerator.CHART_TYPE_BAR, directoryName); logger.debug("basePath: " + basePath); } @@ -217,7 +217,7 @@ * @param chartType * @param directoryName */ - public void writeOutChart(HttpServletRequest request, String chartType, String directoryName) { + public void writeOutChart(HttpServletRequest request, HttpServletResponse response, String chartType, String directoryName) { logger.debug("File.separator: " + File.separator) ; String fileName=chartType + ".png"; logger.debug("output image fileName: " + fileName) ; @@ -226,18 +226,11 @@ try{ OutputStream out = new FileOutputStream(directoryName + File.separator + fileName); VoteChartGenerator voteChartGenerator= new VoteChartGenerator(); - JFreeChart chart=null; - if (chartType.equals("pie")) - { - chart = voteChartGenerator.createChart(request, "pie"); + JFreeChart chart = voteChartGenerator.createChart(request, chartType); + if ( chart != null ) { + response.setContentType("image/png"); + ChartUtilities.writeChartAsPNG(out, chart, 400, 300); } - else - { - chart = voteChartGenerator.createChart(request, "bar"); - } - logger.debug("chart:" + chart); - - ChartUtilities.writeChartAsPNG(out, chart, 400, 300); } catch(FileNotFoundException e) { Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteChartGenerator.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/Attic/VoteChartGenerator.java,v diff -u -r1.16 -r1.17 --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteChartGenerator.java 17 Sep 2006 06:29:22 -0000 1.16 +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteChartGenerator.java 28 Sep 2007 01:00:39 -0000 1.17 @@ -47,13 +47,15 @@ import org.lamsfoundation.lams.tool.vote.service.VoteServiceProxy; /** - *

Enables generation of enerates JFreeCharts

+ *

Enables generation of JFreeCharts

* * @author Ozgur Demirtas * */ public class VoteChartGenerator extends HttpServlet implements VoteAppConstants { static Logger logger = Logger.getLogger(VoteChartGenerator.class.getName()); + public static final String CHART_TYPE_PIE = "pie"; + public static final String CHART_TYPE_BAR = "bar"; public VoteChartGenerator(){ } @@ -123,46 +125,43 @@ public JFreeChart createChart(HttpServletRequest request, String type) { - logger.debug("chartType: " + type); - - if (type.equals("pie")) + if (type.equals(CHART_TYPE_PIE)) { return createPieChart (request); } - else if (type.equals("bar")) + else { return createBarChart (request); } - return null; } public JFreeChart createPieChart(HttpServletRequest request) { - logger.debug("starting createPieChart..."); DefaultPieDataset data= new DefaultPieDataset(); Map mapNominationsContent=(Map)request.getSession().getAttribute(MAP_STANDARD_NOMINATIONS_CONTENT); - logger.error("mapNominationsContent: " + mapNominationsContent); - Map mapVoteRatesContent=(Map)request.getSession().getAttribute(MAP_STANDARD_RATES_CONTENT); - logger.error("mapVoteRatesContent: " + mapVoteRatesContent); + if ( mapNominationsContent == null || mapNominationsContent == null ) { + logger.debug("No voting data, unable to create pie chart"); + return null; + } Iterator itMap = mapNominationsContent.entrySet().iterator(); while (itMap.hasNext()) { Map.Entry pairs = (Map.Entry)itMap.next(); - logger.debug("using the nomination content pair: " + pairs.getKey() + " = " + pairs.getValue()); - String voteRate=(String) mapVoteRatesContent.get(pairs.getKey()); - logger.debug("voteRate:" + voteRate); data.setValue(pairs.getValue().toString(), new Double(voteRate)); } JFreeChart chart=null; chart=ChartFactory.createPieChart3D(SESSION_VOTES_CHART , data, true, true, false); - logger.debug("chart: " + chart) ; - + + if ( logger.isDebugEnabled() ) { + logger.debug("chart: " + chart+" data: "+data) ; + } + return chart; } @@ -172,26 +171,28 @@ DefaultCategoryDataset data= new DefaultCategoryDataset(); Map mapNominationsContent=(Map)request.getSession().getAttribute(MAP_STANDARD_NOMINATIONS_CONTENT); - logger.error("mapNominationsContent: " + mapNominationsContent); - Map mapVoteRatesContent=(Map)request.getSession().getAttribute(MAP_STANDARD_RATES_CONTENT); - logger.error("mapVoteRatesContent: " + mapVoteRatesContent); + if ( mapNominationsContent == null || mapNominationsContent == null ) { + logger.debug("No voting data, unable to create pie chart"); + return null; + } Iterator itMap = mapNominationsContent.entrySet().iterator(); while (itMap.hasNext()) { Map.Entry pairs = (Map.Entry)itMap.next(); - logger.debug("using the nomination content pair: " + pairs.getKey() + " = " + pairs.getValue()); - String voteRate=(String) mapVoteRatesContent.get(pairs.getKey()); - logger.debug("voteRate:" + voteRate); data.setValue(new Double(voteRate), pairs.getValue().toString(), pairs.getValue().toString()); } JFreeChart chart=null; chart=ChartFactory.createBarChart3D(SESSION_VOTES_CHART , "Open Vote", "Percentage", data, PlotOrientation.VERTICAL, true, true, false); - logger.debug("chart: " + chart) ; + + if ( logger.isDebugEnabled() ) { + logger.debug("chart: " + chart+" data: "+data) ; + } + return chart; }