aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-04-29 12:26:47 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-04-29 12:28:55 +0200
commit9395d53849040fb6dacc3de2ea67e563cd16d80e (patch)
tree17c00bc218d8afdb8ba9fd3c2fc67eebadb0513c /sonar-server
parent5b6b523cc19db91333e376b0aed530ad3f990c4f (diff)
downloadsonarqube-9395d53849040fb6dacc3de2ea67e563cd16d80e.tar.gz
sonarqube-9395d53849040fb6dacc3de2ea67e563cd16d80e.zip
SONAR-2327, SONAR-2382 Refactor code
Purpose: review service and web service use the same DB request method
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb41
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/review.rb26
2 files changed, 29 insertions, 38 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
index c037867e9c3..105830de552 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
@@ -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)
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 90ef876cbeb..115f4b7b58f 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
@@ -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