]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2327, SONAR-2382 Refactor code
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 29 Apr 2011 10:26:47 +0000 (12:26 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Fri, 29 Apr 2011 10:28:55 +0000 (12:28 +0200)
Purpose: review service and web service use the same DB request method

sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb

index c037867e9c31a390556037a5ff6a8cddf120ed28..105830de5520a18c623b0c316c7e684544ed02b9 100644 (file)
@@ -298,40 +298,31 @@ class ReviewsController < ApplicationController
   end
 
   def search_reviews
-    conditions=['review_type<>:not_type']
-    values={:not_type => Review::TYPE_FALSE_POSITIVE}
-
-    unless @statuses == [""]
-      conditions << "status in (:statuses)"
-      values[:statuses]=@statuses
+    options = {}
+    unless @statuses == ['']
+      options['statuses']=@statuses.join(',')
     end
-    unless @projects == [""]
-      conditions << "project_id in (:projects)"
-      values[:projects]=@projects
+    unless @projects == ['']
+      options['projects']=@projects.join(',')
     end
-    unless @severities == [""]
-      conditions << "severity in (:severities)"
-      values[:severities]=@severities
+    unless @severities == ['']
+      options['severities']=@severities.join(',')
     end
-    unless @authors == [""]
-      conditions << "user_id in (:authors)"
-      values[:authors]=@authors.map{|s| s.to_i}
+    unless @authors == ['']
+      options['authors']=@authors.map{|s| s.to_i}.join(',')
     end
-    unless @assignees == [""]
-      conditions << "assignee_id in (:assignees)"
-      values[:assignees]=@assignees.map{|s| s.to_i}
+    unless @assignees == ['']
+      options['assignees']=@assignees.map{|s| s.to_i}.join(',')
     end
-    unless @id  == ""
+    unless @id  == ''
       if is_number? @id
-        conditions << "id = :id"
-        values[:id] = @id
+        options['id'] = @id
       else
-        conditions << "id = :id"
-        values[:id] = -1
+        options['id'] = -1
       end
     end
-
-    @reviews = Review.find( :all, :order => "created_at DESC", :conditions => [ conditions.join(" AND "), values] ).uniq
+    
+    @reviews = Review.search(options)
   end
 
   def is_number?(s)
index 90ef876cbeb71700118824e035ee7bf73e3972fc..115f4b7b58fffde63346c0a6734b7ba428049b29 100644 (file)
@@ -55,7 +55,7 @@ class Review < ActiveRecord::Base
       
     review_type = options['review_type']
     if review_type
-      conditions << "review_type=:type"
+      conditions << 'review_type=:type'
       values[:type] = review_type.upcase
     else
       conditions=['review_type<>:not_type']
@@ -63,17 +63,17 @@ class Review < ActiveRecord::Base
     end
     
     ids=options['ids'].split(',') if options['ids']
-    if options[:id]
-      conditions << "id=:id"
-      values[:id]=options[:id].to_i
+    if options['id']
+      conditions << 'id=:id'
+      values[:id]=options['id'].to_i
     elsif ids && ids.size>0 && !ids[0].blank?
-      conditions << "id in (:ids)"
+      conditions << 'id in (:ids)'
       values[:ids]=ids.map{|id| id.to_i}
     end
 
     projects=options['projects'].split(',') if options['projects']
     if projects && projects.size>0 && !projects[0].blank?
-      conditions << "project_id in (:projects)"
+      conditions << 'project_id in (:projects)'
       projectIds = []
       projects.each do |project|
         foundProject = Project.by_key(project)
@@ -84,7 +84,7 @@ class Review < ActiveRecord::Base
 
     resources=options['resources'].split(',') if options['resources']
     if resources && resources.size>0 && !resources[0].blank?
-      conditions << "resource_id in (:resources)"
+      conditions << 'resource_id in (:resources)'
       resourceIds = []
       resources.each do |resource|
         foundResource = Project.by_key(resource)
@@ -95,19 +95,19 @@ class Review < ActiveRecord::Base
 
     statuses=options['statuses'].split(',') if options['statuses']
     if statuses && statuses.size>0 && !statuses[0].blank?
-      conditions << "status in (:statuses)"
+      conditions << 'status in (:statuses)'
       values[:statuses]=statuses
     end
-
+    
     severities=options['severities'].split(',') if options['severities']
     if severities && severities.size>0 && !severities[0].blank?
-      conditions << "severity in (:severities)"
+      conditions << 'severity in (:severities)'
       values[:severities]=severities
     end
 
     authors=options['authors'].split(',') if options['authors']
     if authors && authors.size>0 && !authors[0].blank?
-      conditions << "user_id in (:authors)"
+      conditions << 'user_id in (:authors)'
       unless is_number?(authors[0])
         authors=User.logins_to_ids(authors)
       end
@@ -116,14 +116,14 @@ class Review < ActiveRecord::Base
 
     assignees=options['assignees'].split(',') if options['assignees']
     if assignees && assignees.size>0 && !assignees[0].blank?
-      conditions << "assignee_id in (:assignees)"
+      conditions << 'assignee_id in (: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)
+    Review.find(:all, :include => [ 'review_comments' ], :order => 'created_at DESC', :conditions => [conditions.join(' AND '), values], :limit => 200)
   end
   
   private