From 3d8328d2e842a9bb15d35e428235f45fb9d9da1d Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Tue, 20 Mar 2012 17:52:36 +0100 Subject: [PATCH] SONAR-3006 Remove ChartsControler and related code This is useless now the TimeMachine service has been replaced. --- .../server/charts/jruby/TrendsChart.java | 141 ------------------ .../app/controllers/charts_controller.rb | 59 -------- .../WEB-INF/app/helpers/chart_helper.rb | 22 --- .../webapp/WEB-INF/app/models/trends_chart.rb | 53 ------- .../server/charts/jruby/TrendsChartTest.java | 85 ----------- 5 files changed, 360 deletions(-) delete mode 100644 sonar-server/src/main/java/org/sonar/server/charts/jruby/TrendsChart.java delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/controllers/charts_controller.rb delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/helpers/chart_helper.rb delete mode 100644 sonar-server/src/test/java/org/sonar/server/charts/jruby/TrendsChartTest.java diff --git a/sonar-server/src/main/java/org/sonar/server/charts/jruby/TrendsChart.java b/sonar-server/src/main/java/org/sonar/server/charts/jruby/TrendsChart.java deleted file mode 100644 index 20a6263320a..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/charts/jruby/TrendsChart.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.server.charts.jruby; - -import org.apache.commons.lang.LocaleUtils; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.AxisLocation; -import org.jfree.chart.axis.DateAxis; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.plot.Marker; -import org.jfree.chart.plot.ValueMarker; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; -import org.jfree.chart.title.TextTitle; -import org.jfree.data.time.Day; -import org.jfree.data.time.TimeSeries; -import org.jfree.data.time.TimeSeriesCollection; -import org.jfree.ui.RectangleAnchor; -import org.jfree.ui.RectangleEdge; -import org.jfree.ui.RectangleInsets; -import org.jfree.ui.TextAnchor; -import org.sonar.server.charts.deprecated.BaseChart; - -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.text.DateFormat; -import java.text.DecimalFormat; -import java.text.ParseException; -import java.util.Date; -import java.util.SortedMap; -import java.util.TreeMap; - -public class TrendsChart extends BaseChart { - - private XYPlot plot; - private SortedMap seriesById; - private int percentAxisId = -1; - private boolean displayLegend; - - public TrendsChart(int width, int height, String localeKey, boolean displayLegend) { - super(width, height); - this.displayLegend = displayLegend; - seriesById = new TreeMap(); - plot = new XYPlot(); - DateAxis dateAxis = new DateAxis(); - dateAxis.setDateFormatOverride(DateFormat.getDateInstance(DateFormat.SHORT, LocaleUtils.toLocale(localeKey))); - plot.setDomainAxis(dateAxis); - } - - public void initSerie(Long serieId, String legend, boolean isPercent) { - TimeSeries series = new TimeSeries(legend); - - int index=seriesById.size(); - seriesById.put(serieId, series); - - TimeSeriesCollection timeSeriesColl = new TimeSeriesCollection(); - timeSeriesColl.addSeries(series); - plot.setDataset(index, timeSeriesColl); - - if (isPercent) { - if (percentAxisId == -1) { - NumberAxis rangeAxis = new NumberAxis(); - rangeAxis.setNumberFormatOverride(new DecimalFormat("0'%'")); - rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); - rangeAxis.setUpperBound(100.0); - rangeAxis.setLowerBound(0.0); - plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_LEFT); - plot.setRangeAxis(index, rangeAxis); - plot.mapDatasetToRangeAxis(index, index); - percentAxisId = index; - - } else { - plot.mapDatasetToRangeAxis(index, percentAxisId); - } - } else { - NumberAxis rangeAxis = new NumberAxis(displayLegend ? legend : null); - rangeAxis.setAutoRangeIncludesZero(false); - rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); - rangeAxis.setAutoRangeMinimumSize(2.0); - plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_RIGHT); - plot.setRangeAxis(index, rangeAxis); - plot.mapDatasetToRangeAxis(index, index); - } - - XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); - renderer.setBaseShapesVisible(false); - renderer.setSeriesStroke(0, new BasicStroke(2.0f)); - renderer.setSeriesPaint(0, COLORS[index % COLORS.length]); - plot.setRenderer(index, renderer); - } - - public void addMeasure(Double value, Date date, Long serieId) { - seriesById.get(serieId).addOrUpdate(new Day(date), value); - } - - public void addLabel(Date date, String label) throws ParseException { - addLabel(date, label, false); - } - - public void addLabel(Date date, String label, boolean lower) throws ParseException { - Day d = new Day(date); - double millis = d.getFirstMillisecond(); - Marker marker = new ValueMarker(millis); - marker.setLabel(label); - marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); - marker.setLabelTextAnchor(TextAnchor.TOP_LEFT); - Color c = new Color(17, 40, 95); - marker.setLabelPaint(c); - marker.setPaint(c); - marker.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3.0f, new float[]{5f, 5f, 5f, 5f}, 2.0f)); - if (lower) { - marker.setLabelOffset(new RectangleInsets(18, 0, 0, 5)); - } - plot.addDomainMarker(marker); - } - - @Override - protected BufferedImage getChartImage() throws IOException { - JFreeChart chart = new JFreeChart(null, TextTitle.DEFAULT_FONT, plot, true); - configureChart(chart, displayLegend ? RectangleEdge.BOTTOM : null); - return super.getBufferedImage(chart); - } -} \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/charts_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/charts_controller.rb deleted file mode 100644 index 4327242c00c..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/charts_controller.rb +++ /dev/null @@ -1,59 +0,0 @@ -# -# Sonar, entreprise quality control tool. -# Copyright (C) 2008-2012 SonarSource -# mailto:contact AT sonarsource DOT com -# -# Sonar is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# Sonar is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with Sonar; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 -# - -class ChartsController < ApplicationController - - DEFAULT_TRENDS_WIDTH = 700 - DEFAULT_TRENDS_HEIGHT = 250 - - CHART_COLORS = ["4192D9", "800000", "A7B307", "913C9F", "329F4D"] - - def trends - resource=Project.by_key(params[:id]) - bad_request("Unknown resource") unless resource - access_denied unless has_role?(:user, resource) - - metric_keys=params[:metrics] - metrics=[] - if metric_keys - metric_keys.split(',').each do |key| - metric=Metric.by_key(key) - metrics< 'image/png', :disposition => 'inline' - end -end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/chart_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/chart_helper.rb deleted file mode 100644 index 3f0594566f9..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/chart_helper.rb +++ /dev/null @@ -1,22 +0,0 @@ -# -# Sonar, entreprise quality control tool. -# Copyright (C) 2008-2012 SonarSource -# mailto:contact AT sonarsource DOT com -# -# Sonar is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# Sonar is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with Sonar; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 -# -module ChartHelper - -end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/trends_chart.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/trends_chart.rb index 0780d64a390..207c695598d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/trends_chart.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/trends_chart.rb @@ -19,26 +19,6 @@ # class TrendsChart - def self.png_chart(width, height, resource, metrics, locale, display_legend, options={}) - java_chart = Java::OrgSonarServerChartsJruby::TrendsChart.new(width, height, locale.to_s.gsub(/\-/, '_'), display_legend) - - init_series(java_chart, metrics) - metric_ids=metrics.map{|m| m.id} - add_measures(java_chart, time_machine_measures(resource, metric_ids, options)) - add_labels(java_chart, resource); - - export_chart_as_png(java_chart) - end - - - protected - - def self.init_series(java_chart, metrics) - metrics.each do |metric| - java_chart.initSerie(metric.id, metric.short_name, metric.val_type==Metric::VALUE_TYPE_PERCENT) - end - end - def self.time_machine_measures(resource, metric_ids, options={}) unless metric_ids.empty? sql= "select s.created_at as created_at, m.value as value, m.metric_id as metric_id, s.id as sid " + @@ -65,38 +45,5 @@ class TrendsChart ProjectMeasure.connection.select_all(Project.send(:sanitize_sql, conditions)) end end - - def self.add_measures(java_chart, sqlresult) - if sqlresult && sqlresult.size>0 - sqlresult.each do |hash| - value = hash["value"].to_f - time = Time.parse( hash["created_at"].to_s ) - serie_id=hash["metric_id"].to_i - java_chart.addMeasure(value, time, serie_id) - end - end - end - - def self.add_labels(java_chart, resource) - categories=EventCategory.categories(true) - category_names=categories.map{|cat| cat.name} - Event.find(:all, :conditions => {:resource_id => resource.id}).each do |event| - if category_names.include?(event.category) - time = Time.parse( event.event_date.to_s ) - java_chart.addLabel(time, event.name, event.category==EventCategory::KEY_ALERT) - end - end - end - - def self.export_chart_as_png(java_chart) - java_int_array_to_bytes(java_chart.exportChartAsPNG()) - end - - def self.java_int_array_to_bytes( java_int_array ) - # pack does not exists on the return java array proxy object - # the java proxy array contains integers, they must be packed - # to return a correct byte array stream (c*) - [].concat(java_int_array).pack("c*") - end end \ No newline at end of file diff --git a/sonar-server/src/test/java/org/sonar/server/charts/jruby/TrendsChartTest.java b/sonar-server/src/test/java/org/sonar/server/charts/jruby/TrendsChartTest.java deleted file mode 100644 index 75696e81bd9..00000000000 --- a/sonar-server/src/test/java/org/sonar/server/charts/jruby/TrendsChartTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.server.charts.jruby; - -import org.sonar.server.charts.deprecated.BaseChartTest; - -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.text.ParseException; - -public class TrendsChartTest extends BaseChartTest { - private static final int WIDTH = 900; - private static final int HEIGHT = 350; - - private TrendsChart chart; - - public void testTrendsChart() throws ParseException, IOException { - chart = new TrendsChart(WIDTH, HEIGHT, "fr", true); - chart.initSerie(0L, "Global", false); - chart.initSerie(6L, "Efficiency", true); - chart.initSerie(9L, "Maintanability", false); - chart.initSerie(3L, "Portability", false); - chart.initSerie(24L, "Reliability", true); - chart.initSerie(60L, "Usability", false); - - chart.addMeasure(20.0, stringToDate("12-10-07 8h30"), 0L); - chart.addMeasure(35.0, stringToDate("12-10-07 8h30"), 6L); - chart.addMeasure(12.4, stringToDate("12-10-07 8h30"), 9L); - chart.addMeasure(99.99, stringToDate("12-10-07 8h30"), 3L); - chart.addMeasure(2.3, stringToDate("12-10-07 8h30"), 24L); - chart.addMeasure(12.5, stringToDate("12-10-07 8h30"), 60L); - - chart.addMeasure(10.0, stringToDate("12-11-07 8h30"), 0L); - chart.addMeasure(30.0, stringToDate("12-11-07 8h30"), 6L); - chart.addMeasure(22.4, stringToDate("12-11-07 8h30"), 9L); - chart.addMeasure(99.99, stringToDate("12-11-07 8h30"), 3L); - chart.addMeasure(0.3, stringToDate("12-11-07 8h30"), 24L); - chart.addMeasure(12.5, stringToDate("12-11-07 8h30"), 60L); - - chart.addMeasure(30.0, stringToDate("12-12-07 8h30"), 0L); - chart.addMeasure(15.0, stringToDate("12-12-07 8h30"), 6L); - chart.addMeasure(82.4, stringToDate("12-12-07 8h30"), 9L); - chart.addMeasure(99.99, stringToDate("12-12-07 8h30"), 3L); - chart.addMeasure(52.3, stringToDate("12-12-07 8h30"), 24L); - chart.addMeasure(12.5, stringToDate("12-12-07 8h30"), 60L); - - chart.addLabel(stringToDate("12-11-07 12h35"), "Label A"); - chart.addLabel(stringToDate("11-11-07 12h35"), "Label B", true); - - BufferedImage img = chart.getChartImage(); - assertChartSizeGreaterThan(img, 1000); - saveChart(img, "trends-chart.png"); - } - - - public void testSingleSerieWithoutLegends() throws ParseException, IOException { - chart = new TrendsChart(WIDTH, HEIGHT, "fr", false); - chart.initSerie(0L, "single", false); - - chart.addMeasure(20.0, stringToDate("12-10-07 8h30"), 0L); - chart.addMeasure(10.0, stringToDate("12-11-07 8h30"), 0L); - chart.addMeasure(30.0, stringToDate("12-12-07 8h30"), 0L); - - BufferedImage img = chart.getChartImage(); - assertChartSizeGreaterThan(img, 1000); - saveChart(img, "trends-single-without-legends.png"); - } -} -- 2.39.5