]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2382 Create a new "reviews" web service API
authorFabrice Bellingard <bellingard@gmail.com>
Thu, 28 Apr 2011 16:47:52 +0000 (18:47 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Thu, 28 Apr 2011 16:47:52 +0000 (18:47 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb

index 0f38dda8b028c28e22901b9f747ee7f5f2330734..f78bc3fefbcf6971096d63217a69bf67965891d5 100644 (file)
@@ -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
index 88deba8df15a2b101e83a34df33639f9a79b74bd..90ef876cbeb71700118824e035ee7bf73e3972fc 100644 (file)
@@ -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