diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-11-27 12:49:30 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-11-27 12:49:30 +0100 |
commit | 1b088d7ea2338d9371d6e83f7cb91a50f18a811c (patch) | |
tree | 47a67f29934e2bad6186ed545edcf6d4031ff6b9 | |
parent | 509a6ae09b27e9442e50550ecc0e63f1380e63a1 (diff) | |
download | sonarqube-1b088d7ea2338d9371d6e83f7cb91a50f18a811c.tar.gz sonarqube-1b088d7ea2338d9371d6e83f7cb91a50f18a811c.zip |
SONAR-4893 Fix characteristic infos on an issue
4 files changed, 16 insertions, 149 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb index 12de215d9ca..2ced8040fe1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb @@ -209,8 +209,8 @@ class IssueController < ApplicationController rule_id = @issue_results.rule(@issue).id @requirement = Characteristic.first( - :conditions => ['quality_models.name=? AND characteristics.rule_id=? AND characteristics.enabled=?', 'SQALE', rule_id, true], - :include => [:quality_model, {:parents => :parents}, :characteristic_properties] + :conditions => ['characteristics.rule_id=? AND characteristics.enabled=?', rule_id, true], + :include => [{:parent => :parent}] ) render :partial => 'issue/technicaldebt' end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic.rb index acfa831fc8e..db4084008f9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic.rb @@ -18,24 +18,25 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # class Characteristic < ActiveRecord::Base + NAME_MAX_SIZE=100 - has_and_belongs_to_many :children, :class_name => 'Characteristic', :join_table => 'characteristic_edges', - :foreign_key => 'parent_id', :association_foreign_key => 'child_id', :order => 'characteristic_order ASC' + FUNCTION_CONSTANT_ISSUE = "constant_issue"; + FUNCTION_LINEAR = "linear"; + FUNCTION_LINEAR_WITH_OFFSET = "linear_offset"; - has_and_belongs_to_many :parents, :class_name => 'Characteristic', :join_table => 'characteristic_edges', - :foreign_key => 'child_id', :association_foreign_key => 'parent_id' + DAY = "d" + HOUR = "h" + MINUTE = "mn" + belongs_to :parent, :class_name => 'Characteristic', :foreign_key => 'parent_id' belongs_to :rule - belongs_to :quality_model - has_many :characteristic_properties, :dependent => :delete_all - validates_uniqueness_of :name, :scope => [:quality_model_id, :enabled], :case_sensitive => false, :if => Proc.new { |c| c.rule_id.nil? && c.enabled } + validates_uniqueness_of :name, :scope => [:enabled], :case_sensitive => false, :if => Proc.new { |c| c.rule_id.nil? && c.enabled } validates_length_of :name, :in => 1..NAME_MAX_SIZE, :allow_blank => false, :if => Proc.new { |c| c.rule_id.nil? } - validates_presence_of :quality_model def root? - depth==1 + parent_id.nil? end def key @@ -50,67 +51,8 @@ class Characteristic < ActiveRecord::Base result end - # return the first parent - def parent - parents.empty? ? nil : parents[0] - end - - def enabled_children - children.select{|c| c.enabled} - end - - def properties - characteristic_properties - end - - def property(key) - properties.each do |p| - return p if p.key==key - end - nil - end - - # the property is not saved - def set_property(key, value) - p=property(key) - unless p - p=characteristic_properties.build(:kee => key) - end - if (value.is_a?(Fixnum) || value.is_a?(Float)) - p.value=value.to_f - else - p.text_value=value.to_s - end - p - end - - def save_property(key, value) - p=set_property(key, value) - p.save - end - - def property_value(key, default_value=nil) - p=property(key) - if p - (p.value ? p.value.to_f : nil) || p.text_value || default_value - else - default_value - end - end - - - ### For Requirement - - def function - property(CharacteristicProperty::PROPERTY_REMEDIATION_FUNCTION) - end - - def factor - property(CharacteristicProperty::PROPERTY_REMEDIATION_FACTOR) - end - - def offset - property(CharacteristicProperty::PROPERTY_OFFSET) - end + #def enabled_children + # children.select{|c| c.enabled} + #end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic_property.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic_property.rb index fae9b0c2d69..d095232edf6 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic_property.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/characteristic_property.rb @@ -18,42 +18,6 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # class CharacteristicProperty < ActiveRecord::Base - KEY_MAX_SIZE=100 - PROPERTY_REMEDIATION_FUNCTION = "remediationFunction"; - PROPERTY_REMEDIATION_FACTOR = "remediationFactor"; - PROPERTY_OFFSET = "offset"; - - FUNCTION_CONSTANT = "constant_resource"; - FUNCTION_LINEAR = "linear"; - FUNCTION_LINEAR_WITH_OFFSET = "linear_offset"; - FUNCTION_LINEAR_WITH_THRESHOLD = "linear_threshold"; - - DAY = "d" - HOUR = "h" - MINUTE = "mn" - - belongs_to :characteristic - validates_length_of :kee, :in => 1..KEY_MAX_SIZE, :allow_blank => false - - def key - kee - end - - def constant? - text_value == FUNCTION_CONSTANT - end - - def linear? - text_value == FUNCTION_LINEAR - end - - def linearWithThreshold? - text_value == FUNCTION_LINEAR_WITH_THRESHOLD - end - - def linearWithOffset? - text_value == FUNCTION_LINEAR_WITH_OFFSET - end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/quality_model.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/quality_model.rb index 65fd62f7c1b..05bb61424fe 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/quality_model.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/quality_model.rb @@ -22,43 +22,4 @@ class QualityModel < ActiveRecord::Base validates_length_of :name, :within => 1..100 validates_uniqueness_of :name - has_many :characteristics, :dependent => :delete_all - - def root_characteristics(only_enabled=true) - @roots ||= - begin - characteristics.select do |c| - c.parents.empty? && (!only_enabled || c.enabled) - end - end - end - - def characteristics_with_rule(only_enabled=true) - @characteristics_with_rule ||= - begin - characteristics.select do |c| - (!c.rule_id.nil?) && (!only_enabled || c.enabled) - end - end - end - - def characteristics_without_rule(only_enabled=true) - @characteristics_without_rule ||= - begin - characteristics.select do |c| - c.rule_id.nil? && (!only_enabled || c.enabled) - end - end - end - - # be careful, can return disabled characteristic - def characteristic(id) - @characteristics_by_id ||= - begin - hash={} - characteristics.each {|c| hash[c.id]=c} - hash - end - @characteristics_by_id[id] - end -end
\ No newline at end of file +end |