]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2382 Improve the web service 'reviews'
authorsimonbrandhof <simon.brandhof@gmail.com>
Fri, 29 Apr 2011 12:06:08 +0000 (14:06 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Fri, 29 Apr 2011 12:09:36 +0000 (14:09 +0200)
- New class Api::Utils to define some shared methods (around ISO datetime, markdown, ...)

- Move to_json and to_xml methods to RuleFailure and Review models

- Delete the class MarkdownHelper. Method to convert to html is moved to Api::Utils

16 files changed:
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/timemachine_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/helpers/reviews_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/models/review.rb
sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb
sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb

index e22c280a179fe2b257de546a69cf39774ede004f..afc773baa48d07f5036b98a584c2c7a861a410db 100644 (file)
@@ -206,7 +206,7 @@ class Api::EventsController < Api::ApiController
     hash[:rk]=event.resource.key if event.resource
     hash[:n]=event.name if event.name
     hash[:c]=event.category
-    hash[:dt]=format_datetime(event.event_date) if event.event_date
+    hash[:dt]=Api::Utils.format_datetime(event.event_date) if event.event_date
     hash[:ds]=event.description if event.description
     hash[:data]=event.data if event.data
     hash
@@ -226,7 +226,7 @@ class Api::EventsController < Api::ApiController
       xml.name(event.name) if event.name
       xml.resourceKey(event.resource.key) if event.resource
       xml.category(event.category)
-      xml.date(format_datetime(event.event_date)) if event.event_date
+      xml.date(Api::Utils.format_datetime(event.event_date)) if event.event_date
       xml.description(event.description) if event.description
       xml.data(event.data) if event.data
     end
index e0beb3c82331f4eba6b1908b6326aead06591894..ad53b529d7f934c44c8995ec05d7bf08a2b8de6c 100644 (file)
@@ -134,7 +134,7 @@ class Api::ProjectsController < Api::ApiController
         versions={}
         @snapshots_by_pid[project.id].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot|
           version={:sid => snapshot.id.to_s}
-          version[:d]=format_datetime(snapshot.created_at) if snapshot.created_at
+          version[:d]=Api::Utils.format_datetime(snapshot.created_at) if snapshot.created_at
           if snapshot.last?
             hash[:lv]=snapshot.version
           end
@@ -160,7 +160,7 @@ class Api::ProjectsController < Api::ApiController
           if @snapshots_by_pid && @snapshots_by_pid[project.id]
             @snapshots_by_pid[project.id].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot|
               attributes={:sid => snapshot.id.to_s, :last => snapshot.last?}
-              attributes[:date]=format_datetime(snapshot.created_at) if snapshot.created_at
+              attributes[:date]=Api::Utils.format_datetime(snapshot.created_at) if snapshot.created_at
               xml.version(snapshot.version, attributes)
             end
           end
index a7e01d541d089d0fd7ca2072f4a5f07a350b7174..dd852589a53785e2394b181e0e494b295764b6e9 100644 (file)
@@ -305,7 +305,7 @@ class Api::ResourcesController < Api::ApiController
       'name' => resource.name,
       'scope' => resource.scope,
       'qualifier' => resource.qualifier,
-      'date' => format_datetime(snapshot.created_at)}
+      'date' => Api::Utils.format_datetime(snapshot.created_at)}
     json['lname']=resource.long_name if resource.long_name
     json['lang']=resource.language if resource.language
     json['version']=snapshot.version if snapshot.version
@@ -315,23 +315,23 @@ class Api::ResourcesController < Api::ApiController
     if include_trends
       json[:p1]=snapshot.period1_mode if snapshot.period1_mode
       json[:p1p]=snapshot.period1_param if snapshot.period1_param
-      json[:p1d]=format_datetime(snapshot.period1_date) if snapshot.period1_date
+      json[:p1d]=Api::Utils.format_datetime(snapshot.period1_date) if snapshot.period1_date
 
       json[:p2]=snapshot.period2_mode if snapshot.period2_mode
       json[:p2p]=snapshot.period2_param if snapshot.period2_param
-      json[:p2d]=format_datetime(snapshot.period2_date) if snapshot.period2_date
+      json[:p2d]=Api::Utils.format_datetime(snapshot.period2_date) if snapshot.period2_date
 
       json[:p3]=snapshot.period3_mode if snapshot.period3_mode
       json[:p3p]=snapshot.period3_param if snapshot.period3_param
-      json[:p3d]=format_datetime(snapshot.period3_date) if snapshot.period3_date
+      json[:p3d]=Api::Utils.format_datetime(snapshot.period3_date) if snapshot.period3_date
 
       json[:p4]=snapshot.period4_mode if snapshot.period4_mode
       json[:p4p]=snapshot.period4_param if snapshot.period4_param
-      json[:p4d]=format_datetime(snapshot.period4_date) if snapshot.period4_date
+      json[:p4d]=Api::Utils.format_datetime(snapshot.period4_date) if snapshot.period4_date
 
       json[:p5]=snapshot.period5_mode if snapshot.period5_mode
       json[:p5p]=snapshot.period5_param if snapshot.period5_param
-      json[:p5d]=format_datetime(snapshot.period5_date) if snapshot.period5_date
+      json[:p5d]=Api::Utils.format_datetime(snapshot.period5_date) if snapshot.period5_date
     end
     if measures
       json_measures=[]
@@ -395,30 +395,30 @@ class Api::ResourcesController < Api::ApiController
       xml.qualifier(resource.qualifier)
       xml.lang(resource.language) if resource.language
       xml.version(snapshot.version) if snapshot.version
-      xml.date(format_datetime(snapshot.created_at))
+      xml.date(Api::Utils.format_datetime(snapshot.created_at))
       xml.description(resource.description) if include_descriptions && resource.description
       xml.copy(resource.copy_resource_id) if resource.copy_resource_id
 
       if include_trends
         xml.period1(snapshot.period1_mode) if snapshot.period1_mode
         xml.period1_param(snapshot.period1_param) if snapshot.period1_param
-        xml.period1_date(format_datetime(snapshot.period1_date)) if snapshot.period1_date
+        xml.period1_date(Api::Utils.format_datetime(snapshot.period1_date)) if snapshot.period1_date
 
         xml.period2(snapshot.period2_mode) if snapshot.period2_mode
         xml.period2_param(snapshot.period2_param) if snapshot.period2_param
-        xml.period2_date(format_datetime(snapshot.period2_date)) if snapshot.period2_date
+        xml.period2_date(Api::Utils.format_datetime(snapshot.period2_date)) if snapshot.period2_date
 
         xml.period3(snapshot.period3_mode) if snapshot.period3_mode
         xml.period3_param(snapshot.period3_param) if snapshot.period3_param
-        xml.period3_date(format_datetime(snapshot.period3_date)) if snapshot.period3_date
+        xml.period3_date(Api::Utils.format_datetime(snapshot.period3_date)) if snapshot.period3_date
 
         xml.period4(snapshot.period4_mode) if snapshot.period4_mode
         xml.period4_param(snapshot.period4_param) if snapshot.period4_param
-        xml.period4_date(format_datetime(snapshot.period4_date)) if snapshot.period4_date
+        xml.period4_date(Api::Utils.format_datetime(snapshot.period4_date)) if snapshot.period4_date
 
         xml.period5(snapshot.period5_mode) if snapshot.period5_mode
         xml.period5_param(snapshot.period5_param) if snapshot.period5_param
-        xml.period5_date(format_datetime(snapshot.period5_date)) if snapshot.period5_date
+        xml.period5_date(Api::Utils.format_datetime(snapshot.period5_date)) if snapshot.period5_date
       end
 
       if measures
index 79b00afb83f361e73f493db46b5f48ed30ed3ff4..179238269150d6e0821bc4af9da863f9ec9ad271 100644 (file)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 #
 
-require "json"
+require 'json'
 
 class Api::ReviewsController < Api::ApiController
 
-  include MarkdownHelper, ReviewsHelper
-
   def index
-    convert_markdown=(params[:html]=='true')
     reviews=Review.search(params)
     
     respond_to do |format|
-      format.json { render :json => jsonp(to_json(reviews, convert_markdown)) }
-      format.xml {render :xml => to_xml(reviews, convert_markdown)}
+      format.json { render :json => jsonp(Review.reviews_to_json(reviews)) }
+      format.xml {render :xml => Review.reviews_to_xml(reviews)}
       format.text { render :text => text_not_supported }
     end
   end
index e0e710a3b742be602379f441fba84fe79baff494..cc2443d4ecce5d12b82de421005177a4a239e090 100644 (file)
@@ -191,7 +191,7 @@ class Api::TimemachineController < Api::ApiController
     end
 
     @sids.each do |snapshot_id|
-      cell={:d => format_datetime(@dates_by_sid[snapshot_id])}
+      cell={:d => Api::Utils.format_datetime(@dates_by_sid[snapshot_id])}
       cell_values=[]
       cell[:v]=cell_values
 
@@ -216,7 +216,7 @@ class Api::TimemachineController < Api::ApiController
       end
       csv << header
       @sids.each do |snapshot_id|
-        row=[format_datetime(@dates_by_sid[snapshot_id])]
+        row=[Api::Utils.format_datetime(@dates_by_sid[snapshot_id])]
         @metadata.each do |metadata|
           measure=@measures_by_sid[snapshot_id][metadata.to_id]
           if measure
index f78bc3fefbcf6971096d63217a69bf67965891d5..55a8198579ac520882f76820fbbaf84016538bd3 100644 (file)
@@ -18,7 +18,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 #
 
-require "json"
+require 'json'
 
 class Api::ViolationsController < Api::ResourceRestController
 
@@ -92,15 +92,17 @@ 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")})
+    include_review=(params['include_review']=='true')
+    JSON(rule_failures.collect{|rule_failure| rule_failure.to_json(include_review)})
   end
 
   def rest_to_xml(rule_failures)
+    include_review=(params['include_review']=='true')
     xml = Builder::XmlMarkup.new(:indent => 0)
     xml.instruct!
     xml.violations do
       rule_failures.each do |rule_failure|
-        rule_failure.to_xml(xml, params['include_review']=="true")
+        rule_failure.to_xml(xml, include_review)
       end
     end
   end
index 8c3def0db689b38ef79b72ad76d615cc258b61b6..87384d9fdd51d07836a30047ae9cec0f1f4fdfe8 100644 (file)
@@ -20,7 +20,7 @@
 class ResourceController < ApplicationController
 
   SECTION=Navigation::SECTION_RESOURCE
-  helper :dashboard, :markdown
+  helper :dashboard
   
   def index
     @resource = Project.by_key(params[:id])
index 105830de5520a18c623b0c316c7e684544ed02b9..ac563f86f089f2e1bd37a580c150fc477cb46832 100644 (file)
@@ -26,7 +26,7 @@ class ReviewsController < ApplicationController
          :only => [:assign, :comment_form, :flag_as_false_positive, 
                    :violation_assign, :violation_flag_as_false_positive,:violation_save_comment, :violation_delete_comment], 
          :redirect_to => {:action => :error_not_post}
-  helper ReviewsHelper, MarkdownHelper, SourceHelper
+  helper SourceHelper
 
   def index
     init_params()
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb
deleted file mode 100644 (file)
index 0c6aedf..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
- #
- # Sonar, entreprise quality control tool.
- # Copyright (C) 2008-2011 SonarSource
- # mailto:contact AT sonarsource DOT com
- #
- # Sonar is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Lesser General Public
- # License as published by the Free Software Foundation; either
- # version 3 of the License, or (at your option) any later version.
- #
- # Sonar is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- # Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public
- # License along with Sonar; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- #
-module MarkdownHelper
-
-  def markdown_to_html(input)
-    input ? Java::OrgSonarServerUi::JRubyFacade.markdownToHtml(ERB::Util.html_escape(input)) : ''
-  end
-
-end
\ No newline at end of file
index 41da95a1847b3d1bdfc2d796ea193b1615330a53..2cf6e97b6eef65207f74bd09805267a4a7590906 100644 (file)
@@ -23,69 +23,4 @@ module ReviewsHelper
     Project.find(:all, :select => 'id,name,long_name', :conditions => ['enabled=? AND scope=? AND qualifier IN (?)', true, 'PRJ', ['TRK', 'VW','SVW']], :order => 'name ASC')
   end
   
-  def to_xml(reviews, convert_markdown)
-    xml = Builder::XmlMarkup.new(:indent => 0)
-    xml.instruct!
-    
-    xml.reviews do
-      reviews.each do |review|
-        review_to_xml(xml, review, convert_markdown)
-      end
-    end
-  end
-  
-  def review_to_xml(xml, review, html=false)
-    xml.review do
-      xml.id(review.id.to_i)
-      xml.createdAt(format_datetime(review.created_at))
-      xml.updatedAt(format_datetime(review.updated_at))
-      xml.user(review.user.login)
-      xml.assignee(review.assignee.login) if review.assignee
-      xml.title(review.title)
-      xml.type(review.review_type)
-      xml.status(review.status)
-      xml.severity(review.severity)
-      xml.resource(review.resource.kee)  if review.resource
-      xml.line(review.resource_line) if review.resource_line > 0
-      xml.comments do
-        review.review_comments.each do |comment|
-          xml.comment do
-            xml.author(comment.user.login)
-            xml.updatedAt(format_datetime(comment.updated_at))
-            xml.text(html ? markdown_to_html(comment.review_text): comment.review_text)
-          end
-        end
-      end
-    end
-  end
-  
-  def to_json(reviews, convert_markdown=false)
-    JSON(reviews.collect{|review| review_to_json(review, convert_markdown)})
-  end
-
-  def review_to_json(review, html=false)
-    json = {}
-    json['id'] = review.id.to_i
-    json['createdAt'] = format_datetime(review.created_at)
-    json['updatedAt'] = format_datetime(review.updated_at)
-    json['author'] = review.user.login
-    json['assignee'] = review.assignee.login if review.assignee
-    json['title'] = review.title if review.title
-    json['type'] = review.review_type
-    json['status'] = review.status
-    json['severity'] = review.severity
-    json['resource'] = review.resource.kee if review.resource
-    json['line'] = review.resource_line if review.resource_line > 0
-    comments = []
-    review.review_comments.each do |comment|
-      comments << {
-        'author' => comment.user.login,
-        'updatedAt' => format_datetime(comment.updated_at),
-        'text' => (html ? markdown_to_html(comment.review_text): comment.review_text)
-      }
-    end
-    json['comments'] = comments
-    json
-  end
-  
 end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb
new file mode 100644 (file)
index 0000000..2d7ab0c
--- /dev/null
@@ -0,0 +1,44 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2011 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+#
+require 'time'
+
+class Api::Utils
+
+  # Format dateTime to ISO format
+  def self.format_datetime(datetime)
+    datetime.strftime("%Y-%m-%dT%H:%M:%S%z")
+  end
+
+  def self.parse_datetime(datetime_string, default_is_now=true)
+    if datetime_string.blank?
+      return (default_is_now ? Time.now : nil)
+    end
+    Time.parse(datetime_string)
+  end
+
+  def self.is_number?(s)
+    true if Float(s) rescue false
+  end
+
+  def self.markdown_to_html(markdown)
+    markdown ? Java::OrgSonarServerUi::JRubyFacade.markdownToHtml(ERB::Util.html_escape(markdown)) : ''
+  end
+
+end
index 115f4b7b58fffde63346c0a6734b7ba428049b29..8d0f03590494c9ca2c4f73c68292a1797a6ab2ce 100644 (file)
@@ -108,7 +108,7 @@ class Review < ActiveRecord::Base
     authors=options['authors'].split(',') if options['authors']
     if authors && authors.size>0 && !authors[0].blank?
       conditions << 'user_id in (:authors)'
-      unless is_number?(authors[0])
+      unless Api::Utils.is_number?(authors[0])
         authors=User.logins_to_ids(authors)
       end
       values[:authors]=authors
@@ -117,7 +117,7 @@ class Review < ActiveRecord::Base
     assignees=options['assignees'].split(',') if options['assignees']
     if assignees && assignees.size>0 && !assignees[0].blank?
       conditions << 'assignee_id in (:assignees)'
-      unless is_number?(assignees[0])
+      unless Api::Utils.is_number?(assignees[0])
         assignees=User.logins_to_ids(assignees)
       end
       values[:assignees]=assignees
@@ -125,12 +125,77 @@ class Review < ActiveRecord::Base
 
     Review.find(:all, :include => [ 'review_comments' ], :order => 'created_at DESC', :conditions => [conditions.join(' AND '), values], :limit => 200)
   end
+
+  def self.reviews_to_xml(reviews)
+    xml = Builder::XmlMarkup.new(:indent => 0)
+    xml.instruct!
+    xml.reviews do
+      reviews.each do |review|
+        review.to_xml(xml)
+      end
+    end
+  end
+
+  def to_xml(xml)
+    xml.review do
+      xml.id(id.to_i)
+      xml.createdAt(Api::Utils.format_datetime(created_at))
+      xml.updatedAt(Api::Utils.format_datetime(updated_at))
+      xml.user(user.login)
+      xml.assignee(assignee.login) if assignee
+      xml.title(title)
+      xml.type(review_type)
+      xml.status(status)
+      xml.severity(severity)
+      xml.resource(resource.kee)  if resource
+      xml.line(resource_line) if resource_line && resource_line>0
+      xml.comments do
+        review_comments.each do |comment|
+          xml.comment do
+            xml.author(comment.user.login)
+            xml.updatedAt(Api::Utils.format_datetime(comment.updated_at))
+            xml.text(comment.html_text)
+          end
+        end
+      end
+    end
+  end
+
+  def self.reviews_to_json(reviews)
+    JSON(reviews.collect{|review| review.to_json()})
+  end
+
+  def to_json
+    json = {}
+    json['id'] = id.to_i
+    json['createdAt'] = Api::Utils.format_datetime(created_at)
+    json['updatedAt'] = Api::Utils.format_datetime(updated_at)
+    json['author'] = user.login
+    json['assignee'] = assignee.login if assignee
+    json['title'] = title if title
+    json['type'] = review_type
+    json['status'] = status
+    json['severity'] = severity
+    json['resource'] = resource.kee if resource
+    json['line'] = resource_line if resource_line && resource_line>0
+    comments = []
+    review_comments.each do |comment|
+      comments << {
+        'author' => comment.user.login,
+        'updatedAt' => Api::Utils.format_datetime(comment.updated_at),
+        'text' => comment.html_text
+      }
+    end
+    json['comments'] = comments
+    json
+  end
+
+  
+
   
   private
   
-  def self.is_number?(s)
-    true if Float(s) rescue false
-  end
+
   
   def assign_project
     if self.project.nil? && self.resource
index fa427eb43a58cee5885743eab7c1e7f668c6de48..214f1afa4f9471fe262be47f8a3e6465ed035ca0 100644 (file)
@@ -21,14 +21,18 @@ class ReviewComment < ActiveRecord::Base
   belongs_to :user
   belongs_to :review
   validates_presence_of :user => "can't be empty"
-  validate :comment_should_not_be_empty
+  validate :comment_should_not_be_blank
   
   alias_attribute :text, :review_text
-    
+
+  def html_text
+    Api::Utils.markdown_to_html(review_text)
+  end
+
   private
-  
-  def comment_should_not_be_empty
-    errors.add("Comment", " cannot be empty") if review_text.blank?
+
+  def comment_should_not_be_blank
+    errors.add("Comment", " cannot be blank") if review_text.blank?
   end
 
 end
index f2685534f5d0812efd39c28edbc16481029e86b6..9f529d73f80a22f02e06c08debc0f533c1d6f580 100644 (file)
 
 class RuleFailure < ActiveRecord::Base
 
-  include MarkdownHelper, ReviewsHelper
-  
   belongs_to :rule
   belongs_to :snapshot
   has_one :review, :primary_key => "permanent_id", :foreign_key => "rule_failure_permanent_id", :order => "created_at"
 
-  def false_positive?
-    switched_off==true
-  end
-
   # first line of message
   def title
     @title||=
@@ -43,19 +37,14 @@ class RuleFailure < ActiveRecord::Base
         end
   end
 
-  # in case to_has_json was used somewhere else before the "include_review" param was introduced
-  def to_hash_json
-    to_hash_json(false)
-  end
-
-  def to_hash_json(include_review=false)
+  def to_json(include_review=false)
     json = {}
     json['message'] = message
     json['line'] = line if line && line>=1
     json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase
     json['switchedOff']=true if switched_off?
     if created_at
-      json['createdAt'] = format_datetime(created_at)
+      json['createdAt'] = Api::Utils.format_datetime(created_at)
     end
     json['rule'] = {
       :key => rule.key,
@@ -68,15 +57,10 @@ class RuleFailure < ActiveRecord::Base
       :qualifier => snapshot.project.qualifier,
       :language => snapshot.project.language
     }
-    json['review'] = review_to_json(review, true) if review && include_review
+    json['review'] = review.to_json if include_review && review
     json
   end
 
-  # in case to_xml was used somewhere else before the "include_review" param was introduced
-  def to_xml(xml)
-    to_xml(xml, false)
-  end
-  
   def to_xml(xml=Builder::XmlMarkup.new(:indent => 0), include_review=false)
     xml.violation do
       xml.message(message)
@@ -84,7 +68,7 @@ class RuleFailure < ActiveRecord::Base
       xml.priority(Sonar::RulePriority.to_s(failure_level))
       xml.switchedOff(true) if switched_off?
       if created_at
-        xml.createdAt(format_datetime(created_at))
+        xml.createdAt(Api::Utils.format_datetime(created_at))
       end
       xml.rule do
         xml.key(rule.key)
@@ -97,14 +81,10 @@ class RuleFailure < ActiveRecord::Base
         xml.qualifier(snapshot.project.qualifier)
         xml.language(snapshot.project.language)
       end
-      review_to_xml(xml, review, true) if review && include_review
+      review.to_xml(xml) if include_review && review
     end
   end
 
-  def format_datetime(datetime)
-    datetime.strftime("%Y-%m-%dT%H:%M:%S%z")
-  end
-
   def build_review(options={})
     if review.nil?
       self.review=Review.new(
index bd4e5c8e920fbc7c0632fcda7ff6509a69d5c261..71065ec421f3760ea5996c4148074116600cc2d5 100644 (file)
@@ -19,7 +19,7 @@
          <span class="violation_date"><%= distance_of_time_in_words_to_now(violation.created_at) -%></span>
       &nbsp;
     <% end %>
-    <% if violation.false_positive? %>
+    <% if violation.switched_off? %>
       <%= image_tag("sep12.png") -%>
       &nbsp;
       <span class="falsePositive">False-Positive</span>
@@ -37,7 +37,7 @@
       <%= image_tag("sep12.png") -%>
         <% 
           if violation.review 
-            unless violation.false_positive? 
+            unless violation.switched_off?
         %>
         &nbsp;
         <%= link_to_remote (violation.review && violation.review.assignee_id ? "Reassign" : "Assign"),  
@@ -56,8 +56,8 @@
         <% end %>
       
         &nbsp;
-        <%= link_to_remote (violation.false_positive? ? "Unflag as false-positive" : "Flag as false-positive"),
-                       :url => { :controller => "reviews", :action => "violation_false_positive_form", :id => violation.id, :false_positive => !violation.false_positive? },
+        <%= link_to_remote (violation.switched_off? ? "Unflag as false-positive" : "Flag as false-positive"),
+                       :url => { :controller => "reviews", :action => "violation_false_positive_form", :id => violation.id, :false_positive => !violation.switched_off? },
                        :update => "reviewForm" + violation.id.to_s,
                        :complete => "$('vActions" + violation.id.to_s + "').hide();$('reviewForm" + violation.id.to_s + "').show();$('commentText" + violation.id.to_s + "').focus();" -%>
     </span>
     </h4> 
       <% if is_last_comment %>
         <div id="lastComment<%= violation.id -%>">
-          <%= markdown_to_html(review_comment.text) -%>
+          <%= review_comment.html_text -%>
         </div>
       <% else %>
-        <%= markdown_to_html(review_comment.text) -%>
+        <%= review_comment.html_text -%>
       <% end %>
   </div>
   <% 
index ef40b132d6c69a12fa7deaea26e6e68cd491a163..9b69baadc633718237fb09c7b798a107517737ed 100644 (file)
          </h4>
          <% if is_last_comment %>
            <div id="lastComment">
-             <%= markdown_to_html(comment.text) -%>
+             <%= comment.html_text -%>
            </div>
          <% else %>
-           <%= markdown_to_html(comment.text) -%>
+           <%= comment.html_text -%>
          <% end %>
           </div>
         <% end %>