/**
* LibreSource
* Copyright (C) 2004-2008 Artenum SARL / INRIA
* http://www.libresource.org - contact@artenum.com
*
* This file is part of the LibreSource software,
* which can be used and distributed under license conditions.
* The license conditions are provided in the LICENSE.TXT file
* at the root path of the packaging that enclose this file.
* More information can be found at
* - http://dev.libresource.org/home/license
*
* Initial authors :
*
* Guillaume Bort / INRIA
* Francois Charoy / Universite Nancy 2
* Julien Forest / Artenum
* Claude Godart / Universite Henry Poincare
* Florent Jouille / INRIA
* Sebastien Jourdain / INRIA / Artenum
* Yves Lerumeur / Artenum
* Pascal Molli / Universite Henry Poincare
* Gerald Oster / INRIA
* Mariarosa Penzi / Artenum
* Gerard Sookahet / Artenum
* Raphael Tani / INRIA
*
* Contributors :
*
* Stephane Bagnier / Artenum
* Amadou Dia / Artenum-IUP Blois
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
package org.libresource.web.controllers.core;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.libresource.Libresource;
import org.libresource.core.CoreConstants;
import org.libresource.core.interfaces.LibresourceStatsService;
import org.libresource.web.Controller;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ProjectStatsController implements Controller {
public Object process(URI resource, HttpServletRequest request, HttpServletResponse response)
throws Exception {
LibresourceStatsService libresourceStatsService = (LibresourceStatsService) Libresource.getService(CoreConstants.SERVICE_STAT);
try {
request.setAttribute("stats", libresourceStatsService.getProjectStats(resource));
} catch (Exception e) {
}
if (StatsCache.getImage(resource, DrawPieChartHelper.MOST_ACTIVE_USERS) == null) {
JFreeChart chart = DrawPieChartHelper.drawChart(resource, DrawPieChartHelper.MOST_ACTIVE_USERS);
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ChartUtilities.writeChartAsPNG(baos, chart, 500, 250, info);
StringWriter writer = new StringWriter();
ChartUtilities.writeImageMap(new PrintWriter(writer), DrawPieChartHelper.MOST_ACTIVE_USERS, info);
StatsCache.putItem(baos.toByteArray(), writer.toString(), resource, DrawPieChartHelper.MOST_ACTIVE_USERS);
}
request.setAttribute(DrawPieChartHelper.MOST_ACTIVE_USERS, StatsCache.getMap(resource, DrawPieChartHelper.MOST_ACTIVE_USERS));
if (StatsCache.getImage(resource, DrawPieChartHelper.PREFERED_RESOURCES) == null) {
JFreeChart chart = DrawPieChartHelper.drawChart(resource, DrawPieChartHelper.PREFERED_RESOURCES);
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ChartUtilities.writeChartAsPNG(baos, chart, 500, 250, info);
StringWriter writer = new StringWriter();
ChartUtilities.writeImageMap(new PrintWriter(writer), DrawPieChartHelper.PREFERED_RESOURCES, info);
StatsCache.putItem(baos.toByteArray(), writer.toString(), resource, DrawPieChartHelper.PREFERED_RESOURCES);
}
request.setAttribute(DrawPieChartHelper.PREFERED_RESOURCES, StatsCache.getMap(resource, DrawPieChartHelper.PREFERED_RESOURCES));
if (StatsCache.getImage(resource, DrawPieChartHelper.MOST_ACTIVE_RESOURCES) == null) {
JFreeChart chart = DrawPieChartHelper.drawChart(resource, DrawPieChartHelper.MOST_ACTIVE_RESOURCES);
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ChartUtilities.writeChartAsPNG(baos, chart, 500, 250, info);
StringWriter writer = new StringWriter();
ChartUtilities.writeImageMap(new PrintWriter(writer), DrawPieChartHelper.MOST_ACTIVE_RESOURCES, info);
StatsCache.putItem(baos.toByteArray(), writer.toString(), resource, DrawPieChartHelper.MOST_ACTIVE_RESOURCES);
}
request.setAttribute(DrawPieChartHelper.MOST_ACTIVE_RESOURCES, StatsCache.getMap(resource, DrawPieChartHelper.MOST_ACTIVE_RESOURCES));
return "/pages/modules/core/projectStats.jsp";
}
}
|