*/
package org.sonar.core.measure;
+import com.google.common.base.Strings;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.ServerComponent;
+import org.sonar.api.measures.Metric;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.utils.DateUtils;
filter.setSortOn(MeasureFilterSort.Field.valueOf(s.toUpperCase()));
}
}
+ for (int index = 1; index <= 3; index++) {
+ MeasureFilterCondition condition = toCondition(properties, index);
+ if (condition != null) {
+ filter.addCondition(condition);
+ }
+ }
// if (map.containsKey("sortPeriod")) {
// filter.setSortOnPeriod(((Long) map.get("sortPeriod")).intValue());
// }
return filter;
}
+ private MeasureFilterCondition toCondition(Map<String, Object> props, int index) {
+ MeasureFilterCondition condition = null;
+ String metricKey = (String) props.get("c" + index + "metric");
+ String op = (String) props.get("c" + index + "op");
+ String val = (String) props.get("c" + index + "val");
+ if (!Strings.isNullOrEmpty(metricKey) && !Strings.isNullOrEmpty(op) && !Strings.isNullOrEmpty(val)) {
+ Metric metric = metricFinder.findByKey(metricKey);
+ condition = new MeasureFilterCondition(metric, op, Double.parseDouble(val));
+ String period = (String) props.get("c" + index + "period");
+ if (period != null) {
+ condition.setPeriod(Integer.parseInt(period));
+ }
+ }
+ return condition;
+ }
+
private List<String> toList(@Nullable Object obj) {
List<String> result = null;
if (obj != null) {
if (obj instanceof String) {
- result = Arrays.asList((String)obj);
+ result = Arrays.asList((String) obj);
} else {
- result = (List<String>)obj;
+ result = (List<String>) obj;
}
}
return result;
*/
public class DatabaseVersion implements BatchComponent, ServerComponent {
- public static final int LAST_VERSION = 356;
+ public static final int LAST_VERSION = 357;
public static enum Status {
UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('354');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('355');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('356');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('357');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
class TreemapDisplay < Display
KEY = :treemap
+
+ def initialize(filter)
+ filter.set_criteria_default_value('columns', ['metric:ncloc', 'metric:violations'])
+ @metric_ids = @columns.map { |column| column.metric.id if column.metric }.compact.uniq
+ end
end
DISPLAYS = [ListDisplay, TreemapDisplay]
end
-# ==== Options
-# :user : the authenticated user
+ # ==== Options
+ # :user : the authenticated user
def execute(controller, options={})
init_results
--- /dev/null
+#
+# 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
+#
+
+#
+# Sonar 3.4
+#
+class MoveExistingMeasureFilters < ActiveRecord::Migration
+
+ # the new table
+ class MeasureFilter < ActiveRecord::Base
+ end
+
+ # the old tables
+ class FilterColumn < ActiveRecord::Base
+ set_table_name 'filter_columns'
+ end
+ class Criteria < ActiveRecord::Base
+ set_table_name 'criteria'
+ end
+ class Resource < ActiveRecord::Base
+ set_table_name 'projects'
+ end
+ class Filter < ActiveRecord::Base
+ set_table_name 'filters'
+ end
+
+
+ def self.up
+ old_filters = Filter.find(:all)
+ say_with_time "Moving #{old_filters.size} measure filters" do
+ old_filters.each do |old_filter|
+ move(old_filter)
+ end
+ end
+ end
+
+ private
+
+ def self.move(old_filter)
+ new_filter = MeasureFilter.new
+ new_filter.name = old_filter.name
+ new_filter.user_id = old_filter.user_id
+ new_filter.shared = old_filter.shared
+ data = []
+ data << 'onFavourites=true' if old_filter.favourites
+ if old_filter.resource_id
+ resource = Project.find(:first, :conditions => {:id => old_filter.id})
+ data << "base=#{resource.kee}" if resource
+ end
+ data << "pageSize=#{old_filter.page_size}" if old_filter.page_size
+
+ columns = []
+ asc = nil
+ sort = nil
+ old_columns = FilterColumn.find(:all, :conditions => ['filter_id=?', old_filter.id], :order => 'order_index')
+ old_columns.each do |old_column|
+ column_key = old_column.family
+ column_key += ":#{old_column.kee}" if old_column.kee
+ columns << column_key
+ # TODO old_column.variation
+ if old_column.sort_direction=='ASC'
+ asc = true
+ sort = column_key
+ elsif old_column.sort_direction=='DESC'
+ asc = false
+ sort = column_key
+ end
+ end
+ data << "columns=#{columns.join(',')}" unless columns.empty?
+ if sort
+ data << "sort=#{sort}"
+ data << "asc=#{asc}"
+ end
+
+ # TODO move criteria
+
+ new_filter.data = data.join('|') unless data.empty?
+ new_filter.save
+ # TODO Filter.delete(old_filter.id)
+ end
+end