From: Fabrice Bellingard Date: Thu, 28 Apr 2011 16:47:52 +0000 (+0200) Subject: SONAR-2382 Create a new "reviews" web service API X-Git-Tag: 2.8~81 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=866f8e33a312a316c0abe86a35a341c9dd470484;p=sonarqube.git SONAR-2382 Create a new "reviews" web service API --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb index 0f38dda8b02..f78bc3fefbc 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb @@ -92,7 +92,7 @@ class Api::ViolationsController < Api::ResourceRestController end def rest_to_json(rule_failures) - JSON(rule_failures.collect{|rule_failure| rule_failure.to_hash_json(params['include_review']=="true"?true:false)}) + JSON(rule_failures.collect{|rule_failure| rule_failure.to_hash_json(params['include_review']=="true")}) end def rest_to_xml(rule_failures) @@ -100,7 +100,7 @@ class Api::ViolationsController < Api::ResourceRestController xml.instruct! xml.violations do rule_failures.each do |rule_failure| - rule_failure.to_xml(xml, params['include_review']=="true"?true:false) + rule_failure.to_xml(xml, params['include_review']=="true") end end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb index 88deba8df15..90ef876cbeb 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb @@ -62,7 +62,7 @@ class Review < ActiveRecord::Base values={:not_type => Review::TYPE_FALSE_POSITIVE} end - ids=options['ids'] + ids=options['ids'].split(',') if options['ids'] if options[:id] conditions << "id=:id" values[:id]=options[:id].to_i @@ -71,40 +71,56 @@ class Review < ActiveRecord::Base values[:ids]=ids.map{|id| id.to_i} end - statuses=options['statuses'] - if statuses && statuses.size>0 && !statuses[0].blank? - conditions << "status in (:statuses)" - values[:statuses]=statuses - end - - projects=options['projects'] + projects=options['projects'].split(',') if options['projects'] if projects && projects.size>0 && !projects[0].blank? conditions << "project_id in (:projects)" - values[:projects]=projects + projectIds = [] + projects.each do |project| + foundProject = Project.by_key(project) + projectIds << foundProject.id if foundProject + end + values[:projects]=projectIds end - resources=options['resources'] + resources=options['resources'].split(',') if options['resources'] if resources && resources.size>0 && !resources[0].blank? conditions << "resource_id in (:resources)" - values[:resources]=resources + resourceIds = [] + resources.each do |resource| + foundResource = Project.by_key(resource) + resourceIds << foundResource.id if foundResource + end + values[:resources]=resourceIds + end + + statuses=options['statuses'].split(',') if options['statuses'] + if statuses && statuses.size>0 && !statuses[0].blank? + conditions << "status in (:statuses)" + values[:statuses]=statuses end - severities=options['severities'] + severities=options['severities'].split(',') if options['severities'] if severities && severities.size>0 && !severities[0].blank? conditions << "severity in (:severities)" values[:severities]=severities end - authors=options['authors'] + authors=options['authors'].split(',') if options['authors'] if authors && authors.size>0 && !authors[0].blank? conditions << "user_id in (:authors)" - values[:authors]=User.logins_to_ids(authors) + unless is_number?(authors[0]) + authors=User.logins_to_ids(authors) + end + values[:authors]=authors end - assignees=options['assignees'] + assignees=options['assignees'].split(',') if options['assignees'] if assignees && assignees.size>0 && !assignees[0].blank? conditions << "assignee_id in (:assignees)" - values[:assignees]=User.logins_to_ids(assignees) + unless is_number?(assignees[0]) + assignees=User.logins_to_ids(assignees) + end + values[:assignees]=assignees end Review.find(:all, :include => [ 'review_comments' ], :order => "created_at DESC", :conditions => [conditions.join(" AND "), values], :limit => 200) @@ -112,6 +128,10 @@ class Review < ActiveRecord::Base private + def self.is_number?(s) + true if Float(s) rescue false + end + def assign_project if self.project.nil? && self.resource self.project=self.resource.project